Commit 65aed0ce authored by jclamber's avatar jclamber

merge branches template + hdf5 to trunk

git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@248 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent 10ed299f
# ============================================================================ # ============================================================================
# Copyright Jean-Charles LAMBERT - 2008-2015 # Copyright Jean-Charles LAMBERT - 2008-2016
# Centre de donneeS Astrophysiques de Marseille (CeSAM) # Centre de donneeS Astrophysiques de Marseille (CeSAM)
# e-mail: Jean-Charles.Lambert@lam.fr # e-mail: Jean-Charles.Lambert@lam.fr
# address: Aix Marseille Universite, CNRS, LAM # address: Aix Marseille Universite, CNRS, LAM
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
#INCLUDE(CPack) #INCLUDE(CPack)
# project name # project name
project (UNSIO) project (UNSIO2)
SET(CMAKE_VERBOSE_MAKEFILE OFF) SET(CMAKE_VERBOSE_MAKEFILE OFF)
...@@ -45,6 +45,10 @@ MESSAGE( STATUS "BUILD_TYPE =" ${RELEASE} ) ...@@ -45,6 +45,10 @@ MESSAGE( STATUS "BUILD_TYPE =" ${RELEASE} )
FIND_PACKAGE(NEMO) FIND_PACKAGE(NEMO)
FIND_PACKAGE(SQLITE3) FIND_PACKAGE(SQLITE3)
FIND_PACKAGE(HDF5 COMPONENTS CXX)
#SET(HDF5_CXX_LIBRARIES hdf5_hl_cpp hdf5_cpp)
MESSAGE( STATUS "HDF5_CXX_LIBRARIES=" ${HDF5_CXX_LIBRARIES})
#set (NEMO_INSTALLED FALSE) # fore NEMO not installed #set (NEMO_INSTALLED FALSE) # fore NEMO not installed
IF (NOT NEMO_INSTALLED) IF (NOT NEMO_INSTALLED)
...@@ -80,10 +84,17 @@ SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} ${WARNF}) ...@@ -80,10 +84,17 @@ SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} ${WARNF})
STRING(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) STRING(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
# create library "uns" # create library "uns"
add_library (unsio ${LIBTYPE} ${LIBSOURCES} ) add_library (unsio ${LIBTYPE} ${LIBSOURCES})
if(OSX) if(OSX)
set_target_properties(unsio PROPERTIES LINK_FLAGS "-undefined suppress -flat_namespace -L${NEMOLIB} -lnemo -lsqlite3") set_target_properties(unsio PROPERTIES LINK_FLAGS "-undefined suppress -flat_namespace -L${NEMOLIB} -lnemo -lsqlite3")
else(OSX)
# add " " after .so
string(REPLACE ".so" ".so " HDF5_CXX_LIBRARIES_LIST ${HDF5_CXX_LIBRARIES})
message(STATUS "HDF5_CXX_LIBRARIES_LIST = " ${HDF5_CXX_LIBRARIES_LIST})
# libk unsio against hdf5 and sqlit3
set_target_properties(unsio PROPERTIES LINK_FLAGS "${HDF5_CXX_LIBRARIES_LIST} -lsqlite3")
endif(OSX) endif(OSX)
# ---------------------------------------------------------- # ----------------------------------------------------------
...@@ -130,10 +141,12 @@ set(EXECUTABLE_OUTPUT_PATH bin) ...@@ -130,10 +141,12 @@ set(EXECUTABLE_OUTPUT_PATH bin)
MESSAGE( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} ) MESSAGE( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} )
# Make sure the compiler can find include files from our Hello library. # Make sure the compiler can find include files from our Hello library.
include_directories (${UNSIO_SOURCE_DIR}/src ${NEMOINC} ${NEMOLIB} ${SQLITE3_H_PATH} /usr/include/malloc) include_directories (${UNSIO2_SOURCE_DIR}/src ${NEMOINC} ${NEMOLIB} ${SQLITE3_H_PATH})
include_directories (/usr/include/malloc ${HDF5_INCLUDE_DIR})
# Make sure the linker can find the Hello library once it is built. # Make sure the linker can find the Hello library once it is built.
link_directories (${UNSIO_BINARY_DIR}/lib /usr/X11/lib ${SQLITE3_LIB_PATH} ${NEMOLIB} ${FC_GFORT_PATH} ${FC_G77_PATH}) link_directories (${UNSIO2_BINARY_DIR}/lib /usr/X11/lib ${SQLITE3_LIB_PATH} )
link_directories ( ${NEMOLIB} ${FC_GFORT_PATH} ${FC_G77_PATH} )
# Find all LIB's sources files # Find all LIB's sources files
FILE(GLOB exe_sources test_src/*.F) FILE(GLOB exe_sources test_src/*.F)
...@@ -152,7 +165,7 @@ FOREACH(exe_cpp ${execpp_sources}) ...@@ -152,7 +165,7 @@ FOREACH(exe_cpp ${execpp_sources})
add_executable (${exe} ${exe_cpp}) add_executable (${exe} ${exe_cpp})
# Link the executable to the Hello library. # Link the executable to the Hello library.
target_link_libraries (${exe} unsio nemo ${SQLITE3_LIB} ${FC_GFORT_LIB} ${FC_G77_LIB} stdc++) target_link_libraries (${exe} unsio nemo ${FC_GFORT_LIB} ${FC_G77_LIB} stdc++)
IF (${exe} STREQUAL "uns_info") IF (${exe} STREQUAL "uns_info")
INSTALL(TARGETS ${exe} RUNTIME DESTINATION bin) INSTALL(TARGETS ${exe} RUNTIME DESTINATION bin)
ENDIF() ENDIF()
...@@ -171,7 +184,7 @@ FOREACH(exe_f ${exe_sources}) ...@@ -171,7 +184,7 @@ FOREACH(exe_f ${exe_sources})
# Link the executable to the Hello library. # Link the executable to the Hello library.
#target_link_libraries (${exe} unsio nemomaing77 nemo g2c sqlite3 stdc++) #target_link_libraries (${exe} unsio nemomaing77 nemo g2c sqlite3 stdc++)
target_link_libraries (${exe} unsio nemomaing77 nemo ${SQLITE3_LIB} ${FC_LIB} stdc++) target_link_libraries (${exe} unsio nemomaing77 nemo ${FC_LIB} stdc++)
SET_TARGET_PROPERTIES(${exe} PROPERTIES LINKER_LANGUAGE Fortran) SET_TARGET_PROPERTIES(${exe} PROPERTIES LINKER_LANGUAGE Fortran)
# add "-lstdc++" # add "-lstdc++"
...@@ -185,12 +198,12 @@ endif() ...@@ -185,12 +198,12 @@ endif()
# ---------------------------------------------------------- # ----------------------------------------------------------
# UNS specific includes # UNS specific includes
INSTALL(FILES ${UNSIO_BINARY_DIR}/../src/uns.h DESTINATION inc/uns) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../src/uns.h DESTINATION inc/uns)
INSTALL(FILES ${UNSIO_BINARY_DIR}/../src/unsdebug.h DESTINATION inc/uns) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../src/unsdebug.h DESTINATION inc/uns)
INSTALL(FILES ${UNSIO_BINARY_DIR}/../src/snapshotinterface.h DESTINATION inc/uns) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../src/snapshotinterface.h DESTINATION inc/uns)
INSTALL(FILES ${UNSIO_BINARY_DIR}/../src/componentrange.h DESTINATION inc/uns) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../src/componentrange.h DESTINATION inc/uns)
INSTALL(FILES ${UNSIO_BINARY_DIR}/../src/ctools.h DESTINATION inc/uns) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../src/ctools.h DESTINATION inc/uns)
INSTALL(FILES ${UNSIO_BINARY_DIR}/../src/userselection.h DESTINATION inc/uns) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../src/userselection.h DESTINATION inc/uns)
# NEMO specific includes # NEMO specific includes
IF (NOT NEMO_INSTALLED) IF (NOT NEMO_INSTALLED)
...@@ -213,19 +226,19 @@ IF (NOT NEMO_INSTALLED) ...@@ -213,19 +226,19 @@ IF (NOT NEMO_INSTALLED)
ENDIF() ENDIF()
# unsio lib # unsio lib
INSTALL(FILES ${UNSIO_BINARY_DIR}/lib/libunsio.${LIBEXT} DESTINATION lib) INSTALL(FILES ${UNSIO2_BINARY_DIR}/lib/libunsio.${LIBEXT} DESTINATION lib)
# man # man
INSTALL(FILES ${UNSIO_BINARY_DIR}/../man/man3/unsiof.3 DESTINATION man/man3) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../man/man3/unsiof.3 DESTINATION man/man3)
# some binaries # some binaries
# install sqlite3 database files # install sqlite3 database files
INSTALL(PROGRAMS ${UNSIO_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_get_info.pl DESTINATION bin) INSTALL(PROGRAMS ${UNSIO2_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_get_info.pl DESTINATION bin)
INSTALL(PROGRAMS ${UNSIO_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_update_info.pl DESTINATION bin) INSTALL(PROGRAMS ${UNSIO2_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_update_info.pl DESTINATION bin)
INSTALL(PROGRAMS ${UNSIO_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_update_nemorange.pl DESTINATION bin) INSTALL(PROGRAMS ${UNSIO2_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_update_nemorange.pl DESTINATION bin)
INSTALL(PROGRAMS ${UNSIO_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_create_db.pl DESTINATION bin) INSTALL(PROGRAMS ${UNSIO2_BINARY_DIR}/../scripts/perl/mains/unsio_sql3_create_db.pl DESTINATION bin)
INSTALL(FILES ${UNSIO_BINARY_DIR}/../scripts/perl/lib/Tools/Tools.pm DESTINATION scripts/perl/lib/Tools) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../scripts/perl/lib/Tools/Tools.pm DESTINATION scripts/perl/lib/Tools)
INSTALL(FILES ${UNSIO_BINARY_DIR}/../scripts/perl/lib/Tools/Sqlite3.pm DESTINATION scripts/perl/lib/Tools) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../scripts/perl/lib/Tools/Sqlite3.pm DESTINATION scripts/perl/lib/Tools)
INSTALL(FILES ${UNSIO_BINARY_DIR}/../scripts/sql/create_unsio_db.sql DESTINATION scripts/sql) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../scripts/sql/create_unsio_db.sql DESTINATION scripts/sql)
INSTALL(FILES ${UNSIO_BINARY_DIR}/../scripts/sql/README DESTINATION scripts/sql) INSTALL(FILES ${UNSIO2_BINARY_DIR}/../scripts/sql/README DESTINATION scripts/sql)
2.0.0 (dev)
------------
- new API for reading/writing in float and double
1.1.0 (February 2015) 1.1.0 (February 2015)
----------------------- -----------------------
- Ramses: 2D support - Ramses: 2D support
......
# -*-cmake-*- # -*-cmake-*-
# ============================================================================ # ============================================================================
# Copyright Jean-Charles LAMBERT - 2008-2015 # Copyright Jean-Charles LAMBERT - 2008-2016
# e-mail: Jean-Charles.Lambert@oamp.fr # e-mail: Jean-Charles.Lambert@oamp.fr
# address: Dynamique des galaxies # address: Dynamique des galaxies
# Centre de donneeS Astrophysique de Marseille (CeSAM) # Centre de donneeS Astrophysique de Marseille (CeSAM)
...@@ -38,4 +38,4 @@ if (CMAKE_Fortran_COMPILER) ...@@ -38,4 +38,4 @@ if (CMAKE_Fortran_COMPILER)
# gfortran # gfortran
set (EXTRA_Fortran_FLAGS " ${WARNF} -ffixed-line-length-none ") set (EXTRA_Fortran_FLAGS " ${WARNF} -ffixed-line-length-none ")
endif() endif()
endif() endif()
\ No newline at end of file
#-*-cmake-*- #-*-cmake-*-
# ============================================================================ # ============================================================================
# Copyright Jean-Charles LAMBERT - 2008-2015 # Copyright Jean-Charles LAMBERT - 2008-2016
# e-mail: Jean-Charles.Lambert@oamp.fr # e-mail: Jean-Charles.Lambert@oamp.fr
# address: Dynamique des galaxies # address: Dynamique des galaxies
# Centre de donneeS Astrophysique de Marseille (CeSAM) # Centre de donneeS Astrophysique de Marseille (CeSAM)
......
# -*-cmake-*- # -*-cmake-*-
# ============================================================================ # ============================================================================
# Copyright Jean-Charles LAMBERT - 2009-2015 # Copyright Jean-Charles LAMBERT - 2009-2016
# e-mail: Jean-Charles.Lambert@oamp.fr # e-mail: Jean-Charles.Lambert@oamp.fr
# address: Dynamique des galaxies # address: Dynamique des galaxies
# Centre de donneeS Astrophysique de Marseille (CeSAM) # Centre de donneeS Astrophysique de Marseille (CeSAM)
......
#-*-cmake-*- #-*-cmake-*-
# ============================================================================ # ============================================================================
# Copyright Jean-Charles LAMBERT - 2008-2015 # Copyright Jean-Charles LAMBERT - 2008-2016
# e-mail: Jean-Charles.Lambert@oamp.fr # e-mail: Jean-Charles.Lambert@oamp.fr
# address: Dynamique des galaxies # address: Dynamique des galaxies
# Centre de donneeS Astrophysique de Marseille (CeSAM) # Centre de donneeS Astrophysique de Marseille (CeSAM)
......
#!/usr/bin/python
#
# This program test unsio library by readind and saving same file in different output
# file format (gadget2, nemo) and comparing all arrays with original one
#
from __future__ import print_function
import sys
import argparse
import numpy as np # arrays are treated as numpy arrays
import os.path
#dirname, filename = os.path.split(os.path.abspath(__file__))
#sys.path.append(dirname+'../modules/') # trick to find modules directory
from py_unsio import *
import copy
import tempfile
from IPython import embed
class snap:
time = None
nbody = None
mass = None
pos = None
vel = None
id = None
age = None
hsml = None
rho = None
metal = None
interface = ""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line
def commandLine():
# help
parser = argparse.ArgumentParser(description="test unsio library",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# options
parser.add_argument('simname', help='Simulation name')
parser.add_argument('component', help='component name')
float_parser=parser.add_mutually_exclusive_group(required=True)
float_parser.add_argument('--float', help='floating format operation',action='store_true')
float_parser.add_argument('--double', help='double format operation', action='store_true')
parser.add_argument('--out', help='save output file name ?',default="")
# parse
args = parser.parse_args()
# start main funciton
process(args)
# -----------------------------------------------------
def readSnap(simname, comp, single):
components=comp
verbose=False
#timef=float(times)
# Create a UNSIO object
if (single) :
print("Float format object")
uns = CunsIn(simname,components,"all",verbose)
else:
print("Double format object")
uns = CunsInD(simname,components,"all",verbose)
print ("simname=",simname,file=sys.stderr)
mysnap=snap() # instantiate a snap object
# load frame
ok=uns.nextFrame("")
#print ok
if (ok) :
#embed()
mysnap.interface = uns.getInterfaceType()
ok,mysnap.time = uns.getValueF("time")
ok,mysnap.pos = uns.getArrayF(comp,"pos")
ok,mysnap.vel = uns.getArrayF(comp,"vel")
ok,mysnap.mass = uns.getArrayF(comp,"mass")
ok,mysnap.hsml = uns.getArrayF(comp,"hsml")
ok,mysnap.rho = uns.getArrayF(comp,"rho")
ok,mysnap.age = uns.getArrayF(comp,"age")
ok,mysnap.metal= uns.getArrayF(comp,"metal")
if ok:
mysnap.metal=fixMetal(mysnap.metal)
ok,mysnap.id = uns.getArrayI(comp,"id")
uns.close()
return True,copy.deepcopy(mysnap)
else :
print ("Didn't load anything....",file=sys.stderr)
return False
# -----------------------------------------------------
def saveSnap(insnap,comp,unstype,single):
if (unstype=="nemo"):
comp="all"
if (unstype=="gadget2" and insnap.interface=="Nemo"):
comp="gas"
# create a temporary name file
f = tempfile.NamedTemporaryFile()
myfile=f.name # get filename
f.close() # remode temporary file
## SAVE FILE
# instantiate output object
if (single):
unso=CunsOut(myfile,unstype); # output file
else:
unso=CunsOutD(myfile,unstype); # output file
print("\nSaving in ",unstype," format......")
if (insnap.time) :
unso.setValueF("time",insnap.time) # save time
# proceed on all real array
for attr in ("pos","vel","mass","age","hsml","rho","metal","id"):
name=getattr(insnap,attr)
if (name.size and attr=="id"):
print("save -> ",attr)
unso.setArrayI(comp,attr,name) # save integer array
else :
if (name.size) :
print("save -> ",attr)
unso.setArrayF(comp,attr,name) # save real arrays
unso.save()
unso.close()
## 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
disp=True
if notCompare(CA,CB,attr):
disp=False
else:
if attr=="time":
ok = (A==B)
else:
ok=(A==B).all()
if ok :
if (A.size):
disp=True
else:
disp=False
if (disp):
print("[",attr,"]",ok)
if not ok:
print("\tA:",A[0:2],"\n\tB:",B[0:2])
# -----------------------------------------------------
# do not compare in the following cases
def notCompare(CA,CB,attr):
status=False
if (CA.interface=="Nemo" or CB.interface=="Nemo"):
if attr=="metal":
status=True
if attr=="age":
status=True
if status:
print("<",attr,"> attribute not supported with NEMO format")
A=getattr(CA,attr)
if (attr != "time" and A.size==0):
status=True
print("In <",attr,"> attribute not tested")
return status
# -----------------------------------------------------
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"):
compareArray(CA,CB,attr)
# -----------------------------------------------------
def fixMetal(metal):
if (metal==-1.0).all() :
print("fixing metal....")
return np.empty(0)
else:
return metal
# -----------------------------------------------------
# process
def process(args):
print("simname = ",args.simname)
ok,insnap=readSnap(args.simname,args.component,args.float)
ok,svsnap=saveSnap(insnap,args.component,"gadget2",args.float)
ok,nemosnap=saveSnap(insnap,args.component,"nemo",args.float)
compare(insnap,svsnap)
compare(insnap,nemosnap)
# -----------------------------------------------------
# main program
commandLine() # parse command line
#
...@@ -28,40 +28,60 @@ ...@@ -28,40 +28,60 @@
import_array(); import_array();
%} %}
// getArrayX return 1D numpy array // getArrayX return 1D numpy float array
%apply ( int* DIM1, float ** ARGOUTVIEW_ARRAY1 ) %apply ( int* DIM1, float ** ARGOUTVIEW_ARRAY1 )
{( int* size, float ** farray )}; {( int* size, float ** farray )};
//%apply ( int* DIM1, int ** ARGOUTVIEW_ARRAY1 )
// {( int* size, int ** iarray )};
// getArrayX return 1D numpy double array
%apply ( int* DIM1, double ** ARGOUTVIEW_ARRAY1 )
{( int* size, double ** farray )};
// getArrayX return 1D numpy int array
%apply ( int* DIM1, int ** ARGOUTVIEW_ARRAY1 ) %apply ( int* DIM1, int ** ARGOUTVIEW_ARRAY1 )
{( int* size, int ** iarray )}; {( int* size, int ** iarray )};
// getValueX return float/double/int value
// getValueX return float/int value %apply float *OUTPUT { float * fvalue };
%apply float *OUTPUT { float * fvalue }; %apply double *OUTPUT { double * fvalue };
%apply int *OUTPUT { int * ivalue }; %apply int *OUTPUT { int * ivalue };
// rename methods because of overloading limitations with swig c++ // rename methods because of overloading limitations with swig c++
// IMPORTANT :
// rename statement MUST be placed before inclusion of the header "%include uns.h"
// in order to be renamed
//float
%rename(getValueF) getData(const std::string,float *); %rename(getValueF) getData(const std::string,float *);
%rename(getArrayF) getData(const std::string,const std::string,int *,float **); %rename(getArrayF) getData(const std::string,const std::string,int *,float **);
%rename(getArrayF) getData(const std::string,int *,float **); %rename(getArrayF) getData(const std::string,int *,float **);
//double
%rename(getValueF) getData(const std::string,double *);
%rename(getArrayF) getData(const std::string,const std::string,int *,double **);
%rename(getArrayF) getData(const std::string,int *, double **);
//int
%rename(getValueI) getData(const std::string,int *); %rename(getValueI) getData(const std::string,int *);
%rename(getArrayI) getData(const std::string,const std::string,int *,int **); %rename(getArrayI) getData(const std::string,const std::string,int *,int **);
%rename(getArrayI) getData(const std::string,int *,int **); %rename(getArrayI) getData(const std::string,int *,int **);
// OUTPUT operations
//%apply float *INPUT { float * fvalue };
//%apply int *INPUT { int * ivalue };
%apply (int DIM1 , float * INPLACE_ARRAY1) {( int size, float * farray)}; %apply (int DIM1 , float * INPLACE_ARRAY1) {( int size, float * farray)};
%apply (int DIM1 , double* INPLACE_ARRAY1) {( int size, double* farray)};
%apply (int DIM1 , int * INPLACE_ARRAY1) {( int size, int * iarray)}; %apply (int DIM1 , int * INPLACE_ARRAY1) {( int size, int * iarray)};
// rename methods because of overloading limitations with swig c++ // rename methods because of overloading limitations with swig c++
// float
%rename(setValueF) setData(const std::string,float); %rename(setValueF) setData(const std::string,float);
%rename(setArrayF_do_not_used) setData(const std::string,const std::string,int ,float *,const bool _addr=false); %rename(setArrayF_do_not_used) setData(const std::string,const std::string,int ,float *,const bool _addr=false);
%rename(setArrayF_do_not_used) setData(const std::string,int ,float *,const bool _addr=false); %rename(setArrayF_do_not_used) setData(const std::string,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,int ,double *,const bool _addr=false);
%rename(setArrayF_do_not_used) setData(const std::string,int ,double *,const bool _addr=false);
// int
%rename(setValueI) setData(const std::string,int,const bool _addr=false); %rename(setValueI) setData(const std::string,int,const bool _addr=false);
%rename(setArrayI) setData(const std::string,const std::string,int ,int *,const bool _addr=false); %rename(setArrayI) setData(const std::string,const std::string,int ,int *,const bool _addr=false);
%rename(setArrayI) setData(const std::string,int ,int *); %rename(setArrayI) setData(const std::string,int ,int *);
...@@ -69,48 +89,31 @@ ...@@ -69,48 +89,31 @@
// Parse the original header file // Parse the original header file
%include "uns.h" %include "uns.h"
%extend uns::CunsIn { %extend uns::CunsOut2 {
// getFileName
std::string getFileName() {
std::string ret="";
if ($self->isValid() && $self->snapshot!=NULL ) {
ret=$self->snapshot->getFileName();
}
return ret;
}
// getFileStructure
std::string getFileStructure() {
std::string ret="";
if ($self->isValid() && $self->snapshot!=NULL ) {
ret=$self->snapshot->getFileStructure();
}
return ret;
}
// getInterfaceType
std::string getInterfaceType() {
std::string ret="";
if ($self->isValid() && $self->snapshot!=NULL ) {
ret=$self->snapshot->getInterfaceType();
}
return ret;
}
};
// Extend class
%extend uns::CunsOut {
// we rewrite setArrayF because numpy array size is different from nbody for 3D arrays // we rewrite setArrayF because numpy array size is different from nbody for 3D arrays
int setArrayF(const std::string comp,const std::string prop, int setArrayF(const std::string comp,const std::string prop,
int size,float * farray, const bool _addr=false) { int size,T * farray, const bool _addr=false) {
if (prop=="pos" || prop=="vel" || prop=="acc") size /= 3; if (prop=="pos" || prop=="vel" || prop=="acc") size /= 3;
int status = $self->snapshot->setData(comp,prop,size,farray,_addr); int status = $self->snapshot->setData(comp,prop,size,farray,_addr);
return status; return status;
} }
// we rewrite setArrayF because numpy array size is different from nbody for 3D arrays // we rewrite setArrayF because numpy array size is different from nbody for 3D arrays
int setArrayF(const std::string prop, int setArrayF(const std::string prop,
int size,float * farray, const bool _addr=false) { int size,T * farray, const bool _addr=false) {
if (prop=="pos" || prop=="vel" || prop=="acc") size /= 3; if (prop=="pos" || prop=="vel" || prop=="acc") size /= 3;
int status = $self->snapshot->setData(prop,size,farray,_addr); int status = $self->snapshot->setData(prop,size,farray,_addr);
return status; return status;
} }
}; };
// rename templates
// INPUT
%template(CunsIn) uns::CunsIn2<float>;
//%template(CunsInF) uns::CunsIn2<float>;
%template(CunsInD) uns::CunsIn2<double>;
// OUTPUT
//%template(CunsOutF) uns::CunsOut2<float>;
%template(CunsOut) uns::CunsOut2<float>;
%template(CunsOutD) uns::CunsOut2<double>;
# -----------------------------------------------------------------------
#!/usr/bin/python #!/usr/bin/python
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# The following program shows how to use UNSIO library from # The following program shows how to use UNSIO library from
...@@ -117,16 +116,17 @@ def compute(file,out,comp,times): ...@@ -117,16 +116,17 @@ def compute(file,out,comp,times):
print "file=",file, " outfile=",out," comp=",comp, " times=",times print "file=",file, " outfile=",out," comp=",comp, " times=",times
# instantiate a CunsIn object, here we request to load "all" components # instantiate a CunsIn object, here we request to load "all" components
uns=CunsIn(file,"all",times) uns=CunsInD(file,"all",times)
# load frame # load frame
cpt=0 cpt=0
while (uns.nextFrame("")): # load every snasphots while (uns.nextFrame("")): # load every snasphots
print "File structure : ", uns.getFileStructure(), " \n"
nameout=out+".%05d"%cpt # create out filename nameout=out+".%05d"%cpt # create out filename
print "Filename Out =",nameout print "Filename Out =",nameout
# instantiate a CunsOut object in "gadget2" format # instantiate a CunsOut object in "gadget2" format
unso=CunsOut(nameout,"gadget2") unso=CunsOutD(nameout,"gadget2")
ok,tsnap=uns.getValueF("time") # return snasphot time ok,tsnap=uns.getValueF("time") # return snasphot time
print "Snapshot time : ","%.03f"%tsnap print "Snapshot time : ","%.03f"%tsnap
......
#!/usr/bin/python
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# The following program shows how to use UNSIO library from # The following program shows how to use UNSIO library from
# a Python program # a Python program
...@@ -21,10 +22,10 @@ ...@@ -21,10 +22,10 @@
# unsio module (do not forget to update PYTHONPATH environment variable with # unsio module (do not forget to update PYTHONPATH environment variable with
# py_unsio location path) # py_unsio location path)
from py_unsio import *
import numpy as np import numpy as np
# cmd line # cmd line
import sys, getopt import sys, getopt
from py_unsio import *
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# printProp # printProp
......
// ============================================================================ // ============================================================================
// Copyright Jean-Charles LAMBERT - 2007-2015 // Copyright Jean-Charles LAMBERT - 2007-2016
// Centre de donneeS Astrophysiques de Marseille (CeSAM) // Centre de donneeS Astrophysiques de Marseille (CeSAM)
// e-mail: Jean-Charles.Lambert@lam.fr // e-mail: Jean-Charles.Lambert@lam.fr
// address: Aix Marseille Universite, CNRS, LAM // address: Aix Marseille Universite, CNRS, LAM
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "camr.h" #include "camr.h"
#include "cfortio.h" #include "cfortio.h"
#include "snapshotramses.h" #include "snapshotramses.h"
namespace ramses { namespace ramses {
const double CAmr::XH = 0.76; const double CAmr::XH = 0.76;
const double CAmr::mH = 1.6600000e-24; const double CAmr::mH = 1.6600000e-24;
...@@ -153,7 +154,11 @@ int CAmr::readHeader() ...@@ -153,7 +154,11 @@ int CAmr::readHeader()
} }
// ============================================================================ // ============================================================================
// loadData // loadData
int CAmr::loadData(uns::CParticles * particles, template int CAmr::loadData<float> (uns::CParticles<float> * particles,
const unsigned int req_bits);
template int CAmr::loadData<double> (uns::CParticles<double> * particles,
const unsigned int req_bits);
template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
const unsigned int req_bits) const unsigned int req_bits)
{