1 /**********************************************************************
3 FILENAME: uiuc_1DdataFileReader.cpp
5 ----------------------------------------------------------------------
7 DESCRIPTION: Reads name of data file to be opened and reads data
8 into appropriate arrays or matrices
10 ----------------------------------------------------------------------
14 ----------------------------------------------------------------------
18 ----------------------------------------------------------------------
20 HISTORY: 02/15/2000 initial release
21 09/01/2002 (RD) added second data file reader for
23 06/30/2003 (RD) replaced istrstream with istringstream
24 to get rid of the annoying warning about
25 using the strstream header
27 ----------------------------------------------------------------------
29 AUTHOR(S): Jeff Scott <jscott@mail.com>
30 Robert Deters <rdeters@uiuc.edu>
32 ----------------------------------------------------------------------
36 ----------------------------------------------------------------------
38 INPUTS: -1D data file name
39 -conversion factor for y data
40 -conversion factor for x data
42 ----------------------------------------------------------------------
44 OUTPUTS: -array of x data
46 -max number of data sets
48 ----------------------------------------------------------------------
50 CALLED BY: uiuc_menu.cpp
52 ----------------------------------------------------------------------
54 CALLS TO: specified 1D data file
56 ----------------------------------------------------------------------
58 COPYRIGHT: (C) 2000 by Michael Selig
60 This program is free software; you can redistribute it and/or
61 modify it under the terms of the GNU General Public License
62 as published by the Free Software Foundation.
64 This program is distributed in the hope that it will be useful,
65 but WITHOUT ANY WARRANTY; without even the implied warranty of
66 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 GNU General Public License for more details.
69 You should have received a copy of the GNU General Public License
70 along with this program; if not, write to the Free Software
71 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
72 USA or view http://www.gnu.org/copyleft/gpl.html.
74 **********************************************************************/
76 #include "uiuc_1DdataFileReader.h"
79 uiuc_1DdataFileReader( string file_name,
80 double x[], double y[], int &xmax )
86 int counter = 1, data = 0;
90 static string uiuc_1DdataFileReader_error = " (from uiuc_1DdataFileReader.cpp) ";
92 /* Read the file and get the list of commands */
93 matrix = new ParseFile(file_name);
94 command_list = matrix -> getCommands();
96 for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
98 linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo);
99 linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2
101 istringstream token1(linetoken1.c_str());
102 istringstream token2(linetoken2.c_str());
104 token1 >> token_value1;
105 token2 >> token_value2;
107 x[counter] = token_value1 * convert_x;
108 y[counter] = token_value2 * convert_y;
111 //(RD) will create error check later, we can have more than 100
114 // uiuc_warnings_errors(6, uiuc_1DdataFileReader_error);
121 //can't have conversions in this version since the numbers are
122 //to stay as integers
124 uiuc_1DdataFileReader( string file_name,
125 double x[], int y[], int &xmax )
131 int counter = 1, data = 0;
136 /* Read the file and get the list of commands */
137 matrix = new ParseFile(file_name);
138 command_list = matrix -> getCommands();
140 for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
142 linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo);
143 linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2
145 istringstream token1(linetoken1.c_str());
146 istringstream token2(linetoken2.c_str());
148 token1 >> token_value1;
149 token2 >> token_value2;
151 x[counter] = token_value1;
152 y[counter] = token_value2;
160 // end uiuc_1DdataFileReader.cpp