/[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.8 - (hide annotations) (download)
Wed Apr 13 21:01:33 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
Changes since 1.7: +5 -13 lines
Improvements of MITprof netcdf IO interface. Handling of file names modified.
New functions:
- MITprof_addVar : add a variable to an existing MITprof netcdf file
- MITprof_nc2odv : convert data into ODV4 format

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     % check that file exists and add prefix and suffix if necessary
22 roquet 1.8 [pathstr, name, ext] = fileparts(fileIn);
23     if isempty(pathstr) | strcmp(pathstr,'.'), pathstr=pwd; end
24     if isempty(ext) | ~strcmp(ext,'.nc'), ext='.nc'; end
25     fileIn=[pathstr '/' name ext];
26     if ~exist(filenc,'file'), error([fileIn ' : file not found']); end
27 roquet 1.7
28     % list of variables to read
29     list_vars={'prof_depth','prof_date','prof_YYYYMMDD','prof_HHMMSS',...
30     'prof_lon','prof_lat','prof_basin','prof_point','prof_descr'};
31    
32     % load fields
33     if nargin>1;
34     list_vars=unique({list_vars{:},varargin{1}{:}});
35     for ii=1:length(list_vars),
36     ncload(fileIn,list_vars{ii});
37     end
38     else;
39     f = ncopen(fileIn,'nowrite');
40     list_vars=ncvars(f);
41     ncclose(f);
42     ncload(fileIn);
43 gforget 1.1 end;
44    
45 roquet 1.7 % fill the variable MITprof
46     MITprof=[];
47     N=length(prof_depth);
48     for ii=1:length(list_vars);
49     var=eval(list_vars{ii});
50     if ismember(list_vars{ii},{'prof_depth','prof_HHMMSS','prof_YYYYMMDD',...
51     'prof_lat ','prof_lon','prof_point','prof_basin','prof_date'})
52     MITprof=setfield(MITprof,list_vars{ii},reshape(var,length(var),1));
53     else
54     MITprof=setfield(MITprof,list_vars{ii},var);
55     end
56     end;
57    
58     %fix old name convention:
59     if isempty(prof_depth);
60     ncload(fileIn,'depth');
61     MITprof.prof_depth=depth;
62     clear depth;
63 gforget 1.1 end;
64    
65 gforget 1.5 %make sure that lon is -180+180:
66 roquet 1.7 %-------------------------------
67 gforget 1.5 tmp_lon=MITprof.prof_lon;
68     tmp_lon(find(tmp_lon>180))=tmp_lon(find(tmp_lon>180))-360;
69     MITprof.prof_lon=tmp_lon;
70    
71 gforget 1.6 %get rid of empty variables:
72 roquet 1.7 %---------------------------
73 gforget 1.6 fldNames=fieldnames(MITprof);
74     for iFld=1:length(fldNames);
75     eval(['test0=isempty(MITprof.' fldNames{iFld} ');']);
76     if test0; MITprof=rmfield(MITprof,fldNames{iFld}); end;
77     end;

  ViewVC Help
Powered by ViewVC 1.1.22