/[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.5 - (hide annotations) (download)
Mon Apr 11 20:56:08 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
Changes since 1.4: +51 -68 lines
use new interface for old/new netcdf toolbox

1 gforget 1.1 %function: MITprof_load
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_load(fileIn);
7 roquet 1.5 % ---> loads full data set
8     % [MITprof]=MITprof_load(fileIn,list_vars);
9 gforget 1.1 % ---> 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     %note: this does the same as MITprof_read, but
14 roquet 1.5 % - replaces missing values with NaN
15     % - adds a couple fields: np, nr, nd, list_descr
16     % - replaces prof_descr with a cell form
17 gforget 1.1 %
18     %inputs: fileIn data file name
19     % list_vars variables list (optional)
20     %
21     %outputs: MITprof structure containing the various fields/vectors
22    
23     function [MITprof]=MITprof_load(fileIn,varargin);
24    
25 gforget 1.2
26 roquet 1.5
27     global useNativeMatlabNetcdf;
28     if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end;
29    
30    
31    
32     % load data using the function MITprof_read
33     [MITprof]=MITprof_read(fileIn,varargin{:});
34    
35     % re-check that file exists and add prefix and suffix if necessary
36     if isempty(strfind(fileIn,'/'));
37     fileIn=['./' fileIn];
38 gforget 1.1 end;
39 roquet 1.5 if ~exist(fileIn,'file')
40     if ~exist([fileIn '.nc'],'file')
41     error([fileIn ' : file not found']);
42     else
43     fileIn=[fileIn '.nc'];
44     end
45     end
46 gforget 1.1
47 roquet 1.5 % replace missing_values with NaNs
48     fldNames=fieldnames(MITprof);
49     for ii=1:length(fldNames);
50    
51     fld=getfield(MITprof,fldNames{ii});
52     if ~isempty(fld)
53     if useNativeMatlabNetcdf;
54     f = netcdf.open(fileIn, 'nowrite');
55     varid = netcdf.inqVarID(f,fldNames{ii});
56     if ~isempty(find(strcmp(ncatts(f,varid),'missing_value')));
57     spval = double(netcdf.getAtt(f,varid,'missing_value'));
58     fld(fld==spval)=NaN;
59     MITprof=setfield(MITprof,fldNames{ii},fld);
60     end;
61     netcdf.close(f);
62     else
63     f = netcdf(fileIn, 'nowrite');
64     spval = f{fldNames{ii}}.missing_value(:);
65     if isempty(spval);
66     spval = f{fldNames{ii}}.FillValue_(:);
67     end
68     if ~isempty(spval);
69     fld(fld==spval)=NaN;
70     MITprof=setfield(MITprof,fldNames{ii},fld);
71     end;
72     close(f);
73 gforget 1.2 end
74 roquet 1.5 end
75 gforget 1.3
76 gforget 1.1 end;
77    
78     %replace prof_descr with cell array:
79     %----------------------------------
80 gforget 1.4 MITprof.prof_descr=cellstr(MITprof.prof_descr);
81 gforget 1.1
82     %add a couple things:
83     %--------------------
84     MITprof.np=length(MITprof.prof_lon);
85     MITprof.nr=length(MITprof.prof_depth);
86 gforget 1.4 MITprof.list_descr=unique(MITprof.prof_descr);
87     MITprof.nd=length(MITprof.list_descr);
88 gforget 1.1

  ViewVC Help
Powered by ViewVC 1.1.22