ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2fn7.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 <df1b2fun.h>
12 
13 //#define ADDEBUG_PRINT
14 #if defined(ADDEBUG_PRINT)
15  int addebug_count=0;
16 #endif
17 
18 #ifndef OPT_LIB
19  #include <cassert>
20  #include <climits>
21 #endif
22 
24 void read_tilde_values_1(void);
25 void read_tilde_values_2(void);
26 void read_tilde_values_3(void);
27 
33 {
35  ncount++;
36 #if defined(CHECK_COUNT)
37  if (ncount >= ncount_check)
38  ncount_checker(ncount,ncount_check);
39 #endif
40  size_t total_bytes=sizeof(df1b2_header);
41 
42 #if defined(SAFE_ALL)
43  char ids[]="YS";
44  size_t slen=strlen(ids);
45  total_bytes+=slen;
46 #endif
47  list.check_buffer_size(total_bytes);
48  void* tmpptr=list.bptr;
49 #if defined(SAFE_ALL)
50  memcpy(list,ids,slen);
51 #endif
52 
53  memcpy(list,(df1b2_header*)(px),sizeof(df1b2_header));
54  //list.bptr+=sizeof(df1b2_header);
55  // ***** write record size
58  ++nlist;
59 
60  return 0;
61 }
62 
68 {
70  {
71  case 1:
73  break;
74  case 2:
76  break;
77  case 3:
79  break;
80  default:
81  cerr << "illegal value for df1b2variable::pass = "
83  ad_exit(1);
84  }
85 }
86 
92 {
93  // We are going backword for bptr and nbptr
94  // and forward for bptr2 and nbptr2
95  // the current entry+2 in bptr is the size of the record i.e
96  // points to the next record
97  unsigned int nvar=df1b2variable::nvar;
100  // nlist-=sizeof(int);
101  // get record size
102  int num_bytes=nlist.bptr->numbytes;
103  // backup the size of the record
104  list-=num_bytes;
105  list.saveposition(); // save pointer to beginning of record;
106 #if defined(SAFE_ALL)
107  checkidentiferstring("YS",list);
108 #endif
109  df1b2_header * px=(df1b2_header *) list.bptr; // we don't need this here
110  list.restoreposition(); // save pointer to beginning of record;
111 
112  // don't need this here for = since it zeroes this out.
113  /*
114  for (unsigned int i=0;i<nvar;i++)
115  {
116  px->u_bar[i]=0;
117  px->u_dot_bar[i]=0;
118  }
119  */
120  constexpr size_t sizeofdouble = sizeof(double);
121  size_t size = nvar * sizeofdouble;
122  memset(px->u_bar, 0, size);
123  memset(px->u_dot_bar, 0, size);
124 }
125 
131 {
132  //const int nlist_record_size=sizeof(int)+sizeof(char*);
133  // We are going forward for bptr and backword for bptr2
134  //
135  // list 1
136  //
137  unsigned int nvar=df1b2variable::nvar;
139 
140  size_t total_bytes=sizeof(df1b2_header);
141 #if defined(SAFE_ALL)
142  char ids[]="YS";
143  size_t slen=strlen(ids);
144  total_bytes+=slen;
145 #endif
146  list.check_buffer_size(total_bytes);
147  list.saveposition(); // save pointer to beginning of record;
148 #if defined(SAFE_ALL)
149  checkidentiferstring("YS",list);
150 #endif
151 
152  //fixed_smartlist & nlist=f1b2gradlist->nlist;
153  // nlist-=sizeof(int);
154  // get record size
155  //int num_bytes=nlist.bptr->numbytes;
156  // nlist+=nlist_record_size;
157  df1b2_header* px = (df1b2_header*)list.bptr;
158  //
159  // list 3
160  //
163 
164  size_t total_bytes2=(nvar+1)*sizeof(double);
165 
166 #if defined(SAFE_ALL)
167  char ids2[]="WF";
168  size_t slen2=strlen(ids2);
169  total_bytes2+=slen2;
170 #endif
171 
172  list3.check_buffer_size(total_bytes2);
173 
174  void * tmpptr3=list3.bptr;
175 #if defined(SAFE_ALL)
176  memcpy(list3,ids2,slen);
177 #endif
178 
179  const size_t sizeofdouble = sizeof(double);
180  const size_t size = sizeofdouble * nvar;
181  memcpy(list3, px->get_u_tilde(), sizeofdouble);
182  memcpy(list3, px->get_u_dot_tilde(), size);
183 
184  memset(px->get_u_bar_tilde(), 0, size);
185  memset(px->get_u_dot_bar_tilde(), 0, size);
186  memset(px->get_u_dot_tilde(), 0, size);
187  memset(px->get_u_tilde(), 0, sizeofdouble);
188 
189  *nlist3.bptr=adptr_diff(list3.bptr,tmpptr3);
190  list.bptr+=sizeof(df1b2_header);
191  ++nlist3;
192 }
193 
199 {
200  // We are going backword for bptr and forward for bptr2
201  // the current entry+2 in bptr is the size of the record i.e
202  // points to the next record
203  unsigned int nvar=df1b2variable::nvar;
206  // nlist-=sizeof(int);
207  // get record size
208  int num_bytes=nlist.bptr->numbytes;
209  // backup the size of the record
210  list-=num_bytes;
211  list.saveposition(); // save pointer to beginning of record;
212 #if defined(SAFE_ALL)
213  checkidentiferstring("YS",list);
214 #endif
215  df1b2_header * px=(df1b2_header *) list.bptr;
216  list.restoreposition(); // save pointer to beginning of record;
217  // save the pointer to the beginning of the record
220  --nlist3;
221  // get record size
222  int num_bytes3=*nlist3.bptr;
223  // backup the size of the record
224  list3-=num_bytes3;
225  list3.saveposition(); // save pointer to beginning of record;
226 #if defined(SAFE_ALL)
227  checkidentiferstring("WF",list3);
228 #endif
229  memcpy(px->get_u_tilde(),list3.bptr,sizeof(double));
230  list3.bptr+=sizeof(double);
231  memcpy(px->get_u_dot_tilde(),list3.bptr,nvar*sizeof(double));
232  list3.restoreposition(); // save pointer to beginning of record;
233 }
char * bptr
Definition: df1b2fun.h:543
double * get_u_bar_tilde() const
Definition: df1b2fun.h:234
void check_buffer_size(const size_t)
Description not yet available.
Definition: df1b2f10.cpp:185
df1b2_gradlist * f1b2gradlist
Definition: df1b2glo.cpp:49
void memcpy(test_smartlist &dest, void *source, const size_t nsize)
memcpy for test_smartlist
Definition: df1b2f10.cpp:367
double * u_bar
Definition: df1b2fun.h:197
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
void ad_read_write_tilde_values(void)
Description not yet available.
Definition: df1b2fn7.cpp:67
static int passnumber
Definition: df1b2fun.h:289
double * get_u_dot_tilde() const
Definition: df1b2fun.h:233
int adptr_diff(void *x, void *y)
Definition: df1b2fn2.cpp:110
exitptr ad_exit
Definition: gradstrc.cpp:53
void ncount_checker(int ncount, int ncount_check)
void restoreposition(void)
Definition: df1b2fun.h:560
Description not yet available.
Definition: df1b2fun.h:266
Description not yet available.
Definition: df1b2fun.h:669
fixed_smartlist nlist
Definition: df1b2fun.h:754
Description not yet available.
Definition: df1b2fun.h:602
prnstream & endl(prnstream &)
double * u_dot_bar
Definition: df1b2fun.h:198
test_smartlist list
Definition: df1b2fun.h:753
ADrfptr pf
Definition: df1b2fun.h:595
fixed_smartlist2 nlist3
Definition: df1b2fun.h:758
Description not yet available.
Definition: df1b2fun.h:527
void read_tilde_values_3(void)
Description not yet available.
Definition: df1b2fn7.cpp:198
double * get_u_tilde() const
Definition: df1b2fun.h:232
double * get_u_dot_bar_tilde() const
Definition: df1b2fun.h:235
test_smartlist list3
Definition: df1b2fun.h:757
static unsigned int nvar
Definition: df1b2fun.h:290
void(* ADrfptr)(void)
Definition: df1b2fun.cpp:139
Base class for df1b2variable.
Definition: df1b2fun.h:191
Description not yet available.
fixed_list_entry * bptr
Definition: df1b2fun.h:626
void checkidentiferstring(const char *ids, test_smartlist &list)
Description not yet available.
Definition: df1b2fn5.cpp:256
int write_save_pass2_tilde_values(const df1b2variable *px)
Description not yet available.
Definition: df1b2fn7.cpp:32
int numbytes
Definition: df1b2fun.h:594
void saveposition(void)
Definition: df1b2fun.h:552
void read_tilde_values_2(void)
Description not yet available.
Definition: df1b2fn7.cpp:130
void read_tilde_values_1(void)
Description not yet available.
Definition: df1b2fn7.cpp:91