ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_m10.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include "fvar.hpp"
12 
13 #ifdef __TURBOC__
14  #pragma hdrstop
15  #include <iostream.h>
16 #endif
17 
18 #ifdef __ZTC__
19  #include <iostream.hpp>
20 #endif
21 
22 #include <string.h>
23 #include <ctype.h>
24 #ifndef OPT_LIB
25  #include <cassert>
26  #include <climits>
27 #endif
28 
33  struct dvec_ptr_ptr
34  {
35  void ** m;
36  };
37 
38 const int MAXROWS = 5050;
39 
50 void dvar_matrix::fill(const char* s)
51 {
52  const size_t len = strlen(s);
53 #ifndef OPT_LIB
54  assert(len <= INT_MAX);
55 #endif
56  int n = static_cast<int>(len);
57  int braces = 0;
58  int nrow = 0;
59  int ncol = 0;
60 
61  ivector columns(1, MAXROWS);
62  ivector k1(1, MAXROWS);
63  ivector k2(1, MAXROWS);
64 
65  for (int k = 0; k < n; k++)
66  {
67  if (s[k] == '{')
68  {
69  braces ++;
70  if (braces != 1)
71  {
72  cerr << "Unbalanced braces in dvar_matrix::fill(const char * s)\n";
73  cerr << "at character " << k << "\n";
74  ad_exit(1);
75  }
76  ncol = 1;
77  k1[nrow+1] = k;
78  }
79  else if (s[k] == '}')
80  {
81  braces --;
82  if (braces != 0)
83  {
84  cerr << "Unbalanced braces in dvar_matrix::fill(const char * s)\n";
85  cerr << "at character " << k << "\n";
86  ad_exit(1);
87  }
88  k2[nrow+1] = k;
89  nrow ++;
90  if (nrow > MAXROWS)
91  {
92  cerr << "Too many rows in dvar_matrix::fill(const char * s)\n";
93  ad_exit(1);
94  }
95  columns[nrow] = ncol;
96  }
97  else if (s[k] == ',')
98  {
99  if (braces != 0)
100  {
101  ncol++;
102  }
103  }
104  }
105 
106  if (braces != 0)
107  {
108  cerr << "Unbalanced braces in dvar_matrix::fill(const char * s)\n";
109  cerr << s << "\n";
110  ad_exit(1);
111  }
112 
113 #if defined(__cplusplus) && (__cplusplus >= 201103L)
114  [](unsigned int nrow, unsigned int rowsize)
115  {
116  if (nrow != rowsize)
117  {
118  if (nrow < rowsize)
119  {
120  cerr << " Not enough rows in the data for "
121  "dvar_matrix::fill(const char*)\n";
122  ad_exit(1);
123  }
124  else
125  {
126  cerr << " Too many rows in the data for "
127  "dvar_matrix::fill(const char*)\n";
128  ad_exit(1);
129  }
130  }
131  } (static_cast<unsigned int>(nrow), rowsize());
132 #endif
133 
134  int i;
135  for (i=1; i<=nrow; i++)
136  {
137  unsigned int size = ((*this)[rowmin()+i-1]).size();
138  unsigned int column = static_cast<unsigned int>(columns[i]);
139  if (size > column)
140  {
141  cerr << " Not enough columns in the data in row "
142  << i << " for dvar_matrix::fill(const char *) \n";
143  ad_exit(1);
144  }
145  else if (size < column)
146  {
147  cerr << " Too many columns in the data in row "
148  << i << " for dvar_matrix::fill(const char *) \n";
149  ad_exit(1);
150  }
151  }
152 
153  for (i=rowmin(); i<=rowmax(); i++)
154  {
155  char * t;
156 // t = (char*) new[strlen(s)+1];
157  t = new char[strlen(s)+1];
158 
159  for (int k = k1[i]; k <= k2[i]; k++)
160  {
161  t[k-k1[i]] = s[k];
162  }
163  t[k2[i]-k1[i]+1] = '\0';
164 
165  dvector tt(t);
166  tt.shift(( (*this)(i)).indexmin() );
167 
168  (*this)(i)=tt;
169 
170  delete[] t;
171  t = 0;
172  }
173 }
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat.cpp:11
int rowmax(void) const
Definition: fvar.hpp:2564
void ** m
Definition: dmat.cpp:13
Vector of double precision numbers.
Definition: dvector.h:50
exitptr ad_exit
Definition: gradstrc.cpp:53
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int rowmin(void) const
Definition: fvar.hpp:2560
dvector & shift(int min)
Shift valid range of subscripts.
Definition: dvector.cpp:52
const int MAXROWS
Definition: dmat_io2.cpp:72
unsigned int rowsize() const
Definition: fvar.hpp:2578
dvector column(const dmatrix &matrix, int j)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat6.cpp:13
void fill(const char *)
Fill values of dvar_matrix with text input from s with format rowmin...rowmax where ith row is {colmi...
Definition: fvar_m10.cpp:50
int indexmin(void) const
Definition: fvar.hpp:2568