// read one block from file Block* VamasDataSet::read_block(istream &f, bool includes[], const Block* first_block) { Block *block = new Block; double x_start=0., x_step=0.; string x_name; vector<VecColumn*> ycols; block->set_name(read_line_trim(f)); block->meta["sample identifier"] = read_line_trim(f); string date_time; string first_dt; if (first_block) first_dt = first_block->meta.get("date_time"); // year, month, etc. should be numbers, but don't assume it, just in case if (includes[0]) { date_time = read_line_trim(f); if (date_time.size() < 4) date_time.insert(date_time.begin(), 4 - date_time.size(), ' '); } else { date_time = first_dt.substr(0, 4); } date_time += includes[1] ? "-" + two_digit(read_line_trim(f)) : first_dt.substr(4, 3);; date_time += includes[2] ? "-" + two_digit(read_line_trim(f)) : first_dt.substr(7, 3);; date_time += includes[3] ? " " + two_digit(read_line_trim(f)) : first_dt.substr(10, 3);; date_time += includes[4] ? ":" + two_digit(read_line_trim(f)) : first_dt.substr(13, 3);; date_time += includes[5] ? ":" + two_digit(read_line_trim(f)) : first_dt.substr(16, 3);; if (includes[6]) { string timezone = read_line_trim(f); if (!timezone.empty()) { if (timezone[0] == '-') date_time += " -" + two_digit(timezone.substr(1)) + "00"; else date_time += " +" + two_digit(timezone) + "00"; } } block->meta["date_time"] = date_time; if (includes[7]) { // skip comments on this block int cmt_lines = read_line_int(f); skip_lines(f, cmt_lines); } string tech; if (includes[8]) { tech = read_line_trim(f); block->meta["tech"] = tech; assert_in_array(tech, techs, "tech"); } if (includes[9]) { if ("MAP" == exp_mode_ || "MAPDP" == exp_mode_) { block->meta["x coordinate"] = read_line_trim(f); block->meta["y coordinate"] = read_line_trim(f); } } if (includes[10]) { for (int i = 0; i < exp_var_cnt_; ++i) { block->meta["experimental variable value " + S(i)] = read_line_trim(f); } } if (includes[11]) block->meta["analysis source label"] = read_line_trim(f); if (includes[12]) { if ("MAPDP" == exp_mode_ || "MAPSVDP" == exp_mode_ || "SDP" == exp_mode_ || "SDPSV" == exp_mode_ || "SNMS energy spec" == tech || "FABMS" == tech || "FABMS energy spec" == tech || "ISS" == tech || "SIMS" == tech || "SIMS energy spec" == tech || "SNMS" == tech) { block->meta["sputtering ion oratom atomic number"] = read_line_trim(f); block->meta["number of atoms in sputtering ion or atom particle"] = read_line_trim(f); block->meta["sputtering ion or atom charge sign and number"] = read_line_trim(f); } } if (includes[13]) // a.k.a "analysis source characteristic energy" block->meta["source energy"] = read_line_trim(f); if (includes[14]) block->meta["analysis source strength"] = read_line_trim(f); if (includes[15]) { block->meta["analysis source beam width x"] = read_line_trim(f); block->meta["analysis source beam width y"] = read_line_trim(f); } if (includes[16]) { if ("MAP" == exp_mode_ || "MAPDP" == exp_mode_ || "MAPSV" == exp_mode_ || "MAPSVDP" == exp_mode_ || "SEM" == exp_mode_) { block->meta["field of view x"] = read_line_trim(f); block->meta["field of view y"] = read_line_trim(f); } } if (includes[17]) { if ("SEM" == exp_mode_ || "MAPSV" == exp_mode_ || "MAPSVDP" == exp_mode_) { throw FormatError("unsupported MAPPING mode"); } } if (includes[18]) block->meta["analysis source polar angle of incidence"] = read_line_trim(f); if (includes[19]) block->meta["analysis source azimuth"] = read_line_trim(f); if (includes[20]) block->meta["analyser mode"] = read_line_trim(f); if (includes[21]) block->meta["analyser pass energy or retard ratio or mass resolution"] = read_line_trim(f); if (includes[22]) { if ("AES diff" == tech) { block->meta["differential width"] = read_line_trim(f); } } if (includes[23]) block->meta["magnification of analyser transfer lens"] = read_line_trim(f); if (includes[24]) block->meta["analyser work function or acceptance energy of atom or ion"] = read_line_trim(f); if (includes[25]) block->meta["target bias"] = read_line_trim(f); if (includes[26]) { block->meta["analysis width x"] = read_line_trim(f); block->meta["analysis width y"] = read_line_trim(f); } if (includes[27]) { block->meta["analyser axis take off polar angle"] = read_line_trim(f); block->meta["analyser axis take off azimuth"] = read_line_trim(f); } if (includes[28]) block->meta["species label"] = read_line_trim(f); if (includes[29]) { block->meta["transition or charge state label"] = read_line_trim(f); block->meta["charge of detected particle"] = read_line_trim(f); } if (includes[30]) { if ("REGULAR" == scan_mode_) { x_name = read_line_trim(f); block->meta["abscissa label"] = x_name; block->meta["abscissa units"] = read_line_trim(f); x_start = my_strtod(read_line(f)); x_step = my_strtod(read_line(f)); } else throw FormatError("Only REGULAR scans are supported now"); } else throw FormatError("how to find abscissa properties in this file?"); int cor_var; // number of corresponding variables if (includes[31]) { cor_var = read_line_int(f); if (cor_var < 1) throw FormatError("wrong number of corresponding variables"); // columns initialization for (int i = 0; i != cor_var; ++i) { string corresponding_variable_label = read_line_trim(f); skip_lines(f, 1); // ignoring corresponding variable unit ycols.push_back(new VecColumn); ycols[i]->set_name(corresponding_variable_label); } } else { assert(first_block != NULL); cor_var = first_block->get_column_count() - 1; // don't count xcol for (int i = 0; i != cor_var; ++i) { ycols.push_back(new VecColumn); ycols[i]->set_name(first_block->get_column(i).get_name()); } } if (includes[32]) block->meta["signal mode"] = read_line_trim(f); if (includes[33]) block->meta["signal collection time"] = read_line_trim(f); if (includes[34]) block->meta["# of scans to compile this blk"] = read_line_trim(f); if (includes[35]) block->meta["signal time correction"] = read_line_trim(f); if (includes[36]) { if (("AES diff" == tech || "AES dir" == tech || "EDX" == tech || "ELS" == tech || "UPS" == tech || "XPS" == tech || "XRF" == tech) && ("MAPDP" == exp_mode_ || "MAPSVDP" == exp_mode_ || "SDP" == exp_mode_ || "SDPSV" == exp_mode_)) { skip_lines(f, 7); } } if (includes[37]) { block->meta["sample normal polar angle of tilt"] = read_line_trim(f); block->meta["sample normal polar tilt azimuth"] = read_line_trim(f); } if (includes[38]) block->meta["sample rotate angle"] = read_line_trim(f); if (includes[39]) { int n = read_line_int(f); // # of additional numeric parameters for (int i = 0; i < n; ++i) { // 3 items in every loop: param_label, param_unit, param_value string param_label = read_line_trim(f); string param_unit = read_line_trim(f); block->meta[param_label] = read_line_trim(f) + param_unit; } } skip_lines(f, blk_fue_); // skip future upgrade block entries int cur_blk_steps = read_line_int(f); skip_lines(f, 2 * cor_var); // min & max ordinate StepColumn *xcol = new StepColumn(x_start, x_step); xcol->set_name(x_name); block->add_column(xcol); int col = 0; assert(ycols.size() == (size_t) cor_var); for (int i = 0; i < cur_blk_steps; ++i) { double y = my_strtod(read_line_trim(f)); ycols[col]->add_val(y); col = (col + 1) % cor_var; } for (int i = 0; i < cor_var; ++i) block->add_column(ycols[i]); return block; }
double my_atof(const char *nptr) { int error; const char *end= nptr+65535; /* Should be enough */ return (my_strtod(nptr, (char**) &end, &error)); }
void determine_type_of_constituent_string (void) { bool possible_id, possible_var, possible_sc, possible_ic, possible_fc; bool rereadable; determine_possible_symbol_types_for_string (current_agent(lexeme).string, current_agent(lexeme).length, &possible_id, &possible_var, &possible_sc, &possible_ic, &possible_fc, &rereadable); /* --- check whether it's a variable --- */ if (possible_var) { current_agent(lexeme).type = VARIABLE_LEXEME; return; } /* --- check whether it's an integer --- */ if (possible_ic) { errno = 0; current_agent(lexeme).type = INT_CONSTANT_LEXEME; current_agent(lexeme).int_val = strtol (current_agent(lexeme).string,NULL,10); if (errno) { print ("Error: bad integer (probably too large)\n"); print_location_of_most_recent_lexeme(); current_agent(lexeme).int_val = 0; } return; } /* --- check whether it's a floating point number --- */ if (possible_fc) { errno = 0; current_agent(lexeme).type = FLOAT_CONSTANT_LEXEME; current_agent(lexeme).float_val = (float) my_strtod (current_agent(lexeme).string,NULL,10); if (errno) { print ("Error: bad floating point number\n"); print_location_of_most_recent_lexeme(); current_agent(lexeme).float_val = 0.0; } return; } /* --- check if it's an identifier --- */ if (current_agent(current_file)->allow_ids && possible_id) { current_agent(lexeme).id_letter = toupper(current_agent(lexeme).string[0]); errno = 0; current_agent(lexeme).type = IDENTIFIER_LEXEME; current_agent(lexeme).id_number = my_strtoul (&(current_agent(lexeme).string[1]),NULL,10); if (errno) { print ("Error: bad number for identifier (probably too large)\n"); print_location_of_most_recent_lexeme(); current_agent(lexeme).id_number = 0; } return; } /* --- otherwise it must be a symbolic constant --- */ if (possible_sc) { current_agent(lexeme).type = SYM_CONSTANT_LEXEME; if (current_agent(sysparams)[PRINT_WARNINGS_SYSPARAM]) { if (current_agent(lexeme).string[0] == '<') { if (current_agent(lexeme).string[1] == '<') { print ("Warning: Possible disjunctive encountered in reading symbolic constant\n"); print (" If a disjunctive was intended, add a space after <<\n"); print (" If a constant was intended, surround constant with vertical bars\n"); print_location_of_most_recent_lexeme(); } else { print ("Warning: Possible variable encountered in reading symbolic constant\n"); print (" If a constant was intended, surround constant with vertical bars\n"); print_location_of_most_recent_lexeme(); } } else { if (current_agent(lexeme).string[current_agent(lexeme).length-1] == '>') { if (current_agent(lexeme).string[current_agent(lexeme).length-2] == '>') { print ("Warning: Possible disjunctive encountered in reading symbolic constant\n"); print (" If a disjunctive was intended, add a space before >>\n"); print (" If a constant was intended, surround constant with vertical bars\n"); print_location_of_most_recent_lexeme(); } else { print ("Warning: Possible variable encountered in reading symbolic constant\n"); print (" If a constant was intended, surround constant with vertical bars\n"); print_location_of_most_recent_lexeme(); } } } } return; } #if defined(USE_TCL) current_agent(lexeme).type = QUOTED_STRING_LEXEME; #else char msg[128]; strcpy (msg, "Internal error: can't determine_type_of_constituent_string\n"); abort_with_fatal_error(msg); #endif }