function [T,x,y,z]=extract_levitus_clim(suff,lon_lo,lon_hi,lat_lo,lat_hi) % % Extract Levitus data from netcdf files % % e.g. % [T,x,y,z]=extract_levitus_clim('temp',-180,180,-90,90); % [S,x,y,z]=extract_levitus_clim('salt',0,360,-90,90); % change a name convention: if strcmp(suff,'temp'); suff = 'theta'; end ncquiet; load DATAPATH fname = fullfile(datapath,['levitus_ann_' suff '.cdf']); theResult=ncload(fname); if isempty(theResult); error([fname ' not found']) end if size(X,1) > 1; X = X'; end if size(Y,1) > 1; Y = Y'; end if size(Z,1) > 1; Z = Z'; end i0=round( lon_lo )+1; i1=round( lon_hi ); j0=round( (lat_lo+90) )+1; j1=round( (lat_hi+90) ); if i1>i0 ii=i0:i1; else ii=[i0:360 1:i1]; end ii=mod(ii+360-1,360)+1; jj=j0:j1; nx=prod(size(ii)); ny=prod(size(jj)); if strcmp(suff,'theta'); T=permute(theta(:,jj,ii),[3 2 1]); elseif strcmp(suff,'salt'); T=permute(sal(:,jj,ii),[3 2 1]); else error(['unknown variable ' suff]) end kk = find(isnan(T)); T(kk) = 0; x=X(ii); ih = find(x>lon_hi); x(ih)=x(ih)-360; il = find(x