Transformed to CMake makefile

This commit is contained in:
Guilhem Lavaux 2010-09-12 21:09:39 +02:00
parent aac070e39f
commit f9bb9c64c5
6 changed files with 178 additions and 119 deletions

16
CMakeLists.txt Normal file
View 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)

View File

@ -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

View File

@ -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
View 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")

View File

@ -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,6 +95,10 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
return 0;
}
long NumPart = 0, NumPartTotal = 0;
try
{
f->beginCheckpoint();
for (int i = 0; i < 6; i++)
h.npart[i] = f->readInt32();
@ -112,14 +118,31 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
h.HubbleParam = f->readReal64();
f->endCheckpoint(true);
long NumPart = 0, NumPartTotal = 0;
for(int k=0; k<5; k++)
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;
}
if (loadflags & NEED_POSITION) {
@ -131,8 +154,10 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
}
}
try
{
f->beginCheckpoint();
for(int k = 0, p = 0; k < 5; k++) {
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();
@ -141,6 +166,14 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
}
}
f->endCheckpoint();
}
catch (const InvalidUnformattedAccess& e)
{
cerr << "Invalid format while reading positions" << endl;
delete f;
delete data;
return 0;
}
} else {
// Skip positions
@ -153,13 +186,16 @@ 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;
}
}
try
{
f->beginCheckpoint();
for(int k = 0, p = 0; k < 5; k++) {
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();
@ -168,6 +204,14 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
}
}
f->endCheckpoint();
}
catch (const InvalidUnformattedAccess& e)
{
cerr << "Invalid format while reading velocities" << endl;
delete f;
delete data;
return 0;
}
// TODO: FIX THE UNITS OF THESE FUNKY VELOCITIES !!!
} else {
@ -177,10 +221,13 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
// Skip ids
if (loadflags & NEED_GADGET_ID) {
try
{
f->beginCheckpoint();
data->Id = new int[data->NumPart];
if (data->Id == 0)
{
delete f;
delete data;
return 0;
}
@ -194,6 +241,14 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
}
}
f->endCheckpoint();
}
catch (const InvalidUnformattedAccess& e)
{
cerr << "Invalid formatted while reading ID" << endl;
delete f;
delete data;
return 0;
}
} else {
f->skip(2*4);
for (int k = 0; k < 6; k++)

View File

@ -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;
}