Commit ed6b5111 authored by ashbre's avatar ashbre
Browse files

Adding matlab function for IC generation

parent 2ac80057
clear all
clc
addpath('/projectsa/ETI/Tracer_work/Matlab_progs')
fname = 'initcd_vosaline.nc';
fname_data = 'Sal_16_0000.nc';
z_data = 'domain_cfg.nc';
Sin=ncread(fname_data,'so');
xin=double(ncread(fname_data,'longitude'));
yin=double(ncread(fname_data,'latitude'));
zin=double(ncread(fname_data,'depth'));
Sin=permute(Sin,[2 1 3]);
Sout=double(ncread(fname,'vosaline'));
xout=double(ncread(fname,'x'));
yout=double(ncread(fname,'y'));
dzout=ncread(z_data,'e3t_0');
xout=repmat(xout,1,1,size(Sout,3));
yout=repmat(yout,1,1,size(Sout,3));
z=zeros(size(Sout,1),size(Sout,2),size(Sout,3));
for i=1:size(Sout,3)
if i==1
z(:,:,i)=dzout(:,:,i);
else
z(:,:,i)=z(:,:,i-1)+dzout(:,:,i);
end
end
zin(1)=0;
zin(end)=max(z(:))+1;
%
% parfor i=1:size(Sin,3)
% i
% Sin(:,:,i)=smooth2(Sin(:,:,i),100,100);
%
% end
Sinterp=interp3(xin,yin,zin,Sin,xout,yout,z);
ncid=netcdf.open(fname,'WRITE');
varid = netcdf.inqVarID(ncid,'vosaline');
netcdf.putVar(ncid,varid,Sinterp)
clear all
clc
fname = 'initcd_votemper.nc';
fname_data = 'Temp_16_0000.nc';
z_data = 'domain_cfg.nc';
Tin=ncread(fname_data,'thetao');
xin=double(ncread(fname_data,'longitude'));
yin=double(ncread(fname_data,'latitude'));
zin=double(ncread(fname_data,'depth'));
Tin=permute(Tin,[2 1 3]);
Tout=double(ncread(fname,'votemper'));
xout=double(ncread(fname,'x'));
yout=double(ncread(fname,'y'));
dzout=ncread(z_data,'e3t_0');
xout=repmat(xout,1,1,size(Tout,3));
yout=repmat(yout,1,1,size(Tout,3));
z=zeros(size(Tout,1),size(Tout,2),size(Tout,3));
for i=1:size(Tout,3)
if i==1
z(:,:,i)=dzout(:,:,i);
else
z(:,:,i)=z(:,:,i-1)+dzout(:,:,i);
end
end
zin(1)=0;
zin(end)=max(z(:))+1;
% parfor i=1:size(Tin,3)
% i
% Tin(:,:,i)=smooth2(Tin(:,:,i),100,100);
%
% end
Tinterp=interp3(xin,yin,zin,Tin,xout,yout,z);
ncid=netcdf.open(fname,'WRITE');
varid = netcdf.inqVarID(ncid,'votemper');
netcdf.putVar(ncid,varid,Tinterp)
function [mat_new] = smooth2(mat_old,stencilx,stencily)
%stencil = 2;
% check matrix in each direction
% mat(x,y)
%mat_new=nan(size(mat_old,1),size(mat_old,2));
mat_new = mat_old;
for i=1:size(mat_old,1)
for j=1:size(mat_old,2)
if isnan(mat_old(i,j))
type1=(i-1);
type2=abs(i-size(mat_old,1));
type3=(j-1);
type4=abs(j-size(mat_old,2));
%adj_stencil=min([stencil type1 type2 type3 type4]);
x_min=(i-min([stencilx type1]));
x_max=(i+min([stencilx type2]));
y_min=(j-min([stencily type3]));
y_max=(j+min([stencily type4]));
sub_mat = mat_old(x_min:x_max,y_min:y_max);
mat_new(i,j) = nanmean(sub_mat(:));
%end
% if isnan(mat_old(i,j))
% mat_new(i,j)=NaN;
% end
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment