/[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.8 - (hide annotations) (download)
Wed Apr 13 22:55:28 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
Changes since 1.7: +1 -1 lines
small bug fix

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 roquet 1.7 [pathstr, name, ext] = fileparts(fileIn);
31     if isempty(pathstr) | strcmp(pathstr,'.'), pathstr=pwd; end
32     if isempty(ext) | ~strcmp(ext,'.nc'), ext='.nc'; end
33     fileIn=[pathstr '/' name ext];
34 roquet 1.8 if ~exist(fileIn,'file'), error([fileIn ' : file not found']); end
35 gforget 1.1
36 roquet 1.5 % replace missing_values with NaNs
37     fldNames=fieldnames(MITprof);
38     for ii=1:length(fldNames);
39 roquet 1.6
40 roquet 1.5 fld=getfield(MITprof,fldNames{ii});
41     if ~isempty(fld)
42 roquet 1.6 f = ncopen(fileIn, 'nowrite');
43     varname=fldNames{ii};
44     spval=ncgetFillVal(f,varname);
45     if ~isempty(spval);
46     fld(fld==spval)=NaN;
47     MITprof=setfield(MITprof,fldNames{ii},fld);
48     end;
49     ncclose(f);
50 roquet 1.5 end
51 gforget 1.3
52 gforget 1.1 end;
53    
54     %replace prof_descr with cell array:
55     %----------------------------------
56 gforget 1.4 MITprof.prof_descr=cellstr(MITprof.prof_descr);
57 gforget 1.1
58     %add a couple things:
59     %--------------------
60     MITprof.np=length(MITprof.prof_lon);
61     MITprof.nr=length(MITprof.prof_depth);
62 gforget 1.4 MITprof.list_descr=unique(MITprof.prof_descr);
63     MITprof.nd=length(MITprof.list_descr);
64 gforget 1.1

  ViewVC Help
Powered by ViewVC 1.1.22