Changeset 12416


Ignore:
Timestamp:
06/13/12 15:00:23 (13 years ago)
Author:
utke
Message:

keep these strictlt passive - also retain the xmalloc calls given that memory is passed on to Option instances which may also receive such memory from other sections of the code we don't currently convert but all this memory is deleted in the options dtors.

Location:
issm/trunk-jpl/src/c/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/objects/IoModel.cpp

    r12382 r12416  
    5050        /*Initialize and read constants:*/
    5151        this->constants=new Parameters();
    52         this->FetchConstants(); /*this routine goes through the input file, and fetches bools, ints, doubles and strings only, nothing memory intensive*/
     52        this->FetchConstants(); /*this routine goes through the input file, and fetches bools, ints, IssmPDoubles and strings only, nothing memory intensive*/
    5353
    5454        /*Initialize data: */
    55         this->data=(double**)xmalloc(MaximumNumberOfEnums*sizeof(double*));
     55        this->data=(IssmPDouble**)xmalloc(MaximumNumberOfEnums*sizeof(IssmPDouble*));
    5656        for(int i=0;i<MaximumNumberOfEnums;i++) this->data[i]=NULL;
    5757       
     
    152152}
    153153/*}}}*/
    154 /*FUNCTION IoModel::Constant(double* poutput,int constant_enum){{{*/
    155 void IoModel::Constant(double* poutput,int constant_enum){
     154/*FUNCTION IoModel::Constant(IssmPDouble* poutput,int constant_enum){{{*/
     155void IoModel::Constant(IssmPDouble* poutput,int constant_enum){
    156156
    157157        _assert_(constant_enum>=0);
     
    183183/*}}}*/
    184184/*FUNCTION IoModel::Data{{{*/
    185 double* IoModel::Data(int data_enum){
     185IssmPDouble* IoModel::Data(int data_enum){
    186186
    187187        _assert_(data_enum<MaximumNumberOfEnums);
     
    223223        int  booleanint=0;
    224224        int  integer=0;
    225         double scalar=0;
     225        IssmPDouble scalar=0;
    226226        char* string=NULL;
    227227        int   string_size;
     
    237237                fseek(this->fid,0,SEEK_SET);
    238238
    239                 /*Now march through file looking for the correct data identifiers (bool,int,double or string): */
     239                /*Now march through file looking for the correct data identifiers (bool,int,IssmPDouble or string): */
    240240                for(;;){
    241241                        if(fread(&record_enum,sizeof(int),1,this->fid)==0){
     
    288288                                        case 3:
    289289                                                /*Read the scalar and broadcast it to other cpus:*/
    290                                                 if(fread(&scalar,sizeof(double),1,this->fid)!=1) _error_(" could not read scalar ");
     290                                                if(fread(&scalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_(" could not read scalar ");
    291291                                                #ifdef _HAVE_MPI_
    292292                                                MPI_Bcast(&scalar,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
     
    499499}
    500500/*}}}*/
    501 /*FUNCTION IoModel::FetchData(double*   pscalar,int data_enum){{{*/
    502 void  IoModel::FetchData(double* pscalar,int data_enum){
     501/*FUNCTION IoModel::FetchData(IssmPDouble*   pscalar,int data_enum){{{*/
     502void  IoModel::FetchData(IssmPDouble* pscalar,int data_enum){
    503503
    504504
     
    508508
    509509        /*output: */
    510         double   scalar;
     510        IssmPDouble   scalar;
    511511        int      code;
    512512       
     
    514514        fid=this->SetFilePointerToData(&code,NULL,data_enum);
    515515       
    516         if(code!=3)_error_("expecting a double for enum %s",EnumToStringx(data_enum));
     516        if(code!=3)_error_("expecting a IssmPDouble for enum %s",EnumToStringx(data_enum));
    517517       
    518518        /*We have to read a scalar from disk. First read the dimensions of the scalar, then the scalar: */
    519519        if(my_rank==0){
    520                 if(fread(&scalar,sizeof(double),1,fid)!=1)_error_(" could not read scalar ");
     520                if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1)_error_(" could not read scalar ");
    521521        }
    522522        #ifdef _HAVE_MPI_
     
    589589        /*output: */
    590590        int M,N;
    591         double* matrix=NULL;
     591        IssmPDouble* matrix=NULL;
    592592        int*    integer_matrix=NULL;
    593593        int code=0;
     
    598598        fid=this->SetFilePointerToData(&code,&vector_type,data_enum);
    599599
    600         if((code!=5) && (code!=6) && (code!=7))_error_("expecting a double, integer or boolean matrix for enum %s",EnumToStringx(data_enum));
     600        if((code!=5) && (code!=6) && (code!=7))_error_("expecting a IssmPDouble, integer or boolean matrix for enum %s",EnumToStringx(data_enum));
    601601       
    602602        /*Now fetch: */
     
    621621        /*Now allocate matrix: */
    622622        if(M*N){
    623                 matrix=(double*)xmalloc(M*N*sizeof(double));
     623                matrix=(IssmPDouble*)xmalloc(M*N*sizeof(IssmPDouble));
    624624
    625625                /*Read matrix on node 0, then broadcast: */
    626626                if(my_rank==0){ 
    627                         if(fread(matrix,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix ");
     627                        if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    628628                }
    629629               
     
    655655}
    656656/*}}}*/
    657 /*FUNCTION IoModel::FetchData(double**  pdoublematrix,int* pM,int* pN,int data_enum){{{*/
    658 void  IoModel::FetchData(double** pmatrix,int* pM,int* pN,int data_enum){
     657/*FUNCTION IoModel::FetchData(IssmPDouble**  pIssmPDoublematrix,int* pM,int* pN,int data_enum){{{*/
     658void  IoModel::FetchData(IssmPDouble** pmatrix,int* pM,int* pN,int data_enum){
    659659
    660660        extern int my_rank;
     
    663663        /*output: */
    664664        int M,N;
    665         double* matrix=NULL;
     665        IssmPDouble* matrix=NULL;
    666666        int code=0;
    667667        int vector_type=0;
     
    669669        /*Set file pointer to beginning of the data: */
    670670        fid=this->SetFilePointerToData(&code,&vector_type,data_enum);
    671         if((code!=5) && (code!=6) && (code!=7))_error_("expecting a double, integer or boolean matrix for enum %s",EnumToStringx(data_enum));
     671        if((code!=5) && (code!=6) && (code!=7))_error_("expecting a IssmPDouble, integer or boolean matrix for enum %s",EnumToStringx(data_enum));
    672672       
    673673        /*Now fetch: */
     
    691691        /*Now allocate matrix: */
    692692        if(M*N){
    693                 matrix=(double*)xmalloc(M*N*sizeof(double));
     693                matrix=(IssmPDouble*)xmalloc(M*N*sizeof(IssmPDouble));
    694694
    695695                /*Read matrix on node 0, then broadcast: */
    696696                if(my_rank==0){ 
    697                         if(fread(matrix,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix ");
     697                        if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    698698                }
    699699                #ifdef _HAVE_MPI_
     
    778778}
    779779/*}}}*/
    780 /*FUNCTION IoModel::FetchData(double*** pmatrices,int** pmdims,int** pndims, int* pM,int data_enum){{{*/
    781 void  IoModel::FetchData(double*** pmatrices,int** pmdims,int** pndims, int* pnumrecords,int data_enum){
     780/*FUNCTION IoModel::FetchData(IssmPDouble*** pmatrices,int** pmdims,int** pndims, int* pM,int data_enum){{{*/
     781void  IoModel::FetchData(IssmPDouble*** pmatrices,int** pmdims,int** pndims, int* pnumrecords,int data_enum){
    782782
    783783        int i;
     
    787787
    788788        /*output: */
    789         double** matrices=NULL;
     789        IssmPDouble** matrices=NULL;
    790790        int*     mdims=NULL;
    791791        int*     ndims=NULL;
     
    794794        /*intermediary: */
    795795        int     M, N;
    796         double *matrix = NULL;
     796        IssmPDouble *matrix = NULL;
    797797        int     code;
    798798       
    799799        /*Set file pointer to beginning of the data: */
    800800        fid=this->SetFilePointerToData(&code,NULL,data_enum);
    801         if(code!=8)_error_("expecting a double mat array for enum %s",EnumToStringx(data_enum));
     801        if(code!=8)_error_("expecting a IssmPDouble mat array for enum %s",EnumToStringx(data_enum));
    802802       
    803803        /*Now fetch: */
     
    812812
    813813                /*Allocate matrices :*/
    814                 matrices=(double**)xmalloc(numrecords*sizeof(double*));
     814                matrices=(IssmPDouble**)xmalloc(numrecords*sizeof(IssmPDouble*));
    815815                mdims=(int*)xmalloc(numrecords*sizeof(int));
    816816                ndims=(int*)xmalloc(numrecords*sizeof(int));
     
    841841                        /*Now allocate matrix: */
    842842                        if(M*N){
    843                                 matrix=(double*)xmalloc(M*N*sizeof(double));
     843                                matrix=(IssmPDouble*)xmalloc(M*N*sizeof(IssmPDouble));
    844844
    845845                                /*Read matrix on node 0, then broadcast: */
    846846                                if(my_rank==0){ 
    847                                         if(fread(matrix,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix ");
     847                                        if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    848848                                }
    849849
     
    885885        fid=this->SetFilePointerToData(&code,NULL,index+1);
    886886        switch(code){
    887                 case 3: {//double
    888                           double *value = NULL;
    889                           value=(double*)xmalloc(1*sizeof(double));
     887                case 3: {//IssmPDouble
     888                          IssmPDouble *value = NULL;
     889                          value=(IssmPDouble*)xmalloc(1*sizeof(IssmPDouble));
    890890                          FetchData(value,index+1);
    891891                          _printf_(true,"value = %g\n",*value);
     
    923923        va_list ap;
    924924        int     dataenum;
    925         double* matrix=NULL;
     925        IssmPDouble* matrix=NULL;
    926926        int     M,N;
    927927        int     i;
    928928
    929929        /*Go through the entire list of enums and fetch the corresponding data. Add it to the iomodel->data dataset. Everything
    930          *we fetch is a double* : */
     930         *we fetch is a IssmPDouble* : */
    931931       
    932932        va_start(ap,num);
     
    954954/*}}}*/
    955955/*FUNCTION IoModel::FetchDataToInput{{{*/
    956 void IoModel::FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum,double default_value){
     956void IoModel::FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum,IssmPDouble default_value){
    957957
    958958        /*intermediary: */
     
    973973        bool    boolean;
    974974        int     integer;
    975         double  scalar;
     975        IssmPDouble  scalar;
    976976        char   *string        = NULL;
    977         double *doublevector  = NULL;
     977        IssmPDouble *IssmPDoublevector  = NULL;
    978978        int     M,N;
    979979
     
    993993                                if(this->my_elements[i]){
    994994                                        Element* element=(Element*)elements->GetObjectByOffset(counter);
    995                                         element->InputCreate((double)boolean,vector_enum,code);
     995                                        element->InputCreate((IssmPDouble)boolean,vector_enum,code);
    996996                                        counter++;
    997997                                }
     
    10061006                                if(this->my_elements[i]){
    10071007                                        Element* element=(Element*)elements->GetObjectByOffset(counter);
    1008                                         element->InputCreate((double)integer,vector_enum,code);
     1008                                        element->InputCreate((IssmPDouble)integer,vector_enum,code);
    10091009                                        counter++;
    10101010                                }
    10111011                        }
    10121012                        break; /*}}}*/
    1013                 case 3: //double constant.  {{{
     1013                case 3: //IssmPDouble constant.  {{{
    10141014                        this->FetchData(&scalar,vector_enum);
    10151015
    1016                         /*Add double constant input to all elements: */
     1016                        /*Add IssmPDouble constant input to all elements: */
    10171017                        counter=0;
    10181018                        for (i=0;i<numberofelements;i++){
     
    10271027
    10281028                        /*Fetch vector:*/
    1029                         this->FetchData(&doublevector,&M,&N,vector_enum); //we still have a doublevector, because it might include times in transient mode
     1029                        this->FetchData(&IssmPDoublevector,&M,&N,vector_enum); //we still have a IssmPDoublevector, because it might include times in transient mode
    10301030                        /*Check we got something, otherwise fetch default: */
    1031                         if(doublevector){
     1031                        if(IssmPDoublevector){
    10321032                                defaulting=false;  //we are not defaulting, because  we do have a vector
    10331033                        }
     
    10361036                                if(default_vector_enum!=NoneEnum){
    10371037                                        /*yes. fetch it: */
    1038                                         this->FetchData(&doublevector,&M,&N,default_vector_enum);
    1039                                         if(doublevector){
     1038                                        this->FetchData(&IssmPDoublevector,&M,&N,default_vector_enum);
     1039                                        if(IssmPDoublevector){
    10401040                                                defaulting=false;  //we are not defaulting, because  we do have a vector
    10411041                                        }
     
    10571057                                        Element* element=(Element*)elements->GetObjectByOffset(counter);
    10581058                                        if(defaulting) element->InputCreate(default_value,vector_enum,code);
    1059                                         else           element->InputCreate(doublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
     1059                                        else           element->InputCreate(IssmPDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
    10601060                                        counter++;
    10611061                                }
     
    10651065
    10661066                        /*Fetch vector:*/
    1067                         this->FetchData(&doublevector,&M,&N,vector_enum); //we still have a doublevector, because it might include times in transient mode
     1067                        this->FetchData(&IssmPDoublevector,&M,&N,vector_enum); //we still have a IssmPDoublevector, because it might include times in transient mode
    10681068                        /*Check we got something, otherwise fetch default: */
    1069                         if(doublevector){
     1069                        if(IssmPDoublevector){
    10701070                                defaulting=false;  //we are not defaulting, because  we do have a vector
    10711071                        }
     
    10741074                                if(default_vector_enum!=NoneEnum){
    10751075                                        /*yes. fetch it: */
    1076                                         this->FetchData(&doublevector,&M,&N,default_vector_enum);
    1077                                         if(doublevector){
     1076                                        this->FetchData(&IssmPDoublevector,&M,&N,default_vector_enum);
     1077                                        if(IssmPDoublevector){
    10781078                                                defaulting=false;  //we are not defaulting, because  we do have a vector
    10791079                                        }
     
    10951095                                        Element* element=(Element*)elements->GetObjectByOffset(counter);
    10961096                                        if(defaulting) element->InputCreate(default_value,vector_enum,code);
    1097                                         else           element->InputCreate(doublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
     1097                                        else           element->InputCreate(IssmPDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
    10981098                                        counter++;
    10991099                                }
    11001100                        }
    11011101                        break; /*}}}*/
    1102                 case 7: //double vector{{{
     1102                case 7: //IssmPDouble vector{{{
    11031103
    11041104                        /*Fetch vector:*/
    1105                         this->FetchData(&doublevector,&M,&N,vector_enum);
     1105                        this->FetchData(&IssmPDoublevector,&M,&N,vector_enum);
    11061106                        /*Check we got something, otherwise fetch default: */
    1107                         if(doublevector){
     1107                        if(IssmPDoublevector){
    11081108                                defaulting=false;  //we are not defaulting, because  we do have a vector
    11091109                        }
     
    11121112                                if(default_vector_enum!=NoneEnum){
    11131113                                        /*yes. fetch it: */
    1114                                         this->FetchData(&doublevector,&M,&N,default_vector_enum);
    1115                                         if(doublevector){
     1114                                        this->FetchData(&IssmPDoublevector,&M,&N,default_vector_enum);
     1115                                        if(IssmPDoublevector){
    11161116                                                defaulting=false;  //we are not defaulting, because  we do have a vector
    11171117                                        }
     
    11331133                                        Element* element=(Element*)elements->GetObjectByOffset(counter);
    11341134                                        if(defaulting) element->InputCreate(default_value,vector_enum,code);
    1135                                         else           element->InputCreate(doublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
     1135                                        else           element->InputCreate(IssmPDoublevector,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
    11361136                                        counter++;
    11371137                                }
     
    11451145        }
    11461146        /*Free ressources:*/
    1147         xfree((void**)&doublevector);
     1147        xfree((void**)&IssmPDoublevector);
    11481148        xfree((void**)&string);
    11491149}
  • issm/trunk-jpl/src/c/objects/IoModel.h

    r12382 r12416  
    1818
    1919        private:
    20                 IssmDouble    **data;        //this dataset holds temporary data, memory intensive.
    21                 Parameters  *constants;   //this dataset holds all IssmDouble, int, bool and char *parameters read in from the input file.*
     20                IssmPDouble **data;        //this dataset holds temporary data, memory intensive.
     21                Parameters  *constants;   //this dataset holds all IssmPDouble, int, bool and char *parameters read in from the input file.*
    2222
    2323        public:
     
    4444                void        Constant(bool *poutput,int constant_enum);
    4545                void        Constant(int *poutput,int constant_enum);
    46                 void        Constant(IssmDouble *poutput,int constant_enum);
     46                void        Constant(IssmPDouble *poutput,int constant_enum);
    4747                void        Constant(char **poutput,int constant_enum);
    4848                Param      *CopyConstantObject(int constant_enum);
    49                 IssmDouble *Data(int dataenum);
     49                IssmPDouble *Data(int dataenum);
    5050                void        DeleteData(int num,...);
    5151                void        FetchConstants(void);
    5252                void        FetchData(bool* pboolean,int data_enum);
    5353                void        FetchData(int* pinteger,int data_enum);
    54                 void        FetchData(IssmDouble* pscalar,int data_enum);
     54                void        FetchData(IssmPDouble* pscalar,int data_enum);
    5555                void        FetchData(char** pstring,int data_enum);
    5656                void        FetchData(int** pmatrix,int* pM,int* pN,int data_enum);
    57                 void        FetchData(IssmDouble**  pscalarmatrix,int* pM,int* pN,int data_enum);
     57                void        FetchData(IssmPDouble**  pscalarmatrix,int* pM,int* pN,int data_enum);
    5858                void        FetchData(char***   pstringarray,int* pnumstrings,int data_enum);
    59                 void        FetchData(IssmDouble*** pmatrixarray,int** pmdims,int** pndims, int* pnumrecords,int data_enum);
     59                void        FetchData(IssmPDouble*** pmatrixarray,int** pmdims,int** pndims, int* pnumrecords,int data_enum);
    6060                void        FetchData(Option **poption,int data_enum);
    6161                void        FetchData(int num,...);
    62                 void        FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,IssmDouble default_value=0);
     62                void        FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,IssmPDouble default_value=0);
    6363                void        LastIndex(int *pindex);
    6464                FILE*       SetFilePointerToData(int* pcode,int* pvector_type, int data_enum);
Note: See TracChangeset for help on using the changeset viewer.