/[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.11 - (hide annotations) (download)
Thu Apr 14 23:40:03 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
Changes since 1.10: +27 -34 lines
- Speed optimization
- Better handling of prof_descr field
- Use of ncgetVar.m in MITprof_read.m

1 gforget 1.1 %function: MITprof_read
2 roquet 1.10 %object: read netcdf data files in the "MIT format". Low-level function.
3     % use MITprof_load instead to load data from a MITprof
4     % netcdf file.
5 gforget 1.1 %author: Gael Forget (gforget@mit.edu)
6     %date: june 21th, 2006
7     %
8 gforget 1.3 %usage: [MITprof]=MITprof_read(fileIn);
9 gforget 1.1 % ---> loads full data set
10 gforget 1.3 % [MITprof]=MITprof_read(fileIn,list_vars);
11 gforget 1.1 % ---> loads only the files listed in list_vars cell
12     % array (e.g. list_vars={'prof_T','prof_Tweight'})
13     % plus the one dimensional information (prof_lon etc.)
14     %
15 roquet 1.10 %inputs: fileIn data file name
16     % list_vars variables list (optional)
17 roquet 1.11 % if no list_vars is provided, all fields are loaded.
18 gforget 1.1 %
19     %outputs: MITprof structure containing the various fields/vectors
20    
21 gforget 1.3 function [MITprof]=MITprof_read(fileIn,varargin);
22 gforget 1.1
23 roquet 1.7
24 roquet 1.11 % check that file exists, and open it
25 roquet 1.9 if ~exist(fileIn,'file'), error([fileIn ' : file not found']); end
26 roquet 1.7
27 roquet 1.11 % open netcdf
28     nc=ncopen(fileIn);
29     MITprof=[];
30 gforget 1.1
31 roquet 1.11 % build the list of variable to load
32     if nargin>1; list_vars=varargin{1};
33     else, list_vars=ncvars(nc); end
34     if isempty(list_vars), return, end
35     list_vars=[{'prof_depth','prof_date','prof_lon','prof_lat'} list_vars];
36     [list,m]=unique(list_vars);
37     list_vars=list_vars(sort(m));
38    
39     % load fields into MITprof struct
40     for ii=1:length(list_vars),
41     data=ncgetvar(nc,list_vars{ii});
42     if size(data,1)==1,
43     data=reshape(data,length(data),1);
44     MITprof=setfield(MITprof,list_vars{ii},data);
45 roquet 1.7 else
46 roquet 1.11 MITprof=setfield(MITprof,list_vars{ii},data);
47 roquet 1.7 end
48 roquet 1.11
49     end
50 roquet 1.7
51     %fix old name convention:
52 roquet 1.11 if ~isfield(MITprof,'prof_depth');
53     depth=ncgetvar(nc,'depth');
54 roquet 1.7 MITprof.prof_depth=depth;
55 gforget 1.1 end;
56    
57 roquet 1.11 % close file
58     ncclose(nc);
59    
60 gforget 1.5 %make sure that lon is -180+180:
61 roquet 1.7 %-------------------------------
62 gforget 1.5 tmp_lon=MITprof.prof_lon;
63     tmp_lon(find(tmp_lon>180))=tmp_lon(find(tmp_lon>180))-360;
64     MITprof.prof_lon=tmp_lon;
65    
66 gforget 1.6 %get rid of empty variables:
67 roquet 1.7 %---------------------------
68 gforget 1.6 fldNames=fieldnames(MITprof);
69     for iFld=1:length(fldNames);
70     eval(['test0=isempty(MITprof.' fldNames{iFld} ');']);
71     if test0; MITprof=rmfield(MITprof,fldNames{iFld}); end;
72     end;

  ViewVC Help
Powered by ViewVC 1.1.22