ADMB Documentation  11.1.2493
 All Classes Files Functions Variables Typedefs Friends Defines
model45.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: model45.cpp 2385 2014-09-19 21:15:35Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include <admodel.h>
00008 
00009 void param_init_bounded_vector_vector::set_initial_value(
00010   const double_index_type& _it)
00011  {
00012     it=new double_index_type(_it);
00013  }
00014 
00018 param_init_bounded_vector_vector::param_init_bounded_vector_vector():
00019   v(NULL),
00020   index_min(0),
00021   index_max(0),
00022   it(NULL)
00023 {
00024 }
00025 
00026 void param_init_bounded_vector_vector::allocate(
00027   int min1,
00028   int max1,
00029   const index_type& min,
00030   const index_type& max,
00031   const double_index_type& dmin,
00032   const double_index_type& dmax,
00033   const char* s)
00034 {
00035   allocate(min1,max1,min,max,dmin,dmax,1,s);
00036 }
00037 
00038 void param_init_bounded_vector_vector::allocate(
00039   int min1,
00040   int max1,
00041   const index_type& min,
00042   const index_type& max,
00043   const double_index_type& dmin,
00044   const double_index_type& dmax,
00045   const index_type& phase_start,
00046   const char* s)
00047 {
00048   int size = max1 - min1 + 1;
00049   if (size > 0)
00050   {
00051     v = new param_init_bounded_vector[size];
00052     if (!v)
00053     {
00054         cerr << " error trying to allocate memory in "
00055           "param_init_vector_vector " << endl;
00056         exit(1);
00057     }
00058 
00059     index_min=min1;
00060     index_max=max1;
00061     v-=indexmin();
00062     for (int i=indexmin();i<=indexmax();i++)
00063     {
00064       if (it) v[i].set_initial_value(ad_double((*it)[i]));
00065       adstring ss=s + adstring("[") + str(i) + adstring("]");
00066       v[i].allocate(ad_integer(min[i]),ad_integer(max[i]),
00067          ad_double(dmin[i]),ad_double(dmax[i]),
00068          ad_integer(phase_start[i]),(char*)(ss) );
00069     }
00070   }
00071 }
00075 param_init_bounded_vector_vector::~param_init_bounded_vector_vector()
00076 {
00077   deallocate();
00078 }
00082 void param_init_bounded_vector_vector::deallocate(void)
00083 {
00084   if (it)
00085   {
00086     delete it;
00087     it = NULL;
00088   }
00089   if (v)
00090   {
00091     v += indexmin();
00092     delete [] v;
00093     v = NULL;
00094   }
00095 }