View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

IRAF Task Host Execution

Mike Fitzpatrick wrote on Apr 07, 1999

> How do I run, say for example, wfits, from the unix (say c shell) ?

	In the simplest case all you would need to do is to execute the
binary file directly (bin$x_dataio.e here) and at the '>' prompt type
in the task name and respond to all of the parameter queries, then type
'bye' or an EOF to exit.  This more easily done with a small csh script
to do it automatically, e.g.

        #!/bin/csh -f
        # Demo run on DATAIO standalone binary.  Assumes 'wfits.dpar'
        # was created with "cl> dpar wfits" and the parameters it
        # contains are already set.  Newlines are redirected to satisfy
        # empty string requests.

        /<irafbin_path>/x_dataio.e wfits @wfits.dpar << EOF

        EOF

In more complicated scripts you may wish to pass in shell args for certain
parameters so it looks like a unix command.  To do this you could expand the
script to look something like

        #!/bin/csh -f
        /<irafbin_path>/x_dataio.e wfits iraf_files=$1 fits_files=$2 \
		newtape=$3 @wfits.dpar << EOF

        EOF

In this case the command line parameters override what's in the 'wfits.dpar'
file.
	Even trickier is to have the script write the parameter file itself
and edit in the args when creating the wfits.dpar file.  I'll append a
different example script using RFITS/DISPLAY to show what I mean rather than
work one up for WFITS here, but if you have questions let me know.  Graphics
or interactive tasks can also be made to run from the host level but with
a slightly different approach, see questions 12.7 and 12.8 of our FAQ for
more details (http://iraf.noao.edu/faq).  Lastly, the OpenIRAF initiative
underway now will make it easier to run tasks from the host level (amongst
other things), some features of that may start appearing in the next patch
expected in a few months.
	Hope this helps, let us know if you still have questions.

Regards,
Mike Fitzpatrick

--------------------------------------------------------------------------------
#  DISP.CSH -- Host csh script to convert a FITS file named as the argument
#  to an IRAF image which is then displayed.  The script assumes the FITS
#  file has some sort of extension, the IRAF image will be named the root
#  of the FITS file and neither is deleted.  Parameters for the tasks are
#  the V2.10.4p2 defaults.
#	To port this script to run on a new machine all that should need to
#  be changed is the path to the iraf root (i.e. $iraf), and the architecture
#  type.
#
#!/bin/csh -f

unset   noclobber
unalias cat sed rm grep
onintr  cleanup

# Configurable parameters
set	iraf	= /iraf/iraf/		# must have a trailing '/'
set	arch	= sparc			# architecture: 'hp700', 'sparc', etc

# Shouldn't need to change this.
set	irafbin	= $iraf/bin.$arch/

# Create the RFITS param file.
cat << END_RFITS_PAR |  sed -e s/FITS/$1/g | \
			sed -e s/IRAF/$1:r/g > \
			/tmp/_rfits.par$$
rfits.fits_file = "FITS"
rfits.file_list = 
rfits.iraf_file = "IRAF"
rfits.make_image = yes
rfits.long_header = no
rfits.short_header = yes
rfits.datatype = "none"
rfits.blank = 0.
rfits.scale = yes
rfits.oldirafname = no
rfits.offset = 0
rfits.mode = "ql"
# EOF
END_RFITS_PAR

# Convert the FITS file to an IRAF image.
$irafbin/x_dataio.e rfits @/tmp/_rfits.par$$

# Create the DISPLAY param file.
cat << END_DISPLAY_PAR | sed -e s/IMAGE/$1:r/g > \
			 /tmp/_disp.par$$
display.image = "IMAGE"
display.frame = 1
display.erase = yes
display.border_erase = no
display.select_frame = yes
display.repeat = no
display.fill = no
display.zscale = yes
display.contrast = 0.25
display.zrange = yes
display.nsample_lines = 5
display.xcenter = 0.5
display.ycenter = 0.5
display.xsize = 1.
display.ysize = 1.
display.xmag = 1.
display.ymag = 1.
display.order = 0
display.z1 = 
display.z2 = 
display.ztrans = "linear"
display.lutfile = ""
display.mode = "ql"
# EOF
END_DISPLAY_PAR

# Now display the image.
$irafbin/x_tv.e display @/tmp/_disp.par$$

# Clean up.
cleanup:
	/bin/rm -f /tmp/_*.par*

Mike Fitzpatrick wrote on Apr 07, 1999

>     /<irafbin_path>/x_dataio.e wfits @wfits.dpar << EOF
> 
>     EOF

	I hate following up my own post but I neglected to explain the
syntax used here and the reason why:  The redirection of blank lines is
currently required because regardless of whether you specify a parameter
on the command line or in a 'dpar' file, any string parameter that can
take an empty string as a legal value will prompt the user for the value.
In most scripts like this (at least the ones we write) the output of the
task is redirected to /dev/null so the user doesn't see it, redirecting 
blank lines on input satisfies the parameter prompts and keeps the task
from blocking for input allowing the script to run with only the intended
input command lines.  The number of blank lines required depends on the
task in question.
	Also, it should be noted that by specifying all of the parameters
on the command line any task can be run using a command directly like

	% x_dataio.e wfits par1=value par2=value ... parN=value

The average task has ~N=15 parameters so this command line can get quite
long and even by giving null-string params on the command line you cannot
avoid the prompts so the redirection used above is still required unless
you want to respond to the prompts interactively.  In cases where the csh
script is written to use script args on the command line care should be
taken to handle the args that may be empty strings on the unix command
line.
	Since IRAF tasks weren't designed to be run as host commands we
don't have any formal documentation about how to do this but in most cases
we can offer suggestions for how to write a script to execute them outside
of the normal CL environment.  Again, OpenIRAF will address many of these
issues but until then users should contact site support with specific
questions about tasks and how to run them at the host level if some of the
pointers here aren't sufficient, or if there are still any questions about
host execution of programs.  Followup postings to this newsgroup are en-
couraged so all readers can benefit from the discussion.

-Mike

DENLRH wrote on Apr 15, 1999

You apparently have been sending messages to me by mistake.  Please check
your e-mail address on this subject.  I do not know what you are talking
about.

		denlrh@dames.com


> > How do I run, say for example, wfits, from the unix (say c shell) ?
> 
> 	In the simplest case all you would need to do is to execute the
binary file directly (bin$x_dataio.e here) and at the '>' prompt type in
the task name and respond to all of the parameter queries, then type
'bye' or an EOF to exit.  This more easily done with a small csh script
to do it automatically, e.g.
> 
>         #!/bin/csh -f
>         # Demo run on DATAIO standalone binary.  Assumes 'wfits.dpar'
>         # was created with "cl> dpar wfits" and the parameters it
>         # contains are already set.  Newlines are redirected to satisfy
>         # empty string requests.
> 
>         /<irafbin_path>/x_dataio.e wfits @wfits.dpar << EOF
> 
>         EOF
> 
> In more complicated scripts you may wish to pass in shell args for
certain parameters so it looks like a unix command.  To do this you could
expand the script to look something like
> 
>         #!/bin/csh -f
>         /<irafbin_path>/x_dataio.e wfits iraf_files=$1 fits_files=$2 \
> 		newtape=$3 @wfits.dpar << EOF
> 
>         EOF
> 
> In this case the command line parameters override what's in the
'wfits.dpar' file.
> 	Even trickier is to have the script write the parameter file
itself and edit in the args when creating the wfits.dpar file.  I'll
append a different example script using RFITS/DISPLAY to show what I mean
rather than work one up for WFITS here, but if you have questions let me
know.  Graphics or interactive tasks can also be made to run from the
host level but with a slightly different approach, see questions 12.7 and
12.8 of our FAQ for more details (http://iraf.noao.edu/faq).  Lastly, the
OpenIRAF initiative underway now will make it easier to run tasks from
the host level (amongst other things), some features of that may start
appearing in the next patch expected in a few months.
> 	Hope this helps, let us know if you still have questions.
> 
> Regards, Mike Fitzpatrick
> 
>
-------------------------------------------------------------------------
------- #  DISP.CSH -- Host csh script to convert a FITS file named as
the argument #  to an IRAF image which is then displayed.  The script
assumes the FITS #  file has some sort of extension, the IRAF image will
be named the root #  of the FITS file and neither is deleted.  Parameters
for the tasks are #  the V2.10.4p2 defaults. #	To port this script to
run on a new machine all that should need to #  be changed is the path to
the iraf root (i.e. $iraf), and the architecture #  type. # #!/bin/csh -f
> 
> unset   noclobber unalias cat sed rm grep onintr  cleanup
> 
> # Configurable parameters set	iraf	= /iraf/iraf/		# must
have a trailing '/' set	arch	= sparc			# architecture:
'hp700', 'sparc', etc
> 
> # Shouldn't need to change this. set	irafbin	= $iraf/bin.$arch/
> 
> # Create the RFITS param file. cat << END_RFITS_PAR |  sed -e
s/FITS/$1/g | \
> 			sed -e s/IRAF/$1:r/g > \
> 			/tmp/_rfits.par$$ rfits.fits_file = "FITS"
rfits.file_list =  rfits.iraf_file = "IRAF" rfits.make_image = yes
rfits.long_header = no rfits.short_header = yes rfits.datatype = "none"
rfits.blank = 0. rfits.scale = yes rfits.oldirafname = no rfits.offset =
0 rfits.mode = "ql" # EOF END_RFITS_PAR
> 
> # Convert the FITS file to an IRAF image. $irafbin/x_dataio.e rfits
@/tmp/_rfits.par$$
> 
> # Create the DISPLAY param file. cat << END_DISPLAY_PAR | sed -e
s/IMAGE/$1:r/g > \
> 			 /tmp/_disp.par$$ display.image = "IMAGE"
display.frame = 1 display.erase = yes display.border_erase = no
display.select_frame = yes display.repeat = no display.fill = no
display.zscale = yes display.contrast = 0.25 display.zrange = yes
display.nsample_lines = 5 display.xcenter = 0.5 display.ycenter = 0.5
display.xsize = 1. display.ysize = 1. display.xmag = 1. display.ymag = 1.
display.order = 0 display.z1 =  display.z2 =  display.ztrans = "linear"
display.lutfile = "" display.mode = "ql" # EOF END_DISPLAY_PAR
> 
> # Now display the image. $irafbin/x_tv.e display @/tmp/_disp.par$$
> 
> # Clean up. cleanup:
> 	/bin/rm -f /tmp/_*.par*
>

Last post on Apr 15, 1999