/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_v2/MITprof_load.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_v2/MITprof_load.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (hide annotations) (download)
Wed Apr 20 20:32:25 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
Changes since 1.10: +11 -1 lines
Better handling of prof_date and FillVal

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     if isfield(MITprof,'prof_date'), % special case for prof_date
40     fldNames=setdiff(fldNames,'prof_date');
41     fldNames=[fldNames,{'prof_YYYYMMDD'}];
42     end
43 roquet 1.5 for ii=1:length(fldNames);
44     fld=getfield(MITprof,fldNames{ii});
45     if ~isempty(fld)
46 roquet 1.6 f = ncopen(fileIn, 'nowrite');
47     varname=fldNames{ii};
48     spval=ncgetFillVal(f,varname);
49     if ~isempty(spval);
50     fld(fld==spval)=NaN;
51     MITprof=setfield(MITprof,fldNames{ii},fld);
52     end;
53     ncclose(f);
54 roquet 1.5 end
55 gforget 1.1 end;
56    
57 roquet 1.11 % missing values for prof_date
58     if isfield(MITprof,'prof_date'),
59     MITprof.prof_date( isnan(MITprof.prof_YYYYMMDD) )=NaN;
60     end
61    
62 roquet 1.9 %convert prof_descr into a cell array:
63 gforget 1.1 %----------------------------------
64 roquet 1.10 if isfield(MITprof,'prof_descr')
65     MITprof.prof_descr=cellstr(MITprof.prof_descr);
66     MITprof.list_descr=unique(MITprof.prof_descr);
67     MITprof.nd=length(MITprof.list_descr);
68     end
69 gforget 1.1
70     %add a couple things:
71     %--------------------
72     MITprof.np=length(MITprof.prof_lon);
73     MITprof.nr=length(MITprof.prof_depth);
74    

  ViewVC Help
Powered by ViewVC 1.1.22