function htd2netcdf(filename, htd)
%This file converts the htd files, which contain data, to netCDF files.
    nc_create_empty(filename)
    %nc_dump(filename)
    nc_add_dimension(filename,'time',0)
    %nc_dump(filename)
    varstruct.Name='dayno';
    varstruct.Nctype=nc_double;
    varstruct.Dimension={'time'};
    nc_addvar(filename,varstruct)
    %nc_dump(filename)
    varstruct.Name='waveheight';
    varstruct.Nctype=nc_double;
    varstruct.Dimension={'time'};
    nc_addvar(filename,varstruct)
    %nc_dump(filename)
    varstruct.Name='peakwaveperiod';
    varstruct.Nctype=nc_double;
    varstruct.Dimension={'time'};
    nc_addvar(filename,varstruct)

    varstruct.Name='wavedirection';
    varstruct.Nctype=nc_double;
    varstruc.Dimension={'time'};
    nc_addvar(filename,varstruct)

    varstruct.Name='TM02waveperiod';
    varstruct.Nctype=nc_double;
    varstruc.Dimension={'time'};
    nc_addvar(filename,varstruct)
    %nc_dump(filename)
    varstruct.Name='meanperiod';
    varstruct.Nctype=nc_double;
    varstruct.Dimension={'time'};
    %time_varstruct.Name='time';
    %time_varstruct.Dimension={'time'};
    nc_addvar(filename,varstruct);
    nc_dump(filename);
    
    %global attributes
    % we use the cf
    % convention http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.4/cf-conventions.html
    nc_attput(filename, nc_global, 'Convention', 'CF-1.4');
    nc_attput(filename, nc_global, 'history', 'Here type something about what we did');
    
    nc_varput(filename,'dayno',htd.dayno,0,length(htd.dayno))    
    nc_varput(filename,'waveheight',htd.waveheight,0,length(htd.waveheight))
    nc_varput(filename,'peakwaveperiod',htd.peakwaveperiod,0,length(htd.peakwaveperiod))
    nc_varput(filename,'wavedirection',htd.wavedirection,0,length(htd.wavedirection))
    nc_varput(filename,'TM02waveperiod',htd.TM02waveperiod,0,length(htd.TM02waveperiod))
    nc_varput(filename,'meanperiod',htd.meanperiod,0,length(htd.meanperiod))
    nc_attput(filename,'dayno','units','days')
    nc_attput(filename,'waveheight','units','meters')
    nc_attput(filename,'wavedirection','units','degrees')
    nc_attput(filename,'TM02waveperiod','units','seconds')
    nc_attput(filename,'meanperiod','units','seconds')
    nc_dump(filename)
end