7.- Scripting


ArcVIEW can be handled almost completely by external clients which connects to it. In this case, we will describe how the system can be handles using any type of external scripting or programming language.

There is an important PlugIn called PI_ScriptServer. This PlugIns is an interface between the internal ArcVIEW (Client-Server) protocol and any external ascii-based strings.
Even when all the messages inside ArcVIEW are ascii ones, there are some protocol mechanism involved (callbacks, etc.), so the script server translates basic ascii command into ArcVIEW messages.

The Script Server have two ways of communicating with the external world:

Sockets: This are the most used. The ScriptServer is listening in a socket (currently is a fixed port: 1314).
Files: In the event that a user can use file-based mechanism instead of socket, it can be done. The ScriptServer will receive the command from a file, and will give the answer on another file. This is the simplest way of handling it, since does not involve using socket or any special protocol

The ScriptServer will receive any command ,  it is going to send that command to the Server, and it is going to send the response to the caller. If a "callback" mechanism is involved, there is two ways of handling it: in block or unblock mode. In block mode, the ScriptServer will not send any response until the Callback message has arrived. In unblocked, it will send the "OK" immediately after the firs "immediate" response was received from the Server.

Examples of Cshell scripts can be found on

ArcVIEW/PlugIns/ScriptServer/demos/Csh

Here are examples for taking images using Csh scripts through both a file and a socket.
 
 

7.1- WIRC scripts

As already mentioned, you can use any scripting language that you want for handling the system (Csh, CL, TCL, Python, etc.). However, most of the WIRC scripts that are already done and available
for handling the system are are written using CL, which is the IRAF scripting language.
All this scripts for handling the system are under the wirc iraf package, that it is located on

/home/wirc/irafpkgs/wircpkg/

For accessing this scripts, the user just needs to type "wirc" on any IRAF (cl) console and the wirc package will be loaded, leaving all this script available for usage
The basic scripts are done. If the user wants to build new ones, he can use this basic ones as "bricks" for building more complex ones.
For editing the parameters of any CL script, you need to type "epar taskname", and that will take you to a screen for editing all the parameter of the script.
Important NOTE: In order the scripts which communicates with the ArcVIEW system to work, the Plug-In  PI_ScriptServer must be running. You can select it to start automatically every time the system starts, or you can start it manually
 

Basic-functionallity scripts:

- observe: Script for taking images. This script will prompt  for the basename, the starting image number, the exposure time and the amount of images to take. Depending on the parameters on the enable file it can prompt you for telescope offset, telescope focus and/or filter wheel position (so it can perform all this actions)
- teloffset: this script will move the telescope on the specified offset (will ask for RA and DEC values)
- telfocus: script for changing the telescope focus (will ask for focus value)
- filter: script for moving the filter wheel. It will ask you for a position. You can control the filters independently or both at the same time depending on the setting parameters The installed filters must be described o the filterpars file
- motorinit: initializes the filter wheels

More elaborated scripts:

- dithering: this script allows the user to take a sequence of dither frames, loading a sequence of objects from file. This script will call (internally) the "observe" script for taking the images and the "teloffset" one for moving the telescope. The offsets must  always be related to the starting position. According to a parameter, the telescope can be moved to the initial position at the end of the object sequence. Some example dither files can be found on /home/wirc/irafpkgs/wirckpkg/*.dat
 

Parameter files

    The Parameter files are files for setting up general functionality. This files are edited on the cl window itself, by just typing its name as a normal task. The files currently used are:

enable: this file says if the "observe " script will, besides taking the image, move the telescope and/or change the telescope focus and/or move the filter wheel
obspars: This file sets some parameters specific to the "observe" script (like auto numbering)
filterpars: here must be defined the positions and names of the filter wheels, so the "filter" script  knows which position for each filter is requested when the user ask for a filter name. In the future this file will be automatically filled asking to the Filter Module  the installed filters
telpars: set some parameters specific to all the telescope scripts (teloffset, telfocus)
 

How to build new  Iraf scripts

For adding more Iraf scripts, the steps to perform are:

- Create the actual CL code: this can be done taking as examples some of the alreday-done ones. You can call any already-defined script from inside your new script. Look into the dither.cl script  (this script is calling "observe" and "teloffset") or "observe.cl" (this is calling "teloffset", telfocus" and "filter") as examples.
- After you have your new code, you must edit the file called "wirc.cl", and add your script there, so when the wirc package is loaded it will leave your new script available for execution. What you need to add to the list is:

"task taskname = wirc$taskfilename", where taskname is the name that appears as your script "procedure" name, and taskfilename is the name of your file (normally "taskname.cl")

After that, you need to reload the wirc package by typing "bye" and then "wirc", or "unlearn wirc", and then "wirc"
 
 We must note that already exists a "custom WIRC package tool", mainly provided by Dave Thomson. The package is called WIRCtools and it is available for any user. This is the place intended for observers and users to contribute with public scripts

7.2.-  Special Script: BurnDVD


This Iraf script allows the user to burn a DVD-R, DVD-RW, CD-R or CD-RW with data. The wirc package must be loaded for the script to be available.  The required parameters are:

cl> wirc
wi> epar burn
 

   PACKAGE = wirc
      TASK = burnDVD
   
sdir       =  	  /home2/wirc/images)  source dir
(vlabel    =          		    )  volume label (defaults to current date)
(capacit   =     		4489)  disk capacity (MB) (1MB=1024x1024K)
(isodir    = 	/home2/wirc/dvdfiles)  directory for temporary iso files
(isofile   =           	     iso.raw)  temporary iso file name
(type      =           	       DVD-R)  device type
(deletei   =          	         yes)  delete temporary iso file at the end?
(reuse     =           	          no)  reuse existing ISO file?
(dummymo   =          	          no)  try dummy mode first?
(verify    =           	         yes)  verify data written correctly to dvd?
(devdvddir =        	    /dev/dvd)  device directory
(mntdvddir =         	    /mnt/dvd)  mounted device directory
(mode   =           		  ql)
    

sdir: source directory, which contents that data to be burned
vlabel: desired label for the volume. It will default to the current date

 This two parameters will be asked every time you run the script. The remaining ones are "hiding", which means that the user must change its "manually" (they will not be prompted)

capacity: capacity of the media to be used, in MB.  As a reference,  a standard CD-R and DC-RW has 650-700 MB, while a standard DVD has 4489 MB (4.7 GB)
isodir: directory for storing the temporary ISO file that needs to be created for writing the media
isofile: name that the ISO file will have. If a file already exists, IT WILL BE OVERRIDDEN
type: type of device to use. Choices are DVD-R (recordable DVD, for writing once, of type -R), DVD-RAM, CD-R  (recordable, for writing once), and CD-RW (re-writables CDs). Note that DVD+R or DVD-RW will       not work
deleteiso: controls if you want to delete the ISO file once it has been written to the storage media or you want to leave it on disk
reuse: controls if you want to create a new ISO file from the source dir to burn the media, or if you already have an ISO file and you want to use it
dummymode: controls if you want a real burn or a dummy burn . Dummy burn are useful if you are not sure the media you have is compatible or if it is going to work. The dummy mode performs all the steps that the real burn will do, but the actual laser is turned off during the burning process
verify: if YES, runs an md5checksum on data in source directory and compares to md5checksum on data written to the dvd. Errors, if any, are then listed.
devdvddir: path to the dvd device (/dev/dvd on WIRC2 computer, /dev/dvdram on WIRC computer)
mntdvddir: path to the mounted dvd device (/mnt/dvd on WIRC2 computer, /mnt/dvdram on WIRC computer)
mode: internal use.

This script uses the mkisofs program for generating the ISO file, and the cdrecord-proDVD one for the actual burn. The script is very simple, and it is going to performs the following steps:

- verify that your writable media has enough space for storing your source dir
- verify that there is enough space available on for storing the temporary ISO file (on the specified filesystem)
- generate the ISO file if requested
- burn the media on the requested mode (dummy or real)
 
 

  7.3 - Demo scripts: Image Puller

This are part of the arcview package. They get images from a remote host running an ArcVIEW database module (DBS).
Main script:
getimages.cl

called scripts:
getimlist.cl
pullimages.cl
erasefromlist.cl
postproc.cl

How it works:

For general information about how the images are pulled from the remote machine, see the Data Reduction Computer documentation

getimages will be forever on a loop asking the remote dbs from an image list (through the getimagelist task). Everytime an image list is got, it passes that list to the pullimage task, which will go over the list, and will bring image by image using sftp. After that is done, the erasefromlist task will be called (if set to do so) for deleting the images that were pulled from the remote list. After that, the list of pulled images (now local ones) will passes to the postprocess task (if set to do so), which will perform over the list of images the selected postprocessing. The ones currently implemented are just for demo purposes, but the idea is that it can perform over the images any desired action (like flipping, or substarcting a flat, etc). After that, it will start all over again.

the parameters from the main menu are
               
PACKAGE = arcview
   TASK = getimages

deleteol=                  yes  delete old list of images on host?
(dbshost=                 wirc) host where the images are (dbs host)
(dbsport=                 1300) Port of service on host
(user   =                 wirc) user to login
(imslist=          images.list) file to write list of images from host
(imspull=           images.got) file to write list of last images pulled
(logimag=                  yes) log all images pulled
(imslogf=           images.log) file to write log file (all images)
(sleepti=                   20) time between pollings (secs)
(postpro=                  yes) post process images (epar postproc)
(delreml=                  yes) delete image list on remote host?
(verbose=                  yes) verbose operations
(fd     =                     )
(mode   =                   ql)

parameters explanation:

deleteold    : When the script starts, it will ask the remote database for the image list. If a non-empty file is found, it will prompt the user whether to bring                             those remote images, or to delete its from the remote image list. This parameters says what to do
dbshost, dbsport: address (or name) of remote host, and port on remote host
user: user name to loggin in the remote machine
imslist: file where to get the list of images gotten from the remote dbs
imspulled: file where to write the list of images just pulled (last time)
logimages: whether to generate a log file with all the images than have been pulled
imslogfile: name of the log file to generate if the logimages parameter is set
sleeptime: polling time for getting the images (seconds)
postproc: would you like to call the postproc task, to be run over every image succesfully pulled?
delremlist: if set, it will use the "get image and delete name on remote list", if not set, it will use the "timestamp" mechanism
verbose: do everything verbosely
fd, mode: internal use


The other important parameters file is the one from the pullimages task

PACKAGE = arcview
   TASK = pullimages

(dbshost=                 wirc) host to get images from
(user   =                 wirc) user to log in
(logimag=                  yes) log a list of all images succesfully pulled
(imslogf=           images.log) file name for log file
(imslist=          images.list) file with list of images to pull
(replica=                  yes) try replicating directory structure also
(imgpath=                   ./) directory for images
(locimsp=        imagesloc.got) file to log last images pulled (local name)
(remimsp=        imagesrem.got) file to log last images pulled (remote name)
(lasttim=                     ) timestamp on last image pulled (output)
(thistim=                     ) time when last image pulled was written HERE (ou
(verbose=                  yes) verbose operations
(fd     =                     )
(mode   =                   ql)

Not described before, are:

replicate: if set, it will try to replicate locally the remote directory.
imgpath: if replicate is not set, then this is the directory for leaving all the local images