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

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

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

revision 1141 by gross, Tue May 15 04:24:51 2007 UTC revision 1628 by phornby, Fri Jul 11 13:12:46 2008 UTC
# Line 1  Line 1 
 // $Id$  
1    
2  /*  /* $Id$ */
3   ************************************************************  
4   *          Copyright 2006 by ACcESS MNRF                   *  /*******************************************************
5   *                                                          *   *
6   *              http://www.access.edu.au                    *   *           Copyright 2003-2007 by ACceSS MNRF
7   *       Primary Business: Queensland, Australia            *   *       Copyright 2007 by University of Queensland
8   *  Licensed under the Open Software License version 3.0    *   *
9   *     http://www.opensource.org/licenses/osl-3.0.php       *   *                http://esscc.uq.edu.au
10   *                                                          *   *        Primary Business: Queensland, Australia
11   ************************************************************   *  Licensed under the Open Software License version 3.0
12  */   *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  #include "DataTagged.h"  #include "DataTagged.h"
17    #include "esysUtils/esys_malloc.h"
18    
19  #include "DataConstant.h"  #include "DataConstant.h"
20  #include "DataException.h"  #include "DataException.h"
21  #ifdef USE_NETCDF  #ifdef USE_NETCDF
22  #include "netcdfcpp.h"  #include <netcdfcpp.h>
23  #endif  #endif
24    
25  using namespace std;  using namespace std;
# Line 299  DataTagged::addTaggedValues(const TagLis Line 301  DataTagged::addTaggedValues(const TagLis
301         << " doesn't match number of values: " << values.size();         << " doesn't match number of values: " << values.size();
302        throw DataException(temp.str());        throw DataException(temp.str());
303      } else {      } else {
304        for (int i=0;i<tagKeys.size();i++) {        unsigned int i;
305          for (i=0;i<tagKeys.size();i++) {
306          addTaggedValue(tagKeys[i],values[i]);          addTaggedValue(tagKeys[i],values[i]);
307        }        }
308      }      }
# Line 364  DataTagged::toString() const Line 367  DataTagged::toString() const
367      tempView.setOffset(i->second);      tempView.setOffset(i->second);
368      temp << tempView.toString() << endl;      temp << tempView.toString() << endl;
369    }    }
370    return string(temp.str());    return temp.str();
371  }  }
372    
373  DataArrayView::ValueType::size_type  DataArrayView::ValueType::size_type
# Line 566  void Line 569  void
569  DataTagged::dump(const std::string fileName) const  DataTagged::dump(const std::string fileName) const
570  {  {
571     #ifdef PASO_MPI     #ifdef PASO_MPI
572     throw DataException("Error - DataTagged:: dump is not implemented for MPI yet.")     throw DataException("Error - DataTagged:: dump is not implemented for MPI yet.");
573     #endif     #endif
574     #ifdef USE_NETCDF     #ifdef USE_NETCDF
575     const int ldims=DataArrayView::maxRank+1;     const int ldims=DataArrayView::maxRank+1;
# Line 618  DataTagged::dump(const std::string fileN Line 621  DataTagged::dump(const std::string fileN
621     DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();     DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
622     int ntags=1;     int ntags=1;
623     for (i=thisLookup.begin();i!=thisLookupEnd;i++) ntags++;     for (i=thisLookup.begin();i!=thisLookupEnd;i++) ntags++;
624     int* tags =(int*) malloc(ntags*sizeof(int));     int* tags =(int*) esysUtils::malloc(ntags*sizeof(int));
625     int c=1;     int c=1;
626     tags[0]=-1;     tags[0]=-1;
627     for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;     for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;
628     dims[rank]=ntags;     dims[rank]=ntags;
629     if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )     if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )
630     {     {
631         free(tags);         esysUtils::free(tags);
632             throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");             throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");
633     }     }
634     if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )     if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )
635     {     {
636      free(tags);      esysUtils::free(tags);
637          throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");          throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");
638     }     }
639     if (! (tags_var->put(tags,dims[rank])) )     if (! (tags_var->put(tags,dims[rank])) )
640     {     {
641      free(tags);      esysUtils::free(tags);
642          throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");          throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");
643     }     }
644     if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )     if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
645     {     {
646      free(tags);      esysUtils::free(tags);
647          throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");          throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");
648     }     }
649     if (! (var->put(d_ptr,dims)) )     if (! (var->put(d_ptr,dims)) )
650     {     {
651      free(tags);      esysUtils::free(tags);
652          throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");          throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
653     }     }
654     #else     #else

Legend:
Removed from v.1141  
changed lines
  Added in v.1628

  ViewVC Help
Powered by ViewVC 1.1.26