/*!\file IntExternalResult.c
 * \brief: implementation of the IntExternalResult object
 */

/*header files: */
/*{{{*/
#ifdef HAVE_CONFIG_H
	#include <config.h>
#else
#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
#endif

#include <stdio.h>
#include <string.h>
#include "../objects.h"
#include "../../EnumDefinitions/EnumDefinitions.h"
#include "../../shared/shared.h"
#include "../../Container/Container.h"
#include "../../include/include.h"
/*}}}*/

/*IntExternalResult constructors and destructor*/
/*FUNCTION IntExternalResult::IntExternalResult(){{{*/
IntExternalResult::IntExternalResult(){
	return;
}
/*}}}*/
/*FUNCTION IntExternalResult::IntExternalResult(int in_id, int in_enum_type,int in_value,int in_step, IssmDouble in_time){{{*/
IntExternalResult::IntExternalResult(int in_id, int in_enum_type,int in_value,int in_step, IssmDouble in_time){

	id=in_id;
	enum_type=in_enum_type;
	value=in_value;
	step=in_step;
	time=in_time;
}
/*}}}*/
/*FUNCTION IntExternalResult::~IntExternalResult(){{{*/
IntExternalResult::~IntExternalResult(){
	return;
}
/*}}}*/

/*Object virtual functions definitions:*/
/*FUNCTION IntExternalResult::Echo {{{*/
void IntExternalResult::Echo(void){
	this->DeepEcho();
}
/*}}}*/
/*FUNCTION IntExternalResult::DeepEcho{{{*/
void IntExternalResult::DeepEcho(void){

	_printLine_("IntExternalResult:");
	_printLine_("   id: " << this->id);
	_printLine_("   enum:  " << this->enum_type << " (" << EnumToStringx(this->enum_type) << ")");
	_printLine_("   value: " << this->value);
	_printLine_("   step: " << this->step);
	_printLine_("   time: " << this->time);
}
/*}}}*/
/*FUNCTION IntExternalResult::Id{{{*/
int    IntExternalResult::Id(void){ return -1; }
/*}}}*/
/*FUNCTION IntExternalResult::MyRank{{{*/
int    IntExternalResult::MyRank(void){ 
	extern int my_rank;
	return my_rank; 
}
/*}}}*/
/*FUNCTION IntExternalResult::ObjectEnum{{{*/
int IntExternalResult::ObjectEnum(void){

	return IntExternalResultEnum;

}
/*}}}*/
/*FUNCTION IntExternalResult::copy{{{*/
Object* IntExternalResult::copy() {
	
	return new IntExternalResult(this->id,this->enum_type,this->value,this->step,this->time);

}
/*}}}*/

/*IntExternalResult management: */
/*FUNCTION IntExternalResult::WriteData{{{*/
void   IntExternalResult::WriteData(FILE* fid,bool io_gather){

	int     length;
	int     type;
	int     size;
	char   *name    = NULL;
	IssmPDouble  passiveDouble;
	extern  int my_rank;

	/*return if now on cpu 0: */
	if(my_rank)return;

	/*First write enum: */
	EnumToStringx(&name,this->enum_type);
	length=(strlen(name)+1)*sizeof(char);
	fwrite(&length,sizeof(int),1,fid);
	fwrite(name,length,1,fid);
	xDelete<char>(name);

	/*Now write time and step: */
        passiveDouble=reCast<IssmPDouble>(time);
	fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
	fwrite(&step,sizeof(int),1,fid);

	/*writing a IssmPDouble, type is 1, size is 1: */
	type=1;
	size=1;
	fwrite(&type,sizeof(int),1,fid);
	fwrite(&size,sizeof(int),1,fid);
        /*cast to a IssmPDouble: */
        passiveDouble=reCast<IssmPDouble>(value);
	fwrite(&passiveDouble,size*sizeof(IssmPDouble),1,fid);

}
/*}}}*/
/*FUNCTION IntExternalResult::GetResultName{{{*/
void IntExternalResult::GetResultName(char** pname){
	EnumToStringx(pname,this->enum_type);
}
/*}}}*/
/*FUNCTION IntExternalResult::GetStep{{{*/
int IntExternalResult::GetStep(void){

	return this->step;
}
/*}}}*/
