bool FitsFile::HasGroups() { try { return GetKeywordValue("GROUPS") == "T"; } catch(FitsIOException &e) { return false; } }
int FitsFile::GetTableColumnIndex(const std::string &columnName) { int colCount = GetColumnCount(); for(int i=1;i<=colCount;++i) { std::stringstream s; s << "TTYPE" << i; if(GetKeywordValue(s.str()) == columnName) return i; } throw FitsIOException(std::string("Can not find column with name ") + columnName); }
bool FitsFile::HasGroupParameter(const std::string ¶meterName) { if(!HasGroups()) return false; int parameterCount = GetParameterCount(); for(int i=1;i<=parameterCount;++i) { std::stringstream s; s << "PTYPE" << i; if(GetKeywordValue(s.str()) == parameterName) return true; } return false; }
int FitsFile::GetGroupParameterIndex(const std::string ¶meterName) { if(!HasGroups()) throw FitsIOException("HDU has no groups"); int parameterCount = GetParameterCount(); for(int i=1;i<=parameterCount;++i) { std::stringstream s; s << "PTYPE" << i; if(GetKeywordValue(s.str()) == parameterName) return i-1; } throw FitsIOException(std::string("Can not find parameter with name ") + parameterName); }
bool FitsFile::HasTableColumn(const std::string &columnName, int& columnIndex) { int colCount = GetColumnCount(); for(int i=1;i<=colCount;++i) { std::stringstream s; s << "TTYPE" << i; if(GetKeywordValue(s.str()) == columnName) { columnIndex = i; return true; } } return false; }
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); } }
double FitsFile::GetDoubleKeywordValue(const std::string &keywordName) { return atof(GetKeywordValue(keywordName).c_str()); }
int FitsFile::GetIntKeywordValue(const std::string &keywordName) { return atoi(GetKeywordValue(keywordName).c_str()); }