38 #ifndef IO_NETCDFREADER_H
39 #define IO_NETCDFREADER_H
54 #define MPI_INCLUDED_NETCDF
55 #endif // MPI_INCLUDED
58 #ifdef MPI_INCLUDED_NETCDF
60 #undef MPI_INCLUDED_NETCDF
61 #endif // MPI_INCLUDED_NETCDF
147 std::lock_guard<threads::Mutex> lock(
netcdfLock);
149 if (nc_inq_varid(
m_file,
m_names[i].c_str(), &x) != NC_NOERR)
154 nc_get_var1_double(
m_file, x, &index, &result);
167 unsigned long size =
getSize(i);
169 return std::numeric_limits<double>::infinity();
171 std::lock_guard<threads::Mutex> lock(
netcdfLock);
173 if (nc_inq_varid(
m_file,
m_names[i].c_str(), &x) != NC_NOERR)
178 nc_get_var1_double(
m_file, x, &index, &first);
180 nc_get_var1_double(
m_file, x, &index, &last);
182 return (last - first) / (size - 1);
196 const size_t *offset,
201 size_t actSize[MAX_DIMENSIONS];
203 if (offset[i] + size[i] >
getSize(i))
204 actSize[i] =
getSize(i) - offset[i];
206 actSize[i] = size[i];
210 ptrdiff_t imap[MAX_DIMENSIONS];
211 imap[m_dimensions-1] = 1;
212 for (
int i = m_dimensions-2; i >= 0; i--)
213 imap[i] = imap[i+1] * size[i+1];
215 std::lock_guard<threads::Mutex> lock(
netcdfLock);
216 getVar(offset, actSize, size, imap,
217 static_cast<T*>(block));
239 void getVar(
const size_t *offset,
const size_t *size,
240 const size_t *blockSize,
const ptrdiff_t *imap, T *buffer);
248 const size_t *blockSize,
const ptrdiff_t *imap,
unsigned char *buffer)
258 const size_t *blockSize,
const ptrdiff_t *imap,
int *buffer)
268 const size_t *blockSize,
const ptrdiff_t *imap,
long *buffer)
278 const size_t *blockSize,
const ptrdiff_t *imap,
float *buffer)
288 const size_t *blockSize,
const ptrdiff_t *imap,
double *buffer)
298 const size_t *blockSize,
const ptrdiff_t *imap,
void *buffer)
304 bool doMapping =
false;
306 if (size[i] != blockSize[i])
313 char* byteBuf =
reinterpret_cast<char*
>(buffer);
316 long pos[MAX_DIMENSIONS];
320 indexFile *= size[i];
323 size_t indexBuf = size[0]-1;
325 indexBuf *= blockSize[i];
326 indexBuf += size[i]-1;
330 for (indexFile--; indexFile >= 0 && indexFile < static_cast<long>(indexBuf); indexFile--) {
336 pos[m_dimensions-1]--;
339 for (
int i = m_dimensions-1; pos[i] < 0 && i > 0; i--) {
343 indexBuf -= imap[i-1];
344 indexBuf += imap[i] * size[i];
351 #endif // IO_NETCDFREADER_H
NetCdfReader(const char *filename, int rank)
static threads::Mutex netcdfLock
unsigned int dimensions() const
void getBlock(void *block, const size_t *offset, const size_t *size)
Reads a block of cells from the netcdf file. The type is converted to T.
Include file for C and C++ API.
unsigned int getVarSize() const
void getVar(const size_t *offset, const size_t *size, const size_t *blockSize, const ptrdiff_t *imap, T *buffer)
unsigned long getSize(int i) const
double getScaling(int i) const
double getOffset(int i) const
asagi::Grid::Error open(const char *varname="z")