[4139] | 1 | /*!\file DoubleMatExternalResult.c
|
---|
| 2 | * \brief: implementation of the DoubleMatExternalResult object
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*header files: */
|
---|
[12365] | 6 | /*{{{*/
|
---|
[4139] | 7 | #ifdef HAVE_CONFIG_H
|
---|
[9320] | 8 | #include <config.h>
|
---|
[4139] | 9 | #else
|
---|
| 10 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[9320] | 13 | #include <stdio.h>
|
---|
[4139] | 14 | #include <string.h>
|
---|
| 15 | #include "../objects.h"
|
---|
| 16 | #include "../../EnumDefinitions/EnumDefinitions.h"
|
---|
| 17 | #include "../../shared/shared.h"
|
---|
[4236] | 18 | #include "../../Container/Container.h"
|
---|
[4139] | 19 | #include "../../include/include.h"
|
---|
| 20 | /*}}}*/
|
---|
| 21 |
|
---|
[4248] | 22 | /*DoubleMatExternalResult constructors and destructor*/
|
---|
[12365] | 23 | /*FUNCTION DoubleMatExternalResult::DoubleMatExternalResult(){{{*/
|
---|
[4139] | 24 | DoubleMatExternalResult::DoubleMatExternalResult(){
|
---|
| 25 | return;
|
---|
| 26 | }
|
---|
| 27 | /*}}}*/
|
---|
[12562] | 28 | /*FUNCTION DoubleMatExternalResult::DoubleMatExternalResult(int in_id, int enum_type,IssmDoubleMat values,int M,int N,int in_step,IssmDouble in_time){{{*/
|
---|
| 29 | DoubleMatExternalResult::DoubleMatExternalResult(int in_id, int in_enum_type,IssmDouble* in_values, int in_M,int in_N,int in_step,IssmDouble in_time){
|
---|
[4139] | 30 |
|
---|
| 31 | id=in_id;
|
---|
| 32 | enum_type=in_enum_type;
|
---|
| 33 | M=in_M;
|
---|
| 34 | N=in_N;
|
---|
| 35 |
|
---|
[4191] | 36 | /*Copy result in values*/
|
---|
[4195] | 37 | if(M*N){
|
---|
[12562] | 38 | values=xNew<IssmDouble>(M*N);
|
---|
| 39 | xMemCpy<IssmDouble>(values,in_values,M*N);
|
---|
[4195] | 40 | }
|
---|
| 41 | else values=NULL;
|
---|
[4139] | 42 |
|
---|
| 43 | step=in_step;
|
---|
| 44 | time=in_time;
|
---|
| 45 | }
|
---|
| 46 | /*}}}*/
|
---|
[12365] | 47 | /*FUNCTION DoubleMatExternalResult::~DoubleMatExternalResult(){{{*/
|
---|
[4139] | 48 | DoubleMatExternalResult::~DoubleMatExternalResult(){
|
---|
[4195] | 49 |
|
---|
[12562] | 50 | xDelete<IssmDouble>(this->values);
|
---|
[4139] | 51 | return;
|
---|
| 52 | }
|
---|
| 53 | /*}}}*/
|
---|
| 54 |
|
---|
[4248] | 55 | /*Object virtual functions definitions:*/
|
---|
[12365] | 56 | /*FUNCTION DoubleMatExternalResult::Echo {{{*/
|
---|
[4248] | 57 | void DoubleMatExternalResult::Echo(void){
|
---|
[4139] | 58 |
|
---|
[12511] | 59 | _printLine_("DoubleMatExternalResult:");
|
---|
| 60 | _printLine_(" enum: " << this->enum_type << " (" << EnumToStringx(this->enum_type) << ")");
|
---|
| 61 | _printLine_(" step: " << this->step);
|
---|
| 62 | _printLine_(" time: " << this->time);
|
---|
| 63 | _printLine_(" matrix size: " << this->M << "-" << this->N);
|
---|
[4248] | 64 |
|
---|
[4139] | 65 | }
|
---|
| 66 | /*}}}*/
|
---|
[12365] | 67 | /*FUNCTION DoubleMatExternalResult::DeepEcho{{{*/
|
---|
[4139] | 68 | void DoubleMatExternalResult::DeepEcho(void){
|
---|
| 69 |
|
---|
[4201] | 70 | int i,j;
|
---|
[4139] | 71 |
|
---|
[12511] | 72 | _printLine_("DoubleMatExternalResult:");
|
---|
| 73 | _printLine_(" id: " << this->id);
|
---|
| 74 | _printLine_(" enum: " << this->enum_type << " (" << EnumToStringx(this->enum_type) << ")");
|
---|
| 75 | _printLine_(" step: " << this->step);
|
---|
| 76 | _printLine_(" time: " << this->time);
|
---|
| 77 | _printLine_(" matrix size: " << this->M << "-" << this->N);
|
---|
[4201] | 78 | for (i=0;i<this->M;i++){
|
---|
[12507] | 79 | _printString_(" [ ");
|
---|
[4201] | 80 | for (j=0;j<this->N;j++){
|
---|
[12507] | 81 | _printString_( " " << setw(11) << setprecision (5) << this->values[i*this->N+j]);
|
---|
[4201] | 82 | }
|
---|
[12507] | 83 | _printLine_(" ]");
|
---|
[4201] | 84 | }
|
---|
| 85 |
|
---|
[4139] | 86 | }
|
---|
| 87 | /*}}}*/
|
---|
[12365] | 88 | /*FUNCTION DoubleMatExternalResult::Id{{{*/
|
---|
[4248] | 89 | int DoubleMatExternalResult::Id(void){ return -1; }
|
---|
[4139] | 90 | /*}}}*/
|
---|
[12365] | 91 | /*FUNCTION DoubleMatExternalResult::MyRank{{{*/
|
---|
[4248] | 92 | int DoubleMatExternalResult::MyRank(void){
|
---|
| 93 | extern int my_rank;
|
---|
| 94 | return my_rank;
|
---|
[4139] | 95 | }
|
---|
| 96 | /*}}}*/
|
---|
[12365] | 97 | /*FUNCTION DoubleMatExternalResult::ObjectEnum{{{*/
|
---|
[9883] | 98 | int DoubleMatExternalResult::ObjectEnum(void){
|
---|
[4139] | 99 |
|
---|
[4248] | 100 | return DoubleMatExternalResultEnum;
|
---|
| 101 |
|
---|
| 102 | }
|
---|
| 103 | /*}}}*/
|
---|
[12365] | 104 | /*FUNCTION DoubleMatExternalResult::copy{{{*/
|
---|
[4248] | 105 | Object* DoubleMatExternalResult::copy() {
|
---|
| 106 |
|
---|
| 107 | return new DoubleMatExternalResult(this->id,this->enum_type,this->values,this->M,this->N,this->step,this->time);
|
---|
| 108 |
|
---|
| 109 | }
|
---|
| 110 | /*}}}*/
|
---|
| 111 |
|
---|
| 112 | /*DoubleMatExternalResult management: */
|
---|
[12365] | 113 | /*FUNCTION DoubleMatExternalResult::WriteData{{{*/
|
---|
[6389] | 114 | void DoubleMatExternalResult::WriteData(FILE* fid,bool io_gather){
|
---|
[4139] | 115 |
|
---|
| 116 | int length;
|
---|
| 117 | int type;
|
---|
[4201] | 118 | int rows,cols;
|
---|
[4139] | 119 | char *name = NULL;
|
---|
| 120 | extern int my_rank;
|
---|
[12562] | 121 | IssmPDouble *passiveDouble_p=NULL;
|
---|
| 122 | IssmPDouble passiveDouble;
|
---|
[4139] | 123 |
|
---|
[6389] | 124 | if(io_gather){
|
---|
| 125 | /*we are gathering the data on cpu 0, don't write on other cpus: */
|
---|
| 126 | if(my_rank) return;
|
---|
| 127 | }
|
---|
[4139] | 128 |
|
---|
[12562] | 129 | passiveDouble_p=xNew<IssmPDouble>(M*N);
|
---|
| 130 |
|
---|
[4139] | 131 | /*First write enum: */
|
---|
[11202] | 132 | EnumToStringx(&name,this->enum_type);
|
---|
[4139] | 133 | length=(strlen(name)+1)*sizeof(char);
|
---|
| 134 | fwrite(&length,sizeof(int),1,fid);
|
---|
| 135 | fwrite(name,length,1,fid);
|
---|
[12456] | 136 | xDelete<char>(name);
|
---|
[4139] | 137 |
|
---|
| 138 | /*Now write time and step: */
|
---|
[12562] | 139 | passiveDouble=reCast<IssmPDouble>(time);
|
---|
| 140 | fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
|
---|
[4139] | 141 | fwrite(&step,sizeof(int),1,fid);
|
---|
| 142 |
|
---|
[12562] | 143 | /*writing a IssmDouble array, type is 3:*/
|
---|
[4139] | 144 | type=3;
|
---|
| 145 | fwrite(&type,sizeof(int),1,fid);
|
---|
[4201] | 146 | rows=this->M;
|
---|
| 147 | fwrite(&rows,sizeof(int),1,fid);
|
---|
| 148 | cols=this->N;
|
---|
| 149 | fwrite(&cols,sizeof(int),1,fid);
|
---|
[12562] | 150 | for (int i=0; i<N*M; ++i) passiveDouble_p[i]=reCast<IssmPDouble>(values[i]);
|
---|
| 151 | fwrite(passiveDouble_p,cols*rows*sizeof(IssmPDouble),1,fid);
|
---|
| 152 | xDelete(passiveDouble_p);
|
---|
[4139] | 153 |
|
---|
| 154 | }
|
---|
[12365] | 155 | /*}}}*/
|
---|
| 156 | /*FUNCTION DoubleMatExternalResult::GetResultName{{{*/
|
---|
[11202] | 157 | void DoubleMatExternalResult::GetResultName(char** pname){
|
---|
| 158 | EnumToStringx(pname,this->enum_type);
|
---|
[4166] | 159 | }
|
---|
| 160 | /*}}}*/
|
---|
[12365] | 161 | /*FUNCTION DoubleMatExternalResult::GetStep{{{*/
|
---|
[4182] | 162 | int DoubleMatExternalResult::GetStep(void){
|
---|
| 163 |
|
---|
| 164 | return this->step;
|
---|
| 165 | }
|
---|
| 166 | /*}}}*/
|
---|