| 1 |
cnh |
1.1 |
function csg_obj=load_cs_grid(nr,nb,ng,gdir) |
| 2 |
|
|
% |
| 3 |
|
|
% Plot cube sphere grid lines |
| 4 |
|
|
% e.g. load_cs_grid( 32, 32, 32,'float64'); |
| 5 |
|
|
% e.g. load_cs_grid(510,510,510,'float64'); |
| 6 |
|
|
% |
| 7 |
|
|
|
| 8 |
|
|
% Set cartesian/unstructure list toplogy size |
| 9 |
|
|
csg_obj.nx=0; |
| 10 |
|
|
csg_obj.ny=0; |
| 11 |
|
|
|
| 12 |
|
|
% Set cube topology size. |
| 13 |
|
|
csg_obj.nr=nr; |
| 14 |
|
|
csg_obj.nb=nb; |
| 15 |
|
|
csg_obj.ng=ng; |
| 16 |
|
|
|
| 17 |
|
|
% Set format used to read grid variables |
| 18 |
|
|
% Input if 64-bit floats. The store in memory as 32-bit floats option below |
| 19 |
|
|
% can be used to save memory when working with large grids. |
| 20 |
|
|
gvfmt='float64'; |
| 21 |
|
|
gvprec='double'; |
| 22 |
|
|
gvfmt='float64=>float32'; |
| 23 |
|
|
gvprec='single'; |
| 24 |
|
|
|
| 25 |
|
|
% Calculate cube face sizes |
| 26 |
|
|
csg_obj.fx=zeros(6,1); |
| 27 |
|
|
csg_obj.fy=zeros(6,1); |
| 28 |
|
|
for i=1:6 |
| 29 |
|
|
if i == 1 |
| 30 |
|
|
csg_obj.fx(i)=nb; csg_obj.fy(i)=ng; |
| 31 |
|
|
end |
| 32 |
|
|
if i == 2 |
| 33 |
|
|
csg_obj.fx(i)=nr; csg_obj.fy(i)=ng; |
| 34 |
|
|
end |
| 35 |
|
|
if i == 3 |
| 36 |
|
|
csg_obj.fx(i)=nr; csg_obj.fy(i)=nb; |
| 37 |
|
|
end |
| 38 |
|
|
if i == 4 |
| 39 |
|
|
csg_obj.fx(i)=ng; csg_obj.fy(i)=nb; |
| 40 |
|
|
end |
| 41 |
|
|
if i == 5 |
| 42 |
|
|
csg_obj.fx(i)=ng; csg_obj.fy(i)=nr; |
| 43 |
|
|
end |
| 44 |
|
|
if i == 6 |
| 45 |
|
|
csg_obj.fx(i)=nb; csg_obj.fy(i)=nr; |
| 46 |
|
|
end |
| 47 |
|
|
end |
| 48 |
|
|
|
| 49 |
|
|
% Read in physical grid information |
| 50 |
|
|
% This comes from the 6 tile files which hold |
| 51 |
|
|
% sixteen terms |
| 52 |
|
|
% XC , YC , DXF, DYF, RA , XG , YG , DXV, |
| 53 |
|
|
% DYU, RAZ, DXC, DYC, RAW, RAS, DXG, DYG |
| 54 |
|
|
% that define the grid as follows: |
| 55 |
|
|
% XC - Cell center longitude |
| 56 |
|
|
% YC - Cell center latitude |
| 57 |
|
|
% DXF - Cell face spacing in local X direction in meters and |
| 58 |
|
|
% passing through the cell center. |
| 59 |
|
|
% DYF - |
| 60 |
|
|
xcpos=1; ycpos=2; dxfpos=3; dyfpos=4; |
| 61 |
|
|
rapos=5; xgpos=6; ygpos=7; dxvpos=8; |
| 62 |
|
|
dyupos=9; razpos=10; dxcpos=11; dycpos=12; |
| 63 |
|
|
rawpos=13; raspos=14; dxgpos=15; dygpos=16; |
| 64 |
|
|
csg_obj.xcpos = xcpos; |
| 65 |
|
|
csg_obj.ycpos = ycpos; |
| 66 |
|
|
csg_obj.dxfpos = dxfpos; |
| 67 |
|
|
csg_obj.dyfpos = dyfpos; |
| 68 |
|
|
csg_obj.rapos = rapos; |
| 69 |
|
|
csg_obj.xgpos = xgpos; |
| 70 |
|
|
csg_obj.ygpos = ygpos; |
| 71 |
|
|
csg_obj.dxvpos = dxvpos; |
| 72 |
|
|
csg_obj.dyupos = dyupos; |
| 73 |
|
|
csg_obj.razpos = razpos; |
| 74 |
|
|
csg_obj.dxcpos = dxcpos; |
| 75 |
|
|
csg_obj.dycpos = dycpos; |
| 76 |
|
|
csg_obj.rawpos = rawpos; |
| 77 |
|
|
csg_obj.raspos = raspos; |
| 78 |
|
|
csg_obj.dxgpos = dxgpos; |
| 79 |
|
|
csg_obj.dygpos = dygpos; |
| 80 |
|
|
|
| 81 |
|
|
% Each term is a set grid terms for each cube face for a |
| 82 |
|
|
% total of |
| 83 |
|
|
% (nb+1)*(ng+1)*2+(nr+1)*(ng+1)*2+(nr+1)*(nb+1)*2 |
| 84 |
|
|
% points |
| 85 |
|
|
% 1 - create a dummy 2d array to hold the terms |
| 86 |
|
|
nxd=nb+1+nr+1+ng+1+nb+1; |
| 87 |
|
|
nyd=ng+1+nb+1+nr+1; |
| 88 |
|
|
csg_obj.gridarr=cast(ones(nxd,nyd,16)*12345.6789,gvprec); |
| 89 |
|
|
mask_val=csg_obj.gridarr(1,1,1); |
| 90 |
|
|
% 1- Read tile*.mitgrid |
| 91 |
|
|
% holds terms for cube face 1, size (nb+1)*(ng+1) |
| 92 |
|
|
for i= 1:6 |
| 93 |
|
|
fx=csg_obj.fx(i); |
| 94 |
|
|
fy=csg_obj.fy(i); |
| 95 |
|
|
if i == 1 |
| 96 |
|
|
csg_obj.ilog(1)=1;csg_obj.jlog(1)=1; |
| 97 |
|
|
end |
| 98 |
|
|
if i == 2 |
| 99 |
|
|
csg_obj.ilog(2)=csg_obj.ilog(1)+fx+1; |
| 100 |
|
|
csg_obj.jlog(2)=1; |
| 101 |
|
|
end |
| 102 |
|
|
if i == 3 |
| 103 |
|
|
csg_obj.ilog(3)=csg_obj.ilog(1)+fx+1; |
| 104 |
|
|
csg_obj.jlog(3)=csg_obj.jlog(1)+fy+1; |
| 105 |
|
|
end |
| 106 |
|
|
if i == 4 |
| 107 |
|
|
csg_obj.ilog(4)=csg_obj.ilog(3)+fx+1; |
| 108 |
|
|
csg_obj.jlog(4)=csg_obj.jlog(1)+fy+1; |
| 109 |
|
|
end |
| 110 |
|
|
if i == 5 |
| 111 |
|
|
csg_obj.ilog(5)=csg_obj.ilog(3)+fx+1; |
| 112 |
|
|
csg_obj.jlog(5)=csg_obj.jlog(4)+fy+1; |
| 113 |
|
|
end |
| 114 |
|
|
if i == 6 |
| 115 |
|
|
csg_obj.ilog(6)=csg_obj.ilog(5)+fx+1; |
| 116 |
|
|
csg_obj.jlog(6)=csg_obj.jlog(4)+fx+1; |
| 117 |
|
|
end |
| 118 |
|
|
ilog=csg_obj.ilog(i); |
| 119 |
|
|
jlog=csg_obj.jlog(i); |
| 120 |
|
|
ihi=ilog+fx;jhi=jlog+fy; |
| 121 |
|
|
fnam=sprintf('%s/tile%3.3d.mitgrid',gdir,i); |
| 122 |
|
|
fid=fopen(fnam,'r','ieee-be'); |
| 123 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 124 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,xcpos )=reshape(tmp,[(fx+1) (fy+1)]); |
| 125 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 126 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,ycpos )=reshape(tmp,[(fx+1) (fy+1)]); |
| 127 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 128 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,dxfpos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 129 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 130 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,dyfpos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 131 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 132 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,rapos )=reshape(tmp,[(fx+1) (fy+1)]); |
| 133 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 134 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,xgpos )=reshape(tmp,[(fx+1) (fy+1)]); |
| 135 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 136 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,ygpos )=reshape(tmp,[(fx+1) (fy+1)]); |
| 137 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 138 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,dxvpos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 139 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 140 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,dyupos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 141 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 142 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,razpos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 143 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 144 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,dxcpos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 145 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 146 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,dycpos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 147 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 148 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,rawpos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 149 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 150 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,raspos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 151 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 152 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,dxgpos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 153 |
|
|
tmp=fread(fid,(fx+1)*(fy+1),gvfmt); |
| 154 |
|
|
csg_obj.gridarr(ilog:ihi,jlog:jhi,dygpos)=reshape(tmp,[(fx+1) (fy+1)]); |
| 155 |
|
|
fclose(fid); |
| 156 |
|
|
csg_obj.index_i_center(ilog:ihi,jlog:jhi)=cast(repmat([ilog:ihi]',1,jhi-jlog+1),'int32'); |
| 157 |
|
|
csg_obj.index_j_center(ilog:ihi,jlog:jhi)=cast(repmat([jlog:jhi] ,ihi-ilog+1,1),'int32'); |
| 158 |
|
|
csg_obj.face_center(ilog:ihi,jlog:jhi)=cast(i,'int32'); |
| 159 |
|
|
end |
| 160 |
|
|
csg_obj.gridarr(csg_obj.gridarr==mask_val)=NaN; |
| 161 |
|
|
csg_obj.active_mask=csg_obj.gridarr(:,:,1)*0.+1; |
| 162 |
|
|
|
| 163 |
|
|
return |