/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_IO/ncaddAtt.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/ncaddAtt.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Sun Jan 24 17:05:13 2016 UTC (9 years, 5 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Error occurred while calculating annotation data.
- move routines from MITprof/profiles_misc/ to gcmfaces/gcmfaces_IO/
  to allow for nctiles IO without having to rely on MITprof
- these wrapper routines were originally provided by F. Roquet
  that work both with the native implememtation of ncetcf in recent
  Matlab versions and the third party mex codes used earlier

1 function ncaddAtt(ncid,varname,attrname,attrvalue);
2 % add an attribute to a variable in an existing netcdf file.
3
4 global useNativeMatlabNetcdf;
5 if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end;
6
7 if isempty(varname),
8 if useNativeMatlabNetcdf;
9 netcdf.reDef(ncid);
10 netcdf.putAtt(ncid,-1,attrname,attrvalue);
11 netcdf.endDef(ncid);
12 else;%try to use old mex stuff
13 if ischar(attrvalue)
14 attrvalue(find(double(attrvalue)==10))=[];
15 eval(['ncid.' attrname '=''' attrvalue ''';']);
16 else
17 eval(['ncid.' attrname '=' num2str(attrvalue) ';']);
18 end
19 end;
20 else
21 if useNativeMatlabNetcdf;
22 varid=netcdf.inqVarID(ncid,varname);
23 netcdf.reDef(ncid);
24 netcdf.putAtt(ncid,varid,attrname,attrvalue);
25 netcdf.endDef(ncid);
26 else;%try to use old mex stuff
27 if strcmp(attrname,'_FillValue'),
28 attrname='FillValue_';
29 end
30 if ischar(attrvalue)
31 attrvalue(find(double(attrvalue)==10))=[];
32 eval(['ncid{''' varname '''}.' attrname '=''' attrvalue ''';']);
33 else
34 eval(['ncid{''' varname '''}.' attrname '=' num2str(attrvalue) ';']);
35 end
36 end;
37 end
38
39
40

  ViewVC Help
Powered by ViewVC 1.1.22