| 1 |
%function: netcdf_ecco_read |
| 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: [depth,myvars,prof_descr,mystruct,mystruct1D]=... |
| 7 |
% netcdf_ecco_read(rep_data,file_data); |
| 8 |
% ---> loads a data set |
| 9 |
% [depth,myvars,prof_descr,mystruct,mystruct1D]=... |
| 10 |
% netcdf_ecco_read(rep_equi,file_equi); |
| 11 |
% ---> loads model counterparts |
| 12 |
% [depth,myvars,prof_descr,mystruct,mystruct1D]=... |
| 13 |
% netcdf_ecco_read(rep_data,file_data,rep_equi,suff_equi); |
| 14 |
% ---> loads both the data set and model counterparts |
| 15 |
% |
| 16 |
%inputs: rep_data data file directory |
| 17 |
% file_data data file name |
| 18 |
% rep_equi model file directory |
| 19 |
% suff_equi model file suffix |
| 20 |
% |
| 21 |
%asumption: file_data is 'blabla.nc', and the |
| 22 |
% model file is named ['blabla' suff_equi] |
| 23 |
% |
| 24 |
%outputs: depth depth vector |
| 25 |
% myvars list of the variables |
| 26 |
% prof_descr instruments/cruises id |
| 27 |
% mystruct struct array containing the |
| 28 |
% data(+model counterparts) and weights(+model mask) |
| 29 |
% mystruct1D struct array of dates and positions |
| 30 |
|
| 31 |
function [depth,myvars,prof_descr,mystruct,mystruct1D]=... |
| 32 |
netcdf_ecco_read(rep_data,file_data,varargin); |
| 33 |
|
| 34 |
list_vars=strvcat('T','S','U','V','ptr','ssh'); |
| 35 |
|
| 36 |
if isempty(varargin) |
| 37 |
%either observations or model counterparts: |
| 38 |
ncload(deblank([rep_data file_data])); |
| 39 |
mystruct_txt='mystruct=struct('; myvars=''; |
| 40 |
for num_var=1:size(list_vars,1) |
| 41 |
name_var=deblank(list_vars(num_var,:)); |
| 42 |
if ~isempty(who(['prof_' name_var])); |
| 43 |
myvars=strvcat(myvars,name_var); |
| 44 |
mystruct_txt=[mystruct_txt '''prof_' name_var ''',{prof_' name_var '}']; |
| 45 |
%for observations: |
| 46 |
if ~isempty(who(['prof_' name_var 'weight'])); |
| 47 |
mystruct_txt=[mystruct_txt ',''prof_' name_var 'weight'',{prof_' name_var 'weight},']; |
| 48 |
%or for model counterparts case: |
| 49 |
else mystruct_txt=[mystruct_txt ',''prof_' name_var 'mask'',{prof_' name_var 'mask},']; end; |
| 50 |
end; |
| 51 |
end; |
| 52 |
|
| 53 |
else |
| 54 |
%read both observations and model: |
| 55 |
rep_equi=varargin{1}; suff_equi=varargin{2}; |
| 56 |
tmp1=strfind(file_data,'.nc'); |
| 57 |
% read the model: |
| 58 |
ncload(deblank([rep_equi file_data(1:tmp1-1) suff_equi])); |
| 59 |
mystruct_txt='mystruct=struct('; myvars=''; |
| 60 |
for num_var=1:size(list_vars,1) |
| 61 |
name_var=deblank(list_vars(num_var,:)); |
| 62 |
if ~isempty(who(['prof_' name_var])); |
| 63 |
myvars=strvcat(myvars,name_var); |
| 64 |
mystruct_txt=[mystruct_txt '''prof_' name_var ''',{prof_' name_var '},']; |
| 65 |
mystruct_txt=[mystruct_txt '''prof_' name_var 'weight'',{prof_' name_var 'weight},']; |
| 66 |
mystruct_txt=[mystruct_txt '''prof_' name_var 'equi'',{prof_' name_var 'equi},']; |
| 67 |
mystruct_txt=[mystruct_txt '''prof_' name_var 'mask'',{prof_' name_var 'mask},']; |
| 68 |
eval(['prof_' name_var 'equi=prof_' name_var ';']); |
| 69 |
end |
| 70 |
end |
| 71 |
% then read the observations: |
| 72 |
tmp1=strfind(file_data,'.nc'); |
| 73 |
ncload(deblank([rep_data file_data(1:tmp1-1) '.nc'])); |
| 74 |
end |
| 75 |
|
| 76 |
%structure the 2D arrays: |
| 77 |
mystruct_txt=[mystruct_txt(1:end-1) ');']; |
| 78 |
eval(mystruct_txt); |
| 79 |
|
| 80 |
%structure the 1D arrays: |
| 81 |
mystruct1D=struct('prof_YYYYMMDD',prof_YYYYMMDD,'prof_HHMMSS',prof_HHMMSS,... |
| 82 |
'prof_lon',prof_lon,'prof_lat',prof_lat); |
| 83 |
|
| 84 |
%accomodate new prof_depth convention: |
| 85 |
if isempty(whos('depth')); depth=prof_depth; end; |
| 86 |
|