I need again your help. I've tried to implement wind data from a .txt file into flightgear. Of course, the reading process of the file shall be done only once, because the files a relatively large and reading the file each time step would make FG very slow. My current script in local_weather.nas look like this:
- Code: Select all
...
else if (wind_model_flag == 6) # PALM 3DWind
{
var input_PAlM_data_flag = getprop("local-weather/config/input-PALM-data-flag");
if (input_PAlM_data_flag == 0){
# Input filenames as 1D vectors
var u_input = split("\n", io.readfile("/localdata/giersch/FG-3.6-v1/fgdata/PALMInput/Assist_gauss_6_3d_t_end/u.txt"));
var v_input = split("\n", io.readfile("/localdata/giersch/FG-3.6-v1/fgdata/PALMInput/Assist_gauss_6_3d_t_end/v.txt"));
var w_input = split("\n", io.readfile("/localdata/giersch/FG-3.6-v1/fgdata/PALMInput/Assist_gauss_6_3d_t_end/w.txt"));
var x_input = split("\n", io.readfile("/localdata/giersch/FG-3.6-v1/fgdata/PALMInput/Assist_gauss_6_3d_t_end/x.txt"));
var y_input = split("\n", io.readfile("/localdata/giersch/FG-3.6-v1/fgdata/PALMInput/Assist_gauss_6_3d_t_end/y.txt"));
var zw_input = split("\n", io.readfile("/localdata/giersch/FG-3.6-v1/fgdata/PALMInput/Assist_gauss_6_3d_t_end/zw_3d.txt"));
# Calculate dimensions and grid spacing (last three rows in input file are empty, only valid for constant grid spacing)
var dimx = size(x_input) - 3;
var delta_x = x_input[1] - x_input[0];
var dimy = size(y_input) - 3;
var delta_y = y_input[1] - y_input[0];
var dimz = size(zw_input) - 3;
var delta_z = zw_input[1] - zw_input[0];
# Determine model size
var xsize = (dimx-1)*delta_x;
var ysize = (dimy-1)*delta_y;
var zsize = (dimz-1)*delta_z;
# Inertial airplane position in PALM wind field [m] (center of the model domain)
var xp_old = xsize / 2.0;
var yp_old = ysize / 2.0;
var zp_old = zsize / 2.0;
# Create 3D array appropriate to the input data
var n = 0;
var u_palm = [];
var v_palm = [];
var w_palm = [];
for (var k = 0; k < dimz; k += 1){
var dummy_2d = [];
for (var j = 0; j < dimy; j += 1){
var dummy_1d = [];
for (var i = 0; i < dimx; i += 1){
var pointer = u_input[n];
n += 1;
append(dummy_1d, pointer);
};
append(dummy_2d,dummy_1d);
};
append(u_palm, dummy_2d);
};
setprop("local-weather/config/input-PALM-data-flag",1);
#only exemplary.
var winddir = 45;
var windspeed = u_palm[129][256][256];
}
else
#only exemplary.
var winddir = 45;
var windspeed = u_palm[129][256][256] - 2 * u_palm[128][255][255]; # this is the line which makes problems. Fictitious calculation
}
Thus, the data is read only once until the input_PALM_data_flag is set to 1. After the reading process, FG shall only compute the new wind speed (depending on the aircraft position) each time the local-weather script runs (on the basis of the 3D field u_palm). The problem what appears then is the error message.
Nasal runtime error: undefined symbol: u_palm
The reason for it seems to be that FG don't know u_palm as soon as the input_PALM_data_flag is set to 1. How can I change this that the script runs?
Thank you very much in advance.