fedithead  Richard J. Mathar
Fitsheaderkeywordbatcheditor
 All Classes Files Functions Variables Macros
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
FEditHead Class Reference

The class edits header keywords FITS headers. More...

#include <FEditHead.h>

Inherits FITS.

Public Member Functions

 FEditHead (char *fitsname, char *fitstpl)
 Constructor given a FITS file and a template ASCII file.
 
 FEditHead (char *fitsname, const vector< string > fitstpl)
 Constructor given a FITS file and a list of template ASCII files.
 
 FEditHead (const char *gstream, int glines, int bitpix, int naxis, long *naxes, char fitstpl[], const char *fname)
 
 FEditHead (const char *gstream, int glines, int bitpix, int naxis, long *naxes, const vector< string > fitstpl, const char *fname)
 Constructor given an old-fashioned GEIRS header stream and template ASCII files.
 
 FEditHead (const char *gstream, char *fname, int glines=-1)
 Constructor given an old-fashioned GEIRS header stream.
 
 ~FEditHead ()
 Destructor.
 
void exec (const bool verbose)
 Execute the modifications of the template file in the header.
 
char * allLines (int maxLines)
 

Public Attributes

String cfgFil
 Name of the configuration file with header template keywords.
 
char * buffer
 The concatenation of all input lines, trimed/expanded to a multiple of 80 characters per line, one final \0.
 

Protected Member Functions

vector< string > scanTpl (const char *fitstpl, const bool raw80=false) const
 Scan the template file.
 
vector< string > scanTpl (const string fitstpl, const bool raw80=false) const
 Scan the template file.
 
vector< string > scanTpl (const vector< string >fitstpl, const bool raw80=false) const
 Scan a list of template files.
 
void readStream (const char *gstream, int glines, const bool restr=false)
 

Static Protected Member Functions

static string trimws (const string &instring)
 Strip leading and trailing white space from a string.
 
static char * parse_template (const string &instring)
 Reformat an input string into a standard FITS header line.
 
static int templateAnal (char *card, char keyname[], char keyval[], char cmt[], char dtyp[])
 Analyse a header card.
 
static vector< string > splitColon (const string &instring)
 Split a string using colons or exclamaion marks as delimiters.
 
static vector< string > splitColon (const string &instring, const string &delim)
 Split a string using a specific delimiting string.
 
static bool addHduCard (HDU &hdu, char *card, const bool verbose=false)
 

Protected Attributes

vector< string > tplLins
 The assembly of all template keyword ASCII lines.
 

Detailed Description

The class edits header keywords FITS headers.

The object is created specifying the name of an existing FITS file and the name of a template file which contains instructions to add, delete or modify keywords. A method then allows to run through these instructions and apply them to a specified primary or extension header.

The main intend of this program is to eliminate the limitations known for the fmodhead, fthedit and eso2fits programs. The program fedithead does work with hierarchical keywords, and and it even allows to replace hierarchical keywords by simple keywords and vice versa. Groups of keywords that are pareseable by a regex(7) specification may also be removed or replaced with a syntax known from the sed(1), calculated with the aid of the boost::regex package. Moving keywords between HDU's or re-calculation of keywords as with ESO's FTU is not supported.

Since
2012-10-18
Author
Richard J. Mathar

Constructor & Destructor Documentation

FEditHead::FEditHead ( char *  fitsname,
char *  fitstpl 
)

Constructor given a FITS file and a template ASCII file.

It attempts to open the FITS file and to scan the template file. Applying the template modifications to the FITS file is left to a subsequent call to FEditHead::exec .

Parameters
[in]fitsnameThe name of the FITS file to be modified.
[in]fitstplThe name of the ASCII file with the header template lines.
Since
2012-10-18
Author
Richard J. Mathar
FEditHead::FEditHead ( char *  fitsname,
const vector< string >  fitstpl 
)

Constructor given a FITS file and a list of template ASCII files.

It attempts to open the FITS file and to scan all template files. Applying the template modifications to the FITS file is left to a subsequent call to FEditHead::exec .

Parameters
[in]fitsnameThe name of the FITS file to be modified.
[in]fitstplThe name of the ASCII files with the header template lines.
Since
2013-10-30
Author
Richard J. Mathar
FEditHead::FEditHead ( const char *  gstream,
int  glines,
int  bitpix,
int  naxis,
long *  naxes,
char  fitstpl[],
const char *  fname 
)
FEditHead::FEditHead ( const char *  gstream,
int  glines,
int  bitpix,
int  naxis,
long *  naxes,
const vector< string >  fitstpl,
const char *  fnam 
)

Constructor given an old-fashioned GEIRS header stream and template ASCII files.

It attempts to split the header stream in 80 bytes pieces and to scan all template files. Applying the template modifications to the FITS file is left to a subsequent call to FEditHead::exec .

Parameters
[in]gStreamThe bytes in the GEIRS header. These are characterized by having the shape of non-terminated 80-byte lines.
[in]glinesThe number of 80-byte lines in gstream.
[in]fitstplThe names of the ASCII files with the header template lines.
[in]fnamThe name of the temporary FITS file to be created.
Since
2013-07-12
Author
Richard J. Mathar
FEditHead::FEditHead ( const char *  gstream,
char *  fnam,
int  glines = -1 
)

Constructor given an old-fashioned GEIRS header stream.

It attempts to split the header stream in 80 bytes pieces. Applying the template modifications to the FITS file is left to a subsequent call to FEditHead::exec .

Parameters
[in]gStreamThe bytes in the GEIRS header. These are characterized by having the shape of non-terminated 80-byte lines.
[in]fnamThe name of the temporary FITS file to be created.
Since
2013-07-12
Author
Richard J. Mathar
FEditHead::~FEditHead ( )

Destructor.

De-allocates the buffer with the sequential concatenation of all the 80-bytes header lines. Removes the FITS file if the flag keepDtor was set to false.

Member Function Documentation

void FEditHead::exec ( const bool  verbose)

Execute the modifications of the template file in the header.

Request of adding or modifying keywords are executed in the order of request (in the order of the template file) and the new keywords are appended in that order. This basically means that header cards are not sorted in any particular way to be 'nice.'

Parameters
[in]verboseIf true, comment on each substitution, deletion etc.
Since
2012-10-18
Author
Richard J. Mathar

Do nothing if the requested list of keywords is empty.

Consider in the outer loop each applicable template line.

char * FEditHead::allLines ( int  maxLines)

Dump the lines into the local buffer and return its location.

Parameters
[in]maxLinesA cutoff for the number of lines to be returned. A negative number is interpreted as that no upper limit is set.
Returns
A pointer to a locally allocated buffer. This will be removed once the instance of the class goes out of scope.
Since
2013-07-12
vector< string > FEditHead::scanTpl ( const char *  fitstpl,
const bool  raw80 = false 
) const
protected

Scan the template file.

Parameters
[in]fitstplThe name of the template ASCII file. The file contains six types of lines:
  • Empty lines and lines starting immediately with a hash (#) are ignored (interpreted as lines that comment the template).
  • Lines starting with a dash (-) contain a keyword (right after the dash with optional white space in between) that is to be removed from the FITS header. If the keyword starts with HIERARCH, it may consist of blank-separated components, or otherwise it needs to follow the standard 8-letter limitation.
  • Lines starting with a delimiter, either the colon or the exclamation mark, contain two keywords, separated by another delimiter of the same type. The keyword between the first pair of delimiters is replaced by the keyword in the second pair. This syntax is an extension to the standard cfitsio/fitsio template syntax because this allows to delimit multi-strings as seen with the hierarchical keywords, and on which fedithd will choke if used with its implied rule of the (-)-syntax.
  • Other lines are interpreted as a keyword, value and comment in the standard FITS style. An equal sign separates keyword and value, and the comment following after a slash (/). Hierarchical keywords are allowed. Conversion to upper case letters occurs on the fly. Comments in long input lines are chopped. Note that if the corresponding keyword is already present in the header, it will be replaced by this new one.
  • Lines starting with at least 8 blanks are inserted as COMMENT cards into the FITS header, effectively replacing these blanks by the COMMENT keyword. Long lines will be wrapped into the next COMMENT card to fit into the 80-bytes limits of the standard.
    Parameters
    [in]raw80If true, the file fitstpl contains lines of 80 bytes without line feeds
    Returns
    The non-comment lines of the file. The order of the input file (top to bottom) is preserved.
    Since
    2012-10-18
    Author
    Richard J. Mathar
vector< string > FEditHead::scanTpl ( const string  fitstpl,
const bool  raw80 = false 
) const
protected

Scan the template file.

Parameters
[in]fitstplThe name of the template ASCII file. The contents is the same as documented in the signature with the character pointer.
[in]raw80If true, the file fitstpl contains lines of 80 bytes without line feeds
Returns
The non-comment lines of the file. The order of the input file (top to bottom) is preserved.
Since
2013-10-17
Author
Richard J. Mathar
vector< string > FEditHead::scanTpl ( const vector< string >  fitstpl,
const bool  raw80 = false 
) const
protected

Scan a list of template files.

The function implies a loop of scans over the template files in the order of the vector. This means files later (with higher index) in the vector may override the specs of lines in files earlier in the vector.

Parameters
[in]raw80If true, the file fitstpl contains lines of 80 bytes without line feeds
Returns
The non-comment lines of the file. The order of the input file (top to bottom) is preserved.
Since
2013-10-17
Author
Richard J. Mathar
string FEditHead::trimws ( const string &  instring)
staticprotected

Strip leading and trailing white space from a string.

Parameters
[in]instringThe initial string from which nonprintable leading and trailing characters or white space (tabs, blanks) ought to be removed.
Returns
The string with leading and trailing blanks, tabs etc removed.
char * FEditHead::parse_template ( const string &  instring)
staticprotected

Reformat an input string into a standard FITS header line.

This is an intermediate invocation of the fits_parse_template() functionality of cfitsio.

Parameters
[in]instring
Returns
A validated copy of the card line. This char array should be delete[]d by the caller after return.
int FEditHead::templateAnal ( char *  card,
char  keyname[],
char  keyval[],
char  cmt[],
char  dtyp[] 
)
staticprotected

Analyse a header card.

The header card is decomposed into name, value, comment and type.

Parameters
[in]cardThe card to be analysed, typically up to 80 characters.
[out]keynameKeyword name in the card.
[out]keyvalKeyword value in the card.
[out]cmtComment after the slash in the card.
[out]dtypRough type (string, integer, float, boolean or complex)
Returns
The cfitsio error code. 0 if there was no error.
vector< string > FEditHead::splitColon ( const string &  instring)
staticprotected

Split a string using colons or exclamaion marks as delimiters.

Parameters
[in]instringThis input has the sequential format :....:.....:.... or !...!...!... Either the colon or the exclamation mark are the local delimiters. This means the first, second and third mark delimit the two strings to be defined. The third mark is optional. If missing, the entire residual part of the input defines the 2nd string.
Returns
A vector of 2 strings. The first contains the characters between the first and the second mark, the second between the 2nd and the third mark.
Since
2012-10-18
2013-01-29 With exclamation marks working as delimiters
Author
Richard J. Mathar
vector< string > FEditHead::splitColon ( const string &  instring,
const string &  delim 
)
staticprotected

Split a string using a specific delimiting string.

Parameters
[in]instringThis input has the sequential format <delimit>....<delimit>.....<delimit>... This means the first, second and third mark delimit the two strings to be defined. The third mark is optional. If missing, the entire residual part of the input defines the 2nd string.
[in]delimThe delimiting string.
Returns
A vector of 2 strings. The first contains the characters between the first and the second mark, the second between the 2nd and the third mark. If the delimiters were not found, an empty vector is returned.
Since
2013-01-29
Author
Richard J. Mathar
void FEditHead::readStream ( const char *  gstream,
int  glines,
const bool  restr = false 
)
protected

Put the 80-bytes chunks of the stream into the primary header.

Parameters
gstreamThe characters to be fed into the primary header. This stream contains neither line feeds nor 0-bytes.
[in]glinesThe number of 80-byte blocks in gstream
[in]restrRestrict the lines such that NAXIS keywords are blocked
Since
2013-07-15
bool FEditHead::addHduCard ( HDU &  hdu,
char *  card,
const bool  verbose = false 
)
staticprotected

Insert (or replace) a HDU header card.

Parameters
hduThe header-data unit to be checked for the card.
cardThe (first 80 bytes of) the new header card.
verbose
Returns
true if the new card was installed. Return values of false occur if the syntax of the card is not valid.
Since
2013-07-15

Member Data Documentation

String FEditHead::cfgFil

Name of the configuration file with header template keywords.

char* FEditHead::buffer

The concatenation of all input lines, trimed/expanded to a multiple of 80 characters per line, one final \0.

vector<string> FEditHead::tplLins
protected

The assembly of all template keyword ASCII lines.

These are all lines with the exception of empty or comment lines. They are kept in the order of the configuration file, which may be important if the same keyword may be targeted at more than one place (in case of which the templates are enacted from the top to the bottom of the configuation file.)


The documentation for this class was generated from the following files: