ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmpdif3.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <fvar.hpp>
12 
13 #ifdef __TURBOC__
14  #pragma hdrstop
15  #include <iostream.h>
16 #endif
17 
18 #ifdef __ZTC__
19  #include <iostream.hpp>
20 #endif
21 
22 #include <string.h>
23 
24 #ifndef OPT_LIB
25  #include <cassert>
26  #include <climits>
27  #define CHK_ID_STRING
28 #endif
29 
30 //extern ofstream clogf;
31 
37 {
38  verify_identifier_string("stack");
39  // Back up the stream and read the number of bytes written in the
40  // ``write function'' corresponding to this ``read function''
41  int num_bytes;
42  gradient_structure::fp->fread(&num_bytes,sizeof(int));
43  char str1[100];
44  str1[0]='\0';
45 #ifndef OPT_LIB
46  assert(num_bytes > 0);
47 #endif
48  gradient_structure::fp->fread(str1,(size_t)num_bytes);
49  cout << "in report_gradstack_flag " << str1 << endl;
50 }
51 
52 #if defined(CHK_ID_STRING)
53 
57 static void report_gradstack_flag2(void)
58 {
59  verify_identifier_string("stack");
60  // Back up the stream and read the number of bytes written in the
61  // ``write function'' corresponding to this ``read function''
63  int num_bytes;
64  fp->fread(&num_bytes,sizeof(int));
65  char str1[100];
66  str1[0]='\0';
67 #ifndef OPT_LIB
68  assert(num_bytes >= 0);
69 #endif
70  fp->fread(str1, (size_t)num_bytes);
71  int i,j;
72  fp->fread(&j,sizeof(int));
73  fp->fread(&i,sizeof(int));
74  cout << "in report_gradstack_flag " << str1 << endl;
75 }
76 #endif
77 
83 {
84 #if defined(CHK_ID_STRING)
85  //int wsize=sizeof(char);
86 #ifdef OPT_LIB
87  int length=(int)strlen(str);
88 #else
89  size_t _length = strlen(str);
90  assert(_length <= INT_MAX);
91  int length=(int)_length;
92 #endif
93 #ifndef OPT_LIB
94  assert(length >= 0);
95 #endif
98  fp->fwrite(str, (size_t)length);
99  fp->fwrite(&length,sizeof(int));
101  save_identifier_string("stack");
102 #endif
103 }
104 
109 void set_gradstack_flag(char* _str,int i,int j)
110 {
111 #if defined(CHK_ID_STRING)
112  adstring ads=_str;
113  ads+=" ";
114  ads+=str(i);
115  ads+=" ";
116  ads+=str(j);
117  //int wsize=sizeof(char);
118  char * str=(char*)(ads);
119 #ifdef OPT_LIB
120  int length=(int)strlen(str);
121 #else
122  size_t _length = strlen(str);
123  assert(_length <= INT_MAX);
124  int length=(int)_length;
125 #endif
128  fp->fwrite(&i,sizeof(int));
129  fp->fwrite(&j,sizeof(int));
130 #ifndef OPT_LIB
131  assert(length >= 0);
132 #endif
133  fp->fwrite(str, (size_t)length);
134  fp->fwrite(&length,sizeof(int));
136  save_identifier_string("stack");
137 #endif
138 }
139 
149 void verify_identifier_string(const char* str1)
150 {
151 #if defined(CHK_ID_STRING)
152  // Back up the stream and read the number of bytes written in the
153  // ``write function'' corresponding to this ``read function''
154  size_t num_bytes=strlen(str1);
155  char str[10];
156  str[num_bytes]='\0';
157  gradient_structure::fp->fread(str,num_bytes);
158  //clogf << "in verify_id_string " << str1 << endl;
159  if(strcmp(str1,str))
160  {
161  cerr << "Error reading stack identifer for " << str1 << endl;
162  ad_exit(1);
163  }
164 #endif
165 }
166 
172 {
173  adstring str1;
174 #if defined(CHK_ID_STRING)
175  // Back up the stream and read the number of bytes written in the
176  // ``write function'' corresponding to this ``read function''
177  long int num_bytes=5;
178  char str[10];
179  str[num_bytes]='\0';
180 #ifndef OPT_LIB
181  assert(num_bytes > 0);
182 #endif
183  gradient_structure::fp->fread(str,(size_t)num_bytes);
184  //clogf << "in verify_id_string " << str1 << endl;
185  str1=str;
186 #endif
187  return str1;
188 }
189 
195 {
197 }
199 {
200  // saves the size and address information for a ivector
201  constexpr size_t wsize=sizeof(ivector_position);
202  ivector_position tmp(v);
203  fwrite(&tmp, wsize);
204 }
205 
211 {
213 }
215 {
216  // saves the size and address information for a dvar_vector
217  constexpr size_t wsize=sizeof(dvar_vector_position);
218  dvar_vector_position tmp(v);
219  fwrite(&tmp, wsize);
220 }
221 
226 void save_ad_pointer(void * p)
227 {
228  // saves the size and address information for a dvar_vector
229  size_t wsize=sizeof(void *);
230  gradient_structure::fp->fwrite(&p, wsize);
231 }
232 
237 void * restore_ad_pointer(void)
238 {
239  void * p=0;
240  // saves the size and address information for a dvar_vector
241  size_t wsize=sizeof(void *);
242  gradient_structure::fp->fread(&p, wsize);
243  return p;
244 }
void * restore_ad_pointer(void)
Description not yet available.
Definition: cmpdif3.cpp:237
void save_ivector_position() const
Description not yet available.
Definition: cmpdif3.cpp:194
void save_ivector_position(const ivector &v)
Definition: cmpdif3.cpp:198
Description not yet available.
Definition: fvar.hpp:4814
exitptr ad_exit
Definition: gradstrc.cpp:53
ADMB variable vector.
Definition: fvar.hpp:2172
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
adstring get_string_marker(void)
Description not yet available.
Definition: cmpdif3.cpp:171
void set_gradient_stack(void(*func)(void), double *dep_addr, double *ind_addr1=NULL, double mult1=0, double *ind_addr2=NULL, double mult2=0)
Description not yet available.
Definition: fvar.hpp:1045
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
Description not yet available.
Definition: fvar.hpp:4947
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void set_gradstack_flag(char *str)
Description not yet available.
Definition: cmpdif3.cpp:82
static _THREAD gradient_structure * _instance
int save_identifier_string(const char *)
Writes a gradient stack verification string.
Definition: cmpdif2.cpp:315
adstring str(double x, int minwidth=17, int decplaces=-1)
Convert x to adstring with minimum width and total number of decimal places.
Definition: str.cpp:25
void save_ad_pointer(void *p)
Description not yet available.
Definition: cmpdif3.cpp:226
void save_dvar_vector_position(const dvar_vector &v)
Definition: cmpdif3.cpp:214
static _THREAD DF_FILE * fp
void save_dvar_vector_position() const
Description not yet available.
Definition: cmpdif3.cpp:210
Stores the adjoint gradient data that will be processed by gradcalc.
void fwrite(const void *s, const size_t num_bytes)
Reads num_bytes from s and writes to buffer.
Definition: df_file.cpp:296
void fread(void *s, const size_t num_bytes)
Reads num_bytes from buffer and copies to s.
Definition: df_file.cpp:270
static _THREAD grad_stack * GRAD_STACK1
void report_gradstack_flag(void)
Description not yet available.
Definition: cmpdif3.cpp:36
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
static void report_gradstack_flag2(void)
Description not yet available.
Definition: cmpdif3.cpp:57
size_t length(const adstring &t)
Returns the size of adstr.
Definition: string1.cpp:228