3 #ifndef _BCP_PARAMETERS_H
4 #define _BCP_PARAMETERS_H
15 #if defined(__GNUC__) && (__GNUC__ >= 3)
18 # define BCP_STRINGSTREAM std::istringstream
22 # define BCP_STRINGSTREAM std::istrstream
71 _type(t), _index(i) {}
82 int index()
const {
return _index; }
121 void create_keyword_list();
123 void set_default_entries();
201 std::copy(x.cpar, x.cpar +
static_cast<int>(Par::end_of_chr_params),
203 std::copy(x.ipar, x.ipar +
static_cast<int>(Par::end_of_int_params),
205 std::copy(x.dpar, x.dpar +
static_cast<int>(Par::end_of_dbl_params),
207 std::copy(x.spar, x.spar +
static_cast<int>(Par::end_of_str_params),
210 x.sapar +
static_cast<int>(Par::end_of_str_array_params),
265 const int MAX_PARAM_LINE_LENGTH = 1024;
266 char line[MAX_PARAM_LINE_LENGTH], *end_of_line, *keyword, *ctmp;
267 char value[MAX_PARAM_LINE_LENGTH];
273 BCP_parameters::read_from_stream Scanning parameter stream.\n");
274 while (!parstream.eof()) {
275 parstream.getline(line, MAX_PARAM_LINE_LENGTH);
276 const int len = strlen(line);
277 if (len == MAX_PARAM_LINE_LENGTH - 1) {
279 There's a too long (>= %i characters) line in the parameter file.\n\
280 This is absurd.\n", MAX_PARAM_LINE_LENGTH);
284 end_of_line = line + len;
288 for (keyword = line; keyword < end_of_line; ++keyword) {
289 if (isgraph(*keyword))
292 if (keyword == end_of_line)
295 for (ctmp = keyword; ctmp < end_of_line; ++ctmp) {
301 for ( ; ctmp < end_of_line; ++ctmp) {
305 if (ctmp == end_of_line)
311 for (i = 0; ctmp < end_of_line; ++ctmp) {
313 if (++ctmp == end_of_line)
326 for (i = 0; ctmp < end_of_line; ++ctmp) {
327 if (!isspace(*ctmp)) {
337 if (strcmp(keyword,
"ParamFile") == 0) {
342 if (strcmp(keyword,
"Quiet") == 0) {
343 int val = atoi(value);
348 std::string value_expanded =
expand(value);
351 for (ind = keys.
begin(); ind != keys.
end(); ++ind) {
352 if (ind->first == keyword) {
356 printf(
"%s %s\n", keyword, value_expanded.c_str());
358 set_entry((*ind).second, value_expanded.c_str());
363 for (obs_ind = obsolete_keys.
begin();
364 obs_ind != obsolete_keys.
end();
366 if (*obs_ind == keyword) {
368 printf(
"***WARNING*** : Obsolete keyword `%s' is found.\n",
376 BCP_parameters::read_from_stream Finished scanning parameter stream.\n\n");
389 const int MAX_PARAM_LINE_LENGTH = 1024;
390 char valueBuf[MAX_PARAM_LINE_LENGTH];
391 bool bDollar =
false;
393 for(
int i = 0; value[i] !=
'\0'; i++){
394 char cval = value[i];
400 valueBuf[j++] = cval;
405 char envBuf[MAX_PARAM_LINE_LENGTH];
410 while((c = value[i++]) !=
')' && c !=
'\0')
413 char* eVal = getenv(envBuf);
416 valueBuf[j++] = *eVal++;
422 valueBuf[j++] = cval;
428 std::string sExpand(valueBuf);
443 std::ifstream parstream(paramfile);
456 std::string argstring;
457 for (
int i = 1; i < argnum; i += 2) {
458 argstring += arglist[i];
461 argstring += arglist[i+1];
478 const int size = keys.
size();
479 for (
int i = 0; i < size; ++i) {
482 switch (par.
type()) {
484 outstream << key.
c_str() <<
" "
485 <<
static_cast<int>(cpar[par.
index()]) <<
"\n";
488 outstream << key.
c_str() <<
" "
489 << ipar[par.
index()] <<
"\n";
492 outstream << key.
c_str() <<
" "
493 << dpar[par.
index()] <<
"\n";
496 outstream << key.
c_str() <<
" "
500 for (
size_t j = 0; j < sapar[par.
index()].
size(); ++j) {
501 outstream << key.
c_str() <<
" "
502 << sapar[par.
index()][j].c_str() <<
"\n";
509 BCP_parameters::write_to_stream ERROR: Unrecognized parameter type!\n");
523 buf.
pack(cpar, Par::end_of_chr_params)
524 .
pack(ipar, Par::end_of_int_params)
525 .
pack(dpar, Par::end_of_dbl_params);
526 for (
int i = 0; i < Par::end_of_str_params; ++i)
528 for (
int i = 0; i < Par::end_of_str_array_params; ++i) {
529 buf.
pack(sapar[i].size());
530 for (
size_t j = 0; j < sapar[i].
size(); ++j)
531 buf.
pack(sapar[i][j]);
538 dummy =
static_cast<int>(Par::end_of_chr_params);
539 buf.
unpack(cpar, dummy,
false);
540 dummy =
static_cast<int>(Par::end_of_int_params);
541 buf.
unpack(ipar, dummy,
false);
542 dummy =
static_cast<int>(Par::end_of_dbl_params);
543 buf.
unpack(dpar, dummy,
false);
544 for (
int i = 0; i < Par::end_of_str_params; ++i)
546 for (
int i = 0; i < Par::end_of_str_array_params; ++i) {
550 for (
size_t j = 0; j < str_size; ++j){
552 buf.
unpack(sapar[i].back());
566 cpar(new char[static_cast<int>(Par::end_of_chr_params)+1]),
567 ipar(new int[static_cast<int>(Par::end_of_int_params)+1]),
568 dpar(new double[static_cast<int>(Par::end_of_dbl_params)+1]),
569 spar(new
BCP_string[static_cast<int>(Par::end_of_str_params)+1]),
572 create_keyword_list();
573 set_default_entries();