/[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 983 by gross, Tue Feb 20 02:49:08 2007 UTC revision 1023 by gross, Tue Mar 13 05:43:36 2007 UTC
# Line 15  Line 15 
15    
16  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
17  #include <iostream>  #include <iostream>
18    #ifdef USE_NETCDF
19  #include <netcdfcpp.h>  #include <netcdfcpp.h>
20    #endif
21    
22  using namespace boost::python;  using namespace boost::python;
23    
# Line 73  load(const std::string fileName, Line 75  load(const std::string fileName,
75       const AbstractDomain& domain)       const AbstractDomain& domain)
76  {  {
77     #ifdef PASO_MPI     #ifdef PASO_MPI
78     throw DataException("Error - DataConstant:: dump is not implemented for MPI yet.")     throw DataException("Error - load :: not implemented for MPI yet.")
79     #endif     #endif
80    
81       #ifdef USE_NETCDF
82     NcAtt *type_att, *rank_att, *function_space_type_att;     NcAtt *type_att, *rank_att, *function_space_type_att;
83     // netCDF error handler     // netCDF error handler
84     NcError err(NcError::verbose_nonfatal);     NcError err(NcError::verbose_nonfatal);
# Line 175  load(const std::string fileName, Line 179  load(const std::string fileName,
179     } else if (type == 1) {     } else if (type == 1) {
180        /* tagged data */        /* tagged data */
181        if ( ! (ndims == rank + 1) )        if ( ! (ndims == rank + 1) )
182            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.");
183        if (! (tags_dim=dataFile.get_dim("num_tags")) )        if (! (tags_dim=dataFile.get_dim("num_tags")) )
184            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.");
185        ntags=tags_dim->size();        ntags=tags_dim->size();
186        dims[rank]=ntags;        dims[rank]=ntags;
187        int tags[ntags];        int *tags = (int *) malloc(ntags*sizeof(int));
188        if (! ( tags_var = dataFile.get_var("tags")) )        if (! ( tags_var = dataFile.get_var("tags")) )
189          {
190             free(tags);
191           throw DataException("Error - load:: unable to find tags in netCDF file.");           throw DataException("Error - load:: unable to find tags in netCDF file.");
192          }
193        if (! tags_var->get(tags, ntags) )        if (! tags_var->get(tags, ntags) )
194                throw DataException("Error - load:: unable to recover tags from netCDF file.");        {
195             free(tags);
196             throw DataException("Error - load:: unable to recover tags from netCDF file.");
197          }
198    
199        DataVector data(len_data_point*ntags,0.,len_data_point*ntags);        DataVector data(len_data_point*ntags,0.,len_data_point*ntags);
200        if (!(var = dataFile.get_var("data")))        if (!(var = dataFile.get_var("data")))
201                throw DataException("Error - load:: unable to find data in netCDF file.");        {
202             free(tags);
203             throw DataException("Error - load:: unable to find data in netCDF file.");
204          }
205        if (! var->get(&(data[0]), dims) )        if (! var->get(&(data[0]), dims) )
206                throw DataException("Error - load:: unable to recover data from netCDF file.");        {
207             free(tags);
208             throw DataException("Error - load:: unable to recover data from netCDF file.");
209          }
210        out=Data(DataArrayView(data,shape,0),function_space);        out=Data(DataArrayView(data,shape,0),function_space);
211        for (int t=1; t<ntags; ++t) {        for (int t=1; t<ntags; ++t) {
212           out.setTaggedValueFromCPP(tags[t],DataArrayView(data,shape,t*len_data_point));           out.setTaggedValueFromCPP(tags[t],DataArrayView(data,shape,t*len_data_point));
213        }        }
214          free(tags);
215     } else if (type == 2) {     } else if (type == 2) {
216        /* expanded data */        /* expanded data */
217        if ( ! (ndims == rank + 2) )        if ( ! (ndims == rank + 2) )
# Line 212  load(const std::string fileName, Line 229  load(const std::string fileName,
229        if (! ( ids_var = dataFile.get_var("id")) )        if (! ( ids_var = dataFile.get_var("id")) )
230           throw DataException("Error - load:: unable to find reference ids in netCDF file.");           throw DataException("Error - load:: unable to find reference ids in netCDF file.");
231        const int* ids_p=function_space.borrowSampleReferenceIDs();        const int* ids_p=function_space.borrowSampleReferenceIDs();
232        int ids_of_nc[num_samples];        int *ids_of_nc = (int *)malloc(num_samples*sizeof(int));
233        if (! ids_var->get(ids_of_nc, (long) num_samples) )        if (! ids_var->get(ids_of_nc, (long) num_samples) )
234                throw DataException("Error - load:: unable to recover ids from netCDF file.");        {
235             free(ids_of_nc);
236             throw DataException("Error - load:: unable to recover ids from netCDF file.");
237          }
238        // check order:        // check order:
239        int failed=-1, local_failed=-1, i;        int failed=-1, local_failed=-1, i;
240        #pragma omp parallel private(local_failed)        #pragma omp parallel private(local_failed)
241        {        {
242              local_failed=-1;
243            #pragma omp for private(i) schedule(static)            #pragma omp for private(i) schedule(static)
244            for (i=0;i < num_samples; ++i)            for (i=0;i < num_samples; ++i) {
245                if (ids_of_nc[i]!=ids_p[i]) local_failed=i;                if (ids_of_nc[i]!=ids_p[i]) local_failed=i;
246              }
247            #pragma omp critical            #pragma omp critical
248            if (local_failed>=0) failed = local_failed;            if (local_failed>=0) failed = local_failed;
249        }        }
250        if (failed>=0)        if (failed>=0)
251            throw DataException("Error - load:: data ordering in netCDF file does not match ordering of FunctionSpace.");        {
252             free(ids_of_nc);
253             throw DataException("Error - load:: data ordering in netCDF file does not match ordering of FunctionSpace.");
254          }
255        // get the data:        // get the data:
256        dims[rank]=num_data_points_per_sample;        dims[rank]=num_data_points_per_sample;
257        dims[rank+1]=num_samples;        dims[rank+1]=num_samples;
258        out=Data(0,shape,function_space,true);        out=Data(0,shape,function_space,true);
259        if (!(var = dataFile.get_var("data")))        if (!(var = dataFile.get_var("data")))
260                throw DataException("Error - load:: unable to find data in netCDF file.");        {
261             free(ids_of_nc);
262             throw DataException("Error - load:: unable to find data in netCDF file.");
263          }
264        if (! var->get(&(out.getDataPoint(0,0).getData()[0]), dims) )        if (! var->get(&(out.getDataPoint(0,0).getData()[0]), dims) )
265                throw DataException("Error - load:: unable to recover data from netCDF file.");        {
266             free(ids_of_nc);
267             throw DataException("Error - load:: unable to recover data from netCDF file.");
268          }
269        // if (failed==-1)        // if (failed==-1)
270        //   out->m_data.reorderByReferenceIDs(ids_of_nc)        //   out->m_data.reorderByReferenceIDs(ids_of_nc)
271          free(ids_of_nc);
272     } else {     } else {
273         throw DataException("Error - load:: unknown escript data type in netCDF file.");         throw DataException("Error - load:: unknown escript data type in netCDF file.");
274     }     }
275     return out;     return out;
276       #else
277       throw DataException("Error - load:: is not compiled with netCFD. Please contact your insatllation manager.");
278       #endif
279    }
280    
281    bool
282    loadConfigured()
283    {
284       #ifdef USE_NETCDF
285       return true;
286       #else
287       return false;
288       #endif
289  }  }
290    
291  Data  Data

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

  ViewVC Help
Powered by ViewVC 1.1.26