Missing updates...
This commit is contained in:
parent
fe289507c5
commit
c7d0974857
@ -15,8 +15,10 @@ find_path(NETCDFCPP_INCLUDE_PATH NAMES netcdfcpp.h netcdf)
|
||||
find_path(GSL_INCLUDE_PATH NAMES gsl/gsl_blas.h)
|
||||
|
||||
IF(EXISTS ${NETCDFCPP_INCLUDE_PATH}/netcdf)
|
||||
SET(FOUND_NETCDF4 1)
|
||||
FILE(WRITE ${CMAKE_BINARY_DIR}/src/ctool_netcdf_ver.hpp "#define NETCDFCPP4 1")
|
||||
ELSE(EXISTS ${NETCDFCPP_INCLUDE_PATH}/netcdf)
|
||||
SET(FOUND_NETCDF3 1)
|
||||
FILE(WRITE ${CMAKE_BINARY_DIR}/src/ctool_netcdf_ver.hpp "#undef NETCDFCPP4")
|
||||
ENDIF(EXISTS ${NETCDFCPP_INCLUDE_PATH}/netcdf)
|
||||
|
||||
|
@ -6,11 +6,16 @@ SET(CosmoTool_SRCS
|
||||
loadRamses.cpp
|
||||
octTree.cpp
|
||||
powerSpectrum.cpp
|
||||
yorick.cpp
|
||||
miniargs.cpp
|
||||
growthFactor.cpp
|
||||
)
|
||||
|
||||
IF(FOUND_NETCDF3)
|
||||
SET(CosmoTool_SRCS ${CosmoTool_SRCS} yorick_nc3.cpp)
|
||||
ELSEIF(FOUND_NETCDF4)
|
||||
SET(CosmoTool_SRCS ${CosmoTool_SRCS} yorick_nc4.cpp)
|
||||
ENDIF(FOUN_NETCDF3)
|
||||
|
||||
if (HDF5_FOUND)
|
||||
set(CosmoTool_SRCS ${CosmoTool_SRCS}
|
||||
h5_readFlash.cpp
|
||||
|
@ -1,11 +1,7 @@
|
||||
#include "ctool_netcdf_ver.hpp"
|
||||
#include "config.hpp"
|
||||
#ifdef NETCDFCPP4
|
||||
#include <netcdf>
|
||||
using namespace netCDF
|
||||
#else
|
||||
#include <netcdfcpp.h>
|
||||
#endif
|
||||
using namespace netCDF;
|
||||
#include <fstream>
|
||||
#include "yorick.hpp"
|
||||
#include <assert.h>
|
||||
@ -17,24 +13,24 @@ class NetCDF_handle
|
||||
{
|
||||
public:
|
||||
NcFile *outFile;
|
||||
NcVar *curVar;
|
||||
long *curPos;
|
||||
long *counts;
|
||||
long *dimList;
|
||||
NcVar curVar;
|
||||
vector<size_t> curPos;
|
||||
vector<size_t> counts;
|
||||
vector<NcDim> dimList;
|
||||
uint32_t rank;
|
||||
|
||||
NetCDF_handle(NcFile *f, NcVar *v, long *dimList, uint32_t rank);
|
||||
NetCDF_handle(NcFile *f, NcVar v, vector<NcDim>& dimList, uint32_t rank);
|
||||
virtual ~NetCDF_handle();
|
||||
};
|
||||
|
||||
NetCDF_handle::NetCDF_handle(NcFile *f, NcVar *v, long *dimList, uint32_t rank)
|
||||
NetCDF_handle::NetCDF_handle(NcFile *f, NcVar v, vector<NcDim>& dimList, uint32_t rank)
|
||||
{
|
||||
this->outFile = f;
|
||||
this->curVar = v;
|
||||
this->dimList = dimList;
|
||||
this->rank = rank;
|
||||
this->counts = new long[rank];
|
||||
this->curPos = new long[rank];
|
||||
this->counts.resize(rank);
|
||||
this->curPos.resize(rank);
|
||||
|
||||
for (long i = 0; i < rank; i++)
|
||||
this->curPos[i] = 0;
|
||||
@ -45,7 +41,6 @@ NetCDF_handle::NetCDF_handle(NcFile *f, NcVar *v, long *dimList, uint32_t rank)
|
||||
|
||||
NetCDF_handle::~NetCDF_handle()
|
||||
{
|
||||
delete[] dimList;
|
||||
delete outFile;
|
||||
}
|
||||
|
||||
@ -53,7 +48,7 @@ template<typename T>
|
||||
class InputGenCDF: public NetCDF_handle, public ProgressiveInputImpl<T>
|
||||
{
|
||||
public:
|
||||
InputGenCDF(NcFile *f, NcVar *v, long *dimList, uint32_t rank)
|
||||
InputGenCDF(NcFile *f, NcVar v, vector<NcDim>& dimList, uint32_t rank)
|
||||
: NetCDF_handle(f,v,dimList,rank)
|
||||
{}
|
||||
virtual ~InputGenCDF() {}
|
||||
@ -62,13 +57,12 @@ public:
|
||||
{
|
||||
T a;
|
||||
|
||||
curVar->set_cur(curPos);
|
||||
curVar->get(&a, counts);
|
||||
curVar.getVar(curPos, counts, &a);
|
||||
|
||||
curPos[rank-1]++;
|
||||
for (long i = rank-1; i >= 1; i--)
|
||||
{
|
||||
if (curPos[i] == dimList[i])
|
||||
if (curPos[i] == dimList[i].getSize())
|
||||
{
|
||||
curPos[i-1]++;
|
||||
curPos[i] = 0;
|
||||
@ -88,20 +82,19 @@ template<typename T>
|
||||
class OutputGenCDF: public NetCDF_handle, public ProgressiveOutputImpl<T>
|
||||
{
|
||||
public:
|
||||
OutputGenCDF(NcFile *f, NcVar *v, long *dimList, uint32_t rank)
|
||||
OutputGenCDF(NcFile *f, NcVar v, vector<NcDim>& dimList, uint32_t rank)
|
||||
: NetCDF_handle(f,v,dimList,rank)
|
||||
{}
|
||||
virtual ~OutputGenCDF() {}
|
||||
|
||||
virtual void put(T a)
|
||||
{
|
||||
curVar->set_cur(curPos);
|
||||
curVar->put(&a, counts);
|
||||
curVar.putVar(curPos, counts, &a);
|
||||
|
||||
curPos[rank-1]++;
|
||||
for (long i = rank-1; i >= 1; i--)
|
||||
{
|
||||
if (curPos[i] == dimList[i])
|
||||
if (curPos[i] == dimList[i].getSize())
|
||||
{
|
||||
curPos[i-1]++;
|
||||
curPos[i] = 0;
|
||||
@ -110,40 +103,19 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class NetCDF_type
|
||||
{
|
||||
public:
|
||||
static const NcType t = (NcType)-1;
|
||||
};
|
||||
template<typename T> NcType& get_NetCDF_type();
|
||||
|
||||
template<>
|
||||
class NetCDF_type<int>
|
||||
{
|
||||
public:
|
||||
static const NcType t = ncInt;
|
||||
};
|
||||
#define IMPL_TYPE(T,ncT) \
|
||||
template<> \
|
||||
NcType& get_NetCDF_type<T>() \
|
||||
{ \
|
||||
return ncT; \
|
||||
}
|
||||
|
||||
template<>
|
||||
class NetCDF_type<unsigned int>
|
||||
{
|
||||
public:
|
||||
static const NcType t = ncInt;
|
||||
};
|
||||
|
||||
template<>
|
||||
class NetCDF_type<float>
|
||||
{
|
||||
public:
|
||||
static const NcType t = ncFloat;
|
||||
};
|
||||
|
||||
template<>
|
||||
class NetCDF_type<double>
|
||||
{
|
||||
public:
|
||||
static const NcType t = ncDouble;
|
||||
};
|
||||
IMPL_TYPE(int,ncInt);
|
||||
IMPL_TYPE(unsigned int,ncInt);
|
||||
IMPL_TYPE(double,ncDouble);
|
||||
IMPL_TYPE(float,ncFloat);
|
||||
|
||||
namespace CosmoTool {
|
||||
template<typename T>
|
||||
@ -151,25 +123,23 @@ namespace CosmoTool {
|
||||
ProgressiveOutput<T>::saveArrayProgressive(const std::string& fname, uint32_t *dimList,
|
||||
uint32_t rank)
|
||||
{
|
||||
NcFile *f = new NcFile(fname.c_str(), NcFile::Replace);
|
||||
NcFile *f = new NcFile(fname, NcFile::replace);
|
||||
|
||||
assert(f->is_valid());
|
||||
|
||||
const NcDim **dimArray = new const NcDim *[rank];
|
||||
vector<NcDim> dimArray;
|
||||
for (uint32_t i = 0; i < rank; i++)
|
||||
{
|
||||
char dimName[255];
|
||||
|
||||
sprintf(dimName, "dim%d", i);
|
||||
dimArray[i] = f->add_dim(dimName, dimList[rank-1-i]);
|
||||
dimArray.push_back(f->addDim(dimName, dimList[rank-1-i]));
|
||||
}
|
||||
|
||||
NcVar *v = f->add_var("array", NetCDF_type<T>::t, rank, dimArray);
|
||||
NcVar v = f->addVar("array", get_NetCDF_type<T>(), dimArray);
|
||||
|
||||
long *ldimList = new long[rank];
|
||||
vector<NcDim> ldimList;
|
||||
|
||||
for (uint32_t i = 0; i < rank; i++)
|
||||
ldimList[rank-1-i] = dimList[i];
|
||||
ldimList.push_back(dimArray[rank-1-i]);
|
||||
|
||||
OutputGenCDF<T> *impl = new OutputGenCDF<T>(f, v, ldimList, rank);
|
||||
return ProgressiveOutput<T>(impl);
|
||||
@ -180,20 +150,18 @@ namespace CosmoTool {
|
||||
ProgressiveInput<T>::loadArrayProgressive(const std::string& fname, uint32_t *&dimList,
|
||||
uint32_t& rank)
|
||||
{
|
||||
NcFile *f = new NcFile(fname.c_str(), NcFile::ReadOnly);
|
||||
NcFile *f = new NcFile(fname, NcFile::read);
|
||||
|
||||
assert(f->is_valid());
|
||||
NcVar v = f->getVar("array");
|
||||
|
||||
NcVar *v = f->get_var("array");
|
||||
|
||||
rank = v->num_dims();
|
||||
long *ldimList = v->edges();
|
||||
rank = v.getDimCount();
|
||||
vector<NcDim> vdimlist = v.getDims();
|
||||
dimList = new uint32_t[rank];
|
||||
for (uint32_t i = 0; i < rank; i++)
|
||||
{
|
||||
dimList[rank-i-1] = ldimList[i];
|
||||
dimList[rank-i-1] = vdimlist[i].getSize();
|
||||
}
|
||||
InputGenCDF<T> *impl = new InputGenCDF<T>(f, v, ldimList, rank);
|
||||
InputGenCDF<T> *impl = new InputGenCDF<T>(f, v, vdimlist, rank);
|
||||
|
||||
return ProgressiveInput<T>(impl);
|
||||
}
|
||||
@ -202,24 +170,20 @@ namespace CosmoTool {
|
||||
void saveArray(const std::string& fname,
|
||||
T *array, uint32_t *dimList, uint32_t rank)
|
||||
{
|
||||
NcFile f(fname.c_str(), NcFile::Replace);
|
||||
NcFile f(fname.c_str(), NcFile::replace);
|
||||
|
||||
assert(f.is_valid());
|
||||
|
||||
const NcDim **dimArray = new const NcDim *[rank];
|
||||
vector<NcDim> dimArray;
|
||||
for (uint32_t i = 0; i < rank; i++)
|
||||
{
|
||||
char dimName[255];
|
||||
|
||||
sprintf(dimName, "dim%d", i);
|
||||
dimArray[i] = f.add_dim(dimName, dimList[i]);
|
||||
dimArray.push_back(f.addDim(dimName, dimList[i]));
|
||||
}
|
||||
|
||||
NcVar *v = f.add_var("array", NetCDF_type<T>::t, rank, dimArray);
|
||||
NcVar v = f.addVar("array", get_NetCDF_type<T>(), dimArray);
|
||||
|
||||
long *edge = v->edges();
|
||||
v->put(array, edge);
|
||||
delete[] edge;
|
||||
v.putVar(array);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -227,26 +191,25 @@ namespace CosmoTool {
|
||||
T*&array, uint32_t *&dimList, uint32_t& rank)
|
||||
throw (NoSuchFileException)
|
||||
{
|
||||
NcFile f(fname.c_str(), NcFile::ReadOnly);
|
||||
NcFile f(fname.c_str(), NcFile::read);
|
||||
|
||||
if (!f.is_valid())
|
||||
throw NoSuchFileException(fname);
|
||||
//if (!f.is_valid())
|
||||
// throw NoSuchFileException(fname);
|
||||
|
||||
NcVar *v = f.get_var("array");
|
||||
rank = v->num_dims();
|
||||
long *edge = v->edges();
|
||||
NcVar v = f.getVar("array");
|
||||
vector<NcDim> dims = v.getDims();
|
||||
rank = v.getDimCount();
|
||||
uint32_t fullSize = 1;
|
||||
dimList = new uint32_t[rank];
|
||||
for (int i = 0; i < rank; i++)
|
||||
{
|
||||
dimList[i] = edge[i];
|
||||
fullSize *= edge[i];
|
||||
dimList[i] = dims[i].getSize();
|
||||
fullSize *= dimList[i];
|
||||
}
|
||||
if (fullSize != 0) {
|
||||
array = new T[fullSize];
|
||||
v->get(array, edge);
|
||||
v.getVar(array);
|
||||
}
|
||||
delete[] edge;
|
||||
}
|
||||
|
||||
template class ProgressiveInput<int>;
|
||||
|
Loading…
Reference in New Issue
Block a user