/[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 985 by gross, Tue Feb 20 04:02:10 2007 UTC revision 1020 by phornby, Mon Mar 12 10:12:36 2007 UTC
# Line 175  load(const std::string fileName, Line 175  load(const std::string fileName,
175     } else if (type == 1) {     } else if (type == 1) {
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("num_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        dims[rank]=ntags;        dims[rank]=ntags;
183        int tags[ntags];        int *tags = (int *) malloc(ntags*sizeof(int));
184        if (! ( tags_var = dataFile.get_var("tags")) )        if (! ( tags_var = dataFile.get_var("tags")) )
185          {
186             free(tags);
187           throw DataException("Error - load:: unable to find tags in netCDF file.");           throw DataException("Error - load:: unable to find tags in netCDF file.");
188          }
189        if (! tags_var->get(tags, ntags) )        if (! tags_var->get(tags, ntags) )
190                throw DataException("Error - load:: unable to recover tags from netCDF file.");        {
191             free(tags);
192             throw DataException("Error - load:: unable to recover tags from netCDF file.");
193          }
194    
195        DataVector data(len_data_point*ntags,0.,len_data_point*ntags);        DataVector data(len_data_point*ntags,0.,len_data_point*ntags);
196        if (!(var = dataFile.get_var("data")))        if (!(var = dataFile.get_var("data")))
197                throw DataException("Error - load:: unable to find data in netCDF file.");        {
198             free(tags);
199             throw DataException("Error - load:: unable to find data in netCDF file.");
200          }
201        if (! var->get(&(data[0]), dims) )        if (! var->get(&(data[0]), dims) )
202                throw DataException("Error - load:: unable to recover data from netCDF file.");        {
203             free(tags);
204             throw DataException("Error - load:: unable to recover data from netCDF file.");
205          }
206        out=Data(DataArrayView(data,shape,0),function_space);        out=Data(DataArrayView(data,shape,0),function_space);
207        for (int t=1; t<ntags; ++t) {        for (int t=1; t<ntags; ++t) {
208           out.setTaggedValueFromCPP(tags[t],DataArrayView(data,shape,t*len_data_point));           out.setTaggedValueFromCPP(tags[t],DataArrayView(data,shape,t*len_data_point));
209        }        }
210          free(tags);
211     } else if (type == 2) {     } else if (type == 2) {
212        /* expanded data */        /* expanded data */
213        if ( ! (ndims == rank + 2) )        if ( ! (ndims == rank + 2) )
# Line 212  load(const std::string fileName, Line 225  load(const std::string fileName,
225        if (! ( ids_var = dataFile.get_var("id")) )        if (! ( ids_var = dataFile.get_var("id")) )
226           throw DataException("Error - load:: unable to find reference ids in netCDF file.");           throw DataException("Error - load:: unable to find reference ids in netCDF file.");
227        const int* ids_p=function_space.borrowSampleReferenceIDs();        const int* ids_p=function_space.borrowSampleReferenceIDs();
228        int ids_of_nc[num_samples];        int *ids_of_nc = (int *)malloc(num_samples*sizeof(int));
229        if (! ids_var->get(ids_of_nc, (long) num_samples) )        if (! ids_var->get(ids_of_nc, (long) num_samples) )
230                throw DataException("Error - load:: unable to recover ids from netCDF file.");        {
231             free(ids_of_nc);
232             throw DataException("Error - load:: unable to recover ids from netCDF file.");
233          }
234        // check order:        // check order:
235        int failed=-1, local_failed=-1, i;        int failed=-1, local_failed=-1, i;
236        #pragma omp parallel private(local_failed)        #pragma omp parallel private(local_failed)
# Line 228  load(const std::string fileName, Line 244  load(const std::string fileName,
244            if (local_failed>=0) failed = local_failed;            if (local_failed>=0) failed = local_failed;
245        }        }
246        if (failed>=0)        if (failed>=0)
247            throw DataException("Error - load:: data ordering in netCDF file does not match ordering of FunctionSpace.");        {
248             free(ids_of_nc);
249             throw DataException("Error - load:: data ordering in netCDF file does not match ordering of FunctionSpace.");
250          }
251        // get the data:        // get the data:
252        dims[rank]=num_data_points_per_sample;        dims[rank]=num_data_points_per_sample;
253        dims[rank+1]=num_samples;        dims[rank+1]=num_samples;
254        out=Data(0,shape,function_space,true);        out=Data(0,shape,function_space,true);
255        if (!(var = dataFile.get_var("data")))        if (!(var = dataFile.get_var("data")))
256                throw DataException("Error - load:: unable to find data in netCDF file.");        {
257             free(ids_of_nc);
258             throw DataException("Error - load:: unable to find data in netCDF file.");
259          }
260        if (! var->get(&(out.getDataPoint(0,0).getData()[0]), dims) )        if (! var->get(&(out.getDataPoint(0,0).getData()[0]), dims) )
261                throw DataException("Error - load:: unable to recover data from netCDF file.");        {
262             free(ids_of_nc);
263             throw DataException("Error - load:: unable to recover data from netCDF file.");
264          }
265        // if (failed==-1)        // if (failed==-1)
266        //   out->m_data.reorderByReferenceIDs(ids_of_nc)        //   out->m_data.reorderByReferenceIDs(ids_of_nc)
267          free(ids_of_nc);
268     } else {     } else {
269         throw DataException("Error - load:: unknown escript data type in netCDF file.");         throw DataException("Error - load:: unknown escript data type in netCDF file.");
270     }     }

Legend:
Removed from v.985  
changed lines
  Added in v.1020

  ViewVC Help
Powered by ViewVC 1.1.26