| 1 | /********************************************************************** |
| 2 | |
| 3 | FILENAME: uiuc_1DdataFileReader.cpp |
| 4 | |
| 5 | ---------------------------------------------------------------------- |
| 6 | |
| 7 | DESCRIPTION: Reads name of data file to be opened and reads data |
| 8 | into appropriate arrays or matrices |
| 9 | |
| 10 | ---------------------------------------------------------------------- |
| 11 | |
| 12 | STATUS: alpha version |
| 13 | |
| 14 | ---------------------------------------------------------------------- |
| 15 | |
| 16 | REFERENCES: |
| 17 | |
| 18 | ---------------------------------------------------------------------- |
| 19 | |
| 20 | HISTORY: 02/15/2000 initial release |
| 21 | 09/01/2002 (RD) added second data file reader for |
| 22 | integer case |
| 23 | 06/30/2003 (RD) replaced istrstream with istringstream |
| 24 | to get rid of the annoying warning about |
| 25 | using the strstream header |
| 26 | |
| 27 | ---------------------------------------------------------------------- |
| 28 | |
| 29 | AUTHOR(S): Jeff Scott <[email protected]> |
| 30 | Robert Deters <[email protected]> |
| 31 | |
| 32 | ---------------------------------------------------------------------- |
| 33 | |
| 34 | VARIABLES: |
| 35 | |
| 36 | ---------------------------------------------------------------------- |
| 37 | |
| 38 | INPUTS: -1D data file name |
| 39 | -conversion factor for y data |
| 40 | -conversion factor for x data |
| 41 | |
| 42 | ---------------------------------------------------------------------- |
| 43 | |
| 44 | OUTPUTS: -array of x data |
| 45 | -array of y data |
| 46 | -max number of data sets |
| 47 | |
| 48 | ---------------------------------------------------------------------- |
| 49 | |
| 50 | CALLED BY: uiuc_menu.cpp |
| 51 | |
| 52 | ---------------------------------------------------------------------- |
| 53 | |
| 54 | CALLS TO: specified 1D data file |
| 55 | |
| 56 | ---------------------------------------------------------------------- |
| 57 | |
| 58 | COPYRIGHT: (C) 2000 by Michael Selig |
| 59 | |
| 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. |
| 63 | |
| 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. |
| 68 | |
| 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 72 | |
| 73 | **********************************************************************/ |
| 74 | |
| 75 | #include "uiuc_1DdataFileReader.h" |
| 76 | |
| 77 | using std::string; |
| 78 | using std::istringstream; |
| 79 | |
| 80 | int |
| 81 | uiuc_1DdataFileReader( string file_name, |
| 82 | double x[], double y[], int &xmax ) |
| 83 | { |
| 84 | |
| 85 | ParseFile *matrix; |
| 86 | double token_value1; |
| 87 | double token_value2; |
| 88 | int counter = 1, data = 0; |
| 89 | string linetoken1; |
| 90 | string linetoken2; |
| 91 | stack command_list; |
| 92 | static string uiuc_1DdataFileReader_error = " (from uiuc_1DdataFileReader.cpp) "; |
| 93 | |
| 94 | /* Read the file and get the list of commands */ |
| 95 | matrix = new ParseFile(file_name); |
| 96 | command_list = matrix -> getCommands(); |
| 97 | |
| 98 | for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line) |
| 99 | { |
| 100 | linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo); |
| 101 | linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2 |
| 102 | |
| 103 | istringstream token1(linetoken1.c_str()); |
| 104 | istringstream token2(linetoken2.c_str()); |
| 105 | |
| 106 | token1 >> token_value1; |
| 107 | token2 >> token_value2; |
| 108 | |
| 109 | x[counter] = token_value1 * convert_x; |
| 110 | y[counter] = token_value2 * convert_y; |
| 111 | xmax = counter; |
| 112 | counter++; |
| 113 | //(RD) will create error check later, we can have more than 100 |
| 114 | //if (counter > 100) |
| 115 | //{ |
| 116 | // uiuc_warnings_errors(6, uiuc_1DdataFileReader_error); |
| 117 | //}; |
| 118 | data = 1; |
| 119 | } |
| 120 | delete matrix; |
| 121 | return data; |
| 122 | } |
| 123 | |
| 124 | //can't have conversions in this version since the numbers are |
| 125 | //to stay as integers |
| 126 | int |
| 127 | uiuc_1DdataFileReader( string file_name, |
| 128 | double x[], int y[], int &xmax ) |
| 129 | { |
| 130 | |
| 131 | ParseFile *matrix; |
| 132 | int token_value1; |
| 133 | int token_value2; |
| 134 | int counter = 1, data = 0; |
| 135 | string linetoken1; |
| 136 | string linetoken2; |
| 137 | stack command_list; |
| 138 | |
| 139 | /* Read the file and get the list of commands */ |
| 140 | matrix = new ParseFile(file_name); |
| 141 | command_list = matrix -> getCommands(); |
| 142 | |
| 143 | for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line) |
| 144 | { |
| 145 | linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo); |
| 146 | linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2 |
| 147 | |
| 148 | istringstream token1(linetoken1.c_str()); |
| 149 | istringstream token2(linetoken2.c_str()); |
| 150 | |
| 151 | token1 >> token_value1; |
| 152 | token2 >> token_value2; |
| 153 | |
| 154 | x[counter] = token_value1; |
| 155 | y[counter] = token_value2; |
| 156 | xmax = counter; |
| 157 | counter++; |
| 158 | data = 1; |
| 159 | } |
| 160 | delete matrix; |
| 161 | return data; |
| 162 | } |
| 163 | |
| 164 | // end uiuc_1DdataFileReader.cpp |