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,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){
|
---|
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<IssmPDouble>(M*N);
|
---|
39 | xMemCpy<IssmPDouble>(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<IssmPDouble>(this->values);
|
---|
51 | return;
|
---|
52 | }
|
---|
53 | /*}}}*/
|
---|
54 |
|
---|
55 | /*Object virtual functions definitions:*/
|
---|
56 | /*FUNCTION DoubleMatExternalResult::Echo {{{*/
|
---|
57 | void DoubleMatExternalResult::Echo(void){
|
---|
58 |
|
---|
59 | printf("DoubleMatExternalResult:\n");
|
---|
60 | printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
|
---|
61 | printf(" step: %i\n",this->step);
|
---|
62 | printf(" time: %g\n",this->time);
|
---|
63 | printf(" matrix size: %i-%i\n",this->M,this->N);
|
---|
64 |
|
---|
65 | }
|
---|
66 | /*}}}*/
|
---|
67 | /*FUNCTION DoubleMatExternalResult::DeepEcho{{{*/
|
---|
68 | void DoubleMatExternalResult::DeepEcho(void){
|
---|
69 |
|
---|
70 | int i,j;
|
---|
71 |
|
---|
72 | printf("DoubleMatExternalResult:\n");
|
---|
73 | printf(" id: %i\n",this->id);
|
---|
74 | printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
|
---|
75 | printf(" step: %i\n",this->step);
|
---|
76 | printf(" time: %g\n",this->time);
|
---|
77 | printf(" matrix size: %i-%i\n",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 |
|
---|
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 | }
|
---|
126 |
|
---|
127 | /*First write enum: */
|
---|
128 | EnumToStringx(&name,this->enum_type);
|
---|
129 | length=(strlen(name)+1)*sizeof(char);
|
---|
130 | fwrite(&length,sizeof(int),1,fid);
|
---|
131 | fwrite(name,length,1,fid);
|
---|
132 | xDelete<char>(name);
|
---|
133 |
|
---|
134 | /*Now write time and step: */
|
---|
135 | fwrite(&time,sizeof(IssmPDouble),1,fid);
|
---|
136 | fwrite(&step,sizeof(int),1,fid);
|
---|
137 |
|
---|
138 | /*writing a IssmPDouble array, type is 3:*/
|
---|
139 | type=3;
|
---|
140 | fwrite(&type,sizeof(int),1,fid);
|
---|
141 | rows=this->M;
|
---|
142 | fwrite(&rows,sizeof(int),1,fid);
|
---|
143 | cols=this->N;
|
---|
144 | fwrite(&cols,sizeof(int),1,fid);
|
---|
145 | fwrite(this->values,cols*rows*sizeof(IssmPDouble),1,fid);
|
---|
146 |
|
---|
147 | }
|
---|
148 | /*}}}*/
|
---|
149 | /*FUNCTION DoubleMatExternalResult::GetResultName{{{*/
|
---|
150 | void DoubleMatExternalResult::GetResultName(char** pname){
|
---|
151 | EnumToStringx(pname,this->enum_type);
|
---|
152 | }
|
---|
153 | /*}}}*/
|
---|
154 | /*FUNCTION DoubleMatExternalResult::GetStep{{{*/
|
---|
155 | int DoubleMatExternalResult::GetStep(void){
|
---|
156 |
|
---|
157 | return this->step;
|
---|
158 | }
|
---|
159 | /*}}}*/
|
---|