function [bathy_obj]=load_cs_bathy(csg_obj,gdir,fname,prec); % % Load cube sphere bathymetry % e.g. load_cs_bathy(csg,'t32','bathy.bin','float64'); % returns bathymetry and polygons that define bathymetry. % % 1 - Read land ng=csg_obj.ng; nb=csg_obj.nb; nr=csg_obj.nr; nxd=nb+1+nr+1+ng+1+nb+1; nyd=ng+1+nb+1+nr+1; fnam=sprintf('%s/%s',gdir,fname); fid=fopen(fnam,'r','ieee-be'); tmparr=ones(ng*6*ng,1); tmparr=fread(fid,ng*ng*6,prec); tmparr=reshape(tmparr,[ng*6,ng]); fclose(fid); bathyarr=ones(nxd,nyd)*12345.6789; for i= 1:6 ilog=csg_obj.ilog(i); jlog=csg_obj.jlog(i); fx=csg_obj.fx(i); fy=csg_obj.fy(i); ihi=ilog+fx-1;jhi=jlog+fy-1; tmp=tmparr((i-1)*ng+1:i*ng,1:ng); bathyarr(ilog:ihi,jlog:jhi)=reshape(tmp,[fx fy]); end bathyarr(find(bathyarr==12345.6789))=NaN; % Do some plots on a lat-lon figure clf axis([-180 180 -90 90]);hold on; xg=csg_obj.gridarr(:,:,csg_obj.xgpos); yg=csg_obj.gridarr(:,:,csg_obj.ygpos); clear xc yc; nc=0; np=0; clear xcoord ycoord; xcoord=ones(2,ng*ng*6*4); ycoord=ones(2,ng*ng*6*4); for t=1:6 ilo=csg_obj.ilog(t);jlo=csg_obj.jlog(t); ihi=csg_obj.ilog(t)+csg_obj.fx(t); jhi=csg_obj.jlog(t)+csg_obj.fy(t); nlo=nc+1; nhi=nc+(ihi-ilo)*(jhi-jlo); a=bathyarr(ilo:ihi-1,jlo:jhi-1); c(nlo:nhi)=a(:); nc=nc+(ihi-ilo)*(jhi-jlo); end %clf %patch(px,py,c,'Edgecolor','none'); %patch(px,py,'r','Edgecolor','none'); %set(gcf,'PaperSize',[16 8]); %set(gcf,'PaperPosition',[0 0 16 8]); %set(gca,'Position',[0 0 1 1]); %print -djpeg100 -r600 -painters foo.jpeg bathy_obj.bathyarr=bathyarr; bathy_obj.c=c; return