ADMB Documentation  11.1.1920
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_m10.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_m10.cpp 1919 2014-04-22 22:02:01Z 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 
00025 const unsigned int MAX_LINE_LENGTH = 10000;
00026 const int MAX_FIELD_LENGTH = 500;
00027 const int MAX_NUMBER_COLUMNS = 6550;
00028 const int MAX_NUMBER_ROWS = 6550;
00029 
00034  struct dvec_ptr_ptr
00035  {
00036    void ** m;
00037  };
00038 
00039 const int MAXROWS = 5050;
00040 
00045 void dvar_matrix::fill( const char * s)
00046 {
00047   int n = strlen(s);
00048   int braces = 0;
00049   int nrow = 0;
00050   int ncol = 0;
00051 
00052   ivector columns(1, MAXROWS);
00053   ivector k1(1, MAXROWS);
00054   ivector k2(1, MAXROWS);
00055 
00056   int k;
00057   for (k = 0; k < n; k++)
00058   {
00059     if (s[k] == '{')
00060     {
00061       braces ++;
00062       if (braces != 1)
00063       {
00064         cerr << "Unbalanced braces in dvar_matrix::fill(const char * s)\n";
00065         cerr << "at character " << k << "\n";
00066         ad_exit(1);
00067       }
00068       ncol = 1;
00069       k1[nrow+1] = k;
00070     }
00071     else if (s[k] == '}')
00072     {
00073       braces --;
00074       if (braces != 0)
00075       {
00076         cerr << "Unbalanced braces in dvar_matrix::fill(const char * s)\n";
00077         cerr << "at character " << k << "\n";
00078         ad_exit(1);
00079       }
00080       k2[nrow+1] = k;
00081       nrow ++;
00082       if (nrow > MAXROWS)
00083       {
00084         cerr << "Too many rows in dvar_matrix::fill(const char * s)\n";
00085         ad_exit(1);
00086       }
00087       columns[nrow] = ncol;
00088     }
00089     else if (s[k] == ',')
00090     {
00091       if (braces != 0)
00092       {
00093         ncol++;
00094       }
00095     }
00096   }
00097 
00098   if (braces != 0)
00099   {
00100     cerr << "Unbalanced braces in dvar_matrix::fill(const char * s)\n";
00101     cerr << s << "\n";
00102     ad_exit(1);
00103   }
00104 
00105   if (nrow != rowsize())
00106   {
00107     if (nrow < rowsize())
00108     {
00109       cerr << " Not enough rows in the data for "
00110       "dvar_matrix::fill(const char *) \n";
00111       ad_exit(1);
00112     }
00113     else
00114     {
00115       cerr << " Too many rows in the data for "
00116       "dvar_matrix::fill(const char *) \n";
00117       ad_exit(1);
00118     }
00119   }
00120 
00121   int i;
00122   for (i=1; i<=nrow; i++)
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 dvar_matrix::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 dvar_matrix::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;
00145 //    t = (char*) new[strlen(s)+1];
00146     t = new char[strlen(s)+1];
00147 
00148     for (k = k1[i]; k <= k2[i]; k++)
00149     {
00150       t[k-k1[i]] = s[k];
00151     }
00152     t[k2[i]-k1[i]+1] = '\0';
00153 
00154     dvector tt(t);
00155     tt.shift(( (*this)(i)).indexmin() );
00156 
00157     (*this)(i)=tt;
00158 
00159     delete[] t;
00160     t = 0;
00161   }
00162 }