void PA_terminate(const char *edname, const char *ppname, const char *gfname, int cycle) {int i; if (PA_gs.edit_file != NULL) PA_ERR(io_close(PA_gs.edit_file), "TROUBLE CLOSING EDIT FILE %s - PA_TERMINATE", edname); /* save the number of time plots and the number of points (cycles) */ if (PA_gs.pp_file != NULL) PA_close_pp(); if (PA_gs.pva_file != NULL) PA_ERR(!PD_close(PA_gs.pva_file), "TROUBLE CLOSING PVA FILE %s - PA_TERMINATE", gfname); if (PA_gs.cache_file != NULL) PA_ERR(!PD_close(PA_gs.cache_file), "TROUBLE CLOSING CACHE FILE - PA_TERMINATE"); /* close open state files */ for (i = 0; i < _PA.n_state_files; i++) {PA_ERR(!PD_close(_PA.state_files[i]), "TROUBLE CLOSING STATE FILE %d - PA_TERMINATE", i); _PA.state_files[i] = NULL;}; CFREE(_PA.state_files); PA_gs.pva_file = NULL; PA_gs.edit_file = NULL; PA_gs.cache_file = NULL; return;}
int test_10(char *base, char *tgt, int n) {int err; char datfile[MAXLINE], fname[MAXLINE]; PDBfile *strm; FILE *fp; /* target the file as asked */ test_target(tgt, base, 100+n, fname, datfile, MAXLINE); fp = io_open(fname, "w"); prep_test_10_data(); if (read_only == FALSE) /* create the named file */ {strm = PD_create(datfile); if (strm == NULL) error(1, fp, "Test couldn't create file %s\r\n", datfile); PRINT(fp, "File %s created\n", datfile); /* write the test data */ write_test_10_data(strm); /* close the file */ if (PD_close(strm) == FALSE) error(1, fp, "Test couldn't close file %s\r\n", datfile); PRINT(fp, "File %s closed\n", datfile);}; /* reopen the file */ strm = PD_open(datfile, "r"); if (strm == NULL) error(1, fp, "Test couldn't open file %s\r\n", datfile); PRINT(fp, "File %s opened\n", datfile); /* dump the symbol table */ dump_test_symbol_table(fp, strm->symtab, 1); /* read the data from the file */ read_test_10_data(strm); /* compare the original data with that read in */ err = compare_test_10_data(strm, fp); /* close the file */ if (PD_close(strm) == FALSE) error(1, fp, "Test couldn't close file %s\r\n", datfile); PRINT(fp, "File %s closed\n", datfile); /* print it out to STDOUT */ print_test_10_data(fp); io_close(fp); if (err) REMOVE(fname); return(err);}
static void clear_sys(void) { if (pdsf != NULL) {PD_close(pdsf); pdsf = NULL;} return;}
void PA_file_mon(char *edname, char *ppname, char *gfname) {int64_t curpos; /* check on the edit file */ if (PA_gs.edit_file != NULL) {if (_PA.edstr == 0L) _PA.edstr = io_tell(PA_gs.edit_file); curpos = io_tell(PA_gs.edit_file); if (curpos+_PA.edstr >= MAXSIZE) {io_close(PA_gs.edit_file); PA_advance_name(edname); PA_gs.edit_file = io_open(edname, "w"); PA_ERR((PA_gs.edit_file == NULL), "CAN'T OPEN FILE %s - PA_FILE_MON", edname); PRINT(stdout, "Edit file %s opened\n", edname); _PA.edstr = 0L;};}; /* check on the post processor */ if (PA_gs.pp_file != NULL) {FILE *str; str = PA_gs.pp_file->stream; if (_PA.ppstr == 0L) _PA.ppstr = lio_tell(str); curpos = lio_tell(str); if (curpos+_PA.ppstr >= MAXSIZE) {PA_close_pp(); PA_advance_name(ppname); PA_gs.pp_file = PA_open(ppname, "w", FALSE); PRINT(stdout, "Post processor file %s opened\n", ppname); _PA.ppstr = 0L;};}; /* check on the PVA file */ if (PA_gs.pva_file != NULL) {FILE *str; str = PA_gs.pva_file->stream; if (_PA.ppstr == 0L) _PA.ppstr = lio_tell(str); curpos = lio_tell(str); if (curpos+_PA.ppstr >= MAXSIZE) {PD_close(PA_gs.pva_file); PA_advance_name(gfname); PA_gs.pva_file = PA_open(gfname, "w", FALSE); PA_ERR(((PA_gs.pva_file == NULL) || (PD_def_mapping(PA_gs.pva_file) == 0)), "CAN`T DEFINE MAPPINGS - PA_FILE_MON"); PRINT(stdout, "PVA file %s opened\n", gfname); _PA.ppstr = 0L;};}; return;}
static void makeh(void) {int i, j, l, sz, change, N_var; double t1, t2, *tt, **td, *pd, *time, **ldata; haelem **tab, *hp; source_record *sp; time_list *tp; pcons *pp, *pn; /* order the times for each variable in srctab */ sz = srctab->size; tab = srctab->table; N_var = 0; for (i = 0; i < sz; i++) for (hp = tab[i]; hp != NULL; hp = hp->next) {tp = (time_list *) (hp->def); l = tp->length; /* copy the list into arrays */ tt = time = CMAKE_N(double, l); td = ldata = CMAKE_N(double *, l); for (pp = tp->list; pp != NULL; pp = pn) {sp = (source_record *) pp->car; *(tt++) = sp->time; *(td++) = sp->data; pn = (pcons *) pp->cdr; CFREE(sp); CFREE(pp);}; /* sort the arrays according to the times */ change = TRUE; while (change) {change = FALSE; for (j = 1; j < l; j++) {t1 = time[j-1]; t2 = time[j]; if (t2 < t1) {pd = ldata[j-1]; ldata[j-1] = ldata[j]; ldata[j] = pd; time[j] = t1; time[j-1] = t2; change = TRUE;};};}; /* write the variable and source_record array out */ write_var(pdsf, hp->name, time, ldata, l); N_var++; /* release the temporary storage for this variable */ CFREE(time); CFREE(ldata);}; /* finish up */ PD_write(pdsf, "n_variables", "integer", &N_var); PD_close(pdsf); pdsf = NULL; return;}
void PDBFileObject::Close() { if(pdb) { PD_close(pdb); pdb = 0; } }
int main(int argc, char **argv) { char *infile; char *outfile; gato_data data; PDBfile *fp; long ind[6]; double **m; int i, j, ip, im; double dl, dr, dz; /* Set input file name */ infile = DEFAULT_INPUT; if(argc > 1) { /* First argument is the input file */ infile = argv[1]; } /* Set output file name */ if(argc > 2) { outfile = argv[2]; }else { /* Default output is input + ".pdb" */ outfile = (char*) malloc(strlen(infile) + 5); sprintf(outfile, "%s.pdb", infile); } /* Read the GATO data file */ if(read_gato(infile, &data)) { return(1); } if(!data.b_present) { /* Calculate Br and Bz from Bpol */ data.Br = dmatrix(data.ntheta, data.npsi); data.Bz = dmatrix(data.ntheta, data.npsi); data.b_present = 1; for(i=0;i<data.ntheta;i++) { ip = (i == (data.ntheta-1)) ? 0 : i+1; im = (i == 0) ? data.ntheta-1 : i-1; for(j=0;j<data.npsi;j++) { dl = sqrt(SQ(data.xnorm[ip][j] - data.xnorm[im][j]) + SQ(data.znorm[ip][j] - data.znorm[im][j])); dr = data.xnorm[ip][j] - data.xnorm[im][j]; dz = data.znorm[ip][j] - data.znorm[im][j]; data.Br[i][j] = dr * data.Bpol[i][j] / dl; data.Bz[i][j] = dz * data.Bpol[i][j] / dl; } } } /* Open PDB file */ if((fp = PD_open(outfile, "w")) == (PDBfile*) NULL) { fprintf(stderr, "Error: Could not open '%s' for writing\n", outfile); return(2); } /* Write to PDB file */ ind[0] = 0L; ind[1] = data.npsi-1; ind[2] = 1L; ind[3] = 0L; ind[4] = data.ntheta-1; ind[5] = 1L; /* Size of the grid */ if(!PD_write(fp, "nx", "integer", &data.npsi)) { fprintf(stderr, "Error: Could not write to file '%s'\n", outfile); return(3); } if(!PD_write(fp, "ny", "integer", &data.ntheta)) { fprintf(stderr, "Error: Could not write to file '%s'\n", outfile); return(3); } /* Write 1D flux surface functions */ WRITE1D("psi", data.psiflux); WRITE1D("f", data.fnorm); WRITE1D("ffprime", data.ffpnorm); WRITE1D("mu0p", data.ponly); WRITE1D("mu0pprime", data.pponly); WRITE1D("qsafe", data.qsf); WRITE1D("Ni", data.d); /* Write 2D variables (Need to reverse indices) */ m = dmatrix(data.npsi, data.ntheta); WRITE2D("Rxy", data.xnorm); WRITE2D("Zxy", data.znorm); WRITE2D("Brxy", data.Br); WRITE2D("Bzxy", data.Bz); WRITE2D("Bpxy", data.Bpol); WRITE2D("Btxy", data.Btor); PD_close(fp); free_gato(&data); /* Free data */ return(0); }
int main(int c, char **v) {int i; float nonew[24]; /* these are all half the size of the */ float middlew[24]; /* space that will be defent for them */ float allw[24]; /* which will be of dim [2][6][4] */ float allwstep[48]; float allrstep[48]; float zerostep[48]; float noner[24]; /* over the course of three cases we */ float middler[24]; /* write and read back non-contiguously, */ float allr[24]; /* partially contiguously, and contiguously */ float zero[24]; PDBfile *file; debug_mode = FALSE; for (i = 1; i < c; i++) {if (v[i][0] == '-') {switch (v[i][1]) {case 'd' : debug_mode = TRUE; SC_gs.mm_debug = TRUE; break; case 'h' : print_help(); return(1); case 'v' : PD_set_fmt_version(SC_stoi(v[++i])); break;};} else break;}; file = PD_open(DATA_FILE, "w+"); if (file == NULL) {printf("Error creating %s\n", DATA_FILE); exit(1);}; /* initialize the write vars to some semi-arbitrary values */ for (i = 0; i < 24; i++) {nonew[i] = (float) i; middlew[i] = (float) i; allw[i] = (float) i; zero[i] = 0.0; noner[i] = 0.0; middler[i] = 0.0; allr[i] = 0.0;}; /* step == 1 CASES */ /* first case: NONE of the dimension descriptor describe contiguity */ if (!PD_defent(file, "none[2,6,4]", "float")) {printf("PD_defent failed\n"); exit(2);}; /* write out one "physics" variable such that there * are no contiguous regions to optimize on */ if (!PD_write(file, "none[0:1, 0:5, 0:1]", "float", nonew)) {printf("PD_write failed\n"); exit(3);}; /* zero out the rest of it */ if (!PD_write(file, "none[0:1, 0:5, 2:3]", "float", zero)) {printf("PD_write failed\n"); exit(3);}; /* read that variable back again such that there * are no contiguous regions to optimize on */ if (!PD_read(file, "none[0:1, 0:5, 0:1]", noner)) {printf("PD_read failed\n"); exit(4);}; /* check it to make sure it is correct */ for (i = 0; i < 24; i++) {if (fabsf(nonew[i] - noner[i]) > FLOAT_TOLERANCE) {printf("Error in check %f != %f ", nonew[i], noner[i]); printf("at position none[%d]\n", i); PD_close(file); exit(-1);};}; /* second case: MIDDLE dimension contains contiguity */ if (!PD_defent(file, "middle[2,6,4]", "float")) {printf("PD_defent failed\n"); exit(5);}; /* write out on "physics" variable such that some * partial contiguous regions exist to optimize upon */ if (!PD_write(file, "middle[0:1, 3:5, 0:3]", "float", middlew)) {printf("PD_write failed\n"); exit(6);}; if (!PD_write(file, "middle[0:1, 0:2, 0:3]", "float", zero)) {printf("PD_write failed\n"); exit(6);}; /* read that variable back again */ if (!PD_read(file, "middle[0:1, 3:5, 0:3]", middler)) {printf("PD_read failed\n"); exit(7);}; /* check it to make sure it is correct */ for (i = 0; i < 24; i++) {if (fabs(middlew[i] - middler[i]) > FLOAT_TOLERANCE) {printf("Error in check %f != %f ", middlew[i], middler[i]); printf("at position middle[%d]\n", i); PD_close(file); exit(-1);};}; /* third case: ALL of the region to write/read is contiguous */ if (!PD_defent(file, "all[2,6,4]", "float")) {printf("PD_defent failed\n"); exit(8);}; /* write out on "physics" variable such that the * entire region is contiguous to check full optimization */ if (!PD_write(file, "all[0:0, 0:5, 0:3]", "float", allw)) {printf("PD_write failed\n"); exit(9);}; if (!PD_write(file, "all[1:1, 0:5, 0:3]", "float", zero)) {printf("PD_write failed\n"); exit(9);}; /* read that variable back again */ if (!PD_read(file, "all[0:0, 0:5, 0:3]", allr)) {printf("PD_read failed\n"); exit(10);}; /* check it to make sure it is correct */ for (i = 0; i < 24; i++) {if (fabs(allw[i] - allr[i]) > FLOAT_TOLERANCE) {printf("Error in check %f != %f ", allw[i], allr[i]); printf("at position all[%d]\n", i); PD_close(file); exit(-1);};}; /* step != 1 CASES */ /* first case: NONE of the dimension descriptor describe contiguity */ if (!PD_defent(file, "nonestep[2,6,4]", "float")) {printf("PD_defent failed\n"); exit(2);}; /* write out one "physics" variable such that there * are no contiguous regions to optimize on */ if (!PD_write(file, "nonestep[0:1, 0:5, 1:3:2]", "float", nonew)) {printf("PD_write failed\n"); exit(3);}; /* zero out the rest of it */ if (!PD_write(file, "nonestep[0:1, 0:5, 0:2:2]", "float", zero)) {printf("PD_write failed\n"); exit(3);}; /* read that variable back again such that there * are no contiguous regions to optimize on */ if (!PD_read(file, "nonestep[0:1, 0:5, 1:3:2]", noner)) {printf("PD_read failed\n"); exit(4);}; /* check it to make sure it is correct */ for (i = 0; i < 24; i++) {if (fabs(nonew[i] - noner[i]) > FLOAT_TOLERANCE) {printf("Error in check %f != %f ", nonew[i], noner[i]); printf("at position nonestep[%d]\n", i); PD_close(file); exit(-1);};}; /* second case: MIDDLE dimension contains step; 3rd dim is contiguity */ if (!PD_defent(file, "middlestep[2,6,4]", "float")) {printf("PD_defent failed\n"); exit(5);}; /* write out on "physics" variable such that some * partial contiguous regions exist to optimize upon */ if (!PD_write(file, "middlestep[0:1, 1:5:2, 0:3]", "float", middlew)) {printf("PD_write failed\n"); exit(6);}; if (!PD_write(file, "middlestep[0:1, 0:4:2, 0:3]", "float", zero)) {printf("PD_write failed\n"); exit(6);}; /* read that variable back again */ if (!PD_read(file, "middlestep[0:1, 1:5:2, 0:3]", middler)) {printf("PD_read failed\n"); exit(7);}; /* check it to make sure it is correct */ for (i = 0; i < 24; i++) {if (fabs(middlew[i] - middler[i]) > FLOAT_TOLERANCE) {printf("Error in check %f != %f ", middlew[i], middler[i]); printf("at position middlestep[%d]\n", i); PD_close(file); exit(-1);};}; /* third case: OUTTER dim steps, hence only 2nd dim in is contiguous * This is the only step != 1 case that causes optimization */ for (i = 0; i < 48; i++) {allwstep[i] = (float) i; allrstep[i] = 0.0; zerostep[i] = 0.0;}; if (!PD_defent(file, "allstep[4,6,4]", "float")) {printf("PD_defent failed\n"); exit(8);}; /* write out on "physics" variable such that the * entire region is contiguous to check full optimization */ if (!PD_write(file, "allstep[0:2:2, 0:5, 0:3]", "float", allwstep)) {printf("PD_write failed\n"); exit(9);}; if (!PD_write(file, "allstep[1:3:2, 0:5, 0:3]", "float", zerostep)) {printf("PD_write failed\n"); exit(9);}; /* read that variable back again */ if (!PD_read(file, "allstep[0:2:2, 0:5, 0:3]", allrstep)) {printf("PD_read failed\n"); exit(10);}; /* check it to make sure it is correct */ for (i = 0; i < 24; i++) {if (fabs(allwstep[i] - allrstep[i]) > FLOAT_TOLERANCE) {printf("Error in check %f != %f ", allwstep[i], allrstep[i]); printf("at position allstep[%d]\n", i); PD_close(file); exit(-1);};}; PD_close(file); SC_remove(DATA_FILE); exit(0);}
int main(int argc, char** argv) { if(argc < 4) { fprintf(stderr, "Useage: %s <input file> <output file> <t stride>\n", argv[0]); return 1; } int tstride; if(sscanf(argv[3], "%d", &tstride) != 1) { fprintf(stderr, "\tERROR: t stride must be an integer\n"); return 1; } // Open input file PDBfile *in; if((in = PD_open(argv[1], "r")) == NULL) { fprintf(stderr, "\tERROR: Could not open input file '%s'\n", argv[1]); return 1; } // Open output file PDBfile *out; if((out = PD_open(argv[2], "w")) == NULL) { fprintf(stderr, "\tERROR: Could not open output file '%s'\n", argv[2]); return 1; } // Get list of variables int nvars; char **var_names = PD_ls(in, NULL, NULL, &nvars); if((var_names == (char**) NULL) || (nvars < 1)) { fprintf(stderr, "\tERROR: No variables\n"); return 1; } // Go through the variables char *varname; for(int var=0;var<nvars;var++) { varname = var_names[var]; syment *ep; // PDB query types dimdes* dims; // Query size of the variable if((ep = PD_query_entry(in, varname, NULL)) == (syment*) NULL) { fprintf(stderr, "\tError querying variable %s\n", varname); return 1; } dims = PD_entry_dimensions(ep); int nd = 0; // Count number of dimensions int varsize = 1; // Number of elements long inds[12]; while(dims != (dimdes*) NULL) { long min, max; min = dims->index_min; max = dims->index_max; if(nd > 3) { fprintf(stderr, "\tERROR: Can't handle variable '%s': more than 4D\n", varname); return 2; } inds[3*nd] = min; inds[3*nd + 1] = max; inds[3*nd + 2] = 1L; varsize *= max - min + 1; nd++; dims = dims->next; } // Get variable type char *typ; typ = PD_entry_type(ep); if((strcmp(varname, "t_array") == 0) && (nd == 1)) { float *fdata = new float[varsize]; // Read the data from the PDB file inds[2] = tstride; int nread; if( (nread = PD_read_as_alt(in, varname, "float", fdata, inds)) == 0) { fprintf(stderr, "\tWARNING: Could not read t_array. Ignoring\n"); delete[] fdata; continue; } inds[0] = 0L; inds[1] = nread-1; inds[2] = 1L; if(PD_write_alt(out, varname, "float", fdata, 1, inds) == FALSE) { fprintf(stderr, "\tWARNING: Could not write '%s'. Ignoring\n", varname); } delete[] fdata; }else if(nd == 4) { // Reducing time resolution if(strcasecmp(typ, "integer") == 0) { int *idata = new int[varsize]; // Read the data from the PDB file inds[2] = tstride; int nread; if( (nread = PD_read_as_alt(in, varname, "integer", idata, inds)) == 0) { fprintf(stderr, "\tWARNING: Could not read '%s'. Ignoring\n", varname); delete[] idata; continue; } if( nread % (varsize / (inds[1] - inds[0] + 1)) != 0 ) { fprintf(stderr, "ERROR: Accounting error: (%ld, %ld), %d, %d\n", inds[0], inds[1], varsize, nread); delete[] idata; continue; } nread = nread / (varsize / (inds[1] - inds[0] + 1)); inds[0] = 0L; inds[1] = nread - 1; inds[2] = 1L; if(PD_write_alt(out, varname, "integer", idata, 4, inds) == FALSE) { fprintf(stderr, "\tWARNING: Could not write '%s'. Ignoring\n", varname); } delete[] idata; }else if( (strcasecmp(typ, "float") == 0) || (strcasecmp(typ, "double") == 0) ) { // Convert doubles to floats float *fdata = new float[varsize]; // Read the data from the PDB file inds[2] = tstride; int nread; if( (nread = PD_read_as_alt(in, varname, "float", fdata, inds)) == 0) { fprintf(stderr, "\tWARNING: Could not read '%s'. Ignoring\n", varname); delete[] fdata; continue; } if( nread % (varsize / (inds[1] - inds[0] + 1)) != 0 ) { fprintf(stderr, "ERROR: Accounting error: (%ld, %ld), %d, %d\n", inds[0], inds[1], varsize, nread); delete[] fdata; continue; } nread = nread / (varsize / (inds[1] - inds[0] + 1)); inds[0] = 0L; inds[1] = nread - 1; inds[2] = 1L; if(PD_write_alt(out, varname, "float", fdata, 4, inds) == FALSE) { fprintf(stderr, "\tWARNING: Could not write '%s'. Ignoring\n", varname); } delete[] fdata; }else { fprintf(stderr, "\tWARNING: '%s' has unrecognised type '%s'. Ignoring\n", varname, typ); } }else { // Just copy the data across if(strcasecmp(typ, "integer") == 0) { int *idata = new int[varsize]; // Read the data from the PDB file if (PD_read_as(in, varname, "integer", idata) == 0) { fprintf(stderr, "\t\tWARNING: Could not read variable. Ignoring\n"); delete[] idata; continue; } if(PD_write_alt(out, varname, "integer", idata, nd, inds) == FALSE) { fprintf(stderr, "\tWARNING: Could not write variable '%s'\n", varname); } delete[] idata; }else if( (strcasecmp(typ, "float") == 0) || (strcasecmp(typ, "double") == 0) ) { // Convert doubles to floats float *fdata = new float[varsize]; // Read the data from the PDB file if (PD_read_as(in, varname, "float", fdata) == 0) { fprintf(stderr, "\tWARNING: Could not read variable '%s'. Ignoring\n", varname); delete[] fdata; continue; } if(PD_write_alt(out, varname, "float", fdata, nd, inds) == FALSE) { fprintf(stderr, "\tWARNING: Could not write variable '%s'\n", varname); } delete[] fdata; }else { fprintf(stderr, "WARNING: '%s' has unrecognised type '%s'. Ignoring\n", varname, typ); } } } PD_close(in); PD_close(out); return 0; }
/** \b Usage: "dakota_restart_util to_pdb dakota.rst dakota.pdb"\n "dakota_restart_util to_tabular dakota.rst dakota.txt" Unrolls all data associated with a particular tag for all evaluations and then writes this data in a tabular format (e.g., to a PDB database or MATLAB/TECPLOT data file). */ void print_restart_tabular(int argc, char** argv, String print_dest) { if (print_dest != "pdb_file" && print_dest != "text_file") { Cerr << "Error: bad print_dest in print_restart_tabular" << endl; exit(-1); } else if (print_dest == "pdb_file" && argc != 4) { Cerr << "Usage: \"dakota_restart_util to_pdb <restart_file> <pdb_file>\"." << endl; exit(-1); } else if (print_dest == "text_file" && argc != 4) { Cerr << "Usage: \"dakota_restart_util to_tabular <restart_file> " << "<text_file>\"." << endl; exit(-1); } std::ifstream restart_input_fs(argv[2], std::ios::binary); if (!restart_input_fs.good()) { Cerr << "Error: failed to open restart file " << argv[2] << endl; exit(-1); } boost::archive::binary_iarchive restart_input_archive(restart_input_fs); extern PRPCache data_pairs; size_t records_read = 0; // counter for restart records read size_t num_evals = 0; // unique insertions to data_pairs while (restart_input_fs.good() && !restart_input_fs.eof()) { ParamResponsePair current_pair; try { restart_input_archive & current_pair; } catch(const boost::archive::archive_exception& e) { Cerr << "\nError reading restart file (boost::archive exception):\n" << e.what() << std::endl; abort_handler(-1); } catch(const std::string& err_msg) { Cout << "\nWarning reading restart file: " << err_msg << std::endl; break; } ++records_read; std::pair<PRPCacheCIter, bool> insert_result; insert_result = data_pairs.insert(current_pair); if (insert_result.second == false) Cout << "Warning: Restart record " << records_read << " (evaluation id " << current_pair.eval_id() << ") is a duplicate; ignoring." << std::endl; else ++num_evals; // more efficient than evaluating data_pairs.size()? // peek to force EOF if the last restart record was read restart_input_fs.peek(); } // size_t num_evals = data_pairs.size(); size_t i, j; if (print_dest == "pdb_file") { PRPCacheCIter prp_iter = data_pairs.begin(); StringMultiArrayConstView cv_labels = prp_iter->prp_parameters().continuous_variable_labels(); StringMultiArrayConstView div_labels = prp_iter->prp_parameters().discrete_int_variable_labels(); StringMultiArrayConstView drv_labels = prp_iter->prp_parameters().discrete_real_variable_labels(); const StringArray& fn_labels = prp_iter->prp_response().function_labels(); size_t num_cv = cv_labels.size(), num_div = div_labels.size(), num_drv = drv_labels.size(), num_fns = fn_labels.size(); // pack up tabular data matrices (organized such that use of a single index // returns the complete history for an attribute). RealVector uninitialized_rv(num_evals, false); IntVector uninitialized_iv(num_evals, false); RealVectorArray tabular_rdata(num_cv+num_drv+num_fns, uninitialized_rv); std::vector<IntVector> tabular_idata(num_div, uninitialized_iv); for (i=0; i<num_evals; ++i, ++prp_iter) { // Extract variables related data const Variables& local_vars = prp_iter->prp_parameters(); const RealVector& local_c_vars = local_vars.continuous_variables(); const IntVector& local_di_vars = local_vars.discrete_int_variables(); const RealVector& local_dr_vars = local_vars.discrete_real_variables(); for (j=0; j<num_cv; ++j) tabular_rdata[j][i] = local_c_vars[j]; for (j=0; j<num_div; ++j) tabular_idata[j][i] = local_di_vars[j]; for (j=0; j<num_drv; ++j) tabular_rdata[j+num_cv][i] = local_dr_vars[j]; // Extract response related data const Response& local_response = prp_iter->prp_response(); const RealVector& local_fns = local_response.function_values(); //const ShortArray& local_asv =local_response.active_set_request_vector(); //const RealMatrix& local_grads = local_response.function_gradients(); //const RealMatrixArray& local_hessians // = local_response.function_hessians(); // NOTE: if any fns are inactive, they will appear as 0's in tabular_data for (j=0; j<num_fns; ++j) tabular_rdata[j+num_cv+num_drv][i] = local_fns[j]; } #ifdef HAVE_PDB_H // open the PDB file cout << "Writing PDB file:" << argv[3] << '\n'; PDBfile *fileID; if ((fileID = PD_open(argv[3], "w")) == NULL){ cout << "Problem opening PDB file"; return; } // Note: tabular_rdata[j] returns the jth row vector from the matrix and // values() returns the double* pointer to the data of this row // vector. const char* and const double* are passed to PDB_Write. char *tag, cdim[6]; std::sprintf(cdim, "(%d)", num_evals); String tag_name, snum_evals(cdim); // write continuous variables for (j=0; j<num_cv; ++j){ tag_name = cv_labels[j] + snum_evals; tag = const_cast<char *>(tag_name.data()); if(!PD_write(fileID, tag, "double", (void *)tabular_rdata[j].values())) cout << "PD_write error=" << PD_err << '\n'; } // write discrete integer variables for (j=0; j<num_div; ++j){ tag_name = div_labels[j] + snum_evals; tag = const_cast<char *>(tag_name.data()); if(!PD_write(fileID, tag, "integer", (void *)tabular_idata[j].values())) cout << "PD_write error=" << PD_err << '\n'; } // write discrete real variables for (j=0; j<num_drv; ++j){ tag_name = drv_labels[j] + snum_evals; tag = const_cast<char *>(tag_name.data()); if(!PD_write(fileID, tag, "double", (void *)tabular_rdata[j+num_cv].values())) cout << "PD_write error=" << PD_err << '\n'; } // write corresponding function values for (j=0; j<num_fns; ++j){ tag_name = fn_labels[j] + snum_evals; tag = const_cast<char *>(tag_name.data()); if(!PD_write(fileID, tag, "double", (void *)tabular_rdata[j+num_cv+num_drv].values())) cout << "PD_write error=" << PD_err << '\n'; } if(!PD_close(fileID)) cout << "Problem closing PDB file" << argv[3] << '\n'; #else cout << "PDB utilities not available" << endl; exit(0); #endif } else if (print_dest == "text_file") { cout << "Writing tabular text file " << argv[3] << '\n'; std::ofstream tabular_text(argv[3]); String curr_interf; PRPCacheCIter prp_iter = data_pairs.begin(); for (i=0; i<num_evals; ++i, ++prp_iter) { const String& new_interf = prp_iter->interface_id(); if (i == 0 || new_interf != curr_interf) { curr_interf = new_interf; // Header (note: use matlab comment syntax "%"): StringMultiArrayConstView acv_labels = prp_iter->prp_parameters().all_continuous_variable_labels(); StringMultiArrayConstView adiv_labels = prp_iter->prp_parameters().all_discrete_int_variable_labels(); StringMultiArrayConstView adrv_labels = prp_iter->prp_parameters().all_discrete_real_variable_labels(); const StringArray& fn_labels = prp_iter->prp_response().function_labels(); size_t num_acv = acv_labels.size(), num_adiv = adiv_labels.size(), num_adrv = adrv_labels.size(), num_fns = fn_labels.size(); if (!curr_interf.empty()) tabular_text << "%Interface = " << curr_interf << '\n'; tabular_text << "%eval_id "; for (j=0; j<num_acv; ++j) tabular_text << setw(14) << acv_labels[j].data() << ' '; for (j=0; j<num_adiv; ++j) tabular_text << setw(14) << adiv_labels[j].data() << ' '; for (j=0; j<num_adrv; ++j) tabular_text << setw(14) << adrv_labels[j].data() << ' '; for (j=0; j<num_fns; ++j) tabular_text << setw(14) << fn_labels[j].data() << ' '; tabular_text << '\n'; } // Data: (note: not maximum precision) prp_iter->write_tabular(tabular_text); } } cout << "Restart file processing completed: " << num_evals << " evaluations tabulated.\n"; }