Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011 #include <df1b2fun.h>
00012
00013
00014 #if defined(ADDEBUG_PRINT)
00015 int addebug_count=0;
00016 #endif
00017
00018 #ifndef OPT_LIB
00019 #include <cassert>
00020 #include <climits>
00021 #endif
00022
00023 void ad_read_write_tilde_values(void);
00024 void read_tilde_values_1(void);
00025 void read_tilde_values_2(void);
00026 void read_tilde_values_3(void);
00027
00032 int df1b2_gradlist::write_save_pass2_tilde_values(const df1b2variable* _px)
00033 {
00034 ADUNCONST(df1b2variable*, px)
00035 ncount++;
00036 #if defined(CHECK_COUNT)
00037 if (ncount >= ncount_check)
00038 ncount_checker(ncount,ncount_check);
00039 #endif
00040 size_t total_bytes=sizeof(df1b2_header);
00041
00042 #if defined(SAFE_ALL)
00043 char ids[]="YS";
00044 size_t slen=strlen(ids);
00045 total_bytes+=slen;
00046 #endif
00047 list.check_buffer_size(total_bytes);
00048 void* tmpptr=list.bptr;
00049 #if defined(SAFE_ALL)
00050 memcpy(list,ids,slen);
00051 #endif
00052
00053 memcpy(list,(df1b2_header*)(px),sizeof(df1b2_header));
00054
00055
00056 nlist.bptr->numbytes=adptr_diff(list.bptr,tmpptr);
00057 nlist.bptr->pf=(ADrfptr)(&ad_read_write_tilde_values);
00058 ++nlist;
00059
00060 return 0;
00061 }
00062
00067 void ad_read_write_tilde_values(void)
00068 {
00069 switch(df1b2variable::passnumber)
00070 {
00071 case 1:
00072 read_tilde_values_1();
00073 break;
00074 case 2:
00075 read_tilde_values_2();
00076 break;
00077 case 3:
00078 read_tilde_values_3();
00079 break;
00080 default:
00081 cerr << "illegal value for df1b2variable::pass = "
00082 << df1b2variable::passnumber << endl;
00083 exit(1);
00084 }
00085 }
00086
00091 void read_tilde_values_1(void)
00092 {
00093
00094
00095
00096
00097 unsigned int nvar=df1b2variable::nvar;
00098 fixed_smartlist & nlist=f1b2gradlist->nlist;
00099 test_smartlist& list=f1b2gradlist->list;
00100
00101
00102 int num_bytes=nlist.bptr->numbytes;
00103
00104 list-=num_bytes;
00105 list.saveposition();
00106 #if defined(SAFE_ALL)
00107 checkidentiferstring("YS",list);
00108 #endif
00109 df1b2_header * px=(df1b2_header *) list.bptr;
00110 list.restoreposition();
00111
00112
00113 for (unsigned int i=0;i<nvar;i++)
00114 {
00115 px->u_bar[i]=0;
00116 px->u_dot_bar[i]=0;
00117 }
00118 }
00119
00124 void read_tilde_values_2(void)
00125 {
00126
00127
00128
00129
00130
00131 unsigned int nvar=df1b2variable::nvar;
00132 test_smartlist & list=f1b2gradlist->list;
00133
00134 size_t total_bytes=sizeof(df1b2_header);
00135 #if defined(SAFE_ALL)
00136 char ids[]="YS";
00137 size_t slen=strlen(ids);
00138 total_bytes+=slen;
00139 #endif
00140 list.check_buffer_size(total_bytes);
00141 list.saveposition();
00142 #if defined(SAFE_ALL)
00143 checkidentiferstring("YS",list);
00144 #endif
00145
00146
00147
00148
00149
00150
00151 df1b2_header* px = (df1b2_header*)list.bptr;
00152
00153
00154
00155 fixed_smartlist2& nlist3=f1b2gradlist->nlist3;
00156 test_smartlist& list3=f1b2gradlist->list3;
00157
00158 size_t total_bytes2=(nvar+1)*sizeof(double);
00159
00160 #if defined(SAFE_ALL)
00161 char ids2[]="WF";
00162 size_t slen2=strlen(ids2);
00163 total_bytes2+=slen2;
00164 #endif
00165
00166 list3.check_buffer_size(total_bytes2);
00167
00168 void * tmpptr3=list3.bptr;
00169 #if defined(SAFE_ALL)
00170 memcpy(list3,ids2,slen);
00171 #endif
00172
00173 const size_t sizeofdouble = sizeof(double);
00174 const size_t size = sizeofdouble * nvar;
00175 memcpy(list3, px->get_u_tilde(), sizeofdouble);
00176 memcpy(list3, px->get_u_dot_tilde(), size);
00177
00178 memset(px->get_u_bar_tilde(), 0, size);
00179 memset(px->get_u_dot_bar_tilde(), 0, size);
00180 memset(px->get_u_dot_tilde(), 0, size);
00181 memset(px->get_u_tilde(), 0, sizeofdouble);
00182
00183 *nlist3.bptr=adptr_diff(list3.bptr,tmpptr3);
00184 list.bptr+=sizeof(df1b2_header);
00185 ++nlist3;
00186 }
00187
00192 void read_tilde_values_3(void)
00193 {
00194
00195
00196
00197 unsigned int nvar=df1b2variable::nvar;
00198 fixed_smartlist & nlist=f1b2gradlist->nlist;
00199 test_smartlist& list=f1b2gradlist->list;
00200
00201
00202 int num_bytes=nlist.bptr->numbytes;
00203
00204 list-=num_bytes;
00205 list.saveposition();
00206 #if defined(SAFE_ALL)
00207 checkidentiferstring("YS",list);
00208 #endif
00209 df1b2_header * px=(df1b2_header *) list.bptr;
00210 list.restoreposition();
00211
00212 fixed_smartlist2& nlist3=f1b2gradlist->nlist3;
00213 test_smartlist& list3=f1b2gradlist->list3;
00214 --nlist3;
00215
00216 int num_bytes3=*nlist3.bptr;
00217
00218 list3-=num_bytes3;
00219 list3.saveposition();
00220 #if defined(SAFE_ALL)
00221 checkidentiferstring("WF",list3);
00222 #endif
00223 memcpy(px->get_u_tilde(),list3.bptr,sizeof(double));
00224 list3.bptr+=sizeof(double);
00225 memcpy(px->get_u_dot_tilde(),list3.bptr,nvar*sizeof(double));
00226 list3.restoreposition();
00227 }