Ignore:
Timestamp:
06/07/17 10:50:54 (8 years ago)
Author:
Eric.Larour
Message:

CHG: merged branch back to trunk-jpl 21754.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/branches/trunk-larour-NatGeoScience2016/src/c/classes/ExternalResults/GenericExternalResult.h

    r21068 r21759  
    334334}  /*}}}*/
    335335
     336/*Specific instantiations for int*: */
     337template <> inline GenericExternalResult<int*>::GenericExternalResult(int in_id, int in_enum_type,int* in_values, int in_M,int in_N,int in_step,IssmDouble in_time){/*{{{*/
     338
     339        id = in_id;
     340        M  = in_M;
     341        N  = in_N;
     342
     343        EnumToStringx(&this->result_name,in_enum_type);
     344
     345        step = in_step;
     346        time = in_time;
     347
     348        /*Copy result in values*/
     349        if(M*N){
     350                value=xNew<int>(M*N);
     351                xMemCpy<int>(value,in_values,M*N);
     352        }
     353        else value=NULL;
     354}
     355/*}}}*/
     356template <> inline GenericExternalResult<int*>::GenericExternalResult(int in_id,const char* in_result_name,int* in_values, int in_M,int in_N,int in_step,IssmDouble in_time){/*{{{*/
     357
     358        id = in_id;
     359        M  = in_M;
     360        N  = in_N;
     361
     362        /*Copy name*/
     363        this->result_name = xNew<char>(strlen(in_result_name)+1);
     364        xMemCpy<char>(this->result_name,in_result_name,strlen(in_result_name)+1);
     365
     366        step = in_step;
     367        time = in_time;
     368
     369        /*Copy result in values*/
     370        if(M*N){
     371                value=xNew<int>(M*N);
     372                xMemCpy<int>(value,in_values,M*N);
     373        }
     374        else value=NULL;
     375}
     376/*}}}*/
     377template <> inline GenericExternalResult<int*>::GenericExternalResult(int in_id, int in_enum_type,int* in_value,int in_step, IssmDouble in_time){ /*{{{*/
     378        _error_("you cannot initialize a GenericExternalResult<int*> without providing the dimensions of the matrix! Please use a more appropriate constructor!");
     379} /*}}}*/
     380template <> inline GenericExternalResult<int*>::~GenericExternalResult(){ /*{{{*/
     381        xDelete<char>(result_name);
     382        xDelete<int>(value);
     383} /*}}}*/
     384template <> inline void GenericExternalResult<int*>::Echo(void){ /*{{{*/
     385
     386        _printf_("GenericExternalResult<int*>:\n");
     387        this->GenericEcho();
     388        _printf_("   matrix size: " << this->M << "-" << this->N << "\n");
     389
     390} /*}}}*/
     391template <> inline void GenericExternalResult<int*>::DeepEcho(void){ /*{{{*/
     392
     393        int i,j;
     394
     395        _printf_("GenericExternalResult<int*>:\n");
     396        this->GenericEcho();
     397
     398        _printf_("   matrix size: " << this->M << "-" << this->N << "\n");
     399        for (i=0;i<this->M;i++){ 
     400                _printf_("   [ ");
     401                for (j=0;j<this->N;j++){
     402                        _printf_( " " << setw(11) << this->value[i*this->N+j]);
     403                } 
     404                _printf_(" ]\n");
     405        } 
     406
     407} /*}}}*/
     408template <> inline Object* GenericExternalResult<int*>::copy(void){ /*{{{*/
     409        return new GenericExternalResult<int*>(this->id,StringToEnumx(this->result_name),this->value,this->M,this->N,this->step,this->time);
     410} /*}}}*/
     411template <> inline void GenericExternalResult<int*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
     412
     413        int     my_rank;
     414        int     type;
     415        int     rows,cols;
     416        char   *name    = NULL;
     417        IssmPDouble passiveDouble;
     418
     419        /*recover my_rank:*/
     420        my_rank=IssmComm::GetRank();
     421
     422        if(io_gather){
     423                /*we are gathering the data on cpu 0, don't write on other cpus: */
     424                if(my_rank) return;
     425        }
     426
     427        /*First write enum: */
     428        int length=(strlen(this->result_name)+1)*sizeof(char);
     429        fwrite(&length,sizeof(int),1,fid);
     430        fwrite(this->result_name,length,1,fid);
     431
     432        /*Now write time and step: */
     433        passiveDouble=reCast<IssmPDouble>(time);
     434        fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
     435        fwrite(&step,sizeof(int),1,fid);
     436
     437        /*writing an int array, type is 4 (see parseresultsfromdisk.m):*/
     438        type=4;
     439        fwrite(&type,sizeof(int),1,fid);
     440        rows=this->M;
     441        fwrite(&rows,sizeof(int),1,fid);
     442        cols=this->N;
     443        fwrite(&cols,sizeof(int),1,fid);
     444        fwrite(value,cols*rows*sizeof(int),1,fid);
     445
     446}
     447/*}}}*/
     448template <> inline int GenericExternalResult<int*>::ObjectEnum(void){ /*{{{*/
     449        return IntMatExternalResultEnum;
     450} /*}}}*/
     451template <> inline void GenericExternalResult<int*>::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){/*{{{*/
     452
     453        MARSHALLING_ENUM(this->ObjectEnum());
     454
     455        MARSHALLING(id);
     456        MARSHALLING(result_name);
     457        MARSHALLING(M);
     458        MARSHALLING(N);
     459        MARSHALLING_DYNAMIC(value,int,M*N);
     460        MARSHALLING(step);
     461        MARSHALLING(time);
     462
     463}  /*}}}*/
     464/*Specific instantiations for int*: */
     465#if defined(_HAVE_ADOLC_) && !defined(_WRAPPERS_)  //We hook off this specific specialization when not running ADOLC, otherwise we get a redeclaration with the next specialization.
     466template <> inline void GenericExternalResult<int*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
     467
     468        int     i;
     469        int     my_rank;
     470        int     type;
     471        int     rows,cols;
     472        char   *name    = NULL;
     473        IssmPDouble passiveDouble;
     474        int* passiveInts;
     475
     476        /*recover my_rank:*/
     477        my_rank=IssmComm::GetRank();
     478
     479        if(io_gather){
     480                /*we are gathering the data on cpu 0, don't write on other cpus: */
     481                if(my_rank) return;
     482        }
     483
     484        /*First write enum: */
     485        int length=(strlen(this->result_name)+1)*sizeof(char);
     486        fwrite(&length,sizeof(int),1,fid);
     487        fwrite(this->result_name,length,1,fid);
     488
     489        /*Now write time and step: */
     490        passiveDouble=reCast<IssmPDouble>(time);
     491        fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
     492        fwrite(&step,sizeof(int),1,fid);
     493
     494        /*writing a int array, type is 4 (see parseresultsfromdisk.m):*/
     495        type=4;
     496        fwrite(&type,sizeof(int),1,fid);
     497        rows=this->M;
     498        fwrite(&rows,sizeof(int),1,fid);
     499        cols=this->N;
     500        fwrite(&cols,sizeof(int),1,fid);
     501
     502        passiveInts=xNew<int>(this->M*this->N);
     503        for (i=0;i<this->M*this->N;i++)passiveInts[i]=reCast<int>(value[i]);
     504        fwrite(passiveInts,cols*rows*sizeof(int),1,fid);
     505        xDelete<int>(int);
     506
     507}
     508/*}}}*/
     509#endif
     510
    336511/*Specific instantiations for IssmPDouble*: */
    337512template <> inline GenericExternalResult<IssmPDouble*>::GenericExternalResult(int in_id, int in_enum_type,IssmPDouble* in_values, int in_M,int in_N,int in_step,IssmDouble in_time){/*{{{*/
Note: See TracChangeset for help on using the changeset viewer.