11 #define __USE_IOSTREAM__
15 #if defined(__TURBOC__)
28 #include <strstream.h>
32 #include <iostream.hpp>
34 #include <sstream.hpp>
36 #include <strstream.h>
61 const int& line_length);
85 const int n = (int)strlen(s);
87 const size_t len = strlen(s);
88 assert(len <= INT_MAX);
89 const int n = (int)len;
99 for (
int k = 0; k < n; k++)
106 cerr <<
"Unbalanced braces in dmatrix::dmatrix( char * s)\n";
107 cerr <<
"at character " << k <<
"\n";
113 else if (s[k] ==
'}')
118 cerr <<
"Unbalanced braces in dmatrix::dmatrix( char * s)\n";
119 cerr <<
"at character " << k <<
"\n";
126 cerr <<
"Too many rows in dmatrix::dmatrix( char * s)\n";
129 columns[nrow] = ncol;
131 else if (s[k] ==
',')
142 cerr <<
"Unbalanced braces in dmatrix::dmatrix(char * s)\n";
151 for (
int i=1; i<=nrow; i++)
160 cerr <<
" Error allocating memory in dmatrix contructor\n";
165 cerr <<
" Error allocating memory in dmatrix contructor\n";
171 cerr <<
"Created a dmatrix with adress "<< farptr_tolong(
m)<<
"\n";
177 char *t =
new char[strlen(s)+1];
180 for (
int k = k1[i]; k <= k2[i]; k++)
184 t[k2[i]-k1[i]+1] =
'\0';
194 ifstream infile(filename);
197 cerr <<
"Error opening file " << filename <<
" in dmatrix constructor "
198 <<
"dmatrix::dmatrix(char * filename)\n";
210 assert(strlen(line) > 0);
216 cerr <<
" MAX_NUMBER_ROWS exceeded in "
217 " dmatrix::dmatrix(char * filename)\n";
223 size_t length = strlen(line);
224 while (index < length)
226 char c = line[index];
227 while (c !=
' ' && c !=
',')
235 cerr <<
" MAX_NUMBER_COLUMNS exceeded in "
236 " dmatrix::dmatrix(char * filename)\n";
239 while (c ==
' ' || c ==
',')
242 if (index >= length)
break;
254 cerr <<
"Error in dmatrix constructor There doesn't seem to be any data\n"
255 <<
"in file " << filename
256 <<
" caled in dmatrix::dmatrix(char * filename)\n";
261 infile.seekg(0,ios::beg);
278 cerr <<
" Error allocating memory in dmatrix contructor\n";
283 cerr <<
" Error allocating memory in dmatrix contructor\n";
288 cerr <<
"Created a dmatrix with adress "<< farptr_tolong(
m)<<
"\n";
295 m[i].
allocate(index_down[i],index_up[i]);
297 cerr <<
"Created a dvector with address "<< farptr_tolong((
void*)(
m+i))<<
"\n";
315 size_t length = strlen(line);
316 while (index < length)
319 char c = line[index];
320 while (c !=
' ' && c !=
',')
322 field[field_index] = c;
328 field[field_index] =
'\0';
331 elem(i,j)=strtod(field,&err_ptr);
333 if (isalpha((
unsigned char)err_ptr[0]))
335 cerr <<
"Error decoding field " << filename
336 <<
" in dmatrix::dmatrix(char * filename) " <<
"\n";
337 cerr <<
"Error occurred in line " << i <<
" at field " << j <<
"\n";
338 cerr <<
"Offending characters start with "
342 << err_ptr[3] <<
"\n";
345 if (
elem(i,j) == HUGE_VAL ||
elem(i,j) == -HUGE_VAL)
347 cerr <<
"Overflow Error decoding field " << filename
348 <<
" in dmatrix::dmatrix(char * filename) " <<
"\n";
349 cerr <<
"Error occurred in line " << i <<
" at field " << j <<
"\n";
350 cerr <<
"Offending characters start with "
354 << err_ptr[3] <<
"\n";
359 cerr <<
" MAX_NUMBER_COLUMNS exceeded in "
360 " dmatrix::dmatrix(char * filename)\n";
363 while (c ==
' ' || c ==
',')
366 if (index >= length)
break;
385 const ifstream& _infile,
387 const int& line_length)
389 ifstream& infile = (ifstream&)_infile;
391 int peek = infile.peek();
392 while (infile.good() && (iscntrl(peek) || isspace(peek)))
395 peek = infile.peek();
398 infile.get(line, line_length);
400 return infile.good() ?
mystrlen(line) : 0;
void myheapcheck(char *msg)
Does nothing.
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
const int MAX_NUMBER_ROWS
Description not yet available.
const int MAX_LINE_LENGTH
dmatrix(void)
Default constructor.
Vector of double precision numbers.
const int MAX_FIELD_LENGTH
int mystrlen(const char *line)
Description not yet available.
void allocate(int ncl, int ncu)
Allocate memory for a dvector.
void fill_seqadd(int, int)
Fills ivector elements with values starting from base and incremented by offset.
int get_non_blank_line(const ifstream &infile, char *&line, const int &line_length)
Description not yet available.
Array of integers(int) with indexes from index_min to indexmax.
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
unsigned int rowsize() const
const int MAX_NUMBER_COLUMNS
size_t length(const adstring &t)
Returns the size of adstr.