Index: trunk/SophyaPI/ProgPI/fitsbtadapter.cc
===================================================================
--- trunk/SophyaPI/ProgPI/fitsbtadapter.cc	(revision 2893)
+++ trunk/SophyaPI/ProgPI/fitsbtadapter.cc	(revision 2902)
@@ -1,3 +1,7 @@
 /* Interface Fits BINARY/ASCII Table     cmv 21/05/2001 */
+/*    Ajout commandes generique lecture/ecriture FITS   */
+/*                           Reza , Jan 2006            */
+
+
 #include "sopnamsp.h"
 #include "machdefs.h"
@@ -15,4 +19,8 @@
 #include "fbtntintf.h"
 
+#include "fitsmanager.h"
+#include "fitshandler.h"
+#include "fiosinit.h"
+
 ////////////////////////////////////////////////////////////
 class NOMAdapter_FitsBT : public NObjMgrAdapter {
@@ -95,4 +103,6 @@
 fitsbtadapterExecutor::fitsbtadapterExecutor()
 {
+FitsIOServerInit();  // On s'assure de l'initialisation du module FitsIOServer
+
 NamedObjMgr omg;
 PIACmd * mpiac = omg.GetImgApp()->CmdInterpreter();
@@ -111,5 +121,26 @@
 usage += "\n hdu : Fits HDU (if <=0 take first binary/ascii table)";
 usage += "\n buflen[,bufsens,lp] : buffer length (sens) for fits reading (default is 100,1,0)";
+usage += "\n See also  scanfits writefits readfits ";
 mpiac->RegisterCommand(kw, usage, this, hgrp);
+
+kw = "scanfits";
+usage = "scanfits: scan fits files and print information on each HDU\n" ;
+usage += "Usage: scanfits FileName [slev=0 ... 3]\n";
+usage += "slev=1,3: header keywords , slev=2,3: try to read each HDU";
+mpiac->RegisterCommand(kw, usage, this, hgrp); 
+
+kw = "writefits";
+usage = "writefits: Write objects to a fits file \n" ;
+usage += "Usage: writefits nameobj/pattern FileName \n";
+usage += "(use FitsManager) .... ";
+usage += "See also  scanfits readfits fitsadapt ";
+mpiac->RegisterCommand(kw, usage, this, hgrp); 
+
+kw = "readfits";
+usage = "readfits: Read all HDU's of a fits file \n" ;
+usage += "Usage: readfits nameobj/pattern FileName \n";
+usage += "(use FitsManager) .... ";
+usage += "See also  scanfits writefits fitsadapt ";
+mpiac->RegisterCommand(kw, usage, this, hgrp); 
 }
 
@@ -137,4 +168,77 @@
     omg.AddObj(fbt,nom_obj);
  }
+else if (kw == "scanfits") {
+  if(tokens.size() < 1)  {
+    cout<<"Usage: scanfits FileName [slev] "<<endl;
+    return 1;
+  }
+  int slev = 0;
+  if(tokens.size() > 1)  slev = atoi(tokens[1].c_str());
+  FitsManager::ScanFile(tokens[0], slev); 
+  return 0;
+}
+else if (kw == "writefits") {
+  if(tokens.size() < 2)  {
+    cout<<"Usage: writefits nameobj/pattern FileName "<<endl;
+    return 1;
+  }
+  vector<string> noms;
+  omg.GetObjList(tokens[0], noms);
+  if (noms.size() < 1) {
+    cout<<"writefits/Error: no object with this name "<<endl;
+    return 2;
+  }
+  cout << "writefits: Opening/Creating fits file " << tokens[1] << endl;
+  FitsInOutFile fos(tokens[1], FitsInOutFile::Fits_Create);
+  for(int kk=0; kk<noms.size(); kk++) {
+    AnyDataObj* co = omg.GetObj(noms[kk]);
+    if (co == NULL) continue;
+    fos.SetNextExtensionName(noms[kk]);
+    try {
+      FitsManager::Write(fos, *co);
+      cout << "writefits: Object " << noms[kk] << " written to HDU No " << fos.CurrentHDU() << endl;  
+    }
+    catch (NotFoundExc & exc) {
+      cout << "writefits/Error writing object " << noms[kk] << " -> " << exc.Msg() << endl;
+    }
+  }
+  return 0;
+}
+else if (kw == "readfits") {
+  if(tokens.size() < 1)  {
+    cout<<"Usage: readfits FileName "<<endl;
+    return 1;
+  }
+  cout << "readfits: Opening  fits file " << tokens[0] << endl;
+  FitsInOutFile fis(tokens[0], FitsInOutFile::Fits_RO);
+  string bnom = omg.GetServiceObj()->FileName2Name(tokens[0]);
+  string nom = bnom;
+  char bun[16];
+  int kon = 0;
+  for(int k=0; k<fis.NbHDUs(); k++) {
+    try {
+      FitsHandlerInterface* fhi = FitsManager::Read(fis);
+      AnyDataObj* obj = fhi->DataObj();
+      if (obj) {
+       kon++;
+       if (kon > 1)  { 
+	 sprintf(bun, "%d", kon);
+	 nom = bnom + bun;
+       }
+       omg.AddObj(obj, nom, false);
+       cout << "readfits: " << (string)typeid(*obj).name()
+	    << "  read From HDU " << k+1 << " ->" << nom << endl;
+      }
+      else delete fhi; 
+      //Reza, Jan 2006: Sinon, le fhi ne sera jamais supprime, tant pis 
+      // Il ne prend pas beaucoup de place, une fois que son objet est delete
+    }
+    catch (NotFoundExc & exc) {
+      cout << "readfits/Error - HDU=" << k+1 << " : " << exc.Msg() << endl;
+    }
+    fis.MoveToNextHDU();
+  }
+  return 0;  
+}
  return(0);
 }
