1 |
function [MITprof]=MITprof_load(fileIn,varargin); |
2 |
%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 |
% ---> loads full data set |
9 |
% [MITprof]=MITprof_load(fileIn,list_vars); |
10 |
% ---> 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 |
% - replaces missing values with NaN |
16 |
% - adds a couple fields: np, nr, nd, list_descr |
17 |
% - replaces prof_descr with a cell form |
18 |
% |
19 |
%inputs: fileIn data file name |
20 |
% list_vars variables list (optional) |
21 |
% |
22 |
%outputs: MITprof structure containing the various fields/vectors |
23 |
|
24 |
|
25 |
|
26 |
% check that file exists and add prefix and suffix if necessary |
27 |
[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 |
if ~exist(fileIn,'file'), error([fileIn ' : file not found']); end |
32 |
|
33 |
% load data using the low-level function MITprof_read |
34 |
[MITprof]=MITprof_read(fileIn,varargin{:}); |
35 |
|
36 |
% replace missing_values with NaNs |
37 |
fldNames=fieldnames(MITprof); |
38 |
fldNames=setdiff(fldNames,{'prof_depth','depth'}); % no NaNs in prof_depth |
39 |
fldNames=setdiff(fldNames,{'prof_date','prof_YYYYMMDD','prof_HHMMSS'}); |
40 |
if size(fldNames,2)==1; fldNames=fldNames'; end; |
41 |
|
42 |
for ii=1:length(fldNames); |
43 |
fld=getfield(MITprof,fldNames{ii}); |
44 |
if ~isempty(fld) |
45 |
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 |
end |
54 |
end; |
55 |
|
56 |
% missing values for prof_date |
57 |
if isfield(MITprof,'prof_date'), |
58 |
MITprof.prof_date( isnan(MITprof.prof_YYYYMMDD) )=NaN; |
59 |
end |
60 |
|
61 |
%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 |
%convert prof_descr into a cell array: |
67 |
%---------------------------------- |
68 |
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 |
|
74 |
%add a couple things: |
75 |
%-------------------- |
76 |
MITprof.np=length(MITprof.prof_lon); |
77 |
MITprof.nr=length(MITprof.prof_depth); |
78 |
|