testcod.cc 3.46 KB
Newer Older
jcl's avatar
jcl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2009                                       
// e-mail:   Jean-Charles.Lambert@oamp.fr                                      
// address:  Dynamique des galaxies                                            
//           Laboratoire d'Astrophysique de Marseille                          
//           Pole de l'Etoile, site de Chateau-Gombert                         
//           38, rue Frederic Joliot-Curie                                     
//           13388 Marseille cedex 13 France                                   
//           CNRS U.M.R 6110                                                   
// ============================================================================
#include <iostream>                                   // C++ I/O     
#include <fstream>                                    // C++ file I/O
#include <sstream>
#include <cstdio>                    // changed from stdio.h  WD, Sep 2008
#include <cstdlib>                   // changed from stdlib.h WD, Sep 2008
#include <assert.h>

#include "uns.h"
#define DEBUG 0
#include "unsdebug.h"

#define _vectmath_h // put this statement to avoid conflict with C++ vector class
extern "C" {
#include <nemo.h>                                     // NEMO basics
  int io_nemo(const char *, const char *,...);
}

using namespace std; // prevent writing statment like 'std::cerr'

//------------------------------------------------------------------------------
//                             M   A   I   N                                    
//------------------------------------------------------------------------------
// NEMO parameters
const char * defv[] = {  // use `::'string because of 'using namespace std'
  "in=???\n           input file (gadget|nemo)          ",
  "select=???\n       component selected (disk,stars,halo,gas,range)",
  "time=all\n         selected time",
  "VERSION=1.0\n       compiled on <"__DATE__"> JCL  ",
  NULL
};
const char * usage="test uns library";

//------------------------------------------------------------------------------
// main
int main(int argc, char ** argv )
{
  //   start  NEMO
  initparam(const_cast<char**>(argv),const_cast<char**>(defv));
  if (argc) {;} // remove compiler warning :)
  // Get parameters
  char * simname   = getparam((char *) "in"    );
  char * select_c  = getparam((char *) "select");
  char * select_t  = getparam((char *) "time"  );
  
  // instantiate a new uns object
  //s::Cuns * uns = new uns::Cuns(simname,select_c,select_t);
  uns::CunsIn * uns = new uns::CunsIn(simname,select_c,select_t);
  if (uns->isValid()) {
    while(uns->snapshot->nextFrame()) {
      bool ok;
      int nbody;
      float time;
      // get the input number of bodies according to the selection
      ok=uns->snapshot->getData("nsel",&nbody);
      // get the simulation time
      ok=uns->snapshot->getData("time",&time);
      std::cerr << "nbody=" << nbody << " time="<<time <<"\n";
      float tcod[7];
      
      //int status=uns->snapshot->getCod(std::string("all"),time,tcod);
      int status=uns->snapshot->getCod(select_c,time,tcod);
      if (status == 1) {
        for (int i=0; i<7;i++) {
          std::cerr << tcod[i] << "\t";
        }
        std::cerr << "\n";
      }
    }
  }
  else {
    std::cerr << "Unknown UNS file format["<<simname<<"]\n";
  }
  //   finish NEMO
  finiparam();
}
// ----------- End Of [stress_io_nemo.cc] ------------------------------------