ADMB Documentation  11.1.2192
 All Classes Files Functions Variables Typedefs Friends Defines
f1b23d1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f1b23d1.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 <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 ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
00142   {
00143       cerr << " Error allocating memory in df1b23array contructor\n";
00144       ad_exit(21);
00145   }
00146   v -= indexmin();
00147   for (int i=nrl; i<=nrh; i++)
00148   {
00149     v[i].allocate(ncl,nch);
00150   }
00151 }
00152 
00157 void df1b23array::allocate(int nrl,int nrh,const index_type& ncl,
00158   const index_type& nch)
00159 {
00160   index_min=nrl;
00161   index_max=nrh;
00162   int rs=size();
00163   if ( (v = new df1b2matrix[rs]) == 0)
00164   {
00165       cerr << " Error allocating memory in df1b23array contructor\n";
00166       ad_exit(21);
00167   }
00168   if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
00169   {
00170     cerr << " Error allocating memory in df1b23array contructor\n";
00171   }
00172   v -= indexmin();
00173   for (int i=nrl; i<=nrh; i++)
00174   {
00175     v[i].allocate(ad_integer(ncl(i)),ad_integer(nch(i)));
00176   }
00177 }
00178 
00183 void df1b23array::allocate(int nrl,int nrh,
00184   const index_type& ncl,const index_type& nch,
00185   const index_type& nxl,const index_type& nxh)
00186 {
00187   index_min=nrl;
00188   index_max=nrh;
00189   int rs=size();
00190   if ( (v = new df1b2matrix[rs]) == 0)
00191   {
00192       cerr << " Error allocating memory in df1b23array contructor\n";
00193       ad_exit(21);
00194   }
00195   if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
00196   {
00197     cerr << " Error allocating memory in df1b23array contructor\n";
00198   }
00199   v -= indexmin();
00200   for (int i=nrl; i<=nrh; i++)
00201   {
00202     v[i].allocate(ad_integer(ncl(i)),ad_integer(nch(i)),nxl(i),nxh(i));
00203   }
00204 }
00205 
00210 df1b23array::df1b23array(const df1b23array & x)
00211 {
00212   index_min=x.index_min;
00213   index_max=x.index_max;
00214   v=x.v;
00215   shape=x.shape;
00216   if (shape) (shape->ncopies)++;
00217 }
00218 
00223 void df1b23array::allocate(int nrl,int nrh)
00224 {
00225   index_min=nrl;
00226   index_max=nrh;
00227   int rs=size();
00228   if ( (v = new df1b2matrix[rs]) == 0)
00229   {
00230       cerr << " Error allocating memory in df1b23array contructor\n";
00231       ad_exit(21);
00232   }
00233   if ( (shape=new vector_shapex(nrl,nrh,v)) == 0)
00234   {
00235     cerr << " Error allocating memory in df1b23array contructor\n";
00236   }
00237   v -= indexmin();
00238 }
00239 
00244 df1b23array::~df1b23array()
00245 {
00246   if (shape)
00247   {
00248     if (shape->ncopies)
00249     {
00250       (shape->ncopies)--;
00251     }
00252     else
00253     {
00254       deallocate();
00255     }
00256   }
00257 }
00258 
00263 void df1b23array::deallocate()
00264 {
00265   if (shape)
00266   {
00267     v=(df1b2matrix*)(shape->trueptr);
00268     delete [] v;
00269     v=0;
00270     delete shape;
00271     shape=0;
00272   }
00273 }
00274 
00279 void df1b23array::allocate(void)
00280 {
00281   index_min=1;
00282   index_max=0;
00283   v=0;
00284   shape=0;
00285 }
00286 
00291 df1b2variable sum(const df1b23array& _x)
00292 {
00293   ADUNCONST(df1b23array,x)
00294   df1b2variable tmp;
00295   tmp=0.0;
00296   int mmin=x.indexmin();
00297   int mmax=x.indexmax();
00298   for (int i=mmin;i<=mmax;i++)
00299   {
00300     tmp+=sum(x(i));
00301   }
00302   return tmp;
00303 }
00304 
00305 #if !defined(OPT_LIB)
00306 
00311 df1b2variable& df1b23array::operator () (int i,int j,int k)
00312 {
00313   if (i < indexmin() || i > indexmax())
00314   {
00315     ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00316     "df1b2variable& df1b23array::operator () (int i,int j,int k)",
00317     indexmin(), indexmax(), i);
00318   }
00319   return v[i][j][k];
00320 }
00321 
00326 df1b2vector& df1b23array::operator () (int i,int j)
00327 {
00328   if (i < indexmin() || i > indexmax())
00329   {
00330     ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00331     "df1b2vector& df1b23array::operator () (int i,int j)",
00332     indexmin(), indexmax(), i);
00333   }
00334   return v[i][j];
00335 }
00336 
00341 df1b2matrix& df1b23array::operator () (int i)
00342 {
00343   if (i < indexmin() || i > indexmax())
00344   {
00345     ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00346     "df1b2matrix& df1b23array::operator () (int i)",
00347     indexmin(), indexmax(), i);
00348   }
00349   return v[i];
00350 }
00351 
00356 df1b2matrix& df1b23array::operator [] (int i)
00357 {
00358   if (i < indexmin() || i > indexmax())
00359   {
00360     ADMB_ARRAY_BOUNDS_ERROR("Index out of bounds",
00361     "df1b2matrix& df1b23array::operator [] (int i)",
00362     indexmin(), indexmax(), i);
00363   }
00364   return v[i];
00365 }
00366 
00367 #endif // #if !defined(OPT_LIB)
00368 
00373 void df1b23array::initialize(void)
00374 {
00375   int rmin=indexmin();
00376   int rmax=indexmax();
00377   for (int i=rmin;i<=rmax;i++)
00378   {
00379     (*this)(i).initialize();
00380   }
00381 }