Documentation of work_dan


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


Help text

 Step 1: Calculate an SST anomaly data set for the 4 by 6 
 latitude-longitude resolution that Yuan used.

Cross-Reference Information

This script calls

Listing of script work_dan



%  First, define path so my routines work
path('/home/disk/tao/dvimont/matlab/NetCDF',path);
path('/home/disk/tao/dvimont/matlab/Stat_Tools',path);

%%%%%%%%%%%%%%%%%%%%%%%%%%%% Start with SLP %%%%%%%%%%%%%%%%%%%%%

%  Load SLP data
cd /home/disk/tao/data/coads/coads1a
filename = 'slp.mean.5097.nc'; 
varname = 'slp';
time = 'all';  %  Equivalently, one may use tim = [1:576], unless 
               %  more months are added.
latlonlim = [0 360 -90 90];
level = 1;

[slp, lat, lon, time] = ...
    getnc2(filename, varname, latlonlim, level, 'all');

%  Make 4x6 degree averages
[ntim, nlat, nlon] = size(slp);
slp2 = repmat(NaN, [ntim nlat/2 nlon/3]);

for i = 1:nlat/2;
  latind = 2*(i-1)+[1:2];
  for j = 1:nlon/3;
    lonind = 3*(j-1)+[1:3];
    slp2(:,i,j) = ...
	squeeze(mean2(mean2(shiftdim(slp(:,latind,lonind), 1))));
  end
end

lat2 = repmat(NaN, [nlat/3 1]);
for i = 1:nlat/2;
  latind = 2*(i-1)+[1:2];
  lat2(i) = mean(lat(latind));
end

lon2 = repmat(NaN, [nlon/3 1]);
for j = 1:nlon/3;
  lonind = 3*(j-1)+[1:3];
  lon2(j) = mean(lon(lonind));
end

%  Now, remove climatology, and rename slp2 to slp

[slp, slpclim] = annave(slp2);

%  Write slp and slpclim to a netcdf file

%  Define (open) NetCDF files
cd /home/disk/tao/data/coads/sstanom4by6
nc_in = netcdf('slpcoadsanom4by6.18541995.nc', 'nowrite');
nc_out = netcdf('slpcoadsanom4by6.19501997.nc', 'clobber');

%  Define other dimensions (lat, lon)
nc_out('lat') = length(lat2);
nc_out('lon') = length(lon2);
%  Define record dimension (time)
nc_out('time') = 0; d = nc_out('time');
d(:) = length(time);

%  Copy variable information (but not data) from nc_in to nc_out
nc_out < nc_in{'lat'};
nc_out{'lat'} < att(nc_in{'lat'});
nc_out < nc_in{'lon'};
nc_out{'lon'} < att(nc_in{'lon'});
nc_out < nc_in{'time'};
nc_out{'time'} < att(nc_in{'time'});
nc_out < nc_in{'data'};
nc_out{'data'} < att(nc_in{'data'});

%  Store dimension variable data into nc_out
nc_out{'lat'}(:) = lat2;
nc_out{'lon'}(:) = lon2;
nc_out{'time'}(1:length(time)) = time;
nc_out{'time'}.units(:) = 'days since 1-1-1 00:00:0.0';

%  Store slp data into nc_out
mv = nc_in{'data'}.missing_value(:);
ao = nc_in{'data'}.add_offset(:);
sf = nc_in{'data'}.scale_factor(:);
slp2 = (slp-ao)/sf;
slp2(isnan(slp2)) = mv;

nc_out{'data'}(:,:,:) = slp2(:,:,:);

%  Add some descriptive attributes

nc_out{'data'}.long_name(:) = ...
    'Sea Level Pressure Monthly Mean at Surface';
nc_out{'data'}.dataset = 'COADS 2-degree Enhanced';
nc_out{'data'}.averaging = ...
    '2 grid points in latitude, 3 grid points in longitude';

close(nc_out);
close(nc_in);


%%%%%%%%%%%%%%%%%%%%%%%%%%%% Next, SST %%%%%%%%%%%%%%%%%%%%%

%  Load SST data
cd /home/disk/tao/data/coads/coads1a
filename = 'sst.mean.5097.nc'; 
varname = 'sst';
time = 'all';  %  Equivalently, one may use tim = [1:576], unless 
               %  more months are added.
latlonlim = [0 360 -90 90];
level = 1;

[sst, lat, lon, time] = ...
    getnc2(filename, varname, latlonlim, level, 'all');

%  Make 4x6 degree averages
[ntim, nlat, nlon] = size(sst);
sst2 = repmat(NaN, [ntim nlat/2 nlon/3]);

for i = 1:nlat/2;
  latind = 2*(i-1)+[1:2];
  for j = 1:nlon/3;
    lonind = 3*(j-1)+[1:3];
    sst2(:,i,j) = ...
	squeeze(mean2(mean2(shiftdim(sst(:,latind,lonind), 1))));
  end
end

lat2 = repmat(NaN, [nlat/3 1]);
for i = 1:nlat/2;
  latind = 2*(i-1)+[1:2];
  lat2(i) = mean(lat(latind));
end

lon2 = repmat(NaN, [nlon/3 1]);
for j = 1:nlon/3;
  lonind = 3*(j-1)+[1:3];
  lon2(j) = mean(lon(lonind));
end

%  Now, remove climatology, and rename sst2 to sst

[sst, sstclim] = annave(sst2);

%  Write sst and sstclim to a netcdf file

%  Define (open) NetCDF files
cd /home/disk/tao/data/coads/sstanom4by6
nc_in = netcdf('sstcoadsanom4by6.18541995.nc', 'nowrite');
nc_out = netcdf('sstcoadsanom4by6.19501997.nc', 'clobber');

%  Define other dimensions (lat, lon)
nc_out('lat') = length(lat2);
nc_out('lon') = length(lon2);
%  Define record dimension (time)
nc_out('time') = 0; d = nc_out('time');
d(:) = length(time);

%  Copy variable information (but not data) from nc_in to nc_out
nc_out < nc_in{'lat'};
nc_out{'lat'} < att(nc_in{'lat'});
nc_out < nc_in{'lon'};
nc_out{'lon'} < att(nc_in{'lon'});
nc_out < nc_in{'time'};
nc_out{'time'} < att(nc_in{'time'});
nc_out < nc_in{'data'};
nc_out{'data'} < att(nc_in{'data'});

%  Store dimension variable data into nc_out
nc_out{'lat'}(:) = lat2;
nc_out{'lon'}(:) = lon2;
nc_out{'time'}(1:length(time)) = time;
nc_out{'time'}.units(:) = 'days since 1-1-1 00:00:0.0';

%  Store sst data into nc_out
mv = nc_in{'data'}.missing_value(:);
ao = nc_in{'data'}.add_offset(:);
sf = nc_in{'data'}.scale_factor(:);
sst2 = (sst-ao)/sf;
sst2(isnan(sst2)) = mv;

nc_out{'data'}(:,:,:) = sst2(:,:,:);

%  Add some descriptive attributes

nc_out{'data'}.long_name(:) = ...
    '"Sea Surface Temperature Monthly Mean at Surface';
nc_out{'data'}.dataset = 'COADS 2-degree Enhanced';
nc_out{'data'}.averaging = ...
    '2 grid points in latitude, 3 grid points in longitude';

close(nc_out);
close(nc_in);




%%%%%%%%%%%%%%%%%%%%%%%%%%%% Next, UWND %%%%%%%%%%%%%%%%%%%%%

%  Load SST data
cd /home/disk/tao/data/coads/coads1a
filename = 'uwnd.mean.5097.nc'; 
varname = 'uwnd';
time = 'all';  %  Equivalently, one may use tim = [1:576], unless 
               %  more months are added.
latlonlim = [0 360 -90 90];
level = 1;

[uwnd, lat, lon, time] = ...
    getnc2(filename, varname, latlonlim, level, 'all');

%  Make 4x6 degree averages
[ntim, nlat, nlon] = size(uwnd);
uwnd2 = repmat(NaN, [ntim nlat/2 nlon/3]);

for i = 1:nlat/2;
  latind = 2*(i-1)+[1:2];
  for j = 1:nlon/3;
    lonind = 3*(j-1)+[1:3];
    uwnd2(:,i,j) = ...
	squeeze(mean2(mean2(shiftdim(uwnd(:,latind,lonind), 1))));
  end
end

lat2 = repmat(NaN, [nlat/3 1]);
for i = 1:nlat/2;
  latind = 2*(i-1)+[1:2];
  lat2(i) = mean(lat(latind));
end

lon2 = repmat(NaN, [nlon/3 1]);
for j = 1:nlon/3;
  lonind = 3*(j-1)+[1:3];
  lon2(j) = mean(lon(lonind));
end

%  Now, remove climatology, and rename uwnd2 to uwnd

[uwnd, uwndclim] = annave(uwnd2);

%  Write uwnd and uwndclim to a netcdf file

%  Define (open) NetCDF files
cd /home/disk/tao/data/coads/sstanom4by6
nc_in = netcdf('slpcoadsanom4by6.18541995.nc', 'nowrite');
nc_out = netcdf('uwndcoadsanom4by6.19501997.nc', 'write');

%  Define other dimensions (lat, lon)
nc_out('lat') = length(lat2);
nc_out('lon') = length(lon2);
%  Define record dimension (time)
nc_out('time') = 0; d = nc_out('time');
d(:) = length(time);

%  Copy variable information (but not data) from nc_in to nc_out
nc_out < nc_in{'lat'};
nc_out{'lat'} < att(nc_in{'lat'});
nc_out < nc_in{'lon'};
nc_out{'lon'} < att(nc_in{'lon'});
nc_out < nc_in{'time'};
nc_out{'time'} < att(nc_in{'time'});
nc_out < nc_in{'data'};
nc_out{'data'} < att(nc_in{'data'});

%  Store dimension variable data into nc_out
nc_out{'lat'}(:) = lat2;
nc_out{'lon'}(:) = lon2;
nc_out{'time'}(1:length(time)) = time;
nc_out{'time'}.units(:) = 'days since 1-1-1 00:00:0.0';

%  Store uwnd data into nc_out
mv = nc_in{'data'}.missing_value(:);
ao = 0.0;
sf = 0.01;
uwnd2 = (uwnd-ao)/sf;
uwnd2(isnan(uwnd2)) = mv;

nc_out{'data'}(:,:,:) = uwnd2(:,:,:);

%  Add some descriptive attributes

nc_out{'data'}.missing_value = ncshort(mv);
nc_out{'data'}.add_offset = ncfloat(ao);
nc_out{'data'}.scale_factor = ncfloat(sf);
nc_out{'data'}.units(:) = 'm/s';

nc_out{'data'}.long_name(:) = ...
    'u-wind Monthly Mean at Surface';
nc_out{'data'}.dataset = 'COADS 2-degree Enhanced';
nc_out{'data'}.averaging = ...
    '2 grid points in latitude, 3 grid points in longitude';

close(nc_out);
close(nc_in);



%%%%%%%%%%%%%%%%%%%%%%%%%%%% Next, UWND 1854--1995 %%%%%%%%%%%%%%

%  Load SST data
cd /home/disk/tao/data/coads/coads1
filename = 'uwnd.mean.nc'; 
varname = 'uwnd';
tim1 = [1:12*(1949-1854+1)];
latlonlim = [0 360 -90 90];
level = 1;

[uwnd1, lat, lon, time1] = ...
    getnc2(filename, varname, latlonlim, level, tim1);

cd /home/disk/tao/data/coads/coads1a
filename = 'uwnd.mean.5097.nc'; 
tim2 = [1:12*(1995-1950+1)];

[uwnd2, lat, lon, time2] = ...
    getnc2(filename, varname, latlonlim, level, tim2);

uwnd = [uwnd1; uwnd2];
clear uwnd1 uwnd2;

%  Make 4x6 degree averages
[ntim, nlat, nlon] = size(uwnd);
uwnd2 = repmat(NaN, [ntim nlat/2 nlon/3]);

for i = 1:nlat/2;
  latind = 2*(i-1)+[1:2];
  for j = 1:nlon/3;
    lonind = 3*(j-1)+[1:3];
    uwnd2(:,i,j) = ...
	squeeze(mean2(mean2(shiftdim(uwnd(:,latind,lonind), 1))));
  end
end

lat2 = repmat(NaN, [nlat/3 1]);
for i = 1:nlat/2;
  latind = 2*(i-1)+[1:2];
  lat2(i) = mean(lat(latind));
end

lon2 = repmat(NaN, [nlon/3 1]);
for j = 1:nlon/3;
  lonind = 3*(j-1)+[1:3];
  lon2(j) = mean(lon(lonind));
end

%  Now, remove climatology, and rename uwnd2 to uwnd

[uwnd, uwndclim] = annave(uwnd2);

%  Write uwnd and uwndclim to a netcdf file

%  Define (open) NetCDF files
cd /home/disk/tao/data/coads/sstanom4by6
nc_in = netcdf('slpcoadsanom4by6.18541995.nc', 'nowrite');
nc_out = netcdf('uwndcoadsanom4by6.18541995.nc', 'clobber');

%  Get time index
time = nc_in{'time', 1}(:);

%  Define other dimensions (lat, lon)
nc_out('lat') = length(lat2);
nc_out('lon') = length(lon2);
%  Define record dimension (time)
nc_out('time') = 0; d = nc_out('time');
d(:) = length(time);

%  Copy variable information (but not data) from nc_in to nc_out
nc_out < nc_in{'lat'};
nc_out{'lat'} < att(nc_in{'lat'});
nc_out < nc_in{'lon'};
nc_out{'lon'} < att(nc_in{'lon'});
nc_out < nc_in{'time'};
nc_out{'time'} < att(nc_in{'time'});
nc_out < nc_in{'data'};
nc_out{'data'} < att(nc_in{'data'});

%  Store dimension variable data into nc_out
nc_out{'lat'}(:) = lat2;
nc_out{'lon'}(:) = lon2;
nc_out{'time'}(1:length(time)) = time;

%  Store uwnd data into nc_out
mv = nc_in{'data'}.missing_value(:);
ao = 0.0;
sf = 0.01;
uwnd2 = (uwnd-ao)/sf;
uwnd2(isnan(uwnd2)) = mv;

nc_out{'data'}(:,:,:) = uwnd2(:,:,:);

%  Add some descriptive attributes

nc_out{'data'}.missing_value = ncshort(mv);
nc_out{'data'}.add_offset = ncfloat(ao);
nc_out{'data'}.scale_factor = ncfloat(sf);
nc_out{'data'}.units(:) = 'm/s';

nc_out{'data'}.long_name(:) = ...
    'u-wind Monthly Mean at Surface';

close(nc_out);
close(nc_in);