Commit cfabf8d9 authored by jclamber's avatar jclamber

code cleaning + compilation options + fix ramses

git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@115 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent 93fe9851
......@@ -50,7 +50,12 @@ endif(OSX)
# Destination path for the lib
SET(LIBRARY_OUTPUT_PATH ../lib)
# compilation options
add_definitions(-Wall ${OPT} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE)
#add_definitions(-Wall ${OPT} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE)
#add_definitions(${OPT} ${WARNOPT} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE)
add_definitions(${OPT} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE)
SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${WARNCPP} )
SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${WARNC} )
SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} ${WARNF})
# SET NEMOPATH
SET(NEMOLIB ${PROJECT_SOURCE_DIR}/../lib)
......
......@@ -545,7 +545,7 @@ void initparam(string argv[], string defv[])
free(keys[j].val);
keys[j].val = scopy(parvalue(argv[i])); /* get value */
keys[j].count++;
} else if (j=set_indexed(name,&idx)) { /* enter indexed keywords */
} else if (j=set_indexed(name,&idx)) { /* enter indexed keywords */
// process this indexed keyword
#if 1
addindexed(j,argv[i],idx);
......@@ -1467,6 +1467,7 @@ bool updparam(string name)
int getparamstat(string name) {
error("getparamstat is a ZENO feature, not implemented in NEMO yet");
return 0;
}
......
......@@ -67,7 +67,11 @@ FILE(GLOB LIBSOURCES src/*.cc)
SET(LIBRARY_OUTPUT_PATH lib)
# compilation options
add_definitions(-Wall ${OPT} -Wswitch -Wcast-align -Wreturn-type -Wno-unused-function -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE ${DNOSQLITE3})
#dd_definitions(-Wall ${OPT} -Wswitch -Wcast-align -Wreturn-type -Wno-unused-function -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE ${DNOSQLITE3})
add_definitions(${OPT} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE ${DNOSQLITE3})
SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${WARNCPP} )
SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${WARNC} )
SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} ${WARNF})
# create library "uns"
add_library (unsio ${LIBTYPE} ${LIBSOURCES} )
......
......@@ -33,6 +33,10 @@ else ()
typed_cache_set (STRING "Optimizer" OPT "-O3")
endif ()
#typed_cache_set (STRING "compilation warnings" WARNCPP "-Waddress -Warray-bounds -Wc++0x-compat -Wchar-subscripts -Wenum-compare -Wcomment -Wformat -Wmain -Wmissing-braces -Wparentheses -Wreorder -Wreturn-type -Wsequence-point -Wsign-compare -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wvolatile-register-var")
typed_cache_set (STRING "compilation warnings" WARNCPP "-Wall")
typed_cache_set (STRING "compilation warnings" WARNC "-Warray-bounds -Wchar-subscripts -Wenum-compare -Wcomment -Wformat -Wmain -Wmissing-braces -Wsequence-point -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused-label -Wvolatile-register-var")
typed_cache_set (STRING "compilation warnings" WARNF "-Wall" )
# just for testing
option(RELEASE "RELEASE " ON) # SHARED lib default
if ( NOT RELEASE ) # Debug TRUE
......
......@@ -41,7 +41,7 @@ CAmr::CAmr(const std::string _indir, const bool _v)
std::cerr << "indir =[" << indir <<"]\n";
found=(int) indir.rfind("output_");
if (found!=std::string::npos) {
if (found!=(int) std::string::npos) {
s_run_index= indir.substr(found+7,indir.length()-1); // output_ = 7 characters
while ((found=s_run_index.find_last_of("/"))>0) { // remove trailing "/"
......@@ -109,7 +109,7 @@ int CAmr::readHeader()
amr.readDataBlock((char *) &ngrid_current);
amr.skipBlock();
if (len2==len1) ; // remove warning....
return 1;
}
// ============================================================================
......@@ -125,7 +125,6 @@ int CAmr::loadData(uns::CParticles * particles,
std::string infile;
nbody = 0;
int cpt=0;
bool count_only=false;
//if (index==NULL) count_only=true;
......@@ -334,6 +333,13 @@ int CAmr::loadData(uns::CParticles * particles,
}
nbody++;
}
else {
// if (ilevel>=lmin) {
// std::cerr << "Not ok lmin="<<lmin<<" ilevel="<<ilevel<<" xmin="<<xmin<<" xmax="<<xmax
// <<" ymin="<<ymin<<" ymax="<<ymax
// <<" zmin="<<zmin<<" zmax="<<zmax<<"\n";
// }
}
}
}
// garbage collecting
......
......@@ -20,6 +20,7 @@
#include <fstream>
#include <iostream>
#include <vector>
#include <cstdlib>
#include "cfortio.h"
#include "snapshotramses.h"
......@@ -45,7 +46,10 @@ public:
} else {
lmax = (int) x[7];
}
lmin = std::min((int) x[6],lmax-1);
std::cerr << "min = "<< (int) x[6] << " lmax="<<lmax<<" lmin="<<lmin<<"\n";
//exit(1);
}
bool isValid();
int loadData(uns::CParticles * particles,
......
......@@ -36,6 +36,7 @@ public:
int len1=readFRecord();
readData(ptr,1,len1);
int len2=readFRecord();
if (len2==len1) ; // remove warning....
assert(good() && len1==len2);
return len1;
} else return 1;
......@@ -78,6 +79,7 @@ public:
int len1 = readFRecord();
in.seekg(len1,std::ios::cur);
int len2 = readFRecord();
if (len2==len1) ; // remove warning....
assert(in.good() && len1==len2);
}
}
......
......@@ -38,7 +38,7 @@ CPart::CPart(const std::string _indir, const bool _v)
std::cerr << "indir =" << indir <<"\n";
found=(int) indir.rfind("output_");
if (found!=std::string::npos) {
if (found!=(int) std::string::npos) {
s_run_index= indir.substr(found+7,indir.length()-1); // output_ = 7 characters
while ((found=s_run_index.find_last_of("/"))>0) { // remove trailing "/"
......@@ -373,5 +373,6 @@ int CPart::loadData(uns::CParticles * particles,
} // for ...
return nselect;
#endif
return 1;
}
} // namespace ramses
......@@ -222,7 +222,8 @@ template <class T> int CSnapshotGadgetIn::readCompData(T ** data, const int * in
}
}
int len2 = readFRecord();
assert(in.good() && len1==len2 && len1==bytes_counter);
if (len2==len1) ; // remove warning....
assert(len2==len1 && in.good() && len1==bytes_counter);
return 1;
}
// ============================================================================
......@@ -247,7 +248,8 @@ template <class T> int CSnapshotGadgetIn::readGasStarsUnknownArray(T ** data, in
assert((idx+(*nguess)*header.npart[4])<=(*nguess)*(header.npartTotal[0]+header.npartTotal[4]));
readData((char *) &ptr[idx], sizeof(float),(*nguess)*header.npart[4]);
int len2 = readFRecord();
assert(in.good() && len1==len2 && len1==bytes_counter);
if (len2==len1) ; // remove warning....
assert(in.good() && len2==len1 && len1==bytes_counter);
return 1;
}
// ============================================================================
......@@ -265,6 +267,7 @@ template <class T> int CSnapshotGadgetIn::readOneArray(T ** data, const int comp
assert((idx+header.npart[compid])<=header.npartTotal[compid]);
readData((char *) &ptr[idx], sizeof(float),header.npart[compid] );
int len2 = readFRecord();
if (len2==len1) ; // remove warning....
assert(in.good() && len1==len2 && len1==bytes_counter);
return 1;
}
......@@ -327,7 +330,7 @@ int CSnapshotGadgetIn::read(uns::UserSelection &user_select)
if (i>0) {
close(); // close previous file
int fail=open(infile); // open new file,read header
assert(!fail); // fail is true abort
if (fail) assert(0); // fail is true abort
}
}
else infile=filename; // lonely file
......@@ -393,7 +396,8 @@ int CSnapshotGadgetIn::read(uns::UserSelection &user_select)
} // for k
if (ntotmasses > 0.) { // different masses
len2 = readFRecord(); // we must read from disk
assert(in.good() && len1==len2 && len1==bytes_counter);
if (len2==len1) ; // remove warning....
assert(in.good() && len2==len1 && len1==bytes_counter);
}
if (version==1) stop=true; // we stop reading for gadget1
}
......@@ -576,15 +580,19 @@ int CSnapshotGadgetIn::read(uns::UserSelection &user_select)
// unitConversion()
void CSnapshotGadgetIn::unitConversion()
{
double GRAVITY, BOLTZMANN, PROTONMASS;
double BOLTZMANN, PROTONMASS;
double UnitLength_in_cm, UnitMass_in_g, UnitVelocity_in_cm_per_s;
double UnitTime_in_s, UnitDensity_in_cgs, UnitPressure_in_cgs, UnitEnergy_in_cgs;
double G, Xh, HubbleParam;
double UnitTime_in_s, UnitDensity_in_cgs, UnitEnergy_in_cgs;
double Xh;
#if 0
double UnitPressure_in_cgs, HubbleParam=0.65m G;
double GRAVITY;
#endif
double MeanWeight, u, gamma;
double RhoUniverse_omegabar;
/* physical constants in cgs units */
GRAVITY = 6.672e-8;
//GRAVITY = 6.672e-8;
BOLTZMANN = 1.3806e-16;
PROTONMASS = 1.6726e-24;
......@@ -599,13 +607,12 @@ void CSnapshotGadgetIn::unitConversion()
UnitTime_in_s= UnitLength_in_cm / UnitVelocity_in_cm_per_s;
UnitDensity_in_cgs= UnitMass_in_g/ pow(UnitLength_in_cm,3);
UnitPressure_in_cgs= UnitMass_in_g/ UnitLength_in_cm/ pow(UnitTime_in_s,2);
//UnitPressure_in_cgs= UnitMass_in_g/ UnitLength_in_cm/ pow(UnitTime_in_s,2);
UnitEnergy_in_cgs= UnitMass_in_g * pow(UnitLength_in_cm,2) / pow(UnitTime_in_s,2);
G=GRAVITY/ pow(UnitLength_in_cm,3) * UnitMass_in_g * pow(UnitTime_in_s,2);
//G=GRAVITY/ pow(UnitLength_in_cm,3) * UnitMass_in_g * pow(UnitTime_in_s,2);
Xh= 0.76; /* mass fraction of hydrogen */
HubbleParam= 0.65;
RhoUniverse_omegabar=1.9e-29*0.04;
......@@ -2111,7 +2118,7 @@ bool CSnapshotGadgetOut::writeBlockName(std::string block_name, int nextblock)
std::vector<double> CSnapshotGadgetOut::moveToCom()
{
std::vector<double> com(6,0.);
double masstot;
double masstot=0.0;
// loop on all components to compute COM
for (int i=0;i<6;i++) {
if (header.npart[i]) { // component exist
......
......@@ -222,7 +222,8 @@ typedef struct particle_data_lite
in.seekg(len1,std::ios::cur);
int len2 = readFRecord();
if (verbose) std::cerr << "skipping block name ["<<block_name<<"]\n";
assert(in.good() && len1==len2);
if (len2==len1) ; // remove warning....
assert(len1==len2 && in.good());
if (block_name == "AGE" || block_name == "Z" ) {
//std::cerr << "len1 = " << len1 << "\nlen2 = " << len2 << "\n";
}
......
......@@ -105,7 +105,6 @@ namespace uns {
// split a string a:b[:c] into inf, sup,delta
void CSnapshotInterfaceIn::getRangeTime(const std::string rtime)
{
int status;
std::vector<float> store;
int ppos=0;
bool stop=false;
......@@ -153,7 +152,6 @@ namespace uns {
}
assert(sup>=inf);
status=0;
// store inf and supp time in vector array
CSelectTime st(inf,sup,offset,-666.0);
stv.push_back(st);
......
......@@ -60,6 +60,7 @@ namespace uns {
if (snapshot) return snapshot->getFileStructure();
std::cerr << "Algo error : snapshot not defined...\n";
assert(0);
return "";
}
private:
......
......@@ -101,7 +101,6 @@ CSnapshotNemoIn::~CSnapshotNemoIn()
bool CSnapshotNemoIn::isValidNemo()
{
bool status;
float * ntimu;
valid=true;
if (filename == "-") { // we assume here that "-"
......@@ -123,7 +122,6 @@ bool CSnapshotNemoIn::isValidNemo()
strclose(str);
if (status) { // it's a NEMO snapshot
int * ptr=NULL; // get the full nbody
ntimu=NULL;
if (io_nemo(filename.c_str(),"float,read,n,t,b",&ptr,&iotime,&nemobits) != 0) {
io_nemo(filename.c_str(),"close");
} else {
......@@ -241,9 +239,10 @@ int CSnapshotNemoIn::nextFrame(uns::UserSelection &user_select)
cpt++;
}
}
assert(cpt==nsel);
assert(nsel==cpt);
}
}
if (nsel) ; // remove compiler warning
if (verbose) std::cerr << "CSnapshotNemoIn::nextFrame status = " << status << "\n";
if (status == -1) status=1;
return status;
......@@ -843,7 +842,7 @@ int CSnapshotNemoOut::close()
std::vector<double> CSnapshotNemoOut::moveToCom()
{
std::vector<double> com(6,0.);
double masstot;
double masstot=0.0;
// compute center of mass
for (int i=0; i<nbody;i++) {
float massi;
......
......@@ -98,7 +98,7 @@ int CSnapshotRamsesIn::nextFrame(uns::UserSelection &user_select)
x[0]=x[2]=x[4]=std::numeric_limits<float>::min();
x[1]=x[3]=x[5]=std::numeric_limits<float>::max();
x[6]=std::numeric_limits<float>::max(); // level min
x[6]=(float )0; // level min
x[7]=0; // nlevelmax
if ((comp_bits&HALO_BIT || comp_bits&STARS_BIT) && part->isValid()) {
......@@ -106,9 +106,11 @@ int CSnapshotRamsesIn::nextFrame(uns::UserSelection &user_select)
part->loadData(particles,req_bits,comp_bits);
}
if (comp_bits&GAS_BIT && amr->isValid()) {
std::cerr << "in gas\n";
amr->setBoundary(x);
amr->loadData(particles,req_bits);
}
std::cerr << "ntot = "<< particles->ntot <<"\n";
std::cerr << "ngas = "<< particles->ngas <<"\n";
std::cerr << "ndm = "<< particles->ndm <<"\n";
std::cerr << "nstars = "<< particles->nstars <<"\n";
......@@ -175,8 +177,19 @@ int CSnapshotRamsesIn::reorderParticles(uns::UserSelection &user_select)
crv.push_back(cr);
}
}
// set the new real user select
user_select.setCrv(crv);
if (select_part=="all") { // if "all" selected
uns::ComponentRangeVector crvall;
uns::ComponentRange cr;
// all
cr.setData(0,particles->ntot-1);
cr.setType("all");
crvall.push_back(cr);
user_select.setCrv(crvall); // we force CRV with "all" only because select_part="all"
} else { // if not "all" selected
// set the new real user select
user_select.setCrv(crv); // we rebuild CRV with the user selection
}
if (verbose)
uns::ComponentRange::list(&crv);
......@@ -189,13 +202,13 @@ int CSnapshotRamsesIn::reorderParticles(uns::UserSelection &user_select)
crv.insert(it,cr);
for (unsigned int i=0;i<offset_comp.size(); i++) {
std::cerr << "i="<<i<<" ***comp offset="<<offset_comp[i]<<"\n";
std::cerr << "i="<<i<<"["<<comp[i]<<"] offset="<<offset_comp[i]<<"\n";
}
if (verbose)
uns::ComponentRange::list(&crv);
// particles reordering
if (particles->ntot) { // exist particles to reorde
if (particles->ntot) { // exist particles to reorder
std::vector <float> pos,vel,mass;
if (particles->pos.size()>0)
pos.resize(particles->pos.size()); // resize new pos vector
......
......@@ -51,6 +51,7 @@ namespace uns {
if (snapshot) return snapshot->getFileStructure();
std::cerr << "Algo error : snapshot not defined...\n";
assert(0);
return "";
}
bool shift(std::string name, const float x, const float y, const float z) {
return snapshot->shift(name,x,y,z);
......
......@@ -323,7 +323,7 @@ int uns_get_pos_( const int * id, float * pos, int * size)
float *data;
int nbody;
bool ok=snap->getData("pos",&nbody,&data);
assert(ok==true);
if (!ok) assert(0);
checkFArray(*size,nbody);
memcpy(pos,data,sizeof(float)*3*nbody);
return 1;
......@@ -340,7 +340,7 @@ int uns_get_vel_( const int * id, float * vel, int * size)
float *data;
int nbody;
bool ok=snap->getData("vel",&nbody,&data);
assert(ok==true);
if (!ok) assert(0);
checkFArray(*size,nbody);
memcpy(vel,data,sizeof(float)*3*nbody);
return 1;
......@@ -357,7 +357,7 @@ int uns_get_mass_( const int * id, float * mass, int * size)
float *data;
int nbody;
bool ok=snap->getData("mass",&nbody,&data);
assert(ok==true);
if (!ok) assert(0);
checkFArray(*size,nbody);
memcpy(mass,data,sizeof(float)*nbody);
return 1;
......
......@@ -45,7 +45,11 @@ UserSelection::~UserSelection()
// available component for the snapshot.
// This function will build an array of indexes selected by the user.
// This function takes care in which order the user has selected the particles and build
// the array of selected indexes accordingly.
// the array of selected indexes accordingly
// IMPORTANT TO REMEMBER
// CRV is a pointer const, means every modifications of CRV outside
// will be efective here also
// IMPORTANT TO REMEMBER
bool UserSelection::setSelection(const std::string _sel,
const ComponentRangeVector * _crv,bool _nodata)
{
......@@ -183,6 +187,7 @@ int UserSelection::isRange(const std::string comp)
}
assert(last>=first);
int npart=last-first+1; // #part
if (npart) ; // remove compiler warning
assert(npart<=nbody);
fillIndexes(comp,first,last,step,pos); // fill indexes array
pos++;
......@@ -198,7 +203,7 @@ int UserSelection::isRange(const std::string comp)
// return true is the component is component type
int UserSelection::isComponent(const std::string comp)
{
int status;
int status=1;
// Regular expression => all|halo|disk ......
const char * rx[] = {"all","halo","dm","disk","bulge","stars","gas","bndry","halo2",NULL};
int i=0;
......@@ -231,6 +236,7 @@ int UserSelection::isComponent(const std::string comp)
last =(*crv)[icrv].last;
assert(last>=first);
int npart=last-first+1; // #part
if (npart) ; // remove compiler warning
assert(npart<=nbody);
status=0;
fillIndexes(comp,first,last,step,pos); // fill indexes array
......
......@@ -54,28 +54,28 @@ int main(int argc, char ** argv )
uns::CunsIn * uns = new uns::CunsIn(simname,"gas",select_t);
if (uns->isValid()) {
while(uns->snapshot->nextFrame()) {
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";
}
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) ;
}
} else {
std::cerr << "Unknown UNS file format["<<simname<<"]\n";
......
......@@ -71,9 +71,10 @@ int main(int argc, char ** argv )
ok=uns->snapshot->getData("mass",&nbody,&m);
std::cerr << "nbody=" << nbody << " time="<< time <<"\n";
double masstot=0;
for (int i=0; i<nbody; i++) {
masstot += m[i];
}
if (ok)
for (int i=0; i<nbody; i++) {
masstot += m[i];
}
std::cout << time << " " << masstot << "\n";
}
}
......
......@@ -56,14 +56,13 @@ int main(int argc, char ** argv )
//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;
while(uns->snapshot->nextFrame()) {
int nbody;
float time;
// get the input number of bodies according to the selection
ok=uns->snapshot->getData("nsel",&nbody);
uns->snapshot->getData("nsel",&nbody);
// get the simulation time
ok=uns->snapshot->getData("time",&time);
uns->snapshot->getData("time",&time);
std::cerr << "nbody=" << nbody << " time="<<time <<"\n";
float tcod[7];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment