// This may look like C code, but it is really -*- C++ -*-
// Class NTuple
//  CMV+Reza     Juillet 97
//  CEA-DAPNIA      LAL-IN2P3/CNRS

#ifndef NTUPLE_H_SEEN
#define NTUPLE_H_SEEN

#include "objfio.h"

#include <iostream.h>
#include <string>
#include <vector>

#include "ntupintf.h"
#include "ppersist.h"
#include "dvlist.h"

namespace SOPHYA {

//  Forward class declaration for Fits handler
class FITS_XNTuple;

class NTuple : public AnyDataObj , public NTupleInterface {

public:
//  enum {classId = ClassId_NTuple };

  		    NTuple(int nvar, char** noms, int blk=512);
		    NTuple();
                    NTuple(const NTuple& NT);
		    NTuple(char* flnm);
  virtual           ~NTuple();

  NTuple&           operator = (const NTuple& NT);
 
  void              Fill(r_4* x);

  inline int_4      NEntry() const  { return(mNEnt); }  
  inline int_4      NVar() const { return(mNVar); }  
  inline int_4      BLock() const { return(mBlk); }  
// $CHECK$ Reza 21/10/99 Pourquoi faire BLock() ?

  float             GetVal(int n, int k)   const;
  inline float	    GetVal(int n, const char* nom) const 
                            { return(GetVal(n, IndexNom(nom)) ); }
  int               IndexNom(const char* nom)  const ;
  char*             NomIndex(int k) const;

  r_4*	            GetVec(int n, r_4* ret=NULL)  const ;
  r_8*	            GetVecD(int n, r_8* ret=NULL)  const ;

// Impression, I/O
  void              Print(int num, int nmax=1)  const ;
  void              Show(ostream& os) const;
  inline void       Show() const { Show(cout); }

  DVList&           Info();

// Remplissage depuis fichier ASCII 
  int		    FillFromASCIIFile(string const& fn, float defval=0.);


// Declaration de l interface NTuple
  virtual uint_4        NbLines() const ;
  virtual uint_4        NbColumns() const ;
  virtual r_8 *         GetLineD(int n) const ;
  virtual r_8		GetCell(int n, int k) const ;
  virtual r_8		GetCell(int n, string const & nom) const ;
  virtual void		GetMinMax(int k, double& min, double& max)   const ; 
  virtual void		GetMinMax(string const & nom, double& min, double& max)   const ; 
  virtual int           ColumnIndex(string const & nom)  const ;
  virtual string        ColumnName(int k) const;
  virtual string	VarList_C(const char* nomx=NULL) const ;
  virtual string        LineHeaderToString() const;
  virtual string        LineToString(int n) const;  

//  Pour la gestion de persistance
  friend class ObjFileIO<NTuple> ;

  // pour fichiers FITS
    friend class FITS_NTuple;


private:
  void  Clean();

  int_4 mNVar, mNEnt, mBlk, mNBlk;
  r_4* mVar;
  r_8* mVarD;
  char* mNames;

  vector<r_4*> mPtr;

  DVList* mInfo;        // Infos (variables) attachees au NTuple
  
};

/*! Prints table information on stream \b s (nt.Show(s)) */
inline ostream& operator << (ostream& s, NTuple const & nt)
  {  nt.Show(s);  return(s);  }

/*! Writes the object in the POutPersist stream \b os */
inline POutPersist& operator << (POutPersist& os, NTuple & obj)
{ ObjFileIO<NTuple> fio(&obj);  fio.Write(os);  return(os); }
/*! Reads the object from the PInPersist stream \b is */
inline PInPersist& operator >> (PInPersist& is, NTuple & obj)
{ ObjFileIO<NTuple> fio(&obj);  fio.Read(is);  return(is); }

// Classe pour la gestion de persistance
// ObjFileIO<NTuple>



#ifdef __MWERKS__
__MSL_FIX_ITERATORS__(r_4*);
#endif

} // namespace SOPHYA

#endif
  
