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

root/gliderproc/trunk/MATLAB/opnml/IO_Functions/read_icq4.m

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

Initial import of Stark code.

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