]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_1DdataFileReader.cpp
Robert Deters:
[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
22 ----------------------------------------------------------------------
23
24  AUTHOR(S):    Jeff Scott         <jscott@mail.com>
25
26 ----------------------------------------------------------------------
27
28  VARIABLES:
29
30 ----------------------------------------------------------------------
31
32  INPUTS:       -1D data file name
33                -conversion factor for y data
34                -conversion factor for x data
35
36 ----------------------------------------------------------------------
37
38  OUTPUTS:      -array of x data
39                -array of y data
40                -max number of data sets
41
42 ----------------------------------------------------------------------
43
44  CALLED BY:    uiuc_menu.cpp
45
46 ----------------------------------------------------------------------
47
48  CALLS TO:     specified 1D data file
49
50 ----------------------------------------------------------------------
51
52  COPYRIGHT:    (C) 2000 by Michael Selig
53
54  This program is free software; you can redistribute it and/or
55  modify it under the terms of the GNU General Public License
56  as published by the Free Software Foundation.
57
58  This program is distributed in the hope that it will be useful,
59  but WITHOUT ANY WARRANTY; without even the implied warranty of
60  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
61  GNU General Public License for more details.
62
63  You should have received a copy of the GNU General Public License
64  along with this program; if not, write to the Free Software
65  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
66  USA or view http://www.gnu.org/copyleft/gpl.html.
67
68 **********************************************************************/
69
70 #include "uiuc_1DdataFileReader.h"
71
72 int 
73 uiuc_1DdataFileReader( string file_name,  
74                          double x[], double y[], int &xmax ) 
75 {
76
77   ParseFile *matrix;
78   double token_value1;
79   double token_value2;
80   int counter = 1, data = 0;
81   string linetoken1; 
82   string linetoken2; 
83   stack command_list;
84   static string uiuc_1DdataFileReader_error = " (from uiuc_1DdataFileReader.cpp) ";
85
86   /* Read the file and get the list of commands */
87   matrix = new ParseFile(file_name);
88   command_list = matrix -> getCommands();
89
90   for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
91     {
92       linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo);
93       linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2
94
95       istrstream token1(linetoken1.c_str());
96       istrstream token2(linetoken2.c_str());
97
98       token1 >> token_value1;
99       token2 >> token_value2;
100
101       x[counter] = token_value1 * convert_x;
102       y[counter] = token_value2 * convert_y;
103       xmax = counter;
104       counter++;
105       //(RD) will create error check later, we can have more than 100
106       //if (counter > 100)
107       //{      
108       //  uiuc_warnings_errors(6, uiuc_1DdataFileReader_error);
109       //};
110       data = 1;
111     }
112   return data;
113 }
114
115 //can't have conversions in this version since the numbers are
116 //to stay as integers
117 int 
118 uiuc_1DdataFileReader( string file_name,  
119                          double x[], int y[], int &xmax ) 
120 {
121
122   ParseFile *matrix;
123   int token_value1;
124   int token_value2;
125   int counter = 1, data = 0;
126   string linetoken1; 
127   string linetoken2; 
128   stack command_list;
129
130   /* Read the file and get the list of commands */
131   matrix = new ParseFile(file_name);
132   command_list = matrix -> getCommands();
133
134   for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
135     {
136       linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo);
137       linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2
138
139       istrstream token1(linetoken1.c_str());
140       istrstream token2(linetoken2.c_str());
141
142       token1 >> token_value1;
143       token2 >> token_value2;
144
145       x[counter] = token_value1;
146       y[counter] = token_value2;
147       xmax = counter;
148       counter++;
149       data = 1;
150     }
151   return data;
152 }
153
154 // end uiuc_1DdataFileReader.cpp