Changeset 2899 in Sophya for trunk/SophyaProg/PrgUtil


Ignore:
Timestamp:
Jan 13, 2006, 7:27:25 PM (20 years ago)
Author:
ansari
Message:

Amelioration programme scanfits/ appel a FitsManager::ScanFile() - Reza 13/01/2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/PrgUtil/scanfits.cc

    r2615 r2899  
    55
    66#include "sopnamsp.h"
     7
     8#include "fitsfile.h"
     9#include "fitsmanager.h"
     10#include "fiosinit.h"
     11/*
    712#include "histinit.h"
    813#include "dvlist.h"
     
    1116#include "fitsxntuple.h"
    1217#include "fitsntuple.h"
    13 
     18*/
    1419/*!
    1520  \ingroup PrgUtil
     
    4853}
    4954
    50 int main(int narg, char *arg[])
     55static int scanV1(string & flnm)
    5156{
    52   if (narg < 2) {
    53     cerr << "scanfits/Erreur arg - Usage scanfits nomfits \n" << endl;
    54     exit(0);
     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
     92int 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);
     102  }
     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;
    55125  }
    56126  try {
    57127    SophyaInit();
    58     string flnm = arg[1];
    59     int nbblk = FitsInFile::NbBlocks(arg[1]);
    60     cout << " :::::::: File " << flnm << " has " << nbblk << " blocks "
    61          << " :::::::: " << endl;
    62 
    63     //    cout << " FitsFile::FitsExtensionType : FitsExtensionType_IMAGE= " <<
    64     //      (int)FitsFile::FitsExtensionType_IMAGE <<
    65     //      "  FitsExtensionType_ASCII_TBL= " << (int)FitsFile::FitsExtensionType_ASCII_TBL <<
    66     //      "  FitsExtensionType_BINARY_TBL= " << (int)FitsFile::FitsExtensionType_BINARY_TBL << endl;
    67     //    cout << " FitsFile::FitsDataType: FitsDataType_double= " <<
    68     //      (int)FitsFile::FitsDataType_double <<
    69     //      " FitsDataType_float= " << (int)FitsFile::FitsDataType_float <<
    70     //      " FitsDataType_int= " << (int)FitsFile::FitsDataType_int <<
    71     //      " FitsDataType_char= " << (int)FitsFile::FitsDataType_char <<
    72     //      " FitsDataType_ASCII= " << (int)FitsFile::FitsDataType_ASCII << endl << endl;
    73 
    74     for(int i=1; i<=nbblk; i++) {
    75       int naxis;
    76       vector<int> axis;
    77       DVList header;
    78       FitsFile::FitsExtensionType exttype;
    79       FitsFile::FitsDataType datatype;
    80 
    81       FitsInFile::GetBlockType(arg[1], i, exttype, naxis, axis, datatype, header);
    82       cout << "\n--------- Header Num " << i << " Type " << FITSExtType2String(exttype)
    83            << "  --- NAxis= " << naxis
    84            << " DataType= " << FITSDataType2String(datatype) << endl;
    85       if (axis.size() > 0) {
    86         cout << " >> Axis Sizes: " ;
    87         for(int j=0; j<axis.size(); j++) {
    88           if (j > 0) cout << " x " ;
    89           cout  << axis[j] ;
    90         }
    91         cout << endl;
    92       }
    93       cout << " >>> Header info : " ;
    94       cout << header << endl;
    95       cout << "----------------------------------------------------------------------"
    96            << endl;
    97     }
    98  
     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    }
    99135  }
    100136  catch (PThrowable & exc) {
Note: See TracChangeset for help on using the changeset viewer.