function nc_padheader ( ncfile, num_bytes )
% NC_PADHEADER:  pads the metadata header of a netcdf file
%
% When a netCDF file gets very large, adding new attributes can become
% a time-consuming process.  This can be mitigated by padding the 
% netCDF header with additional bytes.  Subsequent new attributes will
% not result in long time delays unless the length of the new 
% attribute exceeds that of the header.
%
% USAGE:  nc_padheader ( ncfile, num_bytes );
%
% In case of an error, an exception is thrown.
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Id: nc_padheader.m 1870 2006-10-09 12:08:53Z johnevans007 $
% $LastChangedDate: 2006-10-09 08:08:53 -0400 (Mon, 09 Oct 2006) $
% $LastChangedRevision: 1870 $
% $LastChangedBy: johnevans007 $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


[ncid,status] = mexnc ( 'open', ncfile, nc_write_mode );
if ( status ~= 0 )
	error ( '%s:  open failed, ''%s''.\n', ncfile, mexnc('strerror',status)   );
end

status = mexnc ( 'redef', ncid );
if ( status ~= 0 )
	error ( '%s:  redef failed, ''%s''.\n', ncfile, mexnc('strerror',status) );
end

%
% Sets the padding to be "num_bytes" at the end of the header section.  The other
% values are default values used by "ENDDEF".
status = mexnc ( '_enddef', ncid, num_bytes, 4, 0, 4 );
if ( status ~= 0 )
	error ( '%s:  _enddef failed, ''%s''.\n', ncfile, mexnc('strerror',status) );
end

status = mexnc ( 'close', ncid );
if ( status ~= 0 )
	error ( '%s:  close failed, ''%s''.\n', ncfile, mexnc('strerror',status) );
end
