]> 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[100], double y[100], 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
85   /* Read the file and get the list of commands */
86   matrix = new ParseFile(file_name);
87   command_list = matrix -> getCommands();
88
89   for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
90     {
91       linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo);
92       linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2
93
94       istrstream token1(linetoken1.c_str());
95       istrstream token2(linetoken2.c_str());
96
97       token1 >> token_value1;
98       token2 >> token_value2;
99
100       x[counter] = token_value1 * convert_x;
101       y[counter] = token_value2 * convert_y;
102       xmax = counter;
103       counter++;
104       data = 1;
105     }
106   return data;
107 }
108
109 //can't have conversions in this version since the numbers are
110 //to stay as integers
111 int 
112 uiuc_1DdataFileReader( string file_name,  
113                          double x[], int y[], int &xmax ) 
114 {
115
116   ParseFile *matrix;
117   int token_value1;
118   int token_value2;
119   int counter = 1, data = 0;
120   string linetoken1; 
121   string linetoken2; 
122   stack command_list;
123
124   /* Read the file and get the list of commands */
125   matrix = new ParseFile(file_name);
126   command_list = matrix -> getCommands();
127
128   for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
129     {
130       linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo);
131       linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2
132
133       istrstream token1(linetoken1.c_str());
134       istrstream token2(linetoken2.c_str());
135
136       token1 >> token_value1;
137       token2 >> token_value2;
138
139       x[counter] = token_value1;
140       y[counter] = token_value2;
141       xmax = counter;
142       counter++;
143       data = 1;
144     }
145   return data;
146 }
147
148 // end uiuc_1DdataFileReader.cpp