Wednesday, April 11, 2007

Teaching the Monkey to Dance: Scripting AIPS #1

Is your wrist tired from typing and re-typing all those AIPS commands and parameters? Then this tutorial is for you! My goal is to relay my hard-won AIPS scripting knowledge to the rest of the world. Enjoy! For the first post, I'm show you how to name your scripts and get them into AIPS.

First, we're going to learn how to get AIPS to figure out where your scripts are. Fire up AIPS in the directory where you're going to put your test scripts. To tell AIPS where to look for your scripts set version="PWD". Now AIPS will look at the directory you started it up to for your scripts. Now we need something to call your script. Unfortunately, you can't just call the script mywonderfulsupergreataipsscript. First, the name needs to be fairly short (try for less than 9 characters). (Note that it also needs to start with a letter NOT a number. Thanks for the tip, Emily!) Second, you need to take the obvious step (or at least obvious if you're AIPS) of appending your AIPS user number in hex to the end of the filename. Fortunately, the task EHEX in AIPS can help you with that. Put in your user number and it will return a four digit number that corresponds to your user number in hex. Append the LAST THREE digits of the number to your file name. Third, you need to have the filename all in uppercase letters because AIPS only understands uppercase.

For example, my user number is 333. EHEX tells me that this is the equivalent of the hex value 0099. Therefore, I call my first script HELLO.099.

Now comes the fun part, what to put in your new script? Below I give some sample code that will tell AIPS to say hi. Type this into the HELLO.099 file.

*
proc sayhello

print 'Hello'

return; finish


Now in AIPS, type run hello. You should see the contents of HELLO.099 printed out on the console. Then type sayhello and AIPS should say 'HELLO'. If so, congratulations! If not, go back and check on your script. If you're still having trouble, leave a comment.

Next time: We're going to get into the nitty-gritty of actually writing a script.

7 comments:

emily said...

i'm not sure if you're going to mention these two things or not but just in case, and before i forget, (1) you *have* to comment out (or skip?) the first line and (2) you have to start the name of the runfile with a letter.

amanda said...

I was going to mention (1) in my next thing about writing scripts. I didn't know (2), so thanks for sharing! I'll put it in the post.

Laura said...

That part about the hex craziness is too funny. Take your user id, but it in a different base system, and then use the last three numbers. How on earth did you figure that one out? So typical AIPS.

Laura said...

Duh, When I run EHEX it gives me letters. Like 54 = '1I '
and 23 = 'N '
you said it should give a 4 digit number, am I missing something?

Laura said...

Worked for me! Thanks, Amanda! I will get over my fear of AIPS scripting yet!

amanda said...

ehex evidentally has changed. Try adding leading zeroes until you've got three digits.

Unknown said...

I have tried to run the hello script by following the instruction from "Teaching the Monkey to Dance: Scripting AIPS #1" (http://aipsforum.blogspot.com/2007/04/teaching-monkey-to-dance-scripting-aips.html).But, it is not working in my AIPS, when I run hello in AIPS it gives me following error :

AIPS 1: ZDIR: COULD NOT TRANSLATE LOGICAL =
AIPS 1: ZDIR: /home/
AIPS 1: ZTXMAT ERROR = 2

Looking forword to your help....
Thanks