Note: The SEQUENCE command now allows a macro file to be run automatically on a sequence of input and output files, with much control over the names of the input and output files. For most purposes this will be much easier to use than operating system command files or scripts (See Section 15.90, Page ). However, under special circumstances the use of a command file or script may allow flexibility which is difficult to achieve with the SEQUENCE command.
The ability to define variable names and values on the operating system command line allows flexible control over processing sequences of files through the use of a Unix ``script'' i.e. an operating system command file which automatically defines calls to FIT2D with different variable values
The Unix ``C''-shell is designed for operating system programming using a language similar to the ``C'' programming language. Thus, loops and conditional branches are available. The following is an example of a ``C''-shell script written by Thomas Ursby (formerly of the ESRF Diffraction Group) which automatically processes all files in a directory ending with the same extension.
The following is a genuine example produced by Thomas Ursby including FIT2D macro files and Unix script files, allowing flexible and easy correction of spatial distortion. These files show how FIT2D macros together with Unix scripts may be used in a very flexible manner. However, clearly this example is only valid for a particular directory structure and users must understand how to edit the file names and programming structures for their own needs. Users who are unsure of ``C''-shell programming should consult a specialist or a programming guide or reference book.
(Very minor changes have been made to these files, simply for display purposes.)
fit2d.batch : corrects all images with a certain extension in a directory. What I finally used were: scorr.batch : which reads a file in which the first row contains the name of the spline-file, the second row the name of the directory where to put the corrected images and then one file name per row. gen_files : would generate this file if one would prefer not to do it manually. scorr_imagequant.mac, etc : are the Fit2D macros. I guess it would work with one macro giving in-file-type as a variable on the command line. Thomas ----------
#!/usr/local/bin/tcsh -f # # set datapath = /users/a/ursby/test/ set splinefile = ${datapath}sbgrid1.spline set macroname = /users/a/ursby/etc/scorr.mac foreach i (${datapath}*.spe) fit2d -dim1242x1152 -svar\#file_in=$i -svar\#file_out=${i:r}.scorr \ -svar\#file_spline=$splinefile -mac${macroname} end
#!/usr/local/bin/tcsh -f # # NAME: scorr.batch # # DESCRIPTION: # Script for running Fit2D in batch mode correcting images # for spatial distortion (or whatever the macro named below # does!). The corrected images end up in a specified directory # with the extension changed to ".scorr". # # CALLING SEQUENCE: # # scorr.batch [-type] < files.txt > scorr.log # # where # # [-type] is one of # -pr for Princeton CCD camera # -ph for Photometrics CCD camera # -md88 for Molecular Dynamics 88um scan (20x25cm plates) # -md176 for Molecular Dynamics 176um scan (20x25cm plates) # If not given then "-md176" is taken as default. # # files.txt is a file containing (one line per parameter): # <name of file containing the spline function> # <name of output directory> # <name of first file to be corrected> # <name of second file to be corrected> # etc # # scorr.log is the name of the file where you want the # output text to be stored. # #### # COMMENTS: # # The "files.txt" can be generated by: # ls -1 grid.spline > files.txt # echo output-directory >> files.txt # ls -1 *.spe >> files.txt # in the case of a spline function file called "grid.spline" # and if we want to correct all the images that have the file name # extension ".spe" in the current directory (images from the # Princeton CCD camera) and put the corrected images in # "output-directory". # Or use "gen_files" # # NOTE: The file-names can be preceded by their path. # # T.Ursby 12/10/94 # To avoid opening of graphics window unsetenv DISPLAY switch ($1) case -pr: set xdim = 1242 set ydim = 1152 set macroname = /users/a/ursby/etc/scorr_princeton.mac breaksw case -ph: set xdim = 1024 set ydim = 1024 set macroname = /users/a/ursby/etc/scorr_photometrics.mac breaksw case -md88: set xdim = 2304 set ydim = 2964 set macroname = /users/a/ursby/etc/scorr_imagequant.mac breaksw case -md176: set xdim = 1152 set ydim = 1482 set macroname = /users/a/ursby/etc/scorr_imagequant.mac breaksw default: set xdim = 1152 set ydim = 1482 set macroname = /users/a/ursby/etc/scorr_imagequant.mac breaksw endsw # Read from input file set splinefile = $< set outdir = $< # Temporary file set tmp_file = `logname`.$$ set i=$< echo $i > /tmp/$tmp_file # Loop for each image (given in the input file) while ($i != '') set base = `basename $i` echo "**************************************************************" echo "Image: " $base echo # Run fit2d for one image fit2d -dim${xdim}x${ydim} -svar\#file_in=$i \ -svar\#file_out=${outdir}/${base:r}.scorr \ -svar\#file_spline=$splinefile -mac${macroname} set i=$< echo $i >> /tmp/$tmp_file end # Make list at end of the log-file of the corrected images echo "**************************************************************" echo 'Corrected images:' echo '(Spline file: ' $splinefile ')' cat /tmp/$tmp_file echo "The corrected images were put in the directory:" echo $outdir echo "**************************************************************" # Clean up /bin/rm /tmp/$tmp_file ----------
#!/bin/csh -f # # NAME: gen_files # # DESCRIPTION: # Generate input file to scorr.batch. # # CALLING SEQUENCE: # # gen_files <grid-file> <base> <image-extension> <output-directory> # # where # <grid-file> is the name of the grid file. # <base> is the path name (if present) and the beginning of the # names of the image files to be listed in the output file. # <image-extension> is the file extension of the files to be # listed in the output file. # <output-directory> is the directory where the corrected images # are to be put. # ### # COMMENTS: # See scorr.batch. # # T.Ursby 12/10/94 # echo $1 echo $4 ls -1 ${2}*.$3
%!*\ BEGINNING OF IO MACRO FILE %!*\ %!*\ This is a comment line %!*\ INPUT DATA IMAGEQUANT #file_in CALIBRATION INPUT SPATIAL FUNCTION #file_spline SPATIAL CORRECTION EXIT NO EXCHANGE OUTPUT DATA DUMP #file_out YES EXIT YES %!*\ END OF IO MACRO FILE
%!*\ BEGINNING OF IO MACRO FILE %!*\ %!*\ This is a comment line %!*\ INPUT DATA PRINCETON CCD FORMAT #file_in CALIBRATION INPUT SPATIAL FUNCTION #file_spline SPATIAL CORRECTION EXIT NO EXCHANGE OUTPUT DATA DUMP #file_out YES EXIT YES %!*\ END OF IO MACRO FILE
%!*\ BEGINNING OF IO MACRO FILE %!*\ %!*\ This is a comment line %!*\ INPUT DATA PHOTOMETRICS CCD FORMAT #file_in CALIBRATION INPUT SPATIAL FUNCTION #file_spline SPATIAL CORRECTION EXIT NO EXCHANGE OUTPUT DATA BINARY #file_out YES EXIT YES %!*\ END OF IO MACRO FILE