Documentation of rw_nmc


Global Index (short | long) | Local contents | Local Index (short | long)


Help text

  rw_nmc;

  slp_nmc=read_nmc;

  This function reads nmc format data, and writes it to a
    file in:

       /home/disk/hayes2/dvimont/ccm/T42

  This file is essentiall created by ccm_climatology, and 
    contains data from a model run.  This program simply 
    overwrites that data.


Cross-Reference Information

This script calls

Listing of script rw_nmc



clear
cd /home/disk/hayes2/dvimont/ccm/T42

%  Define frames

lim=[0 360 -90 90];

%  Set file inputs

file_id1='/home/disk/hayes2/dvimont/ccm/T42/';
file_id2='.nc';

%  Read defaults

file_in=[file_id1, 'hack/hack', file_id2]
[x,nxa,nya,nti,nday,xa,ya,time,xdim,xid]=readnc(file_in,lim);
nc = netcdf(file_in, 'nowrite');
lev = nc{'lev'}(:);
nc = close(nc);

%  Read data for NMC

file_in=[file_id1, 'nmc/slp.monthly.cl7995', file_id2]
[x,nxanmc,nyanmc,nti,nday,xa,ya,time,xdim,xid]=readnc(file_in,lim);

limind = [1 length(nyanmc) 1 length(nxanmc)];

nc = netcdf(file_in, 'nowrite');
slpnmc = nc{'slp'}(:,limind(1):limind(2),limind(3):limind(4));
nc = close(nc);

%  Interpolate slpnmc to the same grid as CCM (lat lon only

[ntm, ny, nx] = size(slpnmc);
ntmvec = 1:ntm;
nxanmc2 = [(nxanmc((nx-1):nx)-360); nxanmc; (nxanmc(1:2)+360)];
slp2 = shiftdim(slpnmc, 2);
slp2 = [slp2(((nx-1):nx),:,:); slp2; slp2(1:2,:,:)];
slp2 = shiftdim(slp2, 1);
slp2 = interpn(ntmvec, nyanmc, nxanmc2, slp2, ntmvec, nya, nxa);
slpnmc = slp2.*100;
clear slp2

%  Read heights

file_in=[file_id1, 'nmc/hgt.monthly.cl7995', file_id2]
nc = netcdf(file_in, 'nowrite');
hgt = nc{'hgt'}(:,:,:,:);
levhgt = nc{'level'}(:);
nc = close(nc);

%  Reshape hgt and add a couple latitude circles so interpolation is better

hgt = shiftdim(hgt, 3);
hgt = [hgt(((nx-1):nx),:,:,:); hgt; hgt(1:2,:,:,:)];
hgt = shiftdim(hgt, 1);
size(hgt)

%  Interpolate heights

for i = 1:length(ntmvec);
  hello(['iteration ' num2str(i)])
  for j = 1:length(levhgt);
    [temp, n] = shiftdim(hgt(i,j,:,:));
    temp = interp2(nxanmc2, nyanmc, temp, nxa', nya);
    hgtnew(i,j,:,:) = shiftdim(temp, -n);
  end
end
hgt = hgtnew;
clear hgtnew;
size(hgt)

levhgt = [levhgt; 0.01];
hgt01 = 82000 .* ones(1, 64, 128, 12);
hgt = shiftdim(hgt, 1);
hgt = [hgt; hgt01];
hgt = shiftdim(hgt, 3);
clear hgt01;

%  Try to write to a NetCDF file:

file_in = [file_id1, 'nmc/nmc_dat', file_id2]
infid = ncmex('OPEN',file_in,'WRITE')

%  Reorder data, so it's in the right format to write.  (Just
%    reverse the order of dimensions).

slpnmcdim = size(slpnmc);
[slpnmc, slpnmcdim] = shift_dim(slpnmc, slpnmcdim, [2 3]);
slpnmc = reshape(slpnmc, slpnmcdim);

hgtdim = size(hgt)
[hgt hgtdim] = shift_dim(hgt, hgtdim, [2 3 4]);
hgt = reshape(hgt, hgtdim);

%  Write the data by first inquiring about the dimesions of the
%    existing data, then replacing it with this new data.

start = 0;
count = -1;
[name,datatype,ndims,dim,natts,levnum] = ncmex('VARINQ',infid,'lev')
status = ncmex('varput',infid,levnum,start,count,levhgt,0)

start = [0 0 0];
count = [-1 -1 -1];
[name,datatype,ndims,dim,natts,pslnum] = ncmex('VARINQ',infid,'PSL')
status = ncmex('varput',infid,pslnum,start,count,slpnmc,0)

start = [0 0 0 0];
count = [-1 -1 -1 -1];
[name,datatype,ndims,dim,natts,hgtnum] = ncmex('VARINQ',infid,'Z3')
status = ncmex('varput',infid,hgtnum,start,count,hgt,0)

infid = ncmex('CLOSE', infid);