/[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.13 - (hide annotations) (download)
Sat Jan 18 22:48:45 2014 UTC (11 years, 6 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q, checkpoint65t, checkpoint65u
Changes since 1.12: +2 -1 lines
- accomodate 2013 matlab update (unique.m output format changed).

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 gforget 1.13 if size(fldNames,2)==1; fldNames=fldNames'; end;
42     fldNames=[fldNames {'prof_YYYYMMDD'}];
43 roquet 1.11 end
44 roquet 1.5 for ii=1:length(fldNames);
45     fld=getfield(MITprof,fldNames{ii});
46     if ~isempty(fld)
47 roquet 1.6 f = ncopen(fileIn, 'nowrite');
48     varname=fldNames{ii};
49     spval=ncgetFillVal(f,varname);
50     if ~isempty(spval);
51     fld(fld==spval)=NaN;
52     MITprof=setfield(MITprof,fldNames{ii},fld);
53     end;
54     ncclose(f);
55 roquet 1.5 end
56 gforget 1.1 end;
57    
58 roquet 1.11 % missing values for prof_date
59     if isfield(MITprof,'prof_date'),
60     MITprof.prof_date( isnan(MITprof.prof_YYYYMMDD) )=NaN;
61     end
62    
63 gforget 1.12 %quick fix when date/lon/lat is NaN:
64     %-----------------------------------
65     ii=find(isnan(MITprof.prof_lon.*MITprof.prof_YYYYMMDD.*MITprof.prof_HHMMSS.*MITprof.prof_lat));
66     MITprof.prof_lon(ii)=0; MITprof.prof_lat(ii)=-90; MITprof.prof_YYYYMMDD(ii)=19000101; MITprof.prof_HHMMSS(ii)=000000;
67    
68 roquet 1.9 %convert prof_descr into a cell array:
69 gforget 1.1 %----------------------------------
70 roquet 1.10 if isfield(MITprof,'prof_descr')
71     MITprof.prof_descr=cellstr(MITprof.prof_descr);
72     MITprof.list_descr=unique(MITprof.prof_descr);
73     MITprof.nd=length(MITprof.list_descr);
74     end
75 gforget 1.1
76     %add a couple things:
77     %--------------------
78     MITprof.np=length(MITprof.prof_lon);
79     MITprof.nr=length(MITprof.prof_depth);
80    

  ViewVC Help
Powered by ViewVC 1.1.22