Ticket #309: my_flex_read_header.m

File my_flex_read_header.m, 1.5 KB (added by zhangxun, 7 months ago)

my flex_read_header.m code

Line 
1%% beginning
2clear all;
3clc;
4pathname = 'C:\Users\dell\Desktop\matlab4FLEXPART\';
5% anonymous helper function to skip some bytes
6skip = @(fid) fread(fid,2,'int32');
7
8nest=0; 
9readp=1; % default: do not read release points
10calcarea=0;
11%
12datespath=pathname;
13header.path=pathname;
14fhd=fopen([header.path 'header']);
15%fprintf('\nreading header');
16header.nest=0;
17%%
18% default settings
19header.decayconstant=0;
20
21  % start reading if header was opened
22if fhd~=-1
23  rl=fread(fhd,1,'int32'); 
24  header.open=1;
25  header.ibdate=fread(fhd,1,'int32');
26  header.ibtime=fread(fhd,1,'int32');
27  pivot_vec=(datevec(date));
28  header.simulationstart=datenum([num2str(header.ibdate)  num2str(header.ibtime,'%06d')],'yyyymmddhhMMss');
29  header.ver=char(transpose(fread(fhd,13,'char')));
30  %%
31  skip(fhd);
32  header.loutstep=fread(fhd,1,'int32');
33  header.loutaver=fread(fhd,1,'int32');
34  header.loutsample=fread(fhd,1,'int32');
35   
36  skip(fhd);
37  header.outlon0=fread(fhd,1,'float');
38  header.outlat0=fread(fhd,1,'float');
39  header.numxgrid=fread(fhd,1,'int32');
40  header.numygrid=fread(fhd,1,'int32');   
41  header.dxout=fread(fhd,1,'float');
42  header.dyout=fread(fhd,1,'float',8);
43  header.numzgrid=fread(fhd,1,'int32');
44  header.outheight=fread(fhd,header.numzgrid,'float');
45  header.outheight=cat(1,[0],header.outheight);
46  skip(fhd);
47  header.jjjjmmdd=fread(fhd,1,'int32');   
48  header.hhmmss=fread(fhd,1,'int32',8);   
49  header.nspec=fread(fhd,1,'int32')/3;
50end
51%%
hosted by ZAMG