8 #if defined(__TURBOC__)
15 #include <iostream.hpp>
17 #include <sstream.hpp>
19 #include <strstream.h>
21 #define __USE_IOSTREAM__
31 #include <strstream.h>
32 #define __USE_IOSTREAM__
50 const size_t n = strlen(s);
55 char* t =
new char[n+1];
59 for (
size_t k = 0; k < n; k++)
81 if (lbraces != rbraces)
83 cerr <<
"Unbalanced braces in dvector::dvector(const char * s)\n";
89 cerr <<
"Only one level of braces allowed in "
90 "dvector::dvector(const char * s)\n";
104 size_t length = strlen(t);
105 for (
int i=ncl;i<=nch;i++)
111 if (index >= length)
break;
118 field[field_index] = c;
122 if (index >= length)
break;
126 field[field_index] =
'\0';
128 v[i]=strtod(field,&err_ptr);
130 if (isalpha((
unsigned char)err_ptr[0]))
132 cerr <<
"Error decoding field "
133 <<
" in dvector::dvector(char * filename) " <<
"\n";
134 cerr <<
"Error occurred at element " << i <<
"\n";
135 cerr <<
"Offending characters start with "
139 if (
elem(i)== HUGE_VAL ||
elem(i)== -HUGE_VAL)
141 cerr <<
"Overflow Error decoding field in dvector::dvector(char* )"
143 cerr <<
"Error occurred at element " << i <<
"\n";
144 cerr <<
"Offending characters start with "
154 const char * filename=s;
155 ifstream infile(filename);
158 cerr <<
"Error opening file " << filename <<
" in dvector constructor "
159 <<
"dvector::dvector(char* filename)\n";
168 while (!infile.eof())
184 }
while (!isspace(c) && c !=
',');
201 infile.seekg(0,ios::beg);
203 if ((
v =
new double[static_cast<unsigned int>(count + 2)]) ==0)
205 cerr <<
" Error trying to allocate memory for dvector\n";
208 #if defined(THREAD_SAFE)
209 if ((
shape =
new ts_vector_shapex(1, count,
v)) == NULL)
214 cerr <<
"Error trying to allocate memory for dvector\n";
222 cout <<
"Created ncopies with address " << _farptr_tolong(&(
shape->
ncopies)) <<
"\n";
223 cout <<
"Created dvector with address " << _farptr_tolong(
v) <<
"\n";
227 for (
int i = 1; i <= count; ++i)
232 while (!infile.eof())
250 }
while (!isspace(c) && c !=
',');
255 elem(i) = strtod(field,&err_ptr);
257 if (isalpha((
unsigned char)err_ptr[0]))
259 cerr <<
"Error decoding field " << filename
260 <<
" in dvector::dvector(char * filename) " <<
"\n";
261 cerr <<
"Error occurred at element " << count <<
"\n";
262 cerr <<
"Offending characters start with "
266 << err_ptr[3] <<
"\n";
269 if (
elem(i) == HUGE_VAL ||
elem(i) == -HUGE_VAL)
271 cerr <<
"Overflow Error decoding field " << filename
272 <<
" in dvector::dvector(char * filename) " <<
"\n";
273 cerr <<
"Error occurred at element " << count <<
"\n";
274 cerr <<
"Offending characters start with "
278 << err_ptr[3] <<
"\n";
298 const size_t n = strlen(s);
303 char* t =
new char[n + 1];
307 for (
size_t k = 0; k < n; k++)
314 else if (s[k] ==
'}')
319 else if (s[k] ==
',')
329 if (lbraces != rbraces)
331 cerr <<
"Unbalanced braces in dvector::dvector(const char* s)\n";
337 cerr <<
"Only one level of braces allowed in "
338 "dvector::dvector(const char* s)\n";
345 int nch = commas + 1;
352 size_t length = strlen(t);
353 for (
int i=ncl;i<=nch;i++)
359 if (index >= length)
break;
366 field[field_index] = c;
370 if (index >= length)
break;
374 field[field_index] =
'\0';
376 v[i] = strtod(field,&err_ptr);
378 if (isalpha((
unsigned char)err_ptr[0]))
380 cerr <<
"Error decoding field "
381 <<
" in dvector::dvector(char * filename) " <<
"\n";
382 cerr <<
"Error occurred at element " << i <<
"\n";
383 cerr <<
"Offending characters start with "
387 << err_ptr[3] <<
"\n";
391 if (
elem(i) == HUGE_VAL ||
elem(i) == -HUGE_VAL)
393 cerr <<
"Overflow Error decoding field "
394 " in dvector::dvector(char * ) " <<
"\n";
395 cerr <<
"Error occurred at element " << i <<
"\n";
404 const char* filename = s;
405 ifstream infile(filename);
408 cerr <<
"Error opening file " << filename <<
" in dvector constructor "
409 <<
"dvector::dvector(char * filename)\n";
432 while (!infile.eof())
448 }
while (!isspace(c) && c !=
',');
453 infile.seekg(0,ios::beg);
455 if ((
v =
new double[static_cast<unsigned int>(count + 2)]) ==0)
457 cerr <<
" Error trying to allocate memory for dvector\n";
460 #if defined(THREAD_SAFE)
461 if ((
shape =
new ts_vector_shapex(1, count,
v)) == NULL)
466 cerr <<
"Error trying to allocate memory for dvector\n";
471 cout <<
"Created ncopies with address " << _farptr_tolong(&(
shape->
ncopies)) <<
"\n";
472 cout <<
"Created dvector with address " << _farptr_tolong(
v) <<
"\n";
479 for (
int i = 1; i <= count; ++i)
484 while (!infile.eof())
502 }
while (!isspace(c) && c !=
',');
507 elem(i) = strtod(field, &err_ptr);
509 if (isalpha((
unsigned char)err_ptr[0]))
511 cerr <<
"Error decoding field " << filename
512 <<
" in dvector::dvector(char * filename) " <<
"\n";
513 cerr <<
"Error occurred at element " << count <<
"\n";
514 cerr <<
"Offending characters start with "
518 << err_ptr[3] <<
"\n";
521 if (
elem(i) == HUGE_VAL ||
elem(i) == -HUGE_VAL)
523 cerr <<
"Overflow Error decoding field " << filename
524 <<
" in dvector::dvector(char * filename) " <<
"\n";
525 cerr <<
"Error occurred at element " << count <<
"\n";
526 cerr <<
"Offending characters start with "
530 << err_ptr[3] <<
"\n";
double * v
pointer to the data
dvector()
Construct a dvector without allocating memory.
int indexmin() const
Get minimum valid index.
const int MAX_FIELD_LENGTH
void allocate(void)
Allocate dvector without allocating memory.
prnstream & endl(prnstream &)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
unsigned int ncopies
Copy counter to enable shallow copies.
int index_min
minimum valid subscript
Holds "shape" information for vector objects.
vector_shapex * shape
pointer to vector "shape"
int index_max
maximum valid subscript
size_t length(const adstring &t)
Returns the size of adstr.