netcdf-1.0.14/ 0000755 0000000 0000000 00000000000 13741574474 011246 5 ustar 00 0000000 0000000 netcdf-1.0.14/.travis.yml 0000644 0000000 0000000 00000000411 13741574474 013353 0 ustar 00 0000000 0000000 language: cpp
sudo: required
dist: trusty
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y octave liboctave-dev libnetcdf-dev netcdf-bin
script: cd ..; mv octave-netcdf netcdf; octave --eval 'pkg install netcdf; pkg load netcdf; test_netcdf'
netcdf-1.0.14/COPYING 0000644 0000000 0000000 00000043077 13741574474 012314 0 ustar 00 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see .
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
netcdf-1.0.14/DESCRIPTION 0000644 0000000 0000000 00000000622 13741574474 012754 0 ustar 00 0000000 0000000 Name: netcdf
Version: 1.0.14
Date: 2020-10-14
Author: Alexander Barth
Maintainer: Alexander Barth , John Donoghue
Title: netcdf
Description: A NetCDF interface for Octave
Depends: octave (>= 3.8.0)
BuildRequires: netcdf-devel [Fedora]
libnetcdf-dev [Debian], netcdf-bin [Debian]
License: GPLv2+
Url: http://octave.sf.net
netcdf-1.0.14/INDEX 0000644 0000000 0000000 00000002176 13741574474 012046 0 ustar 00 0000000 0000000 netcdf >> NetCDF interface
High-level functions
nccreate
ncdisp
ncinfo
ncreadatt
ncread
ncwriteatt
ncwrite
ncwriteschema
Low-level functions
netcdf_getConstant
netcdf_getConstantNames
netcdf_inqLibVers
netcdf_setDefaultFormat
netcdf_setChunkCache
netcdf_getChunkCache
netcdf_create
netcdf_open
netcdf_abort
netcdf_sync
netcdf_setFill
netcdf_inq
netcdf_inqUnlimDims
netcdf_inqFormat
netcdf_defDim
netcdf_renameDim
netcdf_defVar
netcdf_renameVar
netcdf_defVarFill
netcdf_inqVarFill
netcdf_defVarDeflate
netcdf_inqVarDeflate
netcdf_defVarChunking
netcdf_inqVarChunking
netcdf_defVarFletcher32
netcdf_inqVarFletcher32
netcdf_endDef
netcdf_reDef
netcdf_putVar
netcdf_getVar
netcdf_close
netcdf_inqAttName
netcdf_inqAttID
netcdf_inqAtt
netcdf_getAtt
netcdf_putAtt
netcdf_copyAtt
netcdf_renameAtt
netcdf_delAtt
netcdf_inqVarID
netcdf_inqVarIDs
netcdf_inqVar
netcdf_inqDim
netcdf_inqDimID
netcdf_inqDimIDs
netcdf_defGrp
netcdf_inqGrps
netcdf_inqGrpName
netcdf_inqGrpNameFull
netcdf_inqGrpParent
netcdf_inqGrpFullNcid
netcdf_inqNcid
Test function
test_netcdf
netcdf-1.0.14/Makefile 0000644 0000000 0000000 00000021327 13741574474 012713 0 ustar 00 0000000 0000000 ## Copyright 2015-2016 Carnë Draug
## Copyright 2015-2016 Oliver Heimlich
## Copyright 2017 Julien Bect
## Copyright 2017 Olaf Till
## Copyright 2018 John Donoghue
##
## Copying and distribution of this file, with or without modification,
## are permitted in any medium without royalty provided the copyright
## notice and this notice are preserved. This file is offered as-is,
## without any warranty.
TOPDIR := $(shell pwd)
## Some basic tools (can be overriden using environment variables)
SED ?= sed
TAR ?= tar
GREP ?= grep
CUT ?= cut
TR ?= tr
## Note the use of ':=' (immediate set) and not just '=' (lazy set).
## http://stackoverflow.com/a/448939/1609556
package := $(shell $(GREP) "^Name: " DESCRIPTION | $(CUT) -f2 -d" " | \
$(TR) '[:upper:]' '[:lower:]')
version := $(shell $(GREP) "^Version: " DESCRIPTION | $(CUT) -f2 -d" ")
## These are the paths that will be created for the releases.
target_dir := target
release_dir := $(target_dir)/$(package)-$(version)
release_tarball := $(target_dir)/$(package)-$(version).tar.gz
html_dir := $(target_dir)/$(package)-html
html_tarball := $(target_dir)/$(package)-html.tar.gz
## Using $(realpath ...) avoids problems with symlinks due to bug
## #50994 in Octaves scripts/pkg/private/install.m. But at least the
## release directory above is needed in the relative form, for 'git
## archive --format=tar --prefix=$(release_dir).
real_target_dir := $(realpath .)/$(target_dir)
installation_dir := $(real_target_dir)/.installation
package_list := $(installation_dir)/.octave_packages
install_stamp := $(installation_dir)/.install_stamp
## These can be set by environment variables which allow to easily
## test with different Octave versions.
ifndef OCTAVE
OCTAVE := octave
endif
OCTAVE := $(OCTAVE) --no-gui --silent --norc
MKOCTFILE ?= mkoctfile
## Command used to set permissions before creating tarballs
FIX_PERMISSIONS ?= chmod -R a+rX,u+w,go-w,ug-s
GIT := git
GIT_TIMESTAMP := $(firstword $(shell $(GIT) log -n1 --date=unix --format="%ad"))
## Detect which VCS is used
vcs := $(if $(wildcard .hg),hg,$(if $(wildcard .git),git,unknown))
ifeq ($(vcs),hg)
release_dir_dep := .hg/dirstate
endif
ifeq ($(vcs),git)
release_dir_dep := .git/index
endif
TAR_REPRODUCIBLE_OPTIONS := --sort=name --mtime="@$(GIT_TIMESTAMP)" --owner=0 --group=0 --numeric-owner
TAR_OPTIONS := --format=ustar $(TAR_REPRODUCIBLE_OPTIONS)
## .PHONY indicates targets that are not filenames
## (https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html)
.PHONY: help
## make will display the command before runnning them. Use @command
## to not display it (makes specially sense for echo).
help:
@echo "Targets:"
@echo " dist - Create $(release_tarball) for release."
@echo " html - Create $(html_tarball) for release."
@echo " release - Create both of the above and show md5sums."
@echo " install - Install the package in $(installation_dir), where it is not visible in a normal Octave session."
@echo " check - Execute package tests."
@echo " doctest - Test the help texts with the doctest package."
@echo " run - Run Octave with the package installed in $(installation_dir) in the path."
@echo " clean - Remove everything made with this Makefile."
##
## Recipes for release tarballs (package + html)
##
.PHONY: release dist html clean-tarballs clean-unpacked-release
## To make a release, build the distribution and html tarballs.
release: dist html
md5sum $(release_tarball) $(html_tarball)
@echo "Upload @ https://sourceforge.net/p/octave/package-releases/new/"
@echo " and note the changeset the release corresponds to"
## dist and html targets are only PHONY/alias targets to the release
## and html tarballs.
dist: $(release_tarball)
html: $(html_tarball)
## An implicit rule with a recipe to build the tarballs correctly.
%.tar.gz: %
$(TAR) -cf - $(TAR_OPTIONS) -C "$(target_dir)/" "$(notdir $<)" | gzip -9n > "$@"
clean-tarballs:
@echo "## Cleaning release tarballs (package + html)..."
-$(RM) $(release_tarball) $(html_tarball)
@echo
## Create the unpacked package.
##
## Notes:
## * having ".hg/dirstate" (or ".git/index") as a prerequesite means it is
## only rebuilt if we are at a different commit.
## * the variable RM usually defaults to "rm -f"
## * having this recipe separate from the one that makes the tarball
## makes it easy to have packages in alternative formats (such as zip)
## * note that if a commands needs to be run in a specific directory,
## the command to "cd" needs to be on the same line. Each line restores
## the original working directory.
$(release_dir): $(release_dir_dep)
-$(RM) -r "$@"
ifeq (${vcs},hg)
hg archive --exclude ".hg*" --type files "$@"
endif
ifeq (${vcs},git)
git archive --format=tar --prefix="$@/" HEAD | $(TAR) -x
$(RM) "$@/.gitignore"
endif
## Don't fall back to run the supposed necessary contents of
## 'bootstrap' here. Users are better off if they provide
## 'bootstrap'. Administrators, checking build reproducibility, can
## put in the missing 'bootstrap' file if they feel they know its
## necessary contents.
ifneq (,$(wildcard src/autogen.sh))
cd "$@/src" && ./autogen.sh && $(RM) -r "autom4te.cache"
endif
## Uncomment this if your src/Makefile.in has these targets for
## pre-building something for the release (e.g. documentation).
# cd "$@/src" && ./configure && $(MAKE) prebuild && \
# $(MAKE) distclean && $(RM) Makefile
##
${FIX_PERMISSIONS} "$@"
run_in_place = $(OCTAVE) --eval ' pkg ("local_list", "$(package_list)"); ' \
--eval ' pkg ("load", "$(package)"); '
# html_options = --eval 'options = get_html_options ("octave-forge");'
## Uncomment this for package documentation.
html_options = --eval 'options = get_html_options ("octave-forge");'
#html_options = --eval 'options = get_html_options ("octave-forge");' \
# --eval 'options.package_doc = "$(package).texi";'
$(html_dir): $(install_stamp)
$(RM) -r "$@";
$(run_in_place) \
--eval ' pkg load generate_html; ' \
$(html_options) \
--eval ' generate_package_html ("$(package)", "$@", options); ';
$(FIX_PERMISSIONS) "$@";
clean-unpacked-release:
@echo "## Cleaning unpacked release tarballs (package + html)..."
-$(RM) -r $(release_dir) $(html_dir)
@echo
##
## Recipes for installing the package.
##
.PHONY: install clean-install
octave_install_commands = \
' llist_path = pkg ("local_list"); \
mkdir ("$(installation_dir)"); \
load (llist_path); \
local_packages(cellfun (@ (x) strcmp ("$(package)", x.name), local_packages)) = []; \
save ("$(package_list)", "local_packages"); \
pkg ("local_list", "$(package_list)"); \
pkg ("prefix", "$(installation_dir)", "$(installation_dir)"); \
pkg ("install", "-local", "-verbose", "$(release_tarball)"); '
## Install unconditionally. Maybe useful for testing installation with
## different versions of Octave.
install: $(release_tarball)
@echo "Installing package under $(installation_dir) ..."
$(OCTAVE) --eval $(octave_install_commands)
touch $(install_stamp)
## Install only if installation (under target/...) is not current.
$(install_stamp): $(release_tarball)
@echo "Installing package under $(installation_dir) ..."
$(OCTAVE) --eval $(octave_install_commands)
touch $(install_stamp)
clean-install:
@echo "## Cleaning installation under $(installation_dir) ..."
-$(RM) -r $(installation_dir)
@echo
##
## Recipes for testing purposes
##
.PHONY: run doctest check
## Start an Octave session with the package directories on the path for
## interactice test of development sources.
run: $(install_stamp)
$(run_in_place) --persist
## Test example blocks in the documentation. Needs doctest package
## https://octave.sourceforge.io/doctest/index.html
doctest: $(install_stamp)
$(run_in_place) --eval 'pkg load doctest;' \
--eval "targets = '$(shell (cd inst && ls *.m) | $(CUT) -f2 -d@ | $(CUT) -f1 -d.)';" \
--eval "targets = strsplit (targets, ' '); doctest (targets);"
## Test package.
octave_test_commands = \
' pkgs = pkg("list", "$(package)"); \
dirs = {pkgs{1}.dir}; \
__run_test_suite__ (dirs, {}); '
## the following works, too, but provides no overall summary output as
## __run_test_suite__ does:
##
## else cellfun (@runtests, horzcat (cellfun (@ (dir) ostrsplit (([~, dirs] = system (sprintf ("find %s -type d", dir))), "\n\r", true), dirs, "UniformOutput", false){:})); endif '
check: $(install_stamp)
$(run_in_place) --eval $(octave_test_commands)
##
## CLEAN
##
.PHONY: clean
clean: clean-tarballs clean-unpacked-release clean-install
@echo "## Removing target directory (if empty)..."
-rmdir $(target_dir)
@echo
@echo "## Cleaning done"
@echo
netcdf-1.0.14/NEWS 0000644 0000000 0000000 00000005616 13741574474 011755 0 ustar 00 0000000 0000000 Summary of important user-visible changes for netcdf 1.0.14:
-------------------------------------------------------------------
** Add NC_STRING type as an octave type
** Minor bugfixes
Summary of important user-visible changes for netcdf 1.0.13:
-------------------------------------------------------------------
** Update to depend on Octave 3.8+
** Update for Octave 5 and newer
Summary of important user-visible changes for netcdf 1.0.12:
-------------------------------------------------------------------
** Fix bug #51443: configure in dev octave 4.3.0+
Summary of important user-visible changes for netcdf 1.0.11:
-------------------------------------------------------------------
** Fix cleaning of files (thanks to Rafael Laboissiere)
Summary of important user-visible changes for netcdf 1.0.10:
-------------------------------------------------------------------
** Fix bug #46060: building with the --enable-64 option
Summary of important user-visible changes for netcdf 1.0.9:
-------------------------------------------------------------------
** Fix bug #47014: writing NaNs
Summary of important user-visible changes for netcdf 1.0.8:
-------------------------------------------------------------------
** Fix bug #45190, #46747: netcdf(nccreate) to enable DeflateLevel in nccreate
** Fix bug #46798: using the right delete operator
Summary of important user-visible changes for netcdf 1.0.7:
-------------------------------------------------------------------
** Apply patch from John Donoghue to allow cross-compilation (bug #44837)
Summary of important user-visible changes for netcdf 1.0.6:
-------------------------------------------------------------------
** ncread: do not replace _FillValue by NaNs for characters
** ncdisp: fix for attributes value with %-sign
Summary of important user-visible changes for netcdf 1.0.5:
-------------------------------------------------------------------
** Implement DeflateLevel in nccreate
Summary of important user-visible changes for netcdf 1.0.4:
-------------------------------------------------------------------
** Work-around for problem in netcdf 4.1.3 for reading a unlimited
variable of current size 0
Summary of important user-visible changes for netcdf 1.0.3:
-------------------------------------------------------------------
** remove NC_INDEPENDENT and NC_COLLECTIVE which are no longer defined
in netcdf 4.3.1
Summary of important user-visible changes for netcdf 1.0.2:
-------------------------------------------------------------------
** Avoid obsolete isequalwithequalnans functions
Summary of important user-visible changes for netcdf 1.0.1:
-------------------------------------------------------------------
** Fix bug preventing compilation on 32-bit platforms.
Summary of important user-visible changes for netcdf 1.0.0:
-------------------------------------------------------------------
** Initial release
netcdf-1.0.14/PKG_ADD 0000644 0000000 0000000 00000011654 13741574474 012271 0 ustar 00 0000000 0000000 % File automatically generated by PKG_ADD.sh
autoload ("netcdf_getConstant", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_getConstantNames", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqLibVers", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_setDefaultFormat", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_setChunkCache", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_getChunkCache", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_create", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_open", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_abort", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_sync", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_setFill", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inq", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqUnlimDims", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqFormat", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_defDim", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_renameDim", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_defVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_renameVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_defVarFill", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqVarFill", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_defVarDeflate", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqVarDeflate", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_defVarChunking", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqVarChunking", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_defVarFletcher32", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqVarFletcher32", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_endDef", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_reDef", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_putVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_getVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_close", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqAttName", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqAttID", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_getAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_putAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_copyAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_renameAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_delAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqVarID", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqVarIDs", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqDim", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqDimID", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqDimIDs", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_defGrp", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqGrps", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqGrpName", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqGrpNameFull", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqGrpParent", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqGrpFullNcid", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
autoload ("netcdf_inqNcid", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"));
netcdf-1.0.14/PKG_DEL 0000644 0000000 0000000 00000012600 13741574474 012275 0 ustar 00 0000000 0000000 % File automatically generated by PKG_ADD.sh
autoload ("netcdf_getConstant", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_getConstantNames", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqLibVers", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_setDefaultFormat", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_setChunkCache", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_getChunkCache", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_create", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_open", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_abort", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_sync", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_setFill", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inq", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqUnlimDims", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqFormat", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_defDim", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_renameDim", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_defVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_renameVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_defVarFill", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqVarFill", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_defVarDeflate", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqVarDeflate", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_defVarChunking", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqVarChunking", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_defVarFletcher32", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqVarFletcher32", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_endDef", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_reDef", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_putVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_getVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_close", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqAttName", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqAttID", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_getAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_putAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_copyAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_renameAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_delAtt", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqVarID", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqVarIDs", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqVar", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqDim", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqDimID", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqDimIDs", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_defGrp", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqGrps", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqGrpName", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqGrpNameFull", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqGrpParent", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqGrpFullNcid", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
autoload ("netcdf_inqNcid", fullfile (fileparts (mfilename ("fullpath")), "__netcdf__.oct"),"remove");
netcdf-1.0.14/README.md 0000644 0000000 0000000 00000000556 13741574474 012533 0 ustar 00 0000000 0000000 [](https://travis-ci.org/Alexander-Barth/octave-netcdf)
# octave-netcdf
A NetCDF interface for Octave
Releases: https://octave.sourceforge.io/netcdf/
Documentation: https://octave.sourceforge.io/netcdf/overview.html
Wiki: https://github.com/Alexander-Barth/octave-netcdf/wiki
netcdf-1.0.14/inst/ 0000755 0000000 0000000 00000000000 13741574474 012223 5 ustar 00 0000000 0000000 netcdf-1.0.14/inst/import_netcdf.m 0000644 0000000 0000000 00000003743 13741574474 015245 0 ustar 00 0000000 0000000 % File automatically generated by PKG_ADD.sh
netcdf.getConstant = @netcdf_getConstant;
netcdf.getConstantNames = @netcdf_getConstantNames;
netcdf.inqLibVers = @netcdf_inqLibVers;
netcdf.setDefaultFormat = @netcdf_setDefaultFormat;
netcdf.setChunkCache = @netcdf_setChunkCache;
netcdf.getChunkCache = @netcdf_getChunkCache;
netcdf.create = @netcdf_create;
netcdf.open = @netcdf_open;
netcdf.abort = @netcdf_abort;
netcdf.sync = @netcdf_sync;
netcdf.setFill = @netcdf_setFill;
netcdf.inq = @netcdf_inq;
netcdf.inqUnlimDims = @netcdf_inqUnlimDims;
netcdf.inqFormat = @netcdf_inqFormat;
netcdf.defDim = @netcdf_defDim;
netcdf.renameDim = @netcdf_renameDim;
netcdf.defVar = @netcdf_defVar;
netcdf.renameVar = @netcdf_renameVar;
netcdf.defVarFill = @netcdf_defVarFill;
netcdf.inqVarFill = @netcdf_inqVarFill;
netcdf.defVarDeflate = @netcdf_defVarDeflate;
netcdf.inqVarDeflate = @netcdf_inqVarDeflate;
netcdf.defVarChunking = @netcdf_defVarChunking;
netcdf.inqVarChunking = @netcdf_inqVarChunking;
netcdf.defVarFletcher32 = @netcdf_defVarFletcher32;
netcdf.inqVarFletcher32 = @netcdf_inqVarFletcher32;
netcdf.endDef = @netcdf_endDef;
netcdf.reDef = @netcdf_reDef;
netcdf.putVar = @netcdf_putVar;
netcdf.getVar = @netcdf_getVar;
netcdf.close = @netcdf_close;
netcdf.inqAttName = @netcdf_inqAttName;
netcdf.inqAttID = @netcdf_inqAttID;
netcdf.inqAtt = @netcdf_inqAtt;
netcdf.getAtt = @netcdf_getAtt;
netcdf.putAtt = @netcdf_putAtt;
netcdf.copyAtt = @netcdf_copyAtt;
netcdf.renameAtt = @netcdf_renameAtt;
netcdf.delAtt = @netcdf_delAtt;
netcdf.inqVarID = @netcdf_inqVarID;
netcdf.inqVarIDs = @netcdf_inqVarIDs;
netcdf.inqVar = @netcdf_inqVar;
netcdf.inqDim = @netcdf_inqDim;
netcdf.inqDimID = @netcdf_inqDimID;
netcdf.inqDimIDs = @netcdf_inqDimIDs;
netcdf.defGrp = @netcdf_defGrp;
netcdf.inqGrps = @netcdf_inqGrps;
netcdf.inqGrpName = @netcdf_inqGrpName;
netcdf.inqGrpNameFull = @netcdf_inqGrpNameFull;
netcdf.inqGrpParent = @netcdf_inqGrpParent;
netcdf.inqGrpFullNcid = @netcdf_inqGrpFullNcid;
netcdf.inqNcid = @netcdf_inqNcid;
netcdf-1.0.14/inst/nccreate.m 0000644 0000000 0000000 00000007745 13741574474 014202 0 ustar 00 0000000 0000000 ## Copyright (C) 2013 Alexander Barth
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} nccreate(@var{filename},@var{varname})
## @deftypefnx {Function File} {} nccreate(@var{filename},@var{varname},"property",@var{value},...)
##
## Create the variable @var{varname} in the file @var{filename}.
##
## The following properties can be used:
## @itemize
## @item "Dimensions": a cell array with the dimension names followed by their
## length or Inf if the dimension is unlimited. If the property is ommited, a
## scalar variable is created.
## @item "Datatype": a string with the Octave data type name
## (see @code{ncinfo} for the correspondence between Octave and NetCDF data
## types). The default data type is a "double".
## @item "Format": This can be "netcdf4_classic" (default), "classic", "64bit"
## or "netcdf4".
## @item "FillValue": the value used for undefined elements of the NetCDF
## variable.
## @item "ChunkSize": the size of the data chunks. If omited, the variable is
## not chunked.
## @item "DeflateLevel": The deflate level for compression. It can be the string
## "disable" (default) for no compression or an integer between 0 (no
## compression) and 9 (maximum compression).
## @item "Shuffle": true for enabling the shuffle filter or false (default) for
## disabling it.
## @end itemize
##
## Example:
## @example
## nccreate("test.nc","temp","Dimensions",@{"lon",10,"lat",20@},"Format","classic");
## ncdisp("test.nc");
## @end example
## @seealso{ncwrite}
## @end deftypefn
function nccreate(filename,varname,varargin)
dimensions = {};
datatype = 'double';
ncformat = 'netcdf4_classic';
FillValue = [];
ChunkSize = [];
DeflateLevel = 'disable';
Shuffle = false;
for i = 1:2:length(varargin)
if strcmp(varargin{i},'Dimensions')
dimensions = varargin{i+1};
elseif strcmp(varargin{i},'Datatype')
datatype = varargin{i+1};
elseif strcmp(varargin{i},'Format')
ncformat = varargin{i+1};
elseif strcmp(varargin{i},'FillValue')
FillValue = varargin{i+1};
elseif strcmp(varargin{i},'ChunkSize')
ChunkSize = varargin{i+1};
elseif strcmp(varargin{i},'DeflateLevel')
DeflateLevel = varargin{i+1};
elseif strcmp(varargin{i},'Shuffle')
Shuffle = varargin{i+1};
else
error(['unknown keyword ' varargin{i} '.']);
end
end
if ~isempty(stat(filename))
ncid = netcdf_open(filename,'NC_WRITE');
netcdf_reDef(ncid);
else
mode = format2mode(ncformat);
ncid = netcdf_create(filename,mode);
end
% create dimensions
dimids = [];
i = 1;
while i <= length(dimensions)
if i == length(dimensions)
dimids(end+1) = netcdf_inqDimID(ncid,dimensions{i});
i = i+1;
elseif ischar(dimensions{i+1})
dimids(end+1) = netcdf_inqDimID(ncid,dimensions{i});
i = i+1;
else
try
if isinf(dimensions{i+1})
dimensions{i+1} = netcdf_getConstant('NC_UNLIMITED');
end
dimids(end+1) = netcdf_defDim(ncid,dimensions{i},dimensions{i+1});
catch
dimids(end+1) = netcdf_inqDimID(ncid,dimensions{i});
end
i = i+2;
end
end
varid = netcdf_defVar(ncid,varname,oct2nctype(datatype),dimids);
if ~isempty(ChunkSize)
netcdf_defVarChunking(ncid,varid,'chunked',ChunkSize);
end
if ~isempty(FillValue)
% value of nofill?
netcdf_defVarFill(ncid,varid,false,FillValue);
end
if isnumeric(DeflateLevel)
netcdf_defVarDeflate(ncid,varid,Shuffle,true,DeflateLevel);
end
netcdf_close(ncid);
netcdf-1.0.14/inst/ncdisp.m 0000644 0000000 0000000 00000010013 13741574474 013654 0 ustar 00 0000000 0000000 ## Copyright (C) 2013 Alexander Barth
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} ncdisp (@var{filename})
## display meta-data of the NetCDF file @var{filename}
##
## @seealso{ncinfo}
## @end deftypefn
function ncdisp(filename)
info = ncinfo(filename);
fprintf("Source:\n");
indent = repmat(" ",[1 11]);
fprintf("%s%s\n",indent,fullfile(filename));
fprintf("Format:\n");
fprintf("%s%s\n",indent,info.Format);
colors.var = "red";
colors.att = "cyan";
colors.dim = "blue";
group_color = "green";
printgroup("",info,colors);
function s = fmtattr(val)
if ischar(val)
s = sprintf("""%s""",val);
else
s = num2str(val);
end
function s = fmtsize(sz)
s = sprintf("%gx",sz);
s = s(1:end-1);
function printgroup(indent1,info,colors)
indent2 = [indent1 repmat(" ",[1 11])];
indent3 = [indent2 repmat(" ",[1 11])];
% attributes
if ~isempty(info.Attributes)
fprintf("%sGlobal Attributes:\n",indent1);
printattr(indent2,info.Attributes,colors);
end
% dimensions
if ~isempty(info.Dimensions)
% length of the longest attribute name
dim = info.Dimensions;
maxlen = max(cellfun(@length,{dim.Name}));
fprintf("%sDimensions:\n",indent1);
for i = 1:length(dim)
space = repmat(" ",[maxlen-length(dim(i).Name) 1]);
fprintf("%s",indent2);
colormsg(sprintf("%s %s= %d",dim(i).Name,space,dim(i).Length),colors.dim);
fprintf("\n");
end
end
% variables
if isfield(info,"Variables")
if ~isempty(info.Variables)
% length of the longest attribute name
vars = info.Variables;
fprintf("%sVariables:\n",indent1);
for i = 1:length(vars)
%fprintf("%s%s\n",indent2(1:end-7),vars(i).Name);
colormsg(sprintf("%s%s\n",indent2(1:end-7),vars(i).Name),colors.var);
if ~isempty(vars(i).Size)
sz = fmtsize(vars(i).Size);
dimname = sprintf("%s,",vars(i).Dimensions.Name);
dimname = dimname(1:end-1);
else
sz = "1x1";
dimname = "";
end
fprintf("%sSize: %s\n",indent2,sz);
fprintf("%sDimensions: %s\n",indent2,dimname);
fprintf("%sDatatype: %s\n",indent2,vars(i).Datatype);
if ~isempty(vars(i).Attributes);
fprintf("%sAttributes:\n",indent2);
printattr(indent3,vars(i).Attributes,colors);
end
end
end
end
% groups
if ~isempty(info.Groups)
% length of the longest attribute name
grps = info.Groups;
fprintf("%sGroups:\n",indent1);
for i = 1:length(grps)
fprintf("%s%s\n",indent2(1:end-7),grps(i).Name);
printgroup(indent2,grps(i),colors);
end
end
function printattr(indent,attr,colors)
% length of the longest attribute name
maxlen = max(cellfun(@length,{attr.Name}));
for i = 1:length(attr)
space = repmat(" ",[maxlen-length(attr(i).Name) 1]);
%fprintf("%s%s %s= %s\n",indent,attr(i).Name,space,fmtattr(attr(i).Value));
fprintf("%s",indent);
colormsg(sprintf("%s %s= %s\n",attr(i).Name,space,fmtattr(attr(i).Value)),colors.att);
end
function colormsg (msg,color)
if strcmp(getenv("TERM"),"xterm")
esc = char(27);
% ANSI escape codes
colors.black = [esc, "[30m"];
colors.red = [esc, "[31m"];
colors.green = [esc, "[32m"];
colors.yellow = [esc, "[33m"];
colors.blue = [esc, "[34m"];
colors.magenta = [esc, "[35m"];
colors.cyan = [esc, "[36m"];
colors.white = [esc, "[37m"];
reset = [esc, "[0m"];
c = getfield(colors,color);
fprintf('%s',[c, msg, reset]);
else
fprintf('%s',msg);
end
netcdf-1.0.14/inst/ncinfo.m 0000644 0000000 0000000 00000016736 13741574474 013672 0 ustar 00 0000000 0000000 ## Copyright (C) 2013 Alexander Barth
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {@var{info} =} ncinfo (@var{filename})
## @deftypefnx {Function File} {@var{info} =} ncinfo (@var{filename}, @var{varname})
## @deftypefnx {Function File} {@var{info} =} ncinfo (@var{filename}, @var{groupname})
## return information about an entire NetCDF file @var{filename} (i.e. the root
## group "/"), about the variable called @var{varname} or the group called
## @var{groupname}.
##
## The structure @var{info} has always the following fields:
## @itemize
## @item @var{Filename}: the name of the NetCDF file
## @item @var{Format}: one of the strings "CLASSIC", "64BIT", "NETCDF4"
## or "NETCDF4_CLASSIC"
## @end itemize
##
## The structure @var{info} has additional fields depending on wether a
## group of variable is queried.
##
## Groups
##
## Groups are returned as an array structure with the following fields:
##
## @itemize
## @item @var{Name}: the group name. The root group is named "/".
## @item @var{Dimensions}: a array structure with the dimensions.
## @item @var{Variables}: a array structure with the variables.
## @item @var{Attributes}: a array structure with global attributes.
## @item @var{Groups}: a array structure (one for each group) with the
## same fields as this structure.
## @end itemize
##
## Dimensions
##
## Dimensions are returned as an array structure with the following fields:
## @itemize
## @item @var{Name}: the name of the dimension
## @item @var{Length}: the length of the dimension
## @item @var{Unlimited}: true of the dimension has no fixed limited, false
## @end itemize
##
## Variables
##
## Variables are returned as an array structure with the following fields:
## @itemize
## @item @var{Name}: the name of the dimension
## @item @var{Dimensions}: array structure of all dimensions of this variable
## with the same structure as above.
## @item @var{Size}: array with the size of the variable
## @item @var{Datatype}: string with the corresponding octave data-type
## (see below)
## @item @var{Attributes}: a array structure of attributes
## @item @var{FillValue}: the NetCDF fill value of the variable. If the fill
## value is not defined, then this attribute is an empty array ([]).
## @item @var{DeflateLevel}: the NetCDF deflate level between 0 (no
## compression) and 9 (maximum compression).
## @item @var{Shuffle}: is true if the shuffle filter is activated to improve
## compression, otherwise false.
## @item @var{CheckSum}: is set to "fletcher32", if check-sums are used,
# otherwise this field is not defined.
## @end itemize
##
## Attributes
##
## Attributes are returned as an array structure with the following fields:
## @itemize
## @item @var{Name}: the name of the attribute
## @item @var{Value}: the value of the attribute (with the corresponding type)
## @item @var{Unlimited}: true of the dimension has no fixed limited, false
## @end itemize
##
## Data-types
##
## The following the the correspondence between the Octave and NetCDF
## data-types:
##
## @multitable @columnfractions .5 .5
## @headitem Octave type @tab NetCDF type
## @item @code{int8} @tab @code{NC_BYTE}
## @item @code{uint8} @tab @code{NC_UBYTE}
## @item @code{int16} @tab @code{NC_SHORT}
## @item @code{uint16} @tab @code{NC_USHORT}
## @item @code{int32} @tab @code{NC_INT}
## @item @code{uint32} @tab @code{NC_UINT}
## @item @code{int64} @tab @code{NC_INT64}
## @item @code{uint64} @tab @code{NC_UINT64}
## @item @code{single} @tab @code{NC_FLOAT}
## @item @code{double} @tab @code{NC_DOUBLE}
## @item @code{char} @tab @code{NC_CHAR}
## @end multitable
##
## The output of @code{ncinfo} can be used to create a NetCDF file with the same
## meta-data using @code{ncwriteschema}.
##
## Note: If there are no attributes (or variable or groups), the corresponding
## field is an empty matrix and not an empty struct array for compability
## with matlab.
##
## @seealso{ncread,nccreate,ncwriteschema,ncdisp}
##
## @end deftypefn
function info = ncinfo(filename,name)
ncid = netcdf_open(filename,"NC_NOWRITE");
info.Filename = filename;
if nargin == 1
name = "/";
endif
[gid,varid] = ncloc(ncid,name);
if isempty(varid)
info = ncinfo_group(info,gid);
else
unlimdimIDs = netcdf_inqUnlimDims(gid);
info = ncinfo_var(info,gid,varid,unlimdimIDs);
endif
# NetCDF format
ncformat = netcdf_inqFormat(ncid);
info.Format = lower(strrep(ncformat,'FORMAT_',''));
netcdf_close(ncid);
endfunction
function dims = ncinfo_dim(ncid,dimids,unlimdimIDs)
dims = [];
for i=1:length(dimids)
tmp = struct();
[tmp.Name, tmp.Length] = netcdf_inqDim(ncid,dimids(i));
tmp.Unlimited = any(unlimdimIDs == dimids(i));
if isempty(dims)
dims = [tmp];
else
dims(i) = tmp;
endif
endfor
endfunction
function vinfo = ncinfo_var(vinfo,ncid,varid,unlimdimIDs)
[vinfo.Name,xtype,dimids,natts] = netcdf_inqVar(ncid,varid);
% Information about dimension
vinfo.Dimensions = ncinfo_dim(ncid,dimids,unlimdimIDs);
if isempty(vinfo.Dimensions)
vinfo.Size = [];
else
vinfo.Size = cat(2,vinfo.Dimensions.Length);
end
% Data type
vinfo.Datatype = nc2octtype(xtype);
% Attributes
vinfo.Attributes = [];
for i = 0:natts-1
tmp = struct();
tmp.Name = netcdf_inqAttName(ncid,varid,i);
tmp.Value = netcdf_getAtt(ncid,varid,tmp.Name);
if isempty(vinfo.Attributes)
vinfo.Attributes = [tmp];
else
vinfo.Attributes(i+1) = tmp;
endif
endfor
% chunking, fillvalue, compression
[storage,vinfo.ChunkSize] = netcdf_inqVarChunking(ncid,varid);
[nofill,vinfo.FillValue] = netcdf_inqVarFill(ncid,varid);
if nofill
vinfo.FillValue = [];
endif
[shuffle,deflate,vinfo.DeflateLevel] = ...
netcdf_inqVarDeflate(ncid,varid);
if ~deflate
vinfo.DeflateLevel = [];
endif
vinfo.Shuffle = shuffle;
# add checksum information if defined (unlike matlab)
checksum = netcdf_inqVarFletcher32(ncid,varid);
if ~strcmp(checksum,'nochecksum');
vinfo.Checksum = checksum;
endif
endfunction
function info = ncinfo_group(info,ncid)
info.Name = netcdf_inqGrpName(ncid);
unlimdimIDs = netcdf_inqUnlimDims(ncid);
[ndims,nvars,ngatts] = netcdf_inq(ncid);
% dimensions
dimids = netcdf_inqDimIDs(ncid);
info.Dimensions = ncinfo_dim(ncid,dimids,unlimdimIDs);
% variables
for i=1:nvars
info.Variables(i) = ncinfo_var(struct(),ncid,i-1,unlimdimIDs);
endfor
% global attributes
info.Attributes = [];
gid = netcdf_getConstant('NC_GLOBAL');
for i = 0:ngatts-1
tmp = struct();
tmp.Name = netcdf_inqAttName(ncid,gid,i);
tmp.Value = netcdf_getAtt(ncid,gid,tmp.Name);
if isempty(info.Attributes)
info.Attributes = [tmp];
else
info.Attributes(i+1) = tmp;
endif
endfor
info.Groups = [];
gids = netcdf_inqGrps(ncid);
for i = 1:length(gids)
tmp = ncinfo_group(struct(),gids(i));
if isempty(info.Groups)
info.Groups = [tmp];
else
info.Groups(i) = tmp;
endif
endfor
endfunction
netcdf-1.0.14/inst/ncread.m 0000644 0000000 0000000 00000006740 13741574474 013644 0 ustar 00 0000000 0000000 ## Copyright (C) 2013 Alexander Barth
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {@var{x} =} ncread (@var{filename}, @var{varname})
## @deftypefnx {Function File} {@var{x} =} ncread (@var{filename}, @var{varname},@var{start},@var{count},@var{stride})
##
## Read the variable @var{varname} from the NetCDF file @var{filename}.
##
## If @var{start},@var{count} and @var{stride} are present, a subset of the
## variable is loaded. The parameter @var{start} contains the starting indices
## (1-based), @var{count} is the number of elements and @var{stride} the
## increment between two successive elements. These parameters are vectors whose
## length is equal to the number of dimension of the variable. Elements of
## @var{count} might be Inf which means that as many values as possible are
## loaded.
##
## If the variable has the _FillValue attribute, then the corresponding values
## are replaced by NaN (except for characters). NetCDF attributes scale_factor
## (default 1) and add_offset (default 0) are use the transform the variable
## during the loading:
##
## x = scale_factor * x_in_file + add_offset
##
## The output data type matches the NetCDF datatype, except when the attributes
## _FillValue, add_offset or scale_factor are defined in which case the output
## is a array in double precision.
##
## Note that values equal to the attribute missing_value are not replaced by
## NaN (for compatibility).
##
## @seealso{ncwrite,ncinfo,ncdisp}
##
## @end deftypefn
function x = ncread(filename,varname,start,count,stride)
ncid = netcdf_open(filename,'NC_NOWRITE');
[gid,varid] = ncvarid(ncid,varname);
[varname_,xtype,dimids,natts] = netcdf_inqVar(gid,varid);
% number of dimenions
nd = length(dimids);
sz = zeros(1,nd);
for i=1:length(dimids)
[dimname, sz(i)] = netcdf_inqDim(gid,dimids(i));
end
if nargin < 3
start = ones(1,nd);
end
if nargin < 4
count = inf*ones(1,nd);
end
if nargin < 5
stride = ones(1,nd);
end
% replace inf in count
i = count == inf;
count(i) = (sz(i)-start(i))./stride(i) + 1;
x = netcdf_getVar(gid,varid,start-1,count,stride);
% apply attributes
factor = [];
offset = [];
fv = [];
for i = 0:natts-1
attname = netcdf_inqAttName(gid,varid,i);
if strcmp(attname,'scale_factor')
factor = netcdf_getAtt(gid,varid,'scale_factor');
elseif strcmp(attname,'add_offset')
offset = netcdf_getAtt(gid,varid,'add_offset');
elseif strcmp(attname,'_FillValue')
fv = netcdf_getAtt(gid,varid,'_FillValue');
end
end
netcdf_close(ncid);
# the scaling does not make sense of characters
if xtype == netcdf_getConstant('char') || ...
xtype == netcdf_getConstant('string')
return;
end
if !isempty(fv) || !isempty(factor) || !isempty(offset)
if !isa(x,'double')
x = double(x);
end
end
if !isempty(fv)
x(x == fv) = NaN;
end
if !isempty(factor)
x = x * factor;
end
if !isempty(offset)
x = x + offset;
end
netcdf-1.0.14/inst/ncreadatt.m 0000644 0000000 0000000 00000002566 13741574474 014357 0 ustar 00 0000000 0000000 ## Copyright (C) 2013 Alexander Barth
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {@var{val} =} ncreadatt(@var{filename},@var{varname},@var{attname})
##
## Return the attribute @var{attname} of the variable @var{varname} in the file
## @var{filename}.
##
## Gobal attributes can be accessed by using "/" or the group name as
## @var{varname}. The type of attribute is mapped to the Octave data types.
## (see @code{ncinfo}).
##
## @seealso{ncinfo,ncwriteatt}
##
## @end deftypefn
function val = ncreadatt(filename,varname,attname)
ncid = netcdf_open(filename,'NC_NOWRITE');
[gid,varid] = ncloc(ncid,varname);
if isempty(varid)
varid = netcdf_getConstant('NC_GLOBAL');
endif
val = netcdf_getAtt(gid,varid,attname);
netcdf_close(ncid);
netcdf-1.0.14/inst/ncwrite.m 0000644 0000000 0000000 00000005462 13741574474 014063 0 ustar 00 0000000 0000000 ## Copyright (C) 2013 Alexander Barth
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} ncwrite (@var{filename}, @var{varname}, @var{x})
## @deftypefnx {Function File} {} ncwrite (@var{filename}, @var{varname}, @var{x}, @var{start}, @var{stride})
##
## Write array @var{x} to the the variable @var{varname} in the NetCDF file
## @var{filename}.
##
## The variable with the name @var{varname} and the appropriate dimension must
## already exist in the NetCDF file.
##
## If @var{start} and @var{stride} are present, a subset of the
## variable is written. The parameter @var{start} contains the starting indices
## (1-based) and @var{stride} the
## increment between two successive elements. These parameters are vectors whose
## length is equal to the number of dimension of the variable.
##
## If the variable has the _FillValue attribute, then the values equal to NaN
## are replaced by corresponding fill value NetCDF attributes scale_factor
## (default 1) and add_oddset (default 0) are use the transform the variable
## during the writting:
##
## x_in_file = (x - add_offset)/scale_factor
##
## @seealso{ncread,nccreate}
##
## @end deftypefn
function ncwrite(filename,varname,x,start,stride)
ncid = netcdf_open(filename,'NC_WRITE');
[gid,varid] = ncvarid(ncid,varname);
[varname_,xtype,dimids,natts] = netcdf_inqVar(gid,varid);
% number of dimenions
nd = length(dimids);
sz = zeros(1,nd);
count = zeros(1,nd);
for i=1:length(dimids)
[dimname, sz(i)] = netcdf_inqDim(gid,dimids(i));
count(i) = size(x,i);
end
if nargin < 4
start = ones(1,nd);
end
if nargin < 5
stride = ones(1,nd);
end
% apply attributes
factor = [];
offset = [];
fv = [];
for i = 0:natts-1
attname = netcdf_inqAttName(gid,varid,i);
if strcmp(attname,'scale_factor')
factor = netcdf_getAtt(gid,varid,'scale_factor');
elseif strcmp(attname,'add_offset')
offset = netcdf_getAtt(gid,varid,'add_offset');
elseif strcmp(attname,'_FillValue')
fv = netcdf_getAtt(gid,varid,'_FillValue');
end
end
if ~isempty(offset)
x = x - offset;
end
if ~isempty(factor)
x = x / factor;
end
if ~isempty(fv)
x(isnan(x)) = fv;
end
netcdf_putVar(gid,varid,start-1,count,stride,x);
netcdf_close(ncid);
netcdf-1.0.14/inst/ncwriteatt.m 0000644 0000000 0000000 00000002621 13741574474 014566 0 ustar 00 0000000 0000000 ## Copyright (C) 2013 Alexander Barth
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} ncwriteatt(@var{filename},@var{varname},@var{attname},@var{val})
##
## Defines the attribute @var{attname} of the variable @var{varname} in the file
## @var{filename} with the value @var{val}.
##
## Global attributes can be defined by using "/" or the group name as
## @var{varname}. The type of value is mapped to the NetCDF data types.
## (see @code{ncinfo}).
##
## @seealso{ncinfo}
##
## @end deftypefn
function ncwriteatt(filename,varname,attname,val)
ncid = netcdf_open(filename,'NC_WRITE');
netcdf_reDef(ncid);
[gid,varid] = ncloc(ncid,varname);
if isempty(varid)
varid = netcdf_getConstant('NC_GLOBAL');
endif
netcdf_putAtt(ncid,varid,attname,val);
netcdf_close(ncid);
netcdf-1.0.14/inst/ncwriteschema.m 0000644 0000000 0000000 00000010343 13741574474 015236 0 ustar 00 0000000 0000000 ## Copyright (C) 2013 Alexander Barth
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} ncwriteschema (@var{filename}, @var{shema})
##
## Create a NetCDF called @var{filename} with the dimensions, attributes,
## variables and groups given by the structure @var{schema}.
##
## The variable @var{schema} has the same structure as the results of
## @code{ncinfo}. @code{ncinfo} and @code{ncwriteschema} can be used together to
## create a NetCDF using another file as a template:
##
## @example
## schema = ncinfo("template.nc");
## # the new file should be named "new_file.nc"
## ncwriteschema("new_file.nc",schema);
## @end example
##
## Unused field in @var{schema} such as @var{ChunkSize}, @var{Shuffle},
## @var{DeflateLevel}, @var{FillValue}, @var{Checksum} can be left-out if the
## corresponding feature is not used.
##
## Dimensions are considered as limited if the field @var{Unlimited} is missing,
## unless the dimension length is Inf.
##
## @seealso{ncinfo}
##
## @end deftypefn
function ncwriteschema(filename,s)
mode = format2mode(s.Format);
ncid = netcdf_create(filename,mode);
write_group(ncid,s)
netcdf_close(ncid);
end
function write_group(ncid,s)
% normalize schema
if ~isfield(s,'Dimensions')
s.Dimensions = [];
end
if isempty(s.Dimensions)
s.Dimensions = struct('Name',{},'Length',{},'Unlimited',{});
end
if ~isfield(s,'Attributes')
s.Attributes = struct('Name',{},'Value',{});
end
if ~isfield(s,'Variables')
s.Variables = struct('Name',{},'Dimensions',{},'Datatype',{});;
end
% dimension
for i = 1:length(s.Dimensions)
dim = s.Dimensions(i);
if ~isfield(dim,'Unlimited')
dim.Unlimited = false;
end
len = dim.Length;
if dim.Unlimited || isinf(len)
len = netcdf_getConstant('NC_UNLIMITED');
end
s.Dimensions(i).id = netcdf_defDim(ncid,dim.Name,len);
end
% global attributes
gid = netcdf_getConstant('NC_GLOBAL');
for j = 1:length(s.Attributes)
netcdf_putAtt(ncid,gid,s.Attributes(j).Name,s.Attributes(j).Value);
end
% variables
for i = 1:length(s.Variables)
v = s.Variables(i);
%v.Name
% get dimension id
dimids = zeros(length(v.Dimensions),1);
for j = 1:length(v.Dimensions)
dimids(j) = netcdf_inqDimID(ncid,v.Dimensions(j).Name);
end
% define variable
dtype = oct2nctype(v.Datatype);
varid = netcdf_defVar(ncid,v.Name,dtype,dimids);
% define attributes
for j = 1:length(v.Attributes)
netcdf_putAtt(ncid,varid,v.Attributes(j).Name,v.Attributes(j).Value);
end
% define chunk size
if isfield(v,'ChunkSize')
if ~isempty(v.ChunkSize)
netcdf_defVarChunking(ncid,varid,'chunked',v.ChunkSize);
end
end
% define compression
shuffle = false;
deflatelevel = 0;
if isfield(v,'Shuffle')
if ~isempty(v.Shuffle)
shuffle = v.Shuffle;
end
end
if isfield(v,'DeflateLevel')
if ~isempty(v.DeflateLevel)
deflatelevel = v.DeflateLevel;
end
end
if shuffle && defaltelevel != 0
deflate = defaltelevel != 0;
netcdf_defVarDeflate(ncid,varid,shuffle,deflate,deflatelevel);
end
% define fill value
if isfield(v,'FillValue')
if ~isempty(v.FillValue)
% leave nofill setting unchanged
[nofill,fillval] = netcdf_inqVarFill(ncid,varid);
netcdf_defVarFill(ncid,varid,nofill,v.FillValue);
end
end
% define checksum
if isfield(v,'Checksum')
if ~isempty(v.Checksum)
netcdf_defVarFletcher32(ncid,varid,v.Checksum);
end
end
end
% groups
if isfield(s,'Groups')
if ~isempty(s.Groups)
for i=1:length(s.Groups)
g = s.Groups(i);
gid = netcdf_defGrp(ncid,g.Name);
write_group(gid,g);
end
end
end
end
netcdf-1.0.14/inst/private/ 0000755 0000000 0000000 00000000000 13741574474 013675 5 ustar 00 0000000 0000000 netcdf-1.0.14/inst/private/bug_47014.m 0000644 0000000 0000000 00000000542 13741574474 015370 0 ustar 00 0000000 0000000 % test case for bug 47014
% https://savannah.gnu.org/bugs/?func=detailitem&item_id=47014
fname = [tempname '-octave-netcdf.nc'];
nccreate(fname,'var','Dimensions',{'x',10},...
'FillValue',-32767,'Datatype','int16')
var = ones(10,1);
var(1) = NaN;
ncwrite(fname,'var',var);
var2 = ncread(fname,'var');
assert(isequaln(var,var2))
delete(fname)
netcdf-1.0.14/inst/private/format2mode.m 0000644 0000000 0000000 00000002246 13741574474 016276 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function mode = format2mode(format)
mode = netcdf_getConstant("NC_NOCLOBBER");
switch lower(format)
case "classic"
% do nothing
case "64bit"
mode = bitor(mode,netcdf_getConstant("NC_64BIT_OFFSET"));
case "netcdf4_classic"
mode = bitor(bitor(mode,netcdf_getConstant("NC_NETCDF4")),...
netcdf_getConstant("NC_CLASSIC_MODEL"));
case "netcdf4"
mode = bitor(mode,netcdf_getConstant("NC_NETCDF4"));
otherwise
error("netcdf:unkownFormat","unknown format %s",format);
end
netcdf-1.0.14/inst/private/nc2octtype.m 0000644 0000000 0000000 00000003107 13741574474 016146 0 ustar 00 0000000 0000000 %% Copyright (C) 2013-2020 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function otype = nc2octtype(nctype)
if nctype == netcdf_getConstant("NC_CHAR")
otype = "char";
elseif nctype == netcdf_getConstant("NC_FLOAT")
otype = "single";
elseif nctype == netcdf_getConstant("NC_DOUBLE")
otype = "double";
elseif nctype == netcdf_getConstant("NC_BYTE")
otype = "int8";
elseif nctype == netcdf_getConstant("NC_SHORT")
otype = "int16";
elseif nctype == netcdf_getConstant("NC_INT")
otype = "int32";
elseif nctype == netcdf_getConstant("NC_INT64")
otype = "int64";
elseif nctype == netcdf_getConstant("NC_UBYTE")
otype = "uint8";
elseif nctype == netcdf_getConstant("NC_USHORT")
otype = "uint16";
elseif nctype == netcdf_getConstant("NC_UINT")
otype = "uint32";
elseif nctype == netcdf_getConstant("NC_UINT64")
otype = "uint64";
elseif nctype == netcdf_getConstant("NC_STRING")
otype = "string";
else
error("netcdf:unknownDataType","unknown data type %d",nctype)
endif
netcdf-1.0.14/inst/private/ncloc.m 0000644 0000000 0000000 00000001675 13741574474 015162 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
% resolves a location (variable or group) by name
function [gid,varid] = ncloc(ncid,name)
try
# try if name is a group
gid = netcdf_inqGrpFullNcid(ncid,name);
varid = [];
catch
# assume that name is a variable
[gid,varid] = ncvarid(ncid,name);
end_try_catch
netcdf-1.0.14/inst/private/ncvarid.m 0000644 0000000 0000000 00000001711 13741574474 015501 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function [gid,varid] = ncvarid(ncid,varname)
if strcmp(varname(1), '/')
i = find(varname == '/',1,'last');
groupname = varname(1:i-1);
varname = varname(i+1:end);
gid = netcdf_inqGrpFullNcid(ncid,groupname);
else
gid = ncid;
end
varid = netcdf_inqVarID(gid, varname);
netcdf-1.0.14/inst/private/oct2nctype.m 0000644 0000000 0000000 00000003051 13741574474 016144 0 ustar 00 0000000 0000000 %% Copyright (C) 2013-2020 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function nctype = oct2nctype(otype)
typemap.int8 = 'byte';
typemap.uint8 = 'ubyte';
typemap.int16 = 'short';
typemap.uint16 = 'ushort';
typemap.int32 = 'int';
typemap.uint32 = 'uint';
typemap.int64 = 'int64';
typemap.uint64 = 'uint64';
typemap.single = 'float';
typemap.double = 'double';
typemap.char = 'char';
typemap.string = 'string';
if ischar(otype)
otype = lower(otype);
if isfield(typemap,otype)
nctype = typemap.(otype);
else
error('netcdf:unkownType','unknown type %s',otype);
end
else
nctype = otype;
end
%typemap.byte = 'int8';
%typemap.ubyte = 'uint8';
%typemap.short = 'int16';
%typemap.ushort = 'uint16';
%typemap.int = 'int32';
%typemap.uint = 'uint32';
%typemap.int64 = 'int64';
%typemap.uint64 = 'uint64';
%typemap.float = 'single';
%typemap.double = 'double';
%typemap.char = 'char';
%typemap.string = 'string';
netcdf-1.0.14/inst/private/test_netcdf_attributes.m 0000644 0000000 0000000 00000022422 13741574474 020625 0 ustar 00 0000000 0000000 %% Copyright (C) 2013-2014 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function test_netcdf_attributes()
import_netcdf
% rename attributes
fname = [tempname '-octave-netcdf-rename-attrib.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
gid = netcdf.getConstant('global');
netcdf.putAtt(ncid,gid,'toto',int8(123));
name = netcdf.inqAttName(ncid,gid,0);
assert(strcmp(name,'toto'));
netcdf.renameAtt(ncid,gid,'toto','lala');
name = netcdf.inqAttName(ncid,gid,0);
assert(strcmp(name,'lala'));
netcdf.close(ncid);
delete(fname)
% delete attributes
fname = [tempname '-octave-netcdf-delete-attrib.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
gid = netcdf.getConstant('global');
netcdf.putAtt(ncid,gid,'toto',int8(123));
varid = netcdf.defVar(ncid,'double_var','double',[]);
[ndims,nvars,natts] = netcdf.inq(ncid);
assert(natts == 1);
netcdf.delAtt(ncid,gid,'toto');
[ndims,nvars,natts] = netcdf.inq(ncid);
assert(natts == 0);
netcdf.close(ncid);
delete(fname)
% copy attributes
fname = [tempname '-octave-netcdf-copy-attrib.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
gid = netcdf.getConstant('global');
netcdf.putAtt(ncid,gid,'toto',int8(123));
varid = netcdf.defVar(ncid,'double_var','double',[]);
netcdf.copyAtt(ncid,gid,'toto',ncid,varid);
[ndims,nvars,natts] = netcdf.inq(ncid);
assert(natts == 1);
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid,varid);
val = netcdf.getAtt(ncid,varid,'toto');
assert(isequal(val,123));
netcdf.close(ncid);
delete(fname)
% attributes id
fname = [tempname '-octave-netcdf-delete-attrib.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
gid = netcdf.getConstant('global');
netcdf.putAtt(ncid,gid,'toto',int8(123));
attnum = netcdf.inqAttID(ncid,gid,'toto');
name = netcdf.inqAttName(ncid,gid,attnum);
assert(strcmp(name,'toto'))
netcdf.close(ncid);
delete(fname)
% test one unlimited dimensions
fname = [tempname '-octave-netcdf-unlimdim.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
dimID = netcdf.defDim(ncid,'time',netcdf.getConstant('NC_UNLIMITED'));
unlimdimIDs = netcdf.inqUnlimDims(ncid);
assert(dimID == unlimdimIDs);
netcdf.close(ncid);
delete(fname)
% test netcdf_classic format
fname = [tempname '-octave-netcdf-classic-model.nc'];
mode = bitor(netcdf.getConstant('classic_model'),netcdf.getConstant('netcdf4'));
ncid = netcdf.create(fname,mode);
netcdf.close(ncid);
info = ncinfo(fname);
assert(strcmp(info.Format,'netcdf4_classic'));
delete(fname);
% test two unlimited dimensions
fname = [tempname '-octave-netcdf-2unlimdim.nc'];
mode = bitor(netcdf.getConstant('NC_CLOBBER'),netcdf.getConstant('NC_NETCDF4'));
ncid = netcdf.create(fname,mode);
dimID = netcdf.defDim(ncid,'time',netcdf.getConstant('NC_UNLIMITED'));
dimID2 = netcdf.defDim(ncid,'time2',netcdf.getConstant('NC_UNLIMITED'));
unlimdimIDs = netcdf.inqUnlimDims(ncid);
assert(isequal(sort([dimID,dimID2]),sort(unlimdimIDs)));
netcdf.close(ncid);
delete(fname);
% test fill mode
fname = [tempname '-octave-netcdf-fill-mode.nc'];
mode = bitor(netcdf.getConstant('NC_CLOBBER'),netcdf.getConstant('NC_NETCDF4'));
ncid = netcdf.create(fname,mode);
old_mode = netcdf.setFill(ncid,'nofill');
old_mode = netcdf.setFill(ncid,'nofill');
assert(old_mode == netcdf.getConstant('nofill'))
netcdf.close(ncid);
delete(fname);
% deflate for 64bit_offset files
fname = [tempname '-octave-netcdf-deflate.nc'];
ncid = netcdf.create(fname,'64BIT_OFFSET');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'double_var','double',dimids);
[shuffle,deflate,deflateLevel] = netcdf.inqVarDeflate(ncid,varid);
assert(shuffle == 0)
assert(deflate == 0)
assert(deflateLevel == 0)
netcdf.close(ncid);
%system(['ncdump -h ' fname])
delete(fname);
% deflate
fname = [tempname '-octave-netcdf-deflate.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'double_var','double',dimids);
netcdf.defVarDeflate(ncid,varid,true,true,9);
[shuffle,deflate,deflateLevel] = netcdf.inqVarDeflate(ncid,varid);
assert(shuffle)
assert(deflate)
assert(deflateLevel == 9)
netcdf.close(ncid);
%system(['ncdump -h ' fname])
delete(fname);
% chunking - contiguous storage
fname = [tempname '-octave-netcdf-chunking.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'double_var','double',dimids);
netcdf.defVarChunking(ncid,varid,'contiguous');
[storage,chunksize] = netcdf.inqVarChunking(ncid,varid);
assert(strcmp(storage,'contiguous'))
assert(isempty(chunksize))
netcdf.close(ncid);
%system(['ncdump -h ' fname])
delete(fname);
% chunking - chunked storage
fname = [tempname '-octave-netcdf-chunking.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'double_var','double',dimids);
netcdf.defVarChunking(ncid,varid,'chunked',[3 4]);
[storage,chunksize] = netcdf.inqVarChunking(ncid,varid);
assert(strcmp(storage,'chunked'))
assert(isequal(chunksize,[3 4]))
netcdf.close(ncid);
%system(['ncdump -h ' fname])
delete(fname);
% checksum
fname = [tempname '-octave-netcdf-checksum.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'double_var','double',dimids);
checksum = netcdf.inqVarFletcher32(ncid,varid);
assert(strcmp(checksum,'NOCHECKSUM'))
netcdf.defVarFletcher32(ncid,varid,'fletcher32');
checksum = netcdf.inqVarFletcher32(ncid,varid);
assert(strcmp(checksum,'FLETCHER32'))
netcdf.close(ncid);
%system(['ncdump -h ' fname])
delete(fname);
% variable fill
fname = [tempname '-octave-netcdf-fill.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'double_var','double',dimids);
netcdf.defVarFill(ncid,varid,false,-99999.);
[nofill,fillval] = netcdf.inqVarFill(ncid,varid);
assert(isequal(nofill,false))
assert(fillval == -99999.)
netcdf.close(ncid);
%system(['ncdump -h ' fname])
delete(fname);
% variable fill single
fname = [tempname '-octave-netcdf-fill.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'single_var','float',dimids);
netcdf.defVarFill(ncid,varid,false,single(-99999.));
[nofill,fillval] = netcdf.inqVarFill(ncid,varid);
assert(isequal(nofill,false))
assert(fillval == -99999.)
netcdf.close(ncid);
%system(['ncdump -h ' fname])
delete(fname);
% variable fill char
fname = [tempname '-octave-netcdf-fill-char.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'double_var','char',dimids);
netcdf.defVarFill(ncid,varid,false,'X');
[fill,fillval] = netcdf.inqVarFill(ncid,varid);
assert(~fill)
assert(fillval == 'X')
netcdf.close(ncid);
delete(fname);
% check default state of fill
fname = [tempname '-octave-netcdf-fill.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'double_var','double',dimids);
[nofill,fillval] = netcdf.inqVarFill(ncid,varid);
assert(isequal(nofill,false))
netcdf.close(ncid);
%system(['ncdump -h ' fname])
delete(fname);
% create groups
fname = [tempname '-octave-netcdf-groups.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
id1 = netcdf.defGrp(ncid,'group1');
id2 = netcdf.defGrp(ncid,'group2');
id3 = netcdf.defGrp(id1,'subgroup');
ids = netcdf.inqGrps(ncid);
assert(isequal(sort([id1,id2]),sort(ids)));
id4 = netcdf.inqNcid(ncid,'group1');
assert(id1 == id4)
name = netcdf.inqGrpName(id3);
assert(strcmp(name,'subgroup'))
name = netcdf.inqGrpNameFull(id3);
assert(strcmp(name,'/group1/subgroup'))
parentid = netcdf.inqGrpParent(id3);
assert(id1 == parentid);
if 0
id3bis = netcdf.inqGrpFullNcid(ncid,'/group1/subgroup');
assert(id3 == id3bis);
end
netcdf.close(ncid);
%system(['ncdump -h ' fname])
delete(fname);
% check rename dimension
fname = [tempname '-octave-rename-dim.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimid = netcdf.defDim(ncid,'x',123);
[name,len] = netcdf.inqDim(ncid,dimid);
assert(strcmp(name,'x'));
netcdf.renameDim(ncid,dimid,'y');
[name,len] = netcdf.inqDim(ncid,dimid);
assert(strcmp(name,'y'));
netcdf.close(ncid);
delete(fname);
% rename variable
fname = [tempname '-octave-netcdf-rename-var.nc'];
ncid = netcdf.create(fname,'NC_NETCDF4');
dimids = [netcdf.defDim(ncid,'x',123) netcdf.defDim(ncid,'y',12)];
varid = netcdf.defVar(ncid,'double_var','char',dimids);
[varname] = netcdf.inqVar(ncid,varid);
assert(strcmp(varname,'double_var'));
netcdf.renameVar(ncid,varid,'doublev');
[varname] = netcdf.inqVar(ncid,varid);
assert(strcmp(varname,'doublev'));
netcdf.close(ncid);
delete(fname);
netcdf-1.0.14/inst/private/test_netcdf_constant.m 0000644 0000000 0000000 00000002621 13741574474 020267 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
% test netcdf constants
function test_netcdf_constant()
import_netcdf
names = netcdf.getConstantNames();
assert(any(strcmp(names,'NC_WRITE')));
assert(netcdf.getConstant('NC_NOWRITE') == 0)
assert(netcdf.getConstant('NC_WRITE') == 1)
assert(netcdf.getConstant('NC_64BIT_OFFSET') == ...
netcdf.getConstant('64BIT_OFFSET'))
assert(netcdf.getConstant('NC_64BIT_OFFSET') == ...
netcdf.getConstant('64bit_offset'))
assert(isa(netcdf.getConstant('fill_byte'),'int8'))
assert(isa(netcdf.getConstant('fill_ubyte'),'uint8'))
assert(isa(netcdf.getConstant('fill_float'),'single'))
failed = 0;
try
% should trow exception
netcdf.getConstant('not_found')
% should never be reached
failed = 1;
catch
end
assert(~failed);
netcdf-1.0.14/inst/private/test_netcdf_create.m 0000644 0000000 0000000 00000001611 13741574474 017677 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function test_netcdf_create
import_netcdf
fname = [tempname '-octave-netcdf.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
assert(strcmp(netcdf.inqFormat(ncid),'FORMAT_CLASSIC'));
netcdf.close(ncid);
delete(fname);
netcdf-1.0.14/inst/private/test_netcdf_datatypes.m 0000644 0000000 0000000 00000002125 13741574474 020433 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function test_netcdf_datatypes()
test_netcdf_type('byte','int8');
test_netcdf_type('ubyte','uint8');
test_netcdf_type('short','int16');
test_netcdf_type('ushort','uint16');
test_netcdf_type('int','int32');
test_netcdf_type('uint','uint32');
test_netcdf_type('int64','int64');
test_netcdf_type('uint64','uint64');
test_netcdf_type('double','double');
test_netcdf_type('float','single');
test_netcdf_type('char','char');
netcdf-1.0.14/inst/private/test_netcdf_high_level_interface.m 0000644 0000000 0000000 00000007156 13741574474 022574 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
import_netcdf
fname = [tempname '-octave-netcdf.nc'];
nccreate(fname,'temp','Dimensions',{'lon',10,'lat',20});
nccreate(fname,'salt','Dimensions',{'lon',10,'lat',20});
nccreate(fname,'u','Dimensions',{'lon','lat'});
u = randn(10,20);
ncwrite(fname,'u',u);
% for octave prior to 3.8.0
if isempty(which('isequaln'))
isequaln = @(x,y) isequalwithequalnans(x,y);
end
u2 = ncread(fname,'u');
assert(isequaln(u,u2));
u2 = ncread(fname,'u',[10 5],[inf inf],[1 1]);
assert(isequaln(u(10:end,5:end),u2));
ncwriteatt(fname,'temp','units','degree Celsius');
assert(strcmp(ncreadatt(fname,'temp','units'),'degree Celsius'));
ncwriteatt(fname,'temp','range',[0 10]);
assert(isequal(ncreadatt(fname,'temp','range'),[0 10]));
ncwriteatt(fname,'temp','float_range',single([0 10]));
assert(isequal(ncreadatt(fname,'temp','float_range'),[0 10]));
ncwriteatt(fname,'temp','int_range',int32([0 10]));
assert(isequal(ncreadatt(fname,'temp','int_range'),[0 10]));
info = ncinfo(fname);
assert(length(info.Variables) == 3)
assert(strcmp(info.Variables(1).Name,'temp'));
assert(isequal(info.Variables(1).Size,[10 20]));
delete(fname);
nccreate(fname,'temp','Dimensions',{'lon',10,'lat',20},'Format','64bit');
delete(fname);
nccreate(fname,'temp','Dimensions',{'lon',10,'lat',20},'Format','classic');
info = ncinfo(fname);
assert(strcmp(info.Format,'classic'));
delete(fname);
% netcdf4
nccreate(fname,'temp','Dimensions',{'lon',10,'lat',20},'Format','netcdf4');
ncwriteatt(fname,'temp','uint_range',uint32([0 10]));
assert(isequal(ncreadatt(fname,'temp','uint_range'),[0 10]));
info = ncinfo(fname);
assert(strcmp(info.Format,'netcdf4'));
delete(fname)
% scalar variable
nccreate(fname,'temp','Format','netcdf4','Datatype','double');
ncwrite(fname,'temp',123);
assert(ncread(fname,'temp') == 123)
delete(fname)
% test unlimited dimension with nccreate
fname = [tempname '-octave-netcdf.nc'];
nccreate(fname,'temp','Dimensions',{'lon',10,'lat',inf});
%system(['ncdump -h ' fname])
info = ncinfo(fname);
assert(~info.Dimensions(1).Unlimited)
assert(info.Dimensions(2).Unlimited)
delete(fname)
% test double with _FillValue
fname = [tempname '-octave-netcdf.nc'];
fv = 99999.;
nccreate(fname,'flag','Dimensions',{'lon',10,'lat',10},'Datatype','double',...
'FillValue',fv);
%system(['ncdump -h ' fname])
data = zeros(10,10);
data(1,2) = fv;
ncid = netcdf.open(fname,'NC_WRITE');
varid = netcdf.inqVarID(ncid, 'flag');
netcdf.putVar(ncid,varid,data);
netcdf.close(ncid)
data2 = ncread(fname,'flag');
data(data == fv) = NaN;
assert(isequaln(data,data2))
delete(fname)
% test char with _FillValue
fname = [tempname '-octave-netcdf.nc'];
fv = '*';
nccreate(fname,'flag','Dimensions',{'lon',10,'lat',10},'Datatype','char',...
'FillValue',fv);
data = repmat('.',[10 10]);
data(1,2) = fv;
ncid = netcdf.open(fname,'NC_WRITE');
varid = netcdf.inqVarID(ncid, 'flag');
netcdf.putVar(ncid,varid,data);
netcdf.close(ncid)
data2 = ncread(fname,'flag');
assert(isequal(data,data2))
delete(fname)
netcdf-1.0.14/inst/private/test_netcdf_low_level_interface.m 0000644 0000000 0000000 00000011750 13741574474 022451 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function test_netcdf_low_level_interface
import_netcdf
% 2 dimensions
fname = [tempname '-octave-netcdf.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
assert(strcmp(netcdf.inqFormat(ncid),'FORMAT_CLASSIC'));
n = 10;
m = 5;
dimid_lon = netcdf.defDim(ncid,'lon',m);
dimid = netcdf.defDim(ncid,'time',n);
varidd = netcdf.defVar(ncid,'double_var','double',[dimid_lon,dimid]);
varid = netcdf.defVar(ncid,'byte_var','byte',[dimid]);
varidf = netcdf.defVar(ncid,'float_var','float',[dimid]);
varidi = netcdf.defVar(ncid,'int_var','int',[dimid]);
varids = netcdf.defVar(ncid,'short_var','short',[dimid]);
assert(varidd == netcdf.inqVarID(ncid,'double_var'))
[numdims, numvars, numglobalatts, unlimdimID] = netcdf.inq(ncid);
assert(numvars == 5)
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid,varidd);
assert(strcmp(varname,'double_var'));
[dimname,len] = netcdf.inqDim(ncid,dimid);
assert(len == n);
assert(strcmp(dimname,'time'));
types = {'double','float','byte','short','int'};
for i=1:length(types)
vid{i} = netcdf.defVar(ncid,[types{i} '_variable'],types{i},[dimid_lon,dimid]);
end
netcdf.endDef(ncid)
z = randn(m,n);
netcdf.putVar(ncid,varidd,z);
varf = randn(n,1);
netcdf.putVar(ncid,varidf,varf);
vari = floor(randn(n,1));
netcdf.putVar(ncid,varidi,vari);
netcdf.putVar(ncid,varids,[1:n])
z2 = netcdf.getVar(ncid,varidd);
assert(all(all(abs(z2 - z) < 1e-5)))
z2 = netcdf.getVar(ncid,varidd,[0 0]);
assert(z2 == z(1,1))
z2 = netcdf.getVar(ncid,varidd,[2 2],[3 5]);
assert(isequal(z2,z(3:5,3:7)))
z2 = netcdf.getVar(ncid,varidd,[2 2],[3 4],[1 2]);
assert(isequal(z2,z(3:5,3:2:9)))
netcdf.putVar(ncid,varidd,[0 0],123.);
z(1,1) = 123;
z2 = netcdf.getVar(ncid,varidd);
assert(isequal(z,z2))
netcdf.putVar(ncid,varidd,[2 2],[3 3],ones(3,3));
z(3:5,3:5) = 1;
z2 = netcdf.getVar(ncid,varidd);
assert(isequal(z,z2))
netcdf.putVar(ncid,varidd,[0 0],[3 5],[2 2],zeros(3,5));
z(1:2:5,1:2:9) = 0;
z2 = netcdf.getVar(ncid,varidd);
assert(isequal(z,z2))
z2 = netcdf.getVar(ncid,varidf);
assert(all(z2 - varf < 1e-5))
vari2 = netcdf.getVar(ncid,varidi);
assert(all(vari2 == vari))
netcdf.close(ncid);
delete(fname);
% test with different dimensions
for i = 1:5
nc_test_ndims(i);
end
function nc_test_ndims(ndims)
import_netcdf
fname = [tempname '-octave-netcdf.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
sz = ones(1,ndims);
dimids = ones(1,ndims);
for i = 1:ndims
sz(i) = 10+i;
dimids(i) = netcdf.defDim(ncid,sprintf('dim%g',i),sz(i));
end
varid = netcdf.defVar(ncid,'double_var','double',dimids);
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid,varid);
assert(strcmp(varname,'double_var'));
for i = 1:ndims
[dimname,len] = netcdf.inqDim(ncid,dimids(i));
assert(len == sz(i));
assert(strcmp(dimname,sprintf('dim%g',i)));
end
netcdf.endDef(ncid)
if ndims == 1
z = randn(sz,1);
else
z = randn(sz);
end
netcdf.putVar(ncid,varid,z);
z2 = netcdf.getVar(ncid,varid);
assert(isequal(z,z2))
z2 = netcdf.getVar(ncid,varid,zeros(ndims,1));
assert(z2 == z(1))
start = 2 * ones(1,ndims);
count = 5 * ones(1,ndims);
z2 = netcdf.getVar(ncid,varid,start,count);
idx = scs(start,count);
assert(isequal(z2,z(idx{:})))
start = 2 * ones(1,ndims);
count = 5 * ones(1,ndims);
stride = 2 * ones(1,ndims);
z2 = netcdf.getVar(ncid,varid,start,count,stride);
idx = scs(start,count,stride);
assert(isequal(z2,z(idx{:})))
% put with start
start = zeros(1,ndims);
netcdf.putVar(ncid,varid,start,123.);
z(1) = 123;
z2 = netcdf.getVar(ncid,varid);
assert(isequal(z,z2))
% put with start and count
start = 2 * ones(1,ndims);
count = 5 * ones(1,ndims);
if ndims == 1
data = ones(count,1);
else
data = ones(count);
end
netcdf.putVar(ncid,varid,start,count,data);
idx = scs(start,count);
z(idx{:}) = 1;
z2 = netcdf.getVar(ncid,varid);
assert(isequal(z,z2))
% put with start, count and stride
start = 2 * ones(1,ndims);
count = 5 * ones(1,ndims);
stride = 2 * ones(1,ndims);
if ndims == 1
data = zeros(count,1);
else
data = zeros(count);
end
netcdf.putVar(ncid,varid,start,count,stride,data);
idx = scs(start,count,stride);
z(idx{:}) = 0;
z2 = netcdf.getVar(ncid,varid);
assert(isequal(z,z2))
netcdf.close(ncid);
delete(fname);
function idx = scs(start,count,stride)
idx = cell(length(start),1);
if nargin == 2
stride = ones(length(start),1);
end
for i = 1:length(start)
idx{i} = start(i) + 1 + stride(i) * [0:count(i)-1];
end
netcdf-1.0.14/inst/private/test_netcdf_ncwriteschema.m 0000644 0000000 0000000 00000002550 13741574474 021273 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
fname = [tempname '-octave-netcdf-scheme-unlim.nc'];
clear s
s.Name = '/';
s.Format = 'classic';
s.Dimensions(1).Name = 'lon';
s.Dimensions(1).Length = 20;
s.Dimensions(2).Name = 'lat';
s.Dimensions(2).Length = 10;
s.Attributes(1).Name = 'institution';
s.Attributes(1).Value = 'GHER, ULg';
s.Variables(1).Name = 'temp';
s.Variables(1).Dimensions = s.Dimensions;
s.Variables(1).Datatype = 'double';
s.Variables(1).Attributes(1).Name = 'long_name';
s.Variables(1).Attributes(1).Value = 'temperature';
ncwriteschema(fname,s);
info = ncinfo(fname);
assert(strcmp(info.Attributes(1).Name,s.Attributes(1).Name))
assert(strcmp(info.Attributes(1).Value,s.Attributes(1).Value))
delete(fname);
netcdf-1.0.14/inst/private/test_netcdf_ncwriteschema_chunking.m 0000644 0000000 0000000 00000002721 13741574474 023161 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
fname = [tempname '-octave-netcdf-scheme-chunk.nc'];
clear s
s.Name = '/';
s.Format = 'netcdf4';
s.Dimensions(1).Name = 'lon';
s.Dimensions(1).Length = 20;
s.Dimensions(2).Name = 'lat';
s.Dimensions(2).Length = 10;
s.Attributes(1).Name = 'institution';
s.Attributes(1).Value = 'GHER, ULg';
s.Variables(1).Name = 'temp';
s.Variables(1).Dimensions = s.Dimensions;
s.Variables(1).Datatype = 'double';
s.Variables(1).Attributes(1).Name = 'long_name';
s.Variables(1).Attributes(1).Value = 'temperature';
s.Variables(1).ChunkSize = [2 3];
ncwriteschema(fname,s);
info = ncinfo(fname);
assert(strcmp(info.Attributes(1).Name,s.Attributes(1).Name))
assert(strcmp(info.Attributes(1).Value,s.Attributes(1).Value))
assert(isequal(info.Variables(1).ChunkSize,s.Variables(1).ChunkSize));
delete(fname);
netcdf-1.0.14/inst/private/test_netcdf_ncwriteschema_group.m 0000644 0000000 0000000 00000004437 13741574474 022515 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
fname = [tempname '-octave-netcdf-scheme-group.nc'];
clear s
s.Name = '/';
s.Format = 'netcdf4';
s.Dimensions(1).Name = 'lon';
s.Dimensions(1).Length = 20;
s.Dimensions(2).Name = 'lat';
s.Dimensions(2).Length = 10;
s.Attributes(1).Name = 'institution';
s.Attributes(1).Value = 'GHER, ULg';
s.Variables(1).Name = 'temp_diff';
s.Variables(1).Dimensions = s.Dimensions;
s.Variables(1).Datatype = 'double';
s.Variables(1).Attributes(1).Name = 'long_name';
s.Variables(1).Attributes(1).Value = 'temperature';
s.Groups(1).Name = 'forecast';
s.Groups(1).Variables(1).Name = 'temp';
s.Groups(1).Variables(1).Dimensions = s.Dimensions;
s.Groups(1).Variables(1).Datatype = 'double';
s.Groups(1).Variables(1).Attributes(1).Name = 'long_name';
s.Groups(1).Variables(1).Attributes(1).Value = 'temperature';
s.Groups(1).Attributes(1).Name = 'institution';
s.Groups(1).Attributes(1).Value = 'ULg';
s.Groups(2) = s.Groups(1);
s.Groups(2).Name = 'analysis';
ncwriteschema(fname,s);
%system(['ncdump -h ' fname])
info = ncinfo(fname);
assert(strcmp(info.Attributes(1).Name,s.Attributes(1).Name))
assert(strcmp(info.Attributes(1).Value,s.Attributes(1).Value))
assert(strcmp(s.Groups(1).Name,info.Groups(1).Name))
z = randn(20,10);
ncwrite(fname,'/forecast/temp',z);
z2 = ncread(fname,'/forecast/temp');
assert(isequal(z,z2))
ginfo = ncinfo(fname,'forecast');
assert(strcmp(ginfo.Name,'forecast'));
% read global attribute of root group
val = ncreadatt(fname,'/','institution');
assert(strcmp(val,'GHER, ULg'));
% read global attribute of group forecast
val = ncreadatt(fname,'/forecast','institution');
assert(strcmp(val,'ULg'));
delete(fname);
netcdf-1.0.14/inst/private/test_netcdf_ncwriteschema_unlim.m 0000644 0000000 0000000 00000002760 13741574474 022502 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
fname = [tempname '-octave-netcdf-scheme-unlim.nc'];
clear s
s.Name = '/';
s.Format = 'classic';
s.Dimensions(1).Name = 'lon';
s.Dimensions(1).Length = 20;
s.Dimensions(2).Name = 'lat';
s.Dimensions(2).Length = 10;
s.Dimensions(3).Name = 'time';
s.Dimensions(3).Length = Inf;
%s.Dimensions(3).Unlimited = true;
s.Attributes(1).Name = 'institution';
s.Attributes(1).Value = 'GHER, ULg';
s.Variables(1).Name = 'temp';
s.Variables(1).Dimensions = s.Dimensions;
s.Variables(1).Datatype = 'double';
s.Variables(1).Attributes(1).Name = 'long_name';
s.Variables(1).Attributes(1).Value = 'temperature';
ncwriteschema(fname,s);
info = ncinfo(fname);
assert(strcmp(info.Attributes(1).Name,s.Attributes(1).Name))
assert(strcmp(info.Attributes(1).Value,s.Attributes(1).Value))
assert(info.Dimensions(3).Unlimited);
delete(fname);
netcdf-1.0.14/inst/private/test_netcdf_scalar_variable.m 0000644 0000000 0000000 00000001633 13741574474 021552 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function test_netcdf_scalar_variable()
import_netcdf
fname = [tempname '-octave-netcdf.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
varidd_scalar = netcdf.defVar(ncid,'double_scalar','double',[]);
netcdf.close(ncid);
delete(fname);
netcdf-1.0.14/inst/private/test_netcdf_type.m 0000644 0000000 0000000 00000004164 13741574474 017423 0 ustar 00 0000000 0000000 function test_netcdf_type(nctype,octtype)
import_netcdf
m = 5;
n = 10;
fname = [tempname '-octave-netcdf- ' nctype '.nc'];
mode = bitor(netcdf.getConstant('NC_CLOBBER'),...
netcdf.getConstant('NC_NETCDF4'));
ncid = netcdf.create(fname,mode);
dimids = [netcdf.defDim(ncid,'lon',m) ...
netcdf.defDim(ncid,'time',n)];
varid = netcdf.defVar(ncid,'variable',nctype,dimids);
netcdf.endDef(ncid)
if strcmp(octtype,'char')
z = char(floor(26*rand(m,n)) + 65);
testvals = 'a';
testvalv = 'this is a name';
else
z = zeros(m,n,octtype);
z(:) = randn(m,n);
testvals = zeros(1,1,octtype);
testvals(:) = rand(1,1);
testvalv = zeros(1,5,octtype);
testvalv(:) = rand(size(testvalv));
end
netcdf.putVar(ncid,varid,z);
z2 = netcdf.getVar(ncid,varid);
assert(isequal(z,z2))
netcdf.putAtt(ncid,varid,'scalar_attribute',testvals);
val = netcdf.getAtt(ncid,varid,'scalar_attribute');
assert(isequal(val,testvals));
assert(strcmp(class(val),octtype))
[xtype,len] = netcdf.inqAtt(ncid,varid,'scalar_attribute');
assert(xtype == netcdf.getConstant(nctype))
assert(len == numel(testvals));
netcdf.putAtt(ncid,varid,'vector_attribute',testvalv);
val = netcdf.getAtt(ncid,varid,'vector_attribute');
assert(isequal(val,testvalv));
assert(strcmp(class(val),octtype))
[xtype,len] = netcdf.inqAtt(ncid,varid,'vector_attribute');
assert(xtype == netcdf.getConstant(nctype))
assert(len == numel(testvalv));
netcdf.close(ncid);
delete(fname);
%% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
netcdf-1.0.14/inst/private/test_netcdf_unlim.m 0000644 0000000 0000000 00000000546 13741574474 017566 0 ustar 00 0000000 0000000
import_netcdf
% 2 dimensions
fname = [tempname '-octave-netcdf.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
dimid = netcdf.defDim(ncid,'time',0);
varidd = netcdf.defVar(ncid,'time','double',[dimid]);
netcdf.close(ncid)
ncid = netcdf.open(fname,'NC_NOWRITE');
varid = netcdf.inqVarID(ncid, 'time');
x = netcdf.getVar(ncid,varid);
netcdf.close(ncid)
netcdf-1.0.14/inst/private/test_scalar_variable.m 0000644 0000000 0000000 00000001624 13741574474 020227 0 ustar 00 0000000 0000000 %% Copyright (C) 2013 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
function test_scalar_variable()
import_netcdf
fname = [tempname '-octave-netcdf.nc'];
ncid = netcdf.create(fname,'NC_CLOBBER');
varidd_scalar = netcdf.defVar(ncid,'double_scalar','double',[]);
netcdf.close(ncid);
delete(fname);
netcdf-1.0.14/inst/test_netcdf.m 0000644 0000000 0000000 00000003304 13741574474 014703 0 ustar 00 0000000 0000000 % test_netcdf
% Test the netcdf interface
function test_netcdf()
import_netcdf
tests = {'test_netcdf_constant',...
'test_netcdf_create'...
'test_netcdf_low_level_interface'...
'test_netcdf_unlim',...
'test_netcdf_datatypes',...
'test_netcdf_scalar_variable',...
'test_netcdf_attributes',...
'test_netcdf_high_level_interface',...
'test_netcdf_ncwriteschema',...
'test_netcdf_ncwriteschema_unlim',...
'test_netcdf_ncwriteschema_chunking',...
'test_netcdf_ncwriteschema_group',...
'bug_47014'...
};
maxlen = max(cellfun(@(s) length(s),tests));
libver = netcdf.inqLibVers();
fprintf('Using NetCDF library version "%s"\n',libver)
for iindex=1:length(tests);
dots = repmat('.',1,maxlen - length(tests{iindex}));
fprintf('run %s%s ',tests{iindex},dots);
try
eval(tests{iindex});
disp(' OK ');
catch
disp(' FAIL ');
disp(lasterr)
end
end
%% Copyright (C) 2013-2019 Alexander Barth
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; If not, see .
%!test
%! fprintf ("\n");
%! test_netcdf ();
netcdf-1.0.14/octave-netcdf.metainfo.xml 0000644 0000000 0000000 00000002025 13741574474 016312 0 ustar 00 0000000 0000000
octave-netcdfwww.octave.org-octave.desktopNetCDF ToolkitOctave NetCDF toolkit
Toolkit for Network Common Form (NetCDF) File I/O.
NetCDFscientifichttp://octave.sourceforge.net/netcdfhttps://savannah.gnu.org/bugs/?func=additem&group=octaveGPL-3.0+Octave-Forge Communityoctave-maintainers@gnu.orgFSFAP
netcdf-1.0.14/src/ 0000755 0000000 0000000 00000000000 13741574474 012035 5 ustar 00 0000000 0000000 netcdf-1.0.14/src/Makefile.in 0000644 0000000 0000000 00000001627 13741574474 014110 0 ustar 00 0000000 0000000
SHELL = @SHELL@
AWK = @AWK@
AWK ?= awk
MKOCTFILE = @MKOCTFILE@ -v
NC_CONFIG = @NC_CONFIG@
%.oct: %.cc ; $(MKOCTFILE) $<
NCHEADER=$(shell $(NC_CONFIG) --includedir)/netcdf.h
NETCDF_CPPFLAGS=@NETCDF_CPPFLAGS@
NETCDF_LIBS=@NETCDF_LIBS@
SRC = __netcdf__.cc
all: __netcdf__.oct ../PKG_ADD
netcdf_constants.h:
$(info generating netcdf_constants.h)
@if [ -f $(NCHEADER) ]; then \
$(AWK) -f netcdf_constants.awk $(NCHEADER) > netcdf_constants.h; \
elif [ -f /usr/include/netcdf.h ]; then \
$(AWK) -f netcdf_constants.awk /usr/include/netcdf.h > netcdf_constants.h; \
else \
echo >&2 "Couldnt find netcdf.h"; \
false; \
fi;
clean:
rm -f __netcdf__.o __netcdf__.oct netcdf_constants.h
real-clean: clean
rm -f ../PKG_ADD ../inst/import_netcdf.m ../PKG_DEL
__netcdf__.oct: $(SRC) netcdf_constants.h
$(MKOCTFILE) $(NETCDF_CPPFLAGS) $(SRC) $(NETCDF_LIBS)
../PKG_ADD: $(SRC)
$(shell sh ./PKG_ADD.sh)
netcdf-1.0.14/src/PKG_ADD.sh 0000644 0000000 0000000 00000002776 13741574474 013476 0 ustar 00 0000000 0000000 #!/bin/sh
# Copyright (C) 2013 Alexander Barth
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see .
if [ "x$AWK" = "x" ]; then
AWK=awk
fi
netcdf_functions=$($AWK -F'[(,]' '/DEFUN_DLD/ { print $2 } ' __netcdf__.cc)
outfile=../PKG_ADD
outfile_del=../PKG_DEL
importfile=../inst/import_netcdf.m
rm -f $outfile $outfile_del $importfile
echo '% File automatically generated by PKG_ADD.sh' > $importfile
echo '% File automatically generated by PKG_ADD.sh' > $outfile
for i in $netcdf_functions; do
#echo ${i#netcdf_}
cat >> $outfile <> $importfile < $outfile_del
for i in $netcdf_functions; do
#echo ${i#netcdf_}
cat >> $outfile_del <