source: Sophya/trunk/SophyaProg/PrgUtil/scanfits.cc@ 3606

Last change on this file since 3606 was 3572, checked in by cmv, 17 years ago

char* -> const char* pour regler les problemes de deprecated string const... + comparaison unsigned signed + suppression EVOL_PLANCK rz+cmv 07/02/2009

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