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