ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
dmat_a.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 "fvar.hpp"
00012 
00017  struct dvec_ptr_ptr
00018  {
00019    void ** m;
00020  };
00021 
00026  dmatrix::dmatrix(const dvar_matrix_position& pos)
00027  {
00028    int nrl=pos.row_min;
00029    int nrh=pos.row_max;
00030    const ivector& ncl=pos.lb;
00031    const ivector& nch=pos.ub;
00032    #ifdef DIAG
00033      myheapcheck("Entering dmatrix(nrl,nrh,ncl,nch)" );
00034    #endif
00035    if (nrl !=ncl.indexmin() || nrh !=ncl.indexmax() ||
00036      nrl !=nch.indexmin() || nrh !=nch.indexmax())
00037    {
00038      cerr << "Incompatible array bounds in "
00039      "dmatrix(int nrl,int nrh, const ivector& ncl, const ivector& nch)\n";
00040      ad_exit(1);
00041    }
00042    index_min=nrl;
00043    index_max=nrh;
00044 
00045    int rs=rowsize();
00046    if ( (m = new dvector [rs]) == 0)
00047    {
00048      cerr << " Error allocating memory in dmatrix contructor\n";
00049      ad_exit(21);
00050    }
00051    if ( (shape = new mat_shapex(m))== 0)
00052    {
00053      cerr << " Error allocating memory in dmatrix contructor\n";
00054      ad_exit(21);
00055    }
00056 
00057 
00058    #ifdef DIAG
00059      cerr << "Created a dmatrix with adress "<< farptr_tolong(m)<<"\n";
00060    #endif
00061 
00062    m -= rowmin();
00063 
00064    for (int i=rowmin(); i<=rowmax(); i++)
00065    {
00066      m[i].allocate(ncl[i],nch[i]);
00067      #ifdef DIAG
00068        cerr << "Created a dvector with address "<< farptr_tolong(*(m+i))<<"\n";
00069      #endif
00070    }
00071    #ifdef DIAG
00072      myheapcheck("Leaving dmatrix(nrl,nrh,ncl,nch)" );
00073    #endif
00074  }
00075 
00080  dmatrix::dmatrix(const dmatrix_position& pos)
00081  {
00082    int nrl=pos.row_min;
00083    int nrh=pos.row_max;
00084    const ivector& ncl=pos.lb;
00085    const ivector& nch=pos.ub;
00086    #ifdef DIAG
00087      myheapcheck("Entering dmatrix(nrl,nrh,ncl,nch)" );
00088    #endif
00089    if (nrl !=ncl.indexmin() || nrh !=ncl.indexmax() ||
00090      nrl !=nch.indexmin() || nrh !=nch.indexmax())
00091    {
00092      cerr << "Incompatible array bounds in "
00093      "dmatrix(int nrl,int nrh, const ivector& ncl, const ivector& nch)\n";
00094      ad_exit(1);
00095    }
00096    index_min=nrl;
00097    index_max=nrh;
00098 
00099    int rs=rowsize();
00100    if ( (m = new dvector [rs]) == 0)
00101    {
00102      cerr << " Error allocating memory in dmatrix contructor\n";
00103      ad_exit(21);
00104    }
00105 
00106    if ( (shape = new mat_shapex(m))== 0)
00107    {
00108      cerr << " Error allocating memory in dmatrix contructor\n";
00109      ad_exit(21);
00110    }
00111 
00112    #ifdef DIAG
00113      cerr << "Created a dmatrix with adress "<< farptr_tolong(m)<<"\n";
00114    #endif
00115 
00116    m -= rowmin();
00117 
00118    for (int i=rowmin(); i<=rowmax(); i++)
00119    {
00120      m[i].allocate(ncl[i],nch[i]);
00121    }
00122    #ifdef DIAG
00123      myheapcheck("Leaving dmatrix(nrl,nrh,ncl,nch)" );
00124    #endif
00125  }