]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_2DdataFileReader.cpp
Sep 1 2000 updates from the UIUC team.
[flightgear.git] / src / FDM / UIUCModel / uiuc_2DdataFileReader.cpp
1 /**********************************************************************
2
3  FILENAME:     uiuc_2DdataFileReader.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/29/2000   initial release
21
22 ----------------------------------------------------------------------
23
24  AUTHOR(S):    Jeff Scott         <jscott@mail.com>
25
26 ----------------------------------------------------------------------
27
28  VARIABLES:
29
30 ----------------------------------------------------------------------
31
32  INPUTS:       -2D file name
33                -conversion factor for x data
34                -conversion factor for y data
35                -conversion factor for z data
36
37 ----------------------------------------------------------------------
38
39  OUTPUTS:      -2D array of x data for each y case
40                -1D array of y data
41                -2D array of z data for each y case
42                -1D array of max number of x-z data sets for each y case
43                -max number of y data sets
44
45 ----------------------------------------------------------------------
46
47  CALLED BY:    uiuc_menu.cpp
48
49 ----------------------------------------------------------------------
50
51  CALLS TO:     specified 2D data file
52
53 ----------------------------------------------------------------------
54
55  COPYRIGHT:    (C) 2000 by Michael Selig
56
57  This program is free software; you can redistribute it and/or
58  modify it under the terms of the GNU General Public License
59  as published by the Free Software Foundation.
60
61  This program is distributed in the hope that it will be useful,
62  but WITHOUT ANY WARRANTY; without even the implied warranty of
63  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
64  GNU General Public License for more details.
65
66  You should have received a copy of the GNU General Public License
67  along with this program; if not, write to the Free Software
68  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
69  USA or view http://www.gnu.org/copyleft/gpl.html.
70
71 **********************************************************************/
72
73 #include "uiuc_2DdataFileReader.h"
74
75
76 void uiuc_2DdataFileReader( string file_name, 
77                             double x[100][100], 
78                             double y[100], 
79                             double z[100][100], 
80                             int xmax[100], 
81                             int &ymax)
82 {
83   ParseFile *matrix;
84   double token_value1;
85   double token_value2;
86   int counter_y = 1, counter_x = 1;
87   string linetoken1;
88   string linetoken2;
89
90   stack command_list;
91
92   /* Read the file and get the list of commands */
93   matrix = new ParseFile(file_name);
94   command_list = matrix -> getCommands();
95
96   for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
97     {
98       linetoken1 = matrix -> getToken(*command_line, 1); // gettoken(string,tokenNo);
99       linetoken2 = matrix -> getToken(*command_line, 2); // 2 represents token No 2
100
101       istrstream token1(linetoken1.c_str());
102       istrstream token2(linetoken2.c_str());
103
104       //reset token_value2 for first if statement
105       token_value2 = -999;
106
107       token1 >> token_value1;
108       token2 >> token_value2;
109
110       //check to see if only one value on line (token2 blank)
111       if (token_value2 == -999)
112         {
113           y[counter_y] = token_value1 * convert_y;
114
115           ymax = counter_y;
116           counter_y++;
117           counter_x = 1;
118         }
119       else
120         {
121           x[counter_y-1][counter_x] = token_value1 * convert_x;
122           z[counter_y-1][counter_x] = token_value2 * convert_z;
123
124           xmax[counter_y-1] = counter_x;
125           counter_x++;
126         }
127     }
128   return;
129 }
130
131 // end uiuc_2DdataFileReader.cpp