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

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

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

revision 964 by gross, Tue Feb 13 05:10:26 2007 UTC revision 1141 by gross, Tue May 15 04:24:51 2007 UTC
# Line 15  Line 15 
15  #include "DataException.h"  #include "DataException.h"
16  #include "DataConstant.h"  #include "DataConstant.h"
17  #include "DataTagged.h"  #include "DataTagged.h"
18    #ifdef USE_NETCDF
19    #include "netcdfcpp.h"
20    #endif
21    
22  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
23    
# Line 268  DataExpanded::toString() const Line 271  DataExpanded::toString() const
271        }        }
272      }      }
273    }    }
274    return temp.str();    return string(temp.str());
275  }  }
276    
277  DataArrayView::ValueType::size_type  DataArrayView::ValueType::size_type
# Line 615  DataExpanded::eigenvalues_and_eigenvecto Line 618  DataExpanded::eigenvalues_and_eigenvecto
618  }  }
619    
620  void  void
621  DataExpanded::dump(const std::string fileName) const  DataExpanded::setToZero(){
622  {    int numSamples = getNumSamples();
623      throw DataException("Error - DataExpanded:: dump: not implemented.");    int numDataPointsPerSample = getNumDPPSample();
624      DataArrayView& thisView=getPointDataView();
625      DataArrayView::ValueType::size_type n = thisView.noValues();
626      double* p;
627      int  sampleNo,dataPointNo, i;
628      #pragma omp parallel for private(sampleNo,dataPointNo,p,i) schedule(static)
629      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
630        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
631            p=&(m_data[getPointOffset(sampleNo,dataPointNo)]);
632            for (int i=0; i<n ;++i) p[i]=0.;
633        }
634      }
635  }  }
636    
637    
638    void
639    DataExpanded::dump(const std::string fileName) const
640    {
641       #ifdef PASO_MPI
642       throw DataException("Error - DataExpanded:: dump is not implemented for MPI yet.");
643       #endif
644       #ifdef USE_NETCDF
645       const int ldims=2+DataArrayView::maxRank;
646       const NcDim* ncdims[ldims];
647       NcVar *var, *ids;
648       int rank = getPointDataView().getRank();
649       int type=  getFunctionSpace().getTypeCode();
650       int ndims =0;
651       long dims[ldims];
652       const double* d_ptr=&(m_data[0]);
653       DataArrayView::ShapeType shape = getPointDataView().getShape();
654    
655       // netCDF error handler
656       NcError err(NcError::verbose_nonfatal);
657       // Create the file.
658       NcFile dataFile(fileName.c_str(), NcFile::Replace);
659       // check if writing was successful
660       if (!dataFile.is_valid())
661            throw DataException("Error - DataExpanded:: opening of netCDF file for output failed.");
662       if (!dataFile.add_att("type_id",2) )
663            throw DataException("Error - DataExpanded:: appending data type to netCDF file failed.");
664       if (!dataFile.add_att("rank",rank) )
665            throw DataException("Error - DataExpanded:: appending rank attribute to netCDF file failed.");
666       if (!dataFile.add_att("function_space_type",type))
667            throw DataException("Error - DataExpanded:: appending function space attribute to netCDF file failed.");
668       ndims=rank+2;
669       if ( rank >0 ) {
670           dims[0]=shape[0];
671           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
672                throw DataException("Error - DataExpanded:: appending ncdimsion 0 to netCDF file failed.");
673       }
674       if ( rank >1 ) {
675           dims[1]=shape[1];
676           if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
677                throw DataException("Error - DataExpanded:: appending ncdimsion 1 to netCDF file failed.");
678       }
679       if ( rank >2 ) {
680           dims[2]=shape[2];
681           if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
682                throw DataException("Error - DataExpanded:: appending ncdimsion 2 to netCDF file failed.");
683       }
684       if ( rank >3 ) {
685           dims[3]=shape[3];
686           if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
687                throw DataException("Error - DataExpanded:: appending ncdimsion 3 to netCDF file failed.");
688       }
689       dims[rank]=getFunctionSpace().getNumDataPointsPerSample();
690       if (! (ncdims[rank] = dataFile.add_dim("num_data_points_per_sample", dims[rank])) )
691                throw DataException("Error - DataExpanded:: appending num_data_points_per_sample to netCDF file failed.");
692       dims[rank+1]=getFunctionSpace().getNumSamples();
693       if (! (ncdims[rank+1] = dataFile.add_dim("num_samples", dims[rank+1])) )
694                throw DataException("Error - DataExpanded:: appending num_sample to netCDF file failed.");
695    
696       if (! ( ids = dataFile.add_var("id", ncInt, ncdims[rank+1])) )
697            throw DataException("Error - DataExpanded:: appending reference id to netCDF file failed.");
698       const int* ids_p=getFunctionSpace().borrowSampleReferenceIDs();
699       if (! (ids->put(ids_p,dims[rank+1])) )
700            throw DataException("Error - DataExpanded:: copy reference id  to netCDF buffer failed.");
701    
702       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
703            throw DataException("Error - DataExpanded:: appending variable to netCDF file failed.");
704       if (! (var->put(d_ptr,dims)) )
705            throw DataException("Error - DataExpanded:: copy data to netCDF buffer failed.");
706       #else
707       throw DataException("Error - DataExpanded:: dump is not configured with netCDF. Please contact your installation manager.");
708       #endif
709    }
710  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26