[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 | /*}}}*/
|
---|
[12465] | 28 | /*FUNCTION DoubleMatExternalResult::DoubleMatExternalResult(int in_id, int enum_type,IssmDoubleMat values,int M,int N,int in_step,IssmPDouble in_time){{{*/
|
---|
| 29 | DoubleMatExternalResult::DoubleMatExternalResult(int in_id, int in_enum_type,IssmPDouble* in_values, int in_M,int in_N,int in_step,IssmPDouble 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){
|
---|
[12465] | 38 | values=xNew<IssmPDouble>(M*N);
|
---|
| 39 | xMemCpy<IssmPDouble>(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 |
|
---|
[12465] | 50 | xDelete<IssmPDouble>(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;
|
---|
| 121 |
|
---|
[6389] | 122 | if(io_gather){
|
---|
| 123 | /*we are gathering the data on cpu 0, don't write on other cpus: */
|
---|
| 124 | if(my_rank) return;
|
---|
| 125 | }
|
---|
[4139] | 126 |
|
---|
| 127 | /*First write enum: */
|
---|
[11202] | 128 | EnumToStringx(&name,this->enum_type);
|
---|
[4139] | 129 | length=(strlen(name)+1)*sizeof(char);
|
---|
| 130 | fwrite(&length,sizeof(int),1,fid);
|
---|
| 131 | fwrite(name,length,1,fid);
|
---|
[12456] | 132 | xDelete<char>(name);
|
---|
[4139] | 133 |
|
---|
| 134 | /*Now write time and step: */
|
---|
[12465] | 135 | fwrite(&time,sizeof(IssmPDouble),1,fid);
|
---|
[4139] | 136 | fwrite(&step,sizeof(int),1,fid);
|
---|
| 137 |
|
---|
[12465] | 138 | /*writing a IssmPDouble array, type is 3:*/
|
---|
[4139] | 139 | type=3;
|
---|
| 140 | fwrite(&type,sizeof(int),1,fid);
|
---|
[4201] | 141 | rows=this->M;
|
---|
| 142 | fwrite(&rows,sizeof(int),1,fid);
|
---|
| 143 | cols=this->N;
|
---|
| 144 | fwrite(&cols,sizeof(int),1,fid);
|
---|
[12465] | 145 | fwrite(this->values,cols*rows*sizeof(IssmPDouble),1,fid);
|
---|
[4139] | 146 |
|
---|
| 147 | }
|
---|
[12365] | 148 | /*}}}*/
|
---|
| 149 | /*FUNCTION DoubleMatExternalResult::GetResultName{{{*/
|
---|
[11202] | 150 | void DoubleMatExternalResult::GetResultName(char** pname){
|
---|
| 151 | EnumToStringx(pname,this->enum_type);
|
---|
[4166] | 152 | }
|
---|
| 153 | /*}}}*/
|
---|
[12365] | 154 | /*FUNCTION DoubleMatExternalResult::GetStep{{{*/
|
---|
[4182] | 155 | int DoubleMatExternalResult::GetStep(void){
|
---|
| 156 |
|
---|
| 157 | return this->step;
|
---|
| 158 | }
|
---|
| 159 | /*}}}*/
|
---|