ADMB Documentation  11.1.1920
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2fn2.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2fn2.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <cstring>
00012 #if !defined(__BORLANDC__) && !defined(_MSC_VER)
00013 #include <inttypes.h>
00014 #endif
00015 #include <df1b2fun.h>
00016 #include "admb_messages.h"
00017 
00018 do_naught_kludge df1b2_init_number::do_naught_kludge_a;
00019 
00020 //#define  ADDEBUG_PRINT
00021 #if defined(ADDEBUG_PRINT)
00022     int addebug_count=0;
00023 #endif
00024 
00025 //df1b2_gradlist * f1b2gradlist = NULL;
00026 int max_num_init_df1b2variable=500;
00027 
00028 char AD_allocation_error_message[]="Error tryng to allocate memory for ";
00029 
00030 int get_f1b2buffer_size(const char * s);
00031 
00032 #if defined(CHECK_COUNT)
00033   int df1b2_gradlist::ncount_check=-1;
00034 #endif
00035 
00036 adpool * df1b2variable::pool= new adpool();
00037 
00042 df1b2function1::df1b2function1(double (*_f)(double),double (*_df)(double),
00043     double (*_d2f)(double),double (*_d3f)(double), const adstring& _s )
00044 {
00045   f=_f;
00046   df=_df;
00047   d2f=_d2f;
00048   d3f=_d3f;
00049   funname=_s;
00050 }
00051 
00056 ad_dstar::~ad_dstar(void)
00057 {
00058   if (p) delete []p;
00059   p = 0;
00060 }
00061 
00066 int df1b2variable::get_blocksize(void)
00067 {
00068   return get_blocksize(nvar);
00069 }
00070 
00075 int df1b2variable::get_blocksize(int n)
00076 {
00077   return 6*n+5;
00078   //return 6*n+4;
00079 }
00080 
00085 void df1b2variable::set_blocksize(void)
00086 {
00087   blocksize=get_blocksize();
00088   pool->set_size(sizeof(double)*blocksize);
00089   pool->nvar=df1b2variable::get_nvar();
00090 }
00091 
00092 //init_df1b2variable * init_df1b2variable::list[max_num_init_df1b2variable];
00093 init_df1b2variable ** init_df1b2variable::list=0;
00094 int df1b2variable::nvar=0;
00095 int df1b2variable::minder=0;
00096 int df1b2variable::maxder=0;
00097 int df1b2variable::blocksize=0;
00098 int init_df1b2variable::num_variables=0;
00099 int df1b2_gradlist::no_derivatives=0;
00100 int df1b2variable::passnumber=0;
00101 int ad_dstar::n=0;
00102 
00103 void ad_read_pass2(void);
00104 // should inline this
00105 #if !defined(__BORLANDC__)
00106 ptrdiff_t adptr_diff(void* x, void* y)
00107 {
00108   uintptr_t uintptrx = (uintptr_t)x;
00109   uintptr_t uintptry = (uintptr_t)y;
00110   return uintptrx - uintptry;
00111 }
00112 #endif
00113 
00114 #if defined(__CHECK_MEMORY__)
00115   int sanity_flag=0;
00116 #endif
00117 
00121 void df1b2variable::initialize(void)
00122 {
00123 #if defined(__CHECK_MEMORY__)
00124   if (sanity_flag)
00125   {
00126     df1b2variable::pool->sanity_check();
00127   }
00128 #endif
00129   int nvar=((twointsandptr*)ptr)->ptr->nvar;
00130   initialize(nvar);
00131 }
00132 
00138 void df1b2variable::initialize(int n)
00139 {
00140   //int bs=get_blocksize(n);
00141   //for (double * tmp=ptr+2;tmp<ptr+bs-1;*tmp++=0);
00142   int nbytes = (get_blocksize(n) - 2) * sizeof(double);
00143   memset(ptr + 2, 0, nbytes);
00144 }
00145 
00150   void init_df1b2variable::set_u_dot(void)
00151   {
00152     //int j;
00153     double uvalue=*get_u();
00154     initialize();
00155     int nder=maxder-minder+1;
00156     for (int i=0;i<nder;i++)
00157     {
00158       u_dot[i]=0.0;
00159     }
00160     if (ind_index>=minder && ind_index<=maxder)
00161     {
00162       int offset= ind_index-minder;
00163       u_dot[offset]=1.0;
00164     }
00165     *get_u()=uvalue;
00166   }
00167 
00172   void init_df1b2variable::operator = (double d)
00173   {
00174     //int nc=*ncopies;
00175     initialize();
00176     //*ncopies=nc;
00177     if (ind_index>=minder && ind_index<=maxder)
00178     {
00179       int offset= ind_index-minder;
00180       u_dot[offset]=1.0;
00181     }
00182     get_ind_index()=-1;
00183     *u=d;
00184   }
00185 
00190   df1b2variable::df1b2variable(const df1b2variable& v)
00191   {
00192 #if defined(__CHECK_MEMORY__)
00193     if (pchecker)
00194     {
00195       if (v.ptr == pchecker)
00196       {
00197         cout << " copy constructor called  " << endl;
00198       }
00199     }
00200 #endif
00201     if (v.ptr)
00202     {
00203       ptr=v.ptr;
00204       ncopies=v.ncopies;
00205       (*ncopies)++;
00206       u=v.u;
00207       u_dot=v.u_dot;
00208       u_bar=v.u_bar;
00209       u_dot_bar=v.u_dot_bar;
00210       u_tilde=v.u_tilde;
00211       u_dot_tilde=v.u_dot_tilde;
00212       u_bar_tilde=v.u_bar_tilde;
00213       u_dot_bar_tilde=v.u_dot_bar_tilde;
00214     }
00215     else
00216     {
00217       ptr=NULL;
00218       ncopies=NULL;
00219       u=NULL;
00220       u_dot=NULL;
00221       u_bar=NULL;
00222       u_dot_bar=NULL;
00223       u_tilde=NULL;
00224       u_dot_tilde=NULL;
00225       u_bar_tilde=NULL;
00226       u_dot_bar_tilde=NULL;
00227     }
00228   }
00229 
00230   adkludge1 * adkludgexxx;
00231 
00232 typedef init_df1b2variable * PINIT_DF1B2VARIABLE;
00233 
00238   init_df1b2variable::init_df1b2variable(double v) : df1b2variable(adkludgexxx)
00239   {
00240     ++num_variables;
00241    /*
00242     if (list==0)
00243     {
00244       list =new PINIT_DF1B2VARIABLE[max_num_init_df1b2variable];
00245     }
00246     if (++num_variables>= max_num_init_df1b2variable)
00247     {
00248       cerr << "Need to increase the maximum number of init_df1b2variables"
00249        << endl << "Use command line option -mni N" << endl;
00250     }
00251 
00252     if (num_variables>=df1b2variable::nvar)
00253     {
00254       cerr << "Maximum number of independent variables exceeded"
00255            << endl;
00256       cerr << "current max is " << df1b2variable::nvar << endl;
00257     }
00258     list[num_variables]=this;
00259     */
00260     ind_index=num_variables;
00261     *get_u()=v;
00262     if (num_variables>=minder && num_variables<=maxder)
00263     {
00264       //int offset= num_variables-minder;
00265       //u_dot[offset]=1.0;
00266     }
00267   }
00268 
00269   int no_destruct=0;
00270 
00274 df1b2variable::~df1b2variable()
00275 {
00276     deallocate();
00277 }
00278 
00282 void df1b2variable::deallocate(void)
00283 {
00284   if (ptr)
00285   {
00286 #if defined(__CHECK_MEMORY__)
00287     if (pchecker)
00288     {
00289       if (ptr == pchecker)
00290       {
00291         cout << "destructor called  " << endl;
00292       }
00293     }
00294 #endif
00295     if (ncopies && *ncopies)
00296     {
00297       (*ncopies)--;
00298     }
00299     else
00300     {
00301       if (!df1b2_gradlist::no_derivatives)
00302         f1b2gradlist->write_save_pass2_tilde_values(this);
00303       ((twointsandptr*)ptr)->ptr->free(ptr);
00304 
00305       ptr = 0;
00306     }
00307   }
00308 }
00309 
00314   void init_df1b2vector::set_value(const dvector& v)
00315   {
00316     int mmin=indexmin();
00317     int mmax=indexmax();
00318     if (v.indexmin() != mmin || v.indexmax() != mmax )
00319     {
00320       cerr << "incompatible shape in "
00321         "init_df1b2vector::set_value(const dvector& v)" << endl;
00322     }
00323 
00324     for (int i=mmin;i<=mmax;i++)
00325     {
00326       (*this)(i)=v(i);
00327     }
00328   }
00329 
00334   init_df1b2vector::init_df1b2vector(void)
00335   {
00336     allocate();
00337   }
00338 
00343   init_df1b2vector::init_df1b2vector(int lb,int ub)
00344   {
00345     allocate(lb,ub);
00346   }
00347 
00352   void init_df1b2vector::allocate(int lb,int ub)
00353   {
00354     init_df1b2variable::num_variables= 0;
00355     index_min=lb;
00356     index_max=ub;
00357     ncopies=new int;
00358     *ncopies=0;
00359     int size=indexmax()-indexmin()+1;
00360     if (init_df1b2variable::list==0)
00361     {
00362       max_num_init_df1b2variable
00363         =max(size,max_num_init_df1b2variable);
00364 
00365       init_df1b2variable::list =
00366         new PINIT_DF1B2VARIABLE [max_num_init_df1b2variable];
00367       if (init_df1b2variable::list==0)
00368       {
00369         cerr << "Error allocating memory for init_df1b2variable::list"
00370          << endl;
00371         exit(1);
00372       }
00373     }
00374 
00375   // ****************************************
00376     trueptr=new init_df1b2variable[size];
00377     if (trueptr == 0)
00378     {
00379       cerr << "Error allocating memory for init_df1b2variable"
00380            << endl;
00381       ad_exit(1);
00382     }
00383     //AD_ALLOCATE(trueptr,init_df1b2variable,size,df1b2_gradlist)
00384   // ****************************************
00385 
00386     ptr=trueptr;
00387     ptr-=lb;
00388   }
00389 
00394   void init_df1b2vector::reallocate()
00395   {
00396     int mmin=indexmin();
00397     int mmax=indexmax();
00398     for (int i=mmin;i<=mmax;i++)
00399     {
00400       ptr[i].allocate();
00401     }
00402   }
00403 
00408   void init_df1b2vector::allocate(void)
00409   {
00410     //deallocate(); a// don;t know why this was ever here DF 6june09
00411     index_min=0;
00412     index_max=-1;
00413     ncopies=0;
00414     ptr=0;
00415   }
00416 
00421   init_df1b2vector::~init_df1b2vector()
00422   {
00423     if (ncopies)
00424     {
00425       if (*ncopies)
00426         (*ncopies)--;
00427       else
00428       {
00429         if (trueptr)
00430         {
00431           delete [] trueptr;
00432           trueptr=0;
00433         }
00434         delete ncopies;
00435         ncopies=0;
00436       }
00437     }
00438   }
00439 
00444   void init_df1b2vector::deallocate(void)
00445   {
00446     if (ncopies)
00447     {
00448       if (*ncopies)
00449         (*ncopies)--;
00450       else
00451       {
00452         delete [] trueptr;
00453         trueptr=0;
00454         delete ncopies;
00455         ncopies=0;
00456       }
00457     }
00458   }
00459 
00464   init_df1b2vector::init_df1b2vector(const init_df1b2vector & v)
00465   {
00466     ncopies=v.ncopies;
00467     if (v.ncopies)
00468     {
00469       (*ncopies)++;
00470       trueptr=v.trueptr;
00471       ptr=v.ptr;
00472       index_min=v.index_min;
00473       index_max=v.index_max;
00474     }
00475     else
00476     {
00477       trueptr=0;
00478       index_min=1;
00479       index_max=0;
00480     }
00481     //cout << *ncopies << endl;
00482   }
00483 
00488   double& value(const df1b2variable& _x)
00489   {
00490     ADUNCONST(df1b2variable,x)
00491     return *x.u;
00492   }
00493 
00498   df1b2function2::df1b2function2(double (*_f)(double,double),
00499   double (*_df1)(double,double),double (*_df2)(double,double),
00500   double (*_d2f11)(double,double),
00501     double (*_d2f12)(double,double),
00502     double (*_d2f22)(double,double),
00503     double (*_d3f111)(double,double),
00504     double (*_d3f112)(double,double),
00505     double (*_d3f122)(double,double),
00506     double (*_d3f222)(double,double), const adstring& _s)
00507   {
00508     f=_f;
00509     df1=_df1; df2=_df2;
00510     d2f11=_d2f11; d2f12=_d2f12; d2f22=_d2f22;
00511     d3f111=_d3f111;
00512     d3f112=_d3f112;
00513     d3f122=_d3f122;
00514     d3f222=_d3f222;
00515     funname=_s;
00516   }
00517   typedef double (* PTDF)(double);
00518 
00523   PTDF tan_address()
00524   {
00525     return &tan;
00526   }
00527 
00532   df1b2variable df1b2function1::operator () (const df1b2variable& _x)
00533   {
00534     ADUNCONST(df1b2variable,x)
00535     df1b2variable z;
00536     double xu=*x.get_u();
00537     double * xd=x.get_u_dot();
00538     double * zd=z.get_u_dot();
00539     *z.get_u()=(*f)(xu);
00540     double dfx=(*df)(xu);
00541     for (int i=0;i<df1b2variable::nvar;i++)
00542     {
00543       *zd++ =dfx * *xd++;
00544     }
00545 
00546     // WRITE WHATEVER ON TAPE
00547     //df1b2tape->set_tapeinfo_header(&x,&z,this,xd);
00548     // save stuff for first reverse pass
00549     // need &x, &z, this,
00550     if (!df1b2_gradlist::no_derivatives)
00551     {
00552       if ((void*)(f)==tan_address())
00553         f1b2gradlist->write_pass1x(&x,&z,this);
00554       else
00555         f1b2gradlist->write_pass1(&x,&z,this);
00556     }
00557     return z;
00558   }
00559 
00564   df1b2variable df1b2function2::operator () (const df1b2variable& _x,
00565     const df1b2variable& _y)
00566   {
00567     ADUNCONST(df1b2variable,x)
00568     ADUNCONST(df1b2variable,y)
00569     df1b2variable z;
00570     double xu=*x.get_u();
00571     double yu=*y.get_u();
00572     double * xd=x.get_u_dot();
00573     double * yd=y.get_u_dot();
00574     double * zd=z.get_u_dot();
00575     *z.get_u()=(*f)(xu,yu);
00576     double dfx=(*df1)(xu,yu);
00577     double dfy=(*df2)(xu,yu);
00578     for (int i=0;i<df1b2variable::nvar;i++)
00579     {
00580       *zd++ =dfx * *xd++ + dfy * *yd++;
00581     }
00582 
00583     // WRITE WHATEVER ON TAPE
00584     if (!df1b2_gradlist::no_derivatives)
00585       f1b2gradlist->write_pass1(&x,&y,&z,this);
00586     return z;
00587   }
00588 
00593 void df1b2_gradlist::reset(void)
00594 {
00595   ncount=0;
00596   list.reset();
00597   nlist.reset();
00598   list2.reset();
00599   nlist2.reset();
00600   list3.reset();
00601   nlist3.reset();
00602 }
00603 
00608 df1b2_gradlist::df1b2_gradlist
00609 (
00610   unsigned int _bs, unsigned int _nbs,
00611   unsigned int _bs2, unsigned int _nbs2,
00612   unsigned int _bs3, unsigned int _nbs3,
00613   const adstring& _filename
00614 )
00615 {
00616   int bs=get_f1b2buffer_size("-l1");
00617   if (!bs) bs=_bs;
00618   list.allocate(bs,_filename);
00619 
00620   int nbs=get_f1b2buffer_size("-nl1");
00621   if (!nbs) nbs=_nbs;
00622   nlist.allocate(nbs,"n"+_filename);
00623 
00624   int bs2=get_f1b2buffer_size("-l2");
00625   if (!bs2) bs2=_bs2;
00626   list2.allocate(bs2,_filename+"2");
00627 
00628   int nbs2=get_f1b2buffer_size("-nl2");
00629   if (!nbs2) nbs2=_nbs2;
00630   nlist2.allocate(nbs2,"n"+_filename+"2");
00631 
00632   int bs3=get_f1b2buffer_size("-l3");
00633   if (!bs3) bs3=_bs3;
00634   list3.allocate(bs3,_filename+"3");
00635 
00636   int nbs3=get_f1b2buffer_size("-nl3");
00637   if (!nbs3) nbs3=_nbs3;
00638   nlist3.allocate(nbs3,"n"+_filename+"3");
00639 
00640   list3.set_noreadflag(1);
00641   nlist3.set_noreadflag(1);
00642 
00643   ncount=0;
00644 }
00645 /*
00646 smartlist::smartlist(void)
00647 {
00648   bufsize=0;
00649   filename=0;
00650   buffer=0;
00651   buffend=0;
00652   bptr=buffer;
00653   fp=-1;
00654 }
00655 */
00656 
00661 smartlist::smartlist(unsigned int _bufsize,const adstring& _filename)
00662 {
00663   if (sizeof(char)>1)
00664   {
00665     cerr << "need to modify smartlist class for multibyte char" << endl;
00666     exit(1);
00667   }
00668   bufsize=_bufsize;
00669   filename=_filename;
00670   AD_ALLOCATE(buffer,char,bufsize,df1b2_gradlist)
00671   buffend=buffer+bufsize-1;
00672   bptr=buffer;
00673   if ( (fp=open((char*)(filename), O_RDWR | O_CREAT | O_TRUNC |
00674                    O_BINARY, S_IREAD | S_IWRITE) == -1) )
00675   {
00676     cerr << "Error trying to open file " << filename
00677          << " in class smartlist " << endl;
00678     exit(1);
00679   }
00680 }
00681 
00682 void ad_dstar::allocate(int _n){n=_n;}
00683 
00688 ad_dstar::ad_dstar(void)
00689 {
00690   if (!n)
00691   {
00692     cerr << "need to initialize size in class ad_dstar" << endl;
00693     exit(1);
00694   }
00695   p = new double[n];
00696 }
00697 
00702 void set_dependent_variable(const df1b2variable& _x)
00703 {
00704   df1b2variable& x=(df1b2variable&) (_x);
00705   //cout << "dep " << int(x.u) << endl;
00706   for (int i=0;i<df1b2variable::nvar;i++)
00707   {
00708     x.u_dot_bar[i]=1.0;
00709   }
00710 }
00711 
00716 dmatrix get_hessian(const init_df1b2vector& _x)
00717 {
00718   ADUNCONST(init_df1b2vector,x)
00719   int nvar=df1b2variable::nvar;
00720   dmatrix h(1,nvar,1,nvar);
00721   for (int i=1;i<=nvar;i++)
00722   {
00723     for (int j=1;j<=nvar;j++)
00724     {
00725       h(i,j)=x(i).u_bar[j-1];
00726     }
00727   }
00728   return h;
00729 }
00730 
00731 typedef df1b2variable (*P_USER_FUNCTION)(const init_df1b2vector& x);
00732 
00737 double d1F(P_USER_FUNCTION pu,const init_df1b2vector& _x,int i,double _delta)
00738 {
00739   ADUNCONST(init_df1b2vector,x)
00740   double delta=.3*_delta;
00741   double xsave=value(x(i));
00742   x(i)=xsave+delta;
00743   double fp=value(pu(x));
00744   x(i)=xsave-delta;
00745   double fm=value(pu(x));
00746   x(i)=xsave;
00747   double d1fa=(fp-fm)/(2.0*delta);
00748   x(i)=xsave+2.0*delta;
00749   fp=value(pu(x));
00750   x(i)=xsave-2.0*delta;
00751   fm=value(pu(x));
00752   x(i)=xsave;
00753   double d1fb=(fp-fm)/(4.0*delta);
00754   double d1f=(8.0*d1fa-d1fb)/7.0;
00755   return d1f;
00756 }
00757 
00762 double d2F(P_USER_FUNCTION pu,const init_df1b2vector& _x,int i,int j,
00763   double delta)
00764 {
00765   ADUNCONST(init_df1b2vector,x)
00766   double xsave=value(x(i));
00767   x(i)=xsave+delta;
00768   double fp=d1F(pu,x,j,delta);
00769   x(i)=xsave-delta;
00770   double fm=d1F(pu,x,j,delta);
00771   double d1fa=(fp-fm)/(2.0*delta);
00772   x(i)=xsave+2.0*delta;
00773   fp=d1F(pu,x,j,delta);
00774   x(i)=xsave-2.0*delta;
00775   fm=d1F(pu,x,j,delta);
00776   x(i)=xsave;
00777   double d1fb=(fp-fm)/(4.0*delta);
00778   double d1f=(8.0*d1fa-d1fb)/7.0;
00779   return d1f;
00780 }
00781 
00786 double d3F(P_USER_FUNCTION pu,const init_df1b2vector& _x,int i,int j,int k,
00787   double delta)
00788 {
00789   ADUNCONST(init_df1b2vector,x)
00790   double xsave=value(x(i));
00791   x(i)=xsave+delta;
00792   double fp=d2F(pu,x,j,k,delta);
00793   x(i)=xsave-delta;
00794   double fm=d2F(pu,x,j,k,delta);
00795   x(i)=xsave;
00796   double d1f=(fp-fm)/(2.0*delta);
00797   return d1f;
00798 }
00799 
00804 dmatrix check_second_derivatives(const init_df1b2vector& x)
00805 {
00806   f1b2gradlist->set_no_derivatives();
00807   dmatrix h(1,df1b2variable::nvar,1,df1b2variable::nvar);
00808   //const double delta=1.e-3;
00809   h.initialize();
00810   int i,j;
00811   for (i=1;i<=init_df1b2variable::num_variables;i++)
00812   {
00813     for (j=1;j<=init_df1b2variable::num_variables;j++)
00814     {
00815       //h(i,j)=d2F(user_function,x,i,j,delta);
00816     }
00817   }
00818   return h;
00819 }
00820 
00825 d3_array check_third_derivatives(const init_df1b2vector& x)
00826 {
00827   f1b2gradlist->set_no_derivatives();
00828   d3_array h(1,df1b2variable::nvar,1,df1b2variable::nvar,1,df1b2variable::nvar);
00829   //const double delta=2.e-4;
00830   h.initialize();
00831   int i,j,k;
00832   for (i=1;i<=init_df1b2variable::num_variables;i++)
00833   {
00834     for (j=1;j<=init_df1b2variable::num_variables;j++)
00835     {
00836       for (k=1;k<=init_df1b2variable::num_variables;k++)
00837       {
00838         //h(i,j,k)=d3F(user_function,x,i,j,k,delta);
00839       }
00840     }
00841   }
00842   return h;
00843 }
00844 
00845 #if defined(__DERCHECK__)
00846 
00851 dercheck_info::dercheck_info(int _node_number,double _delta,int _index) :
00852   node_number(_node_number), delta(_delta), index(_index)
00853 {
00854   der_value=0.0;
00855   pass_number=0;
00856   counter=0;
00857   f1=0.0;
00858   f2=0.0;
00859 }
00860 dercheck_info * derchecker;
00861 
00862 #endif
00863 
00864 
00865 re_objective_function_value * re_objective_function_value::pobjfun=0;
00866 
00871 re_objective_function_value::re_objective_function_value(void)
00872 {
00873   pobjfun=this;
00874 }
00875 
00880 re_objective_function_value::~re_objective_function_value()
00881 {
00882   pobjfun=0;
00883 }
00884 
00889 re_objective_function_value& re_objective_function_value::operator =
00890   (const df1b2variable& v)
00891 {
00892   df1b2variable::operator = (v);
00893   return *this;
00894 }
00895 
00900 re_objective_function_value& re_objective_function_value::operator =
00901   (double v)
00902 {
00903   df1b2variable::operator = (v);
00904   return *this;
00905 }
00906 
00911 void re_objective_function_value::allocate(void)
00912 {
00913   df1b2variable::allocate();
00914 }
00915 
00920 void re_objective_function_value::allocate(const char * s)
00921 {
00922   pobjfun=this;
00923   df1b2variable::allocate();
00924 }
00925 
00926 #if !defined(OPT_LIB)
00927 
00931 init_df1b2variable& init_df1b2vector::operator () (int i)
00932 {
00933   if (i < indexmin())
00934   {
00935     ADMB_ARRAY_BOUNDS_ERROR("Index too low",
00936     "init_df1b2variable& init_df1b2vector::operator () (int i)",
00937     indexmin(), indexmax(), i);
00938   }
00939   if (i > indexmax())
00940   {
00941     ADMB_ARRAY_BOUNDS_ERROR("Index too high",
00942     "init_df1b2variable& init_df1b2vector::operator () (int i)",
00943     indexmin(), indexmax(), i);
00944   }
00945   return ptr[i];
00946 }
00947 
00952 init_df1b2variable& init_df1b2vector::operator [] (int i)
00953 {
00954   if (i < indexmin())
00955   {
00956     ADMB_ARRAY_BOUNDS_ERROR("Index too low",
00957     "init_df1b2variable& init_df1b2vector::operator [] (int i)",
00958     indexmin(), indexmax(), i);
00959   }
00960   if (i > indexmax())
00961   {
00962     ADMB_ARRAY_BOUNDS_ERROR("Index too high",
00963     "init_df1b2variable& init_df1b2vector::operator [] (int i)",
00964     indexmin(), indexmax(), i);
00965   }
00966   return ptr[i];
00967 }
00968 #endif
00969 
00972 int get_f1b2buffer_size(const char* s)
00973 {
00974   int n=0;
00975   int on1=-1;
00976   int nopt=0;
00977   if ( (on1=option_match(ad_comm::argc,ad_comm::argv,s,nopt))>-1)
00978   {
00979     if (!nopt)
00980     {
00981       cerr << "Usage " << s << " option needs integer  -- ignored" << endl;
00982     }
00983     else
00984     {
00985       n=atoi(ad_comm::argv[on1+1]);
00986     }
00987   }
00988   return n;
00989 }
00990 
00995 df1b2variable::df1b2variable(const random_effects_bounded_vector_info& rebv)
00996 {
00997   df1b2variable& v= *(rebv.pv->v+rebv.i);
00998   if (v.ptr)
00999   {
01000     ptr=v.ptr;
01001     ncopies=v.ncopies;
01002     (*ncopies)++;
01003     u=v.u;
01004     u_dot=v.u_dot;
01005     u_bar=v.u_bar;
01006     u_dot_bar=v.u_dot_bar;
01007     u_tilde=v.u_tilde;
01008     u_dot_tilde=v.u_dot_tilde;
01009     u_bar_tilde=v.u_bar_tilde;
01010     u_dot_bar_tilde=v.u_dot_bar_tilde;
01011   }
01012   else
01013   {
01014     ptr=NULL;
01015     ncopies=NULL;
01016     u=NULL;
01017     u_dot=NULL;
01018     u_bar=NULL;
01019     u_dot_bar=NULL;
01020     u_tilde=NULL;
01021     u_dot_tilde=NULL;
01022     u_bar_tilde=NULL;
01023     u_dot_bar_tilde=NULL;
01024   }
01025 }