[GRASS-SVN] r30633 - in
grass/branches/releasebranch_6_3/swig/python: . NumPtr
NumPtr/lib NumPtr/src examples
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Mar 19 06:31:36 EDT 2008
Author: hamish
Date: 2008-03-19 06:31:36 -0400 (Wed, 19 Mar 2008)
New Revision: 30633
Added:
grass/branches/releasebranch_6_3/swig/python/NumPtr/
grass/branches/releasebranch_6_3/swig/python/NumPtr/AUTHORS
grass/branches/releasebranch_6_3/swig/python/NumPtr/COPYING
grass/branches/releasebranch_6_3/swig/python/NumPtr/ChangeLog
grass/branches/releasebranch_6_3/swig/python/NumPtr/INSTALL
grass/branches/releasebranch_6_3/swig/python/NumPtr/README
grass/branches/releasebranch_6_3/swig/python/NumPtr/README.GRASS
grass/branches/releasebranch_6_3/swig/python/NumPtr/VERSION
grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/
grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/NumPtr.py
grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/__init__.py
grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/test.py
grass/branches/releasebranch_6_3/swig/python/NumPtr/readme.html
grass/branches/releasebranch_6_3/swig/python/NumPtr/setup.py
grass/branches/releasebranch_6_3/swig/python/NumPtr/src/
grass/branches/releasebranch_6_3/swig/python/NumPtr/src/Makefile
grass/branches/releasebranch_6_3/swig/python/NumPtr/src/NumPtr.i
grass/branches/releasebranch_6_3/swig/python/NumPtr/src/getpointer.c
grass/branches/releasebranch_6_3/swig/python/NumPtr/src/getpointer.h
grass/branches/releasebranch_6_3/swig/python/NumPtr/src/test.c
grass/branches/releasebranch_6_3/swig/python/NumPtr/src/test.h
grass/branches/releasebranch_6_3/swig/python/examples/
grass/branches/releasebranch_6_3/swig/python/examples/m.distance
grass/branches/releasebranch_6_3/swig/python/examples/rasteraccess.py
grass/branches/releasebranch_6_3/swig/python/examples/vectoraccess.py
Removed:
grass/branches/releasebranch_6_3/swig/python/rasteraccess.py
grass/branches/releasebranch_6_3/swig/python/vectoraccess.py
Modified:
grass/branches/releasebranch_6_3/swig/python/Makefile.in
grass/branches/releasebranch_6_3/swig/python/README
Log:
backport python/swig updates
Modified: grass/branches/releasebranch_6_3/swig/python/Makefile.in
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/Makefile.in 2008-03-19 10:14:02 UTC (rev 30632)
+++ grass/branches/releasebranch_6_3/swig/python/Makefile.in 2008-03-19 10:31:36 UTC (rev 30633)
@@ -1,19 +1,17 @@
-### DEFINITIONS
-
-PYTHONVERSION=@PYVERSION@
-
-### END DEFINITIONS
-
MODULE_TOPDIR = ../..
include $(MODULE_TOPDIR)/include/Make/Lib.make
include $(MODULE_TOPDIR)/include/Make/Doxygen.make
SWIG=swig
-CFLAGS=-c -fpic -I/usr/include/python$(PYTHONVERSION) -I./ -I$(ARCH_DISTDIR)/include
+CFLAGS=-c -fpic -I./ -I$(ARCH_DISTDIR)/include $(GDALCFLAGS) $(PYTHONCFLAGS)
-LDFLAGS=-shared -L$(ARCH_LIBDIR) -lgrass_I -lgrass_Iortho -lgrass_bitmap -lgrass_btree -lgrass_cdhc -lgrass_datetime -lgrass_dbmibase -lgrass_dbmiclient -lgrass_dbmidriver -lgrass_dbstubs -lgrass_dgl -lgrass_display -lgrass_dspf -lgrass_edit -lgrass_form -lgrass_g3d -lgrass_gis -lgrass_gmath -lgrass_gproj -lgrass_interpdata -lgrass_interpfl -lgrass_linkm -lgrass_qtree -lgrass_raster -lgrass_rowio -lgrass_rtree -lgrass_segment -lgrass_shape -lgrass_sites -lgrass_symb -lgrass_trans -lgrass_vask -lgrass_vect -lgrass_psdriver
+LDFLAGS=-shared -L$(ARCH_LIBDIR) $(GDALLIBS) $(PYTHONLDFLAGS) -lgrass_I -lgrass_Iortho -lgrass_bitmap -lgrass_btree -lgrass_cdhc -lgrass_datetime -lgrass_dbmibase -lgrass_dbmiclient -lgrass_dbmidriver -lgrass_dbstubs -lgrass_dgl -lgrass_display -lgrass_dspf -lgrass_edit -lgrass_form -lgrass_g3d -lgrass_gis -lgrass_gmath -lgrass_gproj -lgrass_interpdata -lgrass_interpfl -lgrass_linkm -lgrass_qtree -lgrass_raster -lgrass_rowio -lgrass_rtree -lgrass_segment -lgrass_shape -lgrass_sites -lgrass_symb -lgrass_trans -lgrass_vask -lgrass_vect -lgrass_psdriver
+# TODO: build the NumPtr module. See NumPtr/README.GRASS
+#SUBDIRS = NumPtr
+#include $(MODULE_TOPDIR)/include/Make/Dir.make
+
default: python_grass6.so
clean:
@@ -23,7 +21,7 @@
-rm -f Makefile
python_grass6_wrap.c: python_grass6.i
- make -C interfaces
+ $(MAKE) -C interfaces
$(SWIG) -python -shadow $<
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/AUTHORS
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/AUTHORS (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/AUTHORS 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,5 @@
+The following people have made this package possible:
+
+Rodrigo Caballero Augi (rca at geosci.uchicago.edu)
+Christian Dieterich (cdieterich at geosci.uchicago.edu)
+Michael Steder (steder at gmail.com)
\ No newline at end of file
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/COPYING
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/COPYING (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/COPYING 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/ChangeLog
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/ChangeLog (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/ChangeLog 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,10 @@
+Version 1.1:
+ Major additions by Christian Dieterich(CSC)
+ * Wrapped getpointer1-3 functions into a single python
+ routine: getpointer
+ * Added support for C int and float type arrays as well
+ as C double types. The "getpointer" function automatically
+ checks type and calls the appropriate wrapper code.
+
+Version 1.0:
+ Initial Public Release
\ No newline at end of file
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/INSTALL
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/INSTALL (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/INSTALL 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,8 @@
+To install simply type the following:
+
+ python setup.py build
+
+As root you can then type:
+
+ python setup.py install
+
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/README
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/README (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/README 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,72 @@
+Numeric Pointer Module
+
+Written by: Rodrigo Caballero Augi (rca at geosci.uchicago.edu),
+Updated: Christian Dieterich (cdieterich at geosci.uchicago.edu),
+Packaged: Michael Steder (steder at gmail.com)
+Department of Geophysical Sciences, University of Chicago
+(http://geosci.uchicago.edu/csc)
+2004
+
+* Introduction *
+
+The Numeric Pointer module (NumPtr) is a SWIGable module that makes it possible to access data stored in Numeric arrays as if they were normal C/C++ arrays( declared type name[][]; ).
+
+NumPtr was developed to make it possible to work with SWIG'ed C or Fortran climate codes from Python.
+
+This package is also a good example of how to write C extensions for Python that manipulate arrays.
+
+* Getting the Module *
+
+You can download the current version of the module here:
+(http://geosci.uchicago.edu/csc/numptr/)
+
+ * NumPtr 1.1 (Tarball)
+ * NumPtr 1.1 (Zip)
+ * NumPtr 1.1 (Windows Installer)
+
+* Requirements *
+
+ * Python 2.2+ (with Distutils!)
+ * C Compiler
+ * SWIG 1.3+
+
+This package was most recently tested with Python 2.3.3,
+GCC 3.4.1, and SWIG 1.3.21.
+
+* Compiling NumPtr *
+
+To compile NumPtr you simply have to invoke distutils build process:
+( $ represents the command prompt )
+
+ $ python setup.py build
+
+* Installing NumPtr *
+
+To install NumPtr with administrative privileges you must invoke distutils
+with the "install" option:
+
+ $ python setup.py install
+
+To install NumPtr into a different directory then the standard or to install
+it into a home directory (for non-administrators), you can set the "--prefix"
+or "--install-base" options when calling setup.py. For instance.
+
+ $ python setup.py install --prefix=/home/user
+
+Alternatively you can simply copy the files from build/lib.ARCH
+(where ARCH is your machines python version and operating system(kernel)
+version) to your chosen install location.
+
+ $ cp build/lib.linux-i686-2.3/* /home/user/python-libs/
+
+* Using the Module *
+
+* Getting Help *
+
+The Climate Systems Group @ U of C maintains a Wiki community site,
+if you have questions or comments about the Numeric Pointer module
+please ask there:
+
+ CSC Wiki (http://geodoc.uchicago.edu/climatewiki)
+
+© Mike Steder: Climate Systems Center, 2004
\ No newline at end of file
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/README.GRASS
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/README.GRASS (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/README.GRASS 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,60 @@
+Added for GRASS's SWIG interface, Hamish Bowman, 5 March 2008
+
+# NumPtr - Numeric Pointer Module for Python (GPL2)
+# Homepage: http://geosci.uchicago.edu/csc/numptr/
+# Tarball: http://geosci.uchicago.edu/csc/numptr/NumPtr-1.1.tar.gz
+# 23k .tgz ; 100k installed
+
+NumPtr is "a SWIGable module that makes it possible to access data stored
+in Numeric arrays as if they were normal C/C++ arrays. NumPtr was
+developed to make it possible to work with SWIG'ed C or Fortran climate
+codes from Python."
+
+
+How to build:
+ cd NumPtr
+ python setup.py build
+
+ Run "python build/lib.linux-i686-2.4/test.py" to test and to create
+ a byte-compiled version of the module (NumPtr.pyc). The .pyc file
+ is platform independent and may be safely shared among systems.
+ Even so, it doesn't hurt to do it ourselves to make sure we are using
+ an up to date copy.
+
+
+How to install:
+ Copy the fruits of the build into the same place as the GRASS SWIG
+ module (_python_grass6.so etc.). for example:
+
+ cp build/lib.linux-i686-2.4/*NumPtr.* ../
+ or to some place on your system:
+ python setup.py install --prefix=/home/user
+ or
+ If you prefer you can put it in a directory pointed to by the PYTHONPATH
+ environment variable, or use sys.path.append("/path/to/location/")
+ before you import the module.
+
+
+Tutorial:
+ http://www.penzilla.net/tutorials/python/numptr/
+ It is helpful have the Numeric python module (NumPy) installed too.
+ http://numpy.scipy.org/
+
+
+GRASS SWIG script example:
+ See the examples/m.distance
+
+
+Modifications from the upstream tarball:
+ * updated setup.py with current version number, upstream URL
+ * removed old backup versions of a few files
+ * removed binary lib/NumPtr.pyc. It will be automaticall regenerated (??)
+ * added this file, VERSION file
+
+
+TODO:
+ * incorporate the build into swig/python/Makefile, including byte-
+ compiling the .pyc file (by running build/lib.../test.py) and setting
+ an appropriate install destination. (use "setup.py install" to do the
+ install or use the common Makefile method for that?)
+
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/VERSION
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/VERSION (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/VERSION 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1 @@
+1.1
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/NumPtr.py
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/NumPtr.py (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/NumPtr.py 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,156 @@
+"""
+ Copyright 2003,2004 Christian Dieterich
+ rca at geosci.uchicago.edu
+ Department of the Geophysical Sciences, University of Chicago
+ 2003
+
+ The Numeric Pointer Module is free software; you can redistribute it
+ and/or modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ The Numeric Pointer Module 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 the Numeric Pointer Module; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+import _NumPtr
+
+def _swig_setattr(self,class_type,name,value):
+ if (name == "this"):
+ if isinstance(value, class_type):
+ self.__dict__[name] = value.this
+ if hasattr(value,"thisown"): self.__dict__["thisown"] = value.thisown
+ del value.thisown
+ return
+ method = class_type.__swig_setmethods__.get(name,None)
+ if method: return method(self,value)
+ self.__dict__[name] = value
+
+def _swig_getattr(self,class_type,name):
+ method = class_type.__swig_getmethods__.get(name,None)
+ if method: return method(self)
+ raise AttributeError,name
+
+import types
+try:
+ _object = types.ObjectType
+ _newclass = 1
+except AttributeError:
+ class _object : pass
+ _newclass = 0
+
+def getpointer(A):
+ """
+ Returns a SWIG pointer to the data in NumPy array object A.
+ Array can be 1, 2 or 3 dimensional and must be of type Float64,
+ Float32 or Int32.
+ """
+ if (len(A.shape) == 0):
+ if (A.typecode() == 'd'):
+ p = _NumPtr.getdpointer1(A)
+ elif (A.typecode() == 'f'):
+ p = _NumPtr.getfpointer1(A)
+ elif (A.typecode() == 'i'):
+ p = _NumPtr.getipointer1(A)
+ else:
+ raise TypeError, "Your array does not have typecode 'd', 'f' or 'i'."
+ return p
+ elif (len(A.shape) == 1):
+ if (A.typecode() == 'd'):
+ p = _NumPtr.getdpointer1(A)
+ elif (A.typecode() == 'f'):
+ p = _NumPtr.getfpointer1(A)
+ elif (A.typecode() == 'i'):
+ p = _NumPtr.getipointer1(A)
+ else:
+ raise TypeError, "Your array does not have typecode 'd', 'f' or 'i'."
+ return p
+ elif (len(A.shape) == 2):
+ if (A.typecode() == 'd'):
+ p = _NumPtr.getdpointer2(A)
+ elif (A.typecode() == 'f'):
+ p = _NumPtr.getfpointer2(A)
+ elif (A.typecode() == 'i'):
+ p = _NumPtr.getipointer2(A)
+ else:
+ raise TypeError, "Your array does not have typecode 'd', 'f' or 'i'."
+ return p
+ elif (len(A.shape) == 3):
+ if (A.typecode() == 'd'):
+ p = _NumPtr.getdpointer3(A)
+ elif (A.typecode() == 'f'):
+ p = _NumPtr.getfpointer3(A)
+ elif (A.typecode() == 'i'):
+ p = _NumPtr.getipointer3(A)
+ else:
+ raise TypeError, "Your array does not have typecode 'd', 'f' or 'i'."
+ return p
+ else:
+ raise TypeError, "Your array has rank > 3."
+
+def verifypointer(Aptr, n=0, m=None, l=None):
+ """
+ Prints the data in NumPy array object A, where Aptr points to.
+ Array can be 1, 2 or 3 dimensional and must be of type Float64,
+ Float32 or Int32.
+ """
+ if (Aptr.count('_p') == 0):
+ if (Aptr.count('_double') == 1):
+ p = _NumPtr.testd1(Aptr, n)
+ elif (Aptr.count('_float') == 1):
+ p = _NumPtr.testf1(Aptr, n)
+ elif (Aptr.count('_int') == 1):
+ p = _NumPtr.testi1(Aptr, n)
+ else:
+ raise TypeError, "Your array does not have typecode 'd', 'f' or 'i'."
+ return p
+ elif (Aptr.count('_p') == 1):
+ if (Aptr.count('_double') == 1):
+ p = _NumPtr.testd1(Aptr, n)
+ elif (Aptr.count('_float') == 1):
+ p = _NumPtr.testf1(Aptr, n)
+ elif (Aptr.count('_int') == 1):
+ p = _NumPtr.testi1(Aptr, n)
+ else:
+ raise TypeError, "Your array does not have typecode 'd', 'f' or 'i'."
+ return p
+ elif (Aptr.count('_p') == 2):
+ if m == None: m = 0
+ if (Aptr.count('_double') == 1):
+ p = _NumPtr.testd2(Aptr, n, m)
+ elif (Aptr.count('_float') == 1):
+ p = _NumPtr.testf2(Aptr, n, m)
+ elif (Aptr.count('_int') == 1):
+ p = _NumPtr.testi2(Aptr, n, m)
+ else:
+ raise TypeError, "Your array does not have typecode 'd', 'f' or 'i'."
+ return p
+ elif (Aptr.count('_p') == 3):
+ if m == None: m = 0
+ if l == None: l = 0
+ if (Aptr.count('_double') == 1):
+ p = _NumPtr.testd3(Aptr, n, m, l)
+ elif (Aptr.count('_float') == 1):
+ p = _NumPtr.testf3(Aptr, n, m, l)
+ elif (Aptr.count('_int') == 1):
+ p = _NumPtr.testi3(Aptr, n, m, l)
+ else:
+ raise TypeError, "Your array does not have typecode 'd', 'f' or 'i'."
+ return p
+ else:
+ raise TypeError, "Your array has rank greater than 3."
+
+def getpointer1(A):
+ return getpointer(A)
+
+def getpointer2(A):
+ return getpointer(A)
+
+def getpointer3(A):
+ return getpointer(A)
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/__init__.py
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/__init__.py (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/__init__.py 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,2 @@
+from NumPtr import getpointer
+from NumPtr import verifypointer
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/test.py
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/test.py (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/lib/test.py 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,79 @@
+from Numeric import *
+from NumPtr import *
+from _NumPtr import *
+
+a = array([1,2,3,4,5,6],Float64)
+print a
+p=getpointer(a)
+print p
+test1(p,6)
+
+a = array([[1,2,3],[4,5,6]],Float64)
+print a
+p=getpointer(a)
+print p
+test2(p,2,3)
+
+a = array([ [[1,2,3],[4,5,6]] , [[7,8,9],[10,11,12]] ],Float64)
+print a
+print len(a.shape)
+p=getpointer(a)
+print p
+test3(p,2,2,3)
+
+a = array([1,2,3,4,5,6],Float64)
+print a
+p=getpointer(a)
+print p
+testd1(p,6)
+
+a = array([[1,2,3],[4,5,6]],Float64)
+print a
+p=getpointer(a)
+print p
+testd2(p,2,3)
+
+a = array([ [[1,2,3],[4,5,6]] , [[7,8,9],[10,11,12]] ],Float64)
+print a
+print len(a.shape)
+p=getpointer(a)
+print p
+testd3(p,2,2,3)
+
+a = array([1,2,3,4,5,6],Float32)
+print a
+p=getpointer(a)
+print p
+testf1(p,6)
+
+a = array([[1,2,3],[4,5,6]],Float32)
+print a
+p=getpointer(a)
+print p
+testf2(p,2,3)
+
+a = array([ [[1,2,3],[4,5,6]] , [[7,8,9],[10,11,12]] ],Float32)
+print a
+print len(a.shape)
+p=getpointer(a)
+print p
+testf3(p,2,2,3)
+
+a = array([1,2,3,4,5,6],Int32)
+print a
+p=getpointer(a)
+print p
+testi1(p,6)
+
+a = array([[1,2,3],[4,5,6]],Int32)
+print a
+p=getpointer(a)
+print p
+testi2(p,2,3)
+
+a = array([ [[1,2,3],[4,5,6]] , [[7,8,9],[10,11,12]] ],Int32)
+print a
+print len(a.shape)
+p=getpointer(a)
+print p
+testi3(p,2,2,3)
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/readme.html
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/readme.html (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/readme.html 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,82 @@
+<html>
+<head>
+<title>Numeric Pointer Module v1.1</title>
+</head>
+<body>
+
+<H1><font color="blue">Numeric Pointer Module</font></H1>
+<H4><P>
+ Written by: Rodrigo Caballero Augi (<a href="mailto://rca@geosci.uchicago.edu">rca at geosci.uchicago.edu</a>),<br>
+
+ Updated: Christian Dieterich (<a href="mailto://cdieterich@geosci.uchicago.edu">cdieterich at geosci.uchicago.edu</a>),<br>
+ Packaged: Michael Steder (<a href="mailto://steder@gmail.com">steder at gmail.com</a>)<br>
+ <a href="http://geosci.uchicago.edu">Department of Geophysical Sciences, University of Chicago</a><br>
+ 2004<br>
+</H4>
+<H2><font color="green">Introduction:</font></H2>
+
+ <P>The Numeric Pointer module (NumPtr) is a SWIGable module that makes it possible to access
+data stored in <a href="http://www.pfdubois.com/numpy/">Numeric arrays</a> as if they were normal C/C++ arrays( declared <i>type name[][];</i> ).
+
+ <P>NumPtr was developed to make it possible to work with SWIG'ed C or Fortran climate codes from Python.
+
+ <P>This package is also a good example of how to write C extensions for Python that manipulate arrays.
+
+<H2><font color="green">Getting the Module</font></H2>
+ <P>You can download the current version of the module here:
+ <ul><b>
+ <li><a href="numptr-1.1.tar.gz">NumPtr 1.1 (Tarball)</a></li>
+ <li><a href="numptr-1.1.zip">NumPtr 1.1 (Zip)</a></li>
+ <li><a href="numptr-1.1.exe">NumPtr 1.1 (Windows Installer)</a></li>
+ </b></ul>
+
+<H2><font color="green">Requirements</font></H2>
+ <P><ul>
+ <li>Python 2.2+ (with Distutils!)</li>
+ <li>C Compiler</li>
+ <li>SWIG 1.3+</li>
+ </ul>
+ <P>
+ This package was most recently tested with Python 2.3.3, GCC 3.4.1, and SWIG 1.3.21.
+
+<H2><font color="green">Compiling NumPtr</font></H2>
+
+ <P>To compile NumPtr you simply have to invoke distutils build process:
+ ( $ represents the command prompt )
+
+ <ul><b>
+ $ python setup.py build
+ </b></ul>
+
+<H2><font color="green">Installing NumPtr</font></H2>
+ <P>To install NumPtr with administrative privileges you must invoke distutils with the "install" option:
+ <ul><b>
+ $ python setup.py install
+ </b></ul>
+
+ <P>To install NumPtr into a different directory then the standard or to install it into a home directory (for non-administrators), you can set the "--prefix" or "--install-base" options when calling setup.py. For instance.
+ <ul><b>
+ $ python setup.py install --prefix=/home/user
+ </b></ul>
+
+ <P>Alternatively you can simply copy the files from build/lib.ARCH (where ARCH is your machines python version and operating system(kernel) version) to your chosen install location.
+ <ul><b>
+ $ cp build/lib.linux-i686-2.3/* /home/user/python-libs/
+ </b></ul>
+
+<H2><font color="green">Using the Module</font></H2>
+ <P>
+
+<H2><font color="green">Getting Help</font></H2>
+ <P>The Climate Systems Group @ U of C maintains a Wiki community site, if you have questions or comments about the Numeric Pointer module please ask there:
+ <ul><b>
+ <a href="http://geodoc.uchicago.edu/climatewiki">CSC Wiki</a>
+ </b></ul>
+
+</body>
+<footer>
+<hr>
+© Mike Steder: Climate Systems Center, 2004
+</footer>
+</html>
+
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/setup.py
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/setup.py (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/setup.py 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,45 @@
+import os, glob
+
+# Gather up all the files we need.
+
+files = ["src/getpointer.c","src/test.c"]
+files += glob.glob("src/NumPtr.i")
+
+## pfiles = glob.glob("*.py")
+## i = 0
+## while i < len(pfiles):
+## pfiles[i] = os.path.splitext(pfiles[i])[0]
+## i += 1
+
+## Distutils Script
+from distutils.core import setup, Extension
+
+# Some useful directories.
+from distutils.sysconfig import get_python_inc, get_python_lib
+
+python_incdir = os.path.join( get_python_inc(plat_specific=1) )
+python_libdir = os.path.join( get_python_lib(plat_specific=1) )
+
+setup(name="NumPtr",
+ version="1.1",
+ description="Numeric Pointer module",
+ author="Rodrigo Caballero",
+ author_email="rca at geosci.uchicago.edu",
+ maintainer="Mike Steder",
+ maintainer_email="steder at gmail.com",
+ url="http://geosci.uchicago.edu/csc/numptr/",
+ ext_modules = [Extension('_NumPtr',
+ files,
+ include_dirs=[python_incdir],
+ library_dirs=[python_libdir],
+ ),
+ ],
+ # Install these to their own directory
+ # *I want to be able to remove them if I screw up this script
+ # *"Sandboxing", if you will
+ extra_path = 'NumPtr',
+ package_dir={'':'lib'},
+ py_modules=["NumPtr","test"],
+ license="GNU GPL",
+
+ )
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/src/Makefile
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/src/Makefile (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/src/Makefile 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,54 @@
+# Makes SWIGed Python module
+
+# Rodrigo Caballero (rca at geosci.uchicago.edu),
+# Department of the Geophysical Sciences, University of Chicago
+# October 2003
+
+name := NumPtr
+
+ifeq ($(MAKELEVEL),0)
+ CC := pgcc
+ F90 := pgf90
+ PYTHONINC := /usr/include/python2.2
+# PYTHONINC := /sw/include/python2.3
+ CCFLAGS :=
+ F90FLAGS := -r8
+ LDFLAGS := -Mnomain -shared
+ SWIG := /home/rca/bin/swig
+# SWIG := swig
+endif
+
+OS = $(shell uname -s)
+ifeq ($(OS),Darwin)
+ CC := cc
+ CCFLAGS := -fno-common
+ F90 := cc
+ LDFLAGS := -bundle -flat_namespace -undefined suppress
+ SWIG := swig
+endif
+
+%.o : %.c
+ $(CC) $(CCFLAGS) -c -I$(PYTHONINC) -o $@ $<
+
+%.o : %.f
+ $(F90) $(F90FLAGS) -c -o $@ $<
+
+SRC := $(wildcard *.f *.c)
+OBJ := $(SRC:.f=.o)
+OBJ := $(OBJ:.c=.o)
+ifeq (,$(findstring $(name)_wrap.o,$(OBJ)))
+ wrapper := $(name)_wrap.o
+endif
+
+_$(name)_lib.so : $(OBJ) $(name)_wrap.o
+ $(F90) $(LDFLAGS) -o $@ $(OBJ) $(wrapper)
+
+$(name)_wrap.o: $(name).i
+ $(SWIG) -python $(name).i
+ $(CC) -c -I$(PYTHONINC) -o $(name)_wrap.o $(name)_wrap.c
+
+clean:
+ rm -f $(OBJ) *.so *_wrap.* *.pyc *_lib.*
+
+test:
+ python test.py
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/src/NumPtr.i
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/src/NumPtr.i (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/src/NumPtr.i 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,61 @@
+/*
+ Copyright 2003,2004 Rodrigo Caballero Augi
+ rca at geosci.uchicago.edu
+ Department of the Geophysical Sciences, University of Chicago
+ 2003
+
+ This file is part of the Numeric Pointer Module.
+
+ The Numeric Pointer Module is free software; you can redistribute it
+ and/or modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ The Numeric Pointer Module 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 the Numeric Pointer Module; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+%module NumPtr
+
+%{
+#include "getpointer.h"
+#include "test.h"
+%}
+
+double * getpointer1(PyObject *array);
+double ** getpointer2(PyObject *array);
+double *** getpointer3(PyObject *array);
+
+double * getdpointer1(PyObject *array);
+double ** getdpointer2(PyObject *array);
+double *** getdpointer3(PyObject *array);
+
+float * getfpointer1(PyObject *array);
+float ** getfpointer2(PyObject *array);
+float *** getfpointer3(PyObject *array);
+
+int * getipointer1(PyObject *array);
+int ** getipointer2(PyObject *array);
+int *** getipointer3(PyObject *array);
+
+void test1(double * a, int n);
+void test2(double ** a, int n, int m);
+void test3(double *** a, int n, int m, int l);
+
+void testd1(double * a, int n);
+void testd2(double ** a, int n, int m);
+void testd3(double *** a, int n, int m, int l);
+
+void testf1(float * a, int n);
+void testf2(float ** a, int n, int m);
+void testf3(float *** a, int n, int m, int l);
+
+void testi1(int * a, int n);
+void testi2(int ** a, int n, int m);
+void testi3(int *** a, int n, int m, int l);
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/src/getpointer.c
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/src/getpointer.c (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/src/getpointer.c 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,147 @@
+#include "Python.h"
+#include "Numeric/arrayobject.h"
+#include "getpointer.h"
+
+double * getpointer1(PyObject *A){
+ PyArrayObject * array;
+ array= (PyArrayObject *) A;
+ return (double *) (array->data);
+}
+
+double ** getpointer2(PyObject *A){
+ PyArrayObject * array;
+ int imax,i;
+ double ** p=NULL;
+ array = (PyArrayObject *) A;
+ imax = array->dimensions[0];
+ p = (double **) calloc(imax,sizeof(double *));
+ for (i=0; i<imax; i++){
+ p[i]=(double *)(array->data + i*array->strides[0]);
+ }
+ return p;
+}
+
+double *** getpointer3(PyObject *A){
+ PyArrayObject * array;
+ int imax,jmax,i,j;
+ double *** p=NULL;
+ array = (PyArrayObject *) A;
+ imax = array->dimensions[0];
+ jmax = array->dimensions[1];
+ p = (double ***) calloc(imax,sizeof(double **));
+ for (i=0; i<imax; i++){
+ p[i]=(double **) calloc(jmax,sizeof(double *));
+ for (j=0; j<jmax; j++){
+ p[i][j]=(double *)(array->data + i*array->strides[0] + j*array->strides[1]);
+ }
+ }
+ return p;
+}
+
+double * getdpointer1(PyObject *A){
+ PyArrayObject * array;
+ array= (PyArrayObject *) A;
+ return (double *) (array->data);
+}
+
+double ** getdpointer2(PyObject *A){
+ PyArrayObject * array;
+ int imax,i;
+ double ** p=NULL;
+ array = (PyArrayObject *) A;
+ imax = array->dimensions[0];
+ p = (double **) calloc(imax,sizeof(double *));
+ for (i=0; i<imax; i++){
+ p[i]=(double *)(array->data + i*array->strides[0]);
+ }
+ return p;
+}
+
+double *** getdpointer3(PyObject *A){
+ PyArrayObject * array;
+ int imax,jmax,i,j;
+ double *** p=NULL;
+ array = (PyArrayObject *) A;
+ imax = array->dimensions[0];
+ jmax = array->dimensions[1];
+ p = (double ***) calloc(imax,sizeof(double **));
+ for (i=0; i<imax; i++){
+ p[i]=(double **) calloc(jmax,sizeof(double *));
+ for (j=0; j<jmax; j++){
+ p[i][j]=(double *)(array->data + i*array->strides[0] + j*array->strides[1]);
+ }
+ }
+ return p;
+}
+
+float * getfpointer1(PyObject *A){
+ PyArrayObject * array;
+ array= (PyArrayObject *) A;
+ return (float *) (array->data);
+}
+
+float ** getfpointer2(PyObject *A){
+ PyArrayObject * array;
+ int imax,i;
+ float ** p=NULL;
+ array = (PyArrayObject *) A;
+ imax = array->dimensions[0];
+ p = (float **) calloc(imax,sizeof(float *));
+ for (i=0; i<imax; i++){
+ p[i]=(float *)(array->data + i*array->strides[0]);
+ }
+ return p;
+}
+
+float *** getfpointer3(PyObject *A){
+ PyArrayObject * array;
+ int imax,jmax,i,j;
+ float *** p=NULL;
+ array = (PyArrayObject *) A;
+ imax = array->dimensions[0];
+ jmax = array->dimensions[1];
+ p = (float ***) calloc(imax,sizeof(float **));
+ for (i=0; i<imax; i++){
+ p[i]=(float **) calloc(jmax,sizeof(float *));
+ for (j=0; j<jmax; j++){
+ p[i][j]=(float *)(array->data + i*array->strides[0] + j*array->strides[1]);
+ }
+ }
+ return p;
+}
+
+int * getipointer1(PyObject *A){
+ PyArrayObject * array;
+ array= (PyArrayObject *) A;
+ return (int *) (array->data);
+}
+
+int ** getipointer2(PyObject *A){
+ PyArrayObject * array;
+ int imax,i;
+ int ** p=NULL;
+ array = (PyArrayObject *) A;
+ imax = array->dimensions[0];
+ p = (int **) calloc(imax,sizeof(int *));
+ for (i=0; i<imax; i++){
+ p[i]=(int *)(array->data + i*array->strides[0]);
+ }
+ return p;
+}
+
+int *** getipointer3(PyObject *A){
+ PyArrayObject * array;
+ int imax,jmax,i,j;
+ int *** p=NULL;
+ array = (PyArrayObject *) A;
+ imax = array->dimensions[0];
+ jmax = array->dimensions[1];
+ p = (int ***) calloc(imax,sizeof(int **));
+ for (i=0; i<imax; i++){
+ p[i]=(int **) calloc(jmax,sizeof(int *));
+ for (j=0; j<jmax; j++){
+ p[i][j]=(int *)(array->data + i*array->strides[0] + j*array->strides[1]);
+ }
+ }
+ return p;
+}
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/src/getpointer.h
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/src/getpointer.h (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/src/getpointer.h 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,12 @@
+double * getpointer1(PyObject *A);
+double ** getpointer2(PyObject *A);
+double *** getpointer3(PyObject *A);
+double * getdpointer1(PyObject *A);
+double ** getdpointer2(PyObject *A);
+double *** getdpointer3(PyObject *A);
+float * getfpointer1(PyObject *A);
+float ** getfpointer2(PyObject *A);
+float *** getfpointer3(PyObject *A);
+int * getipointer1(PyObject *A);
+int ** getipointer2(PyObject *A);
+int *** getipointer3(PyObject *A);
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/src/test.c
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/src/test.c (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/src/test.c 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,107 @@
+void test1(double * a, int n){
+ int i;
+ for (i=0; i<n ; i++){
+ printf("%f\n",a[i]);
+ }
+}
+
+void test2(double ** a, int n, int m){
+ int i,j;
+ for (i=0; i<n ; i++){
+ for (j=0; j<m ; j++){
+ printf("%i %i\t %f\n",i,j,a[i][j]);
+ }
+}
+}
+
+void test3(double *** a, int n, int m, int l){
+ int i,j,k;
+ for (i=0; i<n ; i++){
+ for (j=0; j<m ; j++){
+ for (k=0; k<l ; k++){
+ printf("%i %i %i\t %f\n",i,j,k,a[i][j][k]);
+ }
+}
+}
+}
+
+void testd1(double * a, int n){
+ int i;
+ for (i=0; i<n ; i++){
+ printf("%f\n",a[i]);
+ }
+}
+
+void testd2(double ** a, int n, int m){
+ int i,j;
+ for (i=0; i<n ; i++){
+ for (j=0; j<m ; j++){
+ printf("%i %i\t %f\n",i,j,a[i][j]);
+ }
+}
+}
+
+void testd3(double *** a, int n, int m, int l){
+ int i,j,k;
+ for (i=0; i<n ; i++){
+ for (j=0; j<m ; j++){
+ for (k=0; k<l ; k++){
+ printf("%i %i %i\t %f\n",i,j,k,a[i][j][k]);
+ }
+}
+}
+}
+
+void testf1(float * a, int n){
+ int i;
+ for (i=0; i<n ; i++){
+ printf("%f\n",a[i]);
+ }
+}
+
+void testf2(float ** a, int n, int m){
+ int i,j;
+ for (i=0; i<n ; i++){
+ for (j=0; j<m ; j++){
+ printf("%i %i\t %f\n",i,j,a[i][j]);
+ }
+}
+}
+
+void testf3(float *** a, int n, int m, int l){
+ int i,j,k;
+ for (i=0; i<n ; i++){
+ for (j=0; j<m ; j++){
+ for (k=0; k<l ; k++){
+ printf("%i %i %i\t %f\n",i,j,k,a[i][j][k]);
+ }
+}
+}
+}
+
+void testi1(int * a, int n){
+ int i;
+ for (i=0; i<n ; i++){
+ printf("%i\n",a[i]);
+ }
+}
+
+void testi2(int ** a, int n, int m){
+ int i,j;
+ for (i=0; i<n ; i++){
+ for (j=0; j<m ; j++){
+ printf("%i %i\t %i\n",i,j,a[i][j]);
+ }
+}
+}
+
+void testi3(int *** a, int n, int m, int l){
+ int i,j,k;
+ for (i=0; i<n ; i++){
+ for (j=0; j<m ; j++){
+ for (k=0; k<l ; k++){
+ printf("%i %i %i\t %i\n",i,j,k,a[i][j][k]);
+ }
+}
+}
+}
Added: grass/branches/releasebranch_6_3/swig/python/NumPtr/src/test.h
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/NumPtr/src/test.h (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/NumPtr/src/test.h 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,12 @@
+void test1(double * a, int n);
+void test2(double ** a, int n, int m);
+void test3(double *** a, int n, int m, int l);
+void testd1(double * a, int n);
+void testd2(double ** a, int n, int m);
+void testd3(double *** a, int n, int m, int l);
+void testf1(float * a, int n);
+void testf2(float ** a, int n, int m);
+void testf3(float *** a, int n, int m, int l);
+void testi1(int * a, int n);
+void testi2(int ** a, int n, int m);
+void testi3(int *** a, int n, int m, int l);
Modified: grass/branches/releasebranch_6_3/swig/python/README
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/README 2008-03-19 10:14:02 UTC (rev 30632)
+++ grass/branches/releasebranch_6_3/swig/python/README 2008-03-19 10:31:36 UTC (rev 30633)
@@ -5,17 +5,29 @@
Currently only a limited set of functions (those needed for
me) are wrapped.
+
How to INSTALL?
---------------
-1. Install SWIG
+1. Install SWIG, the Simplified Wrapper and Interface Generator
+ http://www.swig.org
-2. Edit the Makefile
- - set python version
+2. Be sure you configured GRASS with support for Python:
+ ./configure --with-python=/usr/bin/python2.5-config
-3. Run make
+3. Run make in the swig/python/ directory
It will create two files, python_grass6.py and _python_grass6.so.
+4. From within GRASS (or a fake grass session) run "python test.py" to
+ test and to automatically create a byte-compiled version of the module
+ (python_grass6.pyc). The .pyc file is platform independent and may be
+ safely shared among systems. Even so, it doesn't hurt to rebuild it
+ ourselves while we still have write permissions and to make sure we
+ are using an up to date copy. (out of date copies will be ignored)
+
+5. It is useful to build the NumPtr module as well.
+ - see README.GRASS in that directory for instructions
+
How to use it?
--------------
@@ -26,6 +38,12 @@
mapset=python_grass6.G_mapset()
print mapset
+See examples/m.distance for an example of a working SWIG-Python module.
+
+More examples can be found on the GRASS Wiki site's Python page:
+ http://grass.gdf-hannover.de/wiki/GRASS_and_Python#Python-SWIG-GRASS_interface
+
+
DEBUGGING
----------
@@ -39,6 +57,7 @@
-----
See TODO in this directory.
+
AUTHOR
-----
Added: grass/branches/releasebranch_6_3/swig/python/examples/m.distance
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/examples/m.distance (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/examples/m.distance 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,202 @@
+#!/usr/bin/python
+############################################################################
+#
+# MODULE: m.distance
+#
+# AUTHOR(S): Hamish Bowman, Dunedin, New Zealand
+#
+# PURPOSE: Find distance between two points
+# If the projection is latitude-longitude, this distance
+# is measured along the geodesic.
+# Demonstrates GRASS SWIG-Python interface
+#
+# COPYRIGHT: (c) 2008 Hamish Bowman, and The GRASS Development Team
+#
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
+#
+############################################################################
+#
+# Requires GRASS SWIG-Python interface
+# Requires Numeric module (NumPy) from http://numpy.scipy.org/
+# Requires NumPrt module from http://geosci.uchicago.edu/csc/numptr/
+#
+
+#%Module
+#% label: Finds the distance between two or more points.
+#% description: If the projection is latitude-longitude, this distance is measured along the geodesic.
+#% keywords: miscellaneous, distance, measure
+#%End
+#%Option
+#% key: coord
+#% type: string
+#% required: no
+#% multiple: yes
+#% key_desc: x,y
+#% description: Comma separated list of coordinate pairs
+#%End
+#%Flag
+#% key: i
+#% description: Read coordinate pairs from stdin
+#%End
+
+
+import os, sys
+
+if not os.environ.has_key("GISBASE"):
+ print "You must be in GRASS GIS to run this program."
+ sys.exit(1)
+
+
+def main():
+
+ #### add your code here ####
+
+ # run this before starting python to append module search path:
+ # export PYTHONPATH=/usr/src/grass63/swig/python
+ # check with "import sys; sys.path"
+ # or:
+ sys.path.append("/usr/src/grass63/swig/python")
+ # FIXME: install the g6lib.py bindings in $GISBASE/lib/ ?
+ import python_grass6 as g6lib
+
+ # for passing pointers
+ import Numeric
+ import NumPtr
+
+ g6lib.G_gisinit('m.distance')
+ # returns 0 on success
+
+
+ ### calc distance ###
+
+ proj_type = g6lib.G_begin_distance_calculations()
+ # returns 0 if projection has no metrix (ie. imagery)
+ # returns 1 if projection is planimetric
+ # returns 2 if projection is latitude-longitude
+
+
+ # parser always creates at least an empty variable, and sys.argv is
+ # toast, so no way to check if option was given. So it hangs if
+ # --q was the only option given and there is no data from stdin.
+ coord_ans = os.getenv("GIS_OPT_COORD")
+ stdin_flag = bool(int(os.getenv("GIS_FLAG_I")))
+
+ if stdin_flag is True:
+ coords = []
+ # read line by line from stdin
+ while 1:
+ line = sys.stdin.readline().strip()
+ if not line: # EOF
+ break
+ else:
+ coords += line.split(',')
+ else:
+ # read from coord= command line option
+ coords = coord_ans.split(',')
+
+
+ if len(coords) < 4:
+ print "A minimum of two input coordinate pairs are needed"
+ return
+
+
+ # init variables
+ overall_distance = 0.0
+
+ if proj_type == 2:
+ # lat/lon scan for DDD:MM:SS.SSSS
+ easting = Numeric.array(0., Numeric.Float64)
+ eastPtr = NumPtr.getpointer(easting)
+ northing = Numeric.array(0., Numeric.Float64)
+ northPtr = NumPtr.getpointer(northing)
+
+ # TODO: for clarity, figure out how to replace "3" with
+ # the defined LOCATION_LL constant from gis.i
+ g6lib.G_scan_easting(coords[0], eastPtr, 3)
+ g6lib.G_scan_northing(coords[1], northPtr, 3)
+ x1 = float(easting)
+ y1 = float(northing)
+ else:
+ # plain old coordinates
+ x1 = float(coords[0])
+ y1 = float(coords[1])
+
+ x = [x1]
+ y = [y1]
+
+ for i in range(1, (len(coords) / 2)):
+
+ if proj_type == 2:
+ g6lib.G_scan_easting (coords[ i*2 + 0 ], eastPtr, 3)
+ g6lib.G_scan_northing(coords[ i*2 + 1 ], northPtr, 3)
+ x2 = float(easting)
+ y2 = float(northing)
+ else:
+ x2 = float(coords[ i*2 + 0 ])
+ y2 = float(coords[ i*2 + 1 ])
+
+ segment_distance = g6lib.G_distance(x1, y1, x2, y2)
+ overall_distance += segment_distance
+
+ print "segment %d distance is %.2f meters" % (i, segment_distance)
+
+ # add to the area array
+
+ # setup for the next loop
+ x1 = x2
+ y1 = y2
+
+ x += [x2]
+ y += [y2]
+
+ print
+ print " total distance is %.2f meters" % overall_distance
+ print
+
+
+ ### calc area ###
+ if len(coords) < 6:
+ return
+
+ g6lib.G_begin_polygon_area_calculations()
+ # returns 0 if the projection is not measurable (ie. imagery or xy)
+ # returns 1 if the projection is planimetric (ie. UTM or SP)
+ # returns 2 if the projection is non-planimetric (ie. latitude-longitude)
+
+ # do not need to close polygon (but it doesn't hurt if you do)
+ npoints = len(x)
+
+ # unset variables:
+ #del [Xs, Xptr, Ys, Yptr]
+ # or
+ #Xs = Xptr = Ys = Yptr = None
+
+ Xs = Numeric.array(x, Numeric.Float64)
+ Xptr = NumPtr.getpointer(Xs)
+ Ys = Numeric.array(y, Numeric.Float64)
+ Yptr = NumPtr.getpointer(Ys)
+
+ area = g6lib.G_area_of_polygon(Xptr, Yptr, npoints)
+ print "AREA: %10.2f square meters" % area
+ print
+
+
+ # we don't need this, but just to have a look
+ if False:
+ if proj_type == 1:
+ g6lib.G_database_units_to_meters_factor()
+ # 1.0
+ print "Location units are", g6lib.G_database_unit_name(True)
+
+
+ #### end of your code ####
+ return
+
+if __name__ == "__main__":
+ if ( len(sys.argv) <= 1 or sys.argv[1] != "@ARGS_PARSED@" ):
+ os.execvp("g.parser", [sys.argv[0]] + sys.argv)
+ else:
+ main();
+
Property changes on: grass/branches/releasebranch_6_3/swig/python/examples/m.distance
___________________________________________________________________
Name: svn:executable
+ *
Copied: grass/branches/releasebranch_6_3/swig/python/examples/rasteraccess.py (from rev 30632, grass/branches/releasebranch_6_3/swig/python/rasteraccess.py)
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/examples/rasteraccess.py (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/examples/rasteraccess.py 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+# run within GRASS Spearfish session
+
+import os, sys
+import python_grass6 as g6lib
+
+if not os.environ.has_key("GISBASE"):
+ print "You must be in GRASS GIS to run this program."
+ sys.exit(1)
+
+input = 'elevation.dem'
+mapset = 'PERMANENT'
+
+g6lib.G_gisinit('')
+infd = g6lib.G_open_cell_old(input, mapset)
+
+cell = g6lib.G_allocate_cell_buf()
+
+rown=0
+while 1:
+ myrow = g6lib.G_get_map_row_nomask(infd, cell, rown)
+ print rown,myrow[0:10]
+ rown = rown+1
+ if rown==476:break
+
+g6lib.G_close_cell(infd)
+g6lib.G_free(cell)
Copied: grass/branches/releasebranch_6_3/swig/python/examples/vectoraccess.py (from rev 30632, grass/branches/releasebranch_6_3/swig/python/vectoraccess.py)
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/examples/vectoraccess.py (rev 0)
+++ grass/branches/releasebranch_6_3/swig/python/examples/vectoraccess.py 2008-03-19 10:31:36 UTC (rev 30633)
@@ -0,0 +1,47 @@
+#!/usr/bin/python
+
+# run within GRASS Spearfish session
+
+import os, sys
+import python_grass6 as g6lib
+
+if not os.environ.has_key("GISBASE"):
+ print "You must be in GRASS GIS to run this program."
+ sys.exit(1)
+
+if len(sys.argv)==2:
+ input = sys.argv[1]
+else:
+ input = raw_input("Vector Map Name? ")
+
+mapset = 'PERMANENT'
+
+# initialize
+g6lib.G_gisinit('')
+
+# define map structure
+map = g6lib.Map_info()
+
+# define open level (level 2: topology)
+g6lib.Vect_set_open_level (2)
+
+# open existing map
+g6lib.Vect_open_old(map, input, mapset)
+
+# query
+print 'Vect map: ', input
+print 'Vect is 3D: ', g6lib.Vect_is_3d (map)
+print 'Vect DB links: ', g6lib.Vect_get_num_dblinks(map)
+print 'Map Scale: 1:', g6lib.Vect_get_scale(map)
+# misleading:
+# print 'Number of lines:', g6lib.Vect_get_num_lines(map)
+print 'Number of points: ', g6lib.Vect_get_num_primitives(map,g6lib.GV_POINT)
+# confusing:
+#print 'Number of lines: ', g6lib.Vect_get_num_primitives(map,g6lib.GV_LINE)
+#print 'Number of areas:', g6lib.Vect_get_num_primitives(map,g6lib.GV_AREA)
+print 'Number of areas:', g6lib.Vect_get_num_areas(map)
+
+# close map
+g6lib.Vect_close(map)
+## end of the python script
+
Deleted: grass/branches/releasebranch_6_3/swig/python/rasteraccess.py
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/rasteraccess.py 2008-03-19 10:14:02 UTC (rev 30632)
+++ grass/branches/releasebranch_6_3/swig/python/rasteraccess.py 2008-03-19 10:31:36 UTC (rev 30633)
@@ -1,28 +0,0 @@
-#!/usr/bin/python
-
-# run within GRASS Spearfish session
-
-import os, sys
-import python_grass6 as g6lib
-
-if not os.environ.has_key("GISBASE"):
- print "You must be in GRASS GIS to run this program."
- sys.exit(1)
-
-input = 'elevation.dem'
-mapset = 'PERMANENT'
-
-g6lib.G_gisinit('')
-infd = g6lib.G_open_cell_old(input, mapset)
-
-cell = g6lib.G_allocate_cell_buf()
-
-rown=0
-while 1:
- myrow = g6lib.G_get_map_row_nomask(infd, cell, rown)
- print rown,myrow[0:10]
- rown = rown+1
- if rown==476:break
-
-g6lib.G_close_cell(infd)
-g6lib.G_free(cell)
Deleted: grass/branches/releasebranch_6_3/swig/python/vectoraccess.py
===================================================================
--- grass/branches/releasebranch_6_3/swig/python/vectoraccess.py 2008-03-19 10:14:02 UTC (rev 30632)
+++ grass/branches/releasebranch_6_3/swig/python/vectoraccess.py 2008-03-19 10:31:36 UTC (rev 30633)
@@ -1,47 +0,0 @@
-#!/usr/bin/python
-
-# run within GRASS Spearfish session
-
-import os, sys
-import python_grass6 as g6lib
-
-if not os.environ.has_key("GISBASE"):
- print "You must be in GRASS GIS to run this program."
- sys.exit(1)
-
-if len(sys.argv)==2:
- input = sys.argv[1]
-else:
- input = raw_input("Vector Map Name? ")
-
-mapset = 'PERMANENT'
-
-# initialize
-g6lib.G_gisinit('')
-
-# define map structure
-map = g6lib.Map_info()
-
-# define open level (level 2: topology)
-g6lib.Vect_set_open_level (2)
-
-# open existing map
-g6lib.Vect_open_old(map, input, mapset)
-
-# query
-print 'Vect map: ', input
-print 'Vect is 3D: ', g6lib.Vect_is_3d (map)
-print 'Vect DB links: ', g6lib.Vect_get_num_dblinks(map)
-print 'Map Scale: 1:', g6lib.Vect_get_scale(map)
-# misleading:
-# print 'Number of lines:', g6lib.Vect_get_num_lines(map)
-print 'Number of points: ', g6lib.Vect_get_num_primitives(map,g6lib.GV_POINT)
-# confusing:
-#print 'Number of lines: ', g6lib.Vect_get_num_primitives(map,g6lib.GV_LINE)
-#print 'Number of areas:', g6lib.Vect_get_num_primitives(map,g6lib.GV_AREA)
-print 'Number of areas:', g6lib.Vect_get_num_areas(map)
-
-# close map
-g6lib.Vect_close(map)
-## end of the python script
-
More information about the grass-commit
mailing list