5 #ifndef _GENERIC_EXTERNAL_RESULT_
6 #define _GENERIC_EXTERNAL_RESULT_
12 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
17 #include "../../shared/shared.h"
20 template <
class ResultType>
35 _printf_(
" id : " << this->
id <<
"\n");
36 _printf_(
" result_name : " << this->result_name<<
"\n");
37 _printf_(
" step : " << this->step <<
"\n");
38 _printf_(
" time : " << this->time <<
"\n");
46 int length=(strlen(this->result_name)+1)*
sizeof(
char);
47 fwrite(&length,
sizeof(
int),1,fid);
48 fwrite(this->result_name,length,1,fid);
51 passiveDouble=reCast<IssmPDouble>(
time);
53 fwrite(&
step,
sizeof(
int),1,fid);
55 void GenericMarshall(
char** pmarshalled_data,
int* pmarshalled_data_size,
int marshall_direction){
72 if(
value) isnull=
false;
98 xMemCpy<IssmDouble>(
value,in_values,
M*
N);
107 _error_(
"template GenericExternalResult(int in_id, int in_enum_type,double* in_values, int in_M,int in_N,int in_step,IssmDouble in_time) not implemented for this ResultType\n");
143 this->result_name = xNew<char>(strlen(in_result_name)+1);
144 xMemCpy<char>(this->result_name,in_result_name,strlen(in_result_name)+1);
160 _error_(
"template DeepEcho not implemented for this ResultType\n");
167 _error_(
"template ObjectEnum not implemented for this ResultType\n");
169 void Marshall(
char** pmarshalled_data,
int* pmarshalled_data_size,
int marshall_direction){
170 _error_(
"not implemented yet!");
194 fwrite(&type,
sizeof(
int),1,fid);
195 fwrite(&size,
sizeof(
int),1,fid);
198 passiveDouble=reCast<IssmPDouble>(
value);
199 fwrite(&passiveDouble,size*
sizeof(
IssmPDouble),1,fid);
203 _error_(
"not implemented yet");
206 char* name = xNew<char>(strlen(this->result_name)+1);
207 xMemCpy<char>(name,this->result_name,strlen(this->result_name)+1);
218 _error_(
"not supported for this type of result");
222 _error_(
"not supported for this type of result");
229 _printf_(
"GenericExternalResult<bool>:\n");
231 _printf_(
" value: " <<(this->value?
"true":
"false") <<
"\n");
239 this->GenericMarshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
246 _printf_(
"GenericExternalResult<int>:\n");
248 _printf_(
" value: " << this->value <<
"\n");
256 this->GenericMarshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
263 _printf_(
"GenericExternalResult<double>:\n");
265 _printf_(
" value: " << this->value <<
"\n");
276 this->GenericMarshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
284 value = xNew<char>(strlen(in_value)+1);
285 xMemCpy<char>(value,in_value,(strlen(in_value)+1));
298 value = xNew<char>(strlen(in_value)+1);
299 xMemCpy<char>(value,in_value,(strlen(in_value)+1));
308 xDelete<char>(result_name);
309 xDelete<char>(value);
313 _printf_(
"GenericExternalResult<char*>:\n");
315 _printf_(
" value: " << this->value <<
"\n");
331 this->GenericWriteData(fid);
335 fwrite(&type,
sizeof(
int),1,fid);
337 length=(strlen(this->value)+1)*
sizeof(
char);
338 fwrite(&length,
sizeof(
int),1,fid);
339 fwrite(this->value,length,1,fid);
374 value=xNew<int>(M*N);
375 xMemCpy<int>(value,in_values,M*N);
387 this->result_name = xNew<char>(strlen(in_result_name)+1);
388 xMemCpy<char>(this->result_name,in_result_name,strlen(in_result_name)+1);
395 value=xNew<int>(M*N);
396 xMemCpy<int>(value,in_values,M*N);
402 _error_(
"you cannot initialize a GenericExternalResult<int*> without providing the dimensions of the matrix! Please use a more appropriate constructor!");
405 xDelete<char>(result_name);
410 _printf_(
"GenericExternalResult<int*>:\n");
412 _printf_(
" matrix size: " << this->M <<
"-" << this->N <<
"\n");
419 _printf_(
"GenericExternalResult<int*>:\n");
422 _printf_(
" matrix size: " << this->M <<
"-" << this->N <<
"\n");
423 for (i=0;i<this->M;i++){
425 for (j=0;j<this->N;j++){
426 _printf_(
" " << setw(11) << this->value[i*this->N+j]);
452 int length=(strlen(this->result_name)+1)*
sizeof(
char);
453 fwrite(&length,
sizeof(
int),1,fid);
454 fwrite(this->result_name,length,1,fid);
457 passiveDouble=reCast<IssmPDouble>(time);
459 fwrite(&step,
sizeof(
int),1,fid);
463 fwrite(&type,
sizeof(
int),1,fid);
465 fwrite(&rows,
sizeof(
int),1,fid);
467 fwrite(&cols,
sizeof(
int),1,fid);
468 fwrite(value,cols*rows*
sizeof(
int),1,fid);
503 value=xNew<IssmPDouble>(M*N);
504 xMemCpy<IssmPDouble>(value,in_values,M*N);
516 this->result_name = xNew<char>(strlen(in_result_name)+1);
517 xMemCpy<char>(this->result_name,in_result_name,strlen(in_result_name)+1);
524 value=xNew<IssmPDouble>(M*N);
525 xMemCpy<IssmPDouble>(value,in_values,M*N);
531 _error_(
"you cannot initialize a GenericExternalResult<IssmPDouble*> without providing the dimensions of the matrix! Please use a more appropriate constructor!");
534 xDelete<char>(result_name);
535 xDelete<IssmPDouble>(value);
539 _printf_(
"GenericExternalResult<IssmPDouble*>:\n");
541 _printf_(
" matrix size: " << this->M <<
"-" << this->N <<
"\n");
548 _printf_(
"GenericExternalResult<IssmPDouble*>:\n");
551 _printf_(
" matrix size: " << this->M <<
"-" << this->N <<
"\n");
552 for (i=0;i<this->M;i++){
554 for (j=0;j<this->N;j++){
555 _printf_(
" " << setw(11) << setprecision (5) << this->value[i*this->N+j]);
581 int length=(strlen(this->result_name)+1)*
sizeof(
char);
582 fwrite(&length,
sizeof(
int),1,fid);
583 fwrite(this->result_name,length,1,fid);
586 passiveDouble=reCast<IssmPDouble>(time);
588 fwrite(&step,
sizeof(
int),1,fid);
592 fwrite(&type,
sizeof(
int),1,fid);
594 fwrite(&rows,
sizeof(
int),1,fid);
596 fwrite(&cols,
sizeof(
int),1,fid);
626 for(
int i=0;i<M;i++){
627 for(
int j=0;j<N;j++){
628 temp[j*M+i] = value[i*N+j];
631 xDelete<IssmPDouble>(this->value);
645 #if defined(_HAVE_AD_) && !defined(_WRAPPERS_) //We hook off this specific specialization when not running ADOLC, otherwise we get a redeclaration with the next specialization.
647 xDelete<char>(result_name);
648 xDelete<IssmDouble>(value);
669 int length=(strlen(this->result_name)+1)*
sizeof(
char);
670 fwrite(&length,
sizeof(
int),1,fid);
671 fwrite(this->result_name,length,1,fid);
674 passiveDouble=reCast<IssmPDouble>(time);
676 fwrite(&step,
sizeof(
int),1,fid);
680 fwrite(&type,
sizeof(
int),1,fid);
682 fwrite(&rows,
sizeof(
int),1,fid);
684 fwrite(&cols,
sizeof(
int),1,fid);
686 passiveDoubles=xNew<IssmPDouble>(this->M*this->N);
687 for (i=0;i<this->M*this->N;i++)passiveDoubles[i]=reCast<IssmPDouble>(value[i]);
688 fwrite(passiveDoubles,cols*rows*
sizeof(
IssmPDouble),1,fid);
689 xDelete<IssmPDouble>(passiveDoubles);
697 _error_(
"instanciation not correct");
714 xDelete<char>(this->result_name);
719 _printf_(
"GenericExternalResult<Vector<IssmPDouble>*>:\n");
732 #if defined(_HAVE_AD_) && !defined(_WRAPPERS_) //We hook off this specific specialization when not running ADOLC, otherwise we get a redeclaration with the next specialization.
736 int length,rows,cols=1;
743 IssmPDouble* serialvalues = this->value->ToMPISerial0();
746 this->value->GetSize(&rows);
749 length=(strlen(this->result_name)+1)*
sizeof(
char);
750 fwrite(&length,
sizeof(
int),1,fid);
751 fwrite(this->result_name,length,1,fid);
754 IssmPDouble passiveDouble=reCast<IssmPDouble>(time);
756 fwrite(&step,
sizeof(
int),1,fid);
760 fwrite(&type,
sizeof(
int),1,fid);
761 fwrite(&rows,
sizeof(
int),1,fid);
762 fwrite(&cols,
sizeof(
int),1,fid);
763 fwrite(serialvalues,cols*rows*
sizeof(
IssmPDouble),1,fid);
767 xDelete<IssmPDouble>(serialvalues);
772 xDelete<char>(this->result_name);
786 int length,rows,cols=1;
795 serialvalues = this->value->ToMPISerial0();
800 this->value->GetSize(&rows);
801 pserialvalues=xNew<IssmPDouble>(rows);
802 for(i=0;i<rows;i++)pserialvalues[i]=reCast<IssmPDouble>(serialvalues[i]);
805 length=(strlen(this->result_name)+1)*
sizeof(
char);
806 fwrite(&length,
sizeof(
int),1,fid);
807 fwrite(this->result_name,length,1,fid);
810 IssmPDouble passiveDouble=reCast<IssmPDouble>(time);
812 fwrite(&step,
sizeof(
int),1,fid);
816 fwrite(&type,
sizeof(
int),1,fid);
817 fwrite(&rows,
sizeof(
int),1,fid);
818 fwrite(&cols,
sizeof(
int),1,fid);
819 fwrite(pserialvalues,cols*rows*
sizeof(
IssmPDouble),1,fid);
822 xDelete<IssmPDouble>(pserialvalues);
826 xDelete<IssmDouble>(serialvalues);
831 _error_(
"GenericExternalResult instantiated for type Vector<IssmDouble>* called " << result_name <<
" not implemented yet");