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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 982 by gross, Tue Feb 6 07:01:11 2007 UTC revision 983 by gross, Tue Feb 20 02:49:08 2007 UTC
# Line 16  Line 16 
16    
17  #include "DataConstant.h"  #include "DataConstant.h"
18  #include "DataException.h"  #include "DataException.h"
19    #include <netcdfcpp.h>
20    
21  using namespace std;  using namespace std;
22    
# Line 556  DataTagged::eigenvalues_and_eigenvectors Line 557  DataTagged::eigenvalues_and_eigenvectors
557  void  void
558  DataTagged::dump(const std::string fileName) const  DataTagged::dump(const std::string fileName) const
559  {  {
560      throw DataException("Error - DataTagged:: dump: not implemented.");     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    

Legend:
Removed from v.982  
changed lines
  Added in v.983

  ViewVC Help
Powered by ViewVC 1.1.26