function [ts,x,y,z]=extract_levitus_monthly(suff,months,lon_lo,lon_hi,lat_lo,lat_hi) % % Extract monthly Levitus data from netcdf files % % e.g. % [T,x,y,z]=extract_levitus_monthly('temp',1,-180,180,-90,90); % [S,x,y,z]=extract_levitus_monthly('salt',1:12,0,360,-90,90); % change a name convention: if strcmp(suff,'temp'); suff = 'theta'; end ncquiet; load DATAPATH datapath fname = fullfile(datapath,['levitus_month_' 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 if size(T,1) > 1; T = T'; 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'); ts=permute(theta(months,:,jj,ii),[4 3 2 1]); elseif strcmp(suff,'salt'); ts=permute(sal(months,:,jj,ii),[4 3 2 1]); else error(['unknown variable ' suff]) end kk = find(isnan(ts)); ts(kk) = 0; x=X(ii); ih = find(x>lon_hi); x(ih)=x(ih)-360; il = find(x