%example to read files for tile # 0070, see tile_Arctic.png for location
%see available_diagnostics.log for variable names, units, and descriptions

clear all;
dirin './nctiles_monthly_tides/';

tileno=70;
tileno_str=sprintf('%4.4i',tileno);

ncdisp([dirin 'EXFpress/EXFpress.' tileno_str '.nc']);
%Source:
%           ./EXFpress/EXFpress.0070.nc
%Format:
%           classic
%Global Attributes:
%           Description    = 'High resolution 3.5km run'
%           Institution    = 'Oden Institute for Computational Engineering and Science, UT-Austin'
%           References     = '  '
%           01             = '   Nguyen, A.T., 2022.'
%           Conventions    = 'CF-1.6 (http://cfconventions.org/cf-conventions/v1.6.0/cf-conventions.html)'
%           Software       = 'File created using convert_ASTE2nctiles_DIAG_hires_f3.m'
%           netCDF Version = '4.7.4'
%           matlab Version = '9.11.0.1809720 (R2021b) Update 1'
%           _FillValue     = NaN
%           missing_value  = NaN
%Dimensions:
%           itxt = 30
%           i1   = 11
%           i2   = 90
%           i3   = 90
%Variables:
%    i1      
%           Size:       11x1
%           Dimensions: i1
%           Datatype:   double
%           Attributes:
%                       long_name = 'array index 1'
%                       units     = '1'
%    i2      
%           Size:       90x1
%           Dimensions: i2
%           Datatype:   double
%           Attributes:
%                       long_name = 'array index 2'
%                       units     = '1'
%    i3      
%           Size:       90x1
%           Dimensions: i3
%           Datatype:   double
%           Attributes:
%                       long_name = 'array index 3'
%                       units     = '1'
%    EXFpress
%           Size:       90x90x11
%           Dimensions: i3,i2,i1
%           Datatype:   single
%           Attributes:
%                       long_name   = 'atmospheric pressure field'
%                       units       = 'N/m^2'
%                       coordinates = 'lon lat tim'
%    lon     
%           Size:       90x90
%           Dimensions: i3,i2
%           Datatype:   double
%           Attributes:
%                       long_name     = 'longitude'
%                       standard_name = 'longitude'
%                       units         = 'degrees_east'
%    lat     
%           Size:       90x90
%           Dimensions: i3,i2
%           Datatype:   double
%           Attributes:
%                       long_name     = 'latitude'
%                       standard_name = 'latitude'
%                       units         = 'degrees_north'
%    tim     
%           Size:       11x1
%           Dimensions: i1
%           Datatype:   double
%           Attributes:
%                       long_name     = 'time'
%                       standard_name = 'time'
%                       units         = 'days since 2002-1-1 0:0:0'
%    timstep 
%           Size:       11x1
%           Dimensions: i1
%           Datatype:   double
%           Attributes:
%                       long_name     = 'final time step number'
%                       standard_name = 'final time step number'
%                       units         = '1'
%    land    
%           Size:       90x90
%           Dimensions: i3,i2
%           Datatype:   double
%           Attributes:
%                       long_name     = 'land mask'
%                       standard_name = 'land_binary_mask'
%                       units         = '1'
%    area    
%           Size:       90x90
%           Dimensions: i3,i2
%           Datatype:   double
%           Attributes:
%                       long_name     = 'grid cell area'
%                       standard_name = 'cell_area'
%                       units         = 'm^2'
%

%look at surface pressure, monthly mean, 11 month record length
tmp=ncread([dirin 'EXFpress/EXFpress.' tileno_str '.nc'],'EXFpress'); 
size(tmp)
%    90    90    11
%tile size is 90 x 90 grid points, pick point 1,1:
ix=1;jy=1;
figure(1);clf;plot(squeeze(tmp(ix,jy,:)),'.-');xlabel('month since jan 2014');ylabel('surf press (N/m2)');

%now look at vertical temperature for point 1,1 and through 11 months:
tmp=ncread([dirin 'THETA/THETA.' tileno_str '.nc'],'THETA'); 
size(tmp)
%    90    90    83    11
tmp=permute(tmp,[1,2,4,3]);	%flip time and depth dimension
iz=1:50;	%look down to depth level 50

%also read in depth, lat, lon, use ncdisp to find out the grid info in each GRID.[tileno].nc file
rc=ncread(['./nctiles_grid/GRID.' tileno_str '.nc'],'RC');rc=round(abs(rc));
xc=ncread(['./nctiles_grid/GRID.' tileno_str '.nc'],'XC');
yc=ncread(['./nctiles_grid/GRID.' tileno_str '.nc'],'YC');

figure(1);clf;colormap(jet(21));
  pcolor(1:11,-iz,squeeze(tmp(ix,jy,:,iz))');shading flat;colorbar;grid;xlabel('month beginning jan 2014');
  set(gca,'ytick',[-50:5:-5 -1],'yticklabel',num2str(rc([50:-5:5,1])));ylabel('depth [m]');
  title({['point ' num2str(ix) ',' num2str(jy) ' on tile # ' tileno_str],...
         ['[lon,lat]=[' num2str(xc(ix,jy)) 'E,' num2str(yc(ix,jy)) 'N]']);

