1 | /*!\file BoolExternalResult.c
|
---|
2 | * \brief: implementation of the BoolExternalResult object
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*header files: */
|
---|
6 | /*{{{1*/
|
---|
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 | /*BoolExternalResult constructors and destructor*/
|
---|
23 | /*FUNCTION BoolExternalResult::BoolExternalResult(){{{1*/
|
---|
24 | BoolExternalResult::BoolExternalResult(){
|
---|
25 | return;
|
---|
26 | }
|
---|
27 | /*}}}*/
|
---|
28 | /*FUNCTION BoolExternalResult::BoolExternalResult(int enum_type,bool value){{{1*/
|
---|
29 | BoolExternalResult::BoolExternalResult(int in_id, int in_enum_type,bool in_value,int in_step, double in_time){
|
---|
30 |
|
---|
31 | id=in_id;
|
---|
32 | enum_type=in_enum_type;
|
---|
33 | value=in_value;
|
---|
34 | step=in_step;
|
---|
35 | time=in_time;
|
---|
36 | }
|
---|
37 | /*}}}*/
|
---|
38 | /*FUNCTION BoolExternalResult::~BoolExternalResult(){{{1*/
|
---|
39 | BoolExternalResult::~BoolExternalResult(){
|
---|
40 | return;
|
---|
41 | }
|
---|
42 | /*}}}*/
|
---|
43 |
|
---|
44 | /*Object virtual functions definitions:*/
|
---|
45 | /*FUNCTION BoolExternalResult::Echo {{{1*/
|
---|
46 | void BoolExternalResult::Echo(void){
|
---|
47 | this->DeepEcho();
|
---|
48 | }
|
---|
49 | /*}}}*/
|
---|
50 | /*FUNCTION BoolExternalResult::DeepEcho{{{1*/
|
---|
51 | void BoolExternalResult::DeepEcho(void){
|
---|
52 |
|
---|
53 | printf("BoolExternalResult:\n");
|
---|
54 | printf(" id: %i\n",this->id);
|
---|
55 | printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
|
---|
56 | printf(" value: %s\n",this->value?"true":"false");
|
---|
57 | printf(" step: %i\n",this->step);
|
---|
58 | printf(" time: %g\n",this->time);
|
---|
59 | }
|
---|
60 | /*}}}*/
|
---|
61 | /*FUNCTION BoolExternalResult::Id{{{1*/
|
---|
62 | int BoolExternalResult::Id(void){ return -1; }
|
---|
63 | /*}}}*/
|
---|
64 | /*FUNCTION BoolExternalResult::MyRank{{{1*/
|
---|
65 | int BoolExternalResult::MyRank(void){
|
---|
66 | extern int my_rank;
|
---|
67 | return my_rank;
|
---|
68 | }
|
---|
69 | /*}}}*/
|
---|
70 | #ifdef _SERIAL_
|
---|
71 | /*FUNCTION BoolExternalResult::Marshall{{{1*/
|
---|
72 | void BoolExternalResult::Marshall(char** pmarshalled_dataset){
|
---|
73 |
|
---|
74 | char* marshalled_dataset=NULL;
|
---|
75 | int enum_value=0;
|
---|
76 |
|
---|
77 | /*recover marshalled_dataset: */
|
---|
78 | marshalled_dataset=*pmarshalled_dataset;
|
---|
79 |
|
---|
80 | /*get enum value of BoolExternalResult: */
|
---|
81 | enum_value=BoolExternalResultEnum;
|
---|
82 |
|
---|
83 | /*marshall enum: */
|
---|
84 | memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
|
---|
85 |
|
---|
86 | /*marshall BoolExternalResult data: */
|
---|
87 | memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
|
---|
88 | memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
|
---|
89 | memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
|
---|
90 | memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
|
---|
91 | memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
|
---|
92 |
|
---|
93 | *pmarshalled_dataset=marshalled_dataset;
|
---|
94 | }
|
---|
95 | /*}}}*/
|
---|
96 | /*FUNCTION BoolExternalResult::MarshallSize{{{1*/
|
---|
97 | int BoolExternalResult::MarshallSize(){
|
---|
98 |
|
---|
99 | return sizeof(value)+
|
---|
100 | +sizeof(id)
|
---|
101 | +sizeof(enum_type)
|
---|
102 | +sizeof(step)
|
---|
103 | +sizeof(time)
|
---|
104 | +sizeof(int); //sizeof(int) for enum value
|
---|
105 | }
|
---|
106 | /*}}}*/
|
---|
107 | /*FUNCTION BoolExternalResult::Demarshall{{{1*/
|
---|
108 | void BoolExternalResult::Demarshall(char** pmarshalled_dataset){
|
---|
109 |
|
---|
110 | char* marshalled_dataset=NULL;
|
---|
111 | int i;
|
---|
112 |
|
---|
113 | /*recover marshalled_dataset: */
|
---|
114 | marshalled_dataset=*pmarshalled_dataset;
|
---|
115 |
|
---|
116 | /*this time, no need to get enum type, the pointer directly points to the beginning of the
|
---|
117 | *object data (thanks to DataSet::Demarshall):*/
|
---|
118 | memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
|
---|
119 | memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
|
---|
120 | memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
|
---|
121 | memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
|
---|
122 | memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
|
---|
123 |
|
---|
124 | /*return: */
|
---|
125 | *pmarshalled_dataset=marshalled_dataset;
|
---|
126 | return;
|
---|
127 | }
|
---|
128 | /*}}}*/
|
---|
129 | #endif
|
---|
130 | /*FUNCTION BoolExternalResult::ObjectEnum{{{1*/
|
---|
131 | int BoolExternalResult::ObjectEnum(void){
|
---|
132 |
|
---|
133 | return BoolExternalResultEnum;
|
---|
134 |
|
---|
135 | }
|
---|
136 | /*}}}*/
|
---|
137 | /*FUNCTION BoolExternalResult::copy{{{1*/
|
---|
138 | Object* BoolExternalResult::copy() {
|
---|
139 |
|
---|
140 | return new BoolExternalResult(this->id,this->enum_type,this->value,this->step,this->time);
|
---|
141 |
|
---|
142 | }
|
---|
143 | /*}}}*/
|
---|
144 |
|
---|
145 | /*BoolExternalResult management: */
|
---|
146 | /*FUNCTION BoolExternalResult::WriteData{{{1*/
|
---|
147 | void BoolExternalResult::WriteData(FILE* fid,bool io_gather){
|
---|
148 |
|
---|
149 | int length;
|
---|
150 | int type;
|
---|
151 | int size;
|
---|
152 | double boolean;
|
---|
153 | extern int my_rank;
|
---|
154 | char* name = NULL;
|
---|
155 |
|
---|
156 | /*return if now on cpu 0: */
|
---|
157 | if(my_rank)return;
|
---|
158 |
|
---|
159 | /*First write enum: */
|
---|
160 | EnumToStringx(&name,this->enum_type);
|
---|
161 | length=(strlen(name)+1)*sizeof(char);
|
---|
162 | fwrite(&length,sizeof(int),1,fid);
|
---|
163 | fwrite(name,length,1,fid);
|
---|
164 | xfree((void**)&name);
|
---|
165 |
|
---|
166 | /*Now write time and step: */
|
---|
167 | fwrite(&time,sizeof(double),1,fid);
|
---|
168 | fwrite(&step,sizeof(int),1,fid);
|
---|
169 |
|
---|
170 | /*Now write bool, after casting it: */
|
---|
171 | boolean=(double)this->value;
|
---|
172 |
|
---|
173 | /*writing a double, type is 1, size is 1: */
|
---|
174 | type=1;
|
---|
175 | size=1;
|
---|
176 | fwrite(&type,sizeof(int),1,fid);
|
---|
177 | fwrite(&size,sizeof(int),1,fid);
|
---|
178 | fwrite(&boolean,size*sizeof(double),1,fid);
|
---|
179 |
|
---|
180 | }
|
---|
181 | /*}}}1*/
|
---|
182 | /*FUNCTION BoolExternalResult::GetResultName{{{1*/
|
---|
183 | void BoolExternalResult::GetResultName(char** pname){
|
---|
184 | EnumToStringx(pname,this->enum_type);
|
---|
185 | }
|
---|
186 | /*}}}*/
|
---|
187 | /*FUNCTION BoolExternalResult::SetMatlabField{{{1*/
|
---|
188 | #if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
|
---|
189 | void BoolExternalResult::SetMatlabField(mxArray* dataref){
|
---|
190 |
|
---|
191 | char* name=NULL;
|
---|
192 | this->GetResultName(&name);
|
---|
193 |
|
---|
194 | mxSetField( dataref, this->step-1, name,mxCreateDoubleScalar((double)value));
|
---|
195 | mxSetField( dataref, this->step-1, "time",mxCreateDoubleScalar((double)this->time));
|
---|
196 | mxSetField( dataref, this->step-1, "step",mxCreateDoubleScalar((double)this->step));
|
---|
197 | }
|
---|
198 | #endif
|
---|
199 | /*}}}*/
|
---|
200 | /*FUNCTION BoolExternalResult::GetStep{{{1*/
|
---|
201 | int BoolExternalResult::GetStep(void){
|
---|
202 |
|
---|
203 | return this->step;
|
---|
204 | }
|
---|
205 | /*}}}*/
|
---|