rhotemp.cc 3.44 KB
Newer Older
jcl's avatar
jcl committed
1 2
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2009                                       
jclamber's avatar
jclamber committed
3 4
// e-mail:   Jean-Charles.Lambert@lam.fr                                      
// address:  Aix Marseille Universite, CNRS, LAM 
jcl's avatar
jcl committed
5 6 7 8
//           Laboratoire d'Astrophysique de Marseille                          
//           Pole de l'Etoile, site de Chateau-Gombert                         
//           38, rue Frederic Joliot-Curie                                     
//           13388 Marseille cedex 13 France                                   
jclamber's avatar
jclamber committed
9
//           CNRS UMR 7326                                       
jcl's avatar
jcl committed
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
// ============================================================================
#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)          ",
  "time=all\n         selected time",
  "VERSION=1.0\n       compiled on <"__DATE__"> JCL  ",
  NULL
};
const char * usage="print out rho and temperature for the gas component";

//------------------------------------------------------------------------------
// 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_t  = getparam((char *) "time"  );
  // instantiate a new uns object
  //s::Cuns * uns = new uns::Cuns(simname,select_c,select_t);
54
  uns::CunsIn2<float> * uns = new uns::CunsIn2<float>(simname,"gas",select_t);
jcl's avatar
jcl committed
55 56
  if (uns->isValid()) {
    while(uns->snapshot->nextFrame()) {
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
      bool ok;
      int n,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";
      // rho
      float * rho=NULL;
      ok=uns->snapshot->getData("rho",&n,&rho);
      std::cerr << "n=" << n <<"\n";
      assert(n== nbody);
      // temp
      float * temp=NULL;
      ok=uns->snapshot->getData("temp",&n,&rho);
      std::cerr << "n=" << n <<"\n";
      assert(n== nbody);
      for (int i=0; i<n; i++) {
        std::cout << rho[i] << " " << temp[i] << "\n";
      }
      if (ok) ;
jcl's avatar
jcl committed
79 80 81 82 83 84 85 86
    }
  } else {
    std::cerr << "Unknown UNS file format["<<simname<<"]\n";
  }
  //   finish NEMO
  finiparam();
}
// ----------- End Of [stress_io_nemo.cc] ------------------------------------