/[escript]/branches/arrexp_2137_win/escript/src/DataTagged.cpp
ViewVC logotype

Contents of /branches/arrexp_2137_win/escript/src/DataTagged.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1137 - (show annotations)
Thu May 10 08:11:31 2007 UTC (12 years ago) by gross
Original Path: trunk/escript/src/DataTagged.cpp
File size: 23283 byte(s)
This version passes the tests on windows except for 

   * vtk
   * netCDF

The version needs to be tested on altix and linux
1 // $Id$
2
3 /*
4 ************************************************************
5 * Copyright 2006 by ACcESS MNRF *
6 * *
7 * http://www.access.edu.au *
8 * Primary Business: Queensland, Australia *
9 * Licensed under the Open Software License version 3.0 *
10 * http://www.opensource.org/licenses/osl-3.0.php *
11 * *
12 ************************************************************
13 */
14
15 #include "DataTagged.h"
16
17 #include "DataConstant.h"
18 #include "DataException.h"
19 #ifdef USE_NETCDF
20 #include "netcdfcpp.h"
21 #endif
22
23 using namespace std;
24
25 namespace escript {
26
27 DataTagged::DataTagged()
28 : DataAbstract(FunctionSpace())
29 {
30 // default constructor
31
32 // create a scalar default value
33 m_data.resize(1,0.,1);
34 DataArrayView temp(m_data,DataArrayView::ShapeType());
35 setPointDataView(temp);
36 }
37
38 DataTagged::DataTagged(const TagListType& tagKeys,
39 const ValueListType& values,
40 const DataArrayView& defaultValue,
41 const FunctionSpace& what)
42 : DataAbstract(what)
43 {
44 // constructor
45
46 // initialise the array of data values
47 // the default value is always the first item in the values list
48 int len = defaultValue.noValues();
49 m_data.resize(len,0.,len);
50 for (int i=0; i<defaultValue.noValues(); i++) {
51 m_data[i]=defaultValue.getData(i);
52 }
53
54 // create the data view
55 DataArrayView temp(m_data,defaultValue.getShape());
56 setPointDataView(temp);
57
58 // add remaining tags and values
59 addTaggedValues(tagKeys,values);
60 }
61
62 DataTagged::DataTagged(const FunctionSpace& what,
63 const DataArrayView::ShapeType &shape,
64 const int tags[],
65 const ValueType& data)
66 : DataAbstract(what)
67 {
68 // alternative constructor
69 // not unit_tested tested yet
70
71 // copy the data
72 m_data=data;
73
74 // create the view of the data
75 DataArrayView tempView(m_data,shape);
76 setPointDataView(tempView);
77
78 // create the tag lookup map
79 for (int sampleNo=0; sampleNo<getNumSamples(); sampleNo++) {
80 m_offsetLookup.insert(DataMapType::value_type(sampleNo,tags[sampleNo]));
81 }
82 }
83
84 DataTagged::DataTagged(const FunctionSpace& what,
85 const DataArrayView::ShapeType &shape,
86 const TagListType& tags,
87 const ValueType& data)
88 : DataAbstract(what)
89 {
90 // alternative constructor
91 // not unit_tested tested yet
92
93 // copy the data
94 m_data=data;
95
96 // create the view of the data
97 DataArrayView tempView(m_data,shape);
98 setPointDataView(tempView);
99
100 // create the tag lookup map
101 for (int sampleNo=0; sampleNo<getNumSamples(); sampleNo++) {
102 m_offsetLookup.insert(DataMapType::value_type(sampleNo,tags[sampleNo]));
103 }
104 }
105
106
107 DataTagged::DataTagged(const DataTagged& other)
108 : DataAbstract(other.getFunctionSpace()),
109 m_data(other.m_data),
110 m_offsetLookup(other.m_offsetLookup)
111 {
112 // copy constructor
113
114 // create the data view
115 DataArrayView temp(m_data,other.getPointDataView().getShape());
116 setPointDataView(temp);
117 }
118
119 DataTagged::DataTagged(const DataConstant& other)
120 : DataAbstract(other.getFunctionSpace())
121 {
122 // copy constructor
123
124 // fill the default value with the constant value item from "other"
125 const DataArrayView& value=other.getPointDataView();
126 int len = value.noValues();
127 m_data.resize(len,0.,len);
128 for (int i=0; i<value.noValues(); i++) {
129 m_data[i]=value.getData(i);
130 }
131
132 // create the data view
133 DataArrayView temp(m_data,value.getShape());
134 setPointDataView(temp);
135 }
136
137 DataAbstract*
138 DataTagged::getSlice(const DataArrayView::RegionType& region) const
139 {
140 return new DataTagged(*this, region);
141 }
142
143 DataTagged::DataTagged(const DataTagged& other,
144 const DataArrayView::RegionType& region)
145 : DataAbstract(other.getFunctionSpace())
146 {
147 // slice constructor
148
149 // get the shape of the slice to copy from other
150 DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
151 DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
152
153 // allocate enough space in this for all values
154 // (need to add one to allow for the default value)
155 int len = DataArrayView::noValues(regionShape)*(other.m_offsetLookup.size()+1);
156 m_data.resize(len,0.0,len);
157
158 // create the data view
159 DataArrayView temp(m_data,regionShape);
160 setPointDataView(temp);
161
162 // copy the default value from other to this
163 getDefaultValue().copySlice(other.getDefaultValue(), regionLoopRange);
164
165 // loop through the tag values copying these
166 DataMapType::const_iterator pos;
167 DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();
168 for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();pos++){
169 getPointDataView().copySlice(tagOffset,other.getPointDataView(),pos->second,regionLoopRange);
170 m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));
171 tagOffset+=getPointDataView().noValues();
172 }
173 }
174
175 void
176 DataTagged::setSlice(const DataAbstract* other,
177 const DataArrayView::RegionType& region)
178 {
179
180 // other must be another DataTagged object
181 // Data:setSlice implementation should ensure this
182 const DataTagged* otherTemp=dynamic_cast<const DataTagged*>(other);
183 if (otherTemp==0) {
184 throw DataException("Programming error - casting to DataTagged.");
185 }
186
187 // determine shape of the specified region
188 DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
189
190 // modify region specification as needed to match rank of this object
191 DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
192
193 // ensure rank/shape of this object is compatible with specified region
194 if (getPointDataView().getRank()!=region.size()) {
195 throw DataException("Error - Invalid slice region.");
196 }
197 if (otherTemp->getPointDataView().getRank()>0 && !other->getPointDataView().checkShape(regionShape)) {
198 throw DataException (other->getPointDataView().createShapeErrorMessage(
199 "Error - Couldn't copy slice due to shape mismatch.",regionShape));
200 }
201
202 // copy slice from other default value to this default value
203 getDefaultValue().copySliceFrom(otherTemp->getDefaultValue(), regionLoopRange);
204
205 // loop through tag values in other, adding any which aren't in this, using default value
206 DataMapType::const_iterator pos;
207 for (pos=otherTemp->m_offsetLookup.begin();pos!=otherTemp->m_offsetLookup.end();pos++) {
208 if (!isCurrentTag(pos->first)) {
209 addTaggedValue(pos->first,getDefaultValue());
210 }
211 }
212
213 // loop through the tag values copying slices from other to this
214 for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {
215 getDataPointByTag(pos->first).copySliceFrom(otherTemp->getDataPointByTag(pos->first), regionLoopRange);
216 }
217
218 }
219
220 int
221 DataTagged::getTagNumber(int dpno)
222 {
223 //
224 // Get the number of samples and data-points per sample
225 int numSamples = getNumSamples();
226 int numDataPointsPerSample = getNumDPPSample();
227 int numDataPoints = numSamples * numDataPointsPerSample;
228
229 if (numDataPointsPerSample==0) {
230 throw DataException("DataTagged::getTagNumber error: no data-points associated with this object.");
231 }
232
233 if (dpno<0 || dpno>numDataPoints-1) {
234 throw DataException("DataTagged::getTagNumber error: invalid data-point number supplied.");
235 }
236
237 //
238 // Determine the sample number which corresponds to this data-point number
239 int sampleNo = dpno / numDataPointsPerSample;
240
241 //
242 // Determine the tag number which corresponds to this sample number
243 int tagNo = getFunctionSpace().getTagFromSampleNo(sampleNo);
244
245 //
246 // return the tag number
247 return(tagNo);
248 }
249
250 void
251 DataTagged::setTaggedValues(const TagListType& tagKeys,
252 const ValueListType& values)
253 {
254 addTaggedValues(tagKeys,values);
255 }
256
257 void
258 DataTagged::setTaggedValue(int tagKey,
259 const DataArrayView& value)
260 {
261 if (!getPointDataView().checkShape(value.getShape())) {
262 throw DataException(getPointDataView().createShapeErrorMessage(
263 "Error - Cannot setTaggedValue due to shape mismatch.", value.getShape()));
264 }
265 DataMapType::iterator pos(m_offsetLookup.find(tagKey));
266 if (pos==m_offsetLookup.end()) {
267 // tag couldn't be found so use addTaggedValue
268 addTaggedValue(tagKey,value);
269 } else {
270 // copy the values into the data array at the offset determined by m_offsetLookup
271 int offset=pos->second;
272 for (int i=0; i<getPointDataView().noValues(); i++) {
273 m_data[offset+i]=value.getData(i);
274 }
275 }
276 }
277
278 void
279 DataTagged::addTaggedValues(const TagListType& tagKeys,
280 const ValueListType& values)
281 {
282 if (values.size()==0) {
283 // copy the current default value for each of the tags
284 TagListType::const_iterator iT;
285 for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {
286 // the point data view for DataTagged points at the default value
287 addTaggedValue(*iT,getPointDataView());
288 }
289 } else if (values.size()==1 && tagKeys.size()>1) {
290 // assume the one given value will be used for all tag values
291 TagListType::const_iterator iT;
292 for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {
293 addTaggedValue(*iT,values[0]);
294 }
295 } else {
296 if (tagKeys.size()!=values.size()) {
297 stringstream temp;
298 temp << "Error - (addTaggedValue) Number of tags: " << tagKeys.size()
299 << " doesn't match number of values: " << values.size();
300 throw DataException(temp.str());
301 } else {
302 for (int i=0;i<tagKeys.size();i++) {
303 addTaggedValue(tagKeys[i],values[i]);
304 }
305 }
306 }
307 }
308
309 void
310 DataTagged::addTaggedValue(int tagKey,
311 const DataArrayView& value)
312 {
313 if (!getPointDataView().checkShape(value.getShape())) {
314 throw DataException(getPointDataView().createShapeErrorMessage(
315 "Error - Cannot addTaggedValue due to shape mismatch.", value.getShape()));
316 }
317 DataMapType::iterator pos(m_offsetLookup.find(tagKey));
318 if (pos!=m_offsetLookup.end()) {
319 // tag already exists so use setTaggedValue
320 setTaggedValue(tagKey,value);
321 } else {
322 // save the key and the location of its data in the lookup tab
323 m_offsetLookup.insert(DataMapType::value_type(tagKey,m_data.size()));
324 // add the data given in "value" at the end of m_data
325 // need to make a temp copy of m_data, resize m_data, then copy
326 // all the old values plus the value to be added back into m_data
327 ValueType m_data_temp(m_data);
328 int oldSize=m_data.size();
329 int newSize=m_data.size()+value.noValues();
330 m_data.resize(newSize,0.,newSize);
331 for (int i=0;i<oldSize;i++) {
332 m_data[i]=m_data_temp[i];
333 }
334 for (int i=0;i<value.noValues();i++) {
335 m_data[oldSize+i]=value.getData(i);
336 }
337 }
338 }
339
340 double*
341 DataTagged::getSampleDataByTag(int tag)
342 {
343 DataMapType::iterator pos(m_offsetLookup.find(tag));
344 if (pos==m_offsetLookup.end()) {
345 // tag couldn't be found so return the default value
346 return &(m_data[0]);
347 } else {
348 // return the data-point corresponding to the given tag
349 return &(m_data[pos->second]);
350 }
351 }
352
353 string
354 DataTagged::toString() const
355 {
356 stringstream temp;
357 DataMapType::const_iterator i;
358 temp << "Tag(Default)" << endl;
359 temp << getDefaultValue().toString() << endl;
360 // create a temporary view as the offset will be changed
361 DataArrayView tempView(getPointDataView().getData(), getPointDataView().getShape());
362 for (i=m_offsetLookup.begin();i!=m_offsetLookup.end();++i) {
363 temp << "Tag(" << i->first << ")" << endl;
364 tempView.setOffset(i->second);
365 temp << tempView.toString() << endl;
366 }
367 return string(temp.str());
368 }
369
370 DataArrayView::ValueType::size_type
371 DataTagged::getPointOffset(int sampleNo,
372 int dataPointNo) const
373 {
374 int tagKey=getFunctionSpace().getTagFromSampleNo(sampleNo);
375 DataMapType::const_iterator pos(m_offsetLookup.find(tagKey));
376 DataArrayView::ValueType::size_type offset=m_defaultValueOffset;
377 if (pos!=m_offsetLookup.end()) {
378 offset=pos->second;
379 }
380 return offset;
381 }
382
383 DataArrayView
384 DataTagged::getDataPointByTag(int tag) const
385 {
386 DataMapType::const_iterator pos(m_offsetLookup.find(tag));
387 DataArrayView::ValueType::size_type offset=m_defaultValueOffset;
388 if (pos!=m_offsetLookup.end()) {
389 offset=pos->second;
390 }
391 DataArrayView temp(getPointDataView());
392 temp.setOffset(offset);
393 return temp;
394 }
395
396 DataArrayView
397 DataTagged::getDataPoint(int sampleNo,
398 int dataPointNo)
399 {
400 EsysAssert(validSampleNo(sampleNo),"(getDataPoint) Invalid sampleNo: " << sampleNo);
401 int tagKey=getFunctionSpace().getTagFromSampleNo(sampleNo);
402 return getDataPointByTag(tagKey);
403 }
404
405 int
406 DataTagged::archiveData(ofstream& archiveFile,
407 const DataArrayView::ValueType::size_type noValues) const
408 {
409 return(m_data.archiveData(archiveFile, noValues));
410 }
411
412 int
413 DataTagged::extractData(ifstream& archiveFile,
414 const DataArrayView::ValueType::size_type noValues)
415 {
416 return(m_data.extractData(archiveFile, noValues));
417 }
418 void
419 DataTagged::symmetric(DataAbstract* ev)
420 {
421 DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
422 if (temp_ev==0) {
423 throw DataException("Error - DataTagged::symmetric casting to DataTagged failed (probably a programming error).");
424 }
425 const DataTagged::DataMapType& thisLookup=getTagLookup();
426 DataTagged::DataMapType::const_iterator i;
427 DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
428 for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
429 temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
430 DataArrayView thisView=getDataPointByTag(i->first);
431 DataArrayView evView=temp_ev->getDataPointByTag(i->first);
432 DataArrayView::symmetric(thisView,0,evView,0);
433 }
434 DataArrayView::symmetric(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
435 }
436 void
437 DataTagged::nonsymmetric(DataAbstract* ev)
438 {
439 DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
440 if (temp_ev==0) {
441 throw DataException("Error - DataTagged::nonsymmetric casting to DataTagged failed (probably a programming error).");
442 }
443 const DataTagged::DataMapType& thisLookup=getTagLookup();
444 DataTagged::DataMapType::const_iterator i;
445 DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
446 for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
447 temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
448 DataArrayView thisView=getDataPointByTag(i->first);
449 DataArrayView evView=temp_ev->getDataPointByTag(i->first);
450 DataArrayView::nonsymmetric(thisView,0,evView,0);
451 }
452 DataArrayView::nonsymmetric(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
453 }
454 void
455 DataTagged::trace(DataAbstract* ev, int axis_offset)
456 {
457 DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
458 if (temp_ev==0) {
459 throw DataException("Error - DataTagged::trace casting to DataTagged failed (probably a programming error).");
460 }
461 const DataTagged::DataMapType& thisLookup=getTagLookup();
462 DataTagged::DataMapType::const_iterator i;
463 DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
464 for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
465 temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
466 DataArrayView thisView=getDataPointByTag(i->first);
467 DataArrayView evView=temp_ev->getDataPointByTag(i->first);
468 DataArrayView::trace(thisView,0,evView,0, axis_offset);
469 }
470 DataArrayView::trace(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);
471 }
472
473 void
474 DataTagged::transpose(DataAbstract* ev, int axis_offset)
475 {
476 DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
477 if (temp_ev==0) {
478 throw DataException("Error - DataTagged::transpose casting to DataTagged failed (probably a programming error).");
479 }
480 const DataTagged::DataMapType& thisLookup=getTagLookup();
481 DataTagged::DataMapType::const_iterator i;
482 DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
483 for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
484 temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
485 DataArrayView thisView=getDataPointByTag(i->first);
486 DataArrayView evView=temp_ev->getDataPointByTag(i->first);
487 DataArrayView::transpose(thisView,0,evView,0, axis_offset);
488 }
489 DataArrayView::transpose(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);
490 }
491
492 void
493 DataTagged::swapaxes(DataAbstract* ev, int axis0, int axis1)
494 {
495 DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
496 if (temp_ev==0) {
497 throw DataException("Error - DataTagged::swapaxes casting to DataTagged failed (probably a programming error).");
498 }
499 const DataTagged::DataMapType& thisLookup=getTagLookup();
500 DataTagged::DataMapType::const_iterator i;
501 DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
502 for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
503 temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
504 DataArrayView thisView=getDataPointByTag(i->first);
505 DataArrayView evView=temp_ev->getDataPointByTag(i->first);
506 DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
507 }
508 DataArrayView::swapaxes(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis0,axis1);
509 }
510
511 void
512 DataTagged::eigenvalues(DataAbstract* ev)
513 {
514 DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
515 if (temp_ev==0) {
516 throw DataException("Error - DataTagged::eigenvalues casting to DataTagged failed (propably a programming error).");
517 }
518 const DataTagged::DataMapType& thisLookup=getTagLookup();
519 DataTagged::DataMapType::const_iterator i;
520 DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
521 for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
522 temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
523 DataArrayView thisView=getDataPointByTag(i->first);
524 DataArrayView evView=temp_ev->getDataPointByTag(i->first);
525 DataArrayView::eigenvalues(thisView,0,evView,0);
526 }
527 DataArrayView::eigenvalues(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
528 }
529 void
530 DataTagged::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
531 {
532 DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
533 if (temp_ev==0) {
534 throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
535 }
536 DataTagged* temp_V=dynamic_cast<DataTagged*>(V);
537 if (temp_V==0) {
538 throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
539 }
540 const DataTagged::DataMapType& thisLookup=getTagLookup();
541 DataTagged::DataMapType::const_iterator i;
542 DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
543 for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
544 temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
545 temp_V->addTaggedValue(i->first,temp_V->getDefaultValue());
546 DataArrayView thisView=getDataPointByTag(i->first);
547 DataArrayView evView=temp_ev->getDataPointByTag(i->first);
548 DataArrayView VView=temp_V->getDataPointByTag(i->first);
549 DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,0,tol);
550 }
551 DataArrayView::eigenvalues_and_eigenvectors(getDefaultValue(),0,
552 temp_ev->getDefaultValue(),0,
553 temp_V->getDefaultValue(),0,
554 tol);
555
556
557 }
558
559 void
560 DataTagged::setToZero(){
561 DataArrayView::ValueType::size_type n=m_data.size();
562 for (int i=0; i<n ;++i) m_data[i]=0.;
563 }
564
565 void
566 DataTagged::dump(const std::string fileName) const
567 {
568 #ifdef PASO_MPI
569 throw DataException("Error - DataTagged:: dump is not implemented for MPI yet.")
570 #endif
571 #ifdef USE_NETCDF
572 const int ldims=DataArrayView::maxRank+1;
573 const NcDim* ncdims[ldims];
574 NcVar *var, *tags_var;
575 int rank = getPointDataView().getRank();
576 int type= getFunctionSpace().getTypeCode();
577 int ndims =0;
578 long dims[ldims];
579 DataArrayView::ShapeType shape = getPointDataView().getShape();
580
581 // netCDF error handler
582 NcError err(NcError::verbose_nonfatal);
583 // Create the file.
584 NcFile dataFile(fileName.c_str(), NcFile::Replace);
585 // check if writing was successful
586 if (!dataFile.is_valid())
587 throw DataException("Error - DataTagged:: opening of netCDF file for output failed.");
588 if (!dataFile.add_att("type","tagged") )
589 throw DataException("Error - DataTagged:: appending data type to netCDF file failed.");
590 if (!dataFile.add_att("rank",rank) )
591 throw DataException("Error - DataTagged:: appending rank attribute to netCDF file failed.");
592 if (!dataFile.add_att("function_space_type",type))
593 throw DataException("Error - DataTagged:: appending function space attribute to netCDF file failed.");
594 ndims=rank+1;
595 if ( rank >0 ) {
596 dims[0]=shape[0];
597 if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
598 throw DataException("Error - DataTagged:: appending ncdimsion 0 to netCDF file failed.");
599 }
600 if ( rank >1 ) {
601 dims[1]=shape[1];
602 if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
603 throw DataException("Error - DataTagged:: appending ncdimsion 1 to netCDF file failed.");
604 }
605 if ( rank >2 ) {
606 dims[2]=shape[2];
607 if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
608 throw DataException("Error - DataTagged:: appending ncdimsion 2 to netCDF file failed.");
609 }
610 if ( rank >3 ) {
611 dims[3]=shape[3];
612 if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
613 throw DataException("Error - DataTagged:: appending ncdimsion 3 to netCDF file failed.");
614 }
615 const DataTagged::DataMapType& thisLookup=getTagLookup();
616 DataTagged::DataMapType::const_iterator i;
617 DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
618 int ntags=1;
619 for (i=thisLookup.begin();i!=thisLookupEnd;i++) ntags++;
620 int* tags =(int*) malloc(ntags*sizeof(int));
621 int c=1;
622 tags[0]=-1;
623 for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;
624 dims[rank]=ntags;
625 if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )
626 {
627 free(tags);
628 throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");
629 }
630 if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )
631 {
632 free(tags);
633 throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");
634 }
635 if (! (tags_var->put(tags,dims[rank])) )
636 {
637 free(tags);
638 throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");
639 }
640 if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
641 {
642 free(tags);
643 throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");
644 }
645 if (! (var->put(&m_data[0],dims)) )
646 {
647 free(tags);
648 throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
649 }
650 #else
651 throw DataException("Error - DataTagged:: dump is not configured with netCDF. Please contact your installation manager.");
652 #endif
653 }
654 } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26