Known Problems & Solutions



Problem:   Reading ESO Headers        Proposed Solution:


Gaston Wrote.

This is the reply I got from IRAF about ESO header understanding. It seems
that it gives the solution, though I haven't tried it yet.

---------------------------------------------------------------------

Hi Gaston,
        I'll append a message to another user on the same subject which
contains a script and some explanation about how to deal with these
headers.  Let us know if you still have problems or questions.

Cheers,
Mike Fitzpatrick

--------------------------------------------
>From sites-request Thu Mar 16 15:15:39 2000
From: Rob Seaman <seaman>
To: zheng@pha.jhu.edu
Subject: Re:  hsel

Hello Wei Zheng,

> With "imhead", I see lines like:
> HIERARCH ESO OBS NAME        = 'lss-flat-1_0as' / OB name
> However, I am not able to grab a specific header line using "hsel":
> How can I name a header with spaces?

As you may guess, you are not the first to run into this issue.  Here
is my reply to a similar question about a year ago:

    > I am trying to use hselect task for selecting images by header field.
    > Apparently this task does not recognize long header fields like those
    > frequently used by ESO telescopes. For example the field
    > "HIERACH ESO INS GRAT1 NAME" and similars are not recognized.

    You may be aware that the ESO HIERARCH convention doesn't conform to
    the FITS standard.  In general FITS keywords have to be shorter than
    eight characters and can't contain blanks.  ESO gets away with this
    (partially) since FITS software has to be able to handle HISTORY and
    COMMENT keywords (as well as so-called "blank" keywords) that don't
    actually have any value (that is, no equals sign with a value on the
    other side).  HIERARCH keywords basically have the same syntax as these
    FITS comment keywords - the equals sign is really just part of a comment
    string along with the rest of the hierarchical fields starting with "ESO".

    Most FITS readers place the fewest possible constraints on the headers.
    Certain keywords must be present and obey certain rules - other keywords
    are typically just copied over.  Note that most astronomical packages
    also borrow the FITS keyword rules for their internal image formats
    (like IRAF .imh images).  You don't specify what image format you are
    dealing with, but it seems likely that your data started as ESO FITS.

    However, while the headers are readable and the HIERARCH keywords don't
    cause any overt errors, there is no plumbing in IRAF to support this
    ESO convention directly.  As you found, hselect doesn't know what to
    do with these keywords.

    I have appended a CL script that provides a partial solution to this
    problem.  The "esoselect" script will accept a list of images and a
    single keyword and value to match.  The names of images that have the
    specified value for the specified keyword will be printed out.

    Copy the remainder of this message below "cut here" into a file
    "esoselect.cl" in a convenient directory.  Declare the iraf task with:

        task esoselect = <directoryname>/esoselect.cl

    where <directoryname> is replaced by the full pathname you picked.  At
    this point you should be able to "lpar esoselect" and otherwise treat
    it like any other IRAF task, including using esoselect in a script.
    The task statement can be placed in your login.cl file or loginuser.cl
    file (followed by a keep at the end) so you won't need to type this in
    the future.

    To execute the task use a command like:

        cl> esoselect *.imh "hierarch eso ins grat1 name" "name for grating 1"

    Note that strings containing whitespace should be quoted as usual.  The
    keyword name will be converted to upper case as necessary, but the value
    string is case sensitive.

    You can redirect the standard output into a file or pipe it to another
    task for further processing.

    Write back if you have further questions or if your particular application
    requires somewhat different keyword handling than this script uses.
    You should be able to modify the script to handle most possibilities,
    but it may be easiest to pass the output image list (in a file) back to
    hselect if you have other non-hierarchical keywords selections to perform.

Rob Seaman
NOAO/IRAF

----- < cut here > -----

procedure esoselect (images, keyword, value)

string  images          {prompt="input image list"}
string  keyword         {prompt="keyword to examine"}
string  value           {prompt="value to match"}

string  *list           # used internally, but must be list-directed parameter

begin
        string  limages, lvalue, img, tmp, test
        struct lkeyword, keyval
        int     len, idx

        tmp = mktemp ("tmp$junk")

        # referencing query parameters will cause prompt,
        # so read into local variables for later use
        # (note that keyword names should always be upper case in headers)
        limages = images
        print (keyword) | ucase | scan (lkeyword)
        lvalue = value

        # expand the image template into an explicit list
        sections (limages, opt="fullname", > tmp)

        # step through the image list
        list = tmp
        while (fscan (list, img) != EOF) {
            keyval = ""

            # match the keyword names at the beginning of lines only
            imhead (img, long+, user+) | match ("^" // lkeyword, stop-, meta+) |
                scan (keyval)

            # trim off the keyword name and equals sign
            len = strlen (keyval)
            idx = stridx ("=", keyval)
            print (substr (keyval, idx+1, len) | scan (keyval)

            # trim off leading whitespace (and quote if keyword is a string)
            test = substr (keyval, 1, 1)
            while (test == " " || test == "'") {
                len = strlen (keyval)
                keyval = substr (keyval, 2, len)
                test = substr (keyval, 1, 1)
            }

            # trim off any "/" delimited comment
            idx = stridx ("/", keyval)
            if (idx > 1)
                keyval = substr (keyval, 1, idx-1)

            # trim off trailing whitespace (and quote or slash)
            len = strlen (keyval)
            test = substr (keyval, len, len)
            while (test == " " || test == "'" || test == "/") {
                keyval = substr (keyval, 1, len-1)
                len = strlen (keyval)
                test = substr (keyval, len, len)
            }

            if (keyval == value)
                printf ("%s\n", img)
        }

        delete (tmp, ver-, >& "dev$null")
end
 

------------------------------------------------------------------------------------------------------------------------------------------------------