ADMB Documentation  11.1.2261
 All Classes Files Functions Variables Typedefs Friends Defines
dmat10.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: dmat10.cpp 2248 2014-08-23 00:58:50Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 #include <string.h>
00013 #include <ctype.h>
00014 
00019  struct dvec_ptr_ptr
00020  {
00021    void ** m;
00022  };
00023 
00024 const int MAXROWS = 5050;
00025 
00030 void dmatrix::fill( const char * s)
00031 {
00032   #ifdef DIAG
00033     myheapcheck("Entering dmatrix(const char * s)" );
00034   #endif
00035 
00036   int n = strlen(s);
00037   int braces = 0;
00038   int nrow = 0;
00039   int ncol = 0;
00040   int mincolumn=colmin();
00041   int minrow=rowmin();
00042   rowshift(1);
00043   colshift(1);
00044 
00045   ivector columns(1, MAXROWS);
00046   ivector k1(1, MAXROWS);
00047   ivector k2(1, MAXROWS);
00048 
00049   for (int k = 0; k < n; k++)
00050   {
00051     if (s[k] == '{')
00052     {
00053       braces ++;
00054       if (braces != 1)
00055       {
00056         cerr << "Unbalanced braces in dmatrix::fill(const char * s)\n";
00057         cerr << "at character " << k << "\n";
00058         ad_exit(1);
00059       }
00060       ncol = 1;
00061       k1[nrow+1] = k;
00062     }
00063     else if (s[k] == '}')
00064     {
00065       braces --;
00066       if (braces != 0)
00067       {
00068         cerr << "Unbalanced braces in dmatrix::dmatrix(const char * s)\n";
00069         cerr << "at character " << k << "\n";
00070         ad_exit(1);
00071       }
00072       k2[nrow+1] = k;
00073       nrow ++;
00074       if (nrow > MAXROWS)
00075       {
00076         cerr << "Too many rows in dmatrix::dmatrix(const char * s)\n";
00077         ad_exit(1);
00078       }
00079       columns[nrow] = ncol;
00080     }
00081     else if (s[k] == ',')
00082     {
00083       if (braces != 0)
00084       {
00085         ncol++;
00086       }
00087     }
00088   }
00089 
00090   if (braces != 0)
00091   {
00092     cerr << "Unbalanced braces in dmatrix::dmatrix(const char * s)\n";
00093     cerr << s << "\n";
00094     ad_exit(1);
00095   }
00096 
00097   if (nrow != rowsize())
00098   {
00099     if (nrow < rowsize())
00100     {
00101       cerr << " Not enough rows in the data for dmatrix::fill(const char *) \n";
00102       ad_exit(1);
00103     }
00104     else
00105     {
00106       cerr << " Too many rows in the data for dmatrix::fill(const char *) \n";
00107       ad_exit(1);
00108     }
00109   }
00110 
00111   int i;
00112   for (i=1; i<=nrow; i++)
00113   {
00114     cout << "row  " << i << " matrix  "
00115        << ((*this)[rowmin()+i-1]).size()
00116        << "  colvector " << columns[i] << "\n";
00117 
00118     if ( ((*this)[rowmin()+i-1]).size() != columns[i])
00119     {
00120       if ( ((*this)[rowmin()+i-1]).size() > columns[i])
00121       {
00122         cerr << " Not enough columns in the data in row "
00123              << i << " for dmatrix::fill(const char *) \n";
00124         ad_exit(1);
00125       }
00126       else
00127       {
00128         cerr << " Too many columns in the data in row "
00129              << i << " for dmatrix::fill(const char *) \n";
00130         ad_exit(1);
00131       }
00132     }
00133   }
00134 
00135   for (i=rowmin(); i<=rowmax(); i++)
00136   {
00137     char *t = new char[strlen(s)+1];
00138     //t = (char*) new[strlen(s)+1];
00139 
00140     for (int k = k1[i]; k <= k2[i]; k++)
00141     {
00142       t[k-k1[i]] = s[k];
00143     }
00144     t[k2[i]-k1[i]+1] = '\0';
00145 
00146     dvector tt(t);
00147     tt.shift(( (*this)(i)).indexmin() );
00148 
00149    //    (*this)(i)=dvector(tt);
00150     (*this)(i)=tt;
00151 
00152     delete[] t;
00153     t = 0;
00154   }
00155   rowshift(minrow);
00156   colshift(mincolumn);
00157 }