statmass.cc 3.58 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 54 55 56
// ============================================================================
#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=all\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="Compute total mass";

//------------------------------------------------------------------------------
// 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);
57
    uns::CunsIn2<float> * uns = new uns::CunsIn2<float>(simname,select_c,select_t);
jcl's avatar
jcl committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    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";
          
          // get mass
          float * m;
          ok=uns->snapshot->getData("mass",&nbody,&m);
          std::cerr << "nbody=" << nbody << " time="<< time <<"\n";
          double masstot=0;
74 75 76 77
          if (ok)
            for (int i=0; i<nbody; i++) {
              masstot += m[i];
            }
jcl's avatar
jcl committed
78 79 80 81 82 83 84 85 86 87
          std::cout << time << " " << masstot << "\n";
        }
    }
    else {
        std::cerr << "Unknown UNS file format["<<simname<<"]\n";
    }
    //   finish NEMO
    finiparam();
}
// ----------- End Of [stress_io_nemo.cc] ------------------------------------