ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
f1b23d1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <df1b2fun.h>
00012 #include "admb_messages.h"
00013 
00018 df1b23array::df1b23array(int nrl,int nrh,int ncl,int nch,int nxl,int nxh)
00019 {
00020   if (nrl>nrh)
00021   {
00022     allocate();
00023   }
00024   else
00025   {
00026     allocate(nrl,nrh,ncl,nch,nxl,nxh);
00027   }
00028 }
00029 
00034 df1b23array::df1b23array(int nrl,int nrh,int ncl,int nch)
00035 {
00036   if (nrl>nrh)
00037   {
00038     allocate();
00039   }
00040   else
00041   {
00042     allocate(nrl,nrh,ncl,nch);
00043   }
00044 }
00045 
00050 df1b23array::df1b23array(int nrl,int nrh)
00051 {
00052   if (nrl>nrh)
00053   {
00054     allocate();
00055   }
00056   else
00057   {
00058     allocate(nrl,nrh);
00059   }
00060 }
00061 
00066 df1b23array::df1b23array(void)
00067 {
00068   allocate();
00069 }
00070 
00075 void df1b23array::allocate(int nrl,int nrh,int ncl,int nch,
00076   int nxl,int nxh,const char * s)
00077 {
00078   allocate(nrl,nrh,ncl,nch,nxl,nxh);
00079 }
00080 
00081 /*
00082 void df1b23array::allocate(int nrl,int nrh,int ncl,int nch,const char * s)
00083 {
00084   allocate(nrl,nrh,ncl,nch);
00085 }
00086 
00087 void df1b23array::allocate(int nrl,int nrh,const index_type& ncl,
00088   const index_type& nch,const char * s)
00089 {
00090   allocate(nrl,nrh,ncl,nch);
00091 }
00092 */
00093 
00098 void df1b23array::allocate(int nrl,int nrh,
00099   const index_type& ncl, const index_type& nch,
00100   const index_type& nxl, const index_type& nxh,
00101   const char * s)
00102 {
00103   allocate(nrl,nrh,ncl,nch,nxl,nxh);
00104 }
00105 
00110 void df1b23array::allocate(int nrl,int nrh,int ncl,int nch,
00111   int nxl,int nxh)
00112 {
00113   index_min=nrl;
00114   index_max=nrh;
00115   int rs=size();
00116   if ( (v = new df1b2matrix[rs]) == 0)
00117   {
00118       cerr << " Error allocating memory in df1b23array contructor\n";
00119       ad_exit(21);
00120   }
00121   if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
00122   {
00123     cerr << " Error allocating memory in df1b23array contructor\n";
00124   }
00125   v -= indexmin();
00126   for (int i=nrl; i<=nrh; i++)
00127   {
00128     v[i].allocate(ncl,nch,nxl,nxh);
00129   }
00130 }
00131 
00136 void df1b23array::allocate(int nrl,int nrh,int ncl,int nch)
00137 {
00138   index_min=nrl;
00139   index_max=nrh;
00140   int rs=size();
00141   if ( (v = new df1b2matrix[rs]) == 0)
00142   {
00143       cerr << " Error allocating memory in df1b23array contructor\n";
00144       ad_exit(21);
00145   }
00146   if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
00147   {
00148       cerr << " Error allocating memory in df1b23array contructor\n";
00149       ad_exit(21);
00150   }
00151   v -= indexmin();
00152   for (int i=nrl; i<=nrh; i++)
00153   {
00154     v[i].allocate(ncl,nch);
00155   }
00156 }
00157 
00162 void df1b23array::allocate(int nrl,int nrh,const index_type& ncl,
00163   const index_type& nch)
00164 {
00165   index_min=nrl;
00166   index_max=nrh;
00167   int rs=size();
00168   if ( (v = new df1b2matrix[rs]) == 0)
00169   {
00170       cerr << " Error allocating memory in df1b23array contructor\n";
00171       ad_exit(21);
00172   }
00173   if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
00174   {
00175     cerr << " Error allocating memory in df1b23array contructor\n";
00176   }
00177   v -= indexmin();
00178   for (int i=nrl; i<=nrh; i++)
00179   {
00180     v[i].allocate(ad_integer(ncl(i)),ad_integer(nch(i)));
00181   }
00182 }
00183 
00188 void df1b23array::allocate(int nrl,int nrh,
00189   const index_type& ncl,const index_type& nch,
00190   const index_type& nxl,const index_type& nxh)
00191 {
00192   index_min=nrl;
00193   index_max=nrh;
00194   int rs=size();
00195   if ( (v = new df1b2matrix[rs]) == 0)
00196   {
00197       cerr << " Error allocating memory in df1b23array contructor\n";
00198       ad_exit(21);
00199   }
00200   if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
00201   {
00202     cerr << " Error allocating memory in df1b23array contructor\n";
00203   }
00204   v -= indexmin();
00205   for (int i=nrl; i<=nrh; i++)
00206   {
00207     v[i].allocate(ad_integer(ncl(i)),ad_integer(nch(i)),nxl(i),nxh(i));
00208   }
00209 }
00210 
00215 df1b23array::df1b23array(const df1b23array & x)
00216 {
00217   index_min=x.index_min;
00218   index_max=x.index_max;
00219   v=x.v;
00220   shape=x.shape;
00221   if (shape) (shape->ncopies)++;
00222 }
00223 
00228 void df1b23array::allocate(int nrl,int nrh)
00229 {
00230   index_min=nrl;
00231   index_max=nrh;
00232   int rs=size();
00233   if ( (v = new df1b2matrix[rs]) == 0)
00234   {
00235       cerr << " Error allocating memory in df1b23array contructor\n";
00236       ad_exit(21);
00237   }
00238   if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
00239   {
00240     cerr << " Error allocating memory in df1b23array contructor\n";
00241   }
00242   v -= indexmin();
00243 }
00244 
00248 df1b23array::~df1b23array()
00249 {
00250   if (shape)
00251   {
00252     if (shape->ncopies)
00253     {
00254       (shape->ncopies)--;
00255     }
00256     else
00257     {
00258       deallocate();
00259     }
00260   }
00261 }
00265 void df1b23array::deallocate()
00266 {
00267   if (shape)
00268   {
00269     v=(df1b2matrix*)(shape->trueptr);
00270     delete [] v;
00271     v=0;
00272     delete shape;
00273     shape=0;
00274     index_min=1;
00275     index_max=0;
00276   }
00277 }
00281 void df1b23array::allocate(void)
00282 {
00283   index_min=1;
00284   index_max=0;
00285   v=0;
00286   shape=0;
00287 }
00288 
00293 df1b2variable sum(const df1b23array& _x)
00294 {
00295   ADUNCONST(df1b23array,x)
00296   df1b2variable tmp;
00297   tmp=0.0;
00298   int mmin=x.indexmin();
00299   int mmax=x.indexmax();
00300   for (int i=mmin;i<=mmax;i++)
00301   {
00302     tmp+=sum(x(i));
00303   }
00304   return tmp;
00305 }
00306 
00307 #if !defined(OPT_LIB)
00308 
00313 df1b2variable& df1b23array::operator () (int i,int j,int k)
00314 {
00315   if (i < indexmin() || i > indexmax())
00316   {
00317     ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00318     "df1b2variable& df1b23array::operator () (int i,int j,int k)",
00319     indexmin(), indexmax(), i);
00320   }
00321   return v[i][j][k];
00322 }
00323 
00328 df1b2vector& df1b23array::operator () (int i,int j)
00329 {
00330   if (i < indexmin() || i > indexmax())
00331   {
00332     ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00333     "df1b2vector& df1b23array::operator () (int i,int j)",
00334     indexmin(), indexmax(), i);
00335   }
00336   return v[i][j];
00337 }
00338 
00343 df1b2matrix& df1b23array::operator () (int i)
00344 {
00345   if (i < indexmin() || i > indexmax())
00346   {
00347     ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00348     "df1b2matrix& df1b23array::operator () (int i)",
00349     indexmin(), indexmax(), i);
00350   }
00351   return v[i];
00352 }
00353 
00358 df1b2matrix& df1b23array::operator [] (int i)
00359 {
00360   if (i < indexmin() || i > indexmax())
00361   {
00362     ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00363     "df1b2matrix& df1b23array::operator [] (int i)",
00364     indexmin(), indexmax(), i);
00365   }
00366   return v[i];
00367 }
00368 
00369 #endif // #if !defined(OPT_LIB)
00370 
00375 void df1b23array::initialize(void)
00376 {
00377   int rmin=indexmin();
00378   int rmax=indexmax();
00379   for (int i=rmin;i<=rmax;i++)
00380   {
00381     (*this)(i).initialize();
00382   }
00383 }