How do I structure a code that can read this AVL .vm file format?

6 views (last 30 days)
Dear all,
I am trying to build a code that can read the shear/bending moment along the airplane span that i am simulating. In fact, the only information that a need , it´s the numeric values (in vectors) for shear/bending moment along the span for each one of the surfaces (for these case, there are 4 surfaces). The example file can be seen below:
%-------------------------------------------------------------------------
Shear/q and Bending Moment/q vs Y
Configuration: erj190_WBZ
Mach = 0.200
alpha = 2.220 CLtot = 0.500
beta = 0.000
Sref = 92.50000
Bref = 27.77000
Surface: 1
WING
2Ymin/Bref = 0.117565721
2Ymax/Bref = 1.07207060
2Y/Bref Vz/(q*Sref) Mx/(q*Bref*Sref)
0.1176 0.228546 0.446145E-01
0.1181 0.227899 0.443709E-01
0.1224 0.226586 0.438857E-01
0.1309 0.223899 0.429283E-01
0.1436 0.219784 0.415245E-01
0.1603 0.214221 0.397131E-01
0.1809 0.207237 0.375443E-01
0.2052 0.198910 0.350783E-01
0.2330 0.189369 0.323829E-01
0.2640 0.178798 0.295297E-01
0.3010 0.166398 0.263350E-01
0.3440 0.152447 0.229116E-01
0.3863 0.139256 0.198313E-01
0.4273 0.126942 0.171052E-01
0.4699 0.114626 0.145352E-01
0.5137 0.102491 0.121598E-01
0.5583 0.907087E-01 0.100069E-01
0.6034 0.794377E-01 0.809351E-02
0.6484 0.688126E-01 0.642638E-02
0.6930 0.589413E-01 0.500275E-02
0.7368 0.499010E-01 0.381193E-02
0.7796 0.416836E-01 0.283193E-02
0.8211 0.343029E-01 0.204462E-02
0.8606 0.277970E-01 0.143204E-02
0.8978 0.221447E-01 0.968652E-03
0.9322 0.173112E-01 0.628999E-03
0.9749 0.118704E-01 0.320182E-03
1.0087 0.774024E-02 0.149107E-03
1.0255 0.540175E-02 0.790275E-04
1.0407 0.316395E-02 0.309609E-04
1.0530 0.157737E-02 0.938115E-05
1.0623 0.600948E-03 0.186567E-05
1.0685 0.132440E-03 0.165978E-06
1.0717 0.811139E-05 0.236596E-08
1.0721 0.00000 0.00000
Surface: 2
WING (YDUP)
2Ymin/Bref = -1.07207060
2Ymax/Bref = -0.117565721
2Y/Bref Vz/(q*Sref) Mx/(q*Bref*Sref)
-0.1176 0.228546 -0.446146E-01
-0.1181 0.227899 -0.443709E-01
-0.1224 0.226586 -0.438858E-01
-0.1309 0.223899 -0.429284E-01
-0.1436 0.219784 -0.415246E-01
-0.1603 0.214221 -0.397131E-01
-0.1809 0.207237 -0.375443E-01
-0.2052 0.198910 -0.350784E-01
-0.2330 0.189369 -0.323829E-01
-0.2640 0.178798 -0.295297E-01
-0.3010 0.166398 -0.263350E-01
-0.3440 0.152447 -0.229116E-01
-0.3863 0.139256 -0.198313E-01
-0.4273 0.126942 -0.171053E-01
-0.4699 0.114627 -0.145352E-01
-0.5137 0.102491 -0.121598E-01
-0.5583 0.907087E-01 -0.100069E-01
-0.6034 0.794378E-01 -0.809353E-02
-0.6484 0.688127E-01 -0.642640E-02
-0.6930 0.589414E-01 -0.500276E-02
-0.7368 0.499011E-01 -0.381194E-02
-0.7796 0.416837E-01 -0.283194E-02
-0.8211 0.343030E-01 -0.204463E-02
-0.8606 0.277971E-01 -0.143204E-02
-0.8978 0.221448E-01 -0.968657E-03
-0.9322 0.173112E-01 -0.629003E-03
-0.9749 0.118704E-01 -0.320185E-03
-1.0087 0.774031E-02 -0.149108E-03
-1.0255 0.540181E-02 -0.790280E-04
-1.0407 0.316397E-02 -0.309611E-04
-1.0530 0.157738E-02 -0.938116E-05
-1.0623 0.600949E-03 -0.186567E-05
-1.0685 0.132441E-03 -0.165978E-06
-1.0717 0.811140E-05 -0.236596E-08
-1.0721 0.00000 -0.00000
Surface: 3
INBODY_WING
2Ymin/Bref = 0.00000000
2Ymax/Bref = 0.117565721
2Y/Bref Vz/(q*Sref) Mx/(q*Bref*Sref)
0.0000 0.330557E-01 0.100437E-02
0.0045 0.291099E-01 0.775977E-03
0.0363 0.211989E-01 0.406315E-03
0.0813 0.979557E-02 0.842378E-04
0.1131 0.129067E-02 0.277770E-05
0.1176 0.00000 0.00000
Surface: 4
INBODY_WING (YDUP)
2Ymin/Bref = -0.117565721
2Ymax/Bref = 0.00000000
2Y/Bref Vz/(q*Sref) Mx/(q*Bref*Sref)
0.0000 0.330557E-01 -0.100437E-02
-0.0045 0.291099E-01 -0.775977E-03
-0.0363 0.211989E-01 -0.406315E-03
-0.0813 0.979557E-02 -0.842378E-04
-0.1131 0.129067E-02 -0.277770E-05
-0.1176 0.00000 -0.00000
%-------------------------------------------------------------------------
I´ve tried to use the function textread, but until now without success. Could anyone help me?
Thanks! Iury

Accepted Answer

Stephen23
Stephen23 on 4 Jan 2015
Edited: Stephen23 on 4 Jan 2015
This function I just wrote seems to do the trick:
function A = AVLread(fnm)
% Read the entire file into one string:
txt = fileread(fnm);
% Find sections starting 'key: value':
[S,E,T] = regexpi(txt, '^\s*([A-Z]*):\s*(\w*?)\s*$', 'start', 'end', 'tokens', 'lineanchors');
T = vertcat(T{:});
S = [S,numel(txt)];
% Get all numeric values in the first section:
X = regexpi(txt(E(1):S(2)), '([A-Z]+)\s*=\s*(\d+(\.\d+)?)', 'tokens');
X = [X{:}];
X(2:2:end) = cellfun(@(s) sscanf(s,'%f'), X(2:2:end), 'UniformOutput',false);
A = struct(X{:});
% Get the title and configuration:
A.(T{1,1}) = T{1,2};
A.Title = regexpi(txt, '(?<=^\s*)[A-Z].+?(?=\s*$)', 'match', 'once', 'lineanchors');
% Get each remaining section:
fun = @(z,s) regexpi(z, ['(?<=',s,'\S+\s*=\s*)\S+(?=\s*$)'], 'match', 'once', 'lineanchors');
for k = 2:numel(E)
N = sprintf('%s_%s',T{k,:});
Z = txt(1+E(k):S(k+1));
% Get surface type:
A.(N).Type = regexpi(Z, '(?<=\s*)\w+', 'match', 'once');
% Get min/max:
A.(N).min2Y = sscanf(fun(Z,'min'),'%f');
A.(N).max2Y = sscanf(fun(Z,'max'),'%f');
% Indices of the matrix:
[s,e] = regexpi(Z, '(^\s*\S+\s+[^\s=]+\s+\S+\s*$)+', 'lineanchors');
% Get matrix header:
A.(N).Header = regexpi(Z(s(1):e(1)), '(?<=\s*)\S+', 'match');
% Get matrix data:
A.(N).Data = reshape(sscanf(Z(s(2):e(end)),'%f'), 3,[]).';
end
end
Just call it with the filename of the data file:
A = AVLread('test.vm')
Note that it returns all of data in one structure. All numeric data are converted to double. If you double-click the structure in your workspace then you can browse through it: the arrangement should be fairly self-explanatory.
  4 Comments
Iury
Iury on 7 Jan 2015
Thank you again Stephen! This has solved my problem. Thank you for the information and tips.
Iury

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!