ADMB Documentation  11.1.2496
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2fn2.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2fn2.cpp 2481 2014-10-13 23:42:34Z 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 <cassert>
00017 #include <climits>
00018 #include "admb_messages.h"
00019 
00020 do_naught_kludge df1b2_init_number::do_naught_kludge_a;
00021 
00022 //#define  ADDEBUG_PRINT
00023 #if defined(ADDEBUG_PRINT)
00024     int addebug_count=0;
00025 #endif
00026 
00027 //df1b2_gradlist * f1b2gradlist = NULL;
00028 int max_num_init_df1b2variable=500;
00029 
00030 char AD_allocation_error_message[]="Error tryng to allocate memory for ";
00031 
00032 int get_f1b2buffer_size(const char * s);
00033 
00034 #if defined(CHECK_COUNT)
00035   int df1b2_gradlist::ncount_check=-1;
00036 #endif
00037 
00038 adpool * df1b2variable::pool= new adpool();
00039 
00044 df1b2function1::df1b2function1(double (*_f)(double),double (*_df)(double),
00045     double (*_d2f)(double),double (*_d3f)(double), const adstring& _s )
00046 {
00047   f=_f;
00048   df=_df;
00049   d2f=_d2f;
00050   d3f=_d3f;
00051   funname=_s;
00052 }
00053 
00058 ad_dstar::~ad_dstar(void)
00059 {
00060   if (p) delete []p;
00061   p = 0;
00062 }
00063 
00068 int df1b2variable::get_blocksize(void)
00069 {
00070   return get_blocksize(nvar);
00071 }
00072 
00077 int df1b2variable::get_blocksize(int n)
00078 {
00079   return 6*n+5;
00080   //return 6*n+4;
00081 }
00082 
00087 void df1b2variable::set_blocksize(void)
00088 {
00089   blocksize=get_blocksize();
00090   pool->set_size((unsigned int)sizeof(double)*blocksize);
00091   pool->nvar=df1b2variable::get_nvar();
00092 }
00093 
00094 //init_df1b2variable * init_df1b2variable::list[max_num_init_df1b2variable];
00095 init_df1b2variable ** init_df1b2variable::list=0;
00096 int df1b2variable::nvar=0;
00097 int df1b2variable::minder=0;
00098 int df1b2variable::maxder=0;
00099 int df1b2variable::blocksize=0;
00100 int init_df1b2variable::num_variables=0;
00101 int df1b2_gradlist::no_derivatives=0;
00102 int df1b2variable::passnumber=0;
00103 int ad_dstar::n=0;
00104 
00105 void ad_read_pass2(void);
00106 // should inline this
00107 #if !defined(__BORLANDC__)
00108 int adptr_diff(void* x, void* y)
00109 {
00110   uintptr_t a = (uintptr_t)x;
00111   uintptr_t b = (uintptr_t)y;
00112   ptrdiff_t diff = a - b;
00113   assert(diff <= INT_MAX);
00114   return (int)diff;
00115 }
00116 #endif
00117 
00118 #if defined(__CHECK_MEMORY__)
00119   int sanity_flag=0;
00120 #endif
00121 
00125 void df1b2variable::initialize(void)
00126 {
00127 #if defined(__CHECK_MEMORY__)
00128   if (sanity_flag)
00129   {
00130     df1b2variable::pool->sanity_check();
00131   }
00132 #endif
00133   int nvar=((twointsandptr*)ptr)->ptr->nvar;
00134   initialize(nvar);
00135 }
00136 
00142 void df1b2variable::initialize(int n)
00143 {
00144   //int bs=get_blocksize(n);
00145   //for (double * tmp=ptr+2;tmp<ptr+bs-1;*tmp++=0);
00146   size_t nbytes = (get_blocksize(n) - 2) * sizeof(double);
00147   memset(ptr + 2, 0, nbytes);
00148 }
00149 
00154   void init_df1b2variable::set_u_dot(void)
00155   {
00156     //int j;
00157     double uvalue=*get_u();
00158     initialize();
00159     int nder=maxder-minder+1;
00160     for (int i=0;i<nder;i++)
00161     {
00162       u_dot[i]=0.0;
00163     }
00164     if (ind_index>=minder && ind_index<=maxder)
00165     {
00166       int offset= ind_index-minder;
00167       u_dot[offset]=1.0;
00168     }
00169     *get_u()=uvalue;
00170   }
00171 
00176   void init_df1b2variable::operator = (double d)
00177   {
00178     //int nc=*ncopies;
00179     initialize();
00180     //*ncopies=nc;
00181     if (ind_index>=minder && ind_index<=maxder)
00182     {
00183       int offset= ind_index-minder;
00184       u_dot[offset]=1.0;
00185     }
00186     get_ind_index()=-1;
00187     *u=d;
00188   }
00189 
00194   df1b2variable::df1b2variable(const df1b2variable& v)
00195   {
00196 #if defined(__CHECK_MEMORY__)
00197     if (pchecker)
00198     {
00199       if (v.ptr == pchecker)
00200       {
00201         cout << " copy constructor called  " << endl;
00202       }
00203     }
00204 #endif
00205     if (v.ptr)
00206     {
00207       ptr=v.ptr;
00208       ncopies=v.ncopies;
00209       (*ncopies)++;
00210       u=v.u;
00211       u_dot=v.u_dot;
00212       u_bar=v.u_bar;
00213       u_dot_bar=v.u_dot_bar;
00214       u_tilde=v.u_tilde;
00215       u_dot_tilde=v.u_dot_tilde;
00216       u_bar_tilde=v.u_bar_tilde;
00217       u_dot_bar_tilde=v.u_dot_bar_tilde;
00218     }
00219     else
00220     {
00221       ptr=NULL;
00222       ncopies=NULL;
00223       u=NULL;
00224       u_dot=NULL;
00225       u_bar=NULL;
00226       u_dot_bar=NULL;
00227       u_tilde=NULL;
00228       u_dot_tilde=NULL;
00229       u_bar_tilde=NULL;
00230       u_dot_bar_tilde=NULL;
00231     }
00232   }
00233 
00234   adkludge1 * adkludgexxx;
00235 
00236 typedef init_df1b2variable * PINIT_DF1B2VARIABLE;
00237 
00242   init_df1b2variable::init_df1b2variable(double v) : df1b2variable(adkludgexxx)
00243   {
00244     ++num_variables;
00245    /*
00246     if (list==0)
00247     {
00248       list =new PINIT_DF1B2VARIABLE[max_num_init_df1b2variable];
00249     }
00250     if (++num_variables>= max_num_init_df1b2variable)
00251     {
00252       cerr << "Need to increase the maximum number of init_df1b2variables"
00253        << endl << "Use command line option -mni N" << endl;
00254     }
00255 
00256     if (num_variables>=df1b2variable::nvar)
00257     {
00258       cerr << "Maximum number of independent variables exceeded"
00259            << endl;
00260       cerr << "current max is " << df1b2variable::nvar << endl;
00261     }
00262     list[num_variables]=this;
00263     */
00264     ind_index=num_variables;
00265     *get_u()=v;
00266     if (num_variables>=minder && num_variables<=maxder)
00267     {
00268       //int offset= num_variables-minder;
00269       //u_dot[offset]=1.0;
00270     }
00271   }
00272 
00273   int no_destruct=0;
00274 
00278 df1b2variable::~df1b2variable()
00279 {
00280     deallocate();
00281 }
00282 
00286 void df1b2variable::deallocate(void)
00287 {
00288   if (ptr)
00289   {
00290 #if defined(__CHECK_MEMORY__)
00291     if (pchecker)
00292     {
00293       if (ptr == pchecker)
00294       {
00295         cout << "destructor called  " << endl;
00296       }
00297     }
00298 #endif
00299     if (ncopies && *ncopies)
00300     {
00301       (*ncopies)--;
00302     }
00303     else
00304     {
00305       if (!df1b2_gradlist::no_derivatives)
00306         f1b2gradlist->write_save_pass2_tilde_values(this);
00307       ((twointsandptr*)ptr)->ptr->free(ptr);
00308 
00309       ptr = 0;
00310     }
00311   }
00312 }
00313 
00318   void init_df1b2vector::set_value(const dvector& v)
00319   {
00320     int mmin=indexmin();
00321     int mmax=indexmax();
00322     if (v.indexmin() != mmin || v.indexmax() != mmax )
00323     {
00324       cerr << "incompatible shape in "
00325         "init_df1b2vector::set_value(const dvector& v)" << endl;
00326     }
00327 
00328     for (int i=mmin;i<=mmax;i++)
00329     {
00330       (*this)(i)=v(i);
00331     }
00332   }
00333 
00338   init_df1b2vector::init_df1b2vector(void)
00339   {
00340     allocate();
00341   }
00342 
00347   init_df1b2vector::init_df1b2vector(int lb,int ub)
00348   {
00349     allocate(lb,ub);
00350   }
00351 
00356   void init_df1b2vector::allocate(int lb,int ub)
00357   {
00358     init_df1b2variable::num_variables= 0;
00359     index_min=lb;
00360     index_max=ub;
00361     ncopies=new int;
00362     *ncopies=0;
00363     int size=indexmax()-indexmin()+1;
00364     if (init_df1b2variable::list==0)
00365     {
00366       max_num_init_df1b2variable
00367         =max(size,max_num_init_df1b2variable);
00368 
00369       init_df1b2variable::list =
00370         new PINIT_DF1B2VARIABLE [max_num_init_df1b2variable];
00371       if (init_df1b2variable::list==0)
00372       {
00373         cerr << "Error allocating memory for init_df1b2variable::list"
00374          << endl;
00375         exit(1);
00376       }
00377     }
00378 
00379   // ****************************************
00380     trueptr=new init_df1b2variable[size];
00381     if (trueptr == 0)
00382     {
00383       cerr << "Error allocating memory for init_df1b2variable"
00384            << endl;
00385       ad_exit(1);
00386     }
00387     //AD_ALLOCATE(trueptr,init_df1b2variable,size,df1b2_gradlist)
00388   // ****************************************
00389 
00390     ptr=trueptr;
00391     ptr-=lb;
00392   }
00393 
00398   void init_df1b2vector::reallocate()
00399   {
00400     int mmin=indexmin();
00401     int mmax=indexmax();
00402     for (int i=mmin;i<=mmax;i++)
00403     {
00404       ptr[i].allocate();
00405     }
00406   }
00407 
00412   void init_df1b2vector::allocate(void)
00413   {
00414     //deallocate(); a// don;t know why this was ever here DF 6june09
00415     index_min=0;
00416     index_max=-1;
00417     ncopies=0;
00418     ptr=0;
00419   }
00420 
00425   init_df1b2vector::~init_df1b2vector()
00426   {
00427     if (ncopies)
00428     {
00429       if (*ncopies)
00430         (*ncopies)--;
00431       else
00432       {
00433         if (trueptr)
00434         {
00435           delete [] trueptr;
00436           trueptr=0;
00437         }
00438         delete ncopies;
00439         ncopies=0;
00440       }
00441     }
00442   }
00443 
00448   void init_df1b2vector::deallocate(void)
00449   {
00450     if (ncopies)
00451     {
00452       if (*ncopies)
00453         (*ncopies)--;
00454       else
00455       {
00456         delete [] trueptr;
00457         trueptr=0;
00458         delete ncopies;
00459         ncopies=0;
00460       }
00461     }
00462   }
00463 
00468   init_df1b2vector::init_df1b2vector(const init_df1b2vector & v)
00469   {
00470     ncopies=v.ncopies;
00471     if (v.ncopies)
00472     {
00473       (*ncopies)++;
00474       trueptr=v.trueptr;
00475       ptr=v.ptr;
00476       index_min=v.index_min;
00477       index_max=v.index_max;
00478     }
00479     else
00480     {
00481       trueptr=0;
00482       index_min=1;
00483       index_max=0;
00484     }
00485     //cout << *ncopies << endl;
00486   }
00487 
00492   double& value(const df1b2variable& _x)
00493   {
00494     ADUNCONST(df1b2variable,x)
00495     return *x.u;
00496   }
00497 
00502   df1b2function2::df1b2function2(double (*_f)(double,double),
00503   double (*_df1)(double,double),double (*_df2)(double,double),
00504   double (*_d2f11)(double,double),
00505     double (*_d2f12)(double,double),
00506     double (*_d2f22)(double,double),
00507     double (*_d3f111)(double,double),
00508     double (*_d3f112)(double,double),
00509     double (*_d3f122)(double,double),
00510     double (*_d3f222)(double,double), const adstring& _s)
00511   {
00512     f=_f;
00513     df1=_df1; df2=_df2;
00514     d2f11=_d2f11; d2f12=_d2f12; d2f22=_d2f22;
00515     d3f111=_d3f111;
00516     d3f112=_d3f112;
00517     d3f122=_d3f122;
00518     d3f222=_d3f222;
00519     funname=_s;
00520   }
00521   typedef double (* PTDF)(double);
00522 
00527   PTDF tan_address()
00528   {
00529     return &tan;
00530   }
00531 
00536   df1b2variable df1b2function1::operator () (const df1b2variable& _x)
00537   {
00538     ADUNCONST(df1b2variable,x)
00539     df1b2variable z;
00540     double xu=*x.get_u();
00541     double * xd=x.get_u_dot();
00542     double * zd=z.get_u_dot();
00543     *z.get_u()=(*f)(xu);
00544     double dfx=(*df)(xu);
00545     for (int i=0;i<df1b2variable::nvar;i++)
00546     {
00547       *zd++ =dfx * *xd++;
00548     }
00549 
00550     // WRITE WHATEVER ON TAPE
00551     //df1b2tape->set_tapeinfo_header(&x,&z,this,xd);
00552     // save stuff for first reverse pass
00553     // need &x, &z, this,
00554     if (!df1b2_gradlist::no_derivatives)
00555     {
00556       if ((void*)(f)==tan_address())
00557         f1b2gradlist->write_pass1x(&x,&z,this);
00558       else
00559         f1b2gradlist->write_pass1(&x,&z,this);
00560     }
00561     return z;
00562   }
00563 
00568   df1b2variable df1b2function2::operator () (const df1b2variable& _x,
00569     const df1b2variable& _y)
00570   {
00571     ADUNCONST(df1b2variable,x)
00572     ADUNCONST(df1b2variable,y)
00573     df1b2variable z;
00574     double xu=*x.get_u();
00575     double yu=*y.get_u();
00576     double * xd=x.get_u_dot();
00577     double * yd=y.get_u_dot();
00578     double * zd=z.get_u_dot();
00579     *z.get_u()=(*f)(xu,yu);
00580     double dfx=(*df1)(xu,yu);
00581     double dfy=(*df2)(xu,yu);
00582     for (int i=0;i<df1b2variable::nvar;i++)
00583     {
00584       *zd++ =dfx * *xd++ + dfy * *yd++;
00585     }
00586 
00587     // WRITE WHATEVER ON TAPE
00588     if (!df1b2_gradlist::no_derivatives)
00589       f1b2gradlist->write_pass1(&x,&y,&z,this);
00590     return z;
00591   }
00592 
00597 void df1b2_gradlist::reset(void)
00598 {
00599   ncount=0;
00600   list.reset();
00601   nlist.reset();
00602   list2.reset();
00603   nlist2.reset();
00604   list3.reset();
00605   nlist3.reset();
00606 }
00607 
00612 df1b2_gradlist::df1b2_gradlist
00613 (
00614   unsigned int _bs, unsigned int _nbs,
00615   unsigned int _bs2, unsigned int _nbs2,
00616   unsigned int _bs3, unsigned int _nbs3,
00617   const adstring& _filename
00618 )
00619 {
00620   int bs=get_f1b2buffer_size("-l1");
00621   if (!bs) bs=_bs;
00622   list.allocate(bs,_filename);
00623 
00624   int nbs=get_f1b2buffer_size("-nl1");
00625   if (!nbs) nbs=_nbs;
00626   nlist.allocate(nbs,"n"+_filename);
00627 
00628   int bs2=get_f1b2buffer_size("-l2");
00629   if (!bs2) bs2=_bs2;
00630   list2.allocate(bs2,_filename+"2");
00631 
00632   int nbs2=get_f1b2buffer_size("-nl2");
00633   if (!nbs2) nbs2=_nbs2;
00634   nlist2.allocate(nbs2,"n"+_filename+"2");
00635 
00636   int bs3=get_f1b2buffer_size("-l3");
00637   if (!bs3) bs3=_bs3;
00638   list3.allocate(bs3,_filename+"3");
00639 
00640   int nbs3=get_f1b2buffer_size("-nl3");
00641   if (!nbs3) nbs3=_nbs3;
00642   nlist3.allocate(nbs3,"n"+_filename+"3");
00643 
00644   list3.set_noreadflag(1);
00645   nlist3.set_noreadflag(1);
00646 
00647   ncount=0;
00648 }
00649 /*
00650 smartlist::smartlist(void)
00651 {
00652   bufsize=0;
00653   filename=0;
00654   buffer=0;
00655   buffend=0;
00656   bptr=buffer;
00657   fp=-1;
00658 }
00659 */
00660 
00665 smartlist::smartlist(unsigned int _bufsize,const adstring& _filename)
00666 {
00667 #ifndef OPT_LIB
00668   //cerr << "need to modify smartlist class for multibyte char" << endl;
00669   assert(sizeof(char) == 1);
00670 #endif
00671 
00672   bufsize=_bufsize;
00673   filename=_filename;
00674   AD_ALLOCATE(buffer,char,bufsize,df1b2_gradlist)
00675   buffend=buffer+bufsize-1;
00676   bptr=buffer;
00677   fp = open((char*)filename,
00678     O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE);
00679   if (fp == -1)
00680   {
00681     cerr << "Error trying to open file " << filename
00682          << " in class smartlist " << endl;
00683     exit(1);
00684   }
00685 }
00686 
00687 void ad_dstar::allocate(int _n){n=_n;}
00688 
00693 ad_dstar::ad_dstar(void)
00694 {
00695   if (!n)
00696   {
00697     cerr << "need to initialize size in class ad_dstar" << endl;
00698     exit(1);
00699   }
00700   p = new double[n];
00701 }
00702 
00707 void set_dependent_variable(const df1b2variable& _x)
00708 {
00709   df1b2variable& x=(df1b2variable&) (_x);
00710   //cout << "dep " << int(x.u) << endl;
00711   for (int i=0;i<df1b2variable::nvar;i++)
00712   {
00713     x.u_dot_bar[i]=1.0;
00714   }
00715 }
00716 
00721 dmatrix get_hessian(const init_df1b2vector& _x)
00722 {
00723   ADUNCONST(init_df1b2vector,x)
00724   int nvar=df1b2variable::nvar;
00725   dmatrix h(1,nvar,1,nvar);
00726   for (int i=1;i<=nvar;i++)
00727   {
00728     for (int j=1;j<=nvar;j++)
00729     {
00730       h(i,j)=x(i).u_bar[j-1];
00731     }
00732   }
00733   return h;
00734 }
00735 
00736 typedef df1b2variable (*P_USER_FUNCTION)(const init_df1b2vector& x);
00737 
00742 double d1F(P_USER_FUNCTION pu,const init_df1b2vector& _x,int i,double _delta)
00743 {
00744   ADUNCONST(init_df1b2vector,x)
00745   double delta=.3*_delta;
00746   double xsave=value(x(i));
00747   x(i)=xsave+delta;
00748   double fp=value(pu(x));
00749   x(i)=xsave-delta;
00750   double fm=value(pu(x));
00751   x(i)=xsave;
00752   double d1fa=(fp-fm)/(2.0*delta);
00753   x(i)=xsave+2.0*delta;
00754   fp=value(pu(x));
00755   x(i)=xsave-2.0*delta;
00756   fm=value(pu(x));
00757   x(i)=xsave;
00758   double d1fb=(fp-fm)/(4.0*delta);
00759   double d1f=(8.0*d1fa-d1fb)/7.0;
00760   return d1f;
00761 }
00762 
00767 double d2F(P_USER_FUNCTION pu,const init_df1b2vector& _x,int i,int j,
00768   double delta)
00769 {
00770   ADUNCONST(init_df1b2vector,x)
00771   double xsave=value(x(i));
00772   x(i)=xsave+delta;
00773   double fp=d1F(pu,x,j,delta);
00774   x(i)=xsave-delta;
00775   double fm=d1F(pu,x,j,delta);
00776   double d1fa=(fp-fm)/(2.0*delta);
00777   x(i)=xsave+2.0*delta;
00778   fp=d1F(pu,x,j,delta);
00779   x(i)=xsave-2.0*delta;
00780   fm=d1F(pu,x,j,delta);
00781   x(i)=xsave;
00782   double d1fb=(fp-fm)/(4.0*delta);
00783   double d1f=(8.0*d1fa-d1fb)/7.0;
00784   return d1f;
00785 }
00786 
00791 double d3F(P_USER_FUNCTION pu,const init_df1b2vector& _x,int i,int j,int k,
00792   double delta)
00793 {
00794   ADUNCONST(init_df1b2vector,x)
00795   double xsave=value(x(i));
00796   x(i)=xsave+delta;
00797   double fp=d2F(pu,x,j,k,delta);
00798   x(i)=xsave-delta;
00799   double fm=d2F(pu,x,j,k,delta);
00800   x(i)=xsave;
00801   double d1f=(fp-fm)/(2.0*delta);
00802   return d1f;
00803 }
00804 
00809 dmatrix check_second_derivatives(const init_df1b2vector& x)
00810 {
00811   f1b2gradlist->set_no_derivatives();
00812   dmatrix h(1,df1b2variable::nvar,1,df1b2variable::nvar);
00813   //const double delta=1.e-3;
00814   h.initialize();
00815   int i,j;
00816   for (i=1;i<=init_df1b2variable::num_variables;i++)
00817   {
00818     for (j=1;j<=init_df1b2variable::num_variables;j++)
00819     {
00820       //h(i,j)=d2F(user_function,x,i,j,delta);
00821     }
00822   }
00823   return h;
00824 }
00825 
00830 d3_array check_third_derivatives(const init_df1b2vector& x)
00831 {
00832   f1b2gradlist->set_no_derivatives();
00833   d3_array h(1,df1b2variable::nvar,1,df1b2variable::nvar,1,df1b2variable::nvar);
00834   //const double delta=2.e-4;
00835   h.initialize();
00836   int i,j,k;
00837   for (i=1;i<=init_df1b2variable::num_variables;i++)
00838   {
00839     for (j=1;j<=init_df1b2variable::num_variables;j++)
00840     {
00841       for (k=1;k<=init_df1b2variable::num_variables;k++)
00842       {
00843         //h(i,j,k)=d3F(user_function,x,i,j,k,delta);
00844       }
00845     }
00846   }
00847   return h;
00848 }
00849 
00850 #if defined(__DERCHECK__)
00851 
00856 dercheck_info::dercheck_info(int _node_number,double _delta,int _index) :
00857   node_number(_node_number), delta(_delta), index(_index)
00858 {
00859   der_value=0.0;
00860   pass_number=0;
00861   counter=0;
00862   f1=0.0;
00863   f2=0.0;
00864 }
00865 dercheck_info * derchecker;
00866 
00867 #endif
00868 
00869 
00870 re_objective_function_value * re_objective_function_value::pobjfun=0;
00871 
00876 re_objective_function_value::re_objective_function_value(void)
00877 {
00878   pobjfun=this;
00879 }
00880 
00885 re_objective_function_value::~re_objective_function_value()
00886 {
00887   pobjfun=0;
00888 }
00889 
00894 re_objective_function_value& re_objective_function_value::operator =
00895   (const df1b2variable& v)
00896 {
00897   df1b2variable::operator = (v);
00898   return *this;
00899 }
00900 
00905 re_objective_function_value& re_objective_function_value::operator =
00906   (double v)
00907 {
00908   df1b2variable::operator = (v);
00909   return *this;
00910 }
00911 
00916 void re_objective_function_value::allocate(void)
00917 {
00918   df1b2variable::allocate();
00919 }
00920 
00925 void re_objective_function_value::allocate(const char * s)
00926 {
00927   pobjfun=this;
00928   df1b2variable::allocate();
00929 }
00930 
00931 #if !defined(OPT_LIB)
00932 
00936 init_df1b2variable& init_df1b2vector::operator () (int i)
00937 {
00938   if (i < indexmin())
00939   {
00940     ADMB_ARRAY_BOUNDS_ERROR("Index too low",
00941     "init_df1b2variable& init_df1b2vector::operator () (int i)",
00942     indexmin(), indexmax(), i);
00943   }
00944   if (i > indexmax())
00945   {
00946     ADMB_ARRAY_BOUNDS_ERROR("Index too high",
00947     "init_df1b2variable& init_df1b2vector::operator () (int i)",
00948     indexmin(), indexmax(), i);
00949   }
00950   return ptr[i];
00951 }
00952 
00957 init_df1b2variable& init_df1b2vector::operator [] (int i)
00958 {
00959   if (i < indexmin())
00960   {
00961     ADMB_ARRAY_BOUNDS_ERROR("Index too low",
00962     "init_df1b2variable& init_df1b2vector::operator [] (int i)",
00963     indexmin(), indexmax(), i);
00964   }
00965   if (i > indexmax())
00966   {
00967     ADMB_ARRAY_BOUNDS_ERROR("Index too high",
00968     "init_df1b2variable& init_df1b2vector::operator [] (int i)",
00969     indexmin(), indexmax(), i);
00970   }
00971   return ptr[i];
00972 }
00973 #endif
00974 
00977 int get_f1b2buffer_size(const char* s)
00978 {
00979   int n=0;
00980   int on1=-1;
00981   int nopt=0;
00982   if ( (on1=option_match(ad_comm::argc,ad_comm::argv,s,nopt))>-1)
00983   {
00984     if (!nopt)
00985     {
00986       cerr << "Usage " << s << " option needs integer  -- ignored" << endl;
00987     }
00988     else
00989     {
00990       n=atoi(ad_comm::argv[on1+1]);
00991     }
00992   }
00993   return n;
00994 }
00995 
01000 df1b2variable::df1b2variable(const random_effects_bounded_vector_info& rebv)
01001 {
01002   df1b2variable& v= *(rebv.pv->v+rebv.i);
01003   if (v.ptr)
01004   {
01005     ptr=v.ptr;
01006     ncopies=v.ncopies;
01007     (*ncopies)++;
01008     u=v.u;
01009     u_dot=v.u_dot;
01010     u_bar=v.u_bar;
01011     u_dot_bar=v.u_dot_bar;
01012     u_tilde=v.u_tilde;
01013     u_dot_tilde=v.u_dot_tilde;
01014     u_bar_tilde=v.u_bar_tilde;
01015     u_dot_bar_tilde=v.u_dot_bar_tilde;
01016   }
01017   else
01018   {
01019     ptr=NULL;
01020     ncopies=NULL;
01021     u=NULL;
01022     u_dot=NULL;
01023     u_bar=NULL;
01024     u_dot_bar=NULL;
01025     u_tilde=NULL;
01026     u_dot_tilde=NULL;
01027     u_bar_tilde=NULL;
01028     u_dot_bar_tilde=NULL;
01029   }
01030 }