#define NAMELENGTH 25 #include void clear_nwsp(ifstream*); short prompt_base(char[]); void make_names(char[],char[],char[],char[],char[]); void suffix_name(char[],char[4],char[]); void append_name(char[],char[4],char[]); short equal(char[],char[],short); void convert1(ifstream*,ofstream*,char[],short); void print_help(void); short another(void); void clear_nwsp(ifstream *ifile) { int temp; short cont; do { temp = (*ifile).peek(); if ( cont = ((temp < 33) || (temp > 127)) ) { // we have a white char (*ifile).get(); // Get rid of it. } } while (cont); } short prompt_base(char base[]) { short repeat; do { cout << "Enter the .prb file base name (leave off .prb), \n"; cout << "enter '-h' for help, or enter '-q' to quit: "; cin >> base; repeat = ( (base[0] == '-') && (base[1] == 'h')); if (repeat) { print_help(); } } while (repeat); return ( (base[0] == '-') && (base[1] == 'q') ) ? 0 : 1; } void make_names(char base[], char in[], char an[], char c1[], char c2[]) { suffix_name(base,".prb",in); append_name(base,"and_",an); append_name(base,"caN_",c1); append_name(base,"caP_",c2); } void suffix_name(char base[], char suffix[4], char out[]) { short i = 0; short j; do { out[i] = base[i]; } while (base[++i] != 0); for(j = 0; j < 4; j++) { out[i++] = suffix[j]; } out[i] = 0; } void append_name(char base[], char prefix[4], char out[]) { short i; for(i = 0; i < 4; i++) { out[i] = prefix[i]; } i = 0; do { out[i+4] = base[i]; } while (base[++i] != 0); i += 4; out[i++] = '.'; out[i++] = 't'; out[i++] = 'x'; out[i++] = 't'; out[i] = 0; } short equal(char st1[5], char st2[5], short length) { short i; short result = 1; for(i = 0; i < length; i++) { result *= (st1[i] == st2[i]); } return result; } void convert1(ifstream *infile, ofstream *outfile, char tag[], short num) { char line[100]; double temp; do { clear_nwsp(infile); (*infile).getline(line,100,' '); } while (! equal(line,tag,num) ); clear_nwsp(infile); do { *infile >> temp; *outfile << temp << ','; *infile >> temp; *outfile << temp << '\n'; clear_nwsp(infile); } while ( (*infile).peek() != 58); // i.e. quit when the next character is ":". } void print_help(void) { cout << "\nThis program takes a file of type '.prb'\n"; cout << "output from the probestation DAQ system, and produces\n"; cout << "three comma delimited text files containing the data\n"; cout << "of the anode and both cathode measurements.\n\n"; cout << "It assumes that measurements have been taken for all three\n"; cout << "types of measurements, and that only one run through each\n"; cout << "type of measurement was taken.\n\n"; cout << "The input file must have the extention '.prb'\n"; cout << "and the output files will be named and_.txt,\n"; cout << "caN_.txt, and caP_.txt, "; cout << "where the input is .prb.\n\n"; cout << "From the command line use \n\nprb2txt \n\n"; cout << "or, for multiple files, run prb2txt without arguments and follow\n"; cout << "the prompts.\n\n"; cout << "(c) D. Fiske 1998\nOhio State University.\n\n"; } short another(void) { char answer; cout << "\nConversion successful!\n\n"; cout << "Convert another file (y/n)? "; cin >> answer; cout << '\n'; if ( (answer == 'y') || (answer == 'Y') ) { return 1; } else { return 0; } } int main(int argc, char *argv[]) { char basename[NAMELENGTH-8]; char inname[NAMELENGTH]; char anodename[NAMELENGTH]; char cath1name[NAMELENGTH]; char cath2name[NAMELENGTH]; short repeat = 1; while (repeat) { switch(argc) { case 1: if (prompt_base(basename)) { make_names(basename,inname,anodename,cath1name,cath2name); } else { return 1; } break; case 2: argc = 1; // In so we'll get the right case when repeating. if ( (*argv[1] == '-') && (*(argv[1]+1) == 'h') ) { print_help(); return 1; } else { make_names(argv[1],inname,anodename,cath1name,cath2name); } break; default: return 0; } ifstream infile (inname); ofstream anodefile (anodename); ofstream cath1file (cath1name); ofstream cath2file (cath2name); convert1(&infile,&anodefile,"ANODE",5); convert1(&infile,&cath1file,"CathodeN",8); convert1(&infile,&cath2file,"CathodeP",8); repeat = another(); } return 1; }