Ice Sheet System Model  4.18
Code documentation
DoubleMatArrayParam.cpp
Go to the documentation of this file.
1 
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 "../classes.h"
14 #include "shared/shared.h"
15 /*}}}*/
16 
17 /*DoubleMatArrayParam constructors and destructor*/
19  return;
20 }
21 /*}}}*/
22 DoubleMatArrayParam::DoubleMatArrayParam(int in_enum_type,IssmDouble** in_array, int in_M, int* in_mdim_array, int* in_ndim_array){/*{{{*/
23 
24  int i;
25  IssmDouble* matrix=NULL;
26  int m,n;
27 
28  enum_type=in_enum_type;
29  M=in_M;
30  if(M){
31  array=xNew<IssmDouble*>(M);
32  mdim_array=xNew<int>(M);
33  ndim_array=xNew<int>(M);
34 
35  for(i=0;i<M;i++){
36  m=in_mdim_array[i];
37  n=in_ndim_array[i];
38 
39  mdim_array[i]=m;
40  ndim_array[i]=n;
41 
42  if(m*n){
43  matrix=xNew<IssmDouble>(m*n);
44  xMemCpy<IssmDouble>(matrix,in_array[i],m*n);
45  }
46  else{
47  matrix=NULL;
48  }
49  array[i]=matrix;
50  }
51  }
52  else{
53  array=NULL;
54  mdim_array=NULL;
55  ndim_array=NULL;
56  }
57 }
58 /*}}}*/
60 
61  int i;
62  IssmDouble* matrix=NULL;
63 
64  xDelete<int>(mdim_array);
65  xDelete<int>(ndim_array);
66 
67  for(i=0;i<M;i++){
68  matrix=array[i];
69  xDelete<IssmDouble>(matrix);
70  }
71 
72  xDelete<IssmDouble*>(array);
73  return;
74 }
75 /*}}}*/
76 
77 /*Object virtual functions definitions:*/
79 
80  return new DoubleMatArrayParam(this->enum_type,this->array, this->M, this->mdim_array,this->ndim_array);
81 
82 }
83 /*}}}*/
85 
86  int i,j,k;
87  int m,n;
88  IssmDouble* matrix=NULL;
89 
90  _printf_("DoubleMatArrayParam:\n");
91  _printf_(" enum: " << this->enum_type << " (" << EnumToStringx(this->enum_type) << ")\n");
92  _printf_(" array size: " << this->M << "\n");
93  for(i=0;i<M;i++){
94  _printf_(" array " << i << " (" << mdim_array[i] << "x" << ndim_array[i] << "):\n");
95  matrix=array[i];
96  m=mdim_array[i];
97  n=ndim_array[i];
98 
99  for(j=0;j<m;j++){
100  _printf_(" ");
101  for(k=0;k<n;k++)_printf_(*(matrix+n*j+k) << " ");
102  _printf_("\n");
103  }
104  }
105 }
106 /*}}}*/
107 void DoubleMatArrayParam::Echo(void){/*{{{*/
108 
109  _printf_("DoubleMatArrayParam:\n");
110  _printf_(" enum: " << this->enum_type << " (" << EnumToStringx(this->enum_type) << ")\n");
111  _printf_(" array size: " << this->M << "\n");
112  _printf_(" array pointer: " << this->array << "\n");
113 
114 }
115 /*}}}*/
116 int DoubleMatArrayParam::Id(void){ return -1; }/*{{{*/
117 /*}}}*/
118 void DoubleMatArrayParam::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
119 
121 
123  MARSHALLING(M);
124  if(M){
127  if(marshall_direction==MARSHALLING_BACKWARD && M) array=xNew<IssmDouble*>(M);
128  for(int i=0;i<M;i++){
130  }
131  }
132  else{
133  array=NULL;
134  mdim_array=NULL;
135  ndim_array=NULL;
136  }
137 
138 }
139 /*}}}*/
141 
143 
144 }
145 /*}}}*/
146 
147 /*DoubleMatArrayParam virtual functions definitions: */
148 void DoubleMatArrayParam::GetParameterValue(IssmDouble*** pout_array, int* pout_M,int** pout_mdim_array, int** pout_ndim_array){/*{{{*/
149 
150  int i,m,n;
151  IssmDouble* matrix=NULL;
152  IssmDouble* out_matrix=NULL;
153 
154  /*output: */
155  IssmDouble** out_array=NULL;
156  int out_M;
157  int* out_mdim_array=NULL;
158  int* out_ndim_array=NULL;
159 
160  out_M=this->M;
161  if(out_M){
162  out_array=xNew<IssmDouble*>(M);
163  out_mdim_array=xNew<int>(M);
164  out_ndim_array=xNew<int>(M);
165 
166  xMemCpy<int>(out_mdim_array,this->mdim_array,M);
167  xMemCpy<int>(out_ndim_array,this->ndim_array,M);
168 
169  for(i=0;i<this->M;i++){
170  matrix=this->array[i];
171  m=this->mdim_array[i];
172  n=this->ndim_array[i];
173 
174  if(m*n){
175  out_matrix=xNew<IssmDouble>(m*n);
176  xMemCpy<IssmDouble>(out_matrix,matrix,m*n);
177  }
178  else{
179  out_matrix=NULL;
180  }
181  out_array[i]=out_matrix;
182  }
183  }
184  else{
185  out_array=NULL;
186  out_matrix=NULL;
187  out_ndim_array=NULL;
188  }
189 
190  /*Assign output pointers:*/
191  if(pout_M) *pout_M=out_M;
192  if(pout_mdim_array) *pout_mdim_array=out_mdim_array;
193  if(pout_ndim_array) *pout_ndim_array=out_ndim_array;
194  *pout_array=out_array;
195 
196 }
197 /*}}}*/
198 void DoubleMatArrayParam::SetValue(IssmDouble** in_array, int in_M, int* in_mdim_array, int* in_ndim_array){/*{{{*/
199 
200  int i,m,n;
201  IssmDouble* in_matrix=NULL;
202  IssmDouble* matrix=NULL;
203 
204  /*avoid leak: */
205  xDelete<int>(mdim_array);
206  xDelete<int>(ndim_array);
207  for(i=0;i<M;i++){
208  matrix=array[i];
209  xDelete<IssmDouble>(matrix);
210  }
211  xDelete<IssmDouble*>(array);
212 
213  /*copy data: */
214  this->M=in_M;
215  this->array=xNew<IssmDouble*>(M);
216  this->mdim_array=xNew<int>(M);
217  this->ndim_array=xNew<int>(M);
218 
219  xMemCpy<int>(this->mdim_array,in_mdim_array,M);
220  xMemCpy<int>(this->ndim_array,in_ndim_array,M);
221 
222  for(i=0;i<M;i++){
223  in_matrix=in_array[i];
224  m=in_mdim_array[i];
225  n=in_ndim_array[i];
226 
227  matrix=xNew<IssmDouble>(m*n);
228  xMemCpy<IssmDouble>(matrix,in_matrix,m*n);
229 
230  this->array[i]=matrix;
231  }
232 
233 }
234 /*}}}*/
DoubleMatArrayParam::DeepEcho
void DeepEcho()
Definition: DoubleMatArrayParam.cpp:84
IssmDouble
double IssmDouble
Definition: types.h:37
Param
Definition: Param.h:21
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
DoubleMatArrayParam::array
IssmDouble ** array
Definition: DoubleMatArrayParam.h:24
DoubleMatArrayParam::ObjectEnum
int ObjectEnum()
Definition: DoubleMatArrayParam.cpp:140
DoubleMatArrayParam::~DoubleMatArrayParam
~DoubleMatArrayParam()
Definition: DoubleMatArrayParam.cpp:59
DoubleMatArrayParam::Id
int Id()
Definition: DoubleMatArrayParam.cpp:116
DoubleMatArrayParam::SetValue
void SetValue(bool boolean)
Definition: DoubleMatArrayParam.h:62
MARSHALLING_DYNAMIC
#define MARSHALLING_DYNAMIC(FIELD, TYPE, SIZE)
Definition: Marshalling.h:61
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
MARSHALLING
#define MARSHALLING(FIELD)
Definition: Marshalling.h:29
DoubleMatArrayParam::mdim_array
int * mdim_array
Definition: DoubleMatArrayParam.h:26
MARSHALLING_BACKWARD
@ MARSHALLING_BACKWARD
Definition: Marshalling.h:10
DoubleMatArrayParamEnum
@ DoubleMatArrayParamEnum
Definition: EnumDefinitions.h:1044
DoubleMatArrayParam::enum_type
int enum_type
Definition: DoubleMatArrayParam.h:23
DoubleMatArrayParam::DoubleMatArrayParam
DoubleMatArrayParam()
Definition: DoubleMatArrayParam.cpp:18
DoubleMatArrayParam::M
int M
Definition: DoubleMatArrayParam.h:25
DoubleMatArrayParam::copy
Param * copy()
Definition: DoubleMatArrayParam.cpp:78
DoubleMatArrayParam::Echo
void Echo()
Definition: DoubleMatArrayParam.cpp:107
shared.h
DoubleMatArrayParam::GetParameterValue
void GetParameterValue(bool *pbool)
Definition: DoubleMatArrayParam.h:44
DoubleMatArrayParam::ndim_array
int * ndim_array
Definition: DoubleMatArrayParam.h:27
DoubleMatArrayParam::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: DoubleMatArrayParam.cpp:118