1% Copyright (C) 2008 VZLU Prague, a.s., Czech Republic 2% 3% Author: Jaroslav Hajek <highegg@gmail.com> 4% 5% This file is part of NLWing2. 6% 7% NLWing2 is free software; you can redistribute it and/or modify 8% it under the terms of the GNU General Public License as published by 9% the Free Software Foundation; either version 3 of the License, or 10% (at your option) any later version. 11% 12% This program is distributed in the hope that it will be useful, 13% but WITHOUT ANY WARRANTY; without even the implied warranty of 14% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15% GNU General Public License for more details. 16% 17% You should have received a copy of the GNU General Public License 18% along with this software; see the file COPYING. If not, see 19% <http://www.gnu.org/licenses/>. 20% 21 22% -*- texinfo -*- 23% @deftypefn{Function File} {[ac, pn, ref]} = loadwing (filename) 24% Loads the basic wing geometry from file @var{filename}. 25% The geometry should be described in the file as follows: 26% @verbatim 27% mchord <reference mean aerodynamic chord> 28% area <reference wing area> 29% mcenter <reference mean aerodynamic center> 30% 31% centers 32% <z1> <x1> <y1> <c1> <tw1> 33% : 34% <zN> <xN> <yN> <cN> <twN> 35% 36% polars 37% <polar file name 1> 38% <polar file name 2> 39% 40% @end verbatim 41% 42% xK, yK, zK are coordinates of the K-th point on the mean center line, 43% cK is the corresponding chord length and twK the twist. 44% 45% @end deftypefn 46 47function [ac, pol, ref] = loadwing (filename) 48f = fopen (filename, "rt"); 49if (f < 0) 50 error ("loadwing: cannot open %s", filename) 51endif 52 53unwind_protect 54 55 ac = []; 56 pol = []; 57 ref.sym = true; 58 59 mode = 0; 60 61 while (! feof (f)) 62 line = strtrim (fgets (f)); 63 % skip empty lines 64 if (length (line) == 0) 65 continue; 66 elseif (strcmp (line, "centers")) 67 mode = 1; 68 elseif (strcmp (line, "polars")) 69 mode = 2; 70 elseif (strmatch ('nonsymmetric', line)) 71 mode = 0; 72 ref.sym = false; 73 elseif (strmatch ('area', line)) 74 mode = 0; 75 ref.area = sscanf (line(5:end), ' %f', 'C'); 76 elseif (strmatch ('mchord', line)) 77 mode = 0; 78 ref.cmac = sscanf (line(8:end), ' %f', 'C'); 79 elseif (strmatch ('mcenter', line)) 80 mode = 0; 81 [xmac, ymac] = sscanf (line(8:end), ' %f %f', 'C'); 82 ref.xmac = xmac; 83 if (isempty (ymac)) 84 ref.ymac = 0; 85 else 86 ref.ymac = ymac; 87 endif 88 elseif (mode == 1) 89 [z,x,y,c,a] = sscanf (line, '%f %f %f %f %f', 'C'); 90 if (isempty (a)) 91 a = 0; 92 endif 93 ac(end+1,:) = [z,x,y,c,a]; 94 elseif (mode == 2) 95 i = length (pol) + 1; 96 [pol(i).z, pol(i).names] = sscanf (line, '%f %s', 'C'); 97 endif 98 endwhile 99 100unwind_protect_cleanup 101 fclose(f); 102end_unwind_protect 103 104if (ref.sym) 105 if (ac(1,1) < 0 || ac(end,1) < 0) 106 ac(:,1) = -ac(:,1); 107 endif 108 if (ac(1,1) < 0 || ac(end,1) < 0) 109 warning ("loadwing: invalid symmetric wing"); 110 endif 111 if (ac(1,1) > ac(end,1)) 112 ac = ac(end:-1:1,:); 113 endif 114endif 115 116endfunction 117