51 template<
class T,
unsigned Dim,
class Mesh,
class Centering >
55 Layout(layout), NumFields(numFields)
69 ncid = nccreate(
FName, NC_CLOBBER);
73 int fillmode = ncsetfill(ncid,NC_NOFILL);
82 dimids[0] = ncdimdef(ncid,
"record", NC_UNLIMITED);
83 dimids[1] = ncdimdef(ncid,
"nx", domain[0].length());
86 dimids[0] = ncdimdef(ncid,
"record", NC_UNLIMITED);
87 dimids[1] = ncdimdef(ncid,
"nx", domain[0].length());
88 dimids[2] = ncdimdef(ncid,
"ny", domain[1].length());
91 dimids[0] = ncdimdef(ncid,
"record", NC_UNLIMITED);
92 dimids[1] = ncdimdef(ncid,
"nx", domain[0].length());
93 dimids[2] = ncdimdef(ncid,
"ny", domain[1].length());
94 dimids[3] = ncdimdef(ncid,
"nz", domain[2].length());
97 ERRORMSG(
"FieldBlock: can't write more than 3 dimensions" <<
endl);
101 sprintf(varName,
"var%d", i);
102 ncvardef(ncid, varName, NC_DOUBLE,
Dim+1, dimids);
105 int errRet = ncendef(ncid);
106 rcode = ncclose(ncid);
108 ERRORMSG(
"FieldBlock: ncclose() error, rcode=" << rcode <<
endl);
111 #endif // IPPL_NETCDF
116 template<
class T,
unsigned Dim,
class Mesh,
class Centering >
122 strcpy(
FName, fname);
128 int ncid, ndims, nvars;
134 ncid = ncopen(
FName, NC_NOWRITE);
137 ncinquire(ncid, &ndims, &nvars, 0, 0);
141 for( i = 0; i <
Dim+1 ; i++ ) {
142 ncdiminq(ncid, i, 0, &netSize[i]);
144 for( i = 0; i <
Dim ; i++ ) {
145 if( netSize[i+1] !=
Layout.getDomain()[i].length() ) {
146 ERRORMSG(
"FieldBlock: encountered non-conforming size on axis ");
152 ncvarinq(ncid, i, 0, &datatype, 0, 0, 0);
153 if( datatype != NC_DOUBLE)
154 ERRORMSG(
"FieldBlock: file must contain double precion data" <<
endl);
157 ncdiminq(ncid, 0, 0, &numRecords);
159 rcode = ncclose(ncid);
161 ERRORMSG(
"FieldBlock: ncclose() error, rcode=" << rcode <<
endl);
164 #endif // IPPL_NETCDF
167 template<
class T,
unsigned Dim,
class Mesh,
class Centering >
174 Inform msg(
"FieldBlock::write");
177 if( varID >=NumFields ) {
178 ERRORMSG(varID <<
" is a bad variable ID in FieldBlock::write " <<
endl);
186 ncid = ncopen(FName, NC_WRITE);
190 int fillmode = ncsetfill(ncid,NC_NOFILL);
194 long startIndex[
Dim+1];
195 long countIndex[
Dim+1];
213 LFI msgval = l.
begin();
229 int numVnodes = Layout.size_iv() + Layout.size_rdv();
232 for (
int remaining = numVnodes; remaining>0; --remaining) {
249 for(
int i = 0 ; i <
Dim ; i++ ) {
250 startIndex[Dim - i] = localBlock[Dim - 1 - i].first();
251 countIndex[Dim - i] = localBlock[Dim - 1 - i].length();
252 size *= countIndex[Dim - i];
256 startIndex[0] = record;
258 double* buffer =
new double[size];
261 int n0,n1,n2,i0,i1,i2;
262 if (rhs.IsCompressed()) {
263 for (i0=0; i0<size; ++i0) buffer[icount++] = *rhs;
269 for (i0=0; i0<n0; ++i0)
270 buffer[icount++] = rhs.offset(i0);
275 for (i0=0; i0<n0; ++i0)
276 for (i1=0; i1<n1; ++i1)
277 buffer[icount++] = rhs.offset(i0,i1);
283 for (i0=0; i0<n0; ++i0)
284 for (i1=0; i1<n1; ++i1)
285 for (i2=0; i2<n2; ++i2)
286 buffer[icount++] = rhs.offset(i0,i1,i2);
289 ERRORMSG(
"FieldBlock: bad Dimension in Field::write()" <<
endl);
294 rcode = ncvarput(ncid, varID, startIndex,countIndex, buffer);
297 ERRORMSG(
"FieldBlock: ncvarput() error, rcode=" << rcode <<
endl);
302 rcode = ncclose(ncid);
304 ERRORMSG(
"FieldBlock: ncclose() error, rcode=" << rcode <<
endl);
307 NumRecords = NumRecords > record ? NumRecords : record;
308 #endif // IPPL_NETCDF
311 template<
class T,
unsigned Dim,
class Mesh,
class Centering >
317 Inform msg(
"FieldBlock::read");
324 ncid = ncopen(FName, NC_NOWRITE);
327 if( record >= NumRecords )
328 ERRORMSG(
"invalid record on FieldBlock::read() " <<
endl);
331 long startIndex[
Dim+1];
332 long countIndex[
Dim+1];
346 for (localVnode = Layout.
begin_iv() ;
347 localVnode != Layout.
end_iv(); ++localVnode) {
353 for( i = 0 ; i <
Dim ; i++ ) {
354 startIndex[Dim - i] = lo[Dim - 1 - i].first();
355 countIndex[Dim - i] = lo[Dim - 1 - i].length();
356 size *= countIndex[Dim - i];
359 startIndex[0] = record;
361 double* buffer =
new double[size];
363 rcode = ncvarget(ncid, varID, startIndex, countIndex, buffer);
365 ERRORMSG(
"FieldBlock: ncvarget() error, rcode=" << rcode <<
endl);
370 LFI msgval(buffer, lo, lo);
381 for (remoteVnode = Layout.begin_rdv() ;
382 remoteVnode != Layout.end_rdv(); ++remoteVnode) {
388 for( i = 0 ; i <
Dim ; i++ ) {
389 startIndex[
Dim - i] = lo[
Dim - 1 - i].first();
390 countIndex[
Dim - i] = lo[
Dim - 1 - i].length();
391 size *= countIndex[
Dim - i];
394 startIndex[0] = record;
396 double* buffer =
new double[size];
398 rcode = ncvarget(ncid, varID, startIndex,countIndex, buffer);
400 ERRORMSG(
"FieldBlock: ncvarget() error, rcode=" << rcode <<
endl);
406 LFI msgval(buffer, lo, lo);
413 rcode = ncclose(ncid);
415 ERRORMSG(
"FieldBlock: ncclose() error, rcode=" << rcode <<
endl);
420 int numLocalVnodes = Layout.size_iv();
421 for (
int remaining = numLocalVnodes; remaining>0; --remaining) {
439 myLField = (*local).second.get();
441 if( lo == localBlock ) {
447 ERRORMSG(
"FieldBlock::read: did not match the local NDIndex" <<
endl);
450 LFI lhs = myLField->
begin();
451 int n0,n1,n2,i0,i1,i2;
452 if( lhs.IsCompressed() && rhs.IsCompressed() ) {
455 if( !lhs.IsCompressed() && rhs.IsCompressed() ) {
456 for (i0=0; i0 < localBlock.
size(); ++i0) {
461 if( !rhs.IsCompressed() ) {
462 if( lhs.IsCompressed() ) {
464 lhs = myLField->
begin();
469 for (i0=0; i0<n0; ++i0) {
470 lhs.offset(i0) = *rhs;
477 for (i0=0; i0<n0; ++i0)
478 for (i1=0; i1<n1; ++i1) {
479 lhs.offset(i0,i1) = *rhs;
487 for (i0=0; i0<n0; ++i0)
488 for (i1=0; i1<n1; ++i1)
489 for (i2=0; i2<n2; ++i2) {
490 lhs.offset(i0,i1,i2) = *rhs;
495 ERRORMSG(
"FieldBlock: bad Dimension in write()" <<
endl);
505 #endif // IPPL_NETCDF
FieldBlock(char *fname, FieldLayout< Dim > &layout, unsigned numFields)
ac_id_larray::iterator iterator_if
const NDIndex< Dim > & getOwned() const
void Uncompress(bool fill_domain=true)
int next_tag(int t, int s=1000)
const iterator & begin() const
FieldLayout< Dim > & Layout
void setPrintNode(int n=(-1))
ac_id_vnodes::iterator iterator_iv
const NDIndex< Dim > & getAllocated() const
int size(unsigned d) const
const NDIndex< Dim > & getDomain() const
void read(Field< T, Dim, Mesh, Centering > &f, unsigned varID, unsigned record=0)
void write(Field< T, Dim, Mesh, Centering > &f, unsigned varID, unsigned record=0)
void getMessage(Message &m, T &t)
void putMessage(Message &m, const T &t)
Message * receive_block(int &node, int &tag)
static Communicate * Comm
bool send(Message *, int node, int tag, bool delmsg=true)
Inform & endl(Inform &inf)