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