Ignore:
Timestamp:
07/19/16 13:36:05 (9 years ago)
Author:
Mathieu Morlighem
Message:

CHG: do not keep file pointer, reopen and append to outbin file

File:
1 edited

Legend:

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

    r20940 r20943  
    733733                                ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    734734                                switch(record_code){
    735                                 case 1:
    736                                         /*boolean. get it from cpu 0 */
    737                                         ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    738 
    739                                         /*create BoolParam: */
    740                                         this->AddConstant(new IoConstant((bool)booleanint,record_name)); //cast to a boolean
    741                                         break;
    742 
    743                                 case 2:
    744                                         /*integer. get it from cpu 0 */
    745                                         ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    746 
    747                                         /*create IntParam: */
    748                                         this->AddConstant(new IoConstant(integer,record_name));
    749                                         break;
    750                                 case 3:
    751                                         /*scalar. get it from cpu 0 */
    752                                           {
    753                                                 /*IssmDouble, check whether it is already there (from "declare independents")*/
    754                                                 bool exists = false;
    755                                                 vector<IoConstant*>::iterator iter;
    756                                                 for(iter=constants.begin();iter<constants.end();iter++){
    757                                                         IoConstant* ioconstant=*iter;
    758                                                         if(strcmp(ioconstant->name,record_name)==0){
    759                                                                 exists = true;
    760                                                                 break;
     735                                        case 1:
     736                                                /*boolean. get it from cpu 0 */
     737                                                ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     738
     739                                                /*create BoolParam: */
     740                                                this->AddConstant(new IoConstant((bool)booleanint,record_name)); //cast to a boolean
     741                                                break;
     742
     743                                        case 2:
     744                                                /*integer. get it from cpu 0 */
     745                                                ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     746
     747                                                /*create IntParam: */
     748                                                this->AddConstant(new IoConstant(integer,record_name));
     749                                                break;
     750                                        case 3:
     751                                                /*scalar. get it from cpu 0 */
     752                                                  {
     753                                                        /*IssmDouble, check whether it is already there (from "declare independents")*/
     754                                                        bool exists = false;
     755                                                        vector<IoConstant*>::iterator iter;
     756                                                        for(iter=constants.begin();iter<constants.end();iter++){
     757                                                                IoConstant* ioconstant=*iter;
     758                                                                if(strcmp(ioconstant->name,record_name)==0){
     759                                                                        exists = true;
     760                                                                        break;
     761                                                                }
    761762                                                        }
     763                                                        if(!exists){
     764                                                                ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
     765                                                                scalar=pscalar;
     766                                                                /*create DoubleParam: */
     767                                                                this->AddConstant(new IoConstant(scalar,record_name));
     768                                                        }
     769                                                  }
     770                                                break;
     771                                        case 4:
     772                                                ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     773                                                if(string_size){
     774                                                        string=xNew<char>((string_size+1));
     775                                                        string[string_size]='\0';
     776
     777                                                        /*Read string from cpu 0: */
     778                                                        ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    762779                                                }
    763                                                 if(!exists){
    764                                                         ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    765                                                         scalar=pscalar;
    766                                                         /*create DoubleParam: */
    767                                                         this->AddConstant(new IoConstant(scalar,record_name));
     780                                                else{
     781                                                        string=xNew<char>(1);
     782                                                        string[0]='\0';
    768783                                                }
    769                                           }
    770                                         break;
    771                                 case 4:
    772                                         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    773                                         if(string_size){
    774                                                 string=xNew<char>((string_size+1));
    775                                                 string[string_size]='\0';
    776 
    777                                                 /*Read string from cpu 0: */
    778                                                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    779                                         }
    780                                         else{
    781                                                 string=xNew<char>(1);
    782                                                 string[0]='\0';
    783                                         }
    784                                         if(strcmp(record_name,"md.flowequation.fe_SSA")==0){
    785                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    786                                         } else if(strcmp(record_name,"md.flowequation.fe_HO")==0){
    787                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    788                                         } else if(strcmp(record_name,"md.flowequation.fe_FS")==0){
    789                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    790                                         } else if(strcmp(record_name,"md.groundingline.migration")==0){
    791                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    792                                         } else if(strcmp(record_name,"md.masstransport.hydrostatic_adjustment")==0){
    793                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    794                                         } else {
    795                                                 /*Add string to parameters: */
    796                                                 this->AddConstant(new IoConstant(string,record_name));
    797                                         }
    798 
    799                                         /*Free string*/
    800                                         xDelete<char>(string);
    801 
    802                                         break;
    803                                 case 5: break; //do nothing. not interested in this type of data, which is memory intensive.
    804                                 case 6: break; //do nothing. not interested in this type of data, which is memory intensive.
    805                                 case 7: break; //do nothing. not interested in this type of data, which is memory intensive.
    806                                 case 8: break; //do nothing. not interested in this type of data, which is memory intensive.
    807                                 case 9:
    808                                         ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    809                                         /*Now allocate string array: */
    810                                         if(numstrings){
    811                                                 strings=xNew<char*>(numstrings);
    812                                                 for(int i=0;i<numstrings;i++)strings[i]=NULL;
    813 
    814                                                 /*Go through strings, and read: */
    815                                                 for(int i=0;i<numstrings;i++){
    816 
    817                                                         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    818                                                         if(string_size){
    819                                                                 string=xNew<char>((string_size+1));
    820                                                                 string[string_size]='\0';
    821                                                                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    822                                                         }
    823                                                         else{
    824                                                                 string=xNew<char>(1);
    825                                                                 string[0]='\0';
    826                                                         }
    827                                                         strings[i]=string;
     784                                                if(strcmp(record_name,"md.flowequation.fe_SSA")==0){
     785                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     786                                                } else if(strcmp(record_name,"md.flowequation.fe_HO")==0){
     787                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     788                                                } else if(strcmp(record_name,"md.flowequation.fe_FS")==0){
     789                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     790                                                } else if(strcmp(record_name,"md.groundingline.migration")==0){
     791                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     792                                                } else if(strcmp(record_name,"md.masstransport.hydrostatic_adjustment")==0){
     793                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     794                                                } else {
     795                                                        /*Add string to parameters: */
     796                                                        this->AddConstant(new IoConstant(string,record_name));
    828797                                                }
    829                                         }
    830 
    831                                         /*Add strings to parameters: */
    832                                         this->AddConstant(new IoConstant(strings,numstrings,record_name));
    833 
    834                                         /*Free string*/
    835                                         for(int i=0;i<numstrings;i++) xDelete<char>(strings[i]);
    836                                         xDelete<char*>(strings);
    837                                         break;
    838                                 default:
    839                                         _error_("unknown record type:" << record_code);
    840                                         break;
     798
     799                                                /*Free string*/
     800                                                xDelete<char>(string);
     801
     802                                                break;
     803                                        case 5: break; //do nothing. not interested in this type of data, which is memory intensive.
     804                                        case 6: break; //do nothing. not interested in this type of data, which is memory intensive.
     805                                        case 7: break; //do nothing. not interested in this type of data, which is memory intensive.
     806                                        case 8: break; //do nothing. not interested in this type of data, which is memory intensive.
     807                                        case 9:
     808                                                          ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     809                                                          /*Now allocate string array: */
     810                                                          if(numstrings){
     811                                                                  strings=xNew<char*>(numstrings);
     812                                                                  for(int i=0;i<numstrings;i++)strings[i]=NULL;
     813
     814                                                                  /*Go through strings, and read: */
     815                                                                  for(int i=0;i<numstrings;i++){
     816
     817                                                                          ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     818                                                                          if(string_size){
     819                                                                                  string=xNew<char>((string_size+1));
     820                                                                                  string[string_size]='\0';
     821                                                                                  ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
     822                                                                          }
     823                                                                          else{
     824                                                                                  string=xNew<char>(1);
     825                                                                                  string[0]='\0';
     826                                                                          }
     827                                                                          strings[i]=string;
     828                                                                  }
     829                                                          }
     830
     831                                                          /*Add strings to parameters: */
     832                                                          this->AddConstant(new IoConstant(strings,numstrings,record_name));
     833
     834                                                          /*Free string*/
     835                                                          for(int i=0;i<numstrings;i++) xDelete<char>(strings[i]);
     836                                                          xDelete<char*>(strings);
     837                                                          break;
     838                                        default:
     839                                                          _error_("unknown record type:" << record_code);
     840                                                          break;
    841841                                }
    842 
     842                                xDelete<char>(record_name);
    843843                        }
    844844                }
Note: See TracChangeset for help on using the changeset viewer.