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

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

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


Revision 1.9 - (hide annotations) (download)
Thu Apr 14 20:12:07 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
Changes since 1.8: +3 -5 lines
- Simplification of IO interface to MITcdf netcdf format.
  MITprof_create and MITprof_read are now low-level functions that should not be used by user.
  Instead, use MITprof_write to create/update a file, and MITprof_load to load data.
- Depth levels must now be provided as an argument of MITprof_create and MITprof_struct,
  and cannot be changed once the MITprof ncfile or struct have been created.
- profiles_prep_main and profiles_prep_write_nc have been changed accordingly.

1 gforget 1.1 %function: MITprof_load
2     %object: read netcdf data files in the "MIT format"
3     %author: Gael Forget (gforget@mit.edu)
4     %date: june 21th, 2006
5     %
6     %usage: [MITprof]=MITprof_load(fileIn);
7 roquet 1.5 % ---> loads full data set
8     % [MITprof]=MITprof_load(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     %note: this does the same as MITprof_read, but
14 roquet 1.5 % - replaces missing values with NaN
15     % - adds a couple fields: np, nr, nd, list_descr
16     % - replaces prof_descr with a cell form
17 gforget 1.1 %
18     %inputs: fileIn data file name
19 roquet 1.9 % list_vars variables list (optional)
20 gforget 1.1 %
21     %outputs: MITprof structure containing the various fields/vectors
22    
23     function [MITprof]=MITprof_load(fileIn,varargin);
24    
25 gforget 1.2
26 roquet 1.9 % load data using the low-level function MITprof_read
27 roquet 1.5 [MITprof]=MITprof_read(fileIn,varargin{:});
28    
29     % re-check that file exists and add prefix and suffix if necessary
30 roquet 1.7 [pathstr, name, ext] = fileparts(fileIn);
31     if isempty(pathstr) | strcmp(pathstr,'.'), pathstr=pwd; end
32     if isempty(ext) | ~strcmp(ext,'.nc'), ext='.nc'; end
33     fileIn=[pathstr '/' name ext];
34 roquet 1.8 if ~exist(fileIn,'file'), error([fileIn ' : file not found']); end
35 gforget 1.1
36 roquet 1.5 % replace missing_values with NaNs
37     fldNames=fieldnames(MITprof);
38     for ii=1:length(fldNames);
39     fld=getfield(MITprof,fldNames{ii});
40     if ~isempty(fld)
41 roquet 1.6 f = ncopen(fileIn, 'nowrite');
42     varname=fldNames{ii};
43     spval=ncgetFillVal(f,varname);
44     if ~isempty(spval);
45     fld(fld==spval)=NaN;
46     MITprof=setfield(MITprof,fldNames{ii},fld);
47     end;
48     ncclose(f);
49 roquet 1.5 end
50 gforget 1.1 end;
51    
52 roquet 1.9 %convert prof_descr into a cell array:
53 gforget 1.1 %----------------------------------
54 gforget 1.4 MITprof.prof_descr=cellstr(MITprof.prof_descr);
55 gforget 1.1
56     %add a couple things:
57     %--------------------
58     MITprof.np=length(MITprof.prof_lon);
59     MITprof.nr=length(MITprof.prof_depth);
60 gforget 1.4 MITprof.list_descr=unique(MITprof.prof_descr);
61     MITprof.nd=length(MITprof.list_descr);
62 gforget 1.1

  ViewVC Help
Powered by ViewVC 1.1.22