Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
Glish is a programming language which allows you to perform mathematical computations, both at the Command Line level and also by writing Glish programs or scripts. Glish handles the following types of variables: boolean, byte, short, integer, float, double, complex, double complex, character strings, and records. Another feature of Glish is that it allows Automatic Variable Typing in that variables are automatically assigned a type when they are created. No declaration statements are necessary. While this is convenient, it provides no warning if you inadvertently reassign a variable. A whole array can be wiped out by assigning it to an integer. Variables can be protected by using the keyword constant.
const Pi:=3.14159
Arithmetic operators are:
+ - * / % ^
where % is the modulus operator and is the exponentiation.
Values of variables and constants in an arithmetic expression are
all converted to the type of highest precision in the expression
before performing the mathematical operations.
y:=1:10 | #a 1-d array containing values 1 to 10 |
y +:= 2 | # add 2 to every element of the array |
y := 2 | # square every element of the array |
Array operations are one of the Glish's strong points for computing
efficiency and code economy. For instance
x:=1:10; y:= 11:20 | # creates two arrays x and y of length 10 |
z:= x*y | # performs z(i)=x(i)*y(i);i=1 to 10 |
Indexing arrays can be done in various ways.
index := [3,5,6,8] | # an index array |
y[index] | # get y(3), y(5), y(6) and y(8) |
Another special type of variable in Glish is the record. A record can contain heterogeneous data structures. A record goes by a single variable name and can be passed on as a single unit to a global function. Some functions return a record. You can create a record all at once or add to it piece by piece.
header:= [name='3C273', ra=12.12345, dec=2.3318]
This example makes a record by name header with three members
name (variable type: string), ra (variable type: float) and
dec (float).
header.flux:=27.6 header.type:='quasar' header.frequency:=5.0
header.dec header['dec'] header[3]
- header.flux::units := 'Jy' - header.frequency::unit := 'GHz' - velocity:=20 - velocity::definition:= 'heliocentric' - velocity::units:= 'km/s' - print velocity 20 - print velocity:: [units=km/s, definition=heliocentric]
Like record members, attributes can be accessed by name or by number:
velocity::[1] velocity::units velocity::['units']
The fields of a record many be retrieved using the field_names
function:
field_names(header)
Some tool functions and global functions in AIPS++
return a record with many members as their output.
myimg:=image('my3C273XC1.restored') # Make an image tool posinfo:=myimg.coordmeasures([128,128]) # get info about center pixel print posinfo field_names(posinfo)
We can now use some of the features of Glish in combination
with one of the salient features of AIPS++: namely that all the data,
either from an MS or an Image can be accessed from Glish,
manipulated and placed back, if needed. Many of the tools,
such as Table, MS, and Image, have functions which can
extract the data from specified portions and create Glish
variables or arrays with those data. Thus, it is possible to write
Glish scripts for special user specific applications or do
simple computations at the Command Line window itself. Furthermore,
since tools for printing and plotting are available at the
Command Line level, they can also be included in such applications.
tablecopy('3C273XC1.ms', 'tempcopy.ms') # keep original mytab:=table('tempcopy.ms', readonly=F) # open with write permission uvw:=mytab.getcol('UVW') # get the column named UVW uvw*:=2.0 # double the whole Glish array mytab.putcol('UVW', uvw) # put the Glish array back into the colum mytab.flush() # flush the Table