ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dmat10.cpp
Go to the documentation of this file.
1 
5 #include "fvar.hpp"
6 #include <string.h>
7 #include <ctype.h>
8 #include <cassert>
9 #include <climits>
10 
15  struct dvec_ptr_ptr
16  {
17  void ** m;
18  };
19 
29 void dmatrix::fill(const char* s)
30 {
31  #ifdef DIAG
32  myheapcheck("Entering dmatrix(const char * s)" );
33  #endif
34 
35  size_t len = strlen(s);
36  assert(len <= INT_MAX);
37  int n = static_cast<int>(len);
38  int braces = 0;
39  int nrow = 0;
40  int ncol = 0;
41  int mincolumn=colmin();
42  int minrow=rowmin();
43  rowshift(1);
44  colshift(1);
45 
46  const int MAXROWS = 5050;
47  ivector columns(1, MAXROWS);
48  ivector k1(1, MAXROWS);
49  ivector k2(1, MAXROWS);
50 
51  for (int k = 0; k < n; k++)
52  {
53  if (s[k] == '{')
54  {
55  braces ++;
56  if (braces != 1)
57  {
58  cerr << "Unbalanced braces in dmatrix::fill(const char * s)\n";
59  cerr << "at character " << k << "\n";
60  ad_exit(1);
61  }
62  ncol = 1;
63  k1[nrow+1] = k;
64  }
65  else if (s[k] == '}')
66  {
67  braces --;
68  if (braces != 0)
69  {
70  cerr << "Unbalanced braces in dmatrix::dmatrix(const char * s)\n";
71  cerr << "at character " << k << "\n";
72  ad_exit(1);
73  }
74  k2[nrow+1] = k;
75  nrow ++;
76  if (nrow > MAXROWS)
77  {
78  cerr << "Too many rows in dmatrix::dmatrix(const char * s)\n";
79  ad_exit(1);
80  }
81  columns[nrow] = ncol;
82  }
83  else if (s[k] == ',')
84  {
85  if (braces != 0)
86  {
87  ncol++;
88  }
89  }
90  }
91 
92  if (braces != 0)
93  {
94  cerr << "Unbalanced braces in dmatrix::dmatrix(const char * s)\n";
95  cerr << s << "\n";
96  ad_exit(1);
97  }
98 
99  {
100  unsigned int _nrow = static_cast<unsigned int>(nrow);
101  unsigned int _rowsize = rowsize();
102  if (_nrow < _rowsize)
103  {
104  cerr << " Not enough rows in the data for dmatrix::fill(const char *) \n";
105  ad_exit(1);
106  }
107  else if (_nrow > _rowsize)
108  {
109  cerr << " Too many rows in the data for dmatrix::fill(const char *) \n";
110  ad_exit(1);
111  }
112  }
113 
114  for (int i=1; i<=nrow; i++)
115  {
116  int index = rowmin() + i - 1;
117  unsigned int size = ((*this)[index]).size();
118  unsigned int cols = static_cast<unsigned int>(columns[i]);
119  cout << "row " << i << " matrix " << size << " colvector " << cols << "\n";
120 
121  if (size > cols)
122  {
123  cerr << " Not enough columns in the data in row "
124  << i << " for dmatrix::fill(const char *) \n";
125  ad_exit(1);
126  }
127  else if (size < cols)
128  {
129  cerr << " Too many columns in the data in row "
130  << i << " for dmatrix::fill(const char *) \n";
131  ad_exit(1);
132  }
133  }
134 
135  for (int i=rowmin(); i<=rowmax(); i++)
136  {
137  char *t = new char[strlen(s)+1];
138  //t = (char*) new[strlen(s)+1];
139 
140  for (int k = k1[i]; k <= k2[i]; k++)
141  {
142  t[k-k1[i]] = s[k];
143  }
144  t[k2[i]-k1[i]+1] = '\0';
145 
146  dvector tt(t);
147  tt.shift(( (*this)(i)).indexmin() );
148 
149  // (*this)(i)=dvector(tt);
150  (*this)(i)=tt;
151 
152  delete[] t;
153  t = 0;
154  }
155  rowshift(minrow);
156  colshift(mincolumn);
157 }
void myheapcheck(char *msg)
Does nothing.
Definition: dvector.cpp:669
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat.cpp:11
void ** m
Definition: dmat.cpp:13
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Definition: fvar.hpp:2917
exitptr ad_exit
Definition: gradstrc.cpp:53
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
int rowmax() const
Definition: fvar.hpp:2929
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int colmin(void) const
Definition: fvar.hpp:2939
dvector & shift(int min)
Shift valid range of subscripts.
Definition: dvector.cpp:52
const int MAXROWS
Definition: dmat_io2.cpp:72
void rowshift(int min)
Changes the range of valid indices for the rows.
Definition: dmat9.cpp:48
void colshift(int min)
Description not yet available.
Definition: dmat9.cpp:68
unsigned int rowsize() const
Definition: fvar.hpp:2934
void fill(const char *)
Fill allocated dmatrix with values from input parameter s.
Definition: dmat10.cpp:29
int rowmin() const
Definition: fvar.hpp:2925