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

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

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


Revision 1.7 - (hide annotations) (download)
Mon Apr 11 20:56:08 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
Changes since 1.6: +51 -28 lines
use new interface for old/new netcdf toolbox

1 gforget 1.1 %function: MITprof_read
2     %object: read netcdf data files in the "MIT format"
3     %author: Gael Forget (gforget@mit.edu)
4     %date: june 21th, 2006
5     %
6 gforget 1.3 %usage: [MITprof]=MITprof_read(fileIn);
7 gforget 1.1 % ---> loads full data set
8 gforget 1.3 % [MITprof]=MITprof_read(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 gforget 1.3 %inputs: fileIn data file name
14     % list_vars variables list (optional)
15 gforget 1.1 %
16     %outputs: MITprof structure containing the various fields/vectors
17    
18 gforget 1.3 function [MITprof]=MITprof_read(fileIn,varargin);
19 gforget 1.1
20 roquet 1.7
21     global useNativeMatlabNetcdf;
22     if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end;
23    
24     % check that file exists and add prefix and suffix if necessary
25     if isempty(strfind(fileIn,'/'));
26     fileIn=['./' fileIn];
27     end;
28     if ~exist(fileIn,'file')
29     if ~exist([fileIn '.nc'],'file')
30     error([fileIn ' : file not found']);
31     else
32     fileIn=[fileIn '.nc'];
33     end
34     end
35    
36     % list of variables to read
37     list_vars={'prof_depth','prof_date','prof_YYYYMMDD','prof_HHMMSS',...
38     'prof_lon','prof_lat','prof_basin','prof_point','prof_descr'};
39    
40     % load fields
41     if nargin>1;
42     list_vars=unique({list_vars{:},varargin{1}{:}});
43     for ii=1:length(list_vars),
44     ncload(fileIn,list_vars{ii});
45     end
46     else;
47     f = ncopen(fileIn,'nowrite');
48     list_vars=ncvars(f);
49     ncclose(f);
50     ncload(fileIn);
51 gforget 1.1 end;
52    
53 roquet 1.7 % fill the variable MITprof
54     MITprof=[];
55     N=length(prof_depth);
56     for ii=1:length(list_vars);
57     var=eval(list_vars{ii});
58     if ismember(list_vars{ii},{'prof_depth','prof_HHMMSS','prof_YYYYMMDD',...
59     'prof_lat ','prof_lon','prof_point','prof_basin','prof_date'})
60     MITprof=setfield(MITprof,list_vars{ii},reshape(var,length(var),1));
61     else
62     MITprof=setfield(MITprof,list_vars{ii},var);
63     end
64     end;
65    
66     %fix old name convention:
67     if isempty(prof_depth);
68     ncload(fileIn,'depth');
69     MITprof.prof_depth=depth;
70     clear depth;
71 gforget 1.1 end;
72    
73 gforget 1.5 %make sure that lon is -180+180:
74 roquet 1.7 %-------------------------------
75 gforget 1.5 tmp_lon=MITprof.prof_lon;
76     tmp_lon(find(tmp_lon>180))=tmp_lon(find(tmp_lon>180))-360;
77     MITprof.prof_lon=tmp_lon;
78    
79 gforget 1.6 %get rid of empty variables:
80 roquet 1.7 %---------------------------
81 gforget 1.6 fldNames=fieldnames(MITprof);
82     for iFld=1:length(fldNames);
83     eval(['test0=isempty(MITprof.' fldNames{iFld} ');']);
84     if test0; MITprof=rmfield(MITprof,fldNames{iFld}); end;
85     end;

  ViewVC Help
Powered by ViewVC 1.1.22