Commit c9e10da6 authored by LAMBERT Jean-charles's avatar LAMBERT Jean-charles
Browse files

change int to longint

parent bc772e47
......@@ -132,14 +132,12 @@ def saveSnap(insnap,comp,unstype,single):
## READ FILE BACK
mysnap = snap()
ok,mysnap = readSnap(myfile,comp,single)
#embed()
os.remove(myfile) # rmove temporary file
return True,copy.deepcopy(mysnap)
# -----------------------------------------------------
def compareArray(CA,CB,attr):
#embed()
A=getattr(CA,attr)
B=getattr(CB,attr)
ok=False
......@@ -183,7 +181,7 @@ def notCompare(CA,CB,attr):
def compare(CA,CB):
print("-----------------------------------------------------")
print("Comparing : [",CA.interface,"] vs [",CB.interface,"]\n")
for attr in ("pos","vel","mass","age","hsml","rho","metal", "id","time"):
for attr in ("pos","vel","mass","age","hsml","rho","metal","id","time"):
compareArray(CA,CB,attr)
# -----------------------------------------------------
......
//-*- C -*-
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2008-2015
// Copyright Jean-Charles LAMBERT - 2008-2016
// Centre de donneeS Astrophysiques de Marseille (CeSAM)
// e-mail: Jean-Charles.Lambert@lam.fr
// address: Aix Marseille Universite, CNRS, LAM
......@@ -28,36 +28,36 @@
import_array();
%}
// below we change the type of dimension of numpy array.
// below we change the returning type of numpy array size
// By default it's an "int", but we have std::vector object returning size()
// method as dimension, and which are of type "unsigned int"
// method as dimension, and which are of type "unsigned long int"
// This may cause a problem with BIG simulations. Indeed a simulation with 1.1 billions particles
// store in a xyz positions array a size of 3.3 billions which overtake size of SIGNED int, which go
// only to 2^31 bits = 2.14 billons !!!!! (damn nasty bug....)
%numpy_typemaps(double, NPY_DOUBLE, unsigned int)
%numpy_typemaps(float , NPY_FLOAT , unsigned int)
%numpy_typemaps(int , NPY_INT , unsigned int)
// only to 2^31-1 bits = 2.14 billons !!!!! (damn nasty bug....)
%numpy_typemaps(double, NPY_DOUBLE, long int)
%numpy_typemaps(float , NPY_FLOAT , long int)
%numpy_typemaps(long , NPY_LONG , long int)
// getArrayX return 1D numpy float array
%apply (unsigned int* DIM1, float ** ARGOUTVIEW_ARRAY1 )
{( unsigned int* size, float ** farray )};
%apply (long int* DIM1, float ** ARGOUTVIEW_ARRAY1 )
{( long int* size, float ** farray )};
//%apply ( int* DIM1, int ** ARGOUTVIEW_ARRAY1 )
// {( int* size, int ** iarray )};
// getArrayX return 1D numpy double array
%apply (unsigned int* DIM1, double ** ARGOUTVIEW_ARRAY1 )
{( unsigned int* size, double ** farray )};
%apply (long int* DIM1, double ** ARGOUTVIEW_ARRAY1 )
{( long int* size, double ** farray )};
// getArrayX return 1D numpy int array
%apply (unsigned int* DIM1, int ** ARGOUTVIEW_ARRAY1 )
{( unsigned int* size, int ** iarray )};
%apply (long int* DIM1, long int ** ARGOUTVIEW_ARRAY1 )
{( long int* size, long int ** iarray )};
// getValueX return float/double/int value
%apply float *OUTPUT { float * fvalue };
%apply double *OUTPUT { double * fvalue };
%apply int *OUTPUT { int * ivalue };
%apply long int *OUTPUT { long int * ivalue };
// rename methods because of overloading limitations with swig c++
// IMPORTANT :
......@@ -66,35 +66,35 @@
//float
%rename(getValueF) getData(const std::string,float *);
%rename(getArrayF) getData(const std::string,const std::string,unsigned int *,float **);
%rename(getArrayF) getData(const std::string,unsigned int *,float **);
%rename(getArrayF) getData(const std::string,const std::string,long int *,float **);
%rename(getArrayF) getData(const std::string,long int *,float **);
//double
%rename(getValueF) getData(const std::string,double *);
%rename(getArrayF) getData(const std::string,const std::string,unsigned int *,double **);
%rename(getArrayF) getData(const std::string,unsigned int *, double **);
%rename(getArrayF) getData(const std::string,const std::string,long int *,double **);
%rename(getArrayF) getData(const std::string,long int *, double **);
//int
%rename(getValueI) getData(const std::string,int *);
%rename(getArrayI) getData(const std::string,const std::string,unsigned int *,int **);
%rename(getArrayI) getData(const std::string,unsigned int *,int **);
%rename(getValueI) getData(const std::string,long int *);
%rename(getArrayI) getData(const std::string,const std::string,long int *,long int **);
%rename(getArrayI) getData(const std::string,long int *,long int **);
%apply (unsigned int DIM1 , float * INPLACE_ARRAY1) {(unsigned int size, float * farray)};
%apply (unsigned int DIM1 , double* INPLACE_ARRAY1) {(unsigned int size, double* farray)};
%apply (unsigned int DIM1 , int * INPLACE_ARRAY1) {(unsigned int size, int * iarray)};
%apply (long int DIM1 , float * INPLACE_ARRAY1) {(long int size, float * farray)};
%apply (long int DIM1 , double* INPLACE_ARRAY1) {(long int size, double * farray)};
%apply (long int DIM1 , long int * INPLACE_ARRAY1) {(long int size, long int * iarray)};
// rename methods because of overloading limitations with swig c++
// float
%rename(setValueF) setData(const std::string,float);
%rename(setArrayF_do_not_used) setData(const std::string,const std::string,unsigned int ,float *,const bool _addr=false);
%rename(setArrayF_do_not_used) setData(const std::string,unsigned int ,float *,const bool _addr=false);
%rename(setArrayF_do_not_used) setData(const std::string,const std::string,long int ,float *,const bool _addr=false);
%rename(setArrayF_do_not_used) setData(const std::string,long int ,float *,const bool _addr=false);
// double
%rename(setValueF) setData(const std::string,double);
%rename(setArrayF_do_not_used) setData(const std::string,const std::string, unsigned int ,double *,const bool _addr=false);
%rename(setArrayF_do_not_used) setData(const std::string,unsigned int ,double *,const bool _addr=false);
%rename(setArrayF_do_not_used) setData(const std::string,const std::string, long int ,double *,const bool _addr=false);
%rename(setArrayF_do_not_used) setData(const std::string,long int ,double *,const bool _addr=false);
// int
%rename(setValueI) setData(const std::string,int,const bool _addr=false);
%rename(setArrayI) setData(const std::string,const std::string,unsigned int ,int *,const bool _addr=false);
%rename(setArrayI) setData(const std::string,unsigned int ,int *);
%rename(setValueI) setData(const std::string,long int,const bool _addr=false);
%rename(setArrayI) setData(const std::string,const std::string,long int ,long int *,const bool _addr=false);
%rename(setArrayI) setData(const std::string,long int , long int *);
// Parse the original header file
%include "uns.h"
......@@ -102,14 +102,14 @@
%extend uns::CunsOut2 {
// we rewrite setArrayF because numpy array size is different from nbody for 3D arrays
int setArrayF(const std::string comp,const std::string prop,
unsigned int size,T * farray, const bool _addr=false) {
long int size,T * farray, const bool _addr=false) {
if (prop=="pos" || prop=="vel" || prop=="acc") size /= 3;
int status = $self->snapshot->setData(comp,prop,size,farray,_addr);
return status;
}
// we rewrite setArrayF because numpy array size is different from nbody for 3D arrays
int setArrayF(const std::string prop,
unsigned int size,T * farray, const bool _addr=false) {
long int size,T * farray, const bool _addr=false) {
if (prop=="pos" || prop=="vel" || prop=="acc") size /= 3;
int status = $self->snapshot->setData(prop,size,farray,_addr);
return status;
......
......@@ -386,6 +386,7 @@ int CSnapshotGadgetIn<T>::read(uns::UserSelection &user_select)
long int npartOffset[6], // store absolute component offset (between components)
compOffset[6]; // store relative component offset
if (! is_read ) {
int * id_int=NULL;
//checkCompBits(index,nsel);
// check component bits`
......@@ -467,7 +468,7 @@ int CSnapshotGadgetIn<T>::read(uns::UserSelection &user_select)
if (block_name=="ID" && this->req_bits&ID_BIT) {
this->load_bits |= ID_BIT;
ok=true;
readCompData(&id,index2,npartOffset,1,nsel);
readCompData(&id_int,index2,npartOffset,1,nsel);
if (version==1) next_block_name="MASS";
}
// --> MASS block
......@@ -681,6 +682,14 @@ int CSnapshotGadgetIn<T>::read(uns::UserSelection &user_select)
if (header.npartTotal[0] > 0) {
//unitConversion();
}
// convert id (int) to id (long int)
if (this->req_bits&ID_BIT && id_int != NULL) {
id = new long int [nsel];
for (long int i=0; i<nsel; i++){
id[i]=id_int[i];
}
delete [] id_int;
}
// check bits
this->freeNotLoadedData(&mass ,MASS_BIT);
this->freeNotLoadedData(&pos ,POS_BIT);
......@@ -2401,8 +2410,15 @@ int CSnapshotGadgetOut<T>::write()
} else { // There are IDs
for(int k=0;k<6;k++)
if (header.npart[k]) {// id exist for the component
if (id[k])
writeData((char *) id[k], sizeof(int), header.npart[k]);
if (id[k]) {
int * iid = new int[header.npart[k]];
// convert long int to int
for (long int i=0; i<header.npart[k]; i++) {
iid[i]=id[k][i];
}
writeData((char *) iid, sizeof(int), header.npart[k]);
delete [] iid;
}
else
writeDataValue(0,sizeof(int), header.npart[k]);
}
......
......@@ -29,7 +29,7 @@ namespace uns {
typedef struct io_header_1
{
long int npart[6];
int npart[6];
double mass[6];
double time;
double redshift;
......@@ -241,7 +241,7 @@ const t_data_type_header dth[NB_DATA_HEADER] = {
}
// read fortran record
inline long int readFRecord() {
long int len; in.read((char *) &len,sizeof(int));
int len; in.read((char *) &len,sizeof(int));
// We SWAP data
if (swap) { // swapping requested
swapBytes(&len,sizeof(int));
......
......@@ -1087,7 +1087,11 @@ template <class U> std::vector<U> GH5<T>::getDataset(std::string dset_name, U du
DataType mem_type;
switch (data_type.getClass()) {
case H5T_INTEGER :
mem_type = PredType::NATIVE_INT;//H5T_NATIVE_INT;
if (sizeof(U)==sizeof(long)) {
mem_type = PredType::NATIVE_LONG;//H5T_NATIVE_LONG;
} else {
mem_type = PredType::NATIVE_INT; //H5T_NATIVE_INT;
}
break;
case H5T_FLOAT :
if (sizeof(U)==sizeof(double)) {
......
......@@ -114,14 +114,24 @@ template <class T> bool CSnapshotNemoIn<T>::isValidNemo()
std::string io_nemo_select=realString();
io_nemo_select+=",read,sp,n,pos,vel,mass,dens,aux,acc,pot,key,e,t,st,b";
int * int_iokeys=NULL; // to read keys as int
//select_time="all";
std::string force_select = "all";
status_ionemo=io_nemo(this->filename.c_str(),io_nemo_select.c_str(),
force_select.c_str(),&ionbody,&iopos,&iovel,&iomass,&iorho,&ioaux,&ioacc,&iopot,&iokeys,&ioeps,
force_select.c_str(),&ionbody,&iopos,&iovel,&iomass,&iorho,&ioaux,&ioacc,&iopot,&int_iokeys,&ioeps,
&iotime, this->select_time.c_str(),&nemobits);
full_nbody = *ionbody;
// convert int to longint
if (int_iokeys != NULL) {
if (iokeys) delete [] iokeys;
iokeys = new long int[full_nbody];
for (long int i=0; i<full_nbody; i++) {
iokeys[i]=int_iokeys[i];
}
delete [] int_iokeys;
}
}
else { // Normal file
stream str=stropen(this->filename.c_str(),(char *) "r"); // open NEMO file for reading
......@@ -130,7 +140,7 @@ template <class T> bool CSnapshotNemoIn<T>::isValidNemo()
else status = false; // it's not
strclose(str);
if (status) { // it's a NEMO snapshot
long int * ptr=NULL; // get the full nbody
int * ptr=NULL; // get the full nbody
std::string io_nemo_select=realString();
io_nemo_select+=",read,n,t,b";
if (io_nemo(this->filename.c_str(),io_nemo_select.c_str(),&ptr,&iotime,&nemobits) != 0) {
......@@ -139,7 +149,7 @@ template <class T> bool CSnapshotNemoIn<T>::isValidNemo()
}
assert(ptr);
full_nbody=*ptr;
free((long int *) ptr);
free((int *) ptr);
}
}
this->valid=status;
......@@ -181,12 +191,22 @@ template <class T> int CSnapshotNemoIn<T>::nextFrame(uns::UserSelection &user_se
int status; // io_nemo status
std::string force_select = "all";
if (! first_stream) { // normal file or second reading (stream)
int * int_iokeys=NULL; // to read keys as int
std::string io_nemo_select=realString();
io_nemo_select+=",read,sp,n,pos,vel,mass,dens,aux,acc,pot,key,e,t,st,b";
status=io_nemo(this->filename.c_str(),io_nemo_select.c_str(),
force_select.c_str(),&ionbody,&iopos,&iovel,&iomass,&iorho,&ioaux,&ioacc,&iopot,&iokeys,&ioeps,
force_select.c_str(),&ionbody,&iopos,&iovel,&iomass,&iorho,&ioaux,&ioacc,&iopot,&int_iokeys,&ioeps,
&iotime, this->select_time.c_str(),&nemobits);
full_nbody = *ionbody;
// convert int to longint
if (int_iokeys != NULL) {
if (iokeys) delete [] iokeys;
iokeys = new long int[full_nbody];
for (long int i=0; i<full_nbody; i++) {
iokeys[i]=int_iokeys[i];
}
delete [] int_iokeys;
}
this->crvs = getSnapshotRange();
user_select.setSelection(user_select.getSelection(),this->crvs);
......@@ -597,6 +617,7 @@ template <class T> CSnapshotNemoOut<T>::CSnapshotNemoOut(const std::string _n, c
pot = NULL;
rho = NULL;
keys = NULL;
int_keys = NULL;
eps = NULL;
ptrIsAlloc["mass" ]=false;
......@@ -628,6 +649,8 @@ template <class T> CSnapshotNemoOut<T>::~CSnapshotNemoOut()
if (eps && ptrIsAlloc["eps" ]) delete [] eps;
if ((keys && ptrIsAlloc["keys"]) ||
(keys && ptrIsAlloc["id" ]) ) delete [] keys;
if ((int_keys && ptrIsAlloc["keys"]) ||
(int_keys && ptrIsAlloc["id" ]) ) delete [] int_keys;
if (rho && ptrIsAlloc["rho" ]) delete [] rho;
close();
}
......@@ -865,8 +888,15 @@ template <class T> int CSnapshotNemoOut<T>::save()
io_nemo_select += ",save,n,t,x,v,m,p,a,aux,k,dens,e,b";
if (this->simname=="." || this->simname=="-" || (this->simname!="-" && !tools::Ctools::isFileExist(this->simname))) {
// convert long int to int
if (keys!=NULL) {
int_keys = new int[nbody];
for (long int i=0; i<nbody; i++) {
int_keys[i]=keys[i];
}
}
status=io_nemo(this->simname.c_str(),io_nemo_select.c_str(),
&n,&t,&pos,&vel,&mass,&pot,&acc,&aux,&keys,&rho,&eps,&b);
&n,&t,&pos,&vel,&mass,&pot,&acc,&aux,&int_keys,&rho,&eps,&b);
} else {
std::cerr << "\n\nfile ["<<this->simname<<"] exist, NEMO output cannot overwrite files, please remove it !!!\nAborting...\n\n";
std::exit(0);
......
......@@ -112,6 +112,7 @@ private:
T * mass, * pos, * vel, * aux, * acc, * pot, * rho, * eps;
T time;
long int * keys;
int * int_keys;
long int nbody;
long int bits;
bool is_saved, is_closed;
......
......@@ -58,7 +58,7 @@
namespace uns {
const std::string VERSION="1.2.0.pre-November-24th-2016"; // UNSIO version
const std::string VERSION="1.2.0.pre-longint-November-26th-2016"; // UNSIO version
inline std::string getVersion() { return uns::VERSION; }
......
Supports Markdown
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