Index: /trunk/SophyaProg/PrgUtil/scanfits.cc
===================================================================
--- /trunk/SophyaProg/PrgUtil/scanfits.cc	(revision 2898)
+++ /trunk/SophyaProg/PrgUtil/scanfits.cc	(revision 2899)
@@ -5,4 +5,9 @@
 
 #include "sopnamsp.h"
+
+#include "fitsfile.h"
+#include "fitsmanager.h"
+#include "fiosinit.h"
+/*
 #include "histinit.h"
 #include "dvlist.h"
@@ -11,5 +16,5 @@
 #include "fitsxntuple.h"
 #include "fitsntuple.h"
-
+*/
 /*!
   \ingroup PrgUtil
@@ -48,53 +53,84 @@
 }
 
-int main(int narg, char *arg[])
+static int scanV1(string & flnm) 
 {
-  if (narg < 2) {
-    cerr << "scanfits/Erreur arg - Usage scanfits nomfits \n" << endl;
-    exit(0);
+  char * argnm = new char[ flnm.length()+1 ];
+  strcpy(argnm, flnm.c_str());
+  int nbblk = FitsInFile::NbBlocks(argnm);
+  cout << " :::::::: File " << flnm << " has " << nbblk << " blocks " 
+       << " :::::::: " << endl;
+  
+  
+  for(int i=1; i<=nbblk; i++) {
+    int naxis;
+    vector<int> axis;
+    DVList header;
+    FitsFile::FitsExtensionType exttype;
+    FitsFile::FitsDataType datatype;
+    
+    FitsInFile::GetBlockType(argnm, i, exttype, naxis, axis, datatype, header);
+    cout << "\n--------- Header Num " << i << " Type " << FITSExtType2String(exttype) 
+	 << "  --- NAxis= " << naxis 
+	 << " DataType= " << FITSDataType2String(datatype) << endl;
+    if (axis.size() > 0) { 
+      cout << " >> Axis Sizes: " ;
+      for(int j=0; j<axis.size(); j++) { 
+	if (j > 0) cout << " x " ;
+	cout  << axis[j] ;
+      }
+      cout << endl;
+    }
+    cout << " >>> Header info : " ;
+    cout << header << endl;
+    cout << "----------------------------------------------------------------------" 
+	 << endl;
+  } 
+  delete[] argnm;
+  return 0;
+}
+
+int main(int narg, char *arg[]) 
+{
+  if ((narg < 2) || (strcmp(arg[1],"-h") == 0) ) {
+    cout << " Usage: scanfits [flags] filename \n" 
+	 << " flags = -V1 -lh -rd -header \n"
+	 << "   -V1 : Scan using old (V1) code version \n"  
+	 << "   -rd : try to read each HDU data using appropriate handler \n" 
+	 << "   -rd : try to read each HDU data using appropriate handler \n" 
+	 << "   -header : List header information \n" << endl;
+    return(0);
+  }
+  bool fgv1 = false;
+  bool fgrd = false;
+  bool fglh = false;
+  bool fghd = false;
+  bool fgflnm = false;
+  string flnm = "";
+  for (int k=1; k<narg; k++)   {
+    if (strcmp(arg[k], "-V1") == 0)  fgv1 = true;
+    else if (strcmp(arg[k], "-rd") == 0)  fgrd = true;
+    else if (strcmp(arg[k], "-lh") == 0)  fglh = true;
+    else if (strcmp(arg[k], "-header") == 0)  fghd = true;
+    else { 
+      fgflnm = true; flnm = arg[k]; 
+      break; 
+    }
+  }
+  int slev = 0;
+  if ( fgrd ) slev = 2;
+  if ( fghd ) slev += 1;
+  if (!fglh && !fgflnm) {
+    cout << " scanfits/Erreur : no file name specified and no -lh " << endl;
+    return 1;
   }
   try {
     SophyaInit();
-    string flnm = arg[1];
-    int nbblk = FitsInFile::NbBlocks(arg[1]);
-    cout << " :::::::: File " << flnm << " has " << nbblk << " blocks " 
-	 << " :::::::: " << endl;
-
-    //    cout << " FitsFile::FitsExtensionType : FitsExtensionType_IMAGE= " <<
-    //      (int)FitsFile::FitsExtensionType_IMAGE << 
-    //      "  FitsExtensionType_ASCII_TBL= " << (int)FitsFile::FitsExtensionType_ASCII_TBL <<
-    //      "  FitsExtensionType_BINARY_TBL= " << (int)FitsFile::FitsExtensionType_BINARY_TBL << endl;
-    //    cout << " FitsFile::FitsDataType: FitsDataType_double= " <<
-    //      (int)FitsFile::FitsDataType_double << 
-    //      " FitsDataType_float= " << (int)FitsFile::FitsDataType_float <<
-    //      " FitsDataType_int= " << (int)FitsFile::FitsDataType_int <<
-    //      " FitsDataType_char= " << (int)FitsFile::FitsDataType_char <<
-    //      " FitsDataType_ASCII= " << (int)FitsFile::FitsDataType_ASCII << endl << endl;
-
-    for(int i=1; i<=nbblk; i++) {
-      int naxis;
-      vector<int> axis;
-      DVList header;
-      FitsFile::FitsExtensionType exttype;
-      FitsFile::FitsDataType datatype;
-
-      FitsInFile::GetBlockType(arg[1], i, exttype, naxis, axis, datatype, header);
-      cout << "\n--------- Header Num " << i << " Type " << FITSExtType2String(exttype) 
-	   << "  --- NAxis= " << naxis 
-	   << " DataType= " << FITSDataType2String(datatype) << endl;
-      if (axis.size() > 0) { 
-	cout << " >> Axis Sizes: " ;
-	for(int j=0; j<axis.size(); j++) { 
-	  if (j > 0) cout << " x " ;
-	  cout  << axis[j] ;
-	}
-	cout << endl;
-      }
-      cout << " >>> Header info : " ;
-      cout << header << endl;
-      cout << "----------------------------------------------------------------------" 
-	   << endl;
-    } 
- 
+    FitsIOServerInit();
+    cout << " ====== scanfits: FileName= " << flnm << " ==== " << endl;
+    if ( fglh ) FitsManager::ListHandlers();
+    if ( fgflnm ) {
+      if ( fgv1 ) scanV1(flnm);
+      else FitsManager::ScanFile(flnm, slev);
+    }
   }
   catch (PThrowable & exc) {
