int psrfits_remove_ephem(struct psrfits *pf) { // Delete the ephemeris table int *status = &(pf->status); // Save current HDU, move to polyco table int hdu; fits_get_hdu_num(pf->fptr, &hdu); fits_movnam_hdu(pf->fptr, BINARY_TBL, "PSREPHEM", 0, status); // Delete it fits_delete_hdu(pf->fptr, NULL, status); // Go to the SUBINT HDU fits_movnam_hdu(pf->fptr, BINARY_TBL, "SUBINT", 0, status); return *status; }
static void fits_hdu_remove(struct fitsparams *p, int *r) { char *hdu; fitsfile *fptr; int status=0, hdutype; while(p->remove) { /* Pop-out the top element. */ hdu=gal_list_str_pop(&p->remove); /* Open the FITS file at the specified HDU. */ fptr=gal_fits_hdu_open(p->filename, hdu, READWRITE); /* Delete the extension. */ if( fits_delete_hdu(fptr, &hdutype, &status) ) *r=fits_has_error(p, FITS_ACTION_REMOVE, hdu, status); /* Close the file. */ fits_close_file(fptr, &status); } }
static void fits_hdu_copy(struct fitsparams *p, int cut1_copy0, int *r) { char *hdu; fitsfile *in, *out; int status=0, hdutype; gal_list_str_t *list = cut1_copy0 ? p->cut : p->copy; /* Open the output file. */ out=gal_fits_open_to_write(p->cp.output); /* Copy all the given extensions. */ while(list) { /* Pop-out the top element. */ hdu=gal_list_str_pop(&list); /* Open the FITS file at the specified HDU. */ in=gal_fits_hdu_open(p->filename, hdu, cut1_copy0 ? READWRITE : READONLY); /* Copy to the extension. */ if( fits_copy_hdu(in, out, 0, &status) ) *r=fits_has_error(p, FITS_ACTION_COPY, hdu, status); /* If this is a `cut' operation, then remove the extension. */ if(cut1_copy0) if( fits_delete_hdu(in, &hdutype, &status) ) *r=fits_has_error(p, FITS_ACTION_REMOVE, hdu, status); /* Close the input file. */ fits_close_file(in, &status); } /* Close the output file. */ fits_close_file(out, &status); }
int ngp_read_xtension(fitsfile *ff, int parent_hn, int simple_mode) { int r, exflg, l, my_hn, tmp0, incrementor_index, i, j; int ngph_dim, ngph_bitpix, ngph_node_type, my_version; char incrementor_name[NGP_MAX_STRING], ngph_ctmp; char *ngph_extname = 0; long ngph_size[NGP_MAX_ARRAY_DIM]; NGP_HDU ngph; long lv; incrementor_name[0] = 0; /* signal no keyword+'#' found yet */ incrementor_index = 0; if (NGP_OK != (r = ngp_hdu_init(&ngph))) return(r); if (NGP_OK != (r = ngp_read_line(0))) return(r); /* EOF always means error here */ switch (NGP_XTENSION_SIMPLE & simple_mode) { case 0: if (NGP_TOKEN_XTENSION != ngp_keyidx) return(NGP_TOKEN_NOT_EXPECT); break; default: if (NGP_TOKEN_SIMPLE != ngp_keyidx) return(NGP_TOKEN_NOT_EXPECT); break; } if (NGP_OK != (r = ngp_hdu_insert_token(&ngph, &ngp_linkey))) return(r); for (;;) { if (NGP_OK != (r = ngp_read_line(0))) return(r); /* EOF always means error here */ exflg = 0; switch (ngp_keyidx) { case NGP_TOKEN_SIMPLE: r = NGP_TOKEN_NOT_EXPECT; break; case NGP_TOKEN_END: case NGP_TOKEN_XTENSION: case NGP_TOKEN_GROUP: r = ngp_unread_line(); /* WARNING - not break here .... */ case NGP_TOKEN_EOF: exflg = 1; break; default: l = strlen(ngp_linkey.name); if ((l >= 2) && (l <= 6)) { if ('#' == ngp_linkey.name[l - 1]) { if (0 == incrementor_name[0]) { memcpy(incrementor_name, ngp_linkey.name, l - 1); incrementor_name[l - 1] = 0; } if (((l - 1) == (int)strlen(incrementor_name)) && (0 == memcmp(incrementor_name, ngp_linkey.name, l - 1))) { incrementor_index++; } sprintf(ngp_linkey.name + l - 1, "%d", incrementor_index); } } r = ngp_hdu_insert_token(&ngph, &ngp_linkey); break; } if ((NGP_OK != r) || exflg) break; } if (NGP_OK == r) { /* we should scan keywords, and calculate HDU's */ /* structure ourselves .... */ ngph_node_type = NGP_NODE_INVALID; /* init variables */ ngph_bitpix = 0; ngph_extname = NULL; for (i=0; i<NGP_MAX_ARRAY_DIM; i++) ngph_size[i] = 0; ngph_dim = 0; for (i=0; i<ngph.tokcnt; i++) { if (!strcmp("XTENSION", ngph.tok[i].name)) { if (NGP_TTYPE_STRING == ngph.tok[i].type) { if (!ngp_strcasencmp("BINTABLE", ngph.tok[i].value.s,8)) ngph_node_type = NGP_NODE_BTABLE; if (!ngp_strcasencmp("TABLE", ngph.tok[i].value.s,5)) ngph_node_type = NGP_NODE_ATABLE; if (!ngp_strcasencmp("IMAGE", ngph.tok[i].value.s,5)) ngph_node_type = NGP_NODE_IMAGE; } } else if (!strcmp("SIMPLE", ngph.tok[i].name)) { if (NGP_TTYPE_BOOL == ngph.tok[i].type) { if (ngph.tok[i].value.b) ngph_node_type = NGP_NODE_IMAGE; } } else if (!strcmp("BITPIX", ngph.tok[i].name)) { if (NGP_TTYPE_INT == ngph.tok[i].type) ngph_bitpix = ngph.tok[i].value.i; } else if (!strcmp("NAXIS", ngph.tok[i].name)) { if (NGP_TTYPE_INT == ngph.tok[i].type) ngph_dim = ngph.tok[i].value.i; } else if (!strcmp("EXTNAME", ngph.tok[i].name)) /* assign EXTNAME, I hope struct does not move */ { if (NGP_TTYPE_STRING == ngph.tok[i].type) ngph_extname = ngph.tok[i].value.s; } else if (1 == sscanf(ngph.tok[i].name, "NAXIS%d%c", &j, &ngph_ctmp)) { if (NGP_TTYPE_INT == ngph.tok[i].type) if ((j>=1) && (j <= NGP_MAX_ARRAY_DIM)) { ngph_size[j - 1] = ngph.tok[i].value.i; } } } switch (ngph_node_type) { case NGP_NODE_IMAGE: if (NGP_XTENSION_FIRST == ((NGP_XTENSION_FIRST | NGP_XTENSION_SIMPLE) & simple_mode)) { /* if caller signals that this is 1st HDU in file */ /* and it is IMAGE defined with XTENSION, then we */ /* need create dummy Primary HDU */ fits_create_img(ff, 16, 0, NULL, &r); } /* create image */ fits_create_img(ff, ngph_bitpix, ngph_dim, ngph_size, &r); /* update keywords */ if (NGP_OK == r) r = ngp_keyword_all_write(&ngph, ff, NGP_NON_SYSTEM_ONLY); break; case NGP_NODE_ATABLE: case NGP_NODE_BTABLE: /* create table, 0 rows and 0 columns for the moment */ fits_create_tbl(ff, ((NGP_NODE_ATABLE == ngph_node_type) ? ASCII_TBL : BINARY_TBL), 0, 0, NULL, NULL, NULL, NULL, &r); if (NGP_OK != r) break; /* add columns ... */ r = ngp_append_columns(ff, &ngph, 0); if (NGP_OK != r) break; /* add remaining keywords */ r = ngp_keyword_all_write(&ngph, ff, NGP_NON_SYSTEM_ONLY); if (NGP_OK != r) break; /* if requested add rows */ if (ngph_size[1] > 0) fits_insert_rows(ff, 0, ngph_size[1], &r); break; default: r = NGP_BAD_ARG; break; } } if ((NGP_OK == r) && (NULL != ngph_extname)) { r = ngp_get_extver(ngph_extname, &my_version); /* write correct ext version number */ lv = my_version; /* bugfix - 22-Jan-99, BO - nonalignment of OSF/Alpha */ fits_write_key(ff, TLONG, "EXTVER", &lv, "auto assigned by template parser", &r); } if (NGP_OK == r) { if (parent_hn > 0) { fits_get_hdu_num(ff, &my_hn); fits_movabs_hdu(ff, parent_hn, &tmp0, &r); /* link us to parent */ fits_add_group_member(ff, NULL, my_hn, &r); fits_movabs_hdu(ff, my_hn, &tmp0, &r); if (NGP_OK != r) return(r); } } if (NGP_OK != r) /* in case of error - delete hdu */ { tmp0 = 0; fits_delete_hdu(ff, NULL, &tmp0); } ngp_hdu_clear(&ngph); return(r); }