- Timestamp:
- Nov 27, 2019, 11:39:38 AM (7 years ago)
- Location:
- branches/eam_branches/ipp-20191011
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20191011
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20191011/Ohana
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20191011/Ohana/src/opihi/lib.shell/VectorIO.c
r41136 r41170 162 162 } 163 163 164 // insert a new header line, return end pointer 165 char *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 206 static char *rawkeywords[] = {"SIMPLE", "BITPIX", "NAXIS", "PCOUNT", "GCOUNT", "EXTEND", "EXTNAME", "BSCALE", "BZERO", "TFIELDS", "TFORM", "TZERO", "TSCAL", " ", NULL}; 207 164 208 // 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) {209 int WriteVectorTableFITS (char *filename, char *extname, Header *extraheader, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile) { 166 210 167 211 Header rawheader; … … 191 235 rawtable.header = &rawheader; 192 236 if (!WriteVectorTable (&rawtable, extname, vec, Nvec, format, (compress != NULL))) goto escape; 193 // NOTE : for compression, the table is constructed in native by order237 // NOTE : for compression, the table is constructed in native byte order 194 238 195 239 FTable *outtable = &rawtable; … … 215 259 216 260 if (!append) { 261 // generate a blank PHU header 217 262 Header header; 218 263 Matrix matrix; … … 228 273 } 229 274 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 230 301 // write the actual table data 231 302 gfits_fwrite_Theader (f, outheader);
Note:
See TracChangeset
for help on using the changeset viewer.
