Changeset 20977


Ignore:
Timestamp:
07/21/16 15:00:50 (9 years ago)
Author:
Mathieu Morlighem
Message:

CHG: md.autodiff.independent_object_names is now a string array

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

Legend:

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

    r20976 r20977  
    412412
    413413        bool autodiff,iscontrol;
    414         int  num_independent_objects;
     414        int  num_independent_objects,temp;
    415415        int  Xcount=0;
    416416
     
    427427                this->FetchData(&num_independent_objects,"md.autodiff.num_independent_objects");
    428428                if(num_independent_objects){
    429                         this->FetchData(&names,NULL,"md.autodiff.independent_object_names");
     429                        this->FetchData(&names,&temp,"md.autodiff.independent_object_names");
     430                        _assert_(temp==num_independent_objects);
    430431                        this->FetchData(&types,NULL,NULL,"md.autodiff_independent_object_types");
    431432
     
    980981}
    981982/*}}}*/
     983void  IoModel::FetchData(char*** pstrings,int* pnumstrings,const char* data_name){/*{{{*/
     984
     985        /*output: */
     986        char** strings = NULL;
     987        char*  string  = NULL;
     988        int    numstrings;
     989        int    string_size;
     990        int    code;
     991
     992        /*recover my_rank:*/
     993        int my_rank=IssmComm::GetRank();
     994
     995        /*Set file pointer to beginning of the data: */
     996        fid=this->SetFilePointerToData(&code,NULL,data_name);
     997
     998        if(code!=9)_error_("expecting a string array for \""<<data_name<<"\"");
     999
     1000        /*Now fetch: */
     1001
     1002        if(my_rank==0){ 
     1003                if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_("could not read length of string array");
     1004        }
     1005        ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     1006
     1007        /*Now allocate string array: */
     1008        if(numstrings){
     1009                strings=xNew<char*>(numstrings);
     1010                for(int i=0;i<numstrings;i++) strings[i]=NULL;
     1011
     1012                /*Go through strings, and read: */
     1013                for(int i=0;i<numstrings;i++){
     1014
     1015                        if(my_rank==0){ 
     1016                                if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string ");
     1017                        }
     1018                        ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     1019                        if(string_size){
     1020                                string=xNew<char>((string_size+1));
     1021                                string[string_size]='\0';
     1022                                if(my_rank==0){ 
     1023                                        if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
     1024                                }
     1025                                ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
     1026                        }
     1027                        else{
     1028                                string=xNew<char>(1);
     1029                                string[0]='\0';
     1030                        }
     1031                        strings[i]=string;
     1032                }
     1033        }
     1034
     1035        /*Assign output pointers: */
     1036        *pstrings = strings;
     1037        if(pnumstrings) *pnumstrings = numstrings;
     1038}
     1039/*}}}*/
    9821040void  IoModel::FetchData(int** pmatrix,int* pM,int* pN,const char* data_name){/*{{{*/
    9831041        int i,j;
  • issm/trunk-jpl/src/c/classes/IoModel.h

    r20840 r20977  
    121121                void        FetchData(IssmDouble* pscalar,const char* data_name);
    122122                void        FetchData(char** pstring,const char* data_name);
     123                void        FetchData(char*** pstrings,int* pnumstrings,const char* data_name);
    123124                void        FetchData(int** pmatrix,int* pM,int* pN,const char* data_name);
    124125                void        FetchData(IssmDouble**  pscalarmatrix,int* pM,int* pN,const char* data_name);
Note: See TracChangeset for help on using the changeset viewer.