%6.jun.2024
%atn: script to process a single 2d/3d field into netcdf without hooks to diags or grids:

clear all
dirroot='/scratch/atnguyen/aste_270x450x180/';
dirroot2='/scratch2/atnguyen/aste_270x450x180/';
dirrun=[dirroot 'OFFICIAL_ASTE_R1_Sep2019/'];
dirrun2=[dirroot2 'OFFICIAL_ASTE_R1_Sep2019/'];
gridDir=[dirroot 'GRID/'];
addpath([dirrun '/netcdf_code/victor_tools/']);
nx=270;ncut1=450;ncut2=180;nz=50;
ny=2*ncut1+nx+ncut2;nfx=[nx 0 nx ncut2 ncut1];nfy=[ncut1 0 nx nx nx];
dtilex=90;dtiley=90; %these are the tiles for R1
latcutoff=26;

a=rdmds([dirrun '/ADXXfiles/xx_logdiffkr.effective.' sprintf('%10.10i',62)]);a=reshape(a,nx,ny,nz);
tiles=aste2tiles(a,[nx ncut1 ncut2 nz],[dtilex dtiley],gridDir,latcutoff);
%tiles (struct with fields):
%      tot: 45
%      wet: 29
%     list: [45×2 double]
%    tsize: [90 90]
%    fsize: [270 1350 50]
%      nfx: [270 0 270 180 450]
%      nfy: [450 0 270 270 270]
%     mask: {[270×450 double]  []  [270×270 double]  [180×270 double]  [450×270 double]}
%      lat: 26
%    field: {1×29 cell}
%    index: {1×29 cell}

%set up "info" structure:
info=[];
 info.longName='log10 of diffkr';
 info.units='log10(m2/s)';
 info.nprec=4;
 info.outDir=[dirrun2 'output_tiles_90x90_13p75/adxxfiles_nc/'];
 info.fnameroot='xx_logdiffkr_effective';
 info.varName='logdiffkr';
 info.gridDir='/scratch/atnguyen/aste_270x450x180/GRID_noblank_13p75/'
 info.loc_h='C';
 info.loc_z='M';
 info.nr=tiles.fsize(3); %50
if(~exist(info.outDir));mkdir(info.outDir);end;

%write out files to [grid.outDir '/' info.fnameroot '.' XXXX '.nc']
convert_aste2nctiles_singlefield(tiles,info) 
