| 1 | 
mlosch | 
1.3 | 
%clear all | 
| 2 | 
mlosch | 
1.1 | 
 | 
| 3 | 
mlosch | 
1.2 | 
new = 'input.shelfice'; | 
| 4 | 
  | 
  | 
input = 'input'; | 
| 5 | 
mlosch | 
1.1 | 
eostype = 'mdjwf'; | 
| 6 | 
  | 
  | 
 | 
| 7 | 
mlosch | 
1.2 | 
nx = 45; | 
| 8 | 
  | 
  | 
ny = nx*18; | 
| 9 | 
mlosch | 
1.1 | 
nz = 23; | 
| 10 | 
  | 
  | 
nt = 12; | 
| 11 | 
  | 
  | 
 | 
| 12 | 
mlosch | 
1.3 | 
load MASKS | 
| 13 | 
  | 
  | 
hf = msk; | 
| 14 | 
mlosch | 
1.1 | 
load FMT | 
| 15 | 
mlosch | 
1.2 | 
load HN | 
| 16 | 
  | 
  | 
load ZN | 
| 17 | 
  | 
  | 
% $$$ hn = mit_readfield(fullfile(input,'bathy_llc_p90.bin'),[nx ny],fmt); | 
| 18 | 
  | 
  | 
% $$$ hnz = mit_readfield(fullfile(input,'shelfice_bath.bin'),[nx ny],fmt); | 
| 19 | 
  | 
  | 
% $$$ zn = mit_readfield(fullfile(input,'shelfice_topo.bin'),[nx ny],fmt); | 
| 20 | 
mlosch | 
1.1 | 
 | 
| 21 | 
  | 
  | 
h = hn+hnz; | 
| 22 | 
mlosch | 
1.2 | 
mit_writefield(fullfile(new,'bathy_llc_p90.bin'),mdsiocompact(hn),fmt); | 
| 23 | 
  | 
  | 
mit_writefield(fullfile(new,'bathy_llc_p90.shice'),mdsiocompact(h),fmt); | 
| 24 | 
  | 
  | 
mit_writefield(fullfile(new,'shelfice_topo.bin'),mdsiocompact(zn),fmt); | 
| 25 | 
mlosch | 
1.1 | 
 | 
| 26 | 
  | 
  | 
% create hydrographic fields | 
| 27 | 
  | 
  | 
levt = mit_readfield(fullfile(input,'lev_t.bin'),[nx ny nz nt],fmt); | 
| 28 | 
  | 
  | 
levs = mit_readfield(fullfile(input,'lev_s.bin'),[nx ny nz nt],fmt); | 
| 29 | 
  | 
  | 
is = find(zn~=0); | 
| 30 | 
  | 
  | 
[ix,iy] = find(zn~=0); | 
| 31 | 
  | 
  | 
[t,s] = shelfice_hydrography(ix,iy,is,levt,levs); | 
| 32 | 
mlosch | 
1.2 | 
mit_writefield(fullfile(new,'lev_t.shice'),mdsiocompact(t),fmt); | 
| 33 | 
  | 
  | 
mit_writefield(fullfile(new,'lev_s.shice'),mdsiocompact(s),fmt); | 
| 34 | 
  | 
  | 
 | 
| 35 | 
  | 
  | 
% create hydrographic fields | 
| 36 | 
  | 
  | 
levt = mdsiocompact(mit_readfield(fullfile(input,'lev_t.init'),[nx ny nz],fmt),0); | 
| 37 | 
  | 
  | 
levs = mdsiocompact(mit_readfield(fullfile(input,'lev_s.init'),[nx ny nz],fmt),0); | 
| 38 | 
  | 
  | 
is = find(zn~=0); | 
| 39 | 
  | 
  | 
[ix,iy] = find(zn~=0); | 
| 40 | 
  | 
  | 
[t,s] = shelfice_hydrography(ix,iy,is,levt,levs); | 
| 41 | 
  | 
  | 
mit_writefield(fullfile(new,'lev_t.shice.init'),mdsiocompact(t),fmt); | 
| 42 | 
  | 
  | 
mit_writefield(fullfile(new,'lev_s.shice.init'),mdsiocompact(s),fmt); | 
| 43 | 
mlosch | 
1.1 | 
 | 
| 44 | 
  | 
  | 
% create geopotential anomaly | 
| 45 | 
  | 
  | 
gravity = 9.81; | 
| 46 | 
  | 
  | 
rho0 = 1035; | 
| 47 | 
mlosch | 
1.3 | 
tol0 = 0; | 
| 48 | 
mlosch | 
1.1 | 
si2dbar = 1e-4; | 
| 49 | 
  | 
  | 
disp('compute geopotential anomaly') | 
| 50 | 
  | 
  | 
load VGRID | 
| 51 | 
mlosch | 
1.3 | 
zg = zf; | 
| 52 | 
  | 
  | 
dzm = abs([zg(1)-zc(1) .5*diff(zc)]); | 
| 53 | 
  | 
  | 
dzp = abs([.5*diff(zc) zc(end)-zg(end)]); | 
| 54 | 
  | 
  | 
hFacMin = 0.1; | 
| 55 | 
mlosch | 
1.1 | 
for ks=1:length(ix) | 
| 56 | 
  | 
  | 
  t0 = squeeze(mean(t(ix(ks),iy(ks),:,:),4));  | 
| 57 | 
  | 
  | 
  s0 = squeeze(mean(s(ix(ks),iy(ks),:,:),4)); | 
| 58 | 
  | 
  | 
  % compute potential anomaly exactly as in code | 
| 59 | 
  | 
  | 
  % for that we need the correct density | 
| 60 | 
  | 
  | 
  rho = []; | 
| 61 | 
mlosch | 
1.3 | 
  p   = abs(zc(:))*gravity*rho0*si2dbar; | 
| 62 | 
mlosch | 
1.1 | 
  dp  = p; | 
| 63 | 
  | 
  | 
  tol1 = 1; | 
| 64 | 
  | 
  | 
  tol2 = 2; | 
| 65 | 
mlosch | 
1.3 | 
  kp = 0; | 
| 66 | 
  | 
  | 
  while  tol1 > tol0  | 
| 67 | 
  | 
  | 
    kp = kp+1; | 
| 68 | 
  | 
  | 
    p0 = p; | 
| 69 | 
mlosch | 
1.1 | 
    if strcmp(eostype,'mdjwf') | 
| 70 | 
mlosch | 
1.3 | 
      drho =  densmdjwf(s0,t0,p(:,end))-rho0; | 
| 71 | 
mlosch | 
1.1 | 
    else | 
| 72 | 
  | 
  | 
      error(['unknown eostype: ' eostype]); | 
| 73 | 
  | 
  | 
    end | 
| 74 | 
mlosch | 
1.3 | 
    phiHydF(1) = 0; | 
| 75 | 
  | 
  | 
    for k=1:length(zc(:)); | 
| 76 | 
  | 
  | 
      phiHydC(k)   = phiHydF(k) + dzm(k)*gravity*drho(k)/rho0; | 
| 77 | 
  | 
  | 
      phiHydF(k+1) = phiHydC(k) + dzp(k)*gravity*drho(k)/rho0; | 
| 78 | 
  | 
  | 
    end | 
| 79 | 
  | 
  | 
    p   = [p (gravity*rho0*abs(zc(:)) + phiHydC(:)*rho0)/gravity/rho0]; | 
| 80 | 
mlosch | 
1.1 | 
    dp  = p(:,end)-p(:,end-1); | 
| 81 | 
  | 
  | 
    tol2 = tol1; | 
| 82 | 
  | 
  | 
    tol1 = sqrt(sum(dp.^2)); | 
| 83 | 
  | 
  | 
    if tol1==tol2; break; end; | 
| 84 | 
  | 
  | 
  end | 
| 85 | 
  | 
  | 
  % find the appropriate level | 
| 86 | 
  | 
  | 
  zloc = zn(is(ks)); | 
| 87 | 
mlosch | 
1.3 | 
  kl0 = max(find(abs(zg-hFacMin*zg)<=abs(zloc))); | 
| 88 | 
  | 
  | 
  hfloc= squeeze(hf(ix(ks),iy(ks),:)); | 
| 89 | 
  | 
  | 
  kl = min(find(hfloc>0)); | 
| 90 | 
  | 
  | 
  if isempty(kl); | 
| 91 | 
  | 
  | 
    kl = 0; | 
| 92 | 
  | 
  | 
    ph(ks) = 0; | 
| 93 | 
  | 
  | 
  else | 
| 94 | 
  | 
  | 
    ph(ks) = phiHydF(kl); | 
| 95 | 
  | 
  | 
  end | 
| 96 | 
  | 
  | 
  disp(sprintf('kl0 = %u, kl = %u',kl0,kl)); | 
| 97 | 
mlosch | 
1.1 | 
end | 
| 98 | 
  | 
  | 
 | 
| 99 | 
mlosch | 
1.2 | 
pload = 0*hn; | 
| 100 | 
mlosch | 
1.1 | 
for ks=1:length(ix) | 
| 101 | 
  | 
  | 
  pload(ix(ks),iy(ks)) = -ph(ks)*rho0; | 
| 102 | 
  | 
  | 
end | 
| 103 | 
  | 
  | 
 | 
| 104 | 
mlosch | 
1.2 | 
mit_writefield(fullfile(new,['pload.' eostype]),mdsiocompact(pload),fmt); | 
| 105 | 
mlosch | 
1.1 | 
 |