00001 /* 00002 * $Id: def_eval.cpp 542 2012-07-10 21:04:06Z johnoel $ 00003 * 00004 * Author: David Fournier 00005 * Copyright (c) 2008-2012 Regents of the University of California 00006 */ 00011 #include "fvar.hpp" 00012 00013 #include <sys/stat.h> 00014 #include <fcntl.h> 00015 #include <string.h> 00016 00017 #ifdef __TURBOC__ 00018 #pragma hdrstop 00019 #include <iostream.h> 00020 #endif 00021 00022 #ifdef __ZTC__ 00023 #include <iostream.hpp> 00024 #endif 00025 00026 00027 #include <stdio.h> 00028 #include <stdlib.h> 00029 00030 #ifdef __SUN__ 00031 #include <iostream.h> 00032 #include <fcntl.h> 00033 #include <sys/stat.h> 00034 #include <sys/types.h> 00035 #ifndef __MSVC32__ 00036 #include <unistd.h> 00037 #endif 00038 #endif 00039 00040 #ifdef __GNU__ 00041 #if (__GNUC__ >3) 00042 #include <iostream> 00043 using namespace std; 00044 #else 00045 #include <iostream.h> 00046 #endif 00047 #include <fcntl.h> 00048 #include <sys/stat.h> 00049 #include <sys/types.h> 00050 #include <unistd.h> 00051 #endif 00052 00053 #ifdef __MSVC32__ 00054 #define lseek _lseek 00055 #define read _read 00056 #define write _write 00057 #endif 00058 00059 #if defined (__WAT32__) 00060 #include <io.h> 00061 #include <fcntl.h> 00062 #endif 00063 00064 #include <math.h> 00065 #define XXX 3.70255042e-17 00066 00067 //ofstream gradlog("grad.log"); 00068 00073 void default_evaluation(void) 00074 { 00075 // checks to see how many independent variables there are 00076 grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00077 double * zptr = grad_ptr->dep_addr; 00078 double z = *zptr; 00079 *zptr = 0; 00080 // Check to see if first independent variable is a NULL adress 00081 if ( grad_ptr->ind_addr1 ) 00082 { 00083 * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ; 00084 //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00085 //if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16) 00086 // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00087 #if defined(USE_DDOUBLE) 00088 if ( grad_ptr->mult2 !=0) 00089 #else 00090 if ( grad_ptr->mult2) 00091 #endif 00092 { 00093 * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ; 00094 //gradlog << setprecision(13) << * grad_ptr->ind_addr2 << endl; 00095 //if (fabs(* grad_ptr->ind_addr2+XXX)<1.e-16) 00096 // cout << setprecision(13) << * grad_ptr->ind_addr2 << endl; 00097 } 00098 } 00099 } 00100 00105 void default_evaluation1(void) 00106 { 00107 // there is one independent variable 00108 grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00109 double z = * grad_ptr->dep_addr; 00110 * grad_ptr->dep_addr=0.; 00111 * grad_ptr->ind_addr1 += z; 00112 //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00113 // if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16) 00114 // cout << setscientific() << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00115 } 00116 00121 void default_evaluation1m(void) 00122 { 00123 // there is one independent variable 00124 grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00125 double z = * grad_ptr->dep_addr; 00126 * grad_ptr->dep_addr=0.; 00127 * grad_ptr->ind_addr1 -= z; 00128 //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00129 // if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16) 00130 // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00131 } 00132 00137 void default_evaluation0(void) 00138 { 00139 // there is one independent variable 00140 * gradient_structure::GRAD_STACK1->ptr->dep_addr=0.; 00141 } 00142 00147 void default_evaluation2(void) 00148 { 00149 //char ch; 00150 // there is one independent variable 00151 grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00152 //cout << setprecision(16) << *grad_ptr->dep_addr << endl; 00153 //cout << setprecision(16) << *grad_ptr->ind_addr1 << endl; 00154 //cout << setprecision(16) << grad_ptr->mult1 << endl; 00155 //cin >> ch; 00156 double z = * grad_ptr->dep_addr; 00157 * grad_ptr->dep_addr=0.; 00158 * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ; 00159 //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00160 // if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16) 00161 // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00162 } 00163 00168 void default_evaluation3(void) 00169 { 00170 // there are two independent variables 00171 grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00172 double z = * grad_ptr->dep_addr; 00173 * grad_ptr->dep_addr=0.; 00174 * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ; 00175 * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ; 00176 //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00177 // if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16) 00178 // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00179 } 00180 00185 void default_evaluation3ind(void) 00186 { 00187 // there are three independent variables 00188 grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00189 00190 double mult3=grad_ptr->mult1 ; 00191 double * ind_addr3=grad_ptr->ind_addr1; 00192 if (gradient_structure::GRAD_STACK1->ptr-- == 00193 gradient_structure::GRAD_STACK1->ptr_first) 00194 { 00195 // back up the file one buffer size and read forward 00196 00197 my_off_t lpos=lseek(gradient_structure::GRAD_STACK1->_GRADFILE_PTR, 00198 -((long int)(sizeof(grad_stack_entry)*gradient_structure:: 00199 GRAD_STACK1->length)),SEEK_CUR); 00200 00201 gradient_structure::GRAD_STACK1->read_grad_stack_buffer(lpos); 00202 //gradient_structure::GRAD_STACK1->ptr++; 00203 } 00204 00205 grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00206 double z = * grad_ptr->dep_addr; 00207 * grad_ptr->dep_addr=0.; 00208 * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ; 00209 * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ; 00210 * ind_addr3 += z * mult3 ; 00211 } 00212 00217 void default_evaluation4ind(void) 00218 { 00219 // there are three independent variables 00220 grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00221 00222 double * ind_addr3=grad_ptr->ind_addr1; 00223 double mult3=grad_ptr->mult1 ; 00224 double * ind_addr4=grad_ptr->ind_addr2; 00225 double mult4=grad_ptr->mult2 ; 00226 if (gradient_structure::GRAD_STACK1->ptr-- == 00227 gradient_structure::GRAD_STACK1->ptr_first) 00228 { 00229 // back up the file one buffer size and read forward 00230 my_off_t lpos=lseek(gradient_structure::GRAD_STACK1->_GRADFILE_PTR, 00231 -((long int)(sizeof(grad_stack_entry)*gradient_structure:: 00232 GRAD_STACK1->length)),SEEK_CUR); 00233 00234 gradient_structure::GRAD_STACK1->read_grad_stack_buffer(lpos); 00235 //gradient_structure::GRAD_STACK1->ptr++; 00236 } 00237 00238 grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00239 double z = * grad_ptr->dep_addr; 00240 * grad_ptr->dep_addr=0.; 00241 * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ; 00242 * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ; 00243 * ind_addr3 += z * mult3 ; 00244 * ind_addr4 += z * mult4 ; 00245 //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00246 // if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16) 00247 // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl; 00248 //gradlog << setprecision(13) << * grad_ptr->ind_addr2 << endl; 00249 // if (fabs(* grad_ptr->ind_addr2+XXX)<1.e-16) 00250 // cout << setprecision(13) << * grad_ptr->ind_addr2 << endl; 00251 //gradlog << setprecision(13) << * ind_addr3 << endl; 00252 // if (fabs(* ind_addr3+XXX)<1.e-16) 00253 // cout << setprecision(13) << * ind_addr3 << endl; 00254 //gradlog << setprecision(13) << * ind_addr4 << endl; 00255 // if (fabs(* ind_addr4+XXX)<1.e-16) 00256 // cout << setprecision(13) << * ind_addr4 << endl; 00257 } 00258 00263 void default_evaluation4(void) 00264 { 00265 // there are two independent variables 00266 grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00267 double z = * grad_ptr->dep_addr; 00268 * grad_ptr->dep_addr=0.; 00269 * grad_ptr->ind_addr1 += z; 00270 * grad_ptr->ind_addr2 += z; 00271 } 00272 00277 void default_evaluation4m(void) 00278 { 00279 // there are two independent variables 00280 grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr; 00281 double z = * grad_ptr->dep_addr; 00282 * grad_ptr->dep_addr=0.; 00283 * grad_ptr->ind_addr1 += z; 00284 * grad_ptr->ind_addr2 -= z; 00285 }
|
|
Generated on Wed May 22 2013 13:57:35 for ADMB Documentation by 1.8.0
|