NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/read_icq4.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function ret_struct=read_icq4(filename,flag)
2 %READ_ICQ4 read a QUODDY4 .icq4 file
3 %   READ_ICQ4 reads in and parses the Quoddy 4 model
4 %   results contained in an .icq4 output file.
5 %
6 %   The contents of the .icq4 file are returned to the
7 %   MATLAB workspace as a structure contaioning fields
8 %   for each variable.  Type "help fem_icq4_struct"
9 %   for a description of the icq4 structure.
10 %
11 % Input:   icq4name - .icq4 file to read (optional)
12 %          flag     -  See below. (optional)
13 %
14 %          If icq4name is omitted, READ_ICQ4 enables a
15 %          file browser with which the user can specify
16 %          the .icq4 file.  The flag (0|1) is used to
17 %          only read the header info in the .icq4 file.
18 %          flag==0 -> "read only header info"
19 %          flag==1 -> "read entire .icq4 file"
20 %
21 %          Otherwise, READ_ICQ4 takes as input the filename
22 %          of the icq4 data file, either relative or
23 %          absolute, including the .icq4 suffix.
24 %
25 % Output:  The output of READ_ICQ4 is a fem_icq4_struct
26 %          containing the variables with in the .icq4 file.
27 %          The output structure can be passed directly to
28 %          OPNML routines that take .icq4 structures as
29 %          direct input, like VIZICQ4.
30 %
31 % Call as: icq4struct=read_icq4(icq4name);         
32 %      OR: icq4struct=read_icq4(icq4name,flag);         
33 %   
34 % Written by: Brian Blanton (Dec 1998)
35 %
36
37 err1=['READ_ICQ4 requires 0,1,2 input arguments.'];
38 err2=['READ_ICQ4 requires exactly 1 output arguments.'];
39 err3=['Argument to READ_ICQ4 must be a string (filename)'];
40
41 if nargin > 2
42    error(err1)
43 end
44
45 % Assume full read of .icq4 file if flag not specified
46 if nargin==1|nargin==0,flag=1;,end
47
48 if nargout ~=1
49    error(err2)
50 end
51
52 if ~exist('filename')
53    [fname,fpath]=uigetfile('*.icq4','Which .icq4');
54    if fname==0,return,end
55 else
56    if ~isstr(filename),error(err3),end
57    % break into fpath and fname
58    % parse into filename and pathname
59    slash_place=findstr(filename,'/');
60    if length(slash_place)==0
61       fpath=[];
62       fname=filename;
63    else
64       slash_place=slash_place(length(slash_place));
65       fpath=filename(1:slash_place-1);
66       fname=filename(slash_place+1:length(filename));
67    end
68 end
69
70 % get filetype from tail of fname
71 ftype=fname(length(fname)-3:length(fname));
72
73 % make sure this is an allowed filetype
74 if ~strcmp(ftype,'icq4')
75    error(['READ_ICQ4 cannot read ' ftype ' filetype'])
76 end
77
78 % open fname
79 [pfid,message]=fopen([fpath '/' fname]);
80 if pfid==-1
81    error([fpath '/' fname,' not found. ',message]);
82 end
83
84 % read codename and casename from top of file; header line #1,#2
85 codename=fgets(pfid);
86 codename=blank(codename);
87 casename=fgets(pfid);
88 casename=blank(casename);
89 inqfilename=fgets(pfid);
90 inqfilename=blank(inqfilename);
91 inqfilename=strrep(inqfilename(12:length(inqfilename)),' ','');
92
93 initcondname=fgets(pfid);
94 initcondname=blank(initcondname);
95 initcondname=strrep(initcondname(19:length(initcondname)),' ','');
96
97 % Read in the model dimensions
98 temp = fscanf(pfid,'%d %d',2)';
99 nn= temp(1);
100 nnv = temp(2);
101
102 % Read in the model date, time, and time step
103 datain = fscanf(pfid,'%d %d %d %f %f',5);
104 day = datain(1); month = datain(2); year = datain(3);
105 curr_seconds = datain(4); step_seconds = datain(5);
106
107 % Close input file so that read_icq4_mex5 can re-open if needed.
108 fclose(pfid);
109
110 if flag
111    filename=[fpath '/' fname];
112    if isempty(fpath),filename=fname;,end
113    % Do the actual data read in c-mex file.
114    [HMID, UMID, VMID, HOLD, UOLD, VOLD,...
115     ZMID,  ZOLD, UZMID ,VZMID, WZMID, ...
116     Q2MID, Q2LMID, TMPMID, SALMID]=read_icq4_mex5(filename,nn,nnv);
117
118    % Reshape vectors into nn X nnv arrays
119    ZMID   = reshape(ZMID,nn,nnv);
120    ZOLD   = reshape(ZOLD,nn,nnv);
121    UZMID  = reshape(UZMID,nn,nnv);
122    VZMID  = reshape(VZMID,nn,nnv);
123    WZMID  = reshape(WZMID,nn,nnv);
124    Q2MID  = reshape(Q2MID,nn,nnv);
125    Q2LMID = reshape(Q2LMID,nn,nnv);
126    TMPMID = reshape(TMPMID,nn,nnv);
127    SALMID = reshape(SALMID,nn,nnv);
128
129 else
130    HMID = [];UMID = [];VMID = [];ZMID = [];
131    HOLD = [];UOLD = [];VOLD = [];ZOLD = [];
132    UZMID = [];VZMID = [];WZMID = [];Q2MID = [];
133    Q2LMID =[];TMPMID =[];SALMID =[];
134 end
135
136 ret_struct=struct('codename',codename,'casename',casename,'inqfilename',inqfilename,...
137                   'initcondname',initcondname,'nn',nn,'nnv',nnv,...
138                   'day',day,'month',month,'year',year,'curr_seconds',curr_seconds,...
139                   'HMID',HMID',...
140                   'UMID',UMID',...
141                   'VMID',VMID',...
142                   'HOLD',HOLD',...
143                   'UOLD',UOLD',...
144                   'VOLD',VOLD',...
145                   'ZMID',ZMID,...
146                   'ZOLD',ZOLD,...
147                   'UZMID', UZMID,...
148                   'VZMID', VZMID,...
149                   'WZMID', WZMID,...
150                   'Q2MID', Q2MID,...
151                   'Q2LMID',Q2LMID,...
152                   'TMPMID',TMPMID,...
153                   'SALMID',SALMID);
154
155 %
156 %        Brian O. Blanton
157 %        Department of Marine Sciences
158 %        15-1A Venable Hall
159 %        CB# 3300
160 %        Uni. of North Carolina
161 %        Chapel Hill, NC
162 %                 27599-3300
163 %
164 %        919-962-4466
165 %        blanton@marine.unc.edu
166 %
167
168
Note: See TracBrowser for help on using the browser.