IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 27, 2019, 11:39:38 AM (7 years ago)
Author:
eugene
Message:

merge changes from trunk (mostly Ohana & ippMonitor improvements, some work on ippTools)

Location:
branches/eam_branches/ipp-20191011
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20191011

  • branches/eam_branches/ipp-20191011/Ohana

  • branches/eam_branches/ipp-20191011/Ohana/src/opihi/lib.shell/VectorIO.c

    r41136 r41170  
    162162}
    163163
     164// insert a new header line, return end pointer
     165char *gfits_insert_header_line (Header *header, char *endptr, char *newline) {
     166
     167  if (0) {
     168    char temp1[32], temp2[32];
     169    memset (temp1, 0, 32);
     170    memset (temp2, 0, 32);
     171
     172    if (endptr) {
     173      memcpy (temp1, endptr, 8);
     174    }
     175    memcpy (temp2, newline, 8);
     176    fprintf (stderr, "insert: %s : %s\n", temp1, temp2);
     177  }
     178
     179  /* find the END of the header, if not supplied */
     180  if (!endptr) {
     181    endptr = gfits_header_field (header, "END", 1);
     182    if (endptr == NULL) return NULL;
     183  }
     184
     185  /* is there enough space for 1 more line? */
     186  if (header[0].datasize - (endptr - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
     187    // no, so expand by a full header block (FT_RECORD_SIZE = 32*80 = 2880)
     188    header[0].datasize += FT_RECORD_SIZE;
     189    REALLOCATE (header[0].buffer, char, header[0].datasize);
     190    // re-find the "END" marker, in case new memory block is used
     191    endptr = gfits_header_field (header, "END", 1);
     192    if (endptr == NULL) return NULL;
     193    memset (endptr + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE);
     194  }
     195
     196  /* push END line back 1 */
     197  memmove ((endptr + FT_LINE_LENGTH), endptr, FT_LINE_LENGTH);
     198  memset (endptr, ' ', FT_LINE_LENGTH);
     199
     200  strncpy (endptr, newline, 80);
     201  endptr += FT_LINE_LENGTH;
     202
     203  return endptr;
     204}
     205 
     206static char *rawkeywords[] = {"SIMPLE", "BITPIX", "NAXIS", "PCOUNT", "GCOUNT", "EXTEND", "EXTNAME", "BSCALE", "BZERO", "TFIELDS", "TFORM", "TZERO", "TSCAL", "        ", NULL};
     207
    164208// write a set of vectors to a FITS file (vectors names become fits column names)
    165 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile) {
     209int WriteVectorTableFITS (char *filename, char *extname, Header *extraheader, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile) {
    166210 
    167211  Header rawheader;
     
    191235  rawtable.header = &rawheader;
    192236  if (!WriteVectorTable (&rawtable, extname, vec, Nvec, format, (compress != NULL))) goto escape;
    193   // NOTE : for compression, the table is constructed in native by order
     237  // NOTE : for compression, the table is constructed in native byte order
    194238
    195239  FTable *outtable = &rawtable;
     
    215259
    216260  if (!append) {
     261    // generate a blank PHU header
    217262    Header header;
    218263    Matrix matrix;
     
    228273  }
    229274
     275  if (extraheader) {
     276    // copy keywords which are not the standard or table keywords
     277    char *buf = extraheader->buffer;
     278    char *endptr = NULL;
     279    for (int i = 0; i < extraheader->datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
     280
     281      if (0) {
     282        char temp1[32];
     283        memset (temp1, 0, 32);
     284        memcpy (temp1, buf, 8);
     285        fprintf (stderr, "buffer: %s\n", temp1);
     286      }
     287
     288      for (int j = 0; rawkeywords[j] != NULL; j++) {
     289        if (!strncmp (buf, rawkeywords[j], strlen(rawkeywords[j]))) goto skip_insert;
     290      }
     291      endptr = gfits_insert_header_line (outheader, endptr, buf);
     292      if (!endptr) {
     293        gprint (GP_ERR, "failed to update FITS header with extra keywords\n");
     294        return (FALSE);
     295      }
     296    skip_insert:
     297      continue;
     298    }
     299  }
     300
    230301  // write the actual table data
    231302  gfits_fwrite_Theader (f, outheader);
Note: See TracChangeset for help on using the changeset viewer.