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

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/ncputAtt.m

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


Revision 1.1 - (hide 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
- 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 gforget 1.1 function [nc] = ncputAtt(ncid,varname,attrname,attrvalue);
2     % add an attribute to a variable in a 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.putAtt(ncid,-1,attrname,attrvalue);
10     else;%try to use old mex stuff
11     if ischar(attrvalue)
12     attrvalue(find(double(attrvalue)==10))=[];
13     eval(['ncid.' attrname '=''' attrvalue ''';']);
14     else
15     eval(['ncid.' attrname '=' num2str(attrvalue) ';']);
16     end
17     end;
18     else
19     if useNativeMatlabNetcdf;
20     varid=netcdf.inqVarID(ncid,varname);
21     netcdf.putAtt(ncid,varid,attrname,attrvalue);
22     else;%try to use old mex stuff
23     if strcmp(attrname,'_FillValue'),
24     attrname='FillValue_';
25     end
26     if ischar(attrvalue)
27     attrvalue(find(double(attrvalue)==10))=[];
28     eval(['ncid{''' varname '''}.' attrname '=''' attrvalue ''';']);
29     else
30     eval(['ncid{''' varname '''}.' attrname '=' num2str(attrvalue) ';']);
31     end
32     end;
33     end
34    
35    
36    

  ViewVC Help
Powered by ViewVC 1.1.22