/[escript]/branches/windows_from_1456_trunk_1580_merged_in/escript/src/DataFactory.cpp
ViewVC logotype

Diff of /branches/windows_from_1456_trunk_1580_merged_in/escript/src/DataFactory.cpp

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

revision 1586 by phornby, Wed Jun 4 07:10:43 2008 UTC revision 1587 by phornby, Thu Jun 5 05:50:20 2008 UTC
# Line 14  Line 14 
14   *******************************************************/   *******************************************************/
15    
16  #include "DataFactory.h"  #include "DataFactory.h"
17    #include "esysUtils/esys_malloc.h"
18    
19  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
20  #include <iostream>  #include <iostream>
# Line 116  load(const std::string fileName, Line 117  load(const std::string fileName,
117         } else if (strncmp(type_str, "expanded", strlen("expanded")) == 0 ) {         } else if (strncmp(type_str, "expanded", strlen("expanded")) == 0 ) {
118             type =2;             type =2;
119         }         }
120         free(type_str);         esysUtils::free(type_str);
121     } else {     } else {
122        if (! (type_att=dataFile.get_att("type_id")) )        if (! (type_att=dataFile.get_att("type_id")) )
123      throw DataException("Error - load:: cannot recover type attribute from escript netCDF file.");      throw DataException("Error - load:: cannot recover type attribute from escript netCDF file.");
# Line 191  load(const std::string fileName, Line 192  load(const std::string fileName,
192           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.");
193        ntags=tags_dim->size();        ntags=tags_dim->size();
194        dims[rank]=ntags;        dims[rank]=ntags;
195        int *tags = (int *) malloc(ntags*sizeof(int));        int *tags = (int *) esysUtils::malloc(ntags*sizeof(int));
196        if (! ( tags_var = dataFile.get_var("tags")) )        if (! ( tags_var = dataFile.get_var("tags")) )
197        {        {
198           free(tags);           esysUtils::free(tags);
199           throw DataException("Error - load:: unable to find tags in netCDF file.");           throw DataException("Error - load:: unable to find tags in netCDF file.");
200        }        }
201        if (! tags_var->get(tags, ntags) )        if (! tags_var->get(tags, ntags) )
202        {        {
203           free(tags);           esysUtils::free(tags);
204           throw DataException("Error - load:: unable to recover tags from netCDF file.");           throw DataException("Error - load:: unable to recover tags from netCDF file.");
205        }        }
206    
207        DataVector data(len_data_point * ntags, 0., len_data_point * ntags);        DataVector data(len_data_point * ntags, 0., len_data_point * ntags);
208        if (!(var = dataFile.get_var("data")))        if (!(var = dataFile.get_var("data")))
209        {        {
210           free(tags);           esysUtils::free(tags);
211           throw DataException("Error - load:: unable to find data in netCDF file.");           throw DataException("Error - load:: unable to find data in netCDF file.");
212        }        }
213        if (! var->get(&(data[0]), dims) )        if (! var->get(&(data[0]), dims) )
214        {        {
215           free(tags);           esysUtils::free(tags);
216           throw DataException("Error - load:: unable to recover data from netCDF file.");           throw DataException("Error - load:: unable to recover data from netCDF file.");
217        }        }
218        out=Data(DataArrayView(data,shape,0),function_space);        out=Data(DataArrayView(data,shape,0),function_space);
219        for (int t=1; t<ntags; ++t) {        for (int t=1; t<ntags; ++t) {
220           out.setTaggedValueFromCPP(tags[t],DataArrayView(data,shape,t*len_data_point));           out.setTaggedValueFromCPP(tags[t],DataArrayView(data,shape,t*len_data_point));
221        }        }
222        free(tags);        esysUtils::free(tags);
223     } else if (type == 2) {     } else if (type == 2) {
224        /* expanded data */        /* expanded data */
225        if ( ! (ndims == rank + 2) )        if ( ! (ndims == rank + 2) )
# Line 236  load(const std::string fileName, Line 237  load(const std::string fileName,
237        if (! ( ids_var = dataFile.get_var("id")) )        if (! ( ids_var = dataFile.get_var("id")) )
238           throw DataException("Error - load:: unable to find reference ids in netCDF file.");           throw DataException("Error - load:: unable to find reference ids in netCDF file.");
239        const int* ids_p=function_space.borrowSampleReferenceIDs();        const int* ids_p=function_space.borrowSampleReferenceIDs();
240        int *ids_of_nc = (int *)malloc(num_samples*sizeof(int));        int *ids_of_nc = (int *)esysUtils::malloc(num_samples*sizeof(int));
241        if (! ids_var->get(ids_of_nc, (long) num_samples) )        if (! ids_var->get(ids_of_nc, (long) num_samples) )
242        {        {
243           free(ids_of_nc);           esysUtils::free(ids_of_nc);
244           throw DataException("Error - load:: unable to recover ids from netCDF file.");           throw DataException("Error - load:: unable to recover ids from netCDF file.");
245        }        }
246        // check order:        // check order:
# Line 256  load(const std::string fileName, Line 257  load(const std::string fileName,
257        }        }
258        /* if (failed>=0)        /* if (failed>=0)
259        {        {
260           free(ids_of_nc);           esysUtils::free(ids_of_nc);
261           throw DataException("Error - load:: data ordering in netCDF file does not match ordering of FunctionSpace.");           throw DataException("Error - load:: data ordering in netCDF file does not match ordering of FunctionSpace.");
262        } */        } */
263        // get the data:        // get the data:
# Line 265  load(const std::string fileName, Line 266  load(const std::string fileName,
266        out=Data(0,shape,function_space,true);        out=Data(0,shape,function_space,true);
267        if (!(var = dataFile.get_var("data")))        if (!(var = dataFile.get_var("data")))
268        {        {
269           free(ids_of_nc);           esysUtils::free(ids_of_nc);
270           throw DataException("Error - load:: unable to find data in netCDF file.");           throw DataException("Error - load:: unable to find data in netCDF file.");
271        }        }
272        if (! var->get(&(out.getDataPoint(0,0).getData()[0]), dims) )        if (! var->get(&(out.getDataPoint(0,0).getData()[0]), dims) )
273        {        {
274           free(ids_of_nc);           esysUtils::free(ids_of_nc);
275           throw DataException("Error - load:: unable to recover data from netCDF file.");           throw DataException("Error - load:: unable to recover data from netCDF file.");
276        }        }
277        if (failed>=0) {        if (failed>=0) {
# Line 279  load(const std::string fileName, Line 280  load(const std::string fileName,
280             out.borrowData()->reorderByReferenceIDs(ids_of_nc);             out.borrowData()->reorderByReferenceIDs(ids_of_nc);
281          }          }
282          catch (std::exception& e) {          catch (std::exception& e) {
283             free(ids_of_nc);             esysUtils::free(ids_of_nc);
284             throw DataException("Error - load:: unable to reorder data in netCDF file.");             throw DataException("Error - load:: unable to reorder data in netCDF file.");
285          }          }
286        }        }

Legend:
Removed from v.1586  
changed lines
  Added in v.1587

  ViewVC Help
Powered by ViewVC 1.1.26