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

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

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

revision 950 by gross, Tue Feb 6 07:01:11 2007 UTC revision 1023 by gross, Tue Mar 13 05:43:36 2007 UTC
# Line 16  Line 16 
16    
17  #include "DataConstant.h"  #include "DataConstant.h"
18  #include "DataException.h"  #include "DataException.h"
19    #ifdef USE_NETCDF
20    #include <netcdfcpp.h>
21    #endif
22    
23  using namespace std;  using namespace std;
24    
# Line 556  DataTagged::eigenvalues_and_eigenvectors Line 559  DataTagged::eigenvalues_and_eigenvectors
559  void  void
560  DataTagged::dump(const std::string fileName) const  DataTagged::dump(const std::string fileName) const
561  {  {
562      throw DataException("Error - DataTagged:: dump: not implemented.");     #ifdef PASO_MPI
563       throw DataException("Error - DataTagged:: dump is not implemented for MPI yet.")
564       #endif
565       #ifdef USE_NETCDF
566       const int ldims=DataArrayView::maxRank+1;
567       const NcDim* ncdims[ldims];
568       NcVar *var, *tags_var;
569       int rank = getPointDataView().getRank();
570       int type=  getFunctionSpace().getTypeCode();
571       int ndims =0;
572       long dims[ldims];
573       DataArrayView::ShapeType shape = getPointDataView().getShape();
574    
575       // netCDF error handler
576       NcError err(NcError::verbose_nonfatal);
577       // Create the file.
578       NcFile dataFile(fileName.c_str(), NcFile::Replace);
579       // check if writing was successful
580       if (!dataFile.is_valid())
581            throw DataException("Error - DataTagged:: opening of netCDF file for output failed.");
582       if (!dataFile.add_att("type","tagged") )
583            throw DataException("Error - DataTagged:: appending data type to netCDF file failed.");
584       if (!dataFile.add_att("rank",rank) )
585            throw DataException("Error - DataTagged:: appending rank attribute to netCDF file failed.");
586       if (!dataFile.add_att("function_space_type",type))
587            throw DataException("Error - DataTagged:: appending function space attribute to netCDF file failed.");
588       ndims=rank+1;
589       if ( rank >0 ) {
590           dims[0]=shape[0];
591           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
592                throw DataException("Error - DataTagged:: appending ncdimsion 0 to netCDF file failed.");
593       }
594       if ( rank >1 ) {
595           dims[1]=shape[1];
596           if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
597                throw DataException("Error - DataTagged:: appending ncdimsion 1 to netCDF file failed.");
598       }
599       if ( rank >2 ) {
600           dims[2]=shape[2];
601           if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
602                throw DataException("Error - DataTagged:: appending ncdimsion 2 to netCDF file failed.");
603       }
604       if ( rank >3 ) {
605           dims[3]=shape[3];
606           if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
607                throw DataException("Error - DataTagged:: appending ncdimsion 3 to netCDF file failed.");
608       }
609       const DataTagged::DataMapType& thisLookup=getTagLookup();
610       DataTagged::DataMapType::const_iterator i;
611       DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
612       int ntags=1;
613       for (i=thisLookup.begin();i!=thisLookupEnd;i++) ntags++;
614       int* tags =(int*) malloc(ntags*sizeof(int));
615       int c=1;
616       tags[0]=-1;
617       for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;
618       dims[rank]=ntags;
619       if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )
620       {
621           free(tags);
622               throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");
623       }
624       if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )
625       {
626        free(tags);
627            throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");
628       }
629       if (! (tags_var->put(tags,dims[rank])) )
630       {
631        free(tags);
632            throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");
633       }
634       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
635       {
636        free(tags);
637            throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");
638       }
639       if (! (var->put(&m_data[0],dims)) )
640       {
641        free(tags);
642            throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
643       }
644       #else
645       throw DataException("Error - DataTagged:: dump is not configured with netCDF. Please contact your installation manager.");
646       #endif
647  }  }
   
   
648  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.950  
changed lines
  Added in v.1023

  ViewVC Help
Powered by ViewVC 1.1.26