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

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

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

revision 1795 by ksteube, Wed Sep 3 06:10:39 2008 UTC revision 1796 by jfenwick, Wed Sep 17 01:45:46 2008 UTC
# Line 37  Scalar(double value, Line 37  Scalar(double value,
37  {  {
38      //      //
39      // an empty shape is a scalar      // an empty shape is a scalar
40      DataArrayView::ShapeType shape;      DataTypes::ShapeType shape;
41      return Data(value,shape,what,expanded);      return Data(value,shape,what,expanded);
42  }  }
43    
# Line 46  Vector(double value, Line 46  Vector(double value,
46         const FunctionSpace& what,         const FunctionSpace& what,
47         bool expanded)         bool expanded)
48  {  {
49      DataArrayView::ShapeType shape(1,what.getDomain().getDim());      DataTypes::ShapeType shape(1,what.getDomain().getDim());
50      return Data(value,shape,what,expanded);      return Data(value,shape,what,expanded);
51  }  }
52    
# Line 55  Tensor(double value, Line 55  Tensor(double value,
55         const FunctionSpace& what,         const FunctionSpace& what,
56         bool expanded)         bool expanded)
57  {  {
58      DataArrayView::ShapeType shape(2,what.getDomain().getDim());      DataTypes::ShapeType shape(2,what.getDomain().getDim());
59      return Data(value,shape,what,expanded);      return Data(value,shape,what,expanded);
60  }  }
61    
# Line 64  Tensor3(double value, Line 64  Tensor3(double value,
64          const FunctionSpace& what,          const FunctionSpace& what,
65          bool expanded)          bool expanded)
66  {  {
67      DataArrayView::ShapeType shape(3,what.getDomain().getDim());      DataTypes::ShapeType shape(3,what.getDomain().getDim());
68      return Data(value,shape,what,expanded);      return Data(value,shape,what,expanded);
69  }  }
70    
# Line 73  Tensor4(double value, Line 73  Tensor4(double value,
73          const FunctionSpace& what,          const FunctionSpace& what,
74          bool expanded)          bool expanded)
75  {  {
76      DataArrayView::ShapeType shape(4,what.getDomain().getDim());      DataTypes::ShapeType shape(4,what.getDomain().getDim());
77      return Data(value,shape,what,expanded);      return Data(value,shape,what,expanded);
78  }  }
79    
# Line 109  load(const std::string fileName, Line 109  load(const std::string fileName,
109          throw DataException("Error - load:: cannot recover rank attribute from escript netCDF file.");          throw DataException("Error - load:: cannot recover rank attribute from escript netCDF file.");
110     int rank = rank_att->as_int(0);     int rank = rank_att->as_int(0);
111     delete rank_att;     delete rank_att;
112     if (rank<0 || rank>DataArrayView::maxRank)     if (rank<0 || rank>DataTypes::maxRank)
113          throw DataException("Error - load:: rank in escript netCDF file is greater than maximum rank.");          throw DataException("Error - load:: rank in escript netCDF file is greater than maximum rank.");
114     /* recover type attribute */     /* recover type attribute */
115     int type=-1;     int type=-1;
# Line 135  load(const std::string fileName, Line 135  load(const std::string fileName,
135     int ntags =0 , num_samples =0 , num_data_points_per_sample =0, d=0, len_data_point=1;     int ntags =0 , num_samples =0 , num_data_points_per_sample =0, d=0, len_data_point=1;
136     NcDim *d_dim, *tags_dim, *num_samples_dim, *num_data_points_per_sample_dim;     NcDim *d_dim, *tags_dim, *num_samples_dim, *num_data_points_per_sample_dim;
137     /* recover shape */     /* recover shape */
138     DataArrayView::ShapeType shape;     DataTypes::ShapeType shape;
139     long dims[DataArrayView::maxRank+2];     long dims[DataTypes::maxRank+2];
140     if (rank>0) {     if (rank>0) {
141       if (! (d_dim=dataFile.get_dim("d0")) )       if (! (d_dim=dataFile.get_dim("d0")) )
142            throw DataException("Error - load:: unable to recover d0 from netCDF file.");            throw DataException("Error - load:: unable to recover d0 from netCDF file.");
# Line 187  load(const std::string fileName, Line 187  load(const std::string fileName,
187        out=Data(0,shape,function_space);        out=Data(0,shape,function_space);
188        if (!(var = dataFile.get_var("data")))        if (!(var = dataFile.get_var("data")))
189                throw DataException("Error - load:: unable to find data in netCDF file.");                throw DataException("Error - load:: unable to find data in netCDF file.");
190        if (! var->get(&(out.getDataPoint(0,0).getData()[0]), dims) )        if (! var->get(&(out.getDataAtOffset(out.getDataOffset(0,0))), dims) )
191                throw DataException("Error - load:: unable to recover data from netCDF file.");                throw DataException("Error - load:: unable to recover data from netCDF file.");
192     } else if (type == 1) {     } else if (type == 1) {
193        /* tagged data */        /* tagged data */
# Line 209  load(const std::string fileName, Line 209  load(const std::string fileName,
209           throw DataException("Error - load:: unable to recover tags from netCDF file.");           throw DataException("Error - load:: unable to recover tags from netCDF file.");
210        }        }
211    
212        DataVector data(len_data_point * ntags, 0., len_data_point * ntags);  // Current Version
213    /*      DataVector data(len_data_point * ntags, 0., len_data_point * ntags);
214        if (!(var = dataFile.get_var("data")))        if (!(var = dataFile.get_var("data")))
215        {        {
216           esysUtils::free(tags);           esysUtils::free(tags);
# Line 222  load(const std::string fileName, Line 223  load(const std::string fileName,
223        }        }
224        out=Data(DataArrayView(data,shape,0),function_space);        out=Data(DataArrayView(data,shape,0),function_space);
225        for (int t=1; t<ntags; ++t) {        for (int t=1; t<ntags; ++t) {
226           out.setTaggedValueFromCPP(tags[t],DataArrayView(data,shape,t*len_data_point));       out.setTaggedValueFromCPP(tags[t],shape, data, t*len_data_point);
227    //         out.setTaggedValueFromCPP(tags[t],DataArrayView(data,shape,t*len_data_point));
228          }*/
229    // End current version
230        
231    // New version
232    
233        // A) create a DataTagged dt
234        // B) Read data from file
235        // C) copy default value into dt
236        // D) copy tagged values into dt
237        // E) create a new Data based on dt
238    
239          NcVar* var1;
240          DataVector data1(len_data_point * ntags, 0., len_data_point * ntags);
241          if (!(var1 = dataFile.get_var("data")))
242          {
243             esysUtils::free(tags);
244             throw DataException("Error - load:: unable to find data in netCDF file.");
245          }
246          if (! var1->get(&(data1[0]), dims) )
247          {
248             esysUtils::free(tags);
249             throw DataException("Error - load:: unable to recover data from netCDF file.");
250        }        }
251          DataTagged* dt=new DataTagged(function_space, shape, tags,data1);
252          out=Data(dt);
253        esysUtils::free(tags);        esysUtils::free(tags);
254     } else if (type == 2) {     } else if (type == 2) {
255        /* expanded data */        /* expanded data */
# Line 274  load(const std::string fileName, Line 300  load(const std::string fileName,
300           esysUtils::free(ids_of_nc);           esysUtils::free(ids_of_nc);
301           throw DataException("Error - load:: unable to find data in netCDF file.");           throw DataException("Error - load:: unable to find data in netCDF file.");
302        }        }
303        if (! var->get(&(out.getDataPoint(0,0).getData()[0]), dims) )        if (! var->get(&(out.getDataAtOffset(out.getDataOffset(0,0))), dims) )
304        {        {
305           esysUtils::free(ids_of_nc);           esysUtils::free(ids_of_nc);
306           throw DataException("Error - load:: unable to recover data from netCDF file.");           throw DataException("Error - load:: unable to recover data from netCDF file.");

Legend:
Removed from v.1795  
changed lines
  Added in v.1796

  ViewVC Help
Powered by ViewVC 1.1.26