1 | function nc_addhist ( ncfile, attval ) |
---|
2 | % NC_ADDHIST: adds text to a global history attribute |
---|
3 | % |
---|
4 | % NC_ADDHIST(NCFILE,TEXT) adds the TEXT string to the standard convention |
---|
5 | % "history" global attribute of the netCDF file NCFILE. The string is |
---|
6 | % prepended, rather than appended. |
---|
7 | |
---|
8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
9 | % |
---|
10 | % $Id: nc_addhist.m 2659 2009-04-01 17:38:36Z johnevans007 $ |
---|
11 | % $LastChangedDate: 2009-04-01 13:38:36 -0400 (Wed, 01 Apr 2009) $ |
---|
12 | % $LastChangedRevision: 2659 $ |
---|
13 | % $LastChangedBy: johnevans007 $ |
---|
14 | % |
---|
15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
16 | |
---|
17 | error(nargchk(2,2,nargin,'struct')); |
---|
18 | |
---|
19 | if ~exist(ncfile,'file') |
---|
20 | error ( 'SNCTOOLS:NC_ADDHIST:badFilename', '%s does not exist', ncfile ); |
---|
21 | end |
---|
22 | if ~ischar(attval) |
---|
23 | error ( 'SNCTOOLS:NC_ADDHIST:badDatatype', ... |
---|
24 | 'history attribute addition must be character.' ); |
---|
25 | end |
---|
26 | |
---|
27 | |
---|
28 | try |
---|
29 | old_hist = nc_attget ( ncfile, nc_global, 'history' ); |
---|
30 | catch %#ok<CTCH> |
---|
31 | % |
---|
32 | % The history attribute must not have existed. That's ok. |
---|
33 | old_hist = ''; |
---|
34 | end |
---|
35 | |
---|
36 | |
---|
37 | if isempty(old_hist) |
---|
38 | new_history = sprintf ( '%s: %s', datestr(now), attval ); |
---|
39 | else |
---|
40 | new_history = sprintf ( '%s: %s\n%s', datestr(now), attval, old_hist ); |
---|
41 | end |
---|
42 | nc_attput ( ncfile, nc_global, 'history', new_history ); |
---|
43 | |
---|
44 | |
---|
45 | |
---|