1 %% Copyright (C) 2011, Bilen Oytun Peksel <oytun.peksel@gmail.com>
2 %% All rights reserved.
4 %% Redistribution and use in source and binary forms, with or without
5 %% modification, are permitted provided that the following conditions are met:
7 %% 1 Redistributions of source code must retain the above copyright notice,
8 %% this list of conditions and the following disclaimer.
9 %% 2 Redistributions in binary form must reproduce the above copyright
10 %% notice, this list of conditions and the following disclaimer in the
11 %% documentation and/or other materials provided with the distribution.
13 %% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS''
14 %% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 %% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 %% ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
17 %% ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 %% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 %% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 %% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 %% OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 %% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 %% @deftypefn {Function File} {@var{data} =} pch2mat (@var{filename})
26 %% Converts NASTRAN PCH file (SORT2) to a data structure and frequency vector. A
27 %% filename as a string is the only needed input.
29 %% The output is in the form of struct. containing a freq vector n x 1 called
30 %% data.f, and the remaining data are in the form of subcases, point ids
31 %% and directions respectively. for ex. data.S1.p254686.x and they are n x 2
35 function [data] = pch2mat(filename);
37 %% Open the file and read the file line by line to form a line character array
38 fid = fopen(filename);
45 %% Determine Freq_count and number of lines for each case
46 a = strmatch('$TITLE',raw);
47 lines = a(2) -a(1); %number of lines on each subcase and related point id
48 freq_count = (lines-7)/4;
51 C = length(raw) / lines; %number of subcase and related point id
53 for k = 1 : C; %looping through every case
54 scase = char(raw{(k-1) * lines + 3}(12:16));
55 scase = genvarname(scase);
56 pid = char(raw{(k-1) * lines + 7}(16:25));
57 pid = genvarname(['p' pid]);
59 data.f = zeros(freq_count,1);
61 data.(scase).(pid).x = zeros(freq_count,2);
62 data.(scase).(pid).y = zeros(freq_count,2);
63 data.(scase).(pid).z = zeros(freq_count,2);
64 data.(scase).(pid).r1 = zeros(freq_count,2);
65 data.(scase).(pid).r2 = zeros(freq_count,2);
66 data.(scase).(pid).r3 = zeros(freq_count,2);
67 i = (k-1) * lines + 8 ;
70 while( i <= (lines * k)) %loop for each case
73 data.f(j) = str2double(raw{i}(5:17));
75 data.(scase).(pid).x(j,1) = str2double(raw{i}(25:37));
76 data.(scase).(pid).y(j,1) = str2double(raw{i}(43:55));
77 data.(scase).(pid).z(j,1) = str2double(raw{i}(61:73));
79 data.(scase).(pid).r1(j,1) = str2double(raw{i}(25:37));
80 data.(scase).(pid).r2(j,1) = str2double(raw{i}(43:55));
81 data.(scase).(pid).r3(j,1) = str2double(raw{i}(61:73));
83 data.(scase).(pid).x(j,2) = str2double(raw{i}(25:37));
84 data.(scase).(pid).y(j,2) = str2double(raw{i}(43:55));
85 data.(scase).(pid).z(j,2) = str2double(raw{i}(61:73));
87 data.(scase).(pid).r1(j,2) = str2double(raw{i}(25:37));
88 data.(scase).(pid).r2(j,2) = str2double(raw{i}(43:55));
89 data.(scase).(pid).r3(j,2) = str2double(raw{i}(61:73));