/[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.6 - (hide annotations) (download)
Mon Apr 11 21:36:26 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
Changes since 1.5: +9 -28 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 % load data using the function MITprof_read
27     [MITprof]=MITprof_read(fileIn,varargin{:});
28    
29     % re-check that file exists and add prefix and suffix if necessary
30     if isempty(strfind(fileIn,'/'));
31     fileIn=['./' fileIn];
32 gforget 1.1 end;
33 roquet 1.5 if ~exist(fileIn,'file')
34     if ~exist([fileIn '.nc'],'file')
35     error([fileIn ' : file not found']);
36     else
37     fileIn=[fileIn '.nc'];
38     end
39     end
40 gforget 1.1
41 roquet 1.5 % replace missing_values with NaNs
42     fldNames=fieldnames(MITprof);
43     for ii=1:length(fldNames);
44 roquet 1.6
45 roquet 1.5 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.3
57 gforget 1.1 end;
58    
59     %replace prof_descr with cell array:
60     %----------------------------------
61 gforget 1.4 MITprof.prof_descr=cellstr(MITprof.prof_descr);
62 gforget 1.1
63     %add a couple things:
64     %--------------------
65     MITprof.np=length(MITprof.prof_lon);
66     MITprof.nr=length(MITprof.prof_depth);
67 gforget 1.4 MITprof.list_descr=unique(MITprof.prof_descr);
68     MITprof.nd=length(MITprof.list_descr);
69 gforget 1.1

  ViewVC Help
Powered by ViewVC 1.1.22