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

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

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

trunk/esys2/escript/src/Data/Data.cpp revision 121 by jgs, Fri May 6 04:26:16 2005 UTC trunk/escript/src/Data.cpp revision 711 by gross, Wed Apr 26 22:39:51 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
 /*=============================================================================  
2    
3   ******************************************************************************  /*
4   *                                                                            *   ************************************************************
5   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *          Copyright 2006 by ACcESS MNRF                   *
6   *                                                                            *   *                                                          *
7   * This software is the property of ACcESS.  No part of this code             *   *              http://www.access.edu.au                    *
8   * may be copied in any form or by any means without the expressed written    *   *       Primary Business: Queensland, Australia            *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *  Licensed under the Open Software License version 3.0    *
10   * by any unauthorised person is illegal unless that                          *   *     http://www.opensource.org/licenses/osl-3.0.php       *
11   * person has a software license agreement with ACcESS.                       *   *                                                          *
12   *                                                                            *   ************************************************************
13   ******************************************************************************  */
14    
15    #include "Data.h"
16    
17    #include "DataExpanded.h"
18    #include "DataConstant.h"
19    #include "DataTagged.h"
20    #include "DataEmpty.h"
21    #include "DataArray.h"
22    #include "DataArrayView.h"
23    #include "DataProf.h"
24    #include "FunctionSpaceFactory.h"
25    #include "AbstractContinuousDomain.h"
26    #include "UnaryFuncs.h"
27    
 ******************************************************************************/  
   
 #include "escript/Data/Data.h"  
   
 #include <iostream>  
28  #include <fstream>  #include <fstream>
29  #include <algorithm>  #include <algorithm>
30  #include <vector>  #include <vector>
 #include <exception>  
31  #include <functional>  #include <functional>
32  #include <math.h>  #include <math.h>
33    
34  #include <boost/python/str.hpp>  #include <boost/python/dict.hpp>
35  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
36  #include <boost/python/long.hpp>  #include <boost/python/long.hpp>
37    
 #include "escript/Data/DataException.h"  
 #include "escript/Data/DataExpanded.h"  
 #include "escript/Data/DataConstant.h"  
 #include "escript/Data/DataTagged.h"  
 #include "escript/Data/DataEmpty.h"  
 #include "escript/Data/DataArray.h"  
 #include "escript/Data/DataAlgorithm.h"  
 #include "escript/Data/FunctionSpaceFactory.h"  
 #include "escript/Data/AbstractContinuousDomain.h"  
 #include "escript/Data/UnaryFuncs.h"  
   
38  using namespace std;  using namespace std;
39  using namespace boost::python;  using namespace boost::python;
40  using namespace boost;  using namespace boost;
41  using namespace escript;  using namespace escript;
42    
43    #if defined DOPROF
44    //
45    // global table of profiling data for all Data objects
46    DataProf dataProfTable;
47    #endif
48    
49  Data::Data()  Data::Data()
50  {  {
51    //    //
# Line 52  Data::Data() Line 53  Data::Data()
53    DataAbstract* temp=new DataEmpty();    DataAbstract* temp=new DataEmpty();
54    shared_ptr<DataAbstract> temp_data(temp);    shared_ptr<DataAbstract> temp_data(temp);
55    m_data=temp_data;    m_data=temp_data;
56    #if defined DOPROF
57      // create entry in global profiling table for this object
58      profData = dataProfTable.newData();
59    #endif
60  }  }
61    
62  Data::Data(double value,  Data::Data(double value,
# Line 65  Data::Data(double value, Line 70  Data::Data(double value,
70    }    }
71    DataArray temp(dataPointShape,value);    DataArray temp(dataPointShape,value);
72    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
73    #if defined DOPROF
74      // create entry in global profiling table for this object
75      profData = dataProfTable.newData();
76    #endif
77  }  }
78    
79  Data::Data(double value,  Data::Data(double value,
# Line 75  Data::Data(double value, Line 84  Data::Data(double value,
84    DataArray temp(dataPointShape,value);    DataArray temp(dataPointShape,value);
85    pair<int,int> dataShape=what.getDataShape();    pair<int,int> dataShape=what.getDataShape();
86    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
87    #if defined DOPROF
88      // create entry in global profiling table for this object
89      profData = dataProfTable.newData();
90    #endif
91  }  }
92    
93  Data::Data(const Data& inData)  Data::Data(const Data& inData)
94  {  {
95    m_data=inData.m_data;    m_data=inData.m_data;
96    #if defined DOPROF
97      // create entry in global profiling table for this object
98      profData = dataProfTable.newData();
99    #endif
100  }  }
101    
102  Data::Data(const Data& inData,  Data::Data(const Data& inData,
# Line 90  Data::Data(const Data& inData, Line 107  Data::Data(const Data& inData,
107    DataAbstract* tmp = inData.m_data->getSlice(region);    DataAbstract* tmp = inData.m_data->getSlice(region);
108    shared_ptr<DataAbstract> temp_data(tmp);    shared_ptr<DataAbstract> temp_data(tmp);
109    m_data=temp_data;    m_data=temp_data;
110    #if defined DOPROF
111      // create entry in global profiling table for this object
112      profData = dataProfTable.newData();
113    #endif
114  }  }
115    
116  Data::Data(const Data& inData,  Data::Data(const Data& inData,
117             const FunctionSpace& functionspace)             const FunctionSpace& functionspace)
118  {  {
119    #if defined DOPROF
120      // create entry in global profiling table for this object
121      profData = dataProfTable.newData();
122    #endif
123    if (inData.getFunctionSpace()==functionspace) {    if (inData.getFunctionSpace()==functionspace) {
124      m_data=inData.m_data;      m_data=inData.m_data;
125    } else {    } else {
126        #if defined DOPROF
127        profData->interpolate++;
128        #endif
129      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);
130      // Note for Lutz, Must use a reference or pointer to a derived object      // Note: Must use a reference or pointer to a derived object
131      // in order to get polymorphic behaviour. Shouldn't really      // in order to get polymorphic behaviour. Shouldn't really
132      // be able to create an instance of AbstractDomain but that was done      // be able to create an instance of AbstractDomain but that was done
133      // as a boost python work around which may no longer be required.      // as a boost:python work around which may no longer be required.
134      const AbstractDomain& inDataDomain=inData.getDomain();      const AbstractDomain& inDataDomain=inData.getDomain();
135      if  (inDataDomain==functionspace.getDomain()) {      if  (inDataDomain==functionspace.getDomain()) {
136        inDataDomain.interpolateOnDomain(tmp,inData);        inDataDomain.interpolateOnDomain(tmp,inData);
# Line 125  Data::Data(const DataTagged::TagListType Line 153  Data::Data(const DataTagged::TagListType
153    if (expanded) {    if (expanded) {
154      expand();      expand();
155    }    }
156    #if defined DOPROF
157      // create entry in global profiling table for this object
158      profData = dataProfTable.newData();
159    #endif
160  }  }
161    
162  Data::Data(const numeric::array& value,  Data::Data(const numeric::array& value,
# Line 132  Data::Data(const numeric::array& value, Line 164  Data::Data(const numeric::array& value,
164             bool expanded)             bool expanded)
165  {  {
166    initialise(value,what,expanded);    initialise(value,what,expanded);
167    #if defined DOPROF
168      // create entry in global profiling table for this object
169      profData = dataProfTable.newData();
170    #endif
171  }  }
172    
173  Data::Data(const DataArrayView& value,  Data::Data(const DataArrayView& value,
# Line 139  Data::Data(const DataArrayView& value, Line 175  Data::Data(const DataArrayView& value,
175             bool expanded)             bool expanded)
176  {  {
177    initialise(value,what,expanded);    initialise(value,what,expanded);
178    #if defined DOPROF
179      // create entry in global profiling table for this object
180      profData = dataProfTable.newData();
181    #endif
182  }  }
183    
184  Data::Data(const object& value,  Data::Data(const object& value,
# Line 147  Data::Data(const object& value, Line 187  Data::Data(const object& value,
187  {  {
188    numeric::array asNumArray(value);    numeric::array asNumArray(value);
189    initialise(asNumArray,what,expanded);    initialise(asNumArray,what,expanded);
190    #if defined DOPROF
191      // create entry in global profiling table for this object
192      profData = dataProfTable.newData();
193    #endif
194  }  }
195    
196  Data::Data(const object& value,  Data::Data(const object& value,
# Line 167  Data::Data(const object& value, Line 211  Data::Data(const object& value,
211      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
212      initialise(temp.getView(),other.getFunctionSpace(),false);      initialise(temp.getView(),other.getFunctionSpace(),false);
213    }    }
214    #if defined DOPROF
215      // create entry in global profiling table for this object
216      profData = dataProfTable.newData();
217    #endif
218    }
219    
220    Data::~Data()
221    {
222    
223  }  }
224    
225  escriptDataC  escriptDataC
# Line 353  Data::reshapeDataPoint(const DataArrayVi Line 406  Data::reshapeDataPoint(const DataArrayVi
406  Data  Data
407  Data::wherePositive() const  Data::wherePositive() const
408  {  {
409    #if defined DOPROF
410      profData->where++;
411    #endif
412    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));
413  }  }
414    
415  Data  Data
416  Data::whereNegative() const  Data::whereNegative() const
417  {  {
418    #if defined DOPROF
419      profData->where++;
420    #endif
421    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));
422  }  }
423    
424  Data  Data
425  Data::whereNonNegative() const  Data::whereNonNegative() const
426  {  {
427    #if defined DOPROF
428      profData->where++;
429    #endif
430    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));
431  }  }
432    
433  Data  Data
434  Data::whereNonPositive() const  Data::whereNonPositive() const
435  {  {
436    #if defined DOPROF
437      profData->where++;
438    #endif
439    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));
440  }  }
441    
442  Data  Data
443  Data::whereZero() const  Data::whereZero(double tol) const
444  {  {
445    return escript::unaryOp(*this,bind2nd(equal_to<double>(),0.0));  #if defined DOPROF
446      profData->where++;
447    #endif
448      Data dataAbs=abs();
449      return escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));
450  }  }
451    
452  Data  Data
453  Data::whereNonZero() const  Data::whereNonZero(double tol) const
454  {  {
455    return escript::unaryOp(*this,bind2nd(not_equal_to<double>(),0.0));  #if defined DOPROF
456      profData->where++;
457    #endif
458      Data dataAbs=abs();
459      return escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));
460  }  }
461    
462  Data  Data
463  Data::interpolate(const FunctionSpace& functionspace) const  Data::interpolate(const FunctionSpace& functionspace) const
464  {  {
465    #if defined DOPROF
466      profData->interpolate++;
467    #endif
468    return Data(*this,functionspace);    return Data(*this,functionspace);
469  }  }
470    
# Line 410  Data::probeInterpolation(const FunctionS Line 486  Data::probeInterpolation(const FunctionS
486  Data  Data
487  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
488  {  {
489    #if defined DOPROF
490      profData->grad++;
491    #endif
492    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
493      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
494    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();
# Line 443  Data::getDataPointShape() const Line 522  Data::getDataPointShape() const
522    return getPointDataView().getShape();    return getPointDataView().getShape();
523  }  }
524    
525    void
526    Data::fillFromNumArray(const boost::python::numeric::array num_array)
527    {
528      //
529      // check rank
530      if (num_array.getrank()<getDataPointRank())
531          throw DataException("Rank of numarray does not match Data object rank");
532    
533      //
534      // check shape of num_array
535      for (int i=0; i<getDataPointRank(); i++) {
536        if (extract<int>(num_array.getshape()[i+1])!=getDataPointShape()[i])
537           throw DataException("Shape of numarray does not match Data object rank");
538      }
539    
540      //
541      // make sure data is expanded:
542      if (!isExpanded()) {
543        expand();
544      }
545    
546      //
547      // and copy over
548      m_data->copyAll(num_array);
549    }
550    
551  const  const
552  boost::python::numeric::array  boost::python::numeric::array
553  Data::convertToNumArray()  Data::convertToNumArray()
# Line 748  Data::integrate() const Line 853  Data::integrate() const
853    int rank = getDataPointRank();    int rank = getDataPointRank();
854    DataArrayView::ShapeType shape = getDataPointShape();    DataArrayView::ShapeType shape = getDataPointShape();
855    
856    #if defined DOPROF
857      profData->integrate++;
858    #endif
859    
860    //    //
861    // calculate the integral values    // calculate the integral values
862    vector<double> integrals(getDataPointSize());    vector<double> integrals(getDataPointSize());
# Line 770  Data::integrate() const Line 879  Data::integrate() const
879      }      }
880    }    }
881    if (rank==2) {    if (rank==2) {
882      bp_array.resize(shape[0],shape[1]);         bp_array.resize(shape[0],shape[1]);
883      for (int i=0; i<shape[0]; i++) {         for (int i=0; i<shape[0]; i++) {
884        for (int j=0; j<shape[1]; j++) {           for (int j=0; j<shape[1]; j++) {
885          index = i + shape[0] * j;             index = i + shape[0] * j;
886          bp_array[i,j] = integrals[index];             bp_array[make_tuple(i,j)] = integrals[index];
887        }           }
888      }         }
889    }    }
890    if (rank==3) {    if (rank==3) {
891      bp_array.resize(shape[0],shape[1],shape[2]);      bp_array.resize(shape[0],shape[1],shape[2]);
# Line 784  Data::integrate() const Line 893  Data::integrate() const
893        for (int j=0; j<shape[1]; j++) {        for (int j=0; j<shape[1]; j++) {
894          for (int k=0; k<shape[2]; k++) {          for (int k=0; k<shape[2]; k++) {
895            index = i + shape[0] * ( j + shape[1] * k );            index = i + shape[0] * ( j + shape[1] * k );
896            bp_array[i,j,k] = integrals[index];            bp_array[make_tuple(i,j,k)] = integrals[index];
897          }          }
898        }        }
899      }      }
# Line 796  Data::integrate() const Line 905  Data::integrate() const
905          for (int k=0; k<shape[2]; k++) {          for (int k=0; k<shape[2]; k++) {
906            for (int l=0; l<shape[3]; l++) {            for (int l=0; l<shape[3]; l++) {
907              index = i + shape[0] * ( j + shape[1] * ( k + shape[2] * l ) );              index = i + shape[0] * ( j + shape[1] * ( k + shape[2] * l ) );
908              bp_array[i,j,k,l] = integrals[index];              bp_array[make_tuple(i,j,k,l)] = integrals[index];
909            }            }
910          }          }
911        }        }
# Line 811  Data::integrate() const Line 920  Data::integrate() const
920  Data  Data
921  Data::sin() const  Data::sin() const
922  {  {
923    #if defined DOPROF
924      profData->unary++;
925    #endif
926    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);
927  }  }
928    
929  Data  Data
930  Data::cos() const  Data::cos() const
931  {  {
932    #if defined DOPROF
933      profData->unary++;
934    #endif
935    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);
936  }  }
937    
938  Data  Data
939  Data::tan() const  Data::tan() const
940  {  {
941    #if defined DOPROF
942      profData->unary++;
943    #endif
944    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);
945  }  }
946    
947  Data  Data
948  Data::log() const  Data::asin() const
949    {
950    #if defined DOPROF
951      profData->unary++;
952    #endif
953      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);
954    }
955    
956    Data
957    Data::acos() const
958    {
959    #if defined DOPROF
960      profData->unary++;
961    #endif
962      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);
963    }
964    
965    Data
966    Data::atan() const
967    {
968    #if defined DOPROF
969      profData->unary++;
970    #endif
971      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);
972    }
973    
974    Data
975    Data::sinh() const
976    {
977    #if defined DOPROF
978      profData->unary++;
979    #endif
980      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);
981    }
982    
983    Data
984    Data::cosh() const
985    {
986    #if defined DOPROF
987      profData->unary++;
988    #endif
989      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);
990    }
991    
992    Data
993    Data::tanh() const
994    {
995    #if defined DOPROF
996      profData->unary++;
997    #endif
998      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);
999    }
1000    
1001    Data
1002    Data::asinh() const
1003    {
1004    #if defined DOPROF
1005      profData->unary++;
1006    #endif
1007      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);
1008    }
1009    
1010    Data
1011    Data::acosh() const
1012    {
1013    #if defined DOPROF
1014      profData->unary++;
1015    #endif
1016      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);
1017    }
1018    
1019    Data
1020    Data::atanh() const
1021    {
1022    #if defined DOPROF
1023      profData->unary++;
1024    #endif
1025      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);
1026    }
1027    
1028    Data
1029    Data::log10() const
1030  {  {
1031    #if defined DOPROF
1032      profData->unary++;
1033    #endif
1034    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);
1035  }  }
1036    
1037  Data  Data
1038  Data::ln() const  Data::log() const
1039  {  {
1040    #if defined DOPROF
1041      profData->unary++;
1042    #endif
1043    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);
1044  }  }
1045    
1046  Data  Data
1047  Data::sign() const  Data::sign() const
1048  {  {
1049    #if defined DOPROF
1050      profData->unary++;
1051    #endif
1052    return escript::unaryOp(*this,escript::fsign);    return escript::unaryOp(*this,escript::fsign);
1053  }  }
1054    
1055  Data  Data
1056  Data::abs() const  Data::abs() const
1057  {  {
1058    #if defined DOPROF
1059      profData->unary++;
1060    #endif
1061    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);
1062  }  }
1063    
1064  Data  Data
1065  Data::neg() const  Data::neg() const
1066  {  {
1067    #if defined DOPROF
1068      profData->unary++;
1069    #endif
1070    return escript::unaryOp(*this,negate<double>());    return escript::unaryOp(*this,negate<double>());
1071  }  }
1072    
1073  Data  Data
1074  Data::pos() const  Data::pos() const
1075  {  {
1076    return (*this);  #if defined DOPROF
1077      profData->unary++;
1078    #endif
1079      Data result;
1080      // perform a deep copy
1081      result.copy(*this);
1082      return result;
1083  }  }
1084    
1085  Data  Data
1086  Data::exp() const  Data::exp() const
1087  {  {
1088    #if defined DOPROF
1089      profData->unary++;
1090    #endif
1091    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);
1092  }  }
1093    
1094  Data  Data
1095  Data::sqrt() const  Data::sqrt() const
1096  {  {
1097    #if defined DOPROF
1098      profData->unary++;
1099    #endif
1100    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);
1101  }  }
1102    
1103  double  double
1104  Data::Lsup() const  Data::Lsup() const
1105  {  {
1106    #if defined DOPROF
1107      profData->reduction1++;
1108    #endif
1109    //    //
1110    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1111    return algorithm(DataAlgorithmAdapter<AbsMax>(0));    AbsMax abs_max_func;
1112      return algorithm(abs_max_func,0);
1113  }  }
1114    
1115  double  double
1116  Data::Linf() const  Data::Linf() const
1117  {  {
1118    #if defined DOPROF
1119      profData->reduction1++;
1120    #endif
1121    //    //
1122    // set the initial absolute minimum value to max double    // set the initial absolute minimum value to max double
1123    return algorithm(DataAlgorithmAdapter<AbsMin>(numeric_limits<double>::max()));    AbsMin abs_min_func;
1124      return algorithm(abs_min_func,numeric_limits<double>::max());
1125  }  }
1126    
1127  double  double
1128  Data::sup() const  Data::sup() const
1129  {  {
1130    #if defined DOPROF
1131      profData->reduction1++;
1132    #endif
1133    //    //
1134    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1135    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    FMax fmax_func;
1136      return algorithm(fmax_func,numeric_limits<double>::max()*-1);
1137  }  }
1138    
1139  double  double
1140  Data::inf() const  Data::inf() const
1141  {  {
1142    #if defined DOPROF
1143      profData->reduction1++;
1144    #endif
1145    //    //
1146    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1147    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    FMin fmin_func;
1148      return algorithm(fmin_func,numeric_limits<double>::max());
1149  }  }
1150    
1151  Data  Data
1152  Data::maxval() const  Data::maxval() const
1153  {  {
1154    #if defined DOPROF
1155      profData->reduction2++;
1156    #endif
1157    //    //
1158    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1159    return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    FMax fmax_func;
1160      return dp_algorithm(fmax_func,numeric_limits<double>::max()*-1);
1161  }  }
1162    
1163  Data  Data
1164  Data::minval() const  Data::minval() const
1165  {  {
1166    #if defined DOPROF
1167      profData->reduction2++;
1168    #endif
1169    //    //
1170    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1171    return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    FMin fmin_func;
1172      return dp_algorithm(fmin_func,numeric_limits<double>::max());
1173  }  }
1174    
1175  const boost::python::tuple  Data
1176  Data::mindp() const  Data::trace() const
1177  {  {
1178    Data temp=minval();  #if defined DOPROF
1179      profData->reduction2++;
1180    int numSamples=temp.getNumSamples();  #endif
1181    int numDPPSample=temp.getNumDataPointsPerSample();    Trace trace_func;
1182      return dp_algorithm(trace_func,0);
1183    int i,j,lowi=0,lowj=0;  }
   double min=numeric_limits<double>::max();  
1184    
1185    for (i=0; i<numSamples; i++) {  Data
1186      for (j=0; j<numDPPSample; j++) {  Data::transpose(int axis) const
1187        double next=temp.getDataPoint(i,j)();  {
1188        if (next<min) {  #if defined DOPROF
1189          min=next;    profData->reduction2++;
1190          lowi=i;  #endif
         lowj=j;  
       }  
     }  
   }  
1191    
1192    return make_tuple(lowi,lowj);    // not implemented
1193      throw DataException("Error - Data::transpose not implemented yet.");
1194      return Data();
1195  }  }
1196    
1197  Data  Data
1198  Data::length() const  Data::eigenvalues() const
1199  {  {
1200    return dp_algorithm(DataAlgorithmAdapter<Length>(0));       #if defined DOPROF
1201            profData->unary++;
1202         #endif
1203         // check input
1204         DataArrayView::ShapeType s=getDataPointShape();
1205         if (getDataPointRank()!=2)
1206            throw DataException("Error - Data::eigenvalues can only be calculated for rank 2 object.");
1207         if(s[0] != s[1])
1208            throw DataException("Error - Data::eigenvalues can only be calculated for object with equal first and second dimension.");
1209         // create return
1210         DataArrayView::ShapeType ev_shape(1,s[0]);
1211         Data ev(0.,ev_shape,getFunctionSpace());
1212         ev.typeMatchRight(*this);
1213         m_data->eigenvalues(ev.m_data.get());
1214         return ev;
1215  }  }
1216    
1217  Data  const boost::python::tuple
1218  Data::trace() const  Data::eigenvalues_and_eigenvectors(const double tol) const
1219  {  {
1220    return dp_algorithm(DataAlgorithmAdapter<Trace>(0));       #if defined DOPROF
1221            profData->unary++;
1222         #endif
1223         DataArrayView::ShapeType s=getDataPointShape();
1224         if (getDataPointRank()!=2)
1225            throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");
1226         if(s[0] != s[1])
1227            throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for object with equal first and second dimension.");
1228         // create return
1229         DataArrayView::ShapeType ev_shape(1,s[0]);
1230         Data ev(0.,ev_shape,getFunctionSpace());
1231         ev.typeMatchRight(*this);
1232         DataArrayView::ShapeType V_shape(2,s[0]);
1233         Data V(0.,V_shape,getFunctionSpace());
1234         V.typeMatchRight(*this);
1235         m_data->eigenvalues_and_eigenvectors(ev.m_data.get(),V.m_data.get(),tol);
1236         return make_tuple(boost::python::object(ev),boost::python::object(V));
1237  }  }
1238    
1239  Data  const boost::python::tuple
1240  Data::transpose(int axis) const  Data::mindp() const
1241  {  {
1242    // not implemented    // NB: calc_mindp had to be split off from mindp as boost::make_tuple causes an
1243    throw DataException("Error - Data::transpose not implemented yet.");    // abort (for unknown reasons) if there are openmp directives with it in the
1244    return Data();    // surrounding function
1245    
1246      int SampleNo;
1247      int DataPointNo;
1248    
1249      calc_mindp(SampleNo,DataPointNo);
1250    
1251      return make_tuple(SampleNo,DataPointNo);
1252    }
1253    
1254    void
1255    Data::calc_mindp(int& SampleNo,
1256                     int& DataPointNo) const
1257    {
1258      int i,j;
1259      int lowi=0,lowj=0;
1260      double min=numeric_limits<double>::max();
1261    
1262      Data temp=minval();
1263    
1264      int numSamples=temp.getNumSamples();
1265      int numDPPSample=temp.getNumDataPointsPerSample();
1266    
1267      double next,local_min;
1268      int local_lowi,local_lowj;
1269    
1270      #pragma omp parallel private(next,local_min,local_lowi,local_lowj)
1271      {
1272        local_min=min;
1273        #pragma omp for private(i,j) schedule(static)
1274        for (i=0; i<numSamples; i++) {
1275          for (j=0; j<numDPPSample; j++) {
1276            next=temp.getDataPoint(i,j)();
1277            if (next<local_min) {
1278              local_min=next;
1279              local_lowi=i;
1280              local_lowj=j;
1281            }
1282          }
1283        }
1284        #pragma omp critical
1285        if (local_min<min) {
1286          min=local_min;
1287          lowi=local_lowi;
1288          lowj=local_lowj;
1289        }
1290      }
1291    
1292      SampleNo = lowi;
1293      DataPointNo = lowj;
1294  }  }
1295    
1296  void  void
1297  Data::saveDX(std::string fileName) const  Data::saveDX(std::string fileName) const
1298  {  {
1299    getDomain().saveDX(fileName,*this);    boost::python::dict args;
1300      args["data"]=boost::python::object(this);
1301      getDomain().saveDX(fileName,args);
1302    return;    return;
1303  }  }
1304    
1305  void  void
1306  Data::saveVTK(std::string fileName) const  Data::saveVTK(std::string fileName) const
1307  {  {
1308    getDomain().saveVTK(fileName,*this);    boost::python::dict args;
1309      args["data"]=boost::python::object(this);
1310      getDomain().saveVTK(fileName,args);
1311    return;    return;
1312  }  }
1313    
1314  Data&  Data&
1315  Data::operator+=(const Data& right)  Data::operator+=(const Data& right)
1316  {  {
1317    #if defined DOPROF
1318      profData->binary++;
1319    #endif
1320    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
1321    return (*this);    return (*this);
1322  }  }
# Line 991  Data::operator+=(const Data& right) Line 1324  Data::operator+=(const Data& right)
1324  Data&  Data&
1325  Data::operator+=(const boost::python::object& right)  Data::operator+=(const boost::python::object& right)
1326  {  {
1327    #if defined DOPROF
1328      profData->binary++;
1329    #endif
1330    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
1331    return (*this);    return (*this);
1332  }  }
# Line 998  Data::operator+=(const boost::python::ob Line 1334  Data::operator+=(const boost::python::ob
1334  Data&  Data&
1335  Data::operator-=(const Data& right)  Data::operator-=(const Data& right)
1336  {  {
1337    #if defined DOPROF
1338      profData->binary++;
1339    #endif
1340    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
1341    return (*this);    return (*this);
1342  }  }
# Line 1005  Data::operator-=(const Data& right) Line 1344  Data::operator-=(const Data& right)
1344  Data&  Data&
1345  Data::operator-=(const boost::python::object& right)  Data::operator-=(const boost::python::object& right)
1346  {  {
1347    #if defined DOPROF
1348      profData->binary++;
1349    #endif
1350    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
1351    return (*this);    return (*this);
1352  }  }
# Line 1012  Data::operator-=(const boost::python::ob Line 1354  Data::operator-=(const boost::python::ob
1354  Data&  Data&
1355  Data::operator*=(const Data& right)  Data::operator*=(const Data& right)
1356  {  {
1357    #if defined DOPROF
1358      profData->binary++;
1359    #endif
1360    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
1361    return (*this);    return (*this);
1362  }  }
# Line 1019  Data::operator*=(const Data& right) Line 1364  Data::operator*=(const Data& right)
1364  Data&  Data&
1365  Data::operator*=(const boost::python::object& right)  Data::operator*=(const boost::python::object& right)
1366  {  {
1367    #if defined DOPROF
1368      profData->binary++;
1369    #endif
1370    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
1371    return (*this);    return (*this);
1372  }  }
# Line 1026  Data::operator*=(const boost::python::ob Line 1374  Data::operator*=(const boost::python::ob
1374  Data&  Data&
1375  Data::operator/=(const Data& right)  Data::operator/=(const Data& right)
1376  {  {
1377    #if defined DOPROF
1378      profData->binary++;
1379    #endif
1380    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
1381    return (*this);    return (*this);
1382  }  }
# Line 1033  Data::operator/=(const Data& right) Line 1384  Data::operator/=(const Data& right)
1384  Data&  Data&
1385  Data::operator/=(const boost::python::object& right)  Data::operator/=(const boost::python::object& right)
1386  {  {
1387    #if defined DOPROF
1388      profData->binary++;
1389    #endif
1390    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
1391    return (*this);    return (*this);
1392  }  }
1393    
1394  Data  Data
1395    Data::rpowO(const boost::python::object& left) const
1396    {
1397    #if defined DOPROF
1398      profData->binary++;
1399    #endif
1400      Data left_d(left,*this);
1401      return left_d.powD(*this);
1402    }
1403    
1404    Data
1405  Data::powO(const boost::python::object& right) const  Data::powO(const boost::python::object& right) const
1406  {  {
1407    #if defined DOPROF
1408      profData->binary++;
1409    #endif
1410    Data result;    Data result;
1411    result.copy(*this);    result.copy(*this);
1412    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);
# Line 1049  Data::powO(const boost::python::object& Line 1416  Data::powO(const boost::python::object&
1416  Data  Data
1417  Data::powD(const Data& right) const  Data::powD(const Data& right) const
1418  {  {
1419    #if defined DOPROF
1420      profData->binary++;
1421    #endif
1422    Data result;    Data result;
1423    result.copy(*this);    result.copy(*this);
1424    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);
# Line 1056  Data::powD(const Data& right) const Line 1426  Data::powD(const Data& right) const
1426  }  }
1427    
1428  //  //
1429  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1430  Data  Data
1431  escript::operator+(const Data& left, const Data& right)  escript::operator+(const Data& left, const Data& right)
1432  {  {
# Line 1069  escript::operator+(const Data& left, con Line 1439  escript::operator+(const Data& left, con
1439  }  }
1440    
1441  //  //
1442  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1443  Data  Data
1444  escript::operator-(const Data& left, const Data& right)  escript::operator-(const Data& left, const Data& right)
1445  {  {
# Line 1082  escript::operator-(const Data& left, con Line 1452  escript::operator-(const Data& left, con
1452  }  }
1453    
1454  //  //
1455  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1456  Data  Data
1457  escript::operator*(const Data& left, const Data& right)  escript::operator*(const Data& left, const Data& right)
1458  {  {
# Line 1095  escript::operator*(const Data& left, con Line 1465  escript::operator*(const Data& left, con
1465  }  }
1466    
1467  //  //
1468  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1469  Data  Data
1470  escript::operator/(const Data& left, const Data& right)  escript::operator/(const Data& left, const Data& right)
1471  {  {
# Line 1108  escript::operator/(const Data& left, con Line 1478  escript::operator/(const Data& left, con
1478  }  }
1479    
1480  //  //
1481  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1482  Data  Data
1483  escript::operator+(const Data& left, const boost::python::object& right)  escript::operator+(const Data& left, const boost::python::object& right)
1484  {  {
# Line 1124  escript::operator+(const Data& left, con Line 1494  escript::operator+(const Data& left, con
1494  }  }
1495    
1496  //  //
1497  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1498  Data  Data
1499  escript::operator-(const Data& left, const boost::python::object& right)  escript::operator-(const Data& left, const boost::python::object& right)
1500  {  {
# Line 1140  escript::operator-(const Data& left, con Line 1510  escript::operator-(const Data& left, con
1510  }  }
1511    
1512  //  //
1513  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1514  Data  Data
1515  escript::operator*(const Data& left, const boost::python::object& right)  escript::operator*(const Data& left, const boost::python::object& right)
1516  {  {
# Line 1156  escript::operator*(const Data& left, con Line 1526  escript::operator*(const Data& left, con
1526  }  }
1527    
1528  //  //
1529  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1530  Data  Data
1531  escript::operator/(const Data& left, const boost::python::object& right)  escript::operator/(const Data& left, const boost::python::object& right)
1532  {  {
# Line 1172  escript::operator/(const Data& left, con Line 1542  escript::operator/(const Data& left, con
1542  }  }
1543    
1544  //  //
1545  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1546  Data  Data
1547  escript::operator+(const boost::python::object& left, const Data& right)  escript::operator+(const boost::python::object& left, const Data& right)
1548  {  {
# Line 1185  escript::operator+(const boost::python:: Line 1555  escript::operator+(const boost::python::
1555  }  }
1556    
1557  //  //
1558  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1559  Data  Data
1560  escript::operator-(const boost::python::object& left, const Data& right)  escript::operator-(const boost::python::object& left, const Data& right)
1561  {  {
# Line 1198  escript::operator-(const boost::python:: Line 1568  escript::operator-(const boost::python::
1568  }  }
1569    
1570  //  //
1571  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1572  Data  Data
1573  escript::operator*(const boost::python::object& left, const Data& right)  escript::operator*(const boost::python::object& left, const Data& right)
1574  {  {
# Line 1211  escript::operator*(const boost::python:: Line 1581  escript::operator*(const boost::python::
1581  }  }
1582    
1583  //  //
1584  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1585  Data  Data
1586  escript::operator/(const boost::python::object& left, const Data& right)  escript::operator/(const boost::python::object& left, const Data& right)
1587  {  {
# Line 1224  escript::operator/(const boost::python:: Line 1594  escript::operator/(const boost::python::
1594  }  }
1595    
1596  //  //
 // NOTE: It is essential to specify the namepsace this operator belongs to  
1597  //bool escript::operator==(const Data& left, const Data& right)  //bool escript::operator==(const Data& left, const Data& right)
1598  //{  //{
1599  //  /*  //  /*
# Line 1286  Data::getItem(const boost::python::objec Line 1655  Data::getItem(const boost::python::objec
1655  Data  Data
1656  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataArrayView::RegionType& region) const
1657  {  {
1658    #if defined DOPROF
1659      profData->slicing++;
1660    #endif
1661    return Data(*this,region);    return Data(*this,region);
1662  }  }
1663    
# Line 1302  Data::setItemD(const boost::python::obje Line 1674  Data::setItemD(const boost::python::obje
1674                 const Data& value)                 const Data& value)
1675  {  {
1676    const DataArrayView& view=getPointDataView();    const DataArrayView& view=getPointDataView();
1677    
1678    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataArrayView::RegionType slice_region=view.getSliceRegion(key);
1679    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=view.getRank()) {
1680      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
# Line 1317  void Line 1690  void
1690  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1691                 const DataArrayView::RegionType& region)                 const DataArrayView::RegionType& region)
1692  {  {
1693    #if defined DOPROF
1694      profData->slicing++;
1695    #endif
1696    Data tempValue(value);    Data tempValue(value);
1697    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1698    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 1389  Data::setTaggedValueFromCPP(int tagKey, Line 1765  Data::setTaggedValueFromCPP(int tagKey,
1765    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
1766  }  }
1767    
1768    int
1769    Data::getTagNumber(int dpno)
1770    {
1771      return m_data->getTagNumber(dpno);
1772    }
1773    
1774  void  void
1775  Data::setRefValue(int ref,  Data::setRefValue(int ref,
1776                    const boost::python::numeric::array& value)                    const boost::python::numeric::array& value)
# Line 1428  Data::getRefValue(int ref, Line 1810  Data::getRefValue(int ref,
1810    DataArrayView valueView = valueDataArray.getView();    DataArrayView valueView = valueDataArray.getView();
1811    
1812    if (rank==0) {    if (rank==0) {
1813      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");        boost::python::numeric::array temp_numArray(valueView());
1814          value = temp_numArray;
1815    }    }
1816    if (rank==1) {    if (rank==1) {
1817      for (int i=0; i < shape[0]; i++) {      for (int i=0; i < shape[0]; i++) {
# Line 1436  Data::getRefValue(int ref, Line 1819  Data::getRefValue(int ref,
1819      }      }
1820    }    }
1821    if (rank==2) {    if (rank==2) {
1822      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");      for (int i=0; i < shape[0]; i++) {
1823          for (int j=0; j < shape[1]; j++) {
1824            value[i][j] = valueView(i,j);
1825          }
1826        }
1827    }    }
1828    if (rank==3) {    if (rank==3) {
1829      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");      for (int i=0; i < shape[0]; i++) {
1830          for (int j=0; j < shape[1]; j++) {
1831            for (int k=0; k < shape[2]; k++) {
1832              value[i][j][k] = valueView(i,j,k);
1833            }
1834          }
1835        }
1836    }    }
1837    if (rank==4) {    if (rank==4) {
1838      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");      for (int i=0; i < shape[0]; i++) {
1839          for (int j=0; j < shape[1]; j++) {
1840            for (int k=0; k < shape[2]; k++) {
1841              for (int l=0; l < shape[3]; l++) {
1842                value[i][j][k][l] = valueView(i,j,k,l);
1843              }
1844            }
1845          }
1846        }
1847    }    }
1848    
1849  }  }
# Line 1472  Data::archiveData(const std::string file Line 1873  Data::archiveData(const std::string file
1873      dataType = 3;      dataType = 3;
1874      cout << "\tdataType: DataExpanded" << endl;      cout << "\tdataType: DataExpanded" << endl;
1875    }    }
1876    
1877    if (dataType == -1) {    if (dataType == -1) {
1878      throw DataException("archiveData Error: undefined dataType");      throw DataException("archiveData Error: undefined dataType");
1879    }    }
# Line 1511  Data::archiveData(const std::string file Line 1913  Data::archiveData(const std::string file
1913    cout << ">" << endl;    cout << ">" << endl;
1914    
1915    //    //
1916    // Write common data items to archive file    // Open archive file
1917    ofstream archiveFile;    ofstream archiveFile;
1918    archiveFile.open(fileName.data(), ios::out);    archiveFile.open(fileName.data(), ios::out);
1919    
# Line 1519  Data::archiveData(const std::string file Line 1921  Data::archiveData(const std::string file
1921      throw DataException("archiveData Error: problem opening archive file");      throw DataException("archiveData Error: problem opening archive file");
1922    }    }
1923    
1924      //
1925      // Write common data items to archive file
1926    archiveFile.write(reinterpret_cast<char *>(&dataType),sizeof(int));    archiveFile.write(reinterpret_cast<char *>(&dataType),sizeof(int));
1927    archiveFile.write(reinterpret_cast<char *>(&noSamples),sizeof(int));    archiveFile.write(reinterpret_cast<char *>(&noSamples),sizeof(int));
1928    archiveFile.write(reinterpret_cast<char *>(&noDPPSample),sizeof(int));    archiveFile.write(reinterpret_cast<char *>(&noDPPSample),sizeof(int));
# Line 1542  Data::archiveData(const std::string file Line 1946  Data::archiveData(const std::string file
1946      throw DataException("archiveData Error: problem writing to archive file");      throw DataException("archiveData Error: problem writing to archive file");
1947    }    }
1948    
   archiveFile.close();  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem closing archive file");  
   }  
   
1949    //    //
1950    // Collect and archive underlying data values for each Data type    // Archive underlying data values for each Data type
1951      int noValues;
1952    switch (dataType) {    switch (dataType) {
1953      case 0:      case 0:
1954        // DataEmpty        // DataEmpty
1955          noValues = 0;
1956          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1957          cout << "\tnoValues: " << noValues << endl;
1958        break;        break;
1959      case 1:      case 1:
1960        // DataConstant        // DataConstant
1961          noValues = m_data->getLength();
1962          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1963          cout << "\tnoValues: " << noValues << endl;
1964          if (m_data->archiveData(archiveFile,noValues)) {
1965            throw DataException("archiveData Error: problem writing data to archive file");
1966          }
1967        break;        break;
1968      case 2:      case 2:
1969        // DataTagged        // DataTagged
1970          noValues = m_data->getLength();
1971          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1972          cout << "\tnoValues: " << noValues << endl;
1973          if (m_data->archiveData(archiveFile,noValues)) {
1974            throw DataException("archiveData Error: problem writing data to archive file");
1975          }
1976        break;        break;
1977      case 3:      case 3:
1978        // DataExpanded        // DataExpanded
1979          noValues = m_data->getLength();
1980          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1981          cout << "\tnoValues: " << noValues << endl;
1982          if (m_data->archiveData(archiveFile,noValues)) {
1983            throw DataException("archiveData Error: problem writing data to archive file");
1984          }
1985        break;        break;
1986    }    }
1987    
1988      if (!archiveFile.good()) {
1989        throw DataException("archiveData Error: problem writing data to archive file");
1990      }
1991    
1992      //
1993      // Close archive file
1994      archiveFile.close();
1995    
1996      if (!archiveFile.good()) {
1997        throw DataException("archiveData Error: problem closing archive file");
1998      }
1999    
2000  }  }
2001    
2002  void  void
# Line 1590  Data::extractData(const std::string file Line 2022  Data::extractData(const std::string file
2022    int flatShape[4];    int flatShape[4];
2023    
2024    //    //
2025    // Open the archive file and read common data items    // Open the archive file
2026    ifstream archiveFile;    ifstream archiveFile;
2027    archiveFile.open(fileName.data(), ios::in);    archiveFile.open(fileName.data(), ios::in);
2028    
# Line 1598  Data::extractData(const std::string file Line 2030  Data::extractData(const std::string file
2030      throw DataException("extractData Error: problem opening archive file");      throw DataException("extractData Error: problem opening archive file");
2031    }    }
2032    
2033      //
2034      // Read common data items from archive file
2035    archiveFile.read(reinterpret_cast<char *>(&dataType),sizeof(int));    archiveFile.read(reinterpret_cast<char *>(&dataType),sizeof(int));
2036    archiveFile.read(reinterpret_cast<char *>(&noSamples),sizeof(int));    archiveFile.read(reinterpret_cast<char *>(&noSamples),sizeof(int));
2037    archiveFile.read(reinterpret_cast<char *>(&noDPPSample),sizeof(int));    archiveFile.read(reinterpret_cast<char *>(&noDPPSample),sizeof(int));
# Line 1626  Data::extractData(const std::string file Line 2060  Data::extractData(const std::string file
2060      throw DataException("extractData Error: problem reading from archive file");      throw DataException("extractData Error: problem reading from archive file");
2061    }    }
2062    
2063    archiveFile.close();    //
2064      // Verify the values just read from the archive file
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem closing archive file");  
   }  
   
2065    switch (dataType) {    switch (dataType) {
2066      case 0:      case 0:
2067        cout << "\tdataType: DataEmpty" << endl;        cout << "\tdataType: DataEmpty" << endl;
# Line 1686  Data::extractData(const std::string file Line 2116  Data::extractData(const std::string file
2116    
2117    //    //
2118    // Load this DataVector with the appropriate values    // Load this DataVector with the appropriate values
2119      int noValues;
2120      archiveFile.read(reinterpret_cast<char *>(&noValues),sizeof(int));
2121      cout << "\tnoValues: " << noValues << endl;
2122    switch (dataType) {    switch (dataType) {
2123      case 0:      case 0:
2124        // DataEmpty        // DataEmpty
2125          if (noValues != 0) {
2126            throw DataException("extractData Error: problem reading data from archive file");
2127          }
2128        break;        break;
2129      case 1:      case 1:
2130        // DataConstant        // DataConstant
2131          if (dataVec.extractData(archiveFile,noValues)) {
2132            throw DataException("extractData Error: problem reading data from archive file");
2133          }
2134        break;        break;
2135      case 2:      case 2:
2136        // DataTagged        // DataTagged
2137          if (dataVec.extractData(archiveFile,noValues)) {
2138            throw DataException("extractData Error: problem reading data from archive file");
2139          }
2140        break;        break;
2141      case 3:      case 3:
2142        // DataExpanded        // DataExpanded
2143          if (dataVec.extractData(archiveFile,noValues)) {
2144            throw DataException("extractData Error: problem reading data from archive file");
2145          }
2146        break;        break;
2147    }    }
2148    
2149      if (!archiveFile.good()) {
2150        throw DataException("extractData Error: problem reading from archive file");
2151      }
2152    
2153      //
2154      // Close archive file
2155      archiveFile.close();
2156    
2157      if (!archiveFile.good()) {
2158        throw DataException("extractData Error: problem closing archive file");
2159      }
2160    
2161    //    //
2162    // Construct an appropriate Data object    // Construct an appropriate Data object
2163    DataAbstract* tempData;    DataAbstract* tempData;
# Line 1724  Data::extractData(const std::string file Line 2181  Data::extractData(const std::string file
2181    }    }
2182    shared_ptr<DataAbstract> temp_data(tempData);    shared_ptr<DataAbstract> temp_data(tempData);
2183    m_data=temp_data;    m_data=temp_data;
   
2184  }  }
2185    
2186  ostream& escript::operator<<(ostream& o, const Data& data)  ostream& escript::operator<<(ostream& o, const Data& data)

Legend:
Removed from v.121  
changed lines
  Added in v.711

  ViewVC Help
Powered by ViewVC 1.1.26