ADMB Documentation  11.1.2192
 All Classes Files Functions Variables Typedefs Friends Defines
dmat10.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: dmat10.cpp 1112 2013-07-12 21:41:41Z 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 
00015 const unsigned int MAX_LINE_LENGTH = 10000;
00016 const int MAX_FIELD_LENGTH = 500;
00017 const int MAX_NUMBER_COLUMNS = 6550;
00018 const int MAX_NUMBER_ROWS = 6550;
00019 
00024  struct dvec_ptr_ptr
00025  {
00026    void ** m;
00027  };
00028 
00029 const int MAXROWS = 5050;
00030 
00035 void dmatrix::fill( const char * s)
00036 {
00037   #ifdef DIAG
00038     myheapcheck("Entering dmatrix(const char * s)" );
00039   #endif
00040 
00041   int n = strlen(s);
00042   int braces = 0;
00043   int nrow = 0;
00044   int ncol = 0;
00045   int mincolumn=colmin();
00046   int minrow=rowmin();
00047   rowshift(1);
00048   colshift(1);
00049 
00050   ivector columns(1, MAXROWS);
00051   ivector k1(1, MAXROWS);
00052   ivector k2(1, MAXROWS);
00053 
00054   int k;
00055   for (k = 0; k < n; k++)
00056   {
00057     if (s[k] == '{')
00058     {
00059       braces ++;
00060       if (braces != 1)
00061       {
00062         cerr << "Unbalanced braces in dmatrix::fill(const char * s)\n";
00063         cerr << "at character " << k << "\n";
00064         ad_exit(1);
00065       }
00066       ncol = 1;
00067       k1[nrow+1] = k;
00068     }
00069     else if (s[k] == '}')
00070     {
00071       braces --;
00072       if (braces != 0)
00073       {
00074         cerr << "Unbalanced braces in dmatrix::dmatrix(const char * s)\n";
00075         cerr << "at character " << k << "\n";
00076         ad_exit(1);
00077       }
00078       k2[nrow+1] = k;
00079       nrow ++;
00080       if (nrow > MAXROWS)
00081       {
00082         cerr << "Too many rows in dmatrix::dmatrix(const char * s)\n";
00083         ad_exit(1);
00084       }
00085       columns[nrow] = ncol;
00086     }
00087     else if (s[k] == ',')
00088     {
00089       if (braces != 0)
00090       {
00091         ncol++;
00092       }
00093     }
00094   }
00095 
00096   if (braces != 0)
00097   {
00098     cerr << "Unbalanced braces in dmatrix::dmatrix(const char * s)\n";
00099     cerr << s << "\n";
00100     ad_exit(1);
00101   }
00102 
00103   if (nrow != rowsize())
00104   {
00105     if (nrow < rowsize())
00106     {
00107       cerr << " Not enough rows in the data for dmatrix::fill(const char *) \n";
00108       ad_exit(1);
00109     }
00110     else
00111     {
00112       cerr << " Too many rows in the data for dmatrix::fill(const char *) \n";
00113       ad_exit(1);
00114     }
00115   }
00116 
00117   int i;
00118   for (i=1; i<=nrow; i++)
00119   {
00120     cout << "row  " << i << " matrix  "
00121        << ((*this)[rowmin()+i-1]).size()
00122        << "  colvector " << columns[i] << "\n";
00123 
00124     if ( ((*this)[rowmin()+i-1]).size() != columns[i])
00125     {
00126       if ( ((*this)[rowmin()+i-1]).size() > columns[i])
00127       {
00128         cerr << " Not enough columns in the data in row "
00129              << i << " for dmatrix::fill(const char *) \n";
00130         ad_exit(1);
00131       }
00132       else
00133       {
00134         cerr << " Too many columns in the data in row "
00135              << i << " for dmatrix::fill(const char *) \n";
00136         ad_exit(1);
00137       }
00138     }
00139   }
00140 
00141   k = 0;
00142   for (i=rowmin(); i<=rowmax(); i++)
00143   {
00144     char *t = new char[strlen(s)+1];
00145     //t = (char*) new[strlen(s)+1];
00146 
00147     for (k = k1[i]; k <= k2[i]; k++)
00148     {
00149       t[k-k1[i]] = s[k];
00150     }
00151     t[k2[i]-k1[i]+1] = '\0';
00152 
00153     dvector tt(t);
00154     tt.shift(( (*this)(i)).indexmin() );
00155 
00156    //    (*this)(i)=dvector(tt);
00157     (*this)(i)=tt;
00158 
00159     delete[] t;
00160     t = 0;
00161   }
00162   rowshift(minrow);
00163   colshift(mincolumn);
00164 }