]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_1DdataFileReader.cpp
Port over remaining Point3D usage to the more type and unit safe SG* classes.
[flightgear.git] / src / FDM / UIUCModel / uiuc_1DdataFileReader.cpp
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         <jscott@mail.com>
30                Robert Deters      <rdeters@uiuc.edu>
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 int 
78 uiuc_1DdataFileReader( string file_name,  
79                          double x[], double y[], int &xmax ) 
80 {
81
82   ParseFile *matrix;
83   double token_value1;
84   double token_value2;
85   int counter = 1, data = 0;
86   string linetoken1; 
87   string linetoken2; 
88   stack command_list;
89   static string uiuc_1DdataFileReader_error = " (from uiuc_1DdataFileReader.cpp) ";
90
91   /* Read the file and get the list of commands */
92   matrix = new ParseFile(file_name);
93   command_list = matrix -> getCommands();
94
95   for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
96     {
97       linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo);
98       linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2
99
100       istringstream token1(linetoken1.c_str());
101       istringstream token2(linetoken2.c_str());
102
103       token1 >> token_value1;
104       token2 >> token_value2;
105
106       x[counter] = token_value1 * convert_x;
107       y[counter] = token_value2 * convert_y;
108       xmax = counter;
109       counter++;
110       //(RD) will create error check later, we can have more than 100
111       //if (counter > 100)
112       //{      
113       //  uiuc_warnings_errors(6, uiuc_1DdataFileReader_error);
114       //};
115       data = 1;
116     }
117   return data;
118 }
119
120 //can't have conversions in this version since the numbers are
121 //to stay as integers
122 int 
123 uiuc_1DdataFileReader( string file_name,  
124                          double x[], int y[], int &xmax ) 
125 {
126
127   ParseFile *matrix;
128   int token_value1;
129   int token_value2;
130   int counter = 1, data = 0;
131   string linetoken1; 
132   string linetoken2; 
133   stack command_list;
134
135   /* Read the file and get the list of commands */
136   matrix = new ParseFile(file_name);
137   command_list = matrix -> getCommands();
138
139   for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
140     {
141       linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo);
142       linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2
143
144       istringstream token1(linetoken1.c_str());
145       istringstream token2(linetoken2.c_str());
146
147       token1 >> token_value1;
148       token2 >> token_value2;
149
150       x[counter] = token_value1;
151       y[counter] = token_value2;
152       xmax = counter;
153       counter++;
154       data = 1;
155     }
156   return data;
157 }
158
159 // end uiuc_1DdataFileReader.cpp