/[escript]/trunk/escript/src/DataTagged.cpp
ViewVC logotype

Contents of /trunk/escript/src/DataTagged.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26