1 |
roquet |
1.11 |
function [MITprof]=MITprof_load(fileIn,varargin); |
2 |
gforget |
1.1 |
%function: MITprof_load |
3 |
|
|
%object: read netcdf data files in the "MIT format" |
4 |
|
|
%author: Gael Forget (gforget@mit.edu) |
5 |
|
|
%date: june 21th, 2006 |
6 |
|
|
% |
7 |
|
|
%usage: [MITprof]=MITprof_load(fileIn); |
8 |
roquet |
1.5 |
% ---> loads full data set |
9 |
|
|
% [MITprof]=MITprof_load(fileIn,list_vars); |
10 |
gforget |
1.1 |
% ---> loads only the files listed in list_vars cell |
11 |
|
|
% array (e.g. list_vars={'prof_T','prof_Tweight'}) |
12 |
|
|
% plus the one dimensional information (prof_lon etc.) |
13 |
|
|
% |
14 |
|
|
%note: this does the same as MITprof_read, but |
15 |
roquet |
1.5 |
% - replaces missing values with NaN |
16 |
|
|
% - adds a couple fields: np, nr, nd, list_descr |
17 |
|
|
% - replaces prof_descr with a cell form |
18 |
gforget |
1.1 |
% |
19 |
|
|
%inputs: fileIn data file name |
20 |
roquet |
1.10 |
% list_vars variables list (optional) |
21 |
gforget |
1.1 |
% |
22 |
|
|
%outputs: MITprof structure containing the various fields/vectors |
23 |
|
|
|
24 |
|
|
|
25 |
gforget |
1.2 |
|
26 |
roquet |
1.10 |
% check that file exists and add prefix and suffix if necessary |
27 |
roquet |
1.7 |
[pathstr, name, ext] = fileparts(fileIn); |
28 |
|
|
if isempty(pathstr) | strcmp(pathstr,'.'), pathstr=pwd; end |
29 |
|
|
if isempty(ext) | ~strcmp(ext,'.nc'), ext='.nc'; end |
30 |
|
|
fileIn=[pathstr '/' name ext]; |
31 |
roquet |
1.8 |
if ~exist(fileIn,'file'), error([fileIn ' : file not found']); end |
32 |
gforget |
1.1 |
|
33 |
roquet |
1.10 |
% load data using the low-level function MITprof_read |
34 |
|
|
[MITprof]=MITprof_read(fileIn,varargin{:}); |
35 |
|
|
|
36 |
roquet |
1.5 |
% replace missing_values with NaNs |
37 |
|
|
fldNames=fieldnames(MITprof); |
38 |
roquet |
1.11 |
fldNames=setdiff(fldNames,{'prof_depth','depth'}); % no NaNs in prof_depth |
39 |
gforget |
1.14 |
fldNames=setdiff(fldNames,{'prof_date','prof_YYYYMMDD','prof_HHMMSS'}); |
40 |
|
|
if size(fldNames,2)==1; fldNames=fldNames'; end; |
41 |
|
|
|
42 |
roquet |
1.5 |
for ii=1:length(fldNames); |
43 |
|
|
fld=getfield(MITprof,fldNames{ii}); |
44 |
|
|
if ~isempty(fld) |
45 |
roquet |
1.6 |
f = ncopen(fileIn, 'nowrite'); |
46 |
|
|
varname=fldNames{ii}; |
47 |
|
|
spval=ncgetFillVal(f,varname); |
48 |
|
|
if ~isempty(spval); |
49 |
|
|
fld(fld==spval)=NaN; |
50 |
|
|
MITprof=setfield(MITprof,fldNames{ii},fld); |
51 |
|
|
end; |
52 |
|
|
ncclose(f); |
53 |
roquet |
1.5 |
end |
54 |
gforget |
1.1 |
end; |
55 |
|
|
|
56 |
roquet |
1.11 |
% missing values for prof_date |
57 |
|
|
if isfield(MITprof,'prof_date'), |
58 |
|
|
MITprof.prof_date( isnan(MITprof.prof_YYYYMMDD) )=NaN; |
59 |
|
|
end |
60 |
|
|
|
61 |
gforget |
1.12 |
%quick fix when date/lon/lat is NaN: |
62 |
|
|
%----------------------------------- |
63 |
|
|
ii=find(isnan(MITprof.prof_lon.*MITprof.prof_YYYYMMDD.*MITprof.prof_HHMMSS.*MITprof.prof_lat)); |
64 |
|
|
MITprof.prof_lon(ii)=0; MITprof.prof_lat(ii)=-90; MITprof.prof_YYYYMMDD(ii)=19000101; MITprof.prof_HHMMSS(ii)=000000; |
65 |
|
|
|
66 |
roquet |
1.9 |
%convert prof_descr into a cell array: |
67 |
gforget |
1.1 |
%---------------------------------- |
68 |
roquet |
1.10 |
if isfield(MITprof,'prof_descr') |
69 |
|
|
MITprof.prof_descr=cellstr(MITprof.prof_descr); |
70 |
|
|
MITprof.list_descr=unique(MITprof.prof_descr); |
71 |
|
|
MITprof.nd=length(MITprof.list_descr); |
72 |
|
|
end |
73 |
gforget |
1.1 |
|
74 |
|
|
%add a couple things: |
75 |
|
|
%-------------------- |
76 |
|
|
MITprof.np=length(MITprof.prof_lon); |
77 |
|
|
MITprof.nr=length(MITprof.prof_depth); |
78 |
|
|
|