/[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.12 - (hide annotations) (download)
Wed Apr 20 20:32:25 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q, checkpoint65t, checkpoint65u
Changes since 1.11: +20 -9 lines
Better handling of prof_date and FillVal

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 roquet 1.12 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 roquet 1.11 [list,m]=unique(list_vars);
38     list_vars=list_vars(sort(m));
39    
40 roquet 1.12 % 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 roquet 1.11 % load fields into MITprof struct
46     for ii=1:length(list_vars),
47     data=ncgetvar(nc,list_vars{ii});
48 roquet 1.12 if size(data,1)==1 & ~one_profile,
49 roquet 1.11 data=reshape(data,length(data),1);
50 roquet 1.7 end
51 roquet 1.12 MITprof=setfield(MITprof,list_vars{ii},data);
52     end
53 roquet 1.11
54 roquet 1.12 % 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 roquet 1.11 end
60 roquet 1.12 data=reshape(data,length(data),1);
61     MITprof=setfield(MITprof,'prof_depth',data);
62 roquet 1.7
63 roquet 1.12 % 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 gforget 1.1 end;
67    
68 roquet 1.11 % close file
69     ncclose(nc);
70    
71 gforget 1.5 %make sure that lon is -180+180:
72 roquet 1.7 %-------------------------------
73 gforget 1.5 tmp_lon=MITprof.prof_lon;
74     tmp_lon(find(tmp_lon>180))=tmp_lon(find(tmp_lon>180))-360;
75     MITprof.prof_lon=tmp_lon;
76    
77 gforget 1.6 %get rid of empty variables:
78 roquet 1.7 %---------------------------
79 gforget 1.6 fldNames=fieldnames(MITprof);
80     for iFld=1:length(fldNames);
81     eval(['test0=isempty(MITprof.' fldNames{iFld} ');']);
82     if test0; MITprof=rmfield(MITprof,fldNames{iFld}); end;
83     end;

  ViewVC Help
Powered by ViewVC 1.1.22