/[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 1141 by gross, Tue May 15 04:24:51 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 361  DataTagged::toString() const Line 364  DataTagged::toString() const
364      tempView.setOffset(i->second);      tempView.setOffset(i->second);
365      temp << tempView.toString() << endl;      temp << tempView.toString() << endl;
366    }    }
367    return temp.str();    return string(temp.str());
368  }  }
369    
370  DataArrayView::ValueType::size_type  DataArrayView::ValueType::size_type
# Line 554  DataTagged::eigenvalues_and_eigenvectors Line 557  DataTagged::eigenvalues_and_eigenvectors
557  }  }
558    
559  void  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  DataTagged::dump(const std::string fileName) const
567  {  {
568      throw DataException("Error - DataTagged:: dump: not implemented.");     #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       const double* d_ptr=&(m_data[0]);
580       DataArrayView::ShapeType shape = getPointDataView().getShape();
581    
582       // netCDF error handler
583       NcError err(NcError::verbose_nonfatal);
584       // Create the file.
585       NcFile dataFile(fileName.c_str(), NcFile::Replace);
586       // check if writing was successful
587       if (!dataFile.is_valid())
588            throw DataException("Error - DataTagged:: opening of netCDF file for output failed.");
589       if (!dataFile.add_att("type_id",1) )
590            throw DataException("Error - DataTagged:: appending data type to netCDF file failed.");
591       if (!dataFile.add_att("rank",rank) )
592            throw DataException("Error - DataTagged:: appending rank attribute to netCDF file failed.");
593       if (!dataFile.add_att("function_space_type",type))
594            throw DataException("Error - DataTagged:: appending function space attribute to netCDF file failed.");
595       ndims=rank+1;
596       if ( rank >0 ) {
597           dims[0]=shape[0];
598           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
599                throw DataException("Error - DataTagged:: appending ncdimsion 0 to netCDF file failed.");
600       }
601       if ( rank >1 ) {
602           dims[1]=shape[1];
603           if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
604                throw DataException("Error - DataTagged:: appending ncdimsion 1 to netCDF file failed.");
605       }
606       if ( rank >2 ) {
607           dims[2]=shape[2];
608           if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
609                throw DataException("Error - DataTagged:: appending ncdimsion 2 to netCDF file failed.");
610       }
611       if ( rank >3 ) {
612           dims[3]=shape[3];
613           if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
614                throw DataException("Error - DataTagged:: appending ncdimsion 3 to netCDF file failed.");
615       }
616       const DataTagged::DataMapType& thisLookup=getTagLookup();
617       DataTagged::DataMapType::const_iterator i;
618       DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
619       int ntags=1;
620       for (i=thisLookup.begin();i!=thisLookupEnd;i++) ntags++;
621       int* tags =(int*) malloc(ntags*sizeof(int));
622       int c=1;
623       tags[0]=-1;
624       for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;
625       dims[rank]=ntags;
626       if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )
627       {
628           free(tags);
629               throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");
630       }
631       if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )
632       {
633        free(tags);
634            throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");
635       }
636       if (! (tags_var->put(tags,dims[rank])) )
637       {
638        free(tags);
639            throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");
640       }
641       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
642       {
643        free(tags);
644            throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");
645       }
646       if (! (var->put(d_ptr,dims)) )
647       {
648        free(tags);
649            throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
650       }
651       #else
652       throw DataException("Error - DataTagged:: dump is not configured with netCDF. Please contact your installation manager.");
653       #endif
654  }  }
   
   
655  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26