Add Matlab Example for SLTAC
Add this code by @rebecca-hummels:
clear all
close all
%% define path to data
base_path = '/data/c2/TMdata/git_geomar_de_data/SLTAC_GLO_PHY_L4_REP/';
SLTAC_version = 'v1.x.x';
path_to_data = [base_path,SLTAC_version,'/data/'];
%% create monthly mean surface geostrophic velocity off Brazil from 2000-2017
% find indices of the region
lat_lim = [-12 -4];
lon_lim = [-40 -30]+360;
lat_nc = -89.875:0.25:89.875;
lon_nc = 0.125:0.25:359.875;
idx = find(lon_nc>lon_lim(1) & lon_nc<lon_lim(2));
idy = find(lat_nc>lat_lim(1) & lat_nc<lat_lim(2));
% choose time period
year_folder = [2000:2017];
u_geo_m = NaN(length(idx),length(idy),length(year_folder)*12);
v_geo_m = u_geo_m;
time_m = NaN(length(year_folder)*12,1);
h=waitbar(0,'Loading and averaging ...');
% load all files of one month and average
for iy = 1:length(year_folder)
filename_year = [path_to_data,num2str(year_folder(iy))];
KK=dir(filename_year);KK=KK(3:end);
for id=1:length(KK)
mm(id)=str2num(KK(id).name(29:30));
end
for im = 1:12
kk = find(mm==im);
u_geo = NaN(length(idx),length(idy),length(kk));
v_geo = u_geo;
for ik = 1:length(kk)
time(ik) = double(ncread([filename_year,'/',KK(kk(ik)).name],'time'))+datenum(1950,1,1,0,0,0);
ugos = double(ncread([filename_year,'/',KK(kk(ik)).name],'ugos'));
u_geo(:,:,ik) = ugos(idx,idy);
vgos = double(ncread([filename_year,'/',KK(kk(ik)).name],'vgos'));
v_geo(:,:,ik) = vgos(idx,idy);
end
u_geo_m(:,:,(iy-1)*12+im) = nanmean(u_geo,3);
v_geo_m(:,:,(iy-1)*12+im) = nanmean(v_geo,3);
time_m((iy-1)*12+im) = nanmean(time);
waitbar(((iy-1)*12+im)/(length(year_folder)*12),h)
end
clear mm KK
end
close(h)
% save as matfile
lon = lon_nc(idx)-360;
lat = lat_nc(idy);
time = time_m;
ugeo_mon = u_geo_m;
vgeo_mon = v_geo_m;
save geo_surf_vel lon lat time ugeo_mon vgeo_mon
% figure(1);clf
% m_proj('mercator','long',[-40 -30],'lat',[-12 -4]);hold on
% m_contourf(lon_nc(idx)-360,lat_nc(idy),nanmean(u_geo_m,3)',[-.5:1/63:.5],'edgecolor','none')
% m_gshhs_h('patch',[.5 .5 .5]); hold on
% colorbar