%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) 
%[st1 st2]=size(stname);
%if st1 > st2
%   stname=transpose(stname);
%end
%
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
nc_createi_empty(file)
%
%add dimensions
nsize=max(size(yeari));
nc_adddim(file,'ns',nsize);
nc_adddim(file,'time',191);
nc_adddim(file,'chr',55);

%add and write variables
v1.Name='yearic';
v1.Datatype='double';
v1.Dimension={'ns'};
nc_addvar(file,v1);
nc_varput(file,'yearic',yeari)
%
v1.Name='nsic';
v1.Datatype='double';
v1.Dimension={'ns'};
nc_addvar(file,v1);
nc_varput(file,'nsic',nsi)
%
v1.Name='stnamec';
v1.Datatype='char';
v1.Dimension={'ns','chr'};
%v1.Dimension={'ns'};
nc_addvar(file,v1);
nc_varput(file,'stnamec',char(stname))
%
v1.Name='monthmc';
v1.Datatype='double';
v1.Dimension={'ns','time'};
nc_addvar(file,v1);
nc_varput(file,'monthmc',monthm)
%
v1.Name='daymc';
v1.Datatype='double';
v1.Dimension={'ns','time'};
nc_addvar(file,v1);
nc_varput(file,'daymc',daym)
%
v1.Name='hourmc';
v1.Datatype='double';
v1.Dimension={'ns','time'};
nc_addvar(file,v1);
nc_varput(file,'hourmc',hourm)
%
v1.Name='latmc';
v1.Datatype='double';
v1.Dimension={'ns','time'};
nc_addvar(file,v1);
nc_varput(file,'latmc',latm)
%
v1.Name='longmc';
v1.Datatype='double';
v1.Dimension={'ns','time'};
nc_addvar(file,v1);
nc_varput(file,'longmc',longm)
%
v1.Name='vsmc';
v1.Datatype='double';
v1.Dimension={'ns','time'};
nc_addvar(file,v1);
nc_varput(file,'vsmc',vsm)
%
v1.Name='pcmc';
v1.Datatype='double';
v1.Dimension={'ns','time'};
nc_addvar(file,v1);
nc_varput(file,'pcmc',pcm)
%
%v1.Name='landmc';
%v1.Datatype='double';
%v1.Dimension={'ns','time'};
%nc_addvar(file,v1);
%nc_varput(file,'landmc',landm)
