snapshotnemo.h 4.74 KB
Newer Older
jcl's avatar
jcl committed
1
// ============================================================================
2
// Copyright Jean-Charles LAMBERT - 2008-2016
jclamber's avatar
jclamber committed
3 4 5
//           Centre de donneeS Astrophysiques de Marseille (CeSAM)         
// e-mail:   Jean-Charles.Lambert@lam.fr                                      
// address:  Aix Marseille Universite, CNRS, LAM 
jcl's avatar
jcl committed
6 7 8 9
//           Laboratoire d'Astrophysique de Marseille                          
//           Pôle de l'Etoile, site de Château-Gombert                         
//           38, rue Frédéric Joliot-Curie                                     
//           13388 Marseille cedex 13 France                                   
jclamber's avatar
jclamber committed
10
//           CNRS UMR 7326                                       
jcl's avatar
jcl committed
11 12 13
// ============================================================================

/**
jclamber's avatar
jclamber committed
14
	@author Jean-Charles Lambert <Jean-Charles.Lambert@lam.fr>
jcl's avatar
jcl committed
15 16 17 18 19 20 21 22 23 24 25 26
 */
#ifndef UNSSNAPSHOTNEMO_H
#define UNSSNAPSHOTNEMO_H
#include "snapshotinterface.h"
#include <map>

extern "C" {
  int io_nemo(const char * , const char *, ...);
#include <stdinc.h>
#include <filestruct.h>
#include <nemo.h>
#include <snapshot/snapshot.h>
27
}
jcl's avatar
jcl committed
28 29 30

namespace uns {

31
  template <class T> class CSnapshotNemoIn : public CSnapshotInterfaceIn<T> {
jcl's avatar
jcl committed
32 33 34 35 36 37 38 39 40
  
  public:
    CSnapshotNemoIn(const std::string, const std::string, const std::string,
		  const bool verb=false);
    ~CSnapshotNemoIn();
    int nextFrame(uns::UserSelection &);
    int close();
    ComponentRangeVector * getSnapshotRange();
    // virtual function implemented
41 42
    bool getData(const std::string,int *n,T **);
    bool getData(const std::string,       T * );
jcl's avatar
jcl committed
43 44
    bool getData(const std::string,int *n,int   **);
    bool getData(const std::string,       int   * );
45
    bool getData(const std::string, const std::string ,int *,T **);
jcl's avatar
jcl committed
46 47 48 49 50 51
    bool getData(const std::string, const std::string ,int *,int   **);
   
private:
    int full_nbody;
    int * nemobits , * ionbody, *iokeys;
    int * keys;
52 53
    T * iotime, *iopos, *iovel, *iomass, *iorho, *ioaux, *ioacc, *iopot, *ioeps;
    T * pos, *vel, *mass, * rho, *acc, *aux, *pot, *eps;
jcl's avatar
jcl committed
54 55 56 57 58
    bool first_stream;
    int status_ionemo;
    int last_nbody,last_nemobits;
    void checkBits(std::string,const int);
    bool isValidNemo();
59
    T *  getPos()  { //checkBits("pos",PosBit);
jcl's avatar
jcl committed
60
                         return pos ;}
61
    T *  getVel()  { //checkBits("vel",VelBit);
jcl's avatar
jcl committed
62
                         return vel ;}
63
    T *  getMass() { //checkBits("mass",MassBit);
jcl's avatar
jcl committed
64
                         return mass;}
65 66 67 68 69
    T *  getEps()  { return eps;}
    T *  getRho()  { return rho ;}
    T *  getAux()  { return aux ;}
    T *  getAcc()  { return acc ;}
    T *  getPot()  { return pot ;}
jcl's avatar
jcl committed
70
    int   *  getKeys() { return keys;}
71
    T    getTime() { return *iotime; }
jcl's avatar
jcl committed
72
    int      getNbody(){ return *ionbody;}
73 74 75 76 77 78 79 80 81 82 83 84 85 86

    std::string realString() { // return a string with the real format
      std::string io_nemo_select;
      if (sizeof(T)==sizeof(double)) {
        io_nemo_select="double";
      } else {
        if (sizeof(T)==sizeof(float)) {
          io_nemo_select="float";
        } else {
          assert(0);
        }
      }
      return io_nemo_select;
    }
jcl's avatar
jcl committed
87 88
};
  
89
  template <class T> class CSnapshotNemoOut : public CSnapshotInterfaceOut<T> {
jcl's avatar
jcl committed
90 91 92 93 94 95 96

  public:
    // WRITING constructor
    CSnapshotNemoOut(const std::string, const std::string, const bool);
    ~CSnapshotNemoOut();
    int setHeader(void * );
    int setNbody(const int _n);
97 98
    int setData(std::string, T);
    int setData(std::string, const int , T *,const bool _addr=false);
jcl's avatar
jcl committed
99
    // array by double keys
100
    int setData(std::string, std::string, const int , T *,const bool _addr=false);
jcl's avatar
jcl committed
101 102 103 104
    int setData(std::string, std::string, const int , int   *,const bool _addr=false);
    
    int setData(std::string, const int , int *,const bool _addr=false);
    int setData(std::string, const int , 
105
        T *, T *, T *, const bool _addr=false);
jcl's avatar
jcl committed
106 107 108 109 110 111
    int save();
    std::vector<double> moveToCom();
    int close();
  private:
    // Map to associate the strings with the bool values
    std::map<std::string, bool> ptrIsAlloc;
112 113
    T * mass, * pos, * vel, * aux, * acc, * pot, * rho, * eps;
    T time;
jcl's avatar
jcl committed
114 115 116 117
    int * keys;
    int nbody;
    int bits;
    bool is_saved, is_closed;
118 119 120 121 122 123 124 125 126 127 128 129 130 131

    std::string realString() { // return a string with the real format
      std::string io_nemo_select;
      if (sizeof(T)==sizeof(double)) {
        io_nemo_select="double";
      } else {
        if (sizeof(T)==sizeof(float)) {
          io_nemo_select="float";
        } else {
          assert(0);
        }
      }
      return io_nemo_select;
    }
jcl's avatar
jcl committed
132
    // array
133
    int setArray(const int _n, const int _d, T * src, T ** dest, const char * name, const int tbits, const bool addr);
jcl's avatar
jcl committed
134 135 136 137
    int setArray(const int _n, const int _d, int   * src, int   ** dest, const char * name, const int tbits, const bool addr);
};
}
#endif