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