int main(int argc, char *argv[]) { fitsfile *fptr; /* pointer to the FITS file, defined in fitsio.h */ int status, nkeys, keypos, hdutype, ii, jj; char filename[FLEN_FILENAME]; /* input FITS file */ char card[FLEN_CARD]; /* standard string lengths defined in fitsioc.h */ status = 0; if (argc == 1) strcpy(filename, "-"); /* no command line name, so assume stdin */ else strcpy(filename, argv[1] ); /* name of file to list */ if ( fits_open_file(&fptr, filename, READONLY, &status) ) printerror( status ); /* get the current HDU number */ fits_get_hdu_num(fptr, &ii); /* attempt to move to next HDU, until we get an EOF error */ for (; !(fits_movabs_hdu(fptr, ii, &hdutype, &status) ); ii++) { /* get no. of keywords */ if (fits_get_hdrpos(fptr, &nkeys, &keypos, &status) ) printerror( status ); printf("Header listing for HDU #%d:\n", ii); for (jj = 1; jj <= nkeys; jj++) { if ( fits_read_record(fptr, jj, card, &status) ) printerror( status ); printf("%s\n", card); /* print the keyword card */ } printf("END\n\n"); /* terminate listing with END */ } if (status == END_OF_FILE) /* status values are defined in fitsio.h */ status = 0; /* got the expected EOF error; reset = 0 */ else printerror( status ); /* got an unexpected error */ if ( fits_close_file(fptr, &status) ) printerror( status ); return(0); }
void readheader( char *filename ) /**********************************************************************/ /* Print out all the header keywords in all extensions of a FITS file */ /**********************************************************************/ { fitsfile *fptr; /* pointer to the FITS file, defined in fitsio.h */ int status, nkeys, keypos, hdutype, ii, jj; char card[FLEN_CARD]; /* standard string lengths defined in fitsioc.h */ status = 0; if ( fits_open_file(&fptr, filename, READONLY, &status) ) printerror( status, __LINE__ ); /* attempt to move to next HDU, until we get an EOF error */ for (ii = 1; !(fits_movabs_hdu(fptr, ii, &hdutype, &status) ); ii++) { /* get no. of keywords */ if (fits_get_hdrpos(fptr, &nkeys, &keypos, &status) ) printerror( status, __LINE__ ); printf("Header listing for HDU #%d:\n", ii); for (jj = 1; jj <= nkeys; jj++) { if ( fits_read_record(fptr, jj, card, &status) ) printerror( status, __LINE__ ); printf("%s\n", card); /* print the keyword card */ } printf("END\n\n"); /* terminate listing with END */ } if (status == END_OF_FILE) /* status values are defined in fitsioc.h */ status = 0; /* got the expected EOF error; reset = 0 */ else printerror( status, __LINE__ ); /* got an unexpected error */ if ( fits_close_file(fptr, &status) ) printerror( status, __LINE__ ); return; }
void avtFITSFileFormat::Initialize(avtDatabaseMetaData *md) { const char *mName = "avtFITSFileFormat::Initialize: "; if(fits == 0) { debug4 << mName << "Opening " << filename << endl; int status = 0; if(fits_open_file(&fits, filename, 0, &status)) { PrintError(status); EXCEPTION1(InvalidFilesException, filename); } char card[FLEN_CARD], tmp[100]; std::string fileComment; int hdutype = 0; // Iterate over the HDU's for(int hdu = 1; !(fits_movabs_hdu(fits, hdu, &hdutype, &status)); hdu++) { debug4 << mName << "Looking at HDU " << hdu << endl; // Get no. of keywords int nkeys = 0, keypos = 0; if(fits_get_hdrpos(fits, &nkeys, &keypos, &status)) PrintError(status); if(hdutype == IMAGE_HDU) { debug4 << mName << "HDU " << hdu << " contains an image" << endl; //int status2 = 0; char value[FLEN_VALUE]; std::string objname, bunit, xlabel, ylabel, zlabel; // Try and get the key value for BUNIT if(GetKeywordValue("BUNIT", value)) { bunit = std::string(value); debug4 << "\tBUNIT=" << value << endl; } // Try and get the key value for OBJECT if(GetKeywordValue("OBJECT", value)) { objname = std::string(value); debug4 << "\tOBJECT=" << value << endl; } #if 0 // // Re-enable these someday when we read the mesh coordinates from the file // and use them to construct a sensible mesh. // // Try and get the key value for CTYPE1 if(GetKeywordValue("CTYPE1", value)) { xlabel = std::string(value); debug4 << "\tCTYPE1=" << value << endl; } // Try and get the key value for CTYPE2 if(GetKeywordValue("CTYPE2", value)) { ylabel = std::string(value); debug4 << "\tCTYPE2=" << value << endl; } // Try and get the key value for CTYPE3 if(GetKeywordValue("CTYPE3", value)) { zlabel = std::string(value); debug4 << "\tCTYPE3=" << value << endl; } #endif // Use the keywords to create a comment. SNPRINTF(tmp, 100, "Header listing for HDU #%d:\n", hdu); fileComment += tmp; for(int jj = 1; jj <= nkeys; jj++) { if(fits_read_record(fits, jj, card, &status)) PrintError(status); std::string cs(card); fileComment += cs; if(cs.size() > 0 && cs[cs.size()-1] != '\n') fileComment += "\n"; } fileComment += "\n\n"; // // Get the image's dimensions. // int ndims = 0; if(fits_get_img_dim(fits, &ndims, &status)) PrintError(status); debug4 << mName << "Num dimensions: " << ndims << ", status=" << status << endl; long *dims = new long[ndims]; if(fits_get_img_size(fits, ndims, dims, &status)) PrintError(status); if(ndims == 0) { debug4 << mName << "The image has no dimensions. Skip it." << endl; continue; } // // Create a mesh name for the image. // intVector mdims; std::string meshName("image"); debug4 << mName << "Image dimensions: "; bool dimensionsNonZero = false; for(int i = 0; i < ndims; ++i) { char num[20]; if(i > 0) SNPRINTF(num, 20, "x%d", (int)dims[i]); else SNPRINTF(num, 20, "%d", (int)dims[i]); meshName += num; mdims.push_back((int)dims[i]); dimensionsNonZero |= (dims[i] != 0); debug4 << dims[i] << ", "; } debug4 << endl; if(!dimensionsNonZero) { debug4 << mName << "All dimensions were zero. skip." << endl; continue; } if(ndims == 1 && objname != "") meshName = objname; if(meshDimensions.find(meshName) == meshDimensions.end()) { meshDimensions[meshName] = mdims; // Create metadata if necessary. if(md != 0) { if(ndims == 1) { debug4 << mName << "Adding a curve called " << meshName.c_str() << " for HDU " << hdu << endl; avtCurveMetaData *cmd = new avtCurveMetaData; cmd->name = meshName; if(xlabel != "") cmd->xLabel = xlabel; if(ylabel != "") cmd->yLabel = ylabel; md->Add(cmd); // Do this because we use GetVar to read the data // that we use to create the curve. varToHDU[meshName] = hdu; varToMesh[meshName] = meshName; } else { int sdims, tdims; int nrealdims = (ndims <= 3) ? ndims : 3; #define VECTOR_SUPPORT #ifdef VECTOR_SUPPORT if(nrealdims == 3 && dims[2] == 3) nrealdims = 2; #endif sdims = tdims = nrealdims; debug4 << mName << "Adding a " << sdims << " dimensional mesh called " << meshName.c_str() << " for HDU " << hdu << endl; avtMeshMetaData *mmd = new avtMeshMetaData( meshName, 1, 1, 1, 0, sdims, tdims, AVT_RECTILINEAR_MESH); if(xlabel != "") mmd->xLabel = xlabel; if(ylabel != "") mmd->yLabel = ylabel; if(zlabel != "") mmd->zLabel = zlabel; md->Add(mmd); } } } // // Create a name for the variable at this HDU // if(ndims > 1) { char varname[100]; SNPRINTF(varname, 100, "hdu%d", hdu); std::string vName(varname); if(objname != "") vName = objname; varToHDU[vName] = hdu; varToMesh[vName] = meshName; // Create metadata if necessary if(md != 0) { #ifdef VECTOR_SUPPORT // Limit the dimensions to 3. int ncomps = 1; int nrealdims = (ndims <= 3) ? ndims : 3; if(nrealdims == 3 && dims[2] == 3) ncomps = 3; if(ncomps == 1) { #endif debug4 << mName << "Adding a scalar called " << vName.c_str() << " for HDU " << hdu << endl; // Add the scalar metadata avtScalarMetaData *smd = new avtScalarMetaData( vName, meshName, AVT_ZONECENT); smd->hasUnits = bunit != ""; smd->units = bunit; md->Add(smd); #ifdef VECTOR_SUPPORT } else { debug4 << mName << "Adding a color vector called " << vName.c_str() << " for HDU " << hdu << endl; // Add the vector metadata avtVectorMetaData *vmd = new avtVectorMetaData( vName, meshName, AVT_ZONECENT, 4); // vmd->hasUnits = true; // vmd->units = md->Add(vmd); } #endif } } delete [] dims; } else if(hdutype == ASCII_TBL) { debug4 << mName << "HDU " << hdu << " contains an ascii table" << endl; } else if(hdutype == BINARY_TBL) { debug4 << mName << "HDU " << hdu << " contains a binary table" << endl; // Use the keywords to create a comment. SNPRINTF(tmp, 100, "Header listing for HDU #%d:\n", hdu); debug4 << tmp; for(int jj = 1; jj <= nkeys; jj++) { if(fits_read_record(fits, jj, card, &status)) PrintError(status); std::string cs(card); if(cs.size() > 0 && cs[cs.size()-1] != '\n') cs += "\n"; debug4 << "\t" << cs.c_str(); } } } if(md != 0) md->SetDatabaseComment(fileComment); } }
//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TForm1::BAbrirClick(TObject *Sender) { fitsfile *fptr = 0; /* pointer to the FITS file, defined in fitsio.h */ int status, nkeys, keypos, hdutype, ii, jj; char filename[FLEN_FILENAME]; /* input FITS file */ char card[FLEN_CARD]; /* standard string lengths defined in fitsioc.h */ char aux[300]; int ejes = 0; long ajes[4] = {0,0,0,0}; int tipo; if(fptr != 0) { status = 0; if ( fits_close_file(fptr, &status) ) { printerror( status ); return; } } if(OD1->Execute()) { status = 0; if ( fits_open_file(&fptr, OD1->FileName.c_str(), READWRITE, &status) ) { printerror(status); return; } } else return; fits_get_hdu_num(fptr, &ii); // get the current HDU number Memo1->Lines->Add("HDU NUMBER: " + AnsiString(ii)); // attempt to move to next HDU, until we get an EOF error status = 0; for (; !(fits_movabs_hdu(fptr, ii, &hdutype, &status) ); ii++) { status = 0; if (fits_get_hdrpos(fptr, &nkeys, &keypos, &status) )// get no. of keywords { printerror( status ); return; } wsprintf(aux, "Header listing for HDU #%d:", ii); Memo1->Lines->Add(aux); for (jj = 1; jj <= nkeys; jj++) { status = 0; if ( fits_read_record(fptr, jj, card, &status) ) { printerror( status ); return; } Memo1->Lines->Add(card); // print the keyword card } printf("END\n\n"); /* terminate listing with END */ } if (status == END_OF_FILE) /* status values are defined in fitsio.h */ status = 0; /* got the expected EOF error; reset = 0 */ else { printerror( status ); /* got an unexpected error */ return; } status = 0; if(ffgipr(fptr, 2, &tipo, &ejes, ajes, &status)) { printerror( status ); return; } Memo1->Lines->Add("------"); Memo1->Lines->Add("Tipo : " + AnsiString(tipo)); Memo1->Lines->Add("EJES : " + AnsiString(ejes)); Memo1->Lines->Add("AJES0: " + AnsiString(ajes[0])); Memo1->Lines->Add("AJES1: " + AnsiString(ajes[1])); ejex = ajes[0]; ejey = ajes[1]; ////////////////////////////////////////////////////// NumeroColumnas = ejex/* / Binin*/; NumeroFilas = ejey /*/ Binin*/; X1 = X1F = 0; Y1 = Y1F = 0; X2 = X2F = NumeroColumnas; Y2 = Y2F = NumeroFilas; PB1->Width = X2 + 4; PB1->Height = Y2 + 4; PX1->Caption = X1; PX2->Caption = X2; PY1->Caption = Y1; PY2->Caption = Y2; PFil->Caption = NumeroFilas; PCol->Caption = NumeroColumnas; delete BM1; BM1 = new Graphics::TBitmap(); BM1->Height = NumeroFilas; BM1->Width = NumeroColumnas; BM1->PixelFormat = pf8bit; BM1->Palette = CreatePalette(&SysPal.lpal); for (int y = 0; y < NumeroFilas; y++) { for (int x = 0; x < NumeroColumnas; x++) { Foto[y][x] = 0; } } long primer_elemento = 1; long numelem = ejex*ejey; int cualquiernull = 0; Byte *ptr; short sust = 0; unsigned short *datos; datos = new unsigned short [ejex*ejey]; memset(datos, 0, ejex*ejey*2); status = 0; if(fits_read_img(fptr, TSHORT, primer_elemento, numelem, &sust, //valor por el que se sustituira los indefinidos &datos[primer_elemento], &cualquiernull, // 1 si hay alguna sustitucion &status)) { printerror( status ); } long n = numelem; for(int py = 0; py < ejey; py++) { for (int px = ejex; px > 0; px--) { Foto[py][px] = datos[n--]; } } delete datos; PB1->Repaint(); }