On 23 September 2011 08:11, B. Oytun Peksel <oytun.pek...@gmail.com> wrote:
> 2011/9/22 Carnë Draug <carandraug+...@gmail.com>
>> 2011/9/22 B. Oytun Peksel <oytun.pek...@gmail.com>:
>> > 2011/9/22 Carnë Draug <carandraug+...@gmail.com>
>> >> On 20 September 2011 11:18, B. Oytun Peksel <oytun.pek...@gmail.com>
>> >> wrote:
>> >> > I am trying to write a set of functions for importing data from
>> >> > NASTRAN
>> >> > output files. I've started with import routine for *.pch files for
>> >> > dynamic
>> >> > response. However it is still very slow and resource depending. I
>> >> > think
>> >> > I'll
>> >> > need some help from more experienced developers.
>> >>
>> >> On a quick look at the file, I noticed you don't have a copyright
>> >> notice on the file. Could you add that?
>> >>
>> > Absolutely I can if I had some kind of template to take as an example.
>> > Can
>> > you guide me on that?
>>
>> Take a look at this from imtophat
>>
>> http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/image/inst/imtophat.m?revision=8208&content-type=text%2Fplain
>>
>> If you want to use GPL license, just copy and paste the header from
>> this function (you can replace version 2 by version 3), and replace
>> the names and e-mail with yours. This example also shows a simple
>> example for help text (you can use % instead of # to preserver matlab
>> compatibility).
>
> pch2mat V2.
Hi,
apologies for the late reply, I've been traveling the last few days.
I made a few changes to the file you attached, mostly aesthetic, but
also added a semi-colon and removed the 'disp' to make the function
less verbose. I'm also CC'ing Philip Nienhuis as he is the maintainer
of the IO package since it looks as the most likely place for this
function.
Carnë
%% Copyright (c) 2011, Bilen Oytun Peksel <oytun.pek...@gmail.com>
%% All rights reserved.
%%
%% Redistribution and use in source and binary forms, with or without
%% modification, are permitted provided that the following conditions are
%% met:
%%
%% * Redistributions of source code must retain the above copyright
%% notice, this list of conditions and the following disclaimer.
%% * Redistributions in binary form must reproduce the above copyright
%% notice, this list of conditions and the following disclaimer in
%% the documentation and/or other materials provided with the distribution
%%
%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
%% POSSIBILITY OF SUCH DAMAGE.
%% -*- texinfo -*-
%% @deftypefn {Function File} {@var{data} =} pch2mat (@var{filename})
%% Converts NASTRAN PCH file (SORT2) to a data structure and frequency vector. A
%% filename as a string is the only needed input.
%%
%% The output is in the form of struct. containing a freq vector n x 1 called
%% data.f, and the remaining data are in the form of subcases, point ids
%% and directions respectively. for ex. data.S1.p254686.x and they are n x 2
%%
%% @end deftypefn
function [data] = pch2mat(filename);
%% Open the file and read the file line by line to form a line character array
fid = fopen(filename);
l = 1;
while (~feof(fid))
raw{l} = fgets(fid);
l = l + 1;
end
%% Determine Freq_count and number of lines for each case
a = strmatch('$TITLE',raw);
lines = a(2) -a(1); %number of lines on each subcase and related point id
freq_count = (lines-7)/4;
%% Read from array
C = length(raw) / lines; %number of subcase and related point id
for k = 1 : C; %looping through every case
scase = char(raw{(k-1) * lines + 3}(12:16));
scase = genvarname(scase);
pid = char(raw{(k-1) * lines + 7}(16:25));
pid = genvarname(['p' pid]);
if (k==1)
data.f = zeros(freq_count,1);
end;
data.(scase).(pid).x = zeros(freq_count,2);
data.(scase).(pid).y = zeros(freq_count,2);
data.(scase).(pid).z = zeros(freq_count,2);
data.(scase).(pid).r1 = zeros(freq_count,2);
data.(scase).(pid).r2 = zeros(freq_count,2);
data.(scase).(pid).r3 = zeros(freq_count,2);
i = (k-1) * lines + 8 ;
j = 0;
while( i <= (lines * k)) %loop for each case
j=j+1;
if (k==1)
data.f(j) = str2double(raw{i}(5:17));
end
data.(scase).(pid).x(j,1) = str2double(raw{i}(25:37));
data.(scase).(pid).y(j,1) = str2double(raw{i}(43:55));
data.(scase).(pid).z(j,1) = str2double(raw{i}(61:73));
i=i+1;
data.(scase).(pid).r1(j,1) = str2double(raw{i}(25:37));
data.(scase).(pid).r2(j,1) = str2double(raw{i}(43:55));
data.(scase).(pid).r3(j,1) = str2double(raw{i}(61:73));
i=i+1;
data.(scase).(pid).x(j,2) = str2double(raw{i}(25:37));
data.(scase).(pid).y(j,2) = str2double(raw{i}(43:55));
data.(scase).(pid).z(j,2) = str2double(raw{i}(61:73));
i=i+1;
data.(scase).(pid).r1(j,2) = str2double(raw{i}(25:37));
data.(scase).(pid).r2(j,2) = str2double(raw{i}(43:55));
data.(scase).(pid).r3(j,2) = str2double(raw{i}(61:73));
i=i+1;
end
end
end
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev