[8600] | 1 | /*!\file IntMatParam.c
|
---|
| 2 | * \brief: implementation of the IntMatParam object
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*header files: */
|
---|
| 6 | /*{{{1*/
|
---|
| 7 | #ifdef HAVE_CONFIG_H
|
---|
[9320] | 8 | #include <config.h>
|
---|
[8600] | 9 | #else
|
---|
| 10 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[9320] | 13 | #include <stdio.h>
|
---|
[8600] | 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 | /*IntMatParam constructors and destructor*/
|
---|
| 23 | /*FUNCTION IntMatParam::IntMatParam(){{{1*/
|
---|
| 24 | IntMatParam::IntMatParam(){
|
---|
| 25 | return;
|
---|
| 26 | }
|
---|
| 27 | /*}}}*/
|
---|
| 28 | /*FUNCTION IntMatParam::IntMatParam(int enum_type,IssmIntMat value){{{1*/
|
---|
| 29 | IntMatParam::IntMatParam(int in_enum_type,int* in_value, int in_M,int in_N){
|
---|
| 30 |
|
---|
| 31 | enum_type=in_enum_type;
|
---|
| 32 | M=in_M;
|
---|
| 33 | N=in_N;
|
---|
| 34 |
|
---|
| 35 | value=(int*)xmalloc(M*N*sizeof(int));
|
---|
| 36 | memcpy(value,in_value,M*N*sizeof(int));
|
---|
| 37 | }
|
---|
| 38 | /*}}}*/
|
---|
| 39 | /*FUNCTION IntMatParam::~IntMatParam(){{{1*/
|
---|
| 40 | IntMatParam::~IntMatParam(){
|
---|
| 41 | xfree((void**)&value);
|
---|
| 42 | return;
|
---|
| 43 | }
|
---|
| 44 | /*}}}*/
|
---|
| 45 |
|
---|
| 46 | /*Object virtual functions definitions:*/
|
---|
| 47 | /*FUNCTION IntMatParam::Echo {{{1*/
|
---|
| 48 | void IntMatParam::Echo(void){
|
---|
| 49 |
|
---|
| 50 | printf("IntMatParam:\n");
|
---|
| 51 | printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
|
---|
| 52 | printf(" matrix size: %ix%i\n",this->M,this->N);
|
---|
| 53 |
|
---|
| 54 | }
|
---|
| 55 | /*}}}*/
|
---|
| 56 | /*FUNCTION IntMatParam::DeepEcho{{{1*/
|
---|
| 57 | void IntMatParam::DeepEcho(void){
|
---|
| 58 |
|
---|
| 59 | int i,j;
|
---|
| 60 |
|
---|
| 61 | printf("IntMatParam:\n");
|
---|
| 62 | printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
|
---|
| 63 | printf(" matrix size: %ix%i\n",this->M,this->N);
|
---|
| 64 | for(i=0;i<this->M;i++){
|
---|
| 65 | for(i=0;i<this->N;i++){
|
---|
[11197] | 66 | printf("(%i,%i) %i\n",i,j,*(this->value+N*i+j));
|
---|
[8600] | 67 | }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | /*}}}*/
|
---|
| 71 | /*FUNCTION IntMatParam::Id{{{1*/
|
---|
| 72 | int IntMatParam::Id(void){ return -1; }
|
---|
| 73 | /*}}}*/
|
---|
| 74 | /*FUNCTION IntMatParam::MyRank{{{1*/
|
---|
| 75 | int IntMatParam::MyRank(void){
|
---|
| 76 | extern int my_rank;
|
---|
| 77 | return my_rank;
|
---|
| 78 | }
|
---|
| 79 | /*}}}*/
|
---|
[11936] | 80 | #ifdef _SERIAL_
|
---|
[8600] | 81 | /*FUNCTION IntMatParam::Marshall{{{1*/
|
---|
| 82 | void IntMatParam::Marshall(char** pmarshalled_dataset){
|
---|
| 83 |
|
---|
| 84 | char* marshalled_dataset=NULL;
|
---|
| 85 | int enum_value=0;
|
---|
| 86 |
|
---|
| 87 | /*recover marshalled_dataset: */
|
---|
| 88 | marshalled_dataset=*pmarshalled_dataset;
|
---|
| 89 |
|
---|
| 90 | /*get enum value of IntMatParam: */
|
---|
| 91 | enum_value=IntMatParamEnum;
|
---|
| 92 |
|
---|
| 93 | /*marshall enum: */
|
---|
| 94 | memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
|
---|
| 95 |
|
---|
| 96 | /*marshall IntMatParam data: */
|
---|
| 97 | memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
|
---|
| 98 | memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
|
---|
| 99 | memcpy(marshalled_dataset,&N,sizeof(N));marshalled_dataset+=sizeof(N);
|
---|
| 100 | memcpy(marshalled_dataset,value,M*N*sizeof(int));marshalled_dataset+=M*N*sizeof(int);
|
---|
| 101 |
|
---|
| 102 | *pmarshalled_dataset=marshalled_dataset;
|
---|
| 103 | }
|
---|
| 104 | /*}}}*/
|
---|
| 105 | /*FUNCTION IntMatParam::MarshallSize{{{1*/
|
---|
| 106 | int IntMatParam::MarshallSize(){
|
---|
| 107 |
|
---|
| 108 | return sizeof(M)
|
---|
| 109 | +sizeof(N)
|
---|
| 110 | +M*N*sizeof(int)
|
---|
| 111 | +sizeof(enum_type)+
|
---|
| 112 | +sizeof(int); //sizeof(int) for enum value
|
---|
| 113 | }
|
---|
| 114 | /*}}}*/
|
---|
| 115 | /*FUNCTION IntMatParam::Demarshall{{{1*/
|
---|
| 116 | void IntMatParam::Demarshall(char** pmarshalled_dataset){
|
---|
| 117 |
|
---|
| 118 | char* marshalled_dataset=NULL;
|
---|
| 119 | int i;
|
---|
| 120 |
|
---|
| 121 | /*recover marshalled_dataset: */
|
---|
| 122 | marshalled_dataset=*pmarshalled_dataset;
|
---|
| 123 |
|
---|
| 124 | /*this time, no need to get enum type, the pointer directly points to the beginning of the
|
---|
| 125 | *object data (thanks to DataSet::Demarshall):*/
|
---|
| 126 | memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
|
---|
| 127 |
|
---|
| 128 | /*data: */
|
---|
| 129 | memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
|
---|
| 130 | memcpy(&N,marshalled_dataset,sizeof(N));marshalled_dataset+=sizeof(N);
|
---|
| 131 | value=(int*)xmalloc(M*N*sizeof(int));
|
---|
| 132 | memcpy(value,marshalled_dataset,M*N*sizeof(int));marshalled_dataset+=M*N*sizeof(int);
|
---|
| 133 |
|
---|
| 134 | /*return: */
|
---|
| 135 | *pmarshalled_dataset=marshalled_dataset;
|
---|
| 136 | return;
|
---|
| 137 | }
|
---|
| 138 | /*}}}*/
|
---|
[9777] | 139 | #endif
|
---|
[9883] | 140 | /*FUNCTION IntMatParam::ObjectEnum{{{1*/
|
---|
| 141 | int IntMatParam::ObjectEnum(void){
|
---|
[8600] | 142 |
|
---|
| 143 | return IntMatParamEnum;
|
---|
| 144 |
|
---|
| 145 | }
|
---|
| 146 | /*}}}*/
|
---|
| 147 | /*FUNCTION IntMatParam::copy{{{1*/
|
---|
| 148 | Object* IntMatParam::copy() {
|
---|
| 149 |
|
---|
| 150 | return new IntMatParam(this->enum_type,this->value,this->M,this->N);
|
---|
| 151 |
|
---|
| 152 | }
|
---|
| 153 | /*}}}*/
|
---|
| 154 |
|
---|
| 155 | /*IntMatParam virtual functions definitions: */
|
---|
| 156 | /*FUNCTION IntMatParam::GetParameterValue{{{1*/
|
---|
| 157 | void IntMatParam::GetParameterValue(int** pintarray,int* pM,int* pN){
|
---|
| 158 | int* output=NULL;
|
---|
| 159 |
|
---|
| 160 | output=(int*)xmalloc((int)(M*N*sizeof(int)));
|
---|
| 161 | memcpy(output,value,M*N*sizeof(int));
|
---|
| 162 |
|
---|
| 163 | /*Assign output pointers:*/
|
---|
| 164 | if(pM) *pM=M;
|
---|
| 165 | if(pN) *pN=N;
|
---|
| 166 | *pintarray=output;
|
---|
| 167 | }
|
---|
| 168 | /*}}}*/
|
---|
| 169 | /*FUNCTION IntMatParam::GetParameterName{{{1*/
|
---|
[11202] | 170 | void IntMatParam::GetParameterName(char**pname){
|
---|
| 171 | EnumToStringx(pname,this->enum_type);
|
---|
[8600] | 172 | }
|
---|
| 173 | /*}}}*/
|
---|
| 174 | /*FUNCTION IntMatParam::SetValue{{{1*/
|
---|
| 175 | void IntMatParam::SetValue(int* intarray,int in_M,int in_N){
|
---|
| 176 |
|
---|
| 177 | /*avoid leak: */
|
---|
| 178 | xfree((void**)&this->value);
|
---|
| 179 |
|
---|
| 180 | this->value=(int*)xmalloc(in_M*in_N*sizeof(int));
|
---|
| 181 | memcpy(this->value,intarray,in_M*in_N*sizeof(int));
|
---|
| 182 |
|
---|
| 183 | this->M=in_M;
|
---|
| 184 | this->N=in_N;
|
---|
| 185 | }
|
---|
| 186 | /*}}}*/
|
---|
[9356] | 187 | /*FUNCTION IntMatParam::UnitConversion{{{1*/
|
---|
| 188 | void IntMatParam::UnitConversion(int direction_enum){
|
---|
| 189 | /*do nothing, no unit conversion*/
|
---|
| 190 | }
|
---|
| 191 | /*}}}*/
|
---|