/[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 982 by gross, Mon Feb 19 23:55:52 2007 UTC revision 983 by gross, Tue Feb 20 02:49:08 2007 UTC
# Line 115  load(const std::string fileName, Line 115  load(const std::string fileName,
115     delete type_str;     delete type_str;
116     /* recover dimension */     /* recover dimension */
117     int ndims=dataFile.num_dims();     int ndims=dataFile.num_dims();
118     int ntags =0 , num_samples =0 , num_data_points_per_sample =0, d=0;     int ntags =0 , num_samples =0 , num_data_points_per_sample =0, d=0, len_data_point=1;
119     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;
120     /* recover shape */     /* recover shape */
121     DataArrayView::ShapeType shape;     DataArrayView::ShapeType shape;
# Line 126  load(const std::string fileName, Line 126  load(const std::string fileName,
126        d=d_dim->size();        d=d_dim->size();
127        shape.push_back(d);        shape.push_back(d);
128        dims[0]=d;        dims[0]=d;
129          len_data_point*=d;
130     }     }
131     if (rank>1) {     if (rank>1) {
132       if (! (d_dim=dataFile.get_dim("d1")) )       if (! (d_dim=dataFile.get_dim("d1")) )
# Line 133  load(const std::string fileName, Line 134  load(const std::string fileName,
134        d=d_dim->size();        d=d_dim->size();
135        shape.push_back(d);        shape.push_back(d);
136        dims[1]=d;        dims[1]=d;
137          len_data_point*=d;
138     }     }
139     if (rank>2) {     if (rank>2) {
140       if (! (d_dim=dataFile.get_dim("d2")) )       if (! (d_dim=dataFile.get_dim("d2")) )
# Line 140  load(const std::string fileName, Line 142  load(const std::string fileName,
142        d=d_dim->size();        d=d_dim->size();
143        shape.push_back(d);        shape.push_back(d);
144        dims[2]=d;        dims[2]=d;
145          len_data_point*=d;
146     }     }
147     if (rank>3) {     if (rank>3) {
148       if (! (d_dim=dataFile.get_dim("d3")) )       if (! (d_dim=dataFile.get_dim("d3")) )
# Line 147  load(const std::string fileName, Line 150  load(const std::string fileName,
150        d=d_dim->size();        d=d_dim->size();
151        shape.push_back(d);        shape.push_back(d);
152        dims[3]=d;        dims[3]=d;
153          len_data_point*=d;
154     }     }
155     /* recover stuff */     /* recover stuff */
156     Data out;     Data out;
157     NcVar *var, *ids_var;     NcVar *var, *ids_var, *tags_var;
158     if (type == 0) {     if (type == 0) {
159        /* constant data */        /* constant data */
160        if ( ! ( (ndims == rank && rank >0) || ( ndims ==1 && rank == 0 ) ) )        if ( ! ( (ndims == rank && rank >0) || ( ndims ==1 && rank == 0 ) ) )
# Line 172  load(const std::string fileName, Line 176  load(const std::string fileName,
176        /* tagged data */        /* tagged data */
177        if ( ! (ndims == rank + 1) )        if ( ! (ndims == rank + 1) )
178            throw DataException("Error - load:: illegal number of dimensions for tagged data in netCDF file.");            throw DataException("Error - load:: illegal number of dimensions for tagged data in netCDF file.");
179        if (! (tags_dim=dataFile.get_dim("tags")) )        if (! (tags_dim=dataFile.get_dim("num_tags")) )
180            throw DataException("Error - load:: unable to recover number of tags from netCDF file.");            throw DataException("Error - load:: unable to recover number of tags from netCDF file.");
181        ntags=tags_dim->size();        ntags=tags_dim->size();
182        out=Data(0,shape,function_space);        dims[rank]=ntags;
183          int tags[ntags];
184          if (! ( tags_var = dataFile.get_var("tags")) )
185             throw DataException("Error - load:: unable to find tags in netCDF file.");
186          if (! tags_var->get(tags, ntags) )
187                  throw DataException("Error - load:: unable to recover tags from netCDF file.");
188    
189          DataVector data(len_data_point*ntags,0.,len_data_point*ntags);
190          if (!(var = dataFile.get_var("data")))
191                  throw DataException("Error - load:: unable to find data in netCDF file.");
192          if (! var->get(&(data[0]), dims) )
193                  throw DataException("Error - load:: unable to recover data from netCDF file.");
194          out=Data(DataArrayView(data,shape,0),function_space);
195          for (int t=1; t<ntags; ++t) {
196             out.setTaggedValueFromCPP(tags[t],DataArrayView(data,shape,t*len_data_point));
197          }
198     } else if (type == 2) {     } else if (type == 2) {
199        /* expanded data */        /* expanded data */
200        if ( ! (ndims == rank + 2) )        if ( ! (ndims == rank + 2) )

Legend:
Removed from v.982  
changed lines
  Added in v.983

  ViewVC Help
Powered by ViewVC 1.1.26