View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

ecl patch

Roland Roberts wrote on Jan 07, 2009

I would have sworn I posted this a couple of years ago, but I can't find it now...

It is very convenient to be able to wrap ecl with a shell script that feeds in some command to be done. I have a custom ccxymatch task that I feed in like so
ecl < /path/to/ccxymatch.cl FITS-FILE

Of course, updating/upgrading IRAF breaks this every time because the distributed ecl ends with
exec $file

Changing about three lines makes this work. The most obvious is
exec $file $*

but to be completely correct, there are two places earlier where you have to shift argv. Here's the patch.
595 roland> diff -uw cl.csh.~1~ cl.csh
--- cl.csh.~1~  2007-10-11 00:22:57.000000000 -0400
+++ cl.csh      2009-01-06 22:41:18.000000000 -0500
@@ -19,8 +19,10 @@
 else if ($#argv > 0) then
     if ("$argv[1]" == "-old" || "$argv[1]" == "-o") then
         set cl_binary  = "cl.e"
+        shift
     else if ("$argv[1]" == "-vo" || "$argv[1]" == "-o") then
         set cl_binary  = "vocl.e"
+        shift
     else if ("$argv[1]:e" == "c") then
        # Workaround for autoconf scripts attempting to use this command as
        # a valid compiler option.  On some systems (mostly Debian) a valid
@@ -180,4 +182,4 @@
 set file = ${IRAFBIN}$cl_binary
 
 # Run the desired CL.
-exec $file
+exec $file $*

Can I "lobby" to have this change become permanent?

roland

Mike Fitzpatrick wrote on Jan 07, 2009

The preferred method for something like this is the so-called "#!cl" script, i.e. a way to make a .cl file executable using the CL as the interpreter. See for example

http://iraf.noao.edu/iraf/web/new_stuff/cl_host.html

for details. In that was your ccxymatch.cl file can become a standard host command.

-Mike

Roland Roberts wrote on Jan 07, 2009

I've gone through this with previous releases and I have never been able to get that to work. Consider the "simple" case of using images. One of the examples says
 logver = "IRAF V2.11 May 1997"	# needed for IMAGES package

What other "magic" variables will I need to make various packages work? I don't know, I can't find documentation on "to use package X in a host script, include the following..." and the type of error messages I get back are cryptic.
./foo.cl G5-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT040039
args = G5-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT040039
ERROR: Cannot open connected subprocess (imcoords$x_images.e)
    cl ()
    cl ()
    cl ()
    tv ()
    cl ()
    cl ()
    cl ()
    imutil ()
    cl ()
    immatch ()
    cl ()
    imgeom ()
    cl ()
    imfit ()
    cl ()
    imfilter ()
    cl ()
    imcoords ()
    images ()
    cl ()
    cl ()
Error while reading login.cl file - may need to rebuild with mkiraf
Fatal startup error.  CL dies.

Why is it trying to read my login.cl? Why can't it connect to subprocess imcoord$x_images.e which I didn't even know it was doing for the working version. Searching iraf.net shows no hits on the word "subprocess".

As you can tell, I find this process very frustratng and non-intuitive.

Below is my script, after I commented out the !rm which I also can't figure out how to get to work when running in this mode.
#!/iraf/iraf/bin.redhat/cl.e -f
# Automatically find the plate solution.

lists
images
imcoords
tv

printf("args = %s\n", args)

{
    string sources
    string field
    string match 	
    string platesol	
    string residuals
    string image	

    sources = args+".sources_bright"
    field = args+".usno_bright"
    match = args+".ccxymatch"
    platesol = args+".platesol"
    residuals = args+".residuals"
    image = args+".fit"

    # Remove the old files for idempotency
#    !rm -f match residuals

    ccxymatch sources field match 6 12 matching=triangles nmatch=50 xmag=3 ymag=3 verbose=yes

    ccmap input=match database=platesol results=residuals images=image lngcolumn=1 latcolumn=2 xcolumn=3 ycolumn=4 update=yes interactive=no verbose=no

}
logout

Mike Fitzpatrick wrote on Jan 07, 2009

I think you may have simply mistyped the value of the 'arch' environment variable, which should be the same as the IRAFARCH except for a leading period. In your case IRAFARCH is 'redhat', and so the arch should be ".redhat".

This variable is used internally to find the bin directories and is normally set by the 'cl' script. Also, be sure to do a "limit stacksize unlimited" in your .cshrc file or on the command line for recent linux systems (or use "ulimit -s unlimited" for Bash shells, again something done for you by the 'cl' startup script). Otherwise your script looks fine and nominally works for me as expected.

-Mike

Roland Roberts wrote on Jan 07, 2009

That does seem to be part of the problem. I'm running from bash, I never use csh....

I've set both IRAFARCH and arch as you indicated. I've now tried running using csh as well. I do get closer once the environment variable is set, or by setting it in the script. But which shell makes no difference:
% ./foo.cl G4-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT053827
args = G4-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT053827
sources  = G4-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT053827.sources_bright
field    = G4-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT053827.usno_bright
match    = G4-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT053827.ccxymatch
platesol = G4-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT053827.platesol
residual = G4-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT053827.residuals
image    = G4-rroberts.raso-b-139P-E-240-C-10-X1-Clear-001-UT053827.fit
ERROR: Cannot open file (sources)
    cl ()
    tv ()
    cl ()
    cl ()
    cl ()
    imutil ()
    cl ()
    immatch ()
    cl ()
    imgeom ()
    cl ()
    imfit ()
    cl ()
    imfilter ()
    cl ()
    imcoords ()
    images ()
    cl ()
    cl ()
Error while reading login.cl file - may need to rebuild with mkiraf
Fatal startup error.  CL dies.

What's wrong with the error is that the sources file is present. I can't figure out where it is looking. The files are all right in the current directory. I added some diagnostics but they aren't telling me anything. I've tried adding "cl < login.cl" followed by "keep" out of desperation 'cause I have no clue what is missing. I also tried copying login.cl into my script. Those both fail the same way. ulimit -a shows unlimited stack.
#!/iraf/iraf/bin.redhat/cl.e -f
# Automatically find the plate solution.

set arch = ".redhat"

lists
images
imcoords
tv

printf("args = %s\n", args)

string sources
string field
string match 	
string platesol	
string residuals
string image	

sources = args+".sources_bright"
field = args+".usno_bright"
match = args+".ccxymatch"
platesol = args+".platesol"
residuals = args+".residuals"
image = args+".fit"

printf("sources  = %s\n", sources)
printf("field    = %s\n", field)
printf("match    = %s\n", match)
printf("platesol = %s\n", platesol)
printf("residual = %s\n", residual)
printf("image    = %s\n", image)

# Remove the old files for idempotency
!rm -f match residuals

ccxymatch sources field match 6 12 matching=triangles nmatch=50 xmag=3 ymag=3 verbose=yes

ccmap input=match database=platesol results=residuals images=image lngcolumn=1 latcolumn=2 xcolumn=3 ycolumn=4 update=yes interactive=no verbose=no

logout

I have no idea what I'm missing.

Mike Fitzpatrick wrote on Jan 07, 2009

Try using the "program mode" syntax, i.e.

ccxymatch(sources, field, .....)


instead of

ccxymatch sources field ....


As written, the script is looking for a file names 'sources', not the filename stored in the 'sources' variable. It's a CL quirk, but you'd see the same thing at the interactive prompt:


ecl> s1 = "dev$pix"
ecl> imstat s1
#               IMAGE      NPIX      MEAN    STDDEV       MIN       MAX
Error reading image s1 ...
ecl> imstat (s1)
#               IMAGE      NPIX      MEAN    STDDEV       MIN       MAX
              dev$pix    262144     108.3     131.3       -1.    19936.


-Mike

Roland Roberts wrote on Jan 07, 2009

Thank you! It's mostly working now. I don't understand why the line
!rm -f match residuals

is doing nothing (neither fails nor deletes the files). I can move the delete to the wrapper, but how do I get these type of shell tasks to run from inside cl?
#!/iraf/iraf/bin.redhat/cl.e -f
# Automatically find the plate solution.

set arch = ".redhat"

lists
images
imcoords
tv

printf("args = %s\n", args)

string sources
string field
string match 	
string platesol	
string residuals
string image	

sources = args+".sources_bright"
field = args+".usno_bright"
match = args+".ccxymatch"
platesol = args+".platesol"
residuals = args+".residuals"
image = args+".fit"

printf("sources  = %s\n", sources)
printf("field    = %s\n", field)
printf("match    = %s\n", match)
printf("platesol = %s\n", platesol)
printf("residual = %s\n", residual)
printf("image    = %s\n", image)

# Remove the old files for idempotency
!rm -f match residuals

ccxymatch.matching = "triangles"
ccxymatch.nmatch   = 50
ccxymatch.xmag     =  3
ccxymatch.ymag     =  3
ccxymatch.verbose  = yes
ccxymatch(sources, field, match, 6, 12)

ccmap.results = residuals
ccmap.images = image
ccmap.lngcolumn = 1
ccmap.latcolumn = 2
ccmap.xcolumn = 3
ccmap.ycolumn = 4
ccmap.update = yes
ccmap.interactive = no
ccmap.verbose = no

ccmap(match, platesol)

logout

Mike Fitzpatrick wrote on Jan 07, 2009

Same problem, 'match' and 'residuals' are local script variables, not actual filenames.

You can either use the DELETE command in IRAF to do the same thing, or if you need to construct a host command build the string and pipe it to the CL for execution, e.g.

printf ("!rm -f %s %s\n", match, residuals) | cl()


-Mike

Roland Roberts wrote on Jan 07, 2009

Thanks Mike. My frustration level has receded into the noise :-)

I've been reading the "An Introductory Guide to IRAF Scripts" and it's helping me put some finishing touches on the script where I need less work done in the shell wrapper.

Last post on Jan 07, 2009