% % Read in CS 510 input fields xc1 = zeros(511,511,6); yc1 = zeros(511,511,6); dxf1 = zeros(511,511,6); dyf1 = zeros(511,511,6); ra1 = zeros(511,511,6); xg1 = zeros(511,511,6); yg1 = zeros(511,511,6); dxv1 = zeros(511,511,6); dyu1 = zeros(511,511,6); raz1 = zeros(511,511,6); dxc1 = zeros(511,511,6); dyc1 = zeros(511,511,6); raw1 = zeros(511,511,6); ras1 = zeros(511,511,6); dxg1 = zeros(511,511,6); dyg1 = zeros(511,511,6); for iface=1:6 fid = fopen(['tile00' num2str(iface) '.mitgrid'],'r','b'); xc1(:,:,iface) = fread(fid,[511 511],'real*8'); yc1(:,:,iface) = fread(fid,[511 511],'real*8'); dxf1(:,:,iface) = fread(fid,[511 511],'real*8'); dyf1(:,:,iface) = fread(fid,[511 511],'real*8'); ra1(:,:,iface) = fread(fid,[511 511],'real*8'); xg1(:,:,iface) = fread(fid,[511 511],'real*8'); yg1(:,:,iface) = fread(fid,[511 511],'real*8'); dxv1(:,:,iface) = fread(fid,[511 511],'real*8'); dyu1(:,:,iface) = fread(fid,[511 511],'real*8'); raz1(:,:,iface) = fread(fid,[511 511],'real*8'); dxc1(:,:,iface) = fread(fid,[511 511],'real*8'); dyc1(:,:,iface) = fread(fid,[511 511],'real*8'); raw1(:,:,iface) = fread(fid,[511 511],'real*8'); ras1(:,:,iface) = fread(fid,[511 511],'real*8'); dxg1(:,:,iface) = fread(fid,[511 511],'real*8'); dyg1(:,:,iface) = fread(fid,[511 511],'real*8'); end % % Now output (approx 1 deg) grid ratio = 5; xc2 = zeros(103,103,6); yc2 = zeros(103,103,6); dxf2 = zeros(103,103,6); dyf2 = zeros(103,103,6); ra2 = zeros(103,103,6); xg2 = zeros(103,103,6); yg2 = zeros(103,103,6); dxv2 = zeros(103,103,6); dyu2 = zeros(103,103,6); raz2 = zeros(103,103,6); dxc2 = zeros(103,103,6); dyc2 = zeros(103,103,6); raw2 = zeros(103,103,6); ras2 = zeros(103,103,6); dxg2 = zeros(103,103,6); anglecos2 = zeros(103,103,6); anglesin2 = zeros(103,103,6); dyg2 = zeros(103,103,6); % Create left, x-center, bottom and y-center indeces into 510 grid ileft=[1:5:510]; icent=ileft+2; jbott=[1:5:510]; jcent=jbott+2; % First do the interior of each face for iface=1:6 % lats and lons xc2(1:102,1:102,iface)=xc1(icent,jcent,iface); yc2(1:102,1:102,iface)=yc1(icent,jcent,iface); xg2(1:102,1:102,iface)=xg1(ileft,jbott,iface); yg2(1:102,1:102,iface)=yg1(ileft,jbott,iface); for ipnt=0:ratio-1 dxf2(1:102,1:102,iface)=dxf2(1:102,1:102,iface) + dxf1(ileft+ipnt,jcent,iface); dxg2(1:102,1:102,iface)=dxg2(1:102,1:102,iface) + dxg1(ileft+ipnt,jbott,iface); dxv2(2:102,1:102,iface)=dxv2(2:102,1:102,iface) + dxv1(icent(1:101)+ipnt+1,jbott(1:102),iface); dxc2(2:102,1:102,iface)=dxc2(2:102,1:102,iface) + dxc1(icent(1:101)+ipnt+1,jcent(1:102),iface); end % dx's and dy's for jpnt=0:ratio-1 dyf2(1:102,1:102,iface)=dyf2(1:102,1:102,iface) + dyf1(icent,jbott+jpnt,iface); dyg2(1:102,1:102,iface)=dyg2(1:102,1:102,iface) + dyg1(ileft,jbott+jpnt,iface); dyu2(1:102,2:102,iface)=dyu2(1:102,2:102,iface) + dyu1(ileft(1:102),jcent(1:101)+jpnt+1,iface); dyc2(1:102,2:102,iface)=dyc2(1:102,2:102,iface) + dyc1(icent(1:102),jcent(1:101)+jpnt+1,iface); end % Construct values that we don't know yet - use grid symmetries for edge dx's and dy's dxc2(1,1:102,iface)=dxc1(1,jcent(1:102),iface) + 2.*dxc1(2,jcent(1:102),iface) + 2.*dxc1(3,jcent(1:102),iface); dxv2(1,1:102,iface)=dxv1(1,jbott(1:102),iface) + 2.*dxv1(2,jbott(1:102),iface) + 2.*dxv1(3,jbott(1:102),iface); dyc2(1:102,1,iface)=dyc1(icent(1:102),1,iface) + 2.*dyc1(icent(1:102),2,iface) + 2.*dyc1(icent(1:102),3,iface); dyu2(1:102,1,iface)=dyu1(ileft(1:102),1,iface) + 2.*dyu1(ileft(1:102),2,iface) + 2.*dyu1(ileft(1:102),3,iface); % Areas for ipnt=0:ratio-1 for jpnt=0:ratio-1 ra2(1:102,1:102,iface)=ra2(1:102,1:102,iface) + ra1(ileft+ipnt,jbott+jpnt,iface); ras2(1:102,2:102,iface)=ras2(1:102,2:102,iface) + ras1(ileft(1:102)+ipnt,jcent(1:101)+jpnt+1,iface); raw2(2:102,1:102,iface)=raw2(2:102,1:102,iface) + raw1(icent(1:101)+ipnt+1,jbott(1:102)+jpnt,iface); raz2(2:102,2:102,iface)=raz2(2:102,2:102,iface) + raz1(icent(1:101)+ipnt+1,jcent(1:101)+jpnt+1,iface); end end % Construct values that we don't know yet - use grid symmetries for edge areas for ipnt=0:ratio-1 ras2(1:102,1,iface) = ras2(1:102,1,iface) + ... ras1(ileft(1:102)+ipnt,1,iface) + 2.*ras1(ileft(1:102)+ipnt,2,iface) + 2.*ras1(ileft(1:102)+ipnt,3,iface); end for jpnt=0:ratio-1 raw2(1,1:102,iface) = raw2(1,1:102,iface) + ... raw1(1,jbott(1:102)+jpnt,iface) + 2.*raw1(2,jbott(1:102)+jpnt,iface) + 2.*raw1(3,jbott(1:102)+jpnt,iface); end % Construct values that we don't know yet - vorticity point area, along face edges than at face corner for jpnt=0:ratio-1 raz2(1,2:102,iface) = raz2(1,2:102,iface) + ... raz1(1,jcent(1:101)+jpnt+1,iface) + 2.*raz1(2,jcent(1:101)+jpnt+1,iface) + 2.*raz1(3,jcent(1:101)+jpnt+1,iface); end for ipnt=0:ratio-1 raz2(2:102,1,iface) = raz2(2:102,1,iface) + ... raz1(icent(1:101)+ipnt+1,1,iface) + 2.*raz1(icent(1:101)+1+ipnt,2,iface) + 2.*raz1(icent(1:101)+1+ipnt,3,iface); end raz2(1,1,iface) = sum(raz1(1:3,1,iface),1) + 2.*sum(raz1(1,2:3,iface),2) + ... 3.*sum(raz1(2:3,3,iface),1) + sum(raz1(2:3,2,iface),1); end % Now the exchanges to fill up the extra column and row % Exchange for lon and lat's at center and corners - no directions (xc is always xc) xc2(1:102,103,[1 3 5])=xc2(1,102:-1:1,[3 5 1]); xc2(103,1:102,[1 3 5])=xc2(1,1:102,[2 4 6]); xc2(1:102,103,[2 4 6])=xc2(1:102,1,[3 5 1]); xc2(103,1:102,[2 4 6])=xc2(102:-1:1,1,[4 6 2]); xc2(103,103,[1 2 3 4 5 6])=xc2(1,1,[3 4 5 6 1 2]); yc2(1:102,103,[1 3 5])=yc2(1,102:-1:1,[3 5 1]); yc2(103,1:102,[1 3 5])=yc2(1,1:102,[2 4 6]); yc2(1:102,103,[2 4 6])=yc2(1:102,1,[3 5 1]); yc2(103,1:102,[2 4 6])=yc2(102:-1:1,1,[4 6 2]); yc2(103,103,[1 2 3 4 5 6])=yc2(1,1,[3 4 5 6 1 2]); xg2(1:102,103,[1 3 5])=xg2(1,102:-1:1,[3 5 1]); xg2(103,1:102,[1 3 5])=xg2(1,1:102,[2 4 6]); xg2(1:102,103,[2 4 6])=xg2(1:102,1,[3 5 1]); xg2(103,1:102,[2 4 6])=xg2(102:-1:1,1,[4 6 2]); xg2(103,103,[1 2 3 4 5 6])=xg2(1,1,[3 4 5 6 1 2]); yg2(1:102,103,[1 3 5])=yg2(1,102:-1:1,[3 5 1]); yg2(103,1:102,[1 3 5])=yg2(1,1:102,[2 4 6]); yg2(1:102,103,[2 4 6])=yg2(1:102,1,[3 5 1]); yg2(103,1:102,[2 4 6])=yg2(102:-1:1,1,[4 6 2]); yg2(103,103,[1 2 3 4 5 6])=yg2(1,1,[3 4 5 6 1 2]); % Exchange for areas at center - no directions ra2(1:102,103,[1 3 5])=ra2(1,102:-1:1,[3 5 1]); ra2(103,1:102,[1 3 5])=ra2(1,1:102,[2 4 6]); ra2(1:102,103,[2 4 6])=ra2(1:102,1,[3 5 1]); ra2(103,1:102,[2 4 6])=ra2(102:-1:1,1,[4 6 2]); ra2(103,103,[1 2 3 4 5 6])=ra2(1,1,[3 4 5 6 1 2]); % Exchange for areas at south and west edges - no directions ras2(1:102,103,[1 3 5])=raw2(1,102:-1:1,[3 5 1]); ras2(103,1:102,[1 3 5])=ras2(1,1:102,[2 4 6]); ras2(1:102,103,[2 4 6])=ras2(1:102,1,[3 5 1]); ras2(103,1:102,[2 4 6])=raw2(102:-1:1,1,[4 6 2]); ras2(103,103,[1 2 3 4 5 6])=ras2(1,1,[3 4 5 6 1 2]); raw2(1:102,103,[1 3 5])=ras2(1,102:-1:1,[3 5 1]); raw2(103,1:102,[1 3 5])=raw2(1,1:102,[2 4 6]); raw2(1:102,103,[2 4 6])=raw2(1:102,1,[3 5 1]); raw2(103,1:102,[2 4 6])=ras2(102:-1:1,1,[4 6 2]); raw2(103,103,[1 2 3 4 5 6])=raw2(1,1,[3 4 5 6 1 2]); % Exchange for areas at vorticity points - no directions % Special case: define upper edge assuming symmetry in y % Done because the edge values are ambiguously defined % for quantities defined on a corner %%%%raz2(1:102,103,[1 3 5])=raz2(1,102:-1:1,[3 5 1]); %%%%raz2(1:102,103,[2 4 6])=raz2(1:102,1,[3 5 1]); %%%%raz2(103,1:102,[1 3 5])=raz2(1,1:102,[2 4 6]); %%%%raz2(103,1:102,[2 4 6])=raz2(102:-1:1,1,[4 6 2]); raz2(1:102,103,:)=raz2(1:102,1,:); raz2(103,1:102,:)=raz2(1,1:102,:); raz2(103,103,[1 2 3 4 5 6])=raz2(1,1,[3 4 5 6 1 2]); % % Exchange for dx's and dy's at center - direction but no sign (dx is sometimes from dy) dxf2(1:102,103,[1 3 5])=dyf2(1,102:-1:1,[3 5 1]); dxf2(103,1:102,[1 3 5])=dxf2(1,1:102,[2 4 6]); dxf2(1:102,103,[2 4 6])=dxf2(1:102,1,[3 5 1]); dxf2(103,1:102,[2 4 6])=dyf2(102:-1:1,1,[4 6 2]); dxf2(103,103,[1 2 3 4 5 6])=dxf2(1,1,[3 4 5 6 1 2]); dyf2(1:102,103,[1 3 5])=dxf2(1,102:-1:1,[3 5 1]); dyf2(103,1:102,[1 3 5])=dyf2(1,1:102,[2 4 6]); dyf2(1:102,103,[2 4 6])=dyf2(1:102,1,[3 5 1]); dyf2(103,1:102,[2 4 6])=dxf2(102:-1:1,1,[4 6 2]); dyf2(103,103,[1 2 3 4 5 6])=dyf2(1,1,[3 4 5 6 1 2]); dxg2(1:102,103,[1 3 5])=dyg2(1,102:-1:1,[3 5 1]); dxg2(103,1:102,[1 3 5])=dxg2(1,1:102,[2 4 6]); dxg2(1:102,103,[2 4 6])=dxg2(1:102,1,[3 5 1]); dxg2(103,1:102,[2 4 6])=dyg2(102:-1:1,1,[4 6 2]); dxg2(103,103,[1 2 3 4 5 6])=dxg2(1,1,[3 4 5 6 1 2]); dyg2(1:102,103,[1 3 5])=dxg2(1,102:-1:1,[3 5 1]); dyg2(103,1:102,[1 3 5])=dyg2(1,1:102,[2 4 6]); dyg2(1:102,103,[2 4 6])=dyg2(1:102,1,[3 5 1]); dyg2(103,1:102,[2 4 6])=dxg2(102:-1:1,1,[4 6 2]); dyg2(103,103,[1 2 3 4 5 6])=dyg2(1,1,[3 4 5 6 1 2]); % Exchange for dx's and dy's at edges - direction but no sign (dx is sometimes from dy) dxc2(1:102,103,[1 3 5])=dyc2(1,102:-1:1,[3 5 1]); dxc2(103,1:102,[1 3 5])=dxc2(1,1:102,[2 4 6]); dxc2(1:102,103,[2 4 6])=dxc2(1:102,1,[3 5 1]); dxc2(103,1:102,[2 4 6])=dyc2(102:-1:1,1,[4 6 2]); dxc2(103,103,[1 2 3 4 5 6])=dxc2(1,1,[3 4 5 6 1 2]); dyc2(1:102,103,[1 3 5])=dxc2(1,102:-1:1,[3 5 1]); dyc2(103,1:102,[1 3 5])=dyc2(1,1:102,[2 4 6]); dyc2(1:102,103,[2 4 6])=dyc2(1:102,1,[3 5 1]); dyc2(103,1:102,[2 4 6])=dxc2(102:-1:1,1,[4 6 2]); dyc2(103,103,[1 2 3 4 5 6])=dyc2(1,1,[3 4 5 6 1 2]); % Special case: define upper edge assuming symmetry in y % Done because the edge values are ambiguously defined % for quantities defined on a corner %%%%dxv2(1:102,103,[1 3 5])=dyu2(1,102:-1:1,[3 5 1]); %%%%dxv2(103,1:102,[1 3 5])=dxv2(1,1:102,[2 4 6]); %%%%dxv2(1:102,103,[2 4 6])=dxv2(1:102,1,[3 5 1]); %%%%dxv2(103,1:102,[2 4 6])=dyu2(102:-1:1,1,[4 6 2]); %%%%dyu2(1:102,103,[1 3 5])=dxv2(1,102:-1:1,[3 5 1]); %%%%dyu2(103,1:102,[1 3 5])=dyu2(1,1:102,[2 4 6]); %%%%dyu2(1:102,103,[2 4 6])=dyu2(1:102,1,[3 5 1]); %%%%dyu2(103,1:102,[2 4 6])=dxv2(102:-1:1,1,[4 6 2]); dxv2(1:102,103,:)=dxv2(1:102,1,:); dxv2(103,1:102,:)=dxv2(1,1:102,:); dxv2(103,103,[1 2 3 4 5 6])=dxv2(1,1,[3 4 5 6 1 2]); dyu2(1:102,103,:)=dyu2(1:102,1,:); dyu2(103,1:102,:)=dyu2(1,1:102,:); dyu2(103,103,[1 2 3 4 5 6])=dyu2(1,1,[3 4 5 6 1 2]); % % All done with grid values - now compute angles ygarg1=reshape(permute(yg2(1:102,1:102,:),[1 3 2]),[612 102]); racarg2=reshape(permute(ra2(1:102,1:102,:),[1 3 2]),[612 102]); dxgarg3=reshape(permute(dxg2(1:102,1:102,:),[1 3 2]),[612 102]); dygarg4=reshape(permute(dyg2(1:102,1:102,:),[1 3 2]),[612 102]); [AngleCS,AngleSN] = cubeCalcAngle(ygarg1,racarg2,dxgarg3,dygarg4); anglecos2(1:102,1:102,:)=permute(reshape(AngleCS,[102 6 102]),[1 3 2]); anglesin2(1:102,1:102,:)=permute(reshape(AngleSN,[102 6 102]),[1 3 2]); % % And now write it all out for iface=1:6 fid = fopen(['onedegcube.face00' num2str(iface) '.bin'],'w','b'); fwrite(fid,xc2(:,:,iface),'real*8'); fwrite(fid,yc2(:,:,iface),'real*8'); fwrite(fid,dxf2(:,:,iface),'real*8'); fwrite(fid,dyf2(:,:,iface),'real*8'); fwrite(fid,ra2(:,:,iface),'real*8'); fwrite(fid,xg2(:,:,iface),'real*8'); fwrite(fid,yg2(:,:,iface),'real*8'); fwrite(fid,dxv2(:,:,iface),'real*8'); fwrite(fid,dyu2(:,:,iface),'real*8'); fwrite(fid,raz2(:,:,iface),'real*8'); fwrite(fid,dxc2(:,:,iface),'real*8'); fwrite(fid,dyc2(:,:,iface),'real*8'); fwrite(fid,raw2(:,:,iface),'real*8'); fwrite(fid,ras2(:,:,iface),'real*8'); fwrite(fid,dxg2(:,:,iface),'real*8'); fwrite(fid,dyg2(:,:,iface),'real*8'); fwrite(fid,anglecos2(:,:,iface),'real*8'); fwrite(fid,anglesin2(:,:,iface),'real*8'); fclose(fid); end