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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1020 - (hide annotations)
Mon Mar 12 10:12:36 2007 UTC (12 years, 4 months ago) by phornby
File size: 22841 byte(s)
Added explicit destructors to all Exception classes.

Fixed an ifdef in TestCase.cpp

Made the conditional definition of M_PI in LocalOps.h
depend only on M_PI being undefined.

Replace dynamically dimensioned arrays in DataFactory & DataTagged with malloc.

sort() method of list does not take a named argument
(despite the manual's claims to the contary).


1 jgs 82 // $Id$
2 jgs 121
3 jgs 82 /*
4 elspeth 615 ************************************************************
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 jgs 82 */
14    
15 jgs 474 #include "DataTagged.h"
16 jgs 496
17 jgs 474 #include "DataConstant.h"
18     #include "DataException.h"
19 gross 983 #include <netcdfcpp.h>
20 jgs 82
21     using namespace std;
22    
23     namespace escript {
24    
25 jgs 121 DataTagged::DataTagged()
26     : DataAbstract(FunctionSpace())
27 jgs 82 {
28 jgs 509 // default constructor
29    
30 jgs 82 // create a scalar default value
31 jgs 151 m_data.resize(1,0.,1);
32 jgs 82 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 jgs 102 const FunctionSpace& what)
40     : DataAbstract(what)
41 jgs 82 {
42 jgs 509 // constructor
43    
44 jgs 121 // initialise the array of data values
45     // the default value is always the first item in the values list
46 jgs 151 int len = defaultValue.noValues();
47     m_data.resize(len,0.,len);
48 jgs 121 for (int i=0; i<defaultValue.noValues(); i++) {
49     m_data[i]=defaultValue.getData(i);
50     }
51    
52 jgs 119 // create the data view
53 jgs 82 DataArrayView temp(m_data,defaultValue.getShape());
54     setPointDataView(temp);
55 jgs 121
56 jgs 82 // add remaining tags and values
57     addTaggedValues(tagKeys,values);
58     }
59    
60 jgs 119 DataTagged::DataTagged(const FunctionSpace& what,
61     const DataArrayView::ShapeType &shape,
62     const int tags[],
63 jgs 500 const ValueType& data)
64 jgs 119 : DataAbstract(what)
65     {
66 jgs 509 // alternative constructor
67     // not unit_tested tested yet
68    
69 jgs 121 // copy the data
70 jgs 119 m_data=data;
71 jgs 121
72 jgs 119 // create the view of the data
73     DataArrayView tempView(m_data,shape);
74     setPointDataView(tempView);
75 jgs 121
76 jgs 119 // 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 woo409 757 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 jgs 102 DataTagged::DataTagged(const DataTagged& other)
106     : DataAbstract(other.getFunctionSpace()),
107 jgs 82 m_data(other.m_data),
108     m_offsetLookup(other.m_offsetLookup)
109     {
110 jgs 509 // copy constructor
111    
112 jgs 119 // create the data view
113 jgs 82 DataArrayView temp(m_data,other.getPointDataView().getShape());
114     setPointDataView(temp);
115     }
116    
117 jgs 102 DataTagged::DataTagged(const DataConstant& other)
118     : DataAbstract(other.getFunctionSpace())
119 jgs 82 {
120 jgs 509 // copy constructor
121    
122 jgs 121 // fill the default value with the constant value item from "other"
123 jgs 82 const DataArrayView& value=other.getPointDataView();
124 jgs 151 int len = value.noValues();
125     m_data.resize(len,0.,len);
126 jgs 121 for (int i=0; i<value.noValues(); i++) {
127     m_data[i]=value.getData(i);
128     }
129    
130 jgs 119 // create the data view
131 jgs 82 DataArrayView temp(m_data,value.getShape());
132     setPointDataView(temp);
133     }
134    
135     DataAbstract*
136     DataTagged::getSlice(const DataArrayView::RegionType& region) const
137     {
138 jgs 513 return new DataTagged(*this, region);
139 jgs 82 }
140    
141 jgs 513 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 jgs 82 void
174 jgs 513 DataTagged::setSlice(const DataAbstract* other,
175     const DataArrayView::RegionType& region)
176 jgs 82 {
177 jgs 513
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 jgs 82 throw DataException("Programming error - casting to DataTagged.");
183     }
184 jgs 121
185 jgs 513 // 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 jgs 82 if (getPointDataView().getRank()!=region.size()) {
193     throw DataException("Error - Invalid slice region.");
194     }
195 woo409 757 if (otherTemp->getPointDataView().getRank()>0 && !other->getPointDataView().checkShape(regionShape)) {
196 jgs 513 throw DataException (other->getPointDataView().createShapeErrorMessage(
197     "Error - Couldn't copy slice due to shape mismatch.",regionShape));
198 jgs 82 }
199 jgs 121
200 jgs 513 // copy slice from other default value to this default value
201     getDefaultValue().copySliceFrom(otherTemp->getDefaultValue(), regionLoopRange);
202 jgs 121
203 jgs 541 // 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 jgs 513 // loop through the tag values copying slices from other to this
212 jgs 121 for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {
213 jgs 513 getDataPointByTag(pos->first).copySliceFrom(otherTemp->getDataPointByTag(pos->first), regionLoopRange);
214 jgs 121 }
215 jgs 513
216 jgs 82 }
217    
218 jgs 149 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 jgs 496 if (dpno<0 || dpno>numDataPoints-1) {
232 jgs 149 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 jgs 82 void
249 jgs 509 DataTagged::setTaggedValues(const TagListType& tagKeys,
250     const ValueListType& values)
251     {
252     addTaggedValues(tagKeys,values);
253     }
254    
255     void
256 jgs 82 DataTagged::setTaggedValue(int tagKey,
257     const DataArrayView& value)
258     {
259 jgs 121 if (!getPointDataView().checkShape(value.getShape())) {
260     throw DataException(getPointDataView().createShapeErrorMessage(
261     "Error - Cannot setTaggedValue due to shape mismatch.", value.getShape()));
262     }
263 jgs 82 DataMapType::iterator pos(m_offsetLookup.find(tagKey));
264     if (pos==m_offsetLookup.end()) {
265 jgs 121 // tag couldn't be found so use addTaggedValue
266 jgs 82 addTaggedValue(tagKey,value);
267     } else {
268 jgs 121 // 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 jgs 82 }
273     }
274     }
275    
276     void
277 jgs 509 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 jgs 82 DataTagged::addTaggedValue(int tagKey,
309     const DataArrayView& value)
310     {
311     if (!getPointDataView().checkShape(value.getShape())) {
312     throw DataException(getPointDataView().createShapeErrorMessage(
313 jgs 121 "Error - Cannot addTaggedValue due to shape mismatch.", value.getShape()));
314 jgs 82 }
315 jgs 121 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 jgs 151 m_data.resize(newSize,0.,newSize);
329 jgs 121 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 jgs 82 }
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 jgs 496 DataArrayView::ValueType::size_type
369     DataTagged::getPointOffset(int sampleNo,
370     int dataPointNo) const
371 jgs 82 {
372 jgs 496 int tagKey=getFunctionSpace().getTagFromSampleNo(sampleNo);
373     DataMapType::const_iterator pos(m_offsetLookup.find(tagKey));
374 jgs 82 DataArrayView::ValueType::size_type offset=m_defaultValueOffset;
375     if (pos!=m_offsetLookup.end()) {
376     offset=pos->second;
377     }
378 jgs 496 return offset;
379 jgs 82 }
380    
381 jgs 496 DataArrayView
382     DataTagged::getDataPointByTag(int tag) const
383 jgs 82 {
384 jgs 496 DataMapType::const_iterator pos(m_offsetLookup.find(tag));
385 jgs 82 DataArrayView::ValueType::size_type offset=m_defaultValueOffset;
386     if (pos!=m_offsetLookup.end()) {
387     offset=pos->second;
388     }
389 jgs 496 DataArrayView temp(getPointDataView());
390     temp.setOffset(offset);
391     return temp;
392 jgs 82 }
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 jgs 123 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 gross 580 void
417 ksteube 775 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 gross 800 DataTagged::trace(DataAbstract* ev, int axis_offset)
454 ksteube 775 {
455     DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
456     if (temp_ev==0) {
457 gross 800 throw DataException("Error - DataTagged::trace casting to DataTagged failed (probably a programming error).");
458 ksteube 775 }
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 gross 800 DataArrayView::trace(thisView,0,evView,0, axis_offset);
467 ksteube 775 }
468 gross 800 DataArrayView::trace(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);
469 ksteube 775 }
470 gross 800
471 ksteube 775 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 gross 800
490 ksteube 775 void
491 gross 804 DataTagged::swapaxes(DataAbstract* ev, int axis0, int axis1)
492 gross 800 {
493     DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
494     if (temp_ev==0) {
495 gross 804 throw DataException("Error - DataTagged::swapaxes casting to DataTagged failed (probably a programming error).");
496 gross 800 }
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 gross 804 DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
505 gross 800 }
506 gross 804 DataArrayView::swapaxes(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis0,axis1);
507 gross 800 }
508    
509     void
510 gross 580 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 jgs 123
554 gross 580
555     }
556    
557 gross 950 void
558     DataTagged::dump(const std::string fileName) const
559     {
560 gross 983 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 phornby 1020 int* tags =(int*) malloc(ntags*sizeof(int));
609     int c=1;
610 gross 983 tags[0]=-1;
611     for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;
612     dims[rank]=ntags;
613     if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )
614 phornby 1020 {
615     free(tags);
616     throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");
617     }
618 gross 983 if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )
619 phornby 1020 {
620     free(tags);
621 gross 983 throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");
622 phornby 1020 }
623 gross 983 if (! (tags_var->put(tags,dims[rank])) )
624 phornby 1020 {
625     free(tags);
626 gross 983 throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");
627 phornby 1020 }
628 gross 983 if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
629 phornby 1020 {
630     free(tags);
631 gross 983 throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");
632 phornby 1020 }
633 gross 983 if (! (var->put(&m_data[0],dims)) )
634 phornby 1020 {
635     free(tags);
636 gross 983 throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
637 phornby 1020 }
638 gross 950 }
639 gross 580
640 gross 950
641 jgs 82 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26