%function: netcdf_ecco_read %object: read netcdf data files in the "MIT format" %author: Gael Forget (gforget@mit.edu) %date: june 21th, 2006 % %usage: [depth,myvars,prof_descr,mystruct,mystruct1D]=... % netcdf_ecco_read(rep_data,file_data); % ---> loads a data set % [depth,myvars,prof_descr,mystruct,mystruct1D]=... % netcdf_ecco_read(rep_equi,file_equi); % ---> loads model counterparts % [depth,myvars,prof_descr,mystruct,mystruct1D]=... % netcdf_ecco_read(rep_data,file_data,rep_equi,suff_equi); % ---> loads both the data set and model counterparts % %inputs: rep_data data file directory % file_data data file name % rep_equi model file directory % suff_equi model file suffix % %asumption: file_data is 'blabla.nc', and the % model file is named ['blabla' suff_equi] % %outputs: depth depth vector % myvars list of the variables % prof_descr instruments/cruises id % mystruct struct array containing the % data(+model counterparts) and weights(+model mask) % mystruct1D struct array of dates and positions function [depth,myvars,prof_descr,mystruct,mystruct1D]=... netcdf_ecco_read(rep_data,file_data,varargin); list_vars=strvcat('T','S','U','V','ptr','ssh'); if isempty(varargin) %either observations or model counterparts: ncload(deblank([rep_data file_data])); mystruct_txt='mystruct=struct('; myvars=''; for num_var=1:size(list_vars,1) name_var=deblank(list_vars(num_var,:)); if ~isempty(who(['prof_' name_var])); myvars=strvcat(myvars,name_var); mystruct_txt=[mystruct_txt '''prof_' name_var ''',{prof_' name_var '}']; %for observations: if ~isempty(who(['prof_' name_var 'weight'])); mystruct_txt=[mystruct_txt ',''prof_' name_var 'weight'',{prof_' name_var 'weight},']; %or for model counterparts case: else mystruct_txt=[mystruct_txt ',''prof_' name_var 'mask'',{prof_' name_var 'mask},']; end; end; end; else %read both observations and model: rep_equi=varargin{1}; suff_equi=varargin{2}; tmp1=strfind(file_data,'.nc'); % read the model: ncload(deblank([rep_equi file_data(1:tmp1-1) suff_equi])); mystruct_txt='mystruct=struct('; myvars=''; for num_var=1:size(list_vars,1) name_var=deblank(list_vars(num_var,:)); if ~isempty(who(['prof_' name_var])); myvars=strvcat(myvars,name_var); mystruct_txt=[mystruct_txt '''prof_' name_var ''',{prof_' name_var '},']; mystruct_txt=[mystruct_txt '''prof_' name_var 'weight'',{prof_' name_var 'weight},']; mystruct_txt=[mystruct_txt '''prof_' name_var 'equi'',{prof_' name_var 'equi},']; mystruct_txt=[mystruct_txt '''prof_' name_var 'mask'',{prof_' name_var 'mask},']; eval(['prof_' name_var 'equi=prof_' name_var ';']); end end % then read the observations: tmp1=strfind(file_data,'.nc'); ncload(deblank([rep_data file_data(1:tmp1-1) '.nc'])); end %structure the 2D arrays: mystruct_txt=[mystruct_txt(1:end-1) ');']; eval(mystruct_txt); %structure the 1D arrays: mystruct1D=struct('prof_YYYYMMDD',prof_YYYYMMDD,'prof_HHMMSS',prof_HHMMSS,... 'prof_lon',prof_lon,'prof_lat',prof_lat);