% example to use patchface3D
% faces, faces1, faces2 are identical
% example #1 shows how these faces are read in from individual files.

%==================
%example1: read in 5 grid faces and output to compact format (1) and mapview (3):

dirGRID=...
'/net/weddell/raid3/gforget/grids/gridCompleted/llcRegLatLon/llc_96/';

nx=[96,96,96,288,288];ny=[288,288,96,96,96];
NX=nx(1);NY=NX*13;NZ=1;

for i=1:5;
 fin=['llc_00',num2str(i),'_',num2str(nx(i)),'_',num2str(ny(i)),'.bin'];
 temp=readbin([dirGRID,fin],[nx(i)+1 ny(i)+1 2],1,'real*8');
 XC{i}=temp(1:nx(i),1:ny(i),1);
 YC{i}=temp(1:nx(i),1:ny(i),2);
end

%facesXC is identical to XC, array_compact is in compact format.

direction=1;
array_faces=[XC{1},XC{2},XC{3},XC{4}',XC{5}'];
[array_compact,facesXC]=patchface3D(NX,NY,NZ,array_faces,direction);

direction=3;
[array_map,facesXC]=patchface3D(NX,NY,NZ,array_faces,direction);

%=================
%example2: read in compact form and output to map view:

direction=2;
nx=540;ny=540*13;nz=1;
dirin = '/net/weddell/raid3/heimbach/ecco/aste_grid/prepare_bathy/';
compact = readbin([dirin,'llc540x540x1620_bathy.bin'],[nx ny],1,'real*8');

[compact2map,faces]=patchface3D(nx,ny,nz,compact,direction);

%=================
%example3: world map view to compact format:
% use compact2map from above, size [540*4 540*4 1]

direction=0;
nx=540*4;ny=540*4;nz=1;
[map2compact,faces1]=patchface3D(nx,ny,nz,compact2map,direction);

%=================
%example4: faces to world map:

direction=3;
nx=540;ny=540*13;nz=1;
temp=[faces1{1},faces1{2},faces1{3},faces1{4}',faces1{5}'];
[faces2map,faces2]=patchface3D(nx,ny,nz,temp,direction);

%plotting all examples:

figure(1);clf;
subplot(321);imagesc(array_map);colorbar;title('Longitude - mapview');
subplot(322);imagesc(faces2map);colorbar;title('Bathymetry - mapview');
subplot(312);imagesc(map2compact);colorbar;title('Bathymetry - compact')
subplot(313);imagesc(temp);colorbar;title('Bathymetry - 5 faces (Note last 2 faces were transposed)');

