| 1 | #include <stdio.h> | 
|---|
| 2 | #include <stdlib.h> | 
|---|
| 3 | #include <string.h> | 
|---|
| 4 | #include <math.h> | 
|---|
| 5 | #include <iostream> | 
|---|
| 6 |  | 
|---|
| 7 | #include "sopnamsp.h" | 
|---|
| 8 |  | 
|---|
| 9 | #include "fitsfile.h" | 
|---|
| 10 | #include "fitsmanager.h" | 
|---|
| 11 | #include "fiosinit.h" | 
|---|
| 12 | /* | 
|---|
| 13 | #include "histinit.h" | 
|---|
| 14 | #include "dvlist.h" | 
|---|
| 15 | #include "ntuple.h" | 
|---|
| 16 | #include "fitsntuple.h" | 
|---|
| 17 | */ | 
|---|
| 18 | /*! | 
|---|
| 19 | \ingroup PrgUtil | 
|---|
| 20 | \file scanfits.cc | 
|---|
| 21 | \brief \b scanfits: Check and scan FITS files | 
|---|
| 22 |  | 
|---|
| 23 | Scan FITS files and prints information on each FITS bloc in file. | 
|---|
| 24 | Uses the FitsIOServer module. | 
|---|
| 25 |  | 
|---|
| 26 | \verbatim | 
|---|
| 27 | csh> scanfits -h | 
|---|
| 28 | PIOPersist::Initialize() Starting Sophya Persistence management service | 
|---|
| 29 | SOPHYA Version  1.9 Revision 25 (V_Dec2005) -- Jan  4 2006 14:50:01 cxx | 
|---|
| 30 | Usage: scanfits [flags] filename | 
|---|
| 31 | flags = -V1 -lh -rd -header | 
|---|
| 32 | -V1 : Scan using old (V1) code version | 
|---|
| 33 | -lh : Print the list of registered handlers (FitsHandlerInterface) | 
|---|
| 34 | -rd : try to read each HDU data using appropriate handler | 
|---|
| 35 | -header : List header information | 
|---|
| 36 | \endverbatim | 
|---|
| 37 | */ | 
|---|
| 38 |  | 
|---|
| 39 | string FITSExtType2String(FitsFile::FitsExtensionType exttype) | 
|---|
| 40 | { | 
|---|
| 41 | if (exttype == FitsFile::FitsExtensionType_IMAGE) return("IMAGE"); | 
|---|
| 42 | else if (exttype == FitsFile::FitsExtensionType_ASCII_TBL) return("ASCII_TBL"); | 
|---|
| 43 | else if (exttype == FitsFile::FitsExtensionType_BINARY_TBL) return("BINARY_TBL"); | 
|---|
| 44 | else if (exttype == FitsFile::FitsExtensionType_EOF) return("EOF"); | 
|---|
| 45 | else if (exttype == FitsFile::FitsExtensionType_ERROR) return("ERROR"); | 
|---|
| 46 | else return("Unknown?"); | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | string FITSDataType2String(FitsFile::FitsDataType datatype) | 
|---|
| 50 | { | 
|---|
| 51 | if (datatype == FitsFile::FitsDataType_double) return("double"); | 
|---|
| 52 | else if (datatype == FitsFile::FitsDataType_float) return("float"); | 
|---|
| 53 | else if (datatype == FitsFile::FitsDataType_int) return("int"); | 
|---|
| 54 | else if (datatype == FitsFile::FitsDataType_long) return("long"); | 
|---|
| 55 | else if (datatype == FitsFile::FitsDataType_byte) return("byte"); | 
|---|
| 56 | else if (datatype == FitsFile::FitsDataType_char) return("char"); | 
|---|
| 57 | else if (datatype == FitsFile::FitsDataType_ASCII) return("ASCII"); | 
|---|
| 58 | else if (datatype == FitsFile::FitsDataType_NULL) return("NULL"); | 
|---|
| 59 | else return("Unknown?"); | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | static int scanV1(string & flnm) | 
|---|
| 63 | { | 
|---|
| 64 | char * argnm = new char[ flnm.length()+1 ]; | 
|---|
| 65 | strcpy(argnm, flnm.c_str()); | 
|---|
| 66 | int nbblk = FitsInFile::NbBlocks(argnm); | 
|---|
| 67 | cout << " :::::::: File " << flnm << " has " << nbblk << " blocks " | 
|---|
| 68 | << " :::::::: " << endl; | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | for(int i=1; i<=nbblk; i++) { | 
|---|
| 72 | int naxis; | 
|---|
| 73 | vector<int> axis; | 
|---|
| 74 | DVList header; | 
|---|
| 75 | FitsFile::FitsExtensionType exttype; | 
|---|
| 76 | FitsFile::FitsDataType datatype; | 
|---|
| 77 |  | 
|---|
| 78 | FitsInFile::GetBlockType(argnm, i, exttype, naxis, axis, datatype, header); | 
|---|
| 79 | cout << "\n--------- Header Num " << i << " Type " << FITSExtType2String(exttype) | 
|---|
| 80 | << "  --- NAxis= " << naxis | 
|---|
| 81 | << " DataType= " << FITSDataType2String(datatype) << endl; | 
|---|
| 82 | if (axis.size() > 0) { | 
|---|
| 83 | cout << " >> Axis Sizes: " ; | 
|---|
| 84 | for(int j=0; j<axis.size(); j++) { | 
|---|
| 85 | if (j > 0) cout << " x " ; | 
|---|
| 86 | cout  << axis[j] ; | 
|---|
| 87 | } | 
|---|
| 88 | cout << endl; | 
|---|
| 89 | } | 
|---|
| 90 | cout << " >>> Header info : " ; | 
|---|
| 91 | cout << header << endl; | 
|---|
| 92 | cout << "----------------------------------------------------------------------" | 
|---|
| 93 | << endl; | 
|---|
| 94 | } | 
|---|
| 95 | delete[] argnm; | 
|---|
| 96 | return 0; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | int main(int narg, char *arg[]) | 
|---|
| 100 | { | 
|---|
| 101 | if ((narg < 2) || (strcmp(arg[1],"-h") == 0) ) { | 
|---|
| 102 | cout << " Usage: scanfits [flags] filename \n" | 
|---|
| 103 | << " flags = -V1 -lh -rd -header \n" | 
|---|
| 104 | << "   -V1 : Scan using old (V1) code version \n" | 
|---|
| 105 | << "   -lh : Print the list of registered handlers (FitsHandlerInterface) \n" | 
|---|
| 106 | << "   -rd : try to read each HDU data using appropriate handler \n" | 
|---|
| 107 | << "   -header : List header information \n" << endl; | 
|---|
| 108 | return(0); | 
|---|
| 109 | } | 
|---|
| 110 | bool fgv1 = false; | 
|---|
| 111 | bool fgrd = false; | 
|---|
| 112 | bool fglh = false; | 
|---|
| 113 | bool fghd = false; | 
|---|
| 114 | bool fgflnm = false; | 
|---|
| 115 | string flnm = ""; | 
|---|
| 116 | for (int k=1; k<narg; k++)   { | 
|---|
| 117 | if (strcmp(arg[k], "-V1") == 0)  fgv1 = true; | 
|---|
| 118 | else if (strcmp(arg[k], "-rd") == 0)  fgrd = true; | 
|---|
| 119 | else if (strcmp(arg[k], "-lh") == 0)  fglh = true; | 
|---|
| 120 | else if (strcmp(arg[k], "-header") == 0)  fghd = true; | 
|---|
| 121 | else { | 
|---|
| 122 | fgflnm = true; flnm = arg[k]; | 
|---|
| 123 | break; | 
|---|
| 124 | } | 
|---|
| 125 | } | 
|---|
| 126 | int slev = 0; | 
|---|
| 127 | if ( fgrd ) slev = 2; | 
|---|
| 128 | if ( fghd ) slev += 1; | 
|---|
| 129 | if (!fglh && !fgflnm) { | 
|---|
| 130 | cout << " scanfits/Erreur : no file name specified and no -lh " << endl; | 
|---|
| 131 | return 1; | 
|---|
| 132 | } | 
|---|
| 133 | try { | 
|---|
| 134 | SophyaInit(); | 
|---|
| 135 | FitsIOServerInit(); | 
|---|
| 136 | cout << " ====== scanfits: FileName= " << flnm << " ==== " << endl; | 
|---|
| 137 | if ( fglh ) FitsManager::ListHandlers(); | 
|---|
| 138 | if ( fgflnm ) { | 
|---|
| 139 | if ( fgv1 ) scanV1(flnm); | 
|---|
| 140 | else FitsManager::ScanFile(flnm, slev); | 
|---|
| 141 | } | 
|---|
| 142 | } | 
|---|
| 143 | catch (PThrowable & exc) { | 
|---|
| 144 | cerr << "sanfits: Catched Exception " << (string)typeid(exc).name() | 
|---|
| 145 | << "\n .... Msg= " << exc.Msg() << endl; | 
|---|
| 146 | } | 
|---|
| 147 | catch (...) { | 
|---|
| 148 | cerr << " some other exception was caught ! " << endl; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | } | 
|---|