1 |
gforget |
1.1 |
%function: MITprof_read |
2 |
|
|
%object: read netcdf data files in the "MIT format" |
3 |
|
|
%author: Gael Forget (gforget@mit.edu) |
4 |
|
|
%date: june 21th, 2006 |
5 |
|
|
% |
6 |
|
|
%usage: [MITprof]=MITprof_read(dirIn,fileIn); |
7 |
|
|
% ---> loads full data set |
8 |
|
|
% [MITprof]=MITprof_read(dirIn,fileIn,list_vars); |
9 |
|
|
% ---> loads only the files listed in list_vars cell |
10 |
|
|
% array (e.g. list_vars={'prof_T','prof_Tweight'}) |
11 |
|
|
% plus the one dimensional information (prof_lon etc.) |
12 |
|
|
% |
13 |
|
|
%inputs: dirIn data file directory |
14 |
|
|
% fileIn data file name |
15 |
|
|
% (list_vars optional variable list) |
16 |
|
|
% |
17 |
|
|
%outputs: MITprof structure containing the various fields/vectors |
18 |
|
|
|
19 |
|
|
function [MITprof]=MITprof_read(dirIn,fileIn,varargin); |
20 |
|
|
|
21 |
|
|
if nargin>2; list_vars=varargin{1}; |
22 |
|
|
else; list_vars={'prof_T','prof_Tweight','prof_Tmask','prof_Tatlas','prof_Ttest',... |
23 |
|
|
'prof_S','prof_Sweight','prof_Smask','prof_Satlas','prof_Stest',... |
24 |
|
|
'prof_U','prof_Uweight','prof_Umask',... |
25 |
|
|
'prof_V','prof_Vweight','prof_Vmask',... |
26 |
|
|
'prof_ptr','prof_ptrweight','prof_ptrmask',... |
27 |
|
|
'prof_ssh','prof_sshweight','prof_sshmask'}; |
28 |
|
|
end; |
29 |
|
|
|
30 |
|
|
list_vars_plus=[{'prof_depth','prof_date','prof_YYYYMMDD','prof_HHMMSS',... |
31 |
|
|
'prof_lon','prof_lat','prof_basin','prof_point','prof_descr'}... |
32 |
|
|
list_vars]; |
33 |
|
|
|
34 |
|
|
tmp1=dir([dirIn fileIn]); |
35 |
|
|
if isempty(tmp1); tmp1=dir([dirIn fileIn '.nc']); end; |
36 |
|
|
if isempty(tmp1); error([fileIn ' file not found']); end; |
37 |
|
|
nc=netcdf([dirIn tmp1.name],'read'); |
38 |
|
|
|
39 |
|
|
for ii=1:length(list_vars_plus); |
40 |
|
|
tmp1=nc{list_vars_plus{ii}}(:); |
41 |
|
|
if ii==1; MITprof=struct('prof_depth',tmp1); |
42 |
|
|
elseif ~isempty(tmp1); eval(['MITprof.' list_vars_plus{ii} '=tmp1;']); |
43 |
|
|
end; |
44 |
|
|
end; |
45 |
|
|
|
46 |
|
|
close(nc); |
47 |
|
|
|