Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents
Next: The Measures System in AIPS++ Up: Getting Started in AIPS++ Previous: A Guide to a Typical AIPS++ Data Reduction


Glish Overview

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.




Protect a variable

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.


Combine arithmetic and assignment operators

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.


For contiguous range

y[3:7]



Random indexing is possible with

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.

This example makes a record by name header with three members name (variable type: string), ra (variable type: float) and dec (float).


Add other members to the record


header.flux:=27.6
header.type:='quasar'
header.frequency:=5.0




Accessing record members by name or by number


header.dec
header['dec']
header[3]



Glish variables can be assigned an ``attribute''


Glish variable attributes


- 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:


Accessing record members by name or by number

velocity::[1]
velocity::units
velocity::['units']



The fields of a record many be retrieved using the field_names function:


Retrieval of field names


field_names(header)



Some tool functions and global functions in AIPS++ return a record with many members as their output.


image.coordmeasures


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.


Manipulating MeasurementSet data in Glish

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


next up previous contents
Next: The Measures System in AIPS++ Up: Getting Started in AIPS++ Previous: A Guide to a Typical AIPS++ Data Reduction   Contents
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15