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