/[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 800 by gross, Tue Aug 8 11:23:18 2006 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 131  DataTagged::DataTagged(const DataConstan Line 134  DataTagged::DataTagged(const DataConstan
134    setPointDataView(temp);    setPointDataView(temp);
135  }  }
136    
 void  
 DataTagged::reshapeDataPoint(const DataArrayView::ShapeType& shape)  
 {  
   // can only reshape a rank zero data point  
   if (getPointDataView().getRank()!=0) {  
     stringstream temp;  
     temp << "Error - Can only reshape Data with data points of rank 0. "  
      << "This Data has data points with rank: "  
      << getPointDataView().getRank();  
     throw DataException(temp.str());  
   }  
   
   // allocate enough space for all values  
   DataArrayView::ValueType newData(DataArrayView::noValues(shape)*(m_offsetLookup.size()+1));  
   DataArrayView newView(newData,shape);  
   newView.copy(0,getDefaultValue()());  
   
   // loop through the tag values  
   DataMapType::iterator pos;  
   DataArrayView::ValueType::size_type tagOffset=DataArrayView::noValues(shape);  
   for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++){  
     newView.copy(tagOffset,m_data[pos->second]);  
     pos->second=tagOffset;  
     tagOffset+=DataArrayView::noValues(shape);  
   }  
   m_data=newData;  
   DataArrayView temp(m_data,shape);  
   setPointDataView(temp);  
 }  
   
137  DataAbstract*  DataAbstract*
138  DataTagged::getSlice(const DataArrayView::RegionType& region) const  DataTagged::getSlice(const DataArrayView::RegionType& region) const
139  {  {
# Line 517  DataTagged::transpose(DataAbstract* ev, Line 490  DataTagged::transpose(DataAbstract* ev,
490  }  }
491    
492  void  void
493  DataTagged::swap(DataAbstract* ev, int axis_offset)  DataTagged::swapaxes(DataAbstract* ev, int axis0, int axis1)
494  {  {
495    DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);    DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
496    if (temp_ev==0) {    if (temp_ev==0) {
497      throw DataException("Error - DataTagged::swap casting to DataTagged failed (probably a programming error).");      throw DataException("Error - DataTagged::swapaxes casting to DataTagged failed (probably a programming error).");
498    }    }
499    const DataTagged::DataMapType& thisLookup=getTagLookup();    const DataTagged::DataMapType& thisLookup=getTagLookup();
500    DataTagged::DataMapType::const_iterator i;    DataTagged::DataMapType::const_iterator i;
# Line 530  DataTagged::swap(DataAbstract* ev, int a Line 503  DataTagged::swap(DataAbstract* ev, int a
503        temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());        temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
504        DataArrayView thisView=getDataPointByTag(i->first);        DataArrayView thisView=getDataPointByTag(i->first);
505        DataArrayView evView=temp_ev->getDataPointByTag(i->first);        DataArrayView evView=temp_ev->getDataPointByTag(i->first);
506        DataArrayView::swap(thisView,0,evView,0, axis_offset);        DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
507    }    }
508    DataArrayView::swap(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);    DataArrayView::swapaxes(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis0,axis1);
509  }  }
510    
511  void  void
# Line 583  DataTagged::eigenvalues_and_eigenvectors Line 556  DataTagged::eigenvalues_and_eigenvectors
556    
557  }  }
558    
559    void
560    DataTagged::dump(const std::string fileName) const
561    {
562       #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.800  
changed lines
  Added in v.1023

  ViewVC Help
Powered by ViewVC 1.1.26