%Sample script for writing best track data to netcdf file

%Load best track data matlab binary
filen=input('Enter file name (e.g. attracks)','s');
filein=strcat(filen,'.mat');
load(filein) 
%
clear filedes
if filen == 'attracks'
 filedes='Atlantic tracks';
elseif filen == 'wptracks'
 filedes='Western North Pacific tracks';
elseif filen == 'eptracks'
 filedes='Eastern North Pacific tracks';
elseif filen == 'iotracks'
 filedes='North Indian Ocean tracks';
elseif filen == 'shtracks'
 filedes='Southern Hemisphere tracks';
end
%
%Netcdf output file
file = strcat(filen,'.nc');
%remove old netcdf file if exists
system(['rm -f ',file]);
%create netcdf file
fout = netcdf(file,'clobber');

%Define global attributes
fout.description = 'Atlantic tracks';

%Assign dimensions
dims = size(daym);
fout('stormnum') = dims(1);
fout('obstime') = dims(2);
fout('zero') = 1;

%Variables and attributes
fout{'yearic'} = ncint('stormnum');
fout{'yearic'}(:,:) = yeari;
fout{'yearic'}.units = 'years';

fout{'monthmc'} = ncint('stormnum','obstime');
fout{'monthmc'}(:,:) = monthm;
fout{'monthmc'}.units = 'months';

fout{'daymc'} = ncint('stormnum','obstime');
fout{'daymc'}(:,:) = daym;
fout{'daymc'}.units = 'days';

fout{'hourmc'} = ncint('stormnum','obstime');
fout{'hourmc'}(:,:) = hourm;
fout{'hourmc'}.units = 'hours';

fout{'latmc'} = ncdouble('stormnum','obstime');
fout{'latmc'}(:,:) = latm;
fout{'latmc'}.units = 'degrees';

fout{'longmc'} = ncdouble('stormnum','obstime');
fout{'longmc'}(:,:) = longm;
fout{'longmc'}.units = 'degrees east';

fout{'vsmc'} = ncdouble('stormnum','obstime');
fout{'vsmc'}(:,:) = vsm;
fout{'vsmc'}.units = 'meters per second';

fout{'pcmc'} = ncdouble('stormnum','obstime');
fout{'pcmc'}(:,:) = pcm;
fout{'pcmc'}.units = 'millibars';

fout{'landmc'} = ncint('stormnum','obstime');
fout{'landmc'}(:,:) = landm;
fout{'landmc'}.units = 'boolean';

fout{'nsic'} = ncint('stormnum');
fout{'nsic'}(:) = nsi;

fout{'dimc'} = ncint('zero');
fout{'dimc'}(:) = i;

fout{'idimc'} = ncint('zero');
fout{'idimc'}(:) = idim;

%Close netcdf file
close(fout);
