|
NAMEAstro::FITS::Header - Object Orientated interface to FITS HDUsSYNOPSIS$header = new Astro::FITS::Header( Cards => \@array ); DESCRIPTIONStores information about a FITS header block in an object. Takes an hash with an array reference as an argument. The array should contain a list of FITS header cards as input.METHODSConstructor
Accessor Methods
General Methods
Operator OverloadingThese operators are overloaded:
Private methodsThese methods are for internal use only.
TIED INTERFACEThe "FITS::Header" object can also be tied to a hash:use Astro::FITS::Header; $header = new Astro::FITS::Header( Cards => \@array ); tie %hash, "Astro::FITS::Header", $header $value = $hash{$keyword}; $hash{$keyword} = $value; print "keyword $keyword is present" if exists $hash{$keyword}; foreach my $key (keys %hash) { print "$key = $hash{$key}\n"; } Basic hash translationHeader value type is determined on-the-fly by parsing of the input values. Anything that parses as a number or a logical is converted to that before being put in a card (but see below).Per-card comment fields can be accessed using the tied interface by specifying a key name of "key_COMMENT". This works because in general "_COMMENT" is too long to be confused with a normal key name. $comment = $hdr{CRPIX1_COMMENT}; will return the comment associated with CRPIX1 header item. The comment can be modified in the same way: $hdr{CRPIX1_COMMENT} = "An axis"; You can also modify the comment by slash-delimiting it when setting the associated keyword: $hdr{CRPIX1} = "34 / Set this field manually"; If you want an actual slash character in your string field you must escape it with a backslash. (If you're in double quotes you have to use a double backslash): $hdr{SLASHSTR} = 'foo\/bar / field contains "foo/bar"'; Keywords are CaSE-inNSEnSiTIvE, unlike normal hash keywords. All keywords are translated to upper case internally, per the FITS standard. Aside from the SIMPLE and END keywords, which are automagically placed at the beginning and end of the header respectively, keywords are included in the header in the order received. This gives you a modicum of control over card order, but if you actually care what order they're in, you probably don't want the tied interface. Comment cardsComment cards are a special case because they have no normal value and their comment field is treated as the hash value. The keywords "COMMENT" and "HISTORY" are magic and refer to comment cards; nearly all other keywords create normal valued cards. (see "SIMPLE and END cards", below).Multi-card valuesMultiline string values are broken up, one card per line in the string. Extra-long string values are handled gracefully: they get split among multiple cards, with a backslash at the end of each card image. They're transparently reassembled when you access the data, so that there is a strong analogy between multiline string values and multiple cards.In general, appending to hash entries that look like strings does what you think it should. In particular, comment cards have a newline appended automatically on FETCH, so that $hash{HISTORY} .= "Added multi-line string support"; adds a new HISTORY comment card, while $hash{TELESCOP} .= " dome B"; only modifies an existing TELESCOP card. You can make multi-line values by feeding in newline-delimited strings, or by assigning from an array ref. If you ask for a tag that has a multiline value it's always expanded to a multiline string, even if you fed in an array ref to start with. That's by design: multiline string expansion often acts as though you are getting just the first value back out, because perl string-to-number conversion stops at the first newline. So: $hash{CDELT1} = [3,4,5]; print $hash{CDELT1} + 99,"\n$hash{CDELT1}"; prints "102\n3\n4\n5", and then $hash{CDELT1}++; print $hash{CDELT1}; prints "4". In short, most of the time you get what you want. But you can always fall back on the non-tied interface by calling methods like so: ((tied $hash)->method()) If you prefer to have multi-valued items automagically become array refs, then you can get that behavior using the "tiereturnsref" method: tie %keywords, "Astro::FITS::Header", $header, tiereturnsref => 1; When tiereturnsref is true, multi-valued items will be returned via a reference to an array (ties do not respect calling context). Note that if this is configured you will have to test each return value to see whether it is returning a real value or a reference to an array if you are not sure whether there will be more than one card with a duplicate name. Type forcingBecause perl uses behind-the-scenes typing, there is an ambiguity between strings and numeric and/or logical values: sometimes you want to create a STRING card whose value could parse as a number or as a logical value, and perl kindly parses it into a number for you. To force string evaluation, feed in a trivial array ref:$hash{NUMSTR} = 123; # generates an INT card containing 123. $hash{NUMSTR} = "123"; # generates an INT card containing 123. $hash{NUMSTR} = ["123"]; # generates a STRING card containing "123". $hash{NUMSTR} = [123]; # generates a STRING card containing "123". $hash{ALPHA} = "T"; # generates a LOGICAL card containing T. $hash{ALPHA} = ["T"]; # generates a STRING card containing "T". Calls to keys() or each() will, by default, return the keywords in the order in which they appear in the header. Sub-headersWhen the key refers to a subheader entry (ie an item of type "HEADER"), a hash reference is returned. If a hash reference is stored in a value it is converted to a "Astro::FITS::Header" object.If the special key "SUBHEADERS" is used, it will return the array of subheaders, (as stored using the "subhdrs" method) each of which will be tied to a hash. Subheaders can be stored using normal array operations. SIMPLE and END cardsNo FITS interface would becomplete without special cases.When you assign to SIMPLE or END, the tied interface ensures that they are first or last, respectively, in the deck -- as the FITS standard requires. Other cards are inserted in between the first and last elements, in the order that you define them. The SIMPLE card is forced to FITS LOGICAL (boolean) type. The FITS standard forbids you from setting it to F, but you can if you want -- we're not the FITS police. The END card is forced to a null type, so any value you assign to it will fall on the floor. If present in the deck, the END keyword always contains the value " ", which is both more-or-less invisible when printed and also true -- so you can test the return value to see if an END card is present. SIMPLE and END come pre-defined from the constructor. If for some nefarious reason you want to remove them you must explicitly do so with "delete" or the appropriate method call from the object interface. SEE ALSO"Astro::FITS::Header::Item", "Starlink::AST", "Astro::FITS::Header::CFITSIO", "Astro::FITS::Header::Item::NDF".COPYRIGHTCopyright (C) 2007-2011 Science and Technology Facilties Council. Copyright (C) 2001-2007 Particle Physics and Astronomy Research Council and portions Copyright (C) 2002 Southwest Research Institute. All Rights Reserved.This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,Suite 330, Boston, MA 02111-1307, USA AUTHORSAlasdair Allan <aa@astro.ex.ac.uk>, Tim Jenness <t.jenness@jach.hawaii.edu>, Craig DeForest <deforest@boulder.swri.edu>, Jim Lewis <jrl@ast.cam.ac.uk>, Brad Cavanagh <b.cavanagh@jach.hawaii.edu>
Visit the GSP FreeBSD Man Page Interface. |