00001 /* 00002 * $Id$ 00003 * 00004 * Author: David Fournier 00005 * Copyright (c) 2008-2012 Regents of the University of California 00006 */ 00011 #include <fvar.hpp> 00012 00013 #ifdef __TURBOC__ 00014 #pragma hdrstop 00015 #include <iostream.h> 00016 #endif 00017 00018 #ifdef __ZTC__ 00019 #include <iostream.hpp> 00020 #endif 00021 00022 #include <string.h> 00023 00028 void save_double_derivative(const double x, const prevariable_position& _pos) 00029 { 00030 prevariable_position& pos= (prevariable_position&) _pos; 00031 // adds the derivative value in a double to a prevariables' guts 00032 pos.xval()+=x; 00033 } 00034 00039 prevariable_position restore_prevariable_position(void) 00040 { 00041 double_and_int* tmp; 00042 gradient_structure::get_fp()->fread(&tmp, sizeof(double_and_int*)); 00043 return prevariable_position(tmp); 00044 } 00045 00050 void prevariable::save_prevariable_position() const 00051 { 00052 double_and_int* tmp = get_v(); 00053 size_t wsize = sizeof(double_and_int*); 00054 gradient_structure::get_fp()->fwrite(&tmp, wsize); 00055 } 00056 00061 void prevariable::save_prevariable_value(void) const 00062 { 00063 //double_and_int * tmp=get_v(); 00064 //const unsigned wsize=sizeof(double_and_int*); 00065 //gradient_structure::get_fp()->fwrite(&tmp,wsize); 00066 double x=value(*this); 00067 //const unsigned dsize=sizeof(double); 00068 gradient_structure::get_fp()->fwrite(x); 00069 } 00070 00075 void save_double_value(const double x) 00076 { 00077 //const unsigned wsize=sizeof(double); 00078 gradient_structure::get_fp()->fwrite(x); 00079 } 00080 00085 void save_int_value( int x) 00086 { 00087 //const unsigned wsize=sizeof(double); 00088 gradient_structure::get_fp()->fwrite(x); 00089 } 00090 00095 void save_pointer_value(void *ptr) 00096 { 00097 gradient_structure::get_fp()->fwrite(ptr); 00098 } 00099 00104 double restore_prevariable_derivative(const prevariable_position& _pos) 00105 { 00106 prevariable_position& pos= (prevariable_position&) _pos; 00107 double tmpout=pos.xval(); 00108 pos.xval()=0.0; 00109 return tmpout; 00110 } 00111 00116 double restore_prevariable_derivative(void) 00117 { 00118 // Back up the stream and read the number of bytes written in the 00119 // ``write function'' corresponding to this ``read function'' 00120 double_and_int* tmp; 00121 gradient_structure::get_fp()->fread(&tmp,sizeof(double_and_int *)); 00122 double tmpout=tmp->x; 00123 tmp->x=0.0; 00124 return tmpout; 00125 } 00126 00131 double restore_prevariable_value(void) 00132 { 00133 // Back up the stream and read the number of bytes written in the 00134 // ``write function'' corresponding to this ``read function'' 00135 double tmpout = 0; 00136 gradient_structure::get_fp()->fread(&tmpout,sizeof(double)); 00137 return tmpout; 00138 } 00139 00144 double restore_double_value(void) 00145 { 00146 double tmpout = 0; 00147 gradient_structure::get_fp()->fread(tmpout); 00148 return tmpout; 00149 } 00150 00155 int restore_int_value(void) 00156 { 00157 int tmpout = 0; 00158 gradient_structure::get_fp()->fread(tmpout); 00159 return tmpout; 00160 } 00161 00166 void* restore_pointer_value(void) 00167 { 00168 void* tmpout = NULL; 00169 gradient_structure::get_fp()->fread(tmpout); 00170 return tmpout; 00171 }
Generated on Tue Mar 8 2016 19:51:30 for ADMB Documentation by 1.8.0 |