Changeset 23767


Ignore:
Timestamp:
03/06/19 15:19:25 (6 years ago)
Author:
Mathieu Morlighem
Message:

CHG: switching to int64 for recordlength

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

Legend:

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

    r23657 r23767  
    11/*! \file IoModel.cpp
    2  * \brief  file containing the methods that will help in processing the input data coming 
     2 * \brief  file containing the methods that will help in processing the input data coming
    33 * into ISSM, from Matlab, or through a binary file opened for reading.
    44 */
     
    151151        this->numberofverticalfaces=-1;
    152152        this->numberofedges=-1;
    153         this->numberofverticaledges=-1; 
    154         this->numberofhorizontaledges=-1;       
     153        this->numberofverticaledges=-1;
     154        this->numberofhorizontaledges=-1;
    155155        this->facescols=-1;
    156156        this->elements=NULL;
     
    182182        this->solution_enum = solution_enum_in;
    183183
    184         /*If we are running in AD mode, we need to start the trace and declare our independent variables now, 
    185          *and prevent them from being erased during successive calls to iomodel->FetchConstants, iomodel->FetchData and 
     184        /*If we are running in AD mode, we need to start the trace and declare our independent variables now,
     185         *and prevent them from being erased during successive calls to iomodel->FetchConstants, iomodel->FetchData and
    186186         iomodel->DeleteData:*/
    187187        this->StartTrace(trace);
     
    342342
    343343        bool        found;
    344         int         record_enum,record_length,record_name_size;
     344        int         record_enum,record_name_size;
     345   long long   record_length;
    345346        char       *record_name = NULL;
    346347        const char *mddot = "md.";
     
    392393
    393394                        /*Go to next Enum*/
    394                         if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
     395                        if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
    395396                        fseek(fid,record_length,SEEK_CUR);
    396397                        xDelete<char>(record_name);
     
    467468                        this->FetchData(&types,NULL,NULL,"md.autodiff.independent_object_types");
    468469
    469                         /*create independent objects, and at the same time, fetch the corresponding independent variables, 
     470                        /*create independent objects, and at the same time, fetch the corresponding independent variables,
    470471                         *and declare them as such in ADOLC: */
    471472                        for(int i=0;i<num_independent_objects;i++){
     
    544545        if(numstrings){
    545546                for(int i=0;i<numstrings;i++){
    546                         char* string=stringarray[i]; 
     547                        char* string=stringarray[i];
    547548                        xDelete<char>(string);
    548549                }
     
    557558        char* record_name = NULL;
    558559        int   record_name_size;
    559         int record_length;
     560        long long record_length;
    560561        int record_code; //1 to 7 number
    561562
     
    608609
    609610                        /* Read the record length and the data type code: */
    610                         if(fread(&record_length,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_length");
     611                        if(fread(&record_length,sizeof(long long),1,this->fid)!=1) _error_("Cound not read record_length");
    611612                        if(fread(&record_code  ,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_code");
    612613
     
    615616
    616617                        /*Tell other cpus the name of the data, then branch according to the data type: */
    617                         ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    618                         ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
    619                         ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     618                        ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     619                        ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
     620                        ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm());
    620621
    621622                        switch(record_code){
    622                                 case 1: 
     623                                case 1:
    623624                                        /*Read the boolean and broadcast it to other cpus:*/
    624625                                        if(fread(&booleanint,sizeof(int),1,this->fid)!=1) _error_("could not read boolean ");
    625                                         ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     626                                        ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    626627
    627628                                        /*create BoolParam: */
     
    644645
    645646                                        /*Broadcast to other cpus*/
    646                                         ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     647                                        ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    647648
    648649                                        /*create IntParam: */
     
    664665                                                if(!exists){
    665666                                                        if(fread(&pscalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_("could not read scalar ");
    666                                                         ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     667                                                        ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    667668                                                        scalar=pscalar;
    668669
     
    672673                                          }
    673674                                        break;
    674                                 case 4: 
     675                                case 4:
    675676                                        /*We have to read a string from disk. First read the dimensions of the string, then the string: */
    676677                                        if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_("could not read length of string ");
    677                                         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     678                                        ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    678679
    679680                                        if(string_size){
     
    683684                                                /*Read string, then broadcast: */
    684685                                                if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_(" could not read string ");
    685                                                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     686                                                ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    686687                                        }
    687688                                        else{
     
    724725                                        xDelete<char>(string);
    725726                                        break;
    726                                 case 5: 
    727                                 case 6: 
    728                                 case 7: 
    729                                 case 8: 
     727                                case 5:
     728                                case 6:
     729                                case 7:
     730                                case 8:
    730731                                case 10:
    731732                                        /*We are not interested in this record, too memory intensive. Skip it: */
     
    734735                                        fseek(fid,record_length,SEEK_CUR);
    735736                                        break;
    736                                 case 9: 
     737                                case 9:
    737738                                        /*String Array*/
    738739                                        if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_("could not read length of string array");
    739                                         ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     740                                        ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    740741                                        /*Now allocate string array: */
    741742                                        if(numstrings){
     
    747748
    748749                                                        if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string ");
    749                                                         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     750                                                        ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    750751                                                        if(string_size){
    751752                                                                string=xNew<char>((string_size+1));
    752753                                                                string[string_size]='\0';
    753754                                                                if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
    754                                                                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     755                                                                ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    755756                                                        }
    756757                                                        else{
     
    769770                                        xDelete<char*>(strings);
    770771                                        break;
    771                                 default: 
    772                                         _error_("unknown record type:" << record_code); 
     772                                default:
     773                                        _error_("unknown record type:" << record_code);
    773774                                        break;
    774775                        }
     
    786787                                _assert_(record_name_size);
    787788                                record_name=xNew<char>((record_name_size+1)); record_name[record_name_size]='\0';
    788                                 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
    789                                 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     789                                ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
     790                                ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm());
    790791                                switch(record_code){
    791                                         case 1: 
     792                                        case 1:
    792793                                                /*boolean. get it from cpu 0 */
    793                                                 ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     794                                                ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    794795
    795796                                                /*create BoolParam: */
     
    799800                                        case 2:
    800801                                                /*integer. get it from cpu 0 */
    801                                                 ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     802                                                ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    802803
    803804                                                /*create IntParam: */
     
    825826                                                  }
    826827                                                break;
    827                                         case 4: 
    828                                                 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     828                                        case 4:
     829                                                ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    829830                                                if(string_size){
    830831                                                        string=xNew<char>((string_size+1));
     
    832833
    833834                                                        /*Read string from cpu 0: */
    834                                                         ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     835                                                        ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    835836                                                }
    836837                                                else{
     
    879880                                        case 10: break; //do nothing. not interested in this type of data, which is memory intensive.
    880881                                        case 9:
    881                                                           ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     882                                                          ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    882883                                                          /*Now allocate string array: */
    883884                                                          if(numstrings){
     
    888889                                                                  for(int i=0;i<numstrings;i++){
    889890
    890                                                                           ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     891                                                                          ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    891892                                                                          if(string_size){
    892893                                                                                  string=xNew<char>((string_size+1));
    893894                                                                                  string[string_size]='\0';
    894                                                                                   ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     895                                                                                  ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    895896                                                                          }
    896897                                                                          else{
     
    909910                                                          xDelete<char*>(strings);
    910911                                                          break;
    911                                         default: 
    912                                                           _error_("unknown record type:" << record_code); 
     912                                        default:
     913                                                          _error_("unknown record type:" << record_code);
    913914                                                          break;
    914915                                }
     
    933934
    934935        /*We have to read a boolean from disk. */
    935         if(my_rank==0){ 
     936        if(my_rank==0){
    936937                if(fread(&booleanint,sizeof(int),1,fid)!=1) _error_("could not read boolean ");
    937938        }
    938         ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     939        ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    939940
    940941        /*cast to bool: */
     
    959960
    960961        /*We have to read a integer from disk. First read the dimensions of the integer, then the integer: */
    961         if(my_rank==0){ 
     962        if(my_rank==0){
    962963                if(fread(&integer,sizeof(int),1,fid)!=1) _error_("could not read integer ");
    963964        }
    964965
    965         ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     966        ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    966967
    967968        /*Assign output pointers: */
     
    987988                if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar ");
    988989        }
    989         ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     990        ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    990991
    991992        /*Assign output pointers: */
     
    10121013
    10131014        /*We have to read a string from disk. First read the dimensions of the string, then the string: */
    1014         if(my_rank==0){ 
     1015        if(my_rank==0){
    10151016                if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string ");
    10161017        }
    10171018
    1018         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1019        ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    10191020
    10201021        /*Now allocate string: */
     
    10241025
    10251026                /*Read string on node 0, then broadcast: */
    1026                 if(my_rank==0){ 
     1027                if(my_rank==0){
    10271028                        if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
    10281029                }
    1029                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     1030                ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    10301031        }
    10311032        else{
     
    10571058        /*Now fetch: */
    10581059
    1059         if(my_rank==0){ 
     1060        if(my_rank==0){
    10601061                if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_("could not read length of string array");
    10611062        }
    1062         ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1063        ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    10631064
    10641065        /*Now allocate string array: */
     
    10701071                for(int i=0;i<numstrings;i++){
    10711072
    1072                         if(my_rank==0){ 
     1073                        if(my_rank==0){
    10731074                                if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string ");
    10741075                        }
    1075                         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1076                        ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    10761077                        if(string_size){
    10771078                                string=xNew<char>((string_size+1));
    10781079                                string[string_size]='\0';
    1079                                 if(my_rank==0){ 
     1080                                if(my_rank==0){
    10801081                                        if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
    10811082                                }
    1082                                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     1083                                ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    10831084                        }
    10841085                        else{
     
    11161117        /*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
    11171118        /*numberofelements: */
    1118         if(my_rank==0){ 
     1119        if(my_rank==0){
    11191120                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
    11201121        }
    11211122
    1122         ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    1123 
    1124         if(my_rank==0){ 
     1123        ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     1124
     1125        if(my_rank==0){
    11251126                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
    11261127        }
     
    11321133
    11331134                /*Read matrix on node 0, then broadcast: */
    1134                 if(my_rank==0){ 
     1135                if(my_rank==0){
    11351136                        if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    11361137                }
    11371138
    1138                 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     1139                ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    11391140        }
    11401141
     
    11941195                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
    11951196        }
    1196         ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    1197 
    1198         if(my_rank==0){ 
     1197        ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     1198
     1199        if(my_rank==0){
    11991200                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
    12001201        }
    1201         ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1202        ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    12021203
    12031204        /*Now allocate matrix: */
     
    12071208                        IssmPDouble offset,range;
    12081209                        if(my_rank==0) if(fread(&offset,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read offset");
    1209                         ISSM_MPI_Bcast(&offset,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     1210                        ISSM_MPI_Bcast(&offset,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    12101211
    12111212                        if(my_rank==0) if(fread(&range,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read range");
    1212                         ISSM_MPI_Bcast(&range,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     1213                        ISSM_MPI_Bcast(&range,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    12131214
    12141215                        *pmatrix=xNew<IssmDouble>(M*N);
     
    12171218                        uint8_t* rawmatrix=xNew<uint8_t>((M-1)*N);
    12181219                        if(my_rank==0) if(fread(rawmatrix,(M-1)*N*sizeof(char),1,fid)!=1) _error_("could not read matrix ");
    1219                         ISSM_MPI_Bcast(rawmatrix,(M-1)*N,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     1220                        ISSM_MPI_Bcast(rawmatrix,(M-1)*N,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    12201221
    12211222                        for(int i=0;i<(M-1)*N;++i) (*pmatrix)[i]=offset+range*reCast<IssmDouble>(rawmatrix[i])/255.;
     
    12251226                        IssmPDouble* timematrix=xNew<IssmPDouble>(N);
    12261227                        if(my_rank==0) if(fread(timematrix,N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read time in compressed matrix");
    1227                         ISSM_MPI_Bcast(timematrix,N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     1228                        ISSM_MPI_Bcast(timematrix,N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    12281229
    12291230                        for(int i=0;i<N;++i) (*pmatrix)[(M-1)*N+i]=timematrix[i];
     
    12351236                        matrix=xNew<IssmPDouble>(M*N);
    12361237                        if(my_rank==0) if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    1237                         ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     1238                        ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    12381239
    12391240                        *pmatrix=xNew<IssmDouble>(M*N);
     
    12721273
    12731274        /*Now fetch: */
    1274         if(my_rank==0){ 
     1275        if(my_rank==0){
    12751276                if(fread(&numrecords,sizeof(int),1,fid)!=1) _error_("could not read number of records in matrix array ");
    12761277        }
    1277         ISSM_MPI_Bcast(&numrecords,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1278        ISSM_MPI_Bcast(&numrecords,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    12781279
    12791280        if(numrecords){
     
    12931294                for(i=0;i<numrecords;i++){
    12941295
    1295                         if(my_rank==0){ 
     1296                        if(my_rank==0){
    12961297                                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows in " << i << "th matrix of matrix array");
    12971298                        }
    1298                         ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    1299 
    1300                         if(my_rank==0){ 
     1299                        ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     1300
     1301                        if(my_rank==0){
    13011302                                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns in " << i << "th matrix of matrix array");
    13021303                        }
    1303                         ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1304                        ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    13041305
    13051306                        /*Now allocate matrix: */
     
    13081309
    13091310                                /*Read matrix on node 0, then broadcast: */
    1310                                 if(my_rank==0){ 
     1311                                if(my_rank==0){
    13111312                                        if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    13121313                                }
    13131314
    1314                                 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     1315                                ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    13151316                                matrices[i]=xNew<IssmDouble>(M*N);
    13161317                                for (int j=0;j<M*N;++j) {matrices[i][j]=matrix[j];}
     
    13381339        char* record_name = NULL;
    13391340        int   record_name_size;
    1340         int  record_length;
    1341         int   record_code; 
     1341        long long record_length;
     1342        int   record_code;
    13421343
    13431344        /*records: */
     
    13671368                        /*Is this the record sought for? : */
    13681369                        if(strcmp(record_name,lastnonoption)==0){
    1369                                 if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
     1370                                if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
    13701371                                fseek(fid,record_length,SEEK_CUR);
    13711372                                xDelete<char>(record_name);
     
    13731374                        }
    13741375                        else{
    1375                                 if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
     1376                                if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
    13761377                                fseek(fid,record_length,SEEK_CUR);
    13771378                                xDelete<char>(record_name);
     
    14161417
    14171418                        /* Read the record length and the data type code: */
    1418                         if(fread(&record_length,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_length");
     1419                        if(fread(&record_length,sizeof(long long),1,this->fid)!=1) _error_("Cound not read record_length");
    14191420                        if(fread(&record_code  ,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_code");
    14201421
     
    14231424
    14241425                        /*Tell other cpus the name of the data, then branch according to the data type: */
    1425                         ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    1426                         ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
    1427                         ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1426                        ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     1427                        ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
     1428                        ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm());
    14281429
    14291430                        switch(record_code){
     
    14311432                                          {
    14321433                                                if(fread(&scalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_("could not read scalar ");
    1433                                                 ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     1434                                                ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    14341435                                                GenericOption<IssmDouble>* option = new GenericOption<IssmDouble>();
    14351436                                                char* optionname=xNew<char>(strlen(record_name)-3+1);
     
    14421443                                          }
    14431444                                        break;
    1444                                 case 4: 
     1445                                case 4:
    14451446                                          {
    14461447                                        /*We have to read a string from disk. First read the dimensions of the string, then the string: */
    14471448                                        if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_("could not read length of string ");
    1448                                         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1449                                        ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    14491450
    14501451                                        if(string_size){
     
    14541455                                                /*Read string, then broadcast: */
    14551456                                                if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_(" could not read string ");
    1456                                                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     1457                                                ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    14571458                                        }
    14581459                                        else{
     
    14731474                                          }
    14741475                                        break;
    1475                                 default: 
    1476                                         _error_("record type not supported:" << record_code); 
     1476                                default:
     1477                                        _error_("record type not supported:" << record_code);
    14771478                                        break;
    14781479                        }
     
    14901491                                _assert_(record_name_size);
    14911492                                record_name=xNew<char>((record_name_size+1)); record_name[record_name_size]='\0';
    1492                                 ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
    1493                                 ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1493                                ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
     1494                                ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm());
    14941495                                switch(record_code){
    14951496                                        case 3:
    14961497                                                  {
    14971498                                                        if(fread(&scalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_("could not read scalar ");
    1498                                                         ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     1499                                                        ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    14991500                                                        char* optionname=xNew<char>(strlen(record_name)-3+1);
    15001501                                                        xMemCpy(optionname,&record_name[3],strlen(record_name)-3+1);
     
    15071508                                                  }
    15081509                                                break;
    1509                                         case 4: 
     1510                                        case 4:
    15101511                                                  {
    15111512                                                /*We have to read a string from disk. First read the dimensions of the string, then the string: */
    15121513                                                if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_("could not read length of string ");
    1513                                                 ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1514                                                ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    15141515
    15151516                                                if(string_size){
     
    15191520                                                        /*Read string, then broadcast: */
    15201521                                                        if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_(" could not read string ");
    1521                                                         ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     1522                                                        ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    15221523                                                }
    15231524                                                else{
     
    15371538                                                  }
    15381539                                                break;
    1539                                         default: 
    1540                                                 _error_("record type not supported:" << record_code); 
     1540                                        default:
     1541                                                _error_("record type not supported:" << record_code);
    15411542                                                break;
    15421543                                }
     
    16251626        for(int i=0;i<elements->Size();i++){
    16261627                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
    1627                 if(!doublearray) element->AddInput(input_enum,&default_value,P0Enum); 
     1628                if(!doublearray) element->AddInput(input_enum,&default_value,P0Enum);
    16281629                else             element->InputCreate(doublearray,this,M,N,vector_layout,input_enum,code);//we need i to index into elements.
    16291630        }
     
    16841685                                element->InputUpdateFromConstant(scalar,input_enum);
    16851686                        }
    1686                         break; 
     1687                        break;
    16871688                case 5: //boolean vector
    16881689                        this->FetchData(&doublearray,&M,&N,vector_name); //we still have a doublearray, because it might include times in transient mode
     
    17431744                if(fread(&pscalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar ");
    17441745
    1745                 /*Now, before we even broadcast this to other nodes, declare the scalar  as an independent variable!. If we 
     1746                /*Now, before we even broadcast this to other nodes, declare the scalar  as an independent variable!. If we
    17461747                 *have been supplied an X vector, use it instead of what we just read: */
    17471748                #if defined(_HAVE_CODIPACK_)
     
    17651766        }
    17661767
    1767         ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
     1768        ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    17681769        this->AddConstantIndependent(new IoConstant(scalar,constant_name));
    17691770
     
    17961797        /*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
    17971798        /*numberofelements: */
    1798         if(my_rank==0){ 
     1799        if(my_rank==0){
    17991800                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
    18001801        }
    1801         ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    1802 
    1803         if(my_rank==0){ 
     1802        ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     1803
     1804        if(my_rank==0){
    18041805                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
    18051806        }
    1806         ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1807        ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    18071808
    18081809        /*Now allocate matrix: */
     
    18181819
    18191820                /*Read matrix on node 0, then broadcast: */
    1820                 if(my_rank==0){ 
     1821                if(my_rank==0){
    18211822                        if(fread(buffer,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    18221823
     
    18491850                        #endif
    18501851                }
    1851                 ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
     1852                ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    18521853
    18531854                xDelete<IssmPDouble>(buffer);
     
    18561857
    18571858        // FIXME codi is that at all relevant to CoDiPack or can we simply assume the same?
    1858        
     1859
    18591860        /*Add to data as independent*/
    18601861        this->AddDataIndependent(new IoData(matrix,code,layout,M,N,data_name));
     
    18931894                        if(my_rank==0){
    18941895                                /*check we are indeed finding a string, not something else: */
    1895                                 if(codes[i]!=4)_error_("expecting a string for \""<<data_name<<"\"");
     1896                                if(codes[i]!=4)_error_("expecting a string for \""<<data_name<<"\" but code is "<<codes[i]<<" not 4");
    18961897
    18971898                                /*We have to read a string from disk. First read the dimensions of the string, then the string: */
     
    19001901                        }
    19011902
    1902                         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1903                        ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    19031904
    19041905                        /*Now allocate string: */
     
    19111912                                        if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
    19121913                                }
    1913                                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
     1914                                ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    19141915                        }
    19151916                        else{
     
    19621963                                /*We have to read a integer from disk. First read the dimensions of the integer, then the integer: */
    19631964                                fsetpos(fid,file_positions+i);
    1964                                 if(my_rank==0){ 
     1965                                if(my_rank==0){
    19651966                                        if(fread(&integer,sizeof(int),1,fid)!=1) _error_("could not read integer ");
    19661967                                }
    19671968                        }
    1968                         ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     1969                        ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    19691970
    19701971                        /*Assign: */
     
    20152016                                /*We have to read a double from disk: */
    20162017                                fsetpos(fid,file_positions+i);
    2017                                 if(my_rank==0){ 
     2018                                if(my_rank==0){
    20182019                                        if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read scalar ");
    20192020                                }
    20202021                        }
    2021                         ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     2022                        ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    20222023
    20232024                        /*Assign: */
     
    20772078                                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
    20782079                        }
    2079                         ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    2080 
    2081                         if(my_rank==0){ 
     2080                        ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     2081
     2082                        if(my_rank==0){
    20822083                                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
    20832084                        }
    2084                         ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     2085                        ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    20852086
    20862087                        /*Now allocate matrix: */
     
    20892090
    20902091                                /*Read matrix on node 0, then broadcast: */
    2091                                 if(my_rank==0){ 
     2092                                if(my_rank==0){
    20922093                                        if(fread(pmatrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    20932094                                }
    2094                                 ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     2095                                ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    20952096
    20962097                                //if(this->independents[data_enum]){ FIXME
    2097                                 //      /*this data has already been checked out! So cancel all that we've done here, and return 
     2098                                //      /*this data has already been checked out! So cancel all that we've done here, and return
    20982099                                //       * the data[data_enum] directly: */
    20992100                                //      matrix=this->data[data_enum];
     
    21792180                                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
    21802181                        }
    2181                         ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    2182 
    2183                         if(my_rank==0){ 
     2182                        ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     2183
     2184                        if(my_rank==0){
    21842185                                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
    21852186                        }
    2186                         ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     2187                        ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    21872188
    21882189                        /*Now allocate matrix: */
     
    21922193
    21932194                                /*Read matrix on node 0, then broadcast: */
    2194                                 if(my_rank==0){ 
     2195                                if(my_rank==0){
    21952196                                        if(fread(pmatrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    21962197                                }
    2197                                 ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
     2198                                ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    21982199
    21992200                                //if(this->independents[data_enum]){ FIXME
    2200                                 //      /*this data has already been checked out! So cancel all that we've done here, and return 
     2201                                //      /*this data has already been checked out! So cancel all that we've done here, and return
    22012202                                //       * the data[data_enum] directly: */
    22022203                                //      matrix=this->data[data_enum];
     
    23822383        char* record_name = NULL;
    23832384        int   record_name_size;
    2384         int     record_length;
     2385        long long  record_length;
    23852386        int     record_code;           //1 to 7 number
    23862387        int     vector_type;           //1 to 7 number
     
    23952396        _assert_(strncmp(data_name,mddot,3)==0);
    23962397
    2397         /*Go find in the binary file, the data we want to fetch and count the number of 
     2398        /*Go find in the binary file, the data we want to fetch and count the number of
    23982399         * instances it appears: */
    23992400        if(my_rank==0){
     
    24302431
    24312432                        /*Read the record length, and use it to skip the record: */
    2432                         if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
     2433                        if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
    24332434                        fseek(fid,record_length,SEEK_CUR);
    24342435                        xDelete<char>(record_name);
     
    24422443                }
    24432444
    2444                 /*Reset FILE* position to the beginning of the file, and start again, this time saving the data information 
     2445                /*Reset FILE* position to the beginning of the file, and start again, this time saving the data information
    24452446                 * as we find it: */
    24462447                counter=0;
     
    24742475                        if(strcmp(record_name,data_name)==0){
    24752476                                /*Ok, we have found the correct string. Pass the record length, and read data type code: */
    2476                                 fseek(fid,sizeof(int),SEEK_CUR);
     2477                                fseek(fid,sizeof(long long),SEEK_CUR);
    24772478                                if(fread(&record_code,sizeof(int),1,fid)!=1) _error_("Could not read record_code");
    24782479
     
    24862487
    24872488                                /*backup and skip over the record, as we have more work to do: */
    2488                                 if(5<=record_code && record_code<=7) fseek(fid,-sizeof(int),SEEK_CUR);
    2489                                 fseek(fid,-sizeof(int),SEEK_CUR);
    2490                                 fseek(fid,-sizeof(int),SEEK_CUR);
     2489                                if(5<=record_code && record_code<=7) fseek(fid,-sizeof(int),SEEK_CUR); /*rewind for nodal or elementary type*/
     2490                                fseek(fid,-sizeof(int),SEEK_CUR);/*rewind for data code*/
     2491                                fseek(fid,-sizeof(long long),SEEK_CUR);/*rewind for record length*/
    24912492
    24922493                                /*increment counter: */
     
    24952496
    24962497                        /*Read the record length, and use it to skip this record, as it has already been processed: */
    2497                         if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
     2498                        if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
    24982499                        /*skip: */
    24992500                        fseek(fid,record_length,SEEK_CUR);
     
    25032504
    25042505        /*Broadcast data: */
    2505         ISSM_MPI_Bcast(&num_instances,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     2506        ISSM_MPI_Bcast(&num_instances,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    25062507
    25072508        /*Assign output pointers:*/
     
    25252526        char* record_name = NULL;
    25262527        int   record_name_size;
    2527         int record_length;
     2528        long long record_length;
    25282529        int record_code;       //1 to 7 number
    25292530        int vector_type   = 0; //nodal or elementary
     
    25712572                        if(strcmp(record_name,data_name)==0){
    25722573                                /*Ok, we have found the correct string. Pass the record length, and read data type code: */
    2573                                 fseek(fid,sizeof(int),SEEK_CUR);
     2574                                fseek(fid,sizeof(long long),SEEK_CUR);
    25742575                                if(fread(&record_code,sizeof(int),1,fid)!=1) _error_("Could not read record_code");
    2575 
    25762576                                /*if record_code points to a vector, get its type (nodal or elementary): */
    25772577                                if((5<=record_code && record_code<=7) || record_code==10){
     
    25842584                        else{
    25852585                                /*This is not the correct string, read the record length, and use it to skip this record: */
    2586                                 if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
     2586                                if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
    25872587                                /*skip: */
    25882588                                fseek(fid,record_length,SEEK_CUR);
     
    25912591                }
    25922592        }
    2593         ISSM_MPI_Bcast(&found,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     2593        ISSM_MPI_Bcast(&found,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    25942594        if(!found)_error_("could not find data with name \"" << data_name << "\" in binary file");
    25952595
    25962596        /*Broadcast code and vector type: */
    2597         ISSM_MPI_Bcast(&record_code,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    2598         ISSM_MPI_Bcast(&vector_type,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
     2597        ISSM_MPI_Bcast(&record_code,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     2598        ISSM_MPI_Bcast(&vector_type,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    25992599
    26002600        /*Assign output pointers:*/
  • issm/trunk-jpl/src/m/solve/WriteData.m

    r21704 r23767  
    4747
    4848%Step 1: write the name to identify this record uniquely
    49 fwrite(fid,numel(name),'int'); 
    50 fwrite(fid,name,'char'); 
     49fwrite(fid,numel(name),'int');
     50fwrite(fid,name,'char');
    5151
    5252%Step 2: write the data itself.
     
    5555
    5656        %first write length of record
    57         fwrite(fid,4+4,'int');  %1 bool (disguised as an int)+code
    58 
    59         %write data code: 
    60         fwrite(fid,FormatToCode(format),'int'); 
     57        fwrite(fid,4+4,'int64');  %1 bool (disguised as an int)+code
     58
     59        %write data code:
     60        fwrite(fid,FormatToCode(format),'int');
    6161
    6262        %now write integer
     
    6767
    6868        %first write length of record
    69         fwrite(fid,4+4,'int');  %1 integer + code
    70 
    71         %write data code: 
    72         fwrite(fid,FormatToCode(format),'int'); 
     69        fwrite(fid,4+4,'int64');  %1 integer + code
     70
     71        %write data code:
     72        fwrite(fid,FormatToCode(format),'int');
    7373
    7474        %now write integer
    75         fwrite(fid,data,'int'); 
     75        fwrite(fid,data,'int');
    7676        % }}}
    7777elseif strcmpi(format,'Double'), % {{{
     
    7979
    8080        %first write length of record
    81         fwrite(fid,8+4,'int');  %1 double+code
    82 
    83         %write data code: 
    84         fwrite(fid,FormatToCode(format),'int'); 
     81        fwrite(fid,8+4,'int64');  %1 double+code
     82
     83        %write data code:
     84        fwrite(fid,FormatToCode(format),'int');
    8585
    8686        %now write double
    87         fwrite(fid,data,'double'); 
     87        fwrite(fid,data,'double');
    8888        % }}}
    8989elseif strcmpi(format,'String'), % {{{
    9090        %first write length of record
    91         fwrite(fid,length(data)+4+4,'int');  %string + string size + code
    92 
    93         %write data code: 
    94         fwrite(fid,FormatToCode(format),'int'); 
     91        fwrite(fid,length(data)+4+4,'int64');  %string + string size + code
     92
     93        %write data code:
     94        fwrite(fid,FormatToCode(format),'int');
    9595
    9696        %now write string
    97         fwrite(fid,length(data),'int'); 
    98         fwrite(fid,data,'char'); 
     97        fwrite(fid,length(data),'int');
     98        fwrite(fid,data,'char');
    9999        % }}}
    100100elseif strcmpi(format,'BooleanMat'), % {{{
     
    108108
    109109        %first write length of record
    110         fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int');  %2 integers (32 bits) + the double matrix + code + matrix type
    111 
    112         %write data code and matrix type: 
    113         fwrite(fid,FormatToCode(format),'int'); 
     110        fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int64');  %2 integers (32 bits) + the double matrix + code + matrix type
     111
     112        %write data code and matrix type:
     113        fwrite(fid,FormatToCode(format),'int');
    114114        fwrite(fid,mattype,'int');
    115115
    116116        %now write matrix
    117         fwrite(fid,s(1),'int'); 
    118         fwrite(fid,s(2),'int'); 
     117        fwrite(fid,s(1),'int');
     118        fwrite(fid,s(2),'int');
    119119        if s(1)*s(2),
    120120                fwrite(fid,data','double'); %get to the "c" convention, hence the transpose
     
    131131
    132132        %first write length of record
    133         fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int');  %2 integers (32 bits) + the double matrix + code + matrix type
    134 
    135         %write data code and matrix type: 
    136         fwrite(fid,FormatToCode(format),'int'); 
     133        fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int64');  %2 integers (32 bits) + the double matrix + code + matrix type
     134
     135        %write data code and matrix type:
     136        fwrite(fid,FormatToCode(format),'int');
    137137        fwrite(fid,mattype,'int');
    138138
    139139        %now write matrix
    140         fwrite(fid,s(1),'int'); 
    141         fwrite(fid,s(2),'int'); 
     140        fwrite(fid,s(1),'int');
     141        fwrite(fid,s(2),'int');
    142142        if s(1)*s(2),
    143143                fwrite(fid,data','double'); %get to the "c" convention, hence the transpose
     
    155155        %first write length of record
    156156        recordlength=4+4+8*s(1)*s(2)+4+4; %2 integers (32 bits) + the double matrix + code + matrix type
    157         if recordlength>2^31; error(['field ' name ' cannot be marshalled because it is larger than 2^31 bytes!']); end
    158         fwrite(fid,recordlength,'int');
    159 
    160         %write data code and matrix type: 
    161         fwrite(fid,FormatToCode(format),'int'); 
     157        if recordlength>2^63; error(['field ' name ' cannot be marshalled because it is larger than 2^63 bytes!']); end
     158        fwrite(fid,recordlength,'int64');
     159
     160        %write data code and matrix type:
     161        fwrite(fid,FormatToCode(format),'int');
    162162        fwrite(fid,mattype,'int');
    163163
    164164        %now write matrix
    165         fwrite(fid,s(1),'int'); 
    166         fwrite(fid,s(2),'int'); 
     165        fwrite(fid,s(1),'int');
     166        fwrite(fid,s(2),'int');
    167167        if s(1)*s(2),
    168168                fwrite(fid,data','double'); %get to the "c" convention, hence the transpose
     
    180180        %first write length of record
    181181        recordlength=4+4+8+8+1*(s(1)-1)*s(2)+8*s(2)+4+4; %2 integers (32 bits) + the matrix + code + matrix type
    182         if recordlength>2^31; error(['field ' name ' cannot be marshalled because it is larger than 2^31 bytes!']); end
    183         fwrite(fid,recordlength,'int');
    184 
    185         %write data code and matrix type: 
    186         fwrite(fid,FormatToCode(format),'int'); 
     182        if recordlength>2^63; error(['field ' name ' cannot be marshalled because it is larger than 2^63 bytes!']); end
     183        fwrite(fid,recordlength,'int64');
     184
     185        %write data code and matrix type:
     186        fwrite(fid,FormatToCode(format),'int');
    187187        fwrite(fid,mattype,'int');
    188188
    189189        %write matrix size
    190         fwrite(fid,s(1),'int'); 
    191         fwrite(fid,s(2),'int'); 
     190        fwrite(fid,s(1),'int');
     191        fwrite(fid,s(2),'int');
    192192
    193193        if s(1)*s(2),
     
    205205
    206206                %Write last row as double (time)
    207                 fwrite(fid,data(end,:),'double'); 
     207                fwrite(fid,data(end,:),'double');
    208208        else
    209209
     
    227227
    228228        %write length of record
    229         fwrite(fid,recordlength,'int');
    230 
    231         %write data code: 
    232         fwrite(fid,FormatToCode(format),'int'); 
     229        fwrite(fid,recordlength,'int64');
     230
     231        %write data code:
     232        fwrite(fid,FormatToCode(format),'int');
    233233
    234234        %write data, first number of records
    235         fwrite(fid,numrecords,'int'); 
    236 
    237         %write each matrix: 
     235        fwrite(fid,numrecords,'int');
     236
     237        %write each matrix:
    238238        for i=1:numrecords,
    239239                matrix=data{i};
    240240                s=size(matrix);
    241                 fwrite(fid,s(1),'int'); 
    242                 fwrite(fid,s(2),'int'); 
     241                fwrite(fid,s(1),'int');
     242                fwrite(fid,s(2),'int');
    243243                fwrite(fid,matrix','double');
    244244        end
     
    246246elseif strcmpi(format,'StringArray'), % {{{
    247247
    248         %first get length of string array: 
     248        %first get length of string array:
    249249        num=numel(data);
    250250        if isnumeric(data) & num==1 & isnan(data),
     
    252252        end
    253253
    254         %now get length of record: 
     254        %now get length of record:
    255255        recordlength=4+4; %for length of array + code
    256256        for i=1:num,
     
    260260
    261261        %write length of record
    262         fwrite(fid,recordlength,'int');
    263 
    264         %write data code: 
    265         fwrite(fid,FormatToCode(format),'int'); 
     262        fwrite(fid,recordlength,'int64');
     263
     264        %write data code:
     265        fwrite(fid,FormatToCode(format),'int');
    266266
    267267        %now write length of string array
    268         fwrite(fid,num,'int'); 
     268        fwrite(fid,num,'int');
    269269
    270270        %now write the strings
    271271        for i=1:num,
    272272                string=data{i};
    273                 fwrite(fid,length(string),'int'); 
    274                 fwrite(fid,string,'char'); 
     273                fwrite(fid,length(string),'int');
     274                fwrite(fid,string,'char');
    275275        end
    276276        % }}}
     
    281281
    282282function code=FormatToCode(format) % {{{
    283 %This routine takes the format string, and hardcodes it into an integer, which 
    284 %is passed along the record, in order to identify the nature of the dataset being 
     283%This routine takes the format string, and hardcodes it into an integer, which
     284%is passed along the record, in order to identify the nature of the dataset being
    285285%sent.
    286286        if     strcmpi(format,'Boolean'),
    287287                code=1;
    288         elseif strcmpi(format,'Integer'), 
     288        elseif strcmpi(format,'Integer'),
    289289                code=2;
    290         elseif strcmpi(format,'Double'), 
     290        elseif strcmpi(format,'Double'),
    291291                code=3;
    292         elseif strcmpi(format,'String'), 
     292        elseif strcmpi(format,'String'),
    293293                code=4;
    294294        elseif strcmpi(format,'BooleanMat'),
     
    298298        elseif strcmpi(format,'DoubleMat'),
    299299                code=7;
    300         elseif strcmpi(format,'MatArray'), 
     300        elseif strcmpi(format,'MatArray'),
    301301                code=8;
    302302        elseif strcmpi(format,'StringArray'),
     
    304304        elseif strcmpi(format,'CompressedMat'),
    305305                code=10;
    306         else 
     306        else
    307307                error('FormatToCode error message: data type not supported yet!');
    308308        end
Note: See TracChangeset for help on using the changeset viewer.