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

Contents 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.13 - (show annotations) (download)
Sat Apr 2 14:28:55 2016 UTC (9 years, 3 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.12: +9 -2 lines
- revise handling of prof_date/YYYYMMDD

1 %function: MITprof_read
2 %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 %author: Gael Forget (gforget@mit.edu)
6 %date: june 21th, 2006
7 %
8 %usage: [MITprof]=MITprof_read(fileIn);
9 % ---> loads full data set
10 % [MITprof]=MITprof_read(fileIn,list_vars);
11 % ---> 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 %inputs: fileIn data file name
16 % list_vars variables list (optional)
17 % if no list_vars is provided, all fields are loaded.
18 %
19 %outputs: MITprof structure containing the various fields/vectors
20
21 function [MITprof]=MITprof_read(fileIn,varargin);
22
23
24 % check that file exists, and open it
25 if ~exist(fileIn,'file'), error([fileIn ' : file not found']); end
26
27 % open netcdf
28 nc=ncopen(fileIn);
29 MITprof=[];
30
31 % 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_lon','prof_lat'} list_vars];
36 %if ismember('prof_date',list_vars), list_vars=[{'prof_YYYYMMDD','prof_HHMMSS'} list_vars]; end
37 [list,m]=unique(list_vars);
38 list_vars=list_vars(sort(m));
39
40 % is there only one profile?
41 one_profile=0;
42 data=ncgetvar(nc,'prof_lon');
43 if length(data)==1, one_profile=1; end
44
45 % load fields into MITprof struct
46 for ii=1:length(list_vars),
47 data=ncgetvar(nc,list_vars{ii});
48 if size(data,1)==1 & ~one_profile,
49 data=reshape(data,length(data),1);
50 end
51 MITprof=setfield(MITprof,list_vars{ii},data);
52 end
53
54 % load depth vector separately (either in prof_depth or depth variable)
55 if ismember('prof_depth', list_vars)
56 data=ncgetvar(nc,'prof_depth');
57 elseif ismember('depth', list_vars)
58 data=ncgetvar(nc,'depth');
59 end
60 data=reshape(data,length(data),1);
61 MITprof=setfield(MITprof,'prof_depth',data);
62
63 % add field prof_date if not already in the nc file
64 if ismember('prof_date',list_vars) & ~isfield(MITprof,'prof_date');
65 MITprof.prof_date=datenum(num2str(MITprof.prof_YYYYMMDD*1e6+MITprof.prof_HHMMSS),'yyyymmddHHMMSS');
66 end;
67
68 % add prof_YYYYMMDD and prof_HHMMSS if possible
69 if isfield(MITprof,'prof_date') & ~isfield(MITprof,'prof_YYYYMMDD');
70 tmp1=datevec(MITprof.prof_date);
71 MITprof.prof_YYYYMMDD=tmp1(:,1)*1e4+tmp1(:,2)*1e2+tmp1(:,3);
72 MITprof.prof_HHMMSS=tmp1(:,4)*1e4+tmp1(:,5)*1e2+tmp1(:,6);
73 end;
74
75 % close file
76 ncclose(nc);
77
78 %make sure that lon is -180+180:
79 %-------------------------------
80 tmp_lon=MITprof.prof_lon;
81 tmp_lon(find(tmp_lon>180))=tmp_lon(find(tmp_lon>180))-360;
82 MITprof.prof_lon=tmp_lon;
83
84 %get rid of empty variables:
85 %---------------------------
86 fldNames=fieldnames(MITprof);
87 for iFld=1:length(fldNames);
88 eval(['test0=isempty(MITprof.' fldNames{iFld} ');']);
89 if test0; MITprof=rmfield(MITprof,fldNames{iFld}); end;
90 end;

  ViewVC Help
Powered by ViewVC 1.1.22