/[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.1 - (hide annotations) (download)
Mon Nov 8 19:45:58 2010 UTC (14 years, 8 months ago) by gforget
Branch: MAIN
- MITprof_load.m same as MITprof_read.m but different...
- MITprof_concat.m concatenate two MITprof objects in memory.
- MITprof_subset.m extracts a subset of MITprof.
- MITprof_bin.m bin averages MITprof to a grid.
- MITprof_stats.m does a few stats over MITprof.

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     % ---> loads full data set
8     % [MITprof]=MITprof_load(fileIn,list_vars);
9     % ---> 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     % - removes empty fields
15     % - replaces missing values with NaN
16     % - adds a couple fields
17     % - replaces prof_descr with a cell form
18     %
19     %inputs: fileIn data file name
20     % list_vars variables list (optional)
21     %
22     %outputs: MITprof structure containing the various fields/vectors
23    
24     function [MITprof]=MITprof_load(fileIn,varargin);
25    
26     if nargin>1; list_vars=varargin{1};
27     else; list_vars={'prof_T','prof_Tweight','prof_Tmask','prof_Testim','prof_Tflag',...
28     'prof_S','prof_Sweight','prof_Smask','prof_Sestim','prof_Sflag',...
29     'prof_U','prof_Uweight','prof_Umask',...
30     'prof_V','prof_Vweight','prof_Vmask',...
31     'prof_ptr','prof_ptrweight','prof_ptrmask',...
32     'prof_ssh','prof_sshweight','prof_sshmask'};
33     end;
34    
35     list_vars_plus=[{'prof_depth','prof_date','prof_YYYYMMDD','prof_HHMMSS',...
36     'prof_lon','prof_lat','prof_basin','prof_point','prof_descr'}...
37     list_vars];
38    
39     %get directory name:
40     tmp1=strfind(fileIn,'/');
41     if ~isempty(tmp1); dirIn=fileIn(1:tmp1(end)); else; dirIn='./'; end;
42     %check that file exists:
43     tmp1=dir(fileIn);
44     if isempty(tmp1); tmp1=dir([fileIn '.nc']); end;
45     if isempty(tmp1); error([fileIn ' file not found']); end;
46    
47     for ii=1:length(list_vars_plus);
48     ncload([dirIn tmp1.name],list_vars_plus{ii});
49     %nan mask the data:
50     eval(['test0=~isempty(' list_vars_plus{ii} ');']);
51     if test0;
52     f = netcdf.open([dirIn tmp1.name], 'nowrite');
53     varid = netcdf.inqVarId(f,list_vars_plus{ii});
54     test1=~isempty(find(strcmp(ncatts(f,varid),'missing_value')));
55     if test1;
56     spval = double(netcdf.getAtt(f,varid,'missing_value'));
57     eval([list_vars_plus{ii} '(' list_vars_plus{ii} '==spval)=NaN;']);
58     end;
59     netcdf.close(f);
60     end;
61     %
62     if ii==1; eval(['MITprof=struct(''prof_depth'',prof_depth);']);
63     elseif ~isempty(tmp1); eval(['MITprof.' list_vars_plus{ii} '=' list_vars_plus{ii} ';']);
64     end; eval(['clear ' list_vars_plus{ii} ']);']);
65     end;
66    
67     %replace prof_descr with cell array:
68     %----------------------------------
69     np=length(MITprof.prof_lon); prof_descr={};
70     for pp=1:np; prof_descr(pp)={MITprof.prof_descr(pp,:)}; end;
71     MITprof.prof_descr=prof_descr';
72    
73     %get rid of empty variables:
74     %---------------------------
75     fldNames=fieldnames(MITprof);
76     for iFld=1:length(fldNames);
77     eval(['test0=isempty(MITprof.' fldNames{iFld} ');']);
78     if test0; MITprof=rmfield(MITprof,fldNames{iFld}); end;
79     end;
80    
81     %add a couple things:
82     %--------------------
83     MITprof.np=length(MITprof.prof_lon);
84     MITprof.nr=length(MITprof.prof_depth);
85    

  ViewVC Help
Powered by ViewVC 1.1.22