Transformed to CMake makefile
This commit is contained in:
parent
aac070e39f
commit
f9bb9c64c5
16
CMakeLists.txt
Normal file
16
CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
project(CosmoToolbox)
|
||||
|
||||
find_path(NETCDF_INCLUDE_PATH NAMES netcdf.h)
|
||||
|
||||
find_library(NETCDF_LIBRARY netcdf)
|
||||
find_library(NETCDFCPP_LIBRARY netcdf_c++)
|
||||
|
||||
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
set(NETCDF_FIND_REQUIRED TRUE)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NetCDF DEFAULT_MSG NETCDF_LIBRARY NETCDFCPP_LIBRARY NETCDF_INCLUDE_PATH)
|
||||
|
||||
add_subdirectory(src)
|
51
lib/Makefile
51
lib/Makefile
@ -1,51 +0,0 @@
|
||||
SHLIBS= libCosmoTool.$(SOSUFFIX)
|
||||
SOURCES= loadRamses.cpp yorick.cpp miniargs.cpp fortran.cpp interpolate.cpp load_data.cpp powerSpectrum.cpp octTree.cpp loadGadget.cpp
|
||||
LIBS= -lnetcdf_c++ -lnetcdf -lgsl -lgslcblas -lm
|
||||
|
||||
include config.mk
|
||||
|
||||
VPATH=../src
|
||||
|
||||
all: $(SHLIBS)
|
||||
|
||||
libCosmoTool.$(SOSUFFIX): loadRamses.o yorick.o miniargs.o fortran.o interpolate.o load_data.o powerSpectrum.o octTree.o loadGadget.o
|
||||
|
||||
depend: $(SOURCES)
|
||||
@echo "[DEPENDS] $^"
|
||||
@$(CC) $(CPPFLAGS) -M -MM $^ > .mydepends
|
||||
|
||||
install:
|
||||
@mkdir -p ../install/lib
|
||||
@mkdir -p ../install/include/CosmoTool
|
||||
@echo "Copying libraries"
|
||||
@cp libCosmoTool.$(SOSUFFIX) ../install/lib
|
||||
@echo "Copying header files"
|
||||
@cp ../src/*.hpp ../install/include/CosmoTool
|
||||
@cp ../src/*.tcc ../install/include/CosmoTool
|
||||
|
||||
distclean: clean
|
||||
@rm -f .mydepends
|
||||
|
||||
clean:
|
||||
@rm -f *.o
|
||||
@rm -f $(PROGS)
|
||||
|
||||
.mydepends: depend Makefile config.mk
|
||||
|
||||
%.$(SOSUFFIX):
|
||||
@echo "[LINK SHARED] $@"
|
||||
@$(CXX) $(SOFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
|
||||
|
||||
%.prog:
|
||||
@echo "[L] $@"
|
||||
@$(CXX) -o $@ $^ $(LDFLAGS) $(LIBS)
|
||||
|
||||
%.o: %.c
|
||||
@echo "[C] $< ..."
|
||||
@$(CC) -c -fPIC -o $@ $< $(CPPFLAGS) $(CFLAGS)
|
||||
|
||||
%.o: %.cpp
|
||||
@echo "[C++] $< ..."
|
||||
@$(CXX) -c -fPIC -o $@ $< $(CPPFLAGS) $(CXXFLAGS)
|
||||
|
||||
include .mydepends
|
@ -1,9 +0,0 @@
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
CFLAGS=-ggdb -O0
|
||||
CXXFLAGS=-ggdb -O0
|
||||
LDFLAGS=
|
||||
CPPFLAGS=
|
||||
|
||||
SOSUFFIX=so
|
||||
SOFLAGS=-shared
|
45
src/CMakeLists.txt
Normal file
45
src/CMakeLists.txt
Normal file
@ -0,0 +1,45 @@
|
||||
SET(CosmoTool_SRCS
|
||||
fortran.cpp
|
||||
interpolate.cpp
|
||||
load_data.cpp
|
||||
loadGadget.cpp
|
||||
loadRamses.cpp
|
||||
octTree.cpp
|
||||
powerSpectrum.cpp
|
||||
yorick.cpp
|
||||
)
|
||||
|
||||
SET(CosmoTool_SRCS
|
||||
bqueue.hpp
|
||||
config.hpp
|
||||
dinterpolate.hpp
|
||||
field.hpp
|
||||
fixArray.hpp
|
||||
fortran.hpp
|
||||
interpolate3d.hpp
|
||||
interpolate.hpp
|
||||
kdtree_leaf.hpp
|
||||
linalg.hpp
|
||||
load_data.hpp
|
||||
loadGadget.hpp
|
||||
loadRamses.hpp
|
||||
loadSimu.hpp
|
||||
miniargs.cpp
|
||||
miniargs.hpp
|
||||
mykdtree.hpp
|
||||
octTree.hpp
|
||||
powerSpectrum.hpp
|
||||
sparseGrid.hpp
|
||||
sphSmooth.hpp
|
||||
yorick.hpp
|
||||
)
|
||||
|
||||
add_library(CosmoTool SHARED ${CosmoTool_SRCS})
|
||||
target_link_libraries(CosmoTool ${NETCDF_LIBRARY} ${NETCDFCPP_LIBRARY})
|
||||
|
||||
install(TARGETS CosmoTool
|
||||
LIBRARY DESTINATION lib)
|
||||
install(DIRECTORY . DESTINATION include/CosmoTool
|
||||
FILES_MATCHING PATTERN "*.hpp")
|
||||
install(DIRECTORY . DESTINATION include/CosmoTool
|
||||
FILES_MATCHING PATTERN "*.tcc")
|
@ -1,3 +1,4 @@
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -6,6 +7,7 @@
|
||||
#include "fortran.hpp"
|
||||
|
||||
using namespace CosmoTool;
|
||||
using namespace std;
|
||||
|
||||
PurePositionData *CosmoTool::loadGadgetPosition(const char *fname)
|
||||
{
|
||||
@ -93,33 +95,54 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
f->beginCheckpoint();
|
||||
for (int i = 0; i < 6; i++)
|
||||
h.npart[i] = f->readInt32();
|
||||
for (int i = 0; i < 6; i++)
|
||||
h.mass[i] = f->readReal64();
|
||||
data->time = h.time = f->readReal64();
|
||||
h.redshift = f->readReal64();
|
||||
h.flag_sfr = f->readInt32();
|
||||
h.flag_feedback = f->readInt32();
|
||||
for (int i = 0; i < 6; i++)
|
||||
h.npartTotal[i] = f->readInt32();
|
||||
h.flag_cooling = f->readInt32();
|
||||
h.num_files = f->readInt32();
|
||||
data->BoxSize = h.BoxSize = f->readReal64();
|
||||
h.Omega0 = f->readReal64();
|
||||
h.OmegaLambda = f->readReal64();
|
||||
h.HubbleParam = f->readReal64();
|
||||
f->endCheckpoint(true);
|
||||
|
||||
long NumPart = 0, NumPartTotal = 0;
|
||||
for(int k=0; k<5; k++)
|
||||
|
||||
try
|
||||
{
|
||||
NumPart += h.npart[k];
|
||||
NumPartTotal += (id < 0) ? h.npart[k] : h.npartTotal[k];
|
||||
f->beginCheckpoint();
|
||||
for (int i = 0; i < 6; i++)
|
||||
h.npart[i] = f->readInt32();
|
||||
for (int i = 0; i < 6; i++)
|
||||
h.mass[i] = f->readReal64();
|
||||
data->time = h.time = f->readReal64();
|
||||
h.redshift = f->readReal64();
|
||||
h.flag_sfr = f->readInt32();
|
||||
h.flag_feedback = f->readInt32();
|
||||
for (int i = 0; i < 6; i++)
|
||||
h.npartTotal[i] = f->readInt32();
|
||||
h.flag_cooling = f->readInt32();
|
||||
h.num_files = f->readInt32();
|
||||
data->BoxSize = h.BoxSize = f->readReal64();
|
||||
h.Omega0 = f->readReal64();
|
||||
h.OmegaLambda = f->readReal64();
|
||||
h.HubbleParam = f->readReal64();
|
||||
f->endCheckpoint(true);
|
||||
|
||||
for(int k=0; k<6; k++)
|
||||
{
|
||||
NumPart += h.npart[k];
|
||||
NumPartTotal += (id < 0) ? h.npart[k] : h.npartTotal[k];
|
||||
}
|
||||
data->NumPart = NumPart;
|
||||
data->TotalNumPart = NumPartTotal;
|
||||
}
|
||||
catch (const InvalidUnformattedAccess& e)
|
||||
{
|
||||
cerr << "Invalid format while reading header" << endl;
|
||||
delete data;
|
||||
delete f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (loadflags & NEED_TYPE)
|
||||
{
|
||||
int p = 0;
|
||||
|
||||
data->type = new int[data->NumPart];
|
||||
for (int k = 0; k < 6; k++)
|
||||
for (int n = 0; n < h.npart[k]; n++,p++)
|
||||
data->type[p] = k;
|
||||
}
|
||||
data->NumPart = NumPart;
|
||||
data->TotalNumPart = NumPartTotal;
|
||||
|
||||
if (loadflags & NEED_POSITION) {
|
||||
|
||||
@ -130,17 +153,27 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
f->beginCheckpoint();
|
||||
for(int k = 0, p = 0; k < 5; k++) {
|
||||
for(int n = 0; n < h.npart[k]; n++) {
|
||||
data->Pos[0][p] = f->readReal32();
|
||||
data->Pos[1][p] = f->readReal32();
|
||||
data->Pos[2][p] = f->readReal32();
|
||||
p++;
|
||||
|
||||
try
|
||||
{
|
||||
f->beginCheckpoint();
|
||||
for(int k = 0, p = 0; k < 6; k++) {
|
||||
for(int n = 0; n < h.npart[k]; n++) {
|
||||
data->Pos[0][p] = f->readReal32();
|
||||
data->Pos[1][p] = f->readReal32();
|
||||
data->Pos[2][p] = f->readReal32();
|
||||
p++;
|
||||
}
|
||||
}
|
||||
f->endCheckpoint();
|
||||
}
|
||||
catch (const InvalidUnformattedAccess& e)
|
||||
{
|
||||
cerr << "Invalid format while reading positions" << endl;
|
||||
delete f;
|
||||
delete data;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
f->endCheckpoint();
|
||||
|
||||
} else {
|
||||
// Skip positions
|
||||
@ -153,21 +186,32 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
|
||||
data->Vel[i] = new float[data->NumPart];
|
||||
if (data->Vel[i] == 0)
|
||||
{
|
||||
delete f;
|
||||
delete data;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
f->beginCheckpoint();
|
||||
for(int k = 0, p = 0; k < 5; k++) {
|
||||
for(int n = 0; n < h.npart[k]; n++) {
|
||||
data->Vel[0][p] = f->readReal32();
|
||||
data->Vel[1][p] = f->readReal32();
|
||||
data->Vel[2][p] = f->readReal32();
|
||||
p++;
|
||||
|
||||
try
|
||||
{
|
||||
f->beginCheckpoint();
|
||||
for(int k = 0, p = 0; k < 6; k++) {
|
||||
for(int n = 0; n < h.npart[k]; n++) {
|
||||
data->Vel[0][p] = f->readReal32();
|
||||
data->Vel[1][p] = f->readReal32();
|
||||
data->Vel[2][p] = f->readReal32();
|
||||
p++;
|
||||
}
|
||||
}
|
||||
f->endCheckpoint();
|
||||
}
|
||||
catch (const InvalidUnformattedAccess& e)
|
||||
{
|
||||
cerr << "Invalid format while reading velocities" << endl;
|
||||
delete f;
|
||||
delete data;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
f->endCheckpoint();
|
||||
|
||||
// TODO: FIX THE UNITS OF THESE FUNKY VELOCITIES !!!
|
||||
} else {
|
||||
@ -177,23 +221,34 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
|
||||
|
||||
// Skip ids
|
||||
if (loadflags & NEED_GADGET_ID) {
|
||||
f->beginCheckpoint();
|
||||
data->Id = new int[data->NumPart];
|
||||
if (data->Id == 0)
|
||||
try
|
||||
{
|
||||
f->beginCheckpoint();
|
||||
data->Id = new int[data->NumPart];
|
||||
if (data->Id == 0)
|
||||
{
|
||||
delete f;
|
||||
delete data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(int k = 0, p = 0; k < 6; k++)
|
||||
{
|
||||
for(int n = 0; n < h.npart[k]; n++)
|
||||
{
|
||||
data->Id[p] = f->readInt32();
|
||||
p++;
|
||||
}
|
||||
}
|
||||
f->endCheckpoint();
|
||||
}
|
||||
catch (const InvalidUnformattedAccess& e)
|
||||
{
|
||||
cerr << "Invalid formatted while reading ID" << endl;
|
||||
delete f;
|
||||
delete data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(int k = 0, p = 0; k < 6; k++)
|
||||
{
|
||||
for(int n = 0; n < h.npart[k]; n++)
|
||||
{
|
||||
data->Id[p] = f->readInt32();
|
||||
p++;
|
||||
}
|
||||
}
|
||||
f->endCheckpoint();
|
||||
} else {
|
||||
f->skip(2*4);
|
||||
for (int k = 0; k < 6; k++)
|
||||
|
@ -7,7 +7,7 @@ namespace CosmoTool
|
||||
static const int NEED_GADGET_ID = 1;
|
||||
static const int NEED_POSITION = 2;
|
||||
static const int NEED_VELOCITY = 4;
|
||||
|
||||
static const int NEED_TYPE = 8;
|
||||
|
||||
class SimuData
|
||||
{
|
||||
@ -20,8 +20,9 @@ namespace CosmoTool
|
||||
int *Id;
|
||||
float *Pos[3];
|
||||
float *Vel[3];
|
||||
int *type;
|
||||
public:
|
||||
SimuData() : Id(0),NumPart(0) { Pos[0]=Pos[1]=Pos[2]=0; Vel[0]=Vel[1]=Vel[2]=0; }
|
||||
SimuData() : Id(0),NumPart(0),type(0) { Pos[0]=Pos[1]=Pos[2]=0; Vel[0]=Vel[1]=Vel[2]=0; }
|
||||
~SimuData()
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
@ -31,6 +32,8 @@ namespace CosmoTool
|
||||
if (Vel[j])
|
||||
delete[] Vel[j];
|
||||
}
|
||||
if (type)
|
||||
delete[] type;
|
||||
if (Id)
|
||||
delete[] Id;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user