/[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 983 by gross, Tue Feb 20 02:49:08 2007 UTC revision 1455 by phornby, Thu Feb 28 17:19:44 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    
18  #include "DataConstant.h"  #include "DataConstant.h"
19  #include "DataException.h"  #include "DataException.h"
20    #ifdef USE_NETCDF
21  #include <netcdfcpp.h>  #include <netcdfcpp.h>
22    #endif
23    
24  using namespace std;  using namespace std;
25    
# Line 297  DataTagged::addTaggedValues(const TagLis Line 300  DataTagged::addTaggedValues(const TagLis
300         << " doesn't match number of values: " << values.size();         << " doesn't match number of values: " << values.size();
301        throw DataException(temp.str());        throw DataException(temp.str());
302      } else {      } else {
303        for (int i=0;i<tagKeys.size();i++) {        unsigned int i;
304          for (i=0;i<tagKeys.size();i++) {
305          addTaggedValue(tagKeys[i],values[i]);          addTaggedValue(tagKeys[i],values[i]);
306        }        }
307      }      }
# Line 555  DataTagged::eigenvalues_and_eigenvectors Line 559  DataTagged::eigenvalues_and_eigenvectors
559  }  }
560    
561  void  void
562    DataTagged::setToZero(){
563        DataArrayView::ValueType::size_type n=m_data.size();
564        for (int i=0; i<n ;++i) m_data[i]=0.;
565    }
566    
567    void
568  DataTagged::dump(const std::string fileName) const  DataTagged::dump(const std::string fileName) const
569  {  {
570       #ifdef PASO_MPI
571       throw DataException("Error - DataTagged:: dump is not implemented for MPI yet.");
572       #endif
573       #ifdef USE_NETCDF
574     const int ldims=DataArrayView::maxRank+1;     const int ldims=DataArrayView::maxRank+1;
575     const NcDim* ncdims[ldims];     const NcDim* ncdims[ldims];
576     NcVar *var, *tags_var;     NcVar *var, *tags_var;
# Line 564  DataTagged::dump(const std::string fileN Line 578  DataTagged::dump(const std::string fileN
578     int type=  getFunctionSpace().getTypeCode();     int type=  getFunctionSpace().getTypeCode();
579     int ndims =0;     int ndims =0;
580     long dims[ldims];     long dims[ldims];
581       const double* d_ptr=&(m_data[0]);
582     DataArrayView::ShapeType shape = getPointDataView().getShape();     DataArrayView::ShapeType shape = getPointDataView().getShape();
583    
584     // netCDF error handler     // netCDF error handler
# Line 573  DataTagged::dump(const std::string fileN Line 588  DataTagged::dump(const std::string fileN
588     // check if writing was successful     // check if writing was successful
589     if (!dataFile.is_valid())     if (!dataFile.is_valid())
590          throw DataException("Error - DataTagged:: opening of netCDF file for output failed.");          throw DataException("Error - DataTagged:: opening of netCDF file for output failed.");
591     if (!dataFile.add_att("type","tagged") )     if (!dataFile.add_att("type_id",1) )
592          throw DataException("Error - DataTagged:: appending data type to netCDF file failed.");          throw DataException("Error - DataTagged:: appending data type to netCDF file failed.");
593     if (!dataFile.add_att("rank",rank) )     if (!dataFile.add_att("rank",rank) )
594          throw DataException("Error - DataTagged:: appending rank attribute to netCDF file failed.");          throw DataException("Error - DataTagged:: appending rank attribute to netCDF file failed.");
# Line 605  DataTagged::dump(const std::string fileN Line 620  DataTagged::dump(const std::string fileN
620     DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();     DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
621     int ntags=1;     int ntags=1;
622     for (i=thisLookup.begin();i!=thisLookupEnd;i++) ntags++;     for (i=thisLookup.begin();i!=thisLookupEnd;i++) ntags++;
623     int tags[ntags], c=1;     int* tags =(int*) malloc(ntags*sizeof(int));
624       int c=1;
625     tags[0]=-1;     tags[0]=-1;
626     for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;     for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;
627     dims[rank]=ntags;     dims[rank]=ntags;
628     if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )     if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )
629              throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");     {
630           free(tags);
631               throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");
632       }
633     if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )     if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )
634       {
635        free(tags);
636          throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");          throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");
637       }
638     if (! (tags_var->put(tags,dims[rank])) )     if (! (tags_var->put(tags,dims[rank])) )
639       {
640        free(tags);
641          throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");          throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");
642       }
643     if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )     if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
644       {
645        free(tags);
646          throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");          throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");
647     if (! (var->put(&m_data[0],dims)) )     }
648       if (! (var->put(d_ptr,dims)) )
649       {
650        free(tags);
651          throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");          throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
652       }
653       #else
654       throw DataException("Error - DataTagged:: dump is not configured with netCDF. Please contact your installation manager.");
655       #endif
656  }  }
   
   
657  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26