RNT工具包中的netcdf结构体函数,其中采用了面向对象的编程方法,递归方法,可以大大简化netcdf读写时的语法,使用不仅限于roms模式,其他netcdf的读写也比较方便,依赖库包括RNT中的netcdf包,以及mexcdf库
function self = netcdf(theFilename, thePermission)
% netcdf/netcdf -- Constructor for netcdf class.
%
% netcdf (no arguments) shows extensive "help".
% netcdf('version') shows the present version number.
%
% netcdf('theFilename', 'thePermission') creates and/or
% opens 'theFilename' if 'thePermission' is one of
% {'clobber', 'noclobber', 'write', 'nowrite'} or a
% unique abbreviation thereof. The "netcdf" object
% is assigned silently to "ans" if no output argument
% is provided.
%
% netcdf('thePermission') invokes Matlab's "uiputfile"
% or "uigetfile" dialog for selecting the file to create
% or open, respectively, depending on 'thePermission'
% (default = 'nowrite' if possible, then 'noclobber').
%
% netcdf('random') creates a NetCDF file with a unique,
% random name, suitable for use as a temporary file.
%
% self = netcdf (no argument) calls "netcdf('nowrite')",
% which invokes matlab's "uigetfile" dialog. The returned
% "self" is the "netcdf" object that was opened.
%
% netcdf(theNCid) returns a "netcdf" object corresponding
% to theNCid of an open NetCDF file. This function does
% not re-open the file. TheNCid is the formal identifi
% <<<<<<<<<< Language Synopsis of the NetCDF Toolbox >>>>>>>>>>
%
% [...] denotes default value.
%
% Create or open a NetCDF file:
% f = netcdf('myNetCDF.nc', 'clobber | noclobber')
% f = netcdf('myNetCDF.nc', 'write | [nowrite]')
% where f is the returned "netcdf" object.
% f = netcdf('clobber | noclobber') for "uiputfile" dialog.
% f = netcdf('write | [nowrite]') for "uigetfile" dialog.
% f = netcdf('random') to create a randomly named file.
%
% Define a NetCDF global attribute:
% f.myGlobalAttribute = [myGlobalAttributeDoubleData]
% f.myGlobalAttribute = 'myGlobalAttributeCharData'
% f.myGlobalAttribute = nctype(myGlobalAttributeData)
% where nctype = [ncdouble] | ncfloat | nclong | ...
% ncint | ncshort | ncbyte | [ncchar]
% (N.B. default depends on context.)
% (See "NetCDF User's Guide" for datatype definitions.)
%
% f.myGlobalAttribute = [] deletes the attribute.
% g = f.myGlobalAttribute is the object.
% g(:) = [] deletes the attribute.
%
% Define a NetCDF record-dimension:
% f('myRecordDimension') = 0 defines a record-dimension.
% f('myRecordDimension') = [] deletes the dimension.
% r = f('myRecordDimension') is the object.
% f.myGlobalAttribute = [myGlobalAttributeDoubleData]
% f.myGlobalAttribute = 'myGlobalAttributeCharData'
% f.myGlobalAttribute = nctype(myGlobalAttributeData)
% where nctype = [ncdouble] | ncfloat | nclong | ...
% ncint | ncshort | ncbyte | [ncchar]
% (N.B. default depends on context.)
% (See "NetCDF User's Guide" for datatype definitions.)
%
% f.myGlobalAttribute = [] deletes the attribute.
% g = f.myGlobalAttribute is the object.
% g(:) = [] deletes the attribute.
%
% Define a NetCDF record-dimension:
% f('myRecordDimension') = 0 defines a record-dimension.
% f('myRecordDimension') = [] deletes the dimension.
% r = f('myRecordDimension') is the object.
% r(:) = [] deletes the dimension.
% r(:) = newSize resizes the dimension.
%
% Define a NetCDF dimension:
% f('myDimension') = myDimensionLength
% f('myDimension') = [] deletes the dimension.
% d = f('myDimension') is the object.
% d(:) = [] deletes the dimension.
% d(:) = newSize resizes the dimension.
% isrecdim(d) determines whether d is the record-dimension.
% iscoord(v) determines whether d is a coordinate-dimension.
%
% Define a NetCDF variable:
% f{'myVariable'} = nctype(myRecordDimension, myDimension, ...)
% f{'myVariable'} = nctype(myDimension, ...)
% f{'myVariable'} = nctype(r, d, ...)
% f{'myVariable'} = nctype(d, ...)
% f('myVariable') = [] deletes the variable.
% v = f{'myVariable'} returns the object.
% v = f{'myVariable', 1} returns the object -- auto-scaling enabled.
% v(:) = [] deletes the variable.
% iscoord(v) determines whether v is a coordinate-variable.
% isscalar(v) determines whether v is a scalar-variable.
% d(:) = newSize resizes the dimension.
% isrecdim(d) determines whether d is the record-dimension.
% iscoord(v) determines whether d is a coordinate-dimension.
%
% Define a NetCDF variable:
% f{'myVariable'} = nctype(myRecordDimension, myDimension, ...)
% f{'myVariable'} = nctype(myDimension, ...)
% f{'myVariable'} = nctype(r, d, ...)
% f{'myVariable'} = nctype(d, ...)
% f('myVariable') = [] deletes the variable.
% v = f{'myVariable'} returns the object.
% v = f{'myVariable', 1} returns the object -- auto-scaling enabled.
% v(:) = [] deletes the variable.
% iscoord(v) determines whether v is a coordinate-variable.
% isscalar(v) determines whether v is a scalar-variable.
%
% Define a NetCDF attribute:
% f{'myVariable'}.myAttribute = [myAttributeDoubleData]
% f{'myVariable'}.myAttribute = 'myAttributeCharData'
% f{'myVariable'}.myAttribute = nctype(myAttributeData)
% f{'myVariable'}.myAttribute = [] deletes the attribute.
% v.myAttribute = [myAttributeDoubleData]
% v.myAttribute = 'myAttributeCharData'
%
% Define a NetCDF attribute:
% f{'myVariable'}.myAttribute = [myAttributeDoubleData]
% f{'myVariable'}.myAttribute = 'myAttributeCharData'
% f{'myVariable'}.myAttribute = nctype(myAttributeData)
% f{'myVariable'}.myAttribute = [] deletes the attribute.
% v.myAttribute = [myAttributeDoubleData]
% v.myAttribute = 'myAttributeCharData'
% v.myAttribute = nctype(myAttributeData)
% v.myAttribute = [] deletes the attribute.
% a = f{'myVariable'}.myAttribute is the object.
% a = v.myAttribute is the object.
% a(:) = [] deletes the attribute.
%
% Store and retrieve NetCDF variable data:
% f{'myVariable'}(i, j, ...) = myVariableData
% f{'myVariable', 1}(i, j, ...) = myVariableData -- auto-scaling enabled.
% v(i, j, ...) = myVariableData
% myVariableData = f{'myVariable'}(i, j, ...)
% myVariableData = f{'myVariable', 1}(i, j, ...) -- auto-scaling enabled.
% myVariableData = v(i, j, ...)
%
% Store and retrieve NetCDF attribute data: (always a row vector)
% f.myGlobalAttribute(i) = myGlobalAttributeData
% g(i) = myGlobalAttributeData
% f{'myVariable'}.myAttribute(i) = myAttributeData
% v.myAttribute(i) = myAttributeData
% a(i) = myAttributeData
% myGlobalAttributeData = f.myGlobalAttribute(i)
% myGlobalAttributeData = g(i)
% myAttributeData = f{'myVariable'}.myAttribute(i)
% myAttributeData = v.myAttribute(i)
% myAttributeData = a(i)
% EXCEPTION: v.FillValue_ references the "_FillValue" attribute.
% Use the "fillval(v, ...)" method to avoid confusion.
%
% Store and retrieve NetCDF record data:
% s = f(0) returns the object.
% t = s(0) returns the record template as a struct.
% u = r(i) returns the i-th record data as a struct.
% d = f('myDimension') is the object.
% d(:) = [] deletes the dimension.
% d(:) = newSize resizes the dimension.
% isrecdim(d) determines whether d is the record-dimension.
% iscoord(v) determines whether d is a coordinate-dimension.
%
% Define a NetCDF variable:
% f{'myVariable'} = nctype(myRecordDimension, myDimension, ...)
% f{'myVariable'} = nctype(myDimension, ...)
% f{'myVariable'} = nctype(r, d, ...)
% f{'myVariable'} = nctype(d, ...)
% f('myVariable') = [] deletes the variable.
% v = f{'myVariable'} returns the object.
% v = f{'myVariable', 1} returns the object -- auto-scaling enabled.
% v(:) = [] deletes the variable.
% iscoord(v) determines whether v is a coordinate-variable.
% isscalar(v) determines whether v is a scalar-variable.
%
% Define a NetCDF attribute:
% f{'myVariable'}.myAttribute = [myAttributeDoubleData]
% f{'myVariable'}.myAttribute = 'myAttributeCharData'
% f{'myVariable'}.myAttribute = nctype(myAttributeData)
% f{'myVariable'}.myAttribute = [] deletes the attribute.
% v.myAttribute = [myAttributeDoubleData]
% v.myAttribute = 'myAttributeCharData'
% v.myAttribute = nctype(myAttributeData)
% v.myAttribute = [] deletes the attribute.
% a = f{'myVariable'}.myAttribute is the object.
% a = v.myAttribute is the object.
% a(:) = [] deletes the attribute.
%
% Store and retrieve NetCDF variable data:
% f{'myVariable'}(i, j, ...) = myVariableData
% f{'myVariable', 1}(i, j, ...) = myVariableData -- auto-scaling enabled.
% v(i, j, ...) = myVariableData
% myVariableData = f{'myVariable'}(i, j, ...)
% myVariableData = f{'myVariable', 1}(i, j, ...) -- auto-scaling enabled.
% myVariableData = v(i, j, ...)
%
% Store and retrieve NetCDF attribute data: (always a row vector)
% f.myGlobalAttribute(i) = myGlobalAttributeData
% g(i) = myGlobalAttributeData
% f{'myVariable'}.myAttribute(i) = myAttributeData
% v.myAttribute(i) = myAttributeData
% a(i) = myAttributeData
% myGlobalAttributeData = f.myGlobalAttribute(i)
% myGlobalAttributeData = g(i)
% netcdf(theNCid) returns a "netcdf" object corresponding
% to theNCid of an open NetCDF file. This function does
% not re-open the file. TheNCid is the formal identification
% number that would be returned ordinarily by a call to the
% NetCDF "nccreate" or "ncopen" function.
%
% Other permissions: The word 'readonly' is a synonym for 'nowrite'.
% The word 'define' can be used to open an existing file in 'define'
% mode, although this is not strictly necessary, since the "NetCDF
% Toolbox" switches context automatically, as needed.
%
% <<<<<<<<<< Language Synopsis of the NetCDF Toolbox >>>>>>>>>>
%
% [...] denotes default value.
%
% Create or open a NetCDF file:
% f = netcdf('myNetCDF.nc', 'clobber | noclobber')
% f = netcdf('myNetCDF.nc', 'write | [nowrite]')
% where f is the returned "netcdf" object.
% f = netcdf('clobber | noclobber') for "uiputfile" dialog.
% f = netcdf('write | [nowrite]') for "uigetfile" dialog.
% f = netcdf('random') to create a randomly named file.
%
% Define a NetCDF global attribute:
% f.myGlobalAttribute = [myGlobalAttributeDoubleData]
% f.myGlobalAttribute = 'myGlobalAttributeCharData'
% f.myGlobalAttribute = nctype(myGlobalAttributeData)
% where nctype = [ncdouble] | ncfloat | nclong | ...
% ncint | ncshort | ncbyte | [ncchar]
% (N.B. default depends on context.)
% (See "NetCDF User's Guide" for datatype definitions.)
%
% f.myGlobalAttribute = [] deletes the attribute.
% g = f.myGlobalAttribute is the object.
% g(:) = [] deletes the attribute.
%
% Define a NetCDF record-dimension:
% f('myRecordDimension') = 0 defines a record-dimension.
% f('myRecordDimension') = [] deletes the dimension.
% r = f('myRecordDimension') is the object.
% r(:) = [] deletes the dimension.
% r(:) = newSize resizes the dimension.
%
% Define a NetCDF dimension:
% f('myDimension') = myDimensionLength
% f('myDimension') = [] deletes the dimension.
% d = f('myDimension') is the object.
% d(:) = [] deletes the dimension.
% d(:) = newSize resizes the dimension.
% isrecdim(d) determines whether d is the record-dimension.
% iscoord(v) determines whether d is a coordinate-dimension.
%
% Define a NetCDF variable:
% f{'myVariable'} = nctype(myRecordDimension, myDimension, ...)
% f{'myVariable'} = nctype(myDimension, ...)
% f{'myVariable'} = nctype(r, d, ...)
% f{'myVariable'} = nctype(d, ...)
% f('myVariable') = [] deletes the variable.
% v = f{'myVariable'} returns the object.
% v = f{'myVariable', 1} returns the object -- auto-scaling enabled.
% v(:) = [] deletes the variable.
% iscoord(v) determines whether v is a coordinate-variable.
% isscalar(v) determines whether v is a scalar-variable.
%
% Define a NetCDF attribute:
function self = netcdf(theFilename, thePermission)
% netcdf/netcdf -- Constructor for netcdf class.
%
% netcdf (no arguments) shows extensive "help".
% netcdf('version') shows the present version number.
%
% netcdf('theFilename', 'thePermission') creates and/or
% opens 'theFilename' if 'thePermission' is one of
% {'clobber', 'noclobber', 'write', 'nowrite'} or a
% unique abbreviation thereof. The "netcdf" object
% is assigned silently to "ans" if no output argument
% is provided.
%
% netcdf('thePermission') invokes Matlab's "uiputfile"
% or "uigetfile" dialog for selecting the file to create
% or open, respectively, depending on 'thePermission'
% (default = 'nowrite' if possible, then 'noclobber').
%
% netcdf('random') creates a NetCDF file with a unique,
% random name, suitable for use as a temporary file.
% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO.
% All Rights Reserved.
% Disclosure without explicit written consent from the
% copyright owner does not constitute publication.
注意permission中的clobber是覆盖的意思