ncarray-1.0.5/ 0000755 0000000 0000000 00000000000 14310066641 011343 5 ustar 00 0000000 0000000 ncarray-1.0.5/COPYING 0000644 0000000 0000000 00000104513 14310066641 012402 0 ustar 00 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 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 GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. 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
them 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 prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. 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.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey 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;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If 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 convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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 that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
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.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
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.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
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
state 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 3 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 does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program 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, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU 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 Lesser General
Public License instead of this License. But first, please read
.
ncarray-1.0.5/DESCRIPTION 0000644 0000000 0000000 00000000627 14310066641 013056 0 ustar 00 0000000 0000000 Name: ncarray
Version: 1.0.5
Date: 2022-09-13
Author: Alexander Barth
Maintainer: John Donoghue
Title: ncarray
Description: Access a single or a collection of NetCDF files as a multi-dimensional array
Categories: IO
Depends: octave (>= 3.4.0), netcdf (>= 1.0.2), statistics (>= 1.0.6)
License: GPLv3+
Url: https://octave.sourceforge.io/ncarray/index.html
ncarray-1.0.5/INDEX 0000644 0000000 0000000 00000000766 14310066641 012146 0 ustar 00 0000000 0000000 ncarray >> ncArray
ncArray
ncArray
ncCatArray
nccoord
nctimeunits
ncreadtime
cached_decompress
@ncArray/coord
@ncArray/subsasgn
@ncArray/subsref
ncBaseArray
@BaseArray/BaseArray
@BaseArray/end
@BaseArray/full
@BaseArray/isnumeric
@BaseArray/max
@BaseArray/mean
@BaseArray/min
@BaseArray/moment
@BaseArray/numel
@BaseArray/prod
@BaseArray/reduce
@BaseArray/size
@BaseArray/std
@BaseArray/sum
@BaseArray/sumsq
@BaseArray/var
Test script
test_ncarray
ncarray-1.0.5/Makefile 0000644 0000000 0000000 00000022547 14310066641 013015 0 ustar 00 0000000 0000000 ## Copyright 2015-2016 Carnë Draug
## Copyright 2015-2016 Oliver Heimlich
## Copyright 2017 Julien Bect
## Copyright 2017 Olaf Till
## Copyright 2019 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.
## 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
## Detect which VCS is used
vcs := $(if $(wildcard .hg),hg,$(if $(wildcard .git),git,unknown))
ifeq ($(vcs),hg)
release_dir_dep := .hg/dirstate
HG := hg
HG_CMD = $(HG) --config alias.$(1)=$(1) --config defaults.$(1)= $(1)
HG_ID := $(shell $(call HG_CMD,identify) --id | sed -e 's/+//' )
REPO_TIMESTAMP := $(firstword $(shell $(call HG_CMD,log) --rev $(HG_ID) --template '{date|hgdate}'))
endif
ifeq ($(vcs),git)
release_dir_dep := .git/index
GIT := git
REPO_TIMESTAMP := $(firstword $(shell $(GIT) log -n1 --date=unix --format="%ad"))
endif
TAR_REPRODUCIBLE_OPTIONS := --sort=name --mtime="@$(REPO_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/bootstrap))
cd "$@/src" && ./bootstrap && $(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");' \
## --eval 'options.package_doc = "$(package).texi";'
html_options = --eval 'options = get_html_options ("octave-forge");'
$(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
rungui: $(install_stamp)
$(run_in_place) --persist --gui
## 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 (ls inst; ls src | $(GREP) .oct) | $(CUT) -f2 -d@ | $(CUT) -f1 -d.)';" \
--eval "targets = strsplit (targets, ' '); doctest (targets);"
## Test package.
octave_test_commands = \
' pkgs = pkg("list", "$(package)"); \
cd ("$(target_dir)/"); \
dirs = {sprintf(".installation/%s-%s", pkgs{1}.name, pkgs{1}.version)}; \
__run_test_suite__ (dirs, {}); '
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-check:
@echo "## Removing fntests.log..."
-$(RM) $(target_dir)/fntests.log
@echo
##
## CLEAN
##
.PHONY: clean
clean: clean-tarballs clean-unpacked-release clean-install clean-check
@echo "## Removing target directory (if empty)..."
-if [ -d $(target_dir) ]; then rmdir $(target_dir); fi
@echo
@echo "## Cleaning done"
@echo
ncarray-1.0.5/NEWS 0000644 0000000 0000000 00000003436 14310066641 012050 0 ustar 00 0000000 0000000 Summary of important user-visible changes for ncarray 1.0.5:
------------------------------------------------------------
** minor updates for octave compatability
** update function docs for texinfo
** change license from gplv2+ to gplv3+
Summary of important user-visible changes for ncarray 1.0.4:
------------------------------------------------------------
** Avoid obsolete strmatch function
** Use a tolerance in test script (bug #49391)
Summary of important user-visible changes for ncarray 1.0.3:
------------------------------------------------------------
** use lower-case package name as upper-case latters in the package name can
cause troubles wiht pkg.
** new functions nctimeunits and ncreadtime for handling time variables.
Summary of important user-visible changes for ncArray 1.0.2:
------------------------------------------------------------
** new function: nansum, nanvar, nanstd: mean, variance, standard deviation
ignoring NaNs
** ncarray nows depends on package netcdf (instead of octcdf)
** Add missing dependency to statistics
** Avoid obsolete isequalwithequalnans functions
Summary of important user-visible changes for ncArray 1.0.1:
------------------------------------------------------------
** new function: nanmean: mean ignoring NaNs
** new function: load: load data based on a coordinate range or a single
value (only 1-dimensional coordinates are currently supported)
** CACHED_DECOMPRESS_DIR defaults now to a directory inside the system temporary
directory (/tmp on Linux)
** add support for xz compression
** optimization of assignement operator
** add units and standard_name in nccoord
Summary of important user-visible changes for ncArray 1.0.0:
------------------------------------------------------------
** Initial release
ncarray-1.0.5/inst/ 0000755 0000000 0000000 00000000000 14310066641 012320 5 ustar 00 0000000 0000000 ncarray-1.0.5/inst/@BaseArray/ 0000755 0000000 0000000 00000000000 14310066641 014271 5 ustar 00 0000000 0000000 ncarray-1.0.5/inst/@BaseArray/BaseArray.m 0000644 0000000 0000000 00000002376 14310066641 016330 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{BA} =} BaseArray(@var{SZ})
## Create a BaseArray of size SZ. BaseArray is an abstract class.
##
## Derived classes should implement the methods subsref and subsasgn.
## BaseArray implements several reduction methods such as sum, prod and mean.
##
## @subsubheading Inputs
## @var{SZ} - size of the array.
## SZ should have least two elements.
## @subsubheading Outputs
## @var{BA} - a BaseArray object
## @end deftypefn
function retval = BaseArray(sz)
self.sz = sz;
retval = class(self,'BaseArray');
endfunction
ncarray-1.0.5/inst/@BaseArray/end.m 0000644 0000000 0000000 00000001611 14310066641 015214 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{e} =} end(@var{A}, @var{k})
## Return last index along a dimension.
## @end deftypefn
function e = end(self,k,n)
e = size(self,k);
endfunction
ncarray-1.0.5/inst/@BaseArray/full.m 0000644 0000000 0000000 00000001717 14310066641 015417 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{F} =} full(@var{A})
## Make full (dense) array.
## @end deftypefn
function F = full(self);
n = length(self.sz);
idx.type = '()';
for i=1:n
idx.subs{i} = ':';
endfor
F = subsref(self,idx);
endfunction
ncarray-1.0.5/inst/@BaseArray/isnumeric.m 0000644 0000000 0000000 00000001571 14310066641 016451 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{isn} =} isnumeric(@var{A})
## Test if array is numeric.
## @end deftypefn
function isn = isnumeric(self)
isn = true;
endfunction
ncarray-1.0.5/inst/@BaseArray/length.m 0000644 0000000 0000000 00000001616 14310066641 015734 0 ustar 00 0000000 0000000 % len = length(A)
% Return the "length" of the object A. For matrix objects, the
% length is the number of rows or columns, whichever is greater.
function len = length(self)
len = max(size(self));
% 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 3 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 .
ncarray-1.0.5/inst/@BaseArray/max.m 0000644 0000000 0000000 00000001761 14310066641 015241 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{s} =} max(@var{A}, [], @var{dim})
## Compute the maximum along dimension DIM.
## @end deftypefn
function s = max(self,B,varargin)
assert(isempty(B))
funred = @max;
funelem = @(x) x;
s = reduce(self,funred,funelem,varargin{:});
endfunction
ncarray-1.0.5/inst/@BaseArray/mean.m 0000644 0000000 0000000 00000002020 14310066641 015361 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{s} =} end(@var{A}, @var{dim})
## Compute the mean along dimension DIM.
## @end deftypefn
function s = mean(self,varargin)
funred = @plus;
funelem = @(x) x;
[s,n] = reduce(self,funred,funelem,varargin{:});
if isempty(s)
s = 0;
else
s = s/n;
endif
endfunction
ncarray-1.0.5/inst/@BaseArray/min.m 0000644 0000000 0000000 00000001761 14310066641 015237 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{s} =} end(@var{A}, [], @var{dim})
## Compute the minimum along dimension DIM.
## @end deftypefn
function s = min(self,B,varargin)
assert(isempty(B))
funred = @min;
funelem = @(x) x;
s = reduce(self,funred,funelem,varargin{:});
endfunction
ncarray-1.0.5/inst/@BaseArray/moment.m 0000644 0000000 0000000 00000002161 14310066641 015746 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{s} =} moment(@var{A}, @var{order}, @var{dim})
## Compute the central moment of the given order along dimension DIM.
## @end deftypefn
function s = moment(self,order,varargin)
m = mean(self,varargin{:});
funred = @plus;
funelem = @(x) (x-m).^order;
[s,n] = reduce(self,funred,funelem,varargin{:});
if isempty(s)
s = NaN;
else
s = s/n;
endif
endfunction
ncarray-1.0.5/inst/@BaseArray/nanmean.m 0000644 0000000 0000000 00000002672 14310066641 016073 0 ustar 00 0000000 0000000 % Compute the mean (ignoring NaNs).
% s = mean (X, DIM)
% Compute the mean along dimension DIM.
function [s,total,count] = nanmean(self,varargin)
% s will be a cell element containing
% {the sum, the count of elements different from NaN}
% this is necessary to avoid 2 calls to reduce
[s,n] = reduce(self,...
@(x,y) funred(x,y),...
@(x) funelem(x),...
varargin{:});
if isempty(s)
s = 0;
else
total = s{1};
count = s{2};
s = NaN*zeros(size(total));
nonz = count ~= 0;
s(nonz) = total(nonz) ./ count(nonz);
end
end
function x = funelem(x)
% make sure x is not an ncArray
x = full(x);
m = isnan(x);
x(m) = 0;
x = {x,~m};
end
function s = funred(x,y)
s = {x{1} + y{1}, x{2} + y{2}} ;
end
% 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 3 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 .
ncarray-1.0.5/inst/@BaseArray/nanstd.m 0000644 0000000 0000000 00000001770 14310066641 015743 0 ustar 00 0000000 0000000 % Compute the standard deviation (ignoring NaNs).
% S = nanstd (X, OPT, DIM)
% Compute the standard deviation along dimension DIM. NaNs are treated as absent
% values.
% If OPT is equal to 1, then the standard deviation is bias-corrected.
function s = nanstd(self,varargin)
s = sqrt(nanvar(self,varargin{:}));
% 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 3 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 .
ncarray-1.0.5/inst/@BaseArray/nansum.m 0000644 0000000 0000000 00000002644 14310066641 015756 0 ustar 00 0000000 0000000 % Compute the sum (ignoring NaNs).
% [s,count] = sum (X, DIM)
% Compute the sum along dimension DIM.
% The variable s is the sum and count the number of values summed.
function [total,count] = nansum(self,varargin)
% s will be a cell element containing
% {the sum, the count of elements different from NaN}
% this is necessary to avoid 2 calls to reduce
[s,n] = reduce(self,...
@(x,y) funred(x,y),...
@(x) funelem(x),...
varargin{:});
if isempty(s)
s = 0;
else
total = s{1};
count = s{2};
end
end
function x = funelem(x)
% make sure x is not an ncArray
x = full(x);
m = isnan(x);
x(m) = 0;
x = {x,~m};
end
function s = funred(x,y)
s = {x{1} + y{1}, x{2} + y{2}} ;
end
% 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 3 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 .
ncarray-1.0.5/inst/@BaseArray/nanvar.m 0000644 0000000 0000000 00000002733 14310066641 015741 0 ustar 00 0000000 0000000 % Compute the variance (ignoring NaNs).
% V = var (X, OPT, DIM)
% Compute the variance along dimension DIM.
% If OPT is equal to 1, then the variance is bias-corrected.
function s = nanvar(self,opt,varargin)
if nargin == 1
opt = 0;
elseif isempty(opt)
opt = 0;
end
nm = nanmean(self,varargin{:});
[s,n] = reduce(self,@funred, ...
@(x) funelem(x,nm),varargin{:});
if isempty(s)
s = 0;
else
total = s{1};
count = s{2};
if opt == 0
s = total./(count-1);
else
s = total./count;
end
end
end
function x = funelem(x,nm)
% make sure x is not an ncArray
x = full(x);
mask = isnan(x) | isnan(nm);
diff = zeros(size(x));
diff(mask) = x(mask) - nm(mask);
x = {diff.^2, ~mask};
end
function s = funred(x,y)
s = {x{1} + y{1}, x{2} + y{2}} ;
end
% 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 3 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 .
ncarray-1.0.5/inst/@BaseArray/numel.m 0000644 0000000 0000000 00000001573 14310066641 015575 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{n} =} numel(@var{A})
## Number of elements.
## @end deftypefn
function n = numel(self, varargin)
n = prod(self.sz);
endfunction
ncarray-1.0.5/inst/@BaseArray/prod.m 0000644 0000000 0000000 00000002016 14310066641 015412 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{P} =} prod(@var{A}, @var{dims})
## Compute the product of all elements along dimension DIM.
## @end deftypefn
function s = prod(self,varargin)
funred = @times;
funelem = @(x) x;
s = reduce(self,funred,funelem,varargin{:});
if isempty(s)
s = 1;
endif
endfunction
ncarray-1.0.5/inst/@BaseArray/reduce.m 0000644 0000000 0000000 00000003002 14310066641 015711 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {[@var{s}, @var{n}] =} reducce(@var{A}, @var{funred}, @var{funelem}, @var{dim})
## Reduce array using callback fundtions.
##
## Reduce array using the function FUNRED applied to all elements
## after the function FUNELEM was applied along dimension DIM.
## @end deftypefn
function [s,n] = reduce(self,funred,funelem,dim)
sz = size(self);
if nargin == 3
dim = find(sz ~= 1,1);
if isempty(dim)
dim = 1;
endif
endif
idx.type = '()';
nd = length(sz);
idx.subs = cell(1,nd);
for i=1:nd
idx.subs{i} = ':';
endfor
n = size(self,dim);
if n == 0
s = [];
else
idx.subs{dim} = 1;
s = funelem(subsref(self,idx));
for i=2:n
idx.subs{dim} = i;
s = funred(s,funelem(subsref(self,idx)));
endfor
endif
endfunction
ncarray-1.0.5/inst/@BaseArray/size.m 0000644 0000000 0000000 00000002001 14310066641 015412 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{isz} =} size(@var{A})
## Size of array
## @end deftypefn
function sz = size(self,dim)
sz = self.sz;
if length(sz) == 1
sz = [sz 1];
endif
if nargin == 2
if dim > length(sz)
sz = 1;
else
sz = sz(dim);
endif
endif
endfunction
ncarray-1.0.5/inst/@BaseArray/std.m 0000644 0000000 0000000 00000001645 14310066641 015247 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{s} =} std(@var{A}, @var{opt}, @var{dim})
## Compute the standard deviation.
## @end deftypefn
function s = std(self,varargin)
s = sqrt(var(self,varargin{:}));
endfunction
ncarray-1.0.5/inst/@BaseArray/sum.m 0000644 0000000 0000000 00000001761 14310066641 015260 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{s} =} sum(@var{A}, @var{dim})
## Compute sum along a dimension.
## @end deftypefn
function s = sum(self,varargin)
funred = @plus;
funelem = @(x) x;
s = reduce(self,funred,funelem,varargin{:});
if isempty(s)
s = 0;
endif
endfunction
ncarray-1.0.5/inst/@BaseArray/sumsq.m 0000644 0000000 0000000 00000002043 14310066641 015616 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{s} =} end(@var{A}, @var{dim})
## Compute the sum squared.
##
## Compute the sum squared along dimension DIM.
## @end deftypefn
function s = sumsq(self,varargin)
funred = @plus;
funelem = @(x) x.^2;
s = reduce(self,funred,funelem,varargin{:});
if isempty(s)
s = 1;
endif
endfunction
ncarray-1.0.5/inst/@BaseArray/var.m 0000644 0000000 0000000 00000002414 14310066641 015240 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{s} =} var(@var{A}, @var{opt}, @var{dim})
## Compute the variance along dimension DIM.
##
## If OPT is equal to 1, then the variance is bias-corrected.
## @end deftypefn
function s = var(self,opt,varargin)
if nargin == 1
opt = 0;
elseif isempty(opt)
opt = 0;
endif
m = mean(self,varargin{:});
funred = @plus;
funelem = @(x) (x-m).^2;
[s,n] = reduce(self,funred,funelem,varargin{:});
if isempty(s)
s = 0;
else
if opt == 0
s = s/(n-1);
else
s = s/n;
endif
endif
endfunction
ncarray-1.0.5/inst/@CatArray/ 0000755 0000000 0000000 00000000000 14310066641 014126 5 ustar 00 0000000 0000000 ncarray-1.0.5/inst/@CatArray/CatArray.m 0000644 0000000 0000000 00000004774 14310066641 016026 0 ustar 00 0000000 0000000 % C = CatArray(dim,{array1,array2,...})
%
% Create a concatenated array from a cell-list of arrays. Individual
% elements can be accessed by subscribs, e.g.:
% C(2,3)
function retval = CatArray(dim,arrays)
self.dim = dim;
self.arrays = arrays;
self.na = length(arrays);
% number of dimensions
self.nd = length(size(arrays{1}));
if dim > self.nd
self.nd = dim;
end
self.size = ones(self.na,self.nd);
self.start = ones(self.na,self.nd);
% get size of all arrays
for i=1:self.na
tmp = size(arrays{i});
self.size(i,1:length(tmp)) = tmp;
end
% check if dimensions are consistent
ncd = 1:self.nd ~= dim;
for i=2:self.na
if ~all(self.size(i,ncd) == self.size(1,ncd))
error('Array number %d has inconsistent dimension',i);
end
end
% start index of each sub-array
for i=2:self.na
self.start(i,:) = self.start(i-1,:);
self.start(i,dim) = self.start(i,dim) + self.size(i-1,dim);
end
self.end = self.start + self.size - 1;
self.sz = self.size(1,:);
self.sz(dim) = sum(self.size(:,dim));
self.overlap = false;
self.bounds = [0; cumsum(prod(self.size,2))];
retval = class(self,'CatArray',BaseArray(self.sz));
% Copyright (C) 2012 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 3 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 .
% Copyright (C) 2012 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 3 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 .
ncarray-1.0.5/inst/@CatArray/display.m 0000644 0000000 0000000 00000001407 14310066641 015753 0 ustar 00 0000000 0000000 function display(self)
for i=1:self.na
display(self.arrays{i})
end
% Copyright (C) 2012 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 3 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 .
ncarray-1.0.5/inst/@CatArray/idx_global_local_.m 0000644 0000000 0000000 00000004047 14310066641 017726 0 ustar 00 0000000 0000000 % private method
function [idx_global,idx_local,sz] = idx_global_local_(self,idx)
assert(strcmp(idx.type,'()'))
n = length(size(self));
% number of indices must be equal to dimension
assert(length(idx.subs) == n)
lb = ones(1,n); % lower bound
ub = ones(1,n); % upper bound
sz = ones(1,n); % size
% transform all colons to index range
for i=1:n
if strcmp(idx.subs{i},':')
idx.subs{i} = 1:self.sz(i);
end
lb(i) = min(idx.subs{i});
ub(i) = max(idx.subs{i});
sz(i) = length(idx.subs{i});
end
%sz = ub-lb+1;
idx_local = cell(1,self.na);
idx_global = cell(1,self.na);
% loop over all arrays
for j=1:self.na
idx_local{j} = idx;
idx_global{j} = idx;
% loop over all dimensions
for i=1:n
% rebase subscribt at self.start(j,i)
tmp = idx.subs{i} - self.start(j,i) + 1;
% only indeces within bounds of the j-th array
sel = 1 <= tmp & tmp <= self.size(j,i);
% index for getting the data from the local j-th array
idx_local{j}.subs{i} = tmp(sel);
% index for setting the data in the global B array
%idx_global{j}.subs{i} = idx.subs{i}(sel) - lb(i)+1;
if sum(sel) == 0
idx_global{j}.subs{i} = [];
else
idx_global{j}.subs{i} = (1:sum(sel)) + find(sel,1,'first') - 1;
end
end
end
% Copyright (C) 2012 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 3 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 .
ncarray-1.0.5/inst/@CatArray/subsasgn.m 0000644 0000000 0000000 00000001733 14310066641 016135 0 ustar 00 0000000 0000000 function self = subsasgn(self,idx,x)
[idx_global,idx_local,sz] = idx_global_local_(self,idx);
for j=1:self.na
% get subset from global array x
subset = subsref(x,idx_global{j});
% set subset in j-th array
subsasgn(self.arrays{j},idx_local{j},subset);
end
% Copyright (C) 2012 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 3 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 .
ncarray-1.0.5/inst/@CatArray/subsref.m 0000644 0000000 0000000 00000004653 14310066641 015765 0 ustar 00 0000000 0000000 function B = subsref(self,idx)
% handle case with a single subscript
% for example CA(234)
if strcmp(idx.type,'()') && length(idx.subs) == 1
% indices of elements in B
ind = idx.subs{1};
if strcmp(ind,':')
ind = [1:numel(self)]';
end
% output array
B = zeros(size(ind));
B(:) = NaN;
if self.overlap
% transform linear index ind to subscript subs
subs = cell(1,self.nd);
[subs{:}] = ind2sub(size(self),ind);
% make a nice array length(ind) by self.nd
subs = cell2mat(subs);
% get every element
idxe.type = '()';
idxe.subs = cell(1,self.nd);
for i=1:length(ind)
idxe.subs = mat2cell(subs(i,:),1,ones(1,self.nd));
B(i) = subsref_canonical(self,idxe);
end
else
% assume all arrays does not overlap
for j=1:self.na
sel = self.bounds(j) < ind & ind <= self.bounds(j+1);
B(sel) = self.arrays{j}(ind(sel) - self.bounds(j));
end
end
elseif strcmp(idx.type,'.')
% load attributes from first array
B = subsref(self.arrays{1},idx);
else
B = subsref_canonical(self,idx);
end
end
% for this function we assume that idx.subs has the same dimension than
% the array
function B = subsref_canonical(self,idx)
[idx_global,idx_local,sz] = idx_global_local_(self,idx);
B = zeros(sz);
B(:) = NaN;
for j=1:self.na
% get subset from j-th array
subset = subsref(self.arrays{j},idx_local{j});
% set subset in global array B
% this is slow, why?
%B = subsasgn(B,idx_global{j},subset);
% however this quite fast
idxa = idx_global{j}.subs;
B(idxa{:}) = subset;
end
end
% Copyright (C) 2012 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 3 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 .
ncarray-1.0.5/inst/@ncArray/ 0000755 0000000 0000000 00000000000 14310066641 014017 5 ustar 00 0000000 0000000 ncarray-1.0.5/inst/@ncArray/coord.m 0000644 0000000 0000000 00000002007 14310066641 015302 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{c} =} coord(@var{A})
## Get a array of structures with the coordinate of ncArray A.
## @subsubheading Inputs
## @var{A} - ncArray value
## @subsubheading Outputs
## @var{c} - array of coordinates
## @end deftypefn
function c = coord(self)
c = self.coord;
endfunction
ncarray-1.0.5/inst/@ncArray/dims.m 0000644 0000000 0000000 00000001602 14310066641 015130 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 3 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 {} {@var{c} =} dims(@var{A})
## Get cell-array of dimension names ncArray A.
## @end deftypefn
function c = dims(self)
c = self.dims;
endfunction
ncarray-1.0.5/inst/@ncArray/display.m 0000644 0000000 0000000 00000002351 14310066641 015643 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 3 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 {} {} display(@var{A})
## Display ncArray A
## @end deftypefn
function display(self)
sz = size(self);
tmp = sprintf('%dx',sz);
fprintf('Size: %s\n',tmp(1:end-1))
c = coord(self);
fprintf('Coordinates:\n')
for i = 1:length(c)
tmp = sprintf('%dx',size(c(i).val));
stdname = c(i).standard_name;
if isempty(stdname)
stdname = '';
endif
fprintf(' Name: %15s; standard name: %25s; size %10s\n',...
c(i).name,stdname,tmp(1:end-1));
endfor
endfunction
ncarray-1.0.5/inst/@ncArray/load.m 0000644 0000000 0000000 00000005455 14310066641 015125 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 3 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 {} {[@var{val}, @var{coord1}, @var{coord2} @dots{}] =} load(@var{A}, @var{coord_name1}, @var{range1}, @var{coord_name2}, @var{range2}, @dots{})
## Load a subset of a variable based on range of coordiante variables.
## The names of the coordinates (coord_name1, coord_name2,...) coorespond to the standard_name attribute.
## Only 1-dimensional coordinates are currently supported.
## Time units are converted to "datenum".
##
## @example
## [temp,lon,lat,depth,time] = load(self,'longitude',[0 10],'latitude',[0 10])
## @end example
## @end deftypefn
function varargout = load(self,varargin)
c = coord(self);
for i = 1:length(c)
c(i).v = full(c(i).val);
% per default take all data along a dimension
c(i).index = ':';
% convert time units
if ~isempty(strfind(c(i).units,'since'))
[t0,f] = nctimeunits(c(i).units);
c(i).v = f*double(c(i).v) + t0;
endif
% change vertical axis to positive up
if strcmp(c(i).positive,'down')
c(i).v = -double(c(i).v);
endif
c(i).sub = c(i).v;
endfor
% loop over all constraints
for i = 1:2:length(varargin)
name = varargin{i};
j = find(strcmp(name,{c.standard_name}));
if isempty(j)
warning(['no coordinate has the standard_name ' name ...
'. Try to use variable names.']);
j = find(strcmp(name,{c.name}));
if isempty(j)
error(['no coordinate has the name ' name '.']);
endif
endif
range = varargin{i+1};
if numel(range) == 1
dist = abs(c(j).v - range);
[mindist,i] = min(dist);
%i
%mindist
%c(j).v(i)
%datevec(c(j).v(i))
else
i = find(range(1) < c(j).v & c(j).v < range(end));
i = min(i):max(i);
endif
c(j).index = i;
c(j).sub = c(j).v(i);
endfor
idx = substruct('()',{c.index});
%idx
data = subsref (self,idx);
varargout = {data,c.sub};
% i = 1;
% mask = xr(1) <= x & x <= xr(2);
% l = find(mask);
% [ij{:}] = ind2sub(size(mask),l);
% for j=1:len
% mins(j) = min(ij{j});
% maxs(j) = max(ij{j});
endfunction
ncarray-1.0.5/inst/@ncArray/ncArray.m 0000644 0000000 0000000 00000005742 14310066641 015604 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{V} =} ncArray(@var{filename}, @var{varname})
## @deftypefnx {} {@var{V} =} ncArray(@var{filename}, @var{varname}, @var{propertyname}, @var{propertyvalue}, @dots{})
## Create a ncArray that can be accessed as a normal array.
##
## @subsubheading Inputs
## @var{filename} - filename to read
##
## @var{varname} - variable name to read from file
##
## @var{propertyname}, @var{propertyvalue} - property name and value pairs.
##
## @subsubheading Outputs
## @var{V} - a ncArray of the read file.
##
## For read access filename can be compressed if it has the extensions
## ".gz" or ".bz2". It use the function cache_decompress to cache to
## decompressed files.
##
## Data is loaded by ncread and saved by ncwrite. Values equal to _FillValue
## are thus replaced by NaN and the scaling (add_offset and
## scale_factor) is applied during loading and saving.
##
## @subsubheading Example
##
## Loading the variable (assuming V is 3 dimensional):
## @example
## x = V(1,1,1); % load element 1,1,1
## x = V(:,:,:); % load the complete array
## x = V(); x = full(V) % loads also the complete array
## @end example
##
## Saving data in the netcdf file:
## @example
## V(1,1,1) = x; % save x in element 1,1,1
## V(:,:,:) = x;
## @end example
##
## Attributes
## @example
## units = V.units; % get attribute called "units"
## V.units = 'degree C'; % set attributes;
## @end example
##
## Note: use the '.()' notation if the attribute has a leading underscore
## (due to a limitation in the matlab parser):
##
## @example
## V.('_someStrangeAttribute') = 123;
## @end example
##
## @seealso{cache_decompress, ncCatArray}
## Web: http://modb.oce.ulg.ac.be/mediawiki/index.php/ncArray
## @end deftypefn
function retval = ncArray(varargin)
if ischar(varargin{1})
filename = varargin{1};
varname = varargin{2};
var = ncBaseArray(filename,varname);
[dims,coord] = nccoord(cached_decompress(filename),varname);
for i=1:length(coord)
coord(i).val = ncBaseArray(filename,coord(i).name);
endfor
else
var = varargin{1};
dims = varargin{2};
coord = varargin{3};
endif
self.var = var;
self.dims = dims;
self.nd = length(self.dims);
self.coord = coord;
retval = class(self,'ncArray',BaseArray(size(self.var)));
endfunction
ncarray-1.0.5/inst/@ncArray/subsasgn.m 0000644 0000000 0000000 00000002320 14310066641 016017 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {} subsasgn(@var{A}, @var{idx}, @var{rhs})
## Perform the subscripted assignment operation according to the subscript specified by idx.
##
## A slice of the NetCDF variable can be saved by using A(index1,index2,...) = rhs;
## @subsubheading Inputs
## @var{A} - ncArray value
##
## @var{idx} - idx structure
##
## @var{rhs} - value to assign
## @subsubheading Outputs
## None
## @end deftypefn
function self = subsasgn(self,idx,x)
self = subsasgn(self.var,idx,x);
endfunction
ncarray-1.0.5/inst/@ncArray/subsref.m 0000644 0000000 0000000 00000004501 14310066641 015646 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{out} =} subsref(@var{A}, @var{idx})
## Perform the subscripted element selection operation according to the subscript specified by idx.
##
## @subsubheading Inputs
## @var{A} - ncArray value
##
## @var{idx} - idx structure
##
## @subsubheading Outputs
## @var{out} - output value of operation
##
## A slice of the NetCDF variable can be load by using A(index1,index2,...) and attributes
## can be loaded by A.attribute_name or A.('attribute_name')
##
## If index selection is followed by struct selection 'coord', then the coordinates corresponding to the
## slice are loaded:
##
## For example, the coordinate of element A(4,3):
## @example
## [lon,lat] = A(4,3).coord;
## @end example
## @end deftypefn
function varargout = subsref(self,idx)
if strcmp(idx(1).type,'()')
% no subscripts mean that we load all () -> (:,:,...)
if isempty(idx(1).subs)
for i=1:self.nd
idx(1).subs{i} = ':';
endfor
endif
endif
% catch expressions like:
% data(:,:,:).coord
if length(idx) == 2 && strcmp(idx(2).type,'.') && strcmp(idx(2).subs,'coord')
for i=1:length(self.coord)
% get indeces of the dimensions of the i-th coordinate which are also
% coordinate of the variable
% replace dummy by ~ once older version have died
[dummy,j] = intersect(self.dims,self.coord(i).dims);
j = sort(j);
idx_c.type = '()';
idx_c.subs = idx(1).subs(j);
varargout{i} = subsref(self.coord(i).val,idx_c);
endfor
else
% pass subsref to underlying ncBaseArray
varargout{1} = subsref(self.var,idx);
endif
endfunction
ncarray-1.0.5/inst/@ncBaseArray/ 0000755 0000000 0000000 00000000000 14310066641 014612 5 ustar 00 0000000 0000000 ncarray-1.0.5/inst/@ncBaseArray/display.m 0000644 0000000 0000000 00000001636 14310066641 016443 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {} display(@var{A})
## Display ncBaseArray A
## @end deftypefn
function display(self)
disp([self.varname ' from ' self.filename]);
%self.vinfo
%self.dims
endfunction
ncarray-1.0.5/inst/@ncBaseArray/ncBaseArray.m 0000644 0000000 0000000 00000006040 14310066641 017162 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{V} =} ncBaseArray(@var{filename}, @var{varname})
## @deftypefnx {} {@var{V} =} ncBaseArray(@var{filename}, @var{varname}, @var{propertyname}, @var{propertyvalue})
## create a ncBaseArray that can be accessed as a normal matlab array.
## Ths object is a helper object. Users should normally call ncArray.
##
## For read access filename can be compressed if it has the extensions
## ".gz", ".bz2" or ".xz". It use the function cache_decompress to cache to
## decompressed files.
##
## Data is loaded by ncread and saved by ncwrite. Values equal to _FillValue
## are thus replaced by NaN and the scaling (add_offset and
## scale_factor) is applied during loading and saving.
##
## @subsubheading Properties:
## 'tooBigToLoad': if tooBigToLoad is set to true, then only the minimum
## data will be loaded. However this can be quite slow.
## 'vinfo': result from ncinfo can be specified if it is already known.
##
## @subsubheading Examples:
##
## Loading the variable (assuming V is 3 dimensional):
## @example
## x = V(1,1,1); % load element 1,1,1
## x = V(:,:,:); % load the complete array
## x = V(); x = full(V) % loads also the complete array
## @end example
##
## Saving data in the netcdf file:
## @example
## V(1,1,1) = x; % save x in element 1,1,1
## V(:,:,:) = x;
## @end example
##
## Attributes
## @example
## units = V.units; % get attribute called "units"
## V.units = 'degree C'; % set attributes;
## @end example
##
## Note: use the '.()' notation if the attribute has a leading underscore
## (due to a limitation in the matlab parser):
##
## @example
## V.('_someStrangeAttribute') = 123;
## @end example
##
## @seealso {cache_decompress}
## @end deftypefn
function retval = ncBaseArray(filename,varname,varargin)
self.tooBigToLoad = false;
self.vinfo = [];
prop = varargin;
for i=1:2:length(prop)
if strcmp(prop{i},'tooBigToLoad')
self.tooBigToLoad = prop{i+1};
elseif strcmp(prop{i},'vinfo')
self.vinfo = prop{i+1};
endif
endfor
self.filename = filename;
self.varname = varname;
if isempty(self.vinfo)
self.vinfo = ncinfo(cached_decompress(filename),varname);
endif
self.sz = self.vinfo.Size;
self.dims = self.vinfo.Dimensions;
self.nd = length(self.dims); % number of netcdf dimensions
retval = class(self,'ncBaseArray',BaseArray(self.sz));
endfunction
ncarray-1.0.5/inst/@ncBaseArray/ncsub.m 0000644 0000000 0000000 00000004557 14310066641 016115 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {} ncsub(@var{A}, @var{idx})
## internal function of ncBaseArray
## @end deftypefn
function [start, count, stride] = ncsub(self,idx)
assert(strcmp(idx.type,'()'))
% number of dimension (including singleton dimensions)
%n = length(size(self));
n = self.nd;
% number of subscripts
ns = length(idx.subs);
if ns == 0
% load all
start = ones(1,n);
count = self.sz;
stride = ones(1,n);
else
start = ones(1,ns);
count = ones(1,ns);
stride = ones(1,ns);
% sz is the size padded by 1 if more indices are given than n
sz = ones(1,ns);
sz(1:length(self.sz)) = self.sz;
for i=1:ns
if isempty(idx.subs{i})
count(i) = 0;
elseif strcmp(idx.subs{i},':')
count(i) = sz(i);
else
tmp = idx.subs{i};
if length(tmp) == 1
start(i) = tmp;
else
% check if indexes are at regular intervals
test = tmp(1):tmp(2)-tmp(1):tmp(end);
if size(tmp,2) == 1
% tmp is a row vector, make test also a row vector
test = test';
endif
if all(tmp == test)
start(i) = tmp(1);
stride(i) = tmp(2)-tmp(1);
count(i) = (tmp(end)-tmp(1))/stride(i) +1;
else
error('indeces not at regular intervals');
endif
endif
endif
endfor
assert(all(count(n+1:end) == 1 | count(n+1:end) == 0))
assert(all(start(n+1:end) == 1))
if ~any(count == 0)
count = count(1:n);
start = start(1:n);
stride = stride(1:n);
endif
endif
endfunction
ncarray-1.0.5/inst/@ncBaseArray/subsasgn.m 0000644 0000000 0000000 00000001623 14310066641 016617 0 ustar 00 0000000 0000000 function self = subsasgn(self,idxs,x)
%idx
idx = idxs(1);
assert(strcmp(idx.type,'()'))
[start, count, stride] = ncsub(self,idx);
if all(count ~= 0)
ncwrite(self.filename,self.varname,x,start,stride);
end
% Copyright (C) 2012 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 3 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 .
ncarray-1.0.5/inst/@ncBaseArray/subsref.m 0000644 0000000 0000000 00000005053 14310066641 016444 0 ustar 00 0000000 0000000 ## Copyright (C) 2012 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 3 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 {} {@var{x} =} ncsub(@var{A}, @var{idx})
## subsref function
## @end deftypefn
function x = subsref(self,idx)
assert(length(idx) == 1)
if strcmp(idx.type,'()')
% load data
if strcmp(idx.type,'()') && length(idx.subs) == 1 ...
&& length(idx.subs) < self.nd
% reference like A([2 3 1 5])
if self.tooBigToLoad
% number of elements in x
ind = idx.subs{1};
% transform index to subscript
subs = cell(1,self.nd);
[subs{:}] = ind2sub(size(self),ind);
% make a nice array length(ind) by self.nd
subs = cell2mat(subs);
% output array
x = zeros(size(ind));
x(:) = NaN;
% get every element
% can be quite slow
idxe.type = '()';
idxe.subs = cell(1,self.nd);
for i=1:length(ind)
idxe.subs = mat2cell(subs(i,:),1,ones(1,self.nd));
x(i) = subsref(self,idxe);
endfor
else
% load full array
tmp = full(self);
x = subsref(tmp,idx);
endif
else
[start, count, stride] = ncsub(self,idx);
if any(count == 0)
x = zeros(count);
else
x = ncread(cached_decompress(self.filename),self.varname,...
start,count,stride);
endif
endif
elseif strcmp(idx.type,'.')
% load attribute
name = idx.subs;
% strmatch is obsolete
% index = strmatch(name,{self.vinfo.Attributes(:).Name});
index = find(strcmp(name,{self.vinfo.Attributes(:).Name}));
if isempty(index)
error('variable %s has no attribute called %s',self.varname,name);
else
x = self.vinfo.Attributes(index).Value;
endif
else
error('not supported');
endif
endfunction
ncarray-1.0.5/inst/cached_decompress.m 0000644 0000000 0000000 00000013773 14310066641 016144 0 ustar 00 0000000 0000000 ## Copyright (C) 2012-2022 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 3 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 {} {@var{fname} =} cached_decompress(@var{filename})
## Decompress a file using a cache.
##
## @subsubheading Inputs
## @var{filename}: name of the file which is possibly compressed
##
## @subsubheading Outputs
## @var{fname}: the filename of the uncompressed file
##
## @subsubheading Global variables
## CACHED_DECOMPRESS_DIR (default is the result of tempname)
## cache directory of decompressed files.
##
## CACHED_DECOMPRESS_LOG_FID (default 1): file id for log message
##
## CACHED_DECOMPRESS_MAX_SIZE (default 1e10): maximum size of cache in bytes.
## @end deftypefn
function fname = cached_decompress(url)
global CACHED_DECOMPRESS_DIR
global CACHED_DECOMPRESS_LOG_FID
global CACHED_DECOMPRESS_MAX_SIZE
if startswith(url,'http:') || ...
~(endswith(url,'.gz') || endswith(url,'.bz2') || endswith(url,'.xz'))
% opendap url or not compressed file
fname = url;
return
endif
cache_dir = CACHED_DECOMPRESS_DIR;
if isempty(cache_dir)
cache_dir = tempname;
CACHED_DECOMPRESS_DIR = cache_dir;
mkdir(cache_dir);
fprintf('creating directory %s for temporary files.\n',cache_dir);
endif
%if exist(cache_dir,'dir') ~= 7
% error(['cache directory for compressed files does not exist. '...
% 'Please create the directory %s or change le value of the '...
% 'global variable CACHED_DECOMPRESS_DIR'],cache_dir);
%endif
% where to print logs? default to screen
fid = CACHED_DECOMPRESS_LOG_FID;
if (isempty(fid))
fid = 1;
endif
% form filename for cache
fname = url;
fname = strrep(fname,'/','_SLASH_');
fname = strrep(fname,'*','_STAR_');
fname = strrep(fname,'\','_BSLASH_');
fname = strrep(fname,':','_COLON_');
fname = fullfile(cache_dir,fname);
% test if in cache
if exist(fname,'file') ~= 2
if ispc()
# TODO - just do for all OSs?
tmp_dir = tempname ();
[success, msg] = mkdir (tmp_dir);
if (success != 1)
error ("failed to create temporary directory: %s", msg);
endif
unwind_protect
looks_like_url = regexp (url, '^\w+://');
if looks_like_url;
[~, name, ext] = fileparts (url);
tmp_file = fullfile (tmp_dir, [name ext]);
[~, success, msg] = urlwrite (url, tmp_file);
if (success != 1)
error ("failed downloading '%s': %s", url, msg);
endif
else
[~, name, ext] = fileparts (url);
tmp_file = fullfile (tmp_dir, ["tmp_" name ext]);
success = copyfile(url, tmp_file);
if (success != 1)
error ("failed copying '%s'", url);
endif
endif
if !exist (tmp_file, "file")
error ("No local file '%s' found\n", tmp_file);
endif
if endswith(url,'.zip')
func_uncomp = @unzip;
elseif endswith(url,'.gz')
func_uncomp = @gunzip;
elseif endswith(url,'.bz2')
func_uncomp = @bunzip2;
else
func_uncomp = [];
endif
if !isempty(func_uncomp)
files = func_uncomp(tmp_file, tmp_dir);
else
files = {tmp_file};
endif
if length(files) != 1
error ("Expected single file being added");
endif
success = copyfile(files{1}, fname);
if (success != 1)
error ("Failed to copy file to cache");
endif
unwind_protect_cleanup
if (exist (tmp_dir, "file"))
confirm_recursive_rmdir (0, "local");
rmdir(tmp_dir, "s");
endif
end_unwind_protect
else
# else try via command (after checking it exists?)
if endswith(url,'.gz')
cmd = 'gunzip --stdout -';
elseif endswith(url,'.bz2')
cmd = 'bunzip2 --stdout -';
elseif endswith(url,'.xz')
cmd = 'unxz --stdout -';
else
cmd = 'cat';
endif
if startswith(url,'ftp://')
syscmd('curl --silent "%s" | %s > "%s"',url,cmd,fname);
else
syscmd('%s < "%s" > "%s"',cmd,url,fname);
endif
endif
else
% fprintf(fid,'retrieve from cache %s\n',url);
endif
% check cache size
d=dir(cache_dir);
cashe_size = sum([d.bytes]);
max_cache_size = CACHED_DECOMPRESS_MAX_SIZE;
if isempty(max_cache_size)
max_cache_size = 1e10;
endif
if (cashe_size > max_cache_size)
% look for oldest files
fdate = zeros(1,length(d));
for i=1:length(d);
fdate(i) = datenum(d(i).date);
endfor
[fdate,index] = sort(fdate,'descend');
d=d(index);
cum_size = cumsum([d(:).bytes]);
todelete = find(cum_size > max_cache_size);
for i=todelete
if (d(i).isdir == 0)
fprintf(fid,'clean cashe: delete %s\n', d(i).name);
delete(fullfile(cache_dir,d(i).name));
endif
endfor
endif
endfunction
function t = startswith(s,ext)
if length(ext) <= length(s)
t = strcmp(s(1:length(ext)),ext);
else
t = 0;
endif
endfunction
function t = endswith(s,ext)
if length(ext) <= length(s)
t = strcmp(s(end-length(ext)+1:end),ext);
else
t = 0;
endif
endfunction
function syscmd(varargin)
cmd = sprintf(varargin{:});
%disp(cmd)
status = 0;
[status, output] = system(cmd);
disp(output);
if status ~= 0
error(['command "' cmd '" failed: ' output]);
endif
endfunction
ncarray-1.0.5/inst/ncCatArray.m 0000644 0000000 0000000 00000014575 14310066641 014541 0 ustar 00 0000000 0000000 ## Copyright (C) 2012,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 3 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 .
## Author: Alexander Barth (barth.alexander@gmail.com)
##
## -*- texinfo -*-
## @deftypefn {} {@var{C} =} ncCatArray(@var{dim}, @var{filenames}, @var{varname})
## @deftypefnx {} {@var{C} =} ncCatArray(@var{dim}, @var{pattern}, @var{varname})
## @deftypefnx {} {@var{C} =} ncCatArray(@var{dim}, @var{filenamefun}, @var{varname}, @var{range})
## @deftypefnx {} {@var{C} =} ncCatArray(@dots{} @var{propertyname}, @var{properyvalue})
## Create an array that represent a concatenated NetCDF variables.
##
## Create a concatenated array from variables (varname) in a list of
## netcdf files along dimension dim.Individual elements can be accessed by
## subscripts
##
## e.g. C(2,3) and the corrsponding subset of the appropriate file is loaded
##
## @subsubheading Inputs
## @var{dim} - dimensions use for variables
##
## @var{varname} - variable name to load
##
## @var{filenames} - list of filenames as a cell array
##
## @var{pattern} - shell wildcard pattern (e.g. file_*.nc)
##
## @var{filenamefunc} - a function handle where the i-th filename is
## filenamefun(range(i)).
##
## @var{propertyname}, @var{properyvalue} - propery name and value pairs.
##
## @subsubheading Properties
## 'SameAttributes': false or true (default). If SameAttribute is true,
## the variables' NetCDF attribute of all files are assumed to be the same.
## Only the attributes of the first file is loaded in this case.
##
## @subsubheading Outputs
## @var{C} - a concatenated array from the read variables of the files.
##
## @subsubheading Example
## @example
## data = ncCatArray(3,@{'file-20120708.nc','file-20120709.nc'@},'SST')
##
## data = ncCatArray(3,'file-*.nc','SST')
##
## data = ncCatArray(3,@@(t) ['file-' datestr(t,'yyyymmdd') '.nc'],'SST',...
## datenum(2012,07,08):datenum(2012,07,09));
## @end example
##
## Note: in Octave the glob function is used to determine files matching the
## shell wildcard pattern, while in Matlab rdir is used. The function rdir
## is available from Matlab exchange under BSD license
## (http://www.mathworks.com/matlabcentral/fileexchange/19550).
##
## @seealso {cache_decompress, ncArray}
## @end deftypefn
function data = ncCatArray(dim,pattern,varname,varargin)
catdimname = '_cat_dim';
SameAttributes = true;
range = [];
[reg, prop] = parseparams(varargin);
if length(reg) == 1
range = reg{1};
endif
for i = 1:2:length(prop)
if strcmp(prop{i},'SameAttributes')
SameAttributes = prop{i+1};
elseif strcmp(prop{i},'range')
range = prop{i+1};
else
error(['unknown property value ' prop{i}]);
endif
endfor
% file names
if iscell(pattern)
filenames = pattern;
elseif ischar(pattern)
try
filenames = glob(pattern);
catch
try
d = rdir(pattern);
filenames = {d(:).name};
catch
error(['The function rdir or glob (octave) is not available. '...
'rdir can be installed from '...
'http://www.mathworks.com/matlabcentral/fileexchange/19550']);
end_try_catch
end_try_catch
if isempty(filenames)
error('ncArray:nomatch','no file found matching %s',pattern);
endif
elseif isa(pattern, 'function_handle')
filenames = cell(1,length(range));
for i=1:length(range)
filenames{i} = pattern(range(i));
endfor
endif
if isempty(range)
range = 1:length(filenames);
endif
% get all file information
finfos = cell(length(filenames),1);
if SameAttributes
% assume all files have the same ncinfo as the first one
tmp = ncinfo(cached_decompress(filenames{1}));
for i=1:length(filenames)
finfos{i} = tmp;
endfor
% octave allows the following, but not matlab
%finfos(:) = tmp;
else
for i=1:length(filenames)
finfos{i} = ncinfo(cached_decompress(filenames{i}));
endfor
endif
var = arr(dim,filenames,varname,finfos);
[dims,coord] = nccoord(finfos{1},varname);
% add new dimension to coord if arrays are contatenated over a new dimension
% and if coord information already exist
if (dim > length(dims)) && ~isempty(coord)
% concatenate is new dimension
dims{dim} = catdimname;
coord(dim).dims = {catdimname};
coord(dim).val = range;
coord(dim).name = catdimname;
endif
for i=1:length(coord)
%test if value is already defined, if yes do nothing
if isfield(coord(i),'val')
if ~isempty(coord(i).val)
continue
endif
endif
% the number of the dimension might be different
% find in coord(i).dims the index of the dimension called dims{dim}
% for example we concatenate over time, then two situations can arrise
% the coordinate variable lon can dependent on time (dimc is not empty)
% or it does not depdent on time (dimc is empty)
dimc = find(strcmp(coord(i).dims,dims{dim}));
if isempty(dimc)
vinfo = varinfo(finfos{1},coord(i).name);
coord(i).val = ncBaseArray(filenames{1},coord(i).name,'vinfo',vinfo);
else
% coordinates do also depend on the dimension over which we concatenate
%i,coord(i).name,dimc,dims{dim}
coord(i).val = arr(dimc,filenames,coord(i).name,finfos);
endif
%if dim > length(coord(i).dims)
% coord(i).dims{dim} = catdimname;
%end
endfor
data = ncArray(var,dims,coord);
endfunction
function CA = arr(dim,filenames,varname,finfos)
arrays = cell(1,length(filenames));
for i=1:length(filenames)
vinfo = varinfo(finfos{i},varname);
arrays{i} = ncBaseArray(filenames{i},varname,'vinfo',vinfo);
endfor
CA = CatArray(dim,arrays);
endfunction
function vinfo = varinfo(fileinfo,varname)
index = find(strcmp({fileinfo.Variables(:).Name},varname));
vinfo = fileinfo.Variables(index);
endfunction
ncarray-1.0.5/inst/ncarray_example.m 0000644 0000000 0000000 00000002014 14310066641 015645 0 ustar 00 0000000 0000000
% Tutorial for using ncArray
% It is advised to run this script in an empty directory.
% It will delete and overwrite files named file1.nc, file2.nc and file3.nc.
% size of the example data (2x3)
n = 3;
m = 2;
% create 3 files (file1.nc, file2.nc,...) with a 2x3 variable called SST
data = zeros(n,m);
disp('create example files: file1.nc, file2.nc, file3.nc')
for i = 1:3
data(:) = i;
files{i} = sprintf('file%d.nc',i);
delete(files{i});
ncarray_example_file(files{i},data);
end
% Using ncArray
SST = ncArray('file1.nc','SST');
disp('load the entire file')
data = SST(:,:,:);
disp('get the attribute units')
units = SST.units;
disp('load a particular value');
data = SST(3,2,1);
% Using ncCatArray
disp('concatenate the files over the 3rd dimension (here time)')
SST = ncCatArray(3,{'file1.nc','file2.nc','file3.nc'},'SST');
% or just
% SST = ncCatArray(3,'file*.nc','SST');
disp('load all 3 files');
data = SST(:,:,:);
disp('load a particular value (1,2,1) of the 3rd file');
data = SST(1,2,3);
ncarray-1.0.5/inst/ncarray_example_file.m 0000644 0000000 0000000 00000003621 14310066641 016651 0 ustar 00 0000000 0000000 ## Copyright (C) 2012,2013,2015 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 3 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 .
## Create an example NetCDF file with the name filename and given data
function ncarray_example_file(filename,data)
dtype = 'double';
sz = size(data);
% Variables
nccreate(filename,'lon','Format','classic','Datatype',dtype,...
'Dimensions',{'x',sz(1), 'y',sz(2)});
ncwriteatt(filename,'lon','long_name','Longitude')
ncwriteatt(filename,'lon','units','degrees_east')
nccreate(filename,'lat','Datatype',dtype,'Dimensions',{'x',sz(1), 'y',sz(2)});
ncwriteatt(filename,'lat','long_name','Latitude')
ncwriteatt(filename,'lat','units','degrees_north')
nccreate(filename,'time','Datatype',dtype,'Dimensions',{'time',1});
ncwriteatt(filename,'time','long_name','Time')
ncwriteatt(filename,'time','units','days since 1858-11-17 00:00:00 GMT')
nccreate(filename,'SST','Datatype',dtype,'Dimensions',...
{'x',sz(1), 'y',sz(2), 'time',1});
ncwriteatt(filename,'SST','missing_value',single(9999))
ncwriteatt(filename,'SST','_FillValue',single(9999))
ncwriteatt(filename,'SST','units','degC')
ncwriteatt(filename,'SST','long_name','Sea Surface Temperature')
ncwriteatt(filename,'SST','coordinates','lat lon')
ncwrite(filename,'SST',data);
endfunction
ncarray-1.0.5/inst/nccoord.m 0000644 0000000 0000000 00000007373 14310066641 014137 0 ustar 00 0000000 0000000 ## Copyright (C) 2012, 2013, 2015 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 3 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 .
## Author: Alexander Barth (barth.alexander@gmail.com)
## -*- texinfo -*-
## @deftypefn {} {[@var{dims}, @var{coord}] =} nccoord(@var{filename}, @var{varname})
## Get coordinates of the variable varname in the
## netcdf file called filename. The netcdf is assumed to
## follow the CF convention.
##
## @subsubheading Inputs
## @var{filename} - netcdf filename
##
## @var{varname} - variable name
##
## @subsubheading Outputs
## @var{dims} - a cell-array of the dimensions of varname
##
## @var{coord} - an array of structures with the field 'name'
## for the variable name, 'dims' with a cell-array of the
## netcdf dimensions, the units and NetCDF-CF standard name.
##
## coord is an empty structure if no coordinate information have been
## found.
## @end deftypefn
## TODO: use a predictable order for coord:
## lon, lat, depth, time, ensemble,...
function [dims,coord] = nccoord(filename,varname)
if ischar(filename)
finfo = ncinfo(filename);
else
finfo = filename;
endif
% get variable info
index = find(strcmp({finfo.Variables(:).Name},varname));
vinfo = finfo.Variables(index);
% determine coordinates
% using CF convention
dims = {vinfo.Dimensions(:).Name};
% create empty coord array with the fields name and dims
coord = struct('name',{},'dims',{},'standard_name',{},...
'units',{},'positive',{});
% check the coordinate attribute
if ~isempty(vinfo.Attributes)
index = find(strcmp('coordinates',{vinfo.Attributes(:).Name}));
if ~isempty(index)
tmp = strsplit(vinfo.Attributes(index).Value,' ');
% order should not be siginficant
for i=length(tmp):-1:1
coord = addcoord(coord,tmp{i},finfo);
endfor
endif
endif
% check for coordinate dimensions
for i=1:length(dims)
% check if variable with the same name than the dimension exist
index = find(strcmp(dims{i},{finfo.Variables(:).Name}),1);
if ~isempty(index)
coord = addcoord(coord,dims{i},finfo);
endif
endfor
endfunction
function coord = addcoord(coord,name,finfo)
% check if coordinate is aleady in the list
if isempty(find(strcmp(name,{coord(:).name}),1))
% check if name is variable
index = find(strcmp(name,{finfo.Variables(:).Name}));
if ~isempty(index)
vinfo = finfo.Variables(index);
c.name = name;
d = vinfo.Dimensions;
c.dims = {d(:).Name};
c.standard_name = [];
c.units = [];
c.positive = [];
% get standard_name attribute if present
i = find(strcmp('standard_name',{vinfo.Attributes(:).Name}));
if ~isempty(i)
c.standard_name = vinfo.Attributes(i).Value;
endif
% get units attribute if present
i = find(strcmp('units',{vinfo.Attributes(:).Name}));
if ~isempty(i)
c.units = vinfo.Attributes(i).Value;
endif
% get positive attribute if present
i = find(strcmp('positive',{vinfo.Attributes(:).Name}));
if ~isempty(i)
c.positive = vinfo.Attributes(i).Value;
endif
coord(end+1) = c;
endif
endif
endfunction
ncarray-1.0.5/inst/ncreadtime.m 0000644 0000000 0000000 00000002406 14310066641 014613 0 ustar 00 0000000 0000000 ## Copyright (C) 2012-2022 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 3 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 {} {@var{t} =} ncreadtime(@var{filename}, @var{varname})
## Read a time variable as serial day number.
##
## @subsubheading Inputs
## @var{filename} - netcdf filename
##
## @var{varname} - time variable called varname.
##
## @subsubheading Outputs
## @var{t} serial day number (days since 31 December 1 BC, as datenum).
## @end deftypefn
function t = ncreadtime(filename,varname)
t = double(ncread(filename,varname));
units = ncreadatt(filename,varname,'units');
[t0,f] = nctimeunits(units);
t = f*t + t0;
endfunction
ncarray-1.0.5/inst/nctimeunits.m 0000644 0000000 0000000 00000006014 14310066641 015041 0 ustar 00 0000000 0000000 ## Copyright (C) 2012-2022 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 3 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 {} {[@var{t0}, @var{f}] =} nctimeunits(@var{u})
## Parse netCDF time unit.
##
## @subsubheading Inputs
## @var{u} - netCDF time unit
##
## @subsubheading Outputs
## @var{t0} - time offset (days since 31 December 1 BC, as datenum)
##
## @var{f} - scaling factor (in days)
##
## See the netCDF CF convention for the structure of the time units.
## @url{http://cfconventions.org/Data/cf-conventions/cf-conventions-1.6/build/cf-conventions.html#time-coordinate}
## and @url{http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/CDM/CalendarDateTime.html}
## @end deftypefn
function [t0,f] = nctimeunits(u)
% years in days for udunits
% http://cfconventions.org/Data/cf-conventions/cf-conventions-1.6/build/cf-conventions.html#time-coordinate
year_in_days = 365.242198781;
l = strfind(u,'since');
if length(l) ~= 1
error(['time units sould expect one "since": "' u '"']);
endif
period = strtrim(lower(u(1:l-1)));
reference_date = strtrim(u(l+6:end));
if strcmp(period,'millisec') || strcmp(period,'msec')
f = 1/(24*60*60*1000);
elseif strcmp(period,'second') || strcmp(period,'seconds') ...
|| strcmp(period,'s') || strcmp(period,'sec')
f = 1/(24*60*60);
elseif strcmp(period,'minute') || strcmp(period,'minutes') ...
|| strcmp(period,'min')
f = 1/(24*60);
elseif strcmp(period,'hour') || strcmp(period,'hours') ...
|| strcmp(period,'hr')
f = 1/24;
elseif strcmp(period,'day') || strcmp(period,'days')
f = 1;
elseif strcmp(period,'week') || strcmp(period,'weeks')
f = 1/(24*60*60*7);
elseif strcmp(period,'year') || strcmp(period,'years') ...
strcmp(period,'yr')
f = year_in_days;
elseif strcmp(period,'month') || strcmp(period,'months') ...
strcmp(period,'mon')
f = year_in_days/12;
else
error(['unknown units "' period '"']);
endif
if strcmp(reference_date,'1900-01-01 00:00:0.0')
t0 = datenum(1900,1,1);
else
try
t0 = datenum(reference_date,'yyyy-mm-dd HH:MM:SS');
catch
try
t0 = datenum(reference_date,'yyyy-mm-ddTHH:MM:SS');
catch
try
t0 = datenum(reference_date,'yyyy-mm-dd');
catch
error(['date format is not recogized ' reference_date])
end_try_catch
end_try_catch
end_try_catch
endif
endfunction
ncarray-1.0.5/inst/private/ 0000755 0000000 0000000 00000000000 14310066641 013772 5 ustar 00 0000000 0000000 ncarray-1.0.5/inst/private/assertAlmostEqual.m 0000644 0000000 0000000 00000002446 14310066641 017627 0 ustar 00 0000000 0000000 ## Copyright (C) 2016 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 3 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 {} {} assertAlmostEqual()
## Private function
## @end deftypefn
% this function is necessary because of the limitation of matlab
function assertAlmostEqual(observed,expected)
% tolerance for testing
tol = 1e-10;
% for compatibility with matlab which does not have
% assert (OBSERVED, EXPECTED, TOL)
assert(max(abs(observed(:) - expected(:))) < tol)
% for octave prior to 3.8.0
if isempty(which('isequaln'))
isequaln = @(x,y) isequalwithequalnans(x,y);
endif
% check also NaNS
assert(isequal(isnan(observed),isnan(expected)))
endfunction
ncarray-1.0.5/inst/private/strsplit.m 0000644 0000000 0000000 00000002373 14310066641 016041 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 3 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 {} {parts =} strsplit(@var{name}, @var{sep})
## A simple strsplit implementation.
##
## Once a strsplit becomes widespread in octave and Matlab,
## this file can be deleted.
##
## This file is preferred over octave's strsplit, because it is compatible
## with the Matlab interpreter.
## @end deftypefn
function parts = strsplit(name,sep);
ind = find(name == sep);
parts = cell(length(ind)+1,1);
ind = [0 ind length(name)+1];
for i=1:length(parts)
parts{i} = name(ind(i)+1:ind(i+1)-1);
endfor
endfunction
ncarray-1.0.5/inst/test_ncarray.m 0000644 0000000 0000000 00000022641 14310066641 015201 0 ustar 00 0000000 0000000 ## Copyright (C) 2012, 2015 Alexander Barth
## Copyright (C) 2019 John D
##
## 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 3 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 {} {} test_ncarray()
## Test ncBaseArray, ncCatArray and ncArray.
## @end deftypefn
function test_ncarray()
varname = 'SST';
tmpdir = tempname;
mkdir(tmpdir);
tmpfname = tempname(tmpdir);
refdata = {};
for i = 1:3
files{i} = fullfile(tmpdir,sprintf('file%d.nc',i));
refdata{i} = randn(220,144);
ncarray_example_file(files{i},refdata{i});
endfor
filename = files{1};
% test ncread/ncwrite
copyfile(files{1},tmpfname);
SST_ref = ncread(files{1},'SST');
ncwrite(tmpfname,'SST',zeros(size(SST_ref)));
test = ncread(tmpfname,'SST');
assert(all(test(:) == 0))
ncwrite(tmpfname,'SST',SST_ref);
test = ncread(tmpfname,'SST');
assertAlmostEqual(test,SST_ref)
%%% test ncBaseArray
% reading
copyfile(files{2},tmpfname);
SST = ncBaseArray(tmpfname,varname);
test = SST(:,:,:);
SST_ref = ncread(tmpfname,varname);
assertAlmostEqual(test,SST_ref)
assert(isempty(SST(:,:,:,[])));
assertAlmostEqual(SST_ref, SST(:,:,:,1))
ind = floor(numel(SST_ref) * rand(100,1))+1;
assertAlmostEqual(SST(ind),SST_ref(ind))
% writing
r = round(randn(size(SST)));
SST(:,:,:) = r;
SST_ref = ncread(tmpfname,varname);
assertAlmostEqual(r,SST_ref);
SST(:,:,:) = 3 * r;
SST_ref = ncread(tmpfname,varname);
assertAlmostEqual(3 * r,SST_ref);
%%% test ncArray
% reading
copyfile(files{2},tmpfname);
SST = ncArray(tmpfname,varname);
test = SST(:,:,:);
SST_ref = ncread(tmpfname,varname);
assertAlmostEqual(test,SST_ref)
assert(isempty(SST(:,:,:,[])));
assertAlmostEqual(SST_ref, SST(:,:,:,1))
ind = floor(numel(SST_ref) * rand(100,1))+1;
assertAlmostEqual(SST(ind),SST_ref(ind))
assertAlmostEqual(SST_ref(1,:,:), SST(1,:,:))
% sum
nanmeanSST = nanmean(SST);
nanmeanSSTref = nanmean(SST_ref);
assertAlmostEqual(nanmeanSST, nanmeanSSTref)
%momentSST = moment(SST,2,1);
%momentSSTref = moment(SST_ref,2,1);
%assertAlmostEqual(momentSST, momentSSTref)
sumSST = sum(SST,1);
sumSSTref = sum(SST_ref,1);
assertAlmostEqual(sumSST, sumSSTref)
sumSST = sum(SST,2);
sumSSTref = sum(SST_ref,2);
assertAlmostEqual(sumSST, sumSSTref)
sumSST = sum(SST,3);
sumSSTref = sum(SST_ref,3);
assertAlmostEqual(sumSST, sumSSTref)
sumSST = sum(SST);
sumSSTref = sum(SST_ref);
assertAlmostEqual(sumSST, sumSSTref)
prodSST = prod(SST);
prodSSTref = prod(SST_ref);
assertAlmostEqual(prodSST, prodSSTref)
% only for octave
%sumsqSST = sumsq(SST);
%sumsqSSTref = sumsq(SST_ref); % does not work in matlab
%assertAlmostEqual(sumsqSST, sumsqSSTref)
meanSST = mean(SST);
meanSSTref = mean(SST_ref);
assertAlmostEqual(meanSST, meanSSTref)
varSST = var(SST);
varSSTref = var(SST_ref);
assertAlmostEqual(varSST, varSSTref)
varSST = var(SST,1);
varSSTref = var(SST_ref,1);
assertAlmostEqual(varSST, varSSTref)
varSST = var(SST,[],2);
varSSTref = var(SST_ref,[],2);
assertAlmostEqual(varSST, varSSTref)
stdSST = std(SST);
stdSSTref = std(SST_ref);
assertAlmostEqual(stdSST, stdSSTref)
stdSST = std(SST,1);
stdSSTref = std(SST_ref,1);
assertAlmostEqual(stdSST, stdSSTref)
stdSST = std(SST,[],2);
stdSSTref = std(SST_ref,[],2);
assertAlmostEqual(stdSST, stdSSTref)
maxSST = max(SST,[],2);
maxSSTref = max(SST_ref,[],2);
assertAlmostEqual(maxSST, maxSSTref)
minSST = min(SST,[],2);
minSSTref = min(SST_ref,[],2);
assertAlmostEqual(minSST, minSSTref)
% writing
r = round(randn(size(SST)));
SST(:,:,:) = r;
SST_ref = ncread(tmpfname,varname);
assertAlmostEqual(r,SST_ref);
SST(:,:,:) = 3 * r;
SST_ref = ncread(tmpfname,varname);
assertAlmostEqual(3 * r,SST_ref);
%%% CatArray
% reading
CA = CatArray(3,{...
ncArray(filename,varname),...
ncArray(files{2},varname),...
ncArray(files{3},varname)...
});
assert(isequaln(size(CA),[220 144 3]))
SST_ref = ncread(filename,'SST');
tmp2 = CA(:,:,1);
assertAlmostEqual(SST_ref,tmp2)
SST_test = CA(:,:,2);
SST_ref = ncread(files{2},'SST');
assertAlmostEqual(SST_test,SST_ref)
CA2 = CatArray(4,{...
ncArray(files{1},varname),...
ncArray(files{2},varname),...
ncArray(files{3},varname)...
});
SST_test = CA2(:,:,:,2);
assertAlmostEqual(SST_test,SST_ref)
CA2 = ncCatArray(3,{...
files{1},...
files{2},...
files{3}},...
varname);
SST_test = CA2(:,:,2);
assertAlmostEqual(SST_test,SST_ref)
CA2 = ncCatArray(3,fullfile(tmpdir,'file*nc'),varname);
SST_test = CA2(:,:,2);
assertAlmostEqual(SST_test,SST_ref)
CA2 = ncCatArray(3,...
@(i) fullfile(tmpdir,sprintf('file%d.nc',i)),...
varname,...
1:3);
SST_test = CA2(:,:,2);
assertAlmostEqual(SST_test,SST_ref)
SST_ref = cat(3,...
ncread(files{1},'SST'),...
ncread(files{2},'SST'),...
ncread(files{3},'SST'));
assertAlmostEqual(CA2(:,:,:),SST_ref)
assertAlmostEqual(CA2(:,:,1),SST_ref(:,:,1))
assertAlmostEqual(CA2(3:5:50,3:5:100,1),SST_ref(3:5:50,3:5:100,1))
assertAlmostEqual(CA2(3:5:50,3:5:100,2),SST_ref(3:5:50,3:5:100,2))
assertAlmostEqual(CA2(3:5:50,3:5:100,3),SST_ref(3:5:50,3:5:100,3))
assertAlmostEqual(CA2(3:5:50,3:5:100,end),SST_ref(3:5:50,3:5:100,end))
assertAlmostEqual(CA2(50,100,1:3),SST_ref(50,100,1:3))
assertAlmostEqual(CA2(3:5:50,3:5:100,1:2:3),SST_ref(3:5:50,3:5:100,1:2:3))
assertAlmostEqual(CA2(3:5:50,3:5:end,1:2:3),SST_ref(3:5:50,3:5:end,1:2:3))
assertAlmostEqual(CA2(3:5:50,3:5:end,:),SST_ref(3:5:50,3:5:end,:))
% access with linear index
assertAlmostEqual(CA2(:),SST_ref(:))
assertAlmostEqual(CA2(1:10),SST_ref(1:10))
assertAlmostEqual(CA2(1:2:10),SST_ref(1:2:10))
ind = floor(numel(SST_ref) * rand(100,1))+1;
assertAlmostEqual(CA2(ind),SST_ref(ind))
meanSST = mean(CA2,3);
meanSSTref = mean(SST_ref,3);
%assertAlmostEqual(meanSST, meanSSTref)
diff = meanSST -meanSSTref;
assert(max(diff(:)) < 1e-6)
% writing
for i=1:3
list{i} = tempname;
copyfile(filename,list{i});
endfor
CA2 = ncCatArray(3,list,varname);
r = round(randn(size(CA2)));
CA2(:,:,:) = r;
check = ncread(list{2},varname);
assertAlmostEqual(check,r(:,:,2))
r2 = round(randn(size(CA2)));
r(3:5:50,3:5:end,:) = r2(3:5:50,3:5:end,:);
CA2(3:5:50,3:5:end,:) = r2(3:5:50,3:5:end,:);
assertAlmostEqual(CA2(:,:,:),r)
r(end-1,3:5:end,1:2:3) = 2*r2(end-1,3:5:end,1:2:3);
CA2(end-1,3:5:end,1:2:3) = 2*r2(end-1,3:5:end,1:2:3);
assertAlmostEqual(CA2(:,:,:),r)
if 1
% test ncArray (constructor: ncArray(var,dims,coord)
SST = ncBaseArray(filename,varname);
SST_ref = ncread(filename,varname);
lon_ref = ncread(filename,'lon');
coord(1).val = ncBaseArray(filename,'lon');
coord(1).dims = {'x','y'};
coord(2).val = ncBaseArray(filename,'lat');
coord(2).dims = {'x','y'};
coord(3).val = ncBaseArray(filename,'time');
coord(3).dims = {'time'};
data = ncArray(SST,{'x','y','time'},coord);
[x,y,t] = data(:,:,:).coord;
assertAlmostEqual(data(:,:,:),SST_ref)
assertAlmostEqual(x,lon_ref)
assertAlmostEqual(data(),SST_ref)
[x,y,t] = data().coord;
assertAlmostEqual(x,lon_ref)
assertAlmostEqual(data(1:3:end,:,:),SST_ref(1:3:end,:,:))
[x,y,t] = data(1:3:end,:,:).coord;
assertAlmostEqual(x,lon_ref(1:3:end,:))
% test ncArray (constructor: ncData(filename,varname)
SST = ncArray(filename,varname);
[x,y,t] = data(:,:,:).coord;
assertAlmostEqual(data(:,:,:),SST_ref)
assertAlmostEqual(x,lon_ref)
assertAlmostEqual(data(),SST_ref)
[x,y,t] = data().coord;
assertAlmostEqual(x,lon_ref)
assertAlmostEqual(data(1:3:end,:,:),SST_ref(1:3:end,:,:))
[x,y,t] = data(1:3:end,:,:).coord;
assertAlmostEqual(x,lon_ref(1:3:end,:))
%assert(strcmp(SST.units,'degC'))
assert(strcmp(SST.('units'),'degC'))
endif
% read compressed data
zname = [tmpfname '.gz'];
system(['gzip --stdout ' tmpfname ' > ' zname]);
%zname = [tmpfname '.xz'];
%system(['xz --stdout ' tmpfname ' > ' zname]);
SST = ncArray(zname,'SST');
SST_ref = ncread(tmpfname,'SST');
assertAlmostEqual(SST(),SST_ref)
CA2 = ncCatArray(3,fullfile(tmpdir,'file*nc'),varname);
SST_test = CA2(:,:,2);
SST_ref = ncread(files{2},'SST');
assertAlmostEqual(SST_test,SST_ref)
assert(strcmp(CA2.('units'),'degC'));
test_ncarray_nan
% clean-up
d = dir(tmpdir);
for i = 1:length(d)
if ~strcmp(d(i).name,'.') && ~strcmp(d(i).name,'..')
delete(fullfile(tmpdir,d(i).name));
endif
endfor
rmdir(tmpdir);
[t0,f] = nctimeunits('days since 1770-01-01 00:00:00');
assert(t0 == datenum(1770,01,01));
assert(f == 1);
disp('All tests passed.')
endfunction
%!test
%! test_ncarray()
ncarray-1.0.5/inst/test_ncarray_nan.m 0000644 0000000 0000000 00000003447 14310066641 016040 0 ustar 00 0000000 0000000 % Copyright (C) 2013 Alexander Barth
% Copyright (C) 2019 John D
%
% 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 3 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 ncBaseArray, ncCatArray and ncArray.
function test_ncarray_nan()
% for octave prior to 3.8.0
if isempty(which('isequaln'))
isequaln = @(x,y) isequalwithequalnans(x,y);
end
varname = 'SST';
tmpdir = tempname;
mkdir(tmpdir);
tmpfname = tempname(tmpdir);
dataref = randn(220,144,3);
%dataref(rand(size(dataref)) > 0.7) = NaN;
dataref(50:80,30:90,1:2) = NaN;
for i = 1:3
files{i} = fullfile(tmpdir,sprintf('file%d.nc',i));
ncarray_example_file(files{i},dataref(:,:,i));
end
data = ncCatArray(3,files,varname);
reddata = nanmean(data,3);
reddataref = nanmean(dataref,3);
assertAlmostEqual(reddata, reddataref)
reddata = nansum(data,3);
reddataref = nansum(dataref,3);
assertAlmostEqual(reddata, reddataref)
reddata = nanvar(data,[],3);
reddataref = nanvar(dataref,[],3);
diff = reddata - reddataref;
assert(max(diff(:)) < 1e-6)
reddata = nanstd(data,[],3);
reddataref = nanstd(dataref,[],3);
diff = reddata - reddataref;
assert(max(diff(:)) < 1e-6)
% clean-up
for i = 1:3
delete(files{i});
end
rmdir(tmpdir);
endfunction
%!test
%! test_ncarray_nan ()