[pktools] 01/375: Initial import

Bas Couwenberg sebastic at xs4all.nl
Wed Dec 3 21:53:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

sebastic-guest pushed a commit to branch upstream-master
in repository pktools.

commit c0472d6ad12da667faff3e25a5386e01268307e7
Author: Pieter Kempeneers <kempenep at gmail.com>
Date:   Thu Aug 16 15:36:26 2012 +0200

    Initial import
---
 AUTHORS                           |    1 +
 COPYING                           |  675 ++++
 ChangeLog                         |   31 +
 INSTALL                           |   27 +
 Makefile.am                       |    9 +
 Makefile.in                       |  708 ++++
 NEWS                              |    0
 README                            |   17 +
 aclocal.m4                        | 1110 ++++++
 config.h.in                       |   73 +
 configure                         | 7213 +++++++++++++++++++++++++++++++++++++
 configure.ac                      |   90 +
 depcomp                           |  630 ++++
 install-sh                        |  520 +++
 m4/ax_lib_gdal.m4                 |  153 +
 missing                           |  376 ++
 src/algorithms/ConfusionMatrix.cc |  258 ++
 src/algorithms/ConfusionMatrix.h  |   81 +
 src/algorithms/Egcs.cc            |  208 ++
 src/algorithms/Egcs.h             |   57 +
 src/algorithms/Filter.cc          |   80 +
 src/algorithms/Filter.h           |  278 ++
 src/algorithms/Filter2d.cc        |  928 +++++
 src/algorithms/Filter2d.h         |  277 ++
 src/algorithms/Histogram.cc       |   63 +
 src/algorithms/Histogram.h        |  456 +++
 src/algorithms/Makefile.am        |   19 +
 src/algorithms/Makefile.in        |  513 +++
 src/algorithms/myfann_cpp.h       | 3670 +++++++++++++++++++
 src/apps/Makefile.am              |   45 +
 src/apps/Makefile.in              |  759 ++++
 src/apps/pkascii2img.cc           |  168 +
 src/apps/pkclassify_nn.cc         |  941 +++++
 src/apps/pkclassify_nn.h          |  131 +
 src/apps/pkcreatect.cc            |  207 ++
 src/apps/pkcrop.cc                |  475 +++
 src/apps/pkdiff.cc                |  732 ++++
 src/apps/pkdumpimg.cc             |  320 ++
 src/apps/pkdumpogr.cc             |  202 ++
 src/apps/pkdumpogr.h              |  131 +
 src/apps/pkegcs.cc                |  108 +
 src/apps/pkextract.cc             | 2196 +++++++++++
 src/apps/pkfillnodata.cc          |  152 +
 src/apps/pkfilter.cc              |  320 ++
 src/apps/pkgetmask.cc             |  184 +
 src/apps/pkinfo.cc                |  424 +++
 src/apps/pklas2img.cc             |  516 +++
 src/apps/pkmosaic.cc              |  899 +++++
 src/apps/pkndvi.cc                |  278 ++
 src/apps/pkpolygonize.cc          |  115 +
 src/apps/pkreclass.cc             |  368 ++
 src/apps/pksetmask.cc             |  338 ++
 src/apps/pksieve.cc               |  116 +
 src/apps/pkstat.cc                |  255 ++
 src/apps/pkstatogr.cc             |  118 +
 src/base/Makefile.am              |   26 +
 src/base/Makefile.in              |  515 +++
 src/base/Optionpk.h               |  267 ++
 src/base/PointData.cc             |   28 +
 src/base/PointData.h              |   51 +
 src/base/PosValue.h               |   47 +
 src/base/Vector2d.h               |  294 ++
 src/fileclasses/FileReaderLas.cc  |  140 +
 src/fileclasses/FileReaderLas.h   |   60 +
 src/fileclasses/Makefile.am       |   19 +
 src/fileclasses/Makefile.in       |  507 +++
 src/imageclasses/ImgReaderGdal.cc |  452 +++
 src/imageclasses/ImgReaderGdal.h  |  247 ++
 src/imageclasses/ImgReaderOgr.cc  |  230 ++
 src/imageclasses/ImgReaderOgr.h   |  718 ++++
 src/imageclasses/ImgWriterGdal.cc |  546 +++
 src/imageclasses/ImgWriterGdal.h  |  211 ++
 src/imageclasses/ImgWriterOgr.cc  |  540 +++
 src/imageclasses/ImgWriterOgr.h   |   80 +
 src/imageclasses/Makefile.am      |   19 +
 src/imageclasses/Makefile.in      |  512 +++
 76 files changed, 34528 insertions(+)

diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..9f79234
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Pieter kempeneers (kempenep at gmail.com)
\ No newline at end of file
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..10926e8
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,675 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ 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.
+
+    <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 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 <http://www.gnu.org/licenses/>.
+
+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:
+
+    <program>  Copyright (C) <year>  <name of author>
+    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
+<http://www.gnu.org/licenses/>.
+
+  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
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+
diff --git a/ChangeLog b/ChangeLog
new file mode 100755
index 0000000..28af616
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,31 @@
+version 1.0
+
+ - First release
+
+version 2.1
+ - Introduction of configure options
+	--with-fann (when FANN is installed, needed for pkclassify_nn)
+	--with-las (when LIBLAS is installed, needed for pklas2img)
+ - Introduction of new tools, now includes:
+	pkascii2img
+	pkclassify_nn
+	pkcreatect
+	pkcrop
+	pkdiff
+	pkdumpimg
+	pkdumpogr
+	pkegcs
+	pkextract
+	pkfillnodata
+	pkfilter
+	pkgetmask
+	pkinfo
+	pklas2img
+	pkmosaic
+	pkndvi
+	pkpolygonize
+	pkreclass
+	pksetmask
+	pksieve
+	pkstat
+	pkstatogr
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..58d150a
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,27 @@
+How to install pktools
+----------------------
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.  If you're
+     using `csh' on an old version of System V, you might need to type
+     `sh ./configure' instead to prevent `csh' from trying to execute
+     `configure' itself.
+     
+     configure options (use ./configure --help for help info)
+     
+        --with-gdal=<path to gdal-config file>
+     	--with-fann=yes (to include pkclassify_nn when FANN is installed)
+	--with-las=yes (to include pklas2img when LIBLAS is installed)
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation. You probably will need sudo rights (root access) to write into
+     /usr/local/bin directory (default installation directory).
+
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100755
index 0000000..daabe2a
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,9 @@
+# to include m4 macros into aclocal.m4
+ACLOCAL_AMFLAGS = -I m4
+
+# the subdirectories of the project to go into
+SUBDIRS = src/base \
+	src/algorithms \
+	src/imageclasses \
+	$(FILECLASSES_OPT) \
+	src/apps
diff --git a/Makefile.in b/Makefile.in
new file mode 100644
index 0000000..bcd156b
--- /dev/null
+++ b/Makefile.in
@@ -0,0 +1,708 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+subdir = .
+DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in $(srcdir)/config.h.in \
+	$(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \
+	depcomp install-sh missing
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_gdal.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
+ configure.lineno config.status.lineno
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+SOURCES =
+DIST_SOURCES =
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+	html-recursive info-recursive install-data-recursive \
+	install-dvi-recursive install-exec-recursive \
+	install-html-recursive install-info-recursive \
+	install-pdf-recursive install-ps-recursive install-recursive \
+	installcheck-recursive installdirs-recursive pdf-recursive \
+	ps-recursive uninstall-recursive
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
+  distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+	$(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+	distdir dist dist-all distcheck
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+distdir = $(PACKAGE)-$(VERSION)
+top_distdir = $(distdir)
+am__remove_distdir = \
+  { test ! -d "$(distdir)" \
+    || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+         && rm -fr "$(distdir)"; }; }
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+DIST_ARCHIVES = $(distdir).tar.gz
+GZIP_ENV = --best
+distuninstallcheck_listfiles = find . -type f -print
+distcleancheck_listfiles = find . -type f -print
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_CXXFLAGS = @AM_CXXFLAGS@
+AM_LDFLAGS = @AM_LDFLAGS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FANN_CFLAGS = @FANN_CFLAGS@
+FANN_LIBS = @FANN_LIBS@
+FILECLASSES_OPT = @FILECLASSES_OPT@
+GDAL_CFLAGS = @GDAL_CFLAGS@
+GDAL_CONFIG = @GDAL_CONFIG@
+GDAL_DEP_LDFLAGS = @GDAL_DEP_LDFLAGS@
+GDAL_LDFLAGS = @GDAL_LDFLAGS@
+GDAL_OGR_ENABLED = @GDAL_OGR_ENABLED@
+GDAL_VERSION = @GDAL_VERSION@
+GREP = @GREP@
+GSL_CFLAGS = @GSL_CFLAGS@
+GSL_LIBS = @GSL_LIBS@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+
+# to include m4 macros into aclocal.m4
+ACLOCAL_AMFLAGS = -I m4
+
+# the subdirectories of the project to go into
+SUBDIRS = src/base \
+	src/algorithms \
+	src/imageclasses \
+	$(FILECLASSES_OPT) \
+	src/apps
+
+all: config.h
+	$(MAKE) $(AM_MAKEFLAGS) all-recursive
+
+.SUFFIXES:
+am--refresh:
+	@:
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \
+	      $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \
+		&& exit 0; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    echo ' $(SHELL) ./config.status'; \
+	    $(SHELL) ./config.status;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	$(SHELL) ./config.status --recheck
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	$(am__cd) $(srcdir) && $(AUTOCONF)
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
+$(am__aclocal_m4_deps):
+
+config.h: stamp-h1
+	@if test ! -f $@; then \
+	  rm -f stamp-h1; \
+	  $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \
+	else :; fi
+
+stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
+	@rm -f stamp-h1
+	cd $(top_builddir) && $(SHELL) ./config.status config.h
+$(srcdir)/config.h.in:  $(am__configure_deps) 
+	($(am__cd) $(top_srcdir) && $(AUTOHEADER))
+	rm -f stamp-h1
+	touch $@
+
+distclean-hdr:
+	-rm -f config.h stamp-h1
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+	@fail= failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+	@fail= failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	rev=''; for subdir in $$list; do \
+	  if test "$$subdir" = "."; then :; else \
+	    rev="$$subdir $$rev"; \
+	  fi; \
+	done; \
+	rev="$$rev ."; \
+	target=`echo $@ | sed s/-recursive//`; \
+	for subdir in $$rev; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done && test -z "$$fail"
+tags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+	done
+ctags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+	done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+	  include_option=--etags-include; \
+	  empty_fix=.; \
+	else \
+	  include_option=--include; \
+	  empty_fix=; \
+	fi; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test ! -f $$subdir/TAGS || \
+	      set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+	  fi; \
+	done; \
+	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	$(am__remove_distdir)
+	test -d "$(distdir)" || mkdir "$(distdir)"
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -d "$(distdir)/$$subdir" \
+	    || $(MKDIR_P) "$(distdir)/$$subdir" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+	    $(am__relativize); \
+	    new_distdir=$$reldir; \
+	    dir1=$$subdir; dir2="$(top_distdir)"; \
+	    $(am__relativize); \
+	    new_top_distdir=$$reldir; \
+	    echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+	    echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+	    ($(am__cd) $$subdir && \
+	      $(MAKE) $(AM_MAKEFLAGS) \
+	        top_distdir="$$new_top_distdir" \
+	        distdir="$$new_distdir" \
+		am__remove_distdir=: \
+		am__skip_length_check=: \
+		am__skip_mode_fix=: \
+	        distdir) \
+	      || exit 1; \
+	  fi; \
+	done
+	-test -n "$(am__skip_mode_fix)" \
+	|| find "$(distdir)" -type d ! -perm -755 \
+		-exec chmod u+rwx,go+rx {} \; -o \
+	  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
+	|| chmod -R a+r "$(distdir)"
+dist-gzip: distdir
+	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	$(am__remove_distdir)
+
+dist-bzip2: distdir
+	tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
+	$(am__remove_distdir)
+
+dist-lzma: distdir
+	tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma
+	$(am__remove_distdir)
+
+dist-xz: distdir
+	tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz
+	$(am__remove_distdir)
+
+dist-tarZ: distdir
+	tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
+	$(am__remove_distdir)
+
+dist-shar: distdir
+	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
+	$(am__remove_distdir)
+
+dist-zip: distdir
+	-rm -f $(distdir).zip
+	zip -rq $(distdir).zip $(distdir)
+	$(am__remove_distdir)
+
+dist dist-all: distdir
+	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	$(am__remove_distdir)
+
+# This target untars the dist file and tries a VPATH configuration.  Then
+# it guarantees that the distribution is self-contained by making another
+# tarfile.
+distcheck: dist
+	case '$(DIST_ARCHIVES)' in \
+	*.tar.gz*) \
+	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
+	*.tar.bz2*) \
+	  bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
+	*.tar.lzma*) \
+	  lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\
+	*.tar.xz*) \
+	  xz -dc $(distdir).tar.xz | $(am__untar) ;;\
+	*.tar.Z*) \
+	  uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
+	*.shar.gz*) \
+	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
+	*.zip*) \
+	  unzip $(distdir).zip ;;\
+	esac
+	chmod -R a-w $(distdir); chmod a+w $(distdir)
+	mkdir $(distdir)/_build
+	mkdir $(distdir)/_inst
+	chmod a-w $(distdir)
+	test -d $(distdir)/_build || exit 0; \
+	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
+	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
+	  && am__cwd=`pwd` \
+	  && $(am__cd) $(distdir)/_build \
+	  && ../configure --srcdir=.. --prefix="$$dc_install_base" \
+	    $(DISTCHECK_CONFIGURE_FLAGS) \
+	  && $(MAKE) $(AM_MAKEFLAGS) \
+	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
+	  && $(MAKE) $(AM_MAKEFLAGS) check \
+	  && $(MAKE) $(AM_MAKEFLAGS) install \
+	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
+	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
+	  && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
+	        distuninstallcheck \
+	  && chmod -R a-w "$$dc_install_base" \
+	  && ({ \
+	       (cd ../.. && umask 077 && mkdir "$$dc_destdir") \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
+	            distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
+	      } || { rm -rf "$$dc_destdir"; exit 1; }) \
+	  && rm -rf "$$dc_destdir" \
+	  && $(MAKE) $(AM_MAKEFLAGS) dist \
+	  && rm -rf $(DIST_ARCHIVES) \
+	  && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \
+	  && cd "$$am__cwd" \
+	  || exit 1
+	$(am__remove_distdir)
+	@(echo "$(distdir) archives ready for distribution: "; \
+	  list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
+	  sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
+distuninstallcheck:
+	@$(am__cd) '$(distuninstallcheck_dir)' \
+	&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
+	   || { echo "ERROR: files left after uninstall:" ; \
+	        if test -n "$(DESTDIR)"; then \
+	          echo "  (check DESTDIR support)"; \
+	        fi ; \
+	        $(distuninstallcheck_listfiles) ; \
+	        exit 1; } >&2
+distcleancheck: distclean
+	@if test '$(srcdir)' = . ; then \
+	  echo "ERROR: distcleancheck can only run from a VPATH build" ; \
+	  exit 1 ; \
+	fi
+	@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
+	  || { echo "ERROR: files left in build directory after distclean:" ; \
+	       $(distcleancheck_listfiles) ; \
+	       exit 1; } >&2
+check-am: all-am
+check: check-recursive
+all-am: Makefile config.h
+installdirs: installdirs-recursive
+installdirs-am:
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-generic mostlyclean-am
+
+distclean: distclean-recursive
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+	-rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-hdr distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+	-rm -rf $(top_srcdir)/autom4te.cache
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-generic
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all \
+	ctags-recursive install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+	all all-am am--refresh check check-am clean clean-generic \
+	ctags ctags-recursive dist dist-all dist-bzip2 dist-gzip \
+	dist-lzma dist-shar dist-tarZ dist-xz dist-zip distcheck \
+	distclean distclean-generic distclean-hdr distclean-tags \
+	distcleancheck distdir distuninstallcheck dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs installdirs-am maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
+	pdf-am ps ps-am tags tags-recursive uninstall uninstall-am
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..e69de29
diff --git a/README b/README
new file mode 100644
index 0000000..4030205
--- /dev/null
+++ b/README
@@ -0,0 +1,17 @@
+Description of pktools
+----------------------
+The version of this pktools distribution is 20120625
+pktools is a collection of programs written in C++ to perform operations on raster images.
+It heavily relies on the Geospatial Data Abstraction Library (GDAL, www.gdal.org) and OGR. Some of the programs are similar to the gdal tools (gdalinfo, gdal_translate, gdal_merge,...) and many of the functionalities provided in pktools already exist. The reason for implementing pktools is a combination of personal preference and in some case additional functionality. 
+
+License and distribution
+------------------------
+pktools is written by Pieter Kempeneers and is distributed under the GNU public license GPLv3. Refer to the file COPYING for copying conditions.
+
+Installation of pktools
+-----------------------
+To install the programs in pktools, refer to the file INSTALL
+
+Change history
+-------------
+June 25 2012, first public release of the code
diff --git a/aclocal.m4 b/aclocal.m4
new file mode 100644
index 0000000..1f01ab1
--- /dev/null
+++ b/aclocal.m4
@@ -0,0 +1,1110 @@
+# generated automatically by aclocal 1.11.1 -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.67],,
+[m4_warning([this file was generated for autoconf 2.67.
+You have another version of autoconf.  It may work, but is not guaranteed to.
+If you have problems, you may need to regenerate the build system entirely.
+To do so, use the procedure documented by the package, typically `autoreconf'.])])
+
+# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
+# serial 1 (pkg-config-0.24)
+# 
+# Copyright © 2004 Scott James Remnant <scott at netsplit.com>.
+#
+# 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.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# PKG_PROG_PKG_CONFIG([MIN-VERSION])
+# ----------------------------------
+AC_DEFUN([PKG_PROG_PKG_CONFIG],
+[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
+m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
+AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
+AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
+AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
+
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
+fi
+if test -n "$PKG_CONFIG"; then
+	_pkg_min_version=m4_default([$1], [0.9.0])
+	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+		AC_MSG_RESULT([yes])
+	else
+		AC_MSG_RESULT([no])
+		PKG_CONFIG=""
+	fi
+fi[]dnl
+])# PKG_PROG_PKG_CONFIG
+
+# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+#
+# Check to see whether a particular set of modules exists.  Similar
+# to PKG_CHECK_MODULES(), but does not set variables or print errors.
+#
+# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+# only at the first occurence in configure.ac, so if the first place
+# it's called might be skipped (such as if it is within an "if", you
+# have to call PKG_CHECK_EXISTS manually
+# --------------------------------------------------------------
+AC_DEFUN([PKG_CHECK_EXISTS],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+if test -n "$PKG_CONFIG" && \
+    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
+  m4_default([$2], [:])
+m4_ifvaln([$3], [else
+  $3])dnl
+fi])
+
+# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
+# ---------------------------------------------
+m4_define([_PKG_CONFIG],
+[if test -n "$$1"; then
+    pkg_cv_[]$1="$$1"
+ elif test -n "$PKG_CONFIG"; then
+    PKG_CHECK_EXISTS([$3],
+                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
+		     [pkg_failed=yes])
+ else
+    pkg_failed=untried
+fi[]dnl
+])# _PKG_CONFIG
+
+# _PKG_SHORT_ERRORS_SUPPORTED
+# -----------------------------
+AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi[]dnl
+])# _PKG_SHORT_ERRORS_SUPPORTED
+
+
+# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
+# [ACTION-IF-NOT-FOUND])
+#
+#
+# Note that if there is a possibility the first call to
+# PKG_CHECK_MODULES might not happen, you should be sure to include an
+# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
+#
+#
+# --------------------------------------------------------------
+AC_DEFUN([PKG_CHECK_MODULES],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
+AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
+
+pkg_failed=no
+AC_MSG_CHECKING([for $1])
+
+_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
+_PKG_CONFIG([$1][_LIBS], [libs], [$2])
+
+m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
+and $1[]_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.])
+
+if test $pkg_failed = yes; then
+   	AC_MSG_RESULT([no])
+        _PKG_SHORT_ERRORS_SUPPORTED
+        if test $_pkg_short_errors_supported = yes; then
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
+        else 
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
+
+	m4_default([$4], [AC_MSG_ERROR(
+[Package requirements ($2) were not met:
+
+$$1_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+_PKG_TEXT])[]dnl
+        ])
+elif test $pkg_failed = untried; then
+     	AC_MSG_RESULT([no])
+	m4_default([$4], [AC_MSG_FAILURE(
+[The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+_PKG_TEXT
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
+        ])
+else
+	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
+	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
+        AC_MSG_RESULT([yes])
+	$3
+fi[]dnl
+])# PKG_CHECK_MODULES
+
+# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_AUTOMAKE_VERSION(VERSION)
+# ----------------------------
+# Automake X.Y traces this macro to ensure aclocal.m4 has been
+# generated from the m4 files accompanying Automake X.Y.
+# (This private macro should not be called outside this file.)
+AC_DEFUN([AM_AUTOMAKE_VERSION],
+[am__api_version='1.11'
+dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
+dnl require some minimum version.  Point them to the right macro.
+m4_if([$1], [1.11.1], [],
+      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
+])
+
+# _AM_AUTOCONF_VERSION(VERSION)
+# -----------------------------
+# aclocal traces this macro to find the Autoconf version.
+# This is a private macro too.  Using m4_define simplifies
+# the logic in aclocal, which can simply ignore this definition.
+m4_define([_AM_AUTOCONF_VERSION], [])
+
+# AM_SET_CURRENT_AUTOMAKE_VERSION
+# -------------------------------
+# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
+# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
+AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
+[AM_AUTOMAKE_VERSION([1.11.1])dnl
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
+
+# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
+# $ac_aux_dir to `$srcdir/foo'.  In other projects, it is set to
+# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
+#
+# Of course, Automake must honor this variable whenever it calls a
+# tool from the auxiliary directory.  The problem is that $srcdir (and
+# therefore $ac_aux_dir as well) can be either absolute or relative,
+# depending on how configure is run.  This is pretty annoying, since
+# it makes $ac_aux_dir quite unusable in subdirectories: in the top
+# source directory, any form will work fine, but in subdirectories a
+# relative path needs to be adjusted first.
+#
+# $ac_aux_dir/missing
+#    fails when called from a subdirectory if $ac_aux_dir is relative
+# $top_srcdir/$ac_aux_dir/missing
+#    fails if $ac_aux_dir is absolute,
+#    fails when called from a subdirectory in a VPATH build with
+#          a relative $ac_aux_dir
+#
+# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
+# are both prefixed by $srcdir.  In an in-source build this is usually
+# harmless because $srcdir is `.', but things will broke when you
+# start a VPATH build or use an absolute $srcdir.
+#
+# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
+# iff we strip the leading $srcdir from $ac_aux_dir.  That would be:
+#   am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
+# and then we would define $MISSING as
+#   MISSING="\${SHELL} $am_aux_dir/missing"
+# This will work as long as MISSING is not called from configure, because
+# unfortunately $(top_srcdir) has no meaning in configure.
+# However there are other variables, like CC, which are often used in
+# configure, and could therefore not use this "fixed" $ac_aux_dir.
+#
+# Another solution, used here, is to always expand $ac_aux_dir to an
+# absolute PATH.  The drawback is that using absolute paths prevent a
+# configured tree to be moved without reconfiguration.
+
+AC_DEFUN([AM_AUX_DIR_EXPAND],
+[dnl Rely on autoconf to set up CDPATH properly.
+AC_PREREQ([2.50])dnl
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+])
+
+# AM_CONDITIONAL                                            -*- Autoconf -*-
+
+# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 9
+
+# AM_CONDITIONAL(NAME, SHELL-CONDITION)
+# -------------------------------------
+# Define a conditional.
+AC_DEFUN([AM_CONDITIONAL],
+[AC_PREREQ(2.52)dnl
+ ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
+	[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
+AC_SUBST([$1_TRUE])dnl
+AC_SUBST([$1_FALSE])dnl
+_AM_SUBST_NOTMAKE([$1_TRUE])dnl
+_AM_SUBST_NOTMAKE([$1_FALSE])dnl
+m4_define([_AM_COND_VALUE_$1], [$2])dnl
+if $2; then
+  $1_TRUE=
+  $1_FALSE='#'
+else
+  $1_TRUE='#'
+  $1_FALSE=
+fi
+AC_CONFIG_COMMANDS_PRE(
+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
+  AC_MSG_ERROR([[conditional "$1" was never defined.
+Usually this means the macro was only invoked conditionally.]])
+fi])])
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 10
+
+# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
+# written in clear, in which case automake, when reading aclocal.m4,
+# will think it sees a *use*, and therefore will trigger all it's
+# C support machinery.  Also note that it means that autoscan, seeing
+# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
+
+
+# _AM_DEPENDENCIES(NAME)
+# ----------------------
+# See how the compiler implements dependency checking.
+# NAME is "CC", "CXX", "GCJ", or "OBJC".
+# We try a few techniques and use that to set a single cache variable.
+#
+# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
+# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
+# dependency, and given that the user is not expected to run this macro,
+# just rely on AC_PROG_CC.
+AC_DEFUN([_AM_DEPENDENCIES],
+[AC_REQUIRE([AM_SET_DEPDIR])dnl
+AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
+AC_REQUIRE([AM_MAKE_INCLUDE])dnl
+AC_REQUIRE([AM_DEP_TRACK])dnl
+
+ifelse([$1], CC,   [depcc="$CC"   am_compiler_list=],
+       [$1], CXX,  [depcc="$CXX"  am_compiler_list=],
+       [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
+       [$1], UPC,  [depcc="$UPC"  am_compiler_list=],
+       [$1], GCJ,  [depcc="$GCJ"  am_compiler_list='gcc3 gcc'],
+                   [depcc="$$1"   am_compiler_list=])
+
+AC_CACHE_CHECK([dependency style of $depcc],
+               [am_cv_$1_dependencies_compiler_type],
+[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_$1_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
+  fi
+  am__universal=false
+  m4_case([$1], [CC],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac],
+    [CXX],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac])
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    msvisualcpp | msvcmsys)
+      # This compiler won't grok `-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_$1_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_$1_dependencies_compiler_type=none
+fi
+])
+AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
+AM_CONDITIONAL([am__fastdep$1], [
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
+])
+
+
+# AM_SET_DEPDIR
+# -------------
+# Choose a directory name for dependency files.
+# This macro is AC_REQUIREd in _AM_DEPENDENCIES
+AC_DEFUN([AM_SET_DEPDIR],
+[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
+])
+
+
+# AM_DEP_TRACK
+# ------------
+AC_DEFUN([AM_DEP_TRACK],
+[AC_ARG_ENABLE(dependency-tracking,
+[  --disable-dependency-tracking  speeds up one-time build
+  --enable-dependency-tracking   do not reject slow dependency extractors])
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+fi
+AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
+AC_SUBST([AMDEPBACKSLASH])dnl
+_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
+])
+
+# Generate code to set up dependency tracking.              -*- Autoconf -*-
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+#serial 5
+
+# _AM_OUTPUT_DEPENDENCY_COMMANDS
+# ------------------------------
+AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
+[{
+  # Autoconf 2.62 quotes --file arguments for eval, but not when files
+  # are listed without --file.  Let's play safe and only enable the eval
+  # if we detect the quoting.
+  case $CONFIG_FILES in
+  *\'*) eval set x "$CONFIG_FILES" ;;
+  *)   set x $CONFIG_FILES ;;
+  esac
+  shift
+  for mf
+  do
+    # Strip MF so we end up with the name of the file.
+    mf=`echo "$mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile or not.
+    # We used to match only the files named `Makefile.in', but
+    # some people rename them; so instead we look at the file content.
+    # Grep'ing the first line is not enough: some people post-process
+    # each Makefile.in and add a new line on top of each file to say so.
+    # Grep'ing the whole file is not good either: AIX grep has a line
+    # limit of 2048, but all sed's we know have understand at least 4000.
+    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
+      dirpart=`AS_DIRNAME("$mf")`
+    else
+      continue
+    fi
+    # Extract the definition of DEPDIR, am__include, and am__quote
+    # from the Makefile without running `make'.
+    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+    test -z "$DEPDIR" && continue
+    am__include=`sed -n 's/^am__include = //p' < "$mf"`
+    test -z "am__include" && continue
+    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+    # When using ansi2knr, U may be empty or an underscore; expand it
+    U=`sed -n 's/^U = //p' < "$mf"`
+    # Find all dependency output files, they are included files with
+    # $(DEPDIR) in their names.  We invoke sed twice because it is the
+    # simplest approach to changing $(DEPDIR) to its actual value in the
+    # expansion.
+    for file in `sed -n "
+      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+	 sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
+      # Make sure the directory exists.
+      test -f "$dirpart/$file" && continue
+      fdir=`AS_DIRNAME(["$file"])`
+      AS_MKDIR_P([$dirpart/$fdir])
+      # echo "creating $dirpart/$file"
+      echo '# dummy' > "$dirpart/$file"
+    done
+  done
+}
+])# _AM_OUTPUT_DEPENDENCY_COMMANDS
+
+
+# AM_OUTPUT_DEPENDENCY_COMMANDS
+# -----------------------------
+# This macro should only be invoked once -- use via AC_REQUIRE.
+#
+# This code is only required when automatic dependency tracking
+# is enabled.  FIXME.  This creates each `.P' file that we will
+# need in order to bootstrap the dependency handling code.
+AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
+[AC_CONFIG_COMMANDS([depfiles],
+     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
+     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
+])
+
+# Do all the work for Automake.                             -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 16
+
+# This macro actually does too much.  Some checks are only needed if
+# your package does certain things.  But this isn't really a big deal.
+
+# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
+# AM_INIT_AUTOMAKE([OPTIONS])
+# -----------------------------------------------
+# The call with PACKAGE and VERSION arguments is the old style
+# call (pre autoconf-2.50), which is being phased out.  PACKAGE
+# and VERSION should now be passed to AC_INIT and removed from
+# the call to AM_INIT_AUTOMAKE.
+# We support both call styles for the transition.  After
+# the next Automake release, Autoconf can make the AC_INIT
+# arguments mandatory, and then we can depend on a new Autoconf
+# release and drop the old call support.
+AC_DEFUN([AM_INIT_AUTOMAKE],
+[AC_PREREQ([2.62])dnl
+dnl Autoconf wants to disallow AM_ names.  We explicitly allow
+dnl the ones we care about.
+m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
+AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
+AC_REQUIRE([AC_PROG_INSTALL])dnl
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+AC_SUBST([CYGPATH_W])
+
+# Define the identity of the package.
+dnl Distinguish between old-style and new-style calls.
+m4_ifval([$2],
+[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
+ AC_SUBST([PACKAGE], [$1])dnl
+ AC_SUBST([VERSION], [$2])],
+[_AM_SET_OPTIONS([$1])dnl
+dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
+m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,,
+  [m4_fatal([AC_INIT should be called with package and version arguments])])dnl
+ AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
+ AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
+
+_AM_IF_OPTION([no-define],,
+[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
+ AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
+
+# Some tools Automake needs.
+AC_REQUIRE([AM_SANITY_CHECK])dnl
+AC_REQUIRE([AC_ARG_PROGRAM])dnl
+AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
+AM_MISSING_PROG(AUTOCONF, autoconf)
+AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
+AM_MISSING_PROG(AUTOHEADER, autoheader)
+AM_MISSING_PROG(MAKEINFO, makeinfo)
+AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
+AC_REQUIRE([AM_PROG_MKDIR_P])dnl
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+AC_REQUIRE([AC_PROG_AWK])dnl
+AC_REQUIRE([AC_PROG_MAKE_SET])dnl
+AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
+	      [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
+			     [_AM_PROG_TAR([v7])])])
+_AM_IF_OPTION([no-dependencies],,
+[AC_PROVIDE_IFELSE([AC_PROG_CC],
+		  [_AM_DEPENDENCIES(CC)],
+		  [define([AC_PROG_CC],
+			  defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_CXX],
+		  [_AM_DEPENDENCIES(CXX)],
+		  [define([AC_PROG_CXX],
+			  defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_OBJC],
+		  [_AM_DEPENDENCIES(OBJC)],
+		  [define([AC_PROG_OBJC],
+			  defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl
+])
+_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl
+dnl The `parallel-tests' driver may need to know about EXEEXT, so add the
+dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen.  This macro
+dnl is hooked onto _AC_COMPILER_EXEEXT early, see below.
+AC_CONFIG_COMMANDS_PRE(dnl
+[m4_provide_if([_AM_COMPILER_EXEEXT],
+  [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
+])
+
+dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
+dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
+dnl mangled by Autoconf and run in a shell conditional statement.
+m4_define([_AC_COMPILER_EXEEXT],
+m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
+
+
+# When config.status generates a header, we must update the stamp-h file.
+# This file resides in the same directory as the config header
+# that is generated.  The stamp files are numbered to have different names.
+
+# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
+# loop where config.status creates the headers, so we can generate
+# our stamp files there.
+AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
+[# Compute $1's index in $config_headers.
+_am_arg=$1
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
+
+# Copyright (C) 2001, 2003, 2005, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_SH
+# ------------------
+# Define $install_sh.
+AC_DEFUN([AM_PROG_INSTALL_SH],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+if test x"${install_sh}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+AC_SUBST(install_sh)])
+
+# Copyright (C) 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# Check whether the underlying file-system supports filenames
+# with a leading dot.  For instance MS-DOS doesn't.
+AC_DEFUN([AM_SET_LEADING_DOT],
+[rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+AC_SUBST([am__leading_dot])])
+
+# Check to see how 'make' treats includes.	            -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005, 2009  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 4
+
+# AM_MAKE_INCLUDE()
+# -----------------
+# Check to see how make treats includes.
+AC_DEFUN([AM_MAKE_INCLUDE],
+[am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+	@echo this is the am__doit target
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+AC_MSG_CHECKING([for style of include used by $am_make])
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# Ignore all kinds of additional output from `make'.
+case `$am_make -s -f confmf 2> /dev/null` in #(
+*the\ am__doit\ target*)
+  am__include=include
+  am__quote=
+  _am_result=GNU
+  ;;
+esac
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   case `$am_make -s -f confmf 2> /dev/null` in #(
+   *the\ am__doit\ target*)
+     am__include=.include
+     am__quote="\""
+     _am_result=BSD
+     ;;
+   esac
+fi
+AC_SUBST([am__include])
+AC_SUBST([am__quote])
+AC_MSG_RESULT([$_am_result])
+rm -f confinc confmf
+])
+
+# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
+
+# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 6
+
+# AM_MISSING_PROG(NAME, PROGRAM)
+# ------------------------------
+AC_DEFUN([AM_MISSING_PROG],
+[AC_REQUIRE([AM_MISSING_HAS_RUN])
+$1=${$1-"${am_missing_run}$2"}
+AC_SUBST($1)])
+
+
+# AM_MISSING_HAS_RUN
+# ------------------
+# Define MISSING if not defined so far and test if it supports --run.
+# If it does, set am_missing_run to use it, otherwise, to nothing.
+AC_DEFUN([AM_MISSING_HAS_RUN],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([missing])dnl
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --run true"; then
+  am_missing_run="$MISSING --run "
+else
+  am_missing_run=
+  AC_MSG_WARN([`missing' script is too old or missing])
+fi
+])
+
+# Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_MKDIR_P
+# ---------------
+# Check for `mkdir -p'.
+AC_DEFUN([AM_PROG_MKDIR_P],
+[AC_PREREQ([2.60])dnl
+AC_REQUIRE([AC_PROG_MKDIR_P])dnl
+dnl Automake 1.8 to 1.9.6 used to define mkdir_p.  We now use MKDIR_P,
+dnl while keeping a definition of mkdir_p for backward compatibility.
+dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile.
+dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of
+dnl Makefile.ins that do not define MKDIR_P, so we do our own
+dnl adjustment using top_builddir (which is defined more often than
+dnl MKDIR_P).
+AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl
+case $mkdir_p in
+  [[\\/$]]* | ?:[[\\/]]*) ;;
+  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+])
+
+# Helper functions for option handling.                     -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 4
+
+# _AM_MANGLE_OPTION(NAME)
+# -----------------------
+AC_DEFUN([_AM_MANGLE_OPTION],
+[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
+
+# _AM_SET_OPTION(NAME)
+# ------------------------------
+# Set option NAME.  Presently that only means defining a flag for this option.
+AC_DEFUN([_AM_SET_OPTION],
+[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
+
+# _AM_SET_OPTIONS(OPTIONS)
+# ----------------------------------
+# OPTIONS is a space-separated list of Automake options.
+AC_DEFUN([_AM_SET_OPTIONS],
+[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
+
+# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
+# -------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+AC_DEFUN([_AM_IF_OPTION],
+[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
+
+# Check to make sure that the build environment is sane.    -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 5
+
+# AM_SANITY_CHECK
+# ---------------
+AC_DEFUN([AM_SANITY_CHECK],
+[AC_MSG_CHECKING([whether build environment is sane])
+# Just in case
+sleep 1
+echo timestamp > conftest.file
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[[\\\"\#\$\&\'\`$am_lf]]*)
+    AC_MSG_ERROR([unsafe absolute working directory name]);;
+esac
+case $srcdir in
+  *[[\\\"\#\$\&\'\`$am_lf\ \	]]*)
+    AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);;
+esac
+
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+   if test "$[*]" = "X"; then
+      # -L didn't work.
+      set X `ls -t "$srcdir/configure" conftest.file`
+   fi
+   rm -f conftest.file
+   if test "$[*]" != "X $srcdir/configure conftest.file" \
+      && test "$[*]" != "X conftest.file $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
+alias in your environment])
+   fi
+
+   test "$[2]" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   AC_MSG_ERROR([newly created file is older than distributed files!
+Check your system clock])
+fi
+AC_MSG_RESULT(yes)])
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_STRIP
+# ---------------------
+# One issue with vendor `install' (even GNU) is that you can't
+# specify the program used to strip binaries.  This is especially
+# annoying in cross-compiling environments, where the build's strip
+# is unlikely to handle the host's binaries.
+# Fortunately install-sh will honor a STRIPPROG variable, so we
+# always use install-sh in `make install-strip', and initialize
+# STRIPPROG with the value of the STRIP variable (set by the user).
+AC_DEFUN([AM_PROG_INSTALL_STRIP],
+[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'.  However `strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the `STRIP' environment variable to overrule this program.
+dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
+if test "$cross_compiling" != no; then
+  AC_CHECK_TOOL([STRIP], [strip], :)
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+AC_SUBST([INSTALL_STRIP_PROGRAM])])
+
+# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# _AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
+# This macro is traced by Automake.
+AC_DEFUN([_AM_SUBST_NOTMAKE])
+
+# AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Public sister of _AM_SUBST_NOTMAKE.
+AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
+
+# Check how to create a tarball.                            -*- Autoconf -*-
+
+# Copyright (C) 2004, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# _AM_PROG_TAR(FORMAT)
+# --------------------
+# Check how to create a tarball in format FORMAT.
+# FORMAT should be one of `v7', `ustar', or `pax'.
+#
+# Substitute a variable $(am__tar) that is a command
+# writing to stdout a FORMAT-tarball containing the directory
+# $tardir.
+#     tardir=directory && $(am__tar) > result.tar
+#
+# Substitute a variable $(am__untar) that extract such
+# a tarball read from stdin.
+#     $(am__untar) < result.tar
+AC_DEFUN([_AM_PROG_TAR],
+[# Always define AMTAR for backward compatibility.
+AM_MISSING_PROG([AMTAR], [tar])
+m4_if([$1], [v7],
+     [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
+     [m4_case([$1], [ustar],, [pax],,
+              [m4_fatal([Unknown tar format])])
+AC_MSG_CHECKING([how to create a $1 tar archive])
+# Loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
+_am_tools=${am_cv_prog_tar_$1-$_am_tools}
+# Do not fold the above two line into one, because Tru64 sh and
+# Solaris sh will not grok spaces in the rhs of `-'.
+for _am_tool in $_am_tools
+do
+  case $_am_tool in
+  gnutar)
+    for _am_tar in tar gnutar gtar;
+    do
+      AM_RUN_LOG([$_am_tar --version]) && break
+    done
+    am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
+    am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
+    am__untar="$_am_tar -xf -"
+    ;;
+  plaintar)
+    # Must skip GNU tar: if it does not support --format= it doesn't create
+    # ustar tarball either.
+    (tar --version) >/dev/null 2>&1 && continue
+    am__tar='tar chf - "$$tardir"'
+    am__tar_='tar chf - "$tardir"'
+    am__untar='tar xf -'
+    ;;
+  pax)
+    am__tar='pax -L -x $1 -w "$$tardir"'
+    am__tar_='pax -L -x $1 -w "$tardir"'
+    am__untar='pax -r'
+    ;;
+  cpio)
+    am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
+    am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
+    am__untar='cpio -i -H $1 -d'
+    ;;
+  none)
+    am__tar=false
+    am__tar_=false
+    am__untar=false
+    ;;
+  esac
+
+  # If the value was cached, stop now.  We just wanted to have am__tar
+  # and am__untar set.
+  test -n "${am_cv_prog_tar_$1}" && break
+
+  # tar/untar a dummy directory, and stop if the command works
+  rm -rf conftest.dir
+  mkdir conftest.dir
+  echo GrepMe > conftest.dir/file
+  AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
+  rm -rf conftest.dir
+  if test -s conftest.tar; then
+    AM_RUN_LOG([$am__untar <conftest.tar])
+    grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
+  fi
+done
+rm -rf conftest.dir
+
+AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
+AC_MSG_RESULT([$am_cv_prog_tar_$1])])
+AC_SUBST([am__tar])
+AC_SUBST([am__untar])
+]) # _AM_PROG_TAR
+
+m4_include([m4/ax_lib_gdal.m4])
diff --git a/config.h.in b/config.h.in
new file mode 100644
index 0000000..2257caf
--- /dev/null
+++ b/config.h.in
@@ -0,0 +1,73 @@
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if GDAL library are available */
+#undef HAVE_GDAL
+
+/* Define to 1 if you have the <gdal.h> header file. */
+#undef HAVE_GDAL_H
+
+/* Define to 1 if GDAL library includes OGR support */
+#undef HAVE_GDAL_OGR
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <iostream> header file. */
+#undef HAVE_IOSTREAM
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <string> header file. */
+#undef HAVE_STRING
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Name of package */
+#undef PACKAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Version number of package */
+#undef VERSION
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+#undef size_t
diff --git a/configure b/configure
new file mode 100755
index 0000000..187ca3a
--- /dev/null
+++ b/configure
@@ -0,0 +1,7213 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.67 for pktools 2.1.
+#
+# Report bugs to <kempenep at gmail.com>.
+#
+#
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
+# Foundation, Inc.
+#
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test "x$CONFIG_SHELL" = x; then
+  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+"
+  as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+
+else
+  exitcode=1; echo positional parameters were not saved.
+fi
+test x\$exitcode = x0 || exit 1"
+  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+  if (eval "$as_required") 2>/dev/null; then :
+  as_have_required=yes
+else
+  as_have_required=no
+fi
+  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
+
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_found=false
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  as_found=:
+  case $as_dir in #(
+	 /*)
+	   for as_base in sh bash ksh sh5; do
+	     # Try only shells that exist, to save several forks.
+	     as_shell=$as_dir/$as_base
+	     if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+		    { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  CONFIG_SHELL=$as_shell as_have_required=yes
+		   if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  break 2
+fi
+fi
+	   done;;
+       esac
+  as_found=false
+done
+$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
+	      { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+  CONFIG_SHELL=$SHELL as_have_required=yes
+fi; }
+IFS=$as_save_IFS
+
+
+      if test "x$CONFIG_SHELL" != x; then :
+  # We cannot yet assume a decent shell, so we have to provide a
+	# neutralization value for shells without unset; and this also
+	# works around shells that cannot unset nonexistent variables.
+	BASH_ENV=/dev/null
+	ENV=/dev/null
+	(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+	export CONFIG_SHELL
+	exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
+fi
+
+    if test x$as_have_required = xno; then :
+  $as_echo "$0: This script requires a shell more modern than all"
+  $as_echo "$0: the shells that I found on your system."
+  if test x${ZSH_VERSION+set} = xset ; then
+    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
+    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
+  else
+    $as_echo "$0: Please tell bug-autoconf at gnu.org and kempenep at gmail.com
+$0: about your system, including any error possibly output
+$0: before this message. Then install a modern shell, or
+$0: manually run the script under such a shell if you do
+$0: have one."
+  fi
+  exit 1
+fi
+fi
+fi
+SHELL=${CONFIG_SHELL-/bin/sh}
+export SHELL
+# Unset more variables known to interfere with behavior of common tools.
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
+
+## --------------------- ##
+## M4sh Shell Functions. ##
+## --------------------- ##
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+
+  as_lineno_1=$LINENO as_lineno_1a=$LINENO
+  as_lineno_2=$LINENO as_lineno_2a=$LINENO
+  eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
+  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
+  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
+    sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
+      N
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+      t loop
+      s/-\n.*//
+    ' >$as_me.lineno &&
+  chmod +x "$as_me.lineno" ||
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
+  # Exit status is that of the last command.
+  exit
+}
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -p'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -p'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -p'
+  fi
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in #(
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+test -n "$DJDIR" || exec 7<&0 </dev/null
+exec 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+
+# Identity of this package.
+PACKAGE_NAME='pktools'
+PACKAGE_TARNAME='pktools'
+PACKAGE_VERSION='2.1'
+PACKAGE_STRING='pktools 2.1'
+PACKAGE_BUGREPORT='kempenep at gmail.com'
+PACKAGE_URL=''
+
+ac_unique_file="src/apps/pkinfo.cc"
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subst_vars='am__EXEEXT_FALSE
+am__EXEEXT_TRUE
+LTLIBOBJS
+LIBOBJS
+AM_LDFLAGS
+AM_CXXFLAGS
+CXXCPP
+USE_GSL_FALSE
+USE_GSL_TRUE
+GSL_LIBS
+GSL_CFLAGS
+FILECLASSES_OPT
+USE_LAS_FALSE
+USE_LAS_TRUE
+USE_FANN_FALSE
+USE_FANN_TRUE
+FANN_LIBS
+FANN_CFLAGS
+PKG_CONFIG_LIBDIR
+PKG_CONFIG_PATH
+PKG_CONFIG
+EGREP
+GREP
+CPP
+am__fastdepCC_FALSE
+am__fastdepCC_TRUE
+CCDEPMODE
+ac_ct_CC
+CFLAGS
+CC
+RANLIB
+am__fastdepCXX_FALSE
+am__fastdepCXX_TRUE
+CXXDEPMODE
+AMDEPBACKSLASH
+AMDEP_FALSE
+AMDEP_TRUE
+am__quote
+am__include
+DEPDIR
+OBJEXT
+EXEEXT
+ac_ct_CXX
+CPPFLAGS
+LDFLAGS
+CXXFLAGS
+CXX
+GDAL_OGR_ENABLED
+GDAL_DEP_LDFLAGS
+GDAL_LDFLAGS
+GDAL_CFLAGS
+GDAL_VERSION
+GDAL_CONFIG
+am__untar
+am__tar
+AMTAR
+am__leading_dot
+SET_MAKE
+AWK
+mkdir_p
+MKDIR_P
+INSTALL_STRIP_PROGRAM
+STRIP
+install_sh
+MAKEINFO
+AUTOHEADER
+AUTOMAKE
+AUTOCONF
+ACLOCAL
+VERSION
+PACKAGE
+CYGPATH_W
+am__isrc
+INSTALL_DATA
+INSTALL_SCRIPT
+INSTALL_PROGRAM
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_URL
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
+PATH_SEPARATOR
+SHELL'
+ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+with_gdal
+enable_dependency_tracking
+with_fann
+with_las
+'
+      ac_precious_vars='build_alias
+host_alias
+target_alias
+CXX
+CXXFLAGS
+LDFLAGS
+LIBS
+CPPFLAGS
+CCC
+CC
+CFLAGS
+CPP
+PKG_CONFIG
+PKG_CONFIG_PATH
+PKG_CONFIG_LIBDIR
+FANN_CFLAGS
+FANN_LIBS
+GSL_CFLAGS
+GSL_LIBS
+CXXCPP'
+
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
+
+ac_prev=
+ac_dashdash=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval $ac_prev=\$ac_option
+    ac_prev=
+    continue
+  fi
+
+  case $ac_option in
+  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+  *=)   ac_optarg= ;;
+  *)    ac_optarg=yes ;;
+  esac
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_dashdash$ac_option in
+  --)
+    ac_dashdash=yes ;;
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=*)
+    datadir=$ac_optarg ;;
+
+  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+  | --dataroo | --dataro | --datar)
+    ac_prev=datarootdir ;;
+  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+    datarootdir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=no ;;
+
+  -docdir | --docdir | --docdi | --doc | --do)
+    ac_prev=docdir ;;
+  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+    docdir=$ac_optarg ;;
+
+  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+    ac_prev=dvidir ;;
+  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+    dvidir=$ac_optarg ;;
+
+  -enable-* | --enable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=\$ac_optarg ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+    ac_prev=htmldir ;;
+  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+  | --ht=*)
+    htmldir=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localedir | --localedir | --localedi | --localed | --locale)
+    ac_prev=localedir ;;
+  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+    localedir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst | --locals)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+    ac_prev=pdfdir ;;
+  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+    pdfdir=$ac_optarg ;;
+
+  -psdir | --psdir | --psdi | --psd | --ps)
+    ac_prev=psdir ;;
+  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+    psdir=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=\$ac_optarg ;;
+
+  -without-* | --without-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=no ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) as_fn_error $? "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information"
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    case $ac_envvar in #(
+      '' | [0-9]* | *[!_$as_cr_alnum]* )
+      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
+    esac
+    eval $ac_envvar=\$ac_optarg
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  as_fn_error $? "missing argument to $ac_option"
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+  case $enable_option_checking in
+    no) ;;
+    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
+    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+  esac
+fi
+
+# Check all directory arguments for consistency.
+for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
+		datadir sysconfdir sharedstatedir localstatedir includedir \
+		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+		libdir localedir mandir
+do
+  eval ac_val=\$$ac_var
+  # Remove trailing slashes.
+  case $ac_val in
+    */ )
+      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+      eval $ac_var=\$ac_val;;
+  esac
+  # Be sure to have absolute directory names.
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* )  continue;;
+    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
+  esac
+  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+    $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used" >&2
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+  as_fn_error $? "working directory cannot be determined"
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+  as_fn_error $? "pwd does not report name of working directory"
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then the parent directory.
+  ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_myself" : 'X\(//\)[^/]' \| \
+	 X"$as_myself" : 'X\(//\)$' \| \
+	 X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r "$srcdir/$ac_unique_file"; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r "$srcdir/$ac_unique_file"; then
+  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
+fi
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+	pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+  srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+  eval ac_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_env_${ac_var}_value=\$${ac_var}
+  eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+  # Omit some internal or obsolete options to make the list less imposing.
+  # This message is too long to be a string in the A/UX 3.1 sh.
+  cat <<_ACEOF
+\`configure' configures pktools 2.1 to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking ...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+                          [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+                          [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR            user executables [EPREFIX/bin]
+  --sbindir=DIR           system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR        program executables [EPREFIX/libexec]
+  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --libdir=DIR            object code libraries [EPREFIX/lib]
+  --includedir=DIR        C header files [PREFIX/include]
+  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
+  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
+  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
+  --infodir=DIR           info documentation [DATAROOTDIR/info]
+  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
+  --mandir=DIR            man documentation [DATAROOTDIR/man]
+  --docdir=DIR            documentation root [DATAROOTDIR/doc/pktools]
+  --htmldir=DIR           html documentation [DOCDIR]
+  --dvidir=DIR            dvi documentation [DOCDIR]
+  --pdfdir=DIR            pdf documentation [DOCDIR]
+  --psdir=DIR             ps documentation [DOCDIR]
+_ACEOF
+
+  cat <<\_ACEOF
+
+Program names:
+  --program-prefix=PREFIX            prepend PREFIX to installed program names
+  --program-suffix=SUFFIX            append SUFFIX to installed program names
+  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+  case $ac_init_help in
+     short | recursive ) echo "Configuration of pktools 2.1:";;
+   esac
+  cat <<\_ACEOF
+
+Optional Features:
+  --disable-option-checking  ignore unrecognized --enable/--with options
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --disable-dependency-tracking  speeds up one-time build
+  --enable-dependency-tracking   do not reject slow dependency extractors
+
+Optional Packages:
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --with-gdal=[ARG]       Specify full path to gdal-config script
+  --with-fann             use fann library @@
+  --with-las              use las library @@
+
+Some influential environment variables:
+  CXX         C++ compiler command
+  CXXFLAGS    C++ compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  LIBS        libraries to pass to the linker, e.g. -l<library>
+  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
+              you have headers in a nonstandard directory <include dir>
+  CC          C compiler command
+  CFLAGS      C compiler flags
+  CPP         C preprocessor
+  PKG_CONFIG  path to pkg-config utility
+  PKG_CONFIG_PATH
+              directories to add to pkg-config's search path
+  PKG_CONFIG_LIBDIR
+              path overriding pkg-config's built-in search path
+  FANN_CFLAGS C compiler flags for FANN, overriding pkg-config
+  FANN_LIBS   linker flags for FANN, overriding pkg-config
+  GSL_CFLAGS  C compiler flags for GSL, overriding pkg-config
+  GSL_LIBS    linker flags for GSL, overriding pkg-config
+  CXXCPP      C++ preprocessor
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to <kempenep at gmail.com>.
+_ACEOF
+ac_status=$?
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d "$ac_dir" ||
+      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+      continue
+    ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+    cd "$ac_dir" || { ac_status=$?; continue; }
+    # Check for guested configure.
+    if test -f "$ac_srcdir/configure.gnu"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+    elif test -f "$ac_srcdir/configure"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure" --help=recursive
+    else
+      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi || ac_status=$?
+    cd "$ac_pwd" || { ac_status=$?; break; }
+  done
+fi
+
+test -n "$ac_init_help" && exit $ac_status
+if $ac_init_version; then
+  cat <<\_ACEOF
+pktools configure 2.1
+generated by GNU Autoconf 2.67
+
+Copyright (C) 2010 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit
+fi
+
+## ------------------------ ##
+## Autoconf initialization. ##
+## ------------------------ ##
+
+# ac_fn_cxx_try_compile LINENO
+# ----------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_cxx_try_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext
+  if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_cxx_try_compile
+
+# ac_fn_c_try_compile LINENO
+# --------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext
+  if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_compile
+
+# ac_fn_c_try_cpp LINENO
+# ----------------------
+# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_cpp ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } > conftest.i && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+    ac_retval=1
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_cpp
+
+# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_c_check_header_mongrel ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if eval "test \"\${$3+set}\"" = set; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+  $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_header_compiler=yes
+else
+  ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <$2>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  ac_header_preproc=yes
+else
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
+  yes:no: )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+( $as_echo "## --------------------------------- ##
+## Report this to kempenep at gmail.com ##
+## --------------------------------- ##"
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_header_mongrel
+
+# ac_fn_c_try_run LINENO
+# ----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
+# that executables *can* be run.
+ac_fn_c_try_run ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: program exited with status $ac_status" >&5
+       $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=$ac_status
+fi
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_run
+
+# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists and can be compiled using the include files in
+# INCLUDES, setting the cache variable VAR accordingly.
+ac_fn_c_check_header_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_header_compile
+
+# ac_fn_cxx_try_cpp LINENO
+# ------------------------
+# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
+ac_fn_cxx_try_cpp ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } > conftest.i && {
+	 test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+    ac_retval=1
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_cxx_try_cpp
+
+# ac_fn_cxx_try_run LINENO
+# ------------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
+# that executables *can* be run.
+ac_fn_cxx_try_run ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: program exited with status $ac_status" >&5
+       $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=$ac_status
+fi
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_cxx_try_run
+
+# ac_fn_cxx_check_header_mongrel LINENO HEADER VAR INCLUDES
+# ---------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_cxx_check_header_mongrel ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if eval "test \"\${$3+set}\"" = set; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+  $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_header_compiler=yes
+else
+  ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <$2>
+_ACEOF
+if ac_fn_cxx_try_cpp "$LINENO"; then :
+  ac_header_preproc=yes
+else
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_cxx_preproc_warn_flag in #((
+  yes:no: )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+( $as_echo "## --------------------------------- ##
+## Report this to kempenep at gmail.com ##
+## --------------------------------- ##"
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_cxx_check_header_mongrel
+
+# ac_fn_cxx_check_type LINENO TYPE VAR INCLUDES
+# ---------------------------------------------
+# Tests whether TYPE exists after having included INCLUDES, setting cache
+# variable VAR accordingly.
+ac_fn_cxx_check_type ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=no"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+if (sizeof ($2))
+	 return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+if (sizeof (($2)))
+	    return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+
+else
+  eval "$3=yes"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_cxx_check_type
+cat >config.log <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by pktools $as_me 2.1, which was
+generated by GNU Autoconf 2.67.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+exec 5>>config.log
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    $as_echo "PATH: $as_dir"
+  done
+IFS=$as_save_IFS
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *\'*)
+      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
+    2)
+      as_fn_append ac_configure_args1 " '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+	ac_must_keep_next=false # Got value, back to normal.
+      else
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
+      fi
+      as_fn_append ac_configure_args " '$ac_arg'"
+      ;;
+    esac
+  done
+done
+{ ac_configure_args0=; unset ac_configure_args0;}
+{ ac_configure_args1=; unset ac_configure_args1;}
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    $as_echo "## ---------------- ##
+## Cache variables. ##
+## ---------------- ##"
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+(
+  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+  (set) 2>&1 |
+    case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      sed -n \
+	"s/'\''/'\''\\\\'\'''\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+      ;; #(
+    *)
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+)
+    echo
+
+    $as_echo "## ----------------- ##
+## Output variables. ##
+## ----------------- ##"
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=\$$ac_var
+      case $ac_val in
+      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      esac
+      $as_echo "$ac_var='\''$ac_val'\''"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      $as_echo "## ------------------- ##
+## File substitutions. ##
+## ------------------- ##"
+      echo
+      for ac_var in $ac_subst_files
+      do
+	eval ac_val=\$$ac_var
+	case $ac_val in
+	*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+	esac
+	$as_echo "$ac_var='\''$ac_val'\''"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      $as_echo "## ----------- ##
+## confdefs.h. ##
+## ----------- ##"
+      echo
+      cat confdefs.h
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      $as_echo "$as_me: caught signal $ac_signal"
+    $as_echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core core.conftest.* &&
+    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -f -r conftest* confdefs.h
+
+$as_echo "/* confdefs.h */" > confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_URL "$PACKAGE_URL"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
+if test -n "$CONFIG_SITE"; then
+  # We do not want a PATH search for config.site.
+  case $CONFIG_SITE in #((
+    -*)  ac_site_file1=./$CONFIG_SITE;;
+    */*) ac_site_file1=$CONFIG_SITE;;
+    *)   ac_site_file1=./$CONFIG_SITE;;
+  esac
+elif test "x$prefix" != xNONE; then
+  ac_site_file1=$prefix/share/config.site
+  ac_site_file2=$prefix/etc/config.site
+else
+  ac_site_file1=$ac_default_prefix/share/config.site
+  ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
+do
+  test "x$ac_site_file" = xNONE && continue
+  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file" \
+      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "failed to load site script $ac_site_file
+See \`config.log' for more details" "$LINENO" 5 ; }
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special files
+  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
+  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . "$cache_file";;
+      *)                      . "./$cache_file";;
+    esac
+  fi
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in $ac_precious_vars; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val=\$ac_cv_env_${ac_var}_value
+  eval ac_new_val=\$ac_env_${ac_var}_value
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+	# differences in whitespace do not lead to failure.
+	ac_old_val_w=`echo x $ac_old_val`
+	ac_new_val_w=`echo x $ac_new_val`
+	if test "$ac_old_val_w" != "$ac_new_val_w"; then
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	  ac_cache_corrupted=:
+	else
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+	  eval $ac_var=\$ac_old_val
+	fi
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
+$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
+$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+fi
+## -------------------- ##
+## Main body of script. ##
+## -------------------- ##
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+am__api_version='1.11'
+
+ac_aux_dir=
+for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
+  if test -f "$ac_dir/install-sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install-sh -c"
+    break
+  elif test -f "$ac_dir/install.sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install.sh -c"
+    break
+  elif test -f "$ac_dir/shtool"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/shtool install -c"
+    break
+  fi
+done
+if test -z "$ac_aux_dir"; then
+  as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
+fi
+
+# These three variables are undocumented and unsupported,
+# and are intended to be withdrawn in a future Autoconf release.
+# They can cause serious problems if a builder's source tree is in a directory
+# whose full name contains unusual characters.
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
+ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
+
+
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+# Reject install programs that cannot install multiple files.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
+$as_echo_n "checking for a BSD-compatible install... " >&6; }
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in #((
+  ./ | .// | /[cC]/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+	if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then
+	  if test $ac_prog = install &&
+	    grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # AIX install.  It has an incompatible calling convention.
+	    :
+	  elif test $ac_prog = install &&
+	    grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # program-specific install script used by HP pwplus--don't use.
+	    :
+	  else
+	    rm -rf conftest.one conftest.two conftest.dir
+	    echo one > conftest.one
+	    echo two > conftest.two
+	    mkdir conftest.dir
+	    if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
+	      test -s conftest.one && test -s conftest.two &&
+	      test -s conftest.dir/conftest.one &&
+	      test -s conftest.dir/conftest.two
+	    then
+	      ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+	      break 3
+	    fi
+	  fi
+	fi
+      done
+    done
+    ;;
+esac
+
+  done
+IFS=$as_save_IFS
+
+rm -rf conftest.one conftest.two conftest.dir
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    INSTALL=$ac_install_sh
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
+$as_echo "$INSTALL" >&6; }
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5
+$as_echo_n "checking whether build environment is sane... " >&6; }
+# Just in case
+sleep 1
+echo timestamp > conftest.file
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[\\\"\#\$\&\'\`$am_lf]*)
+    as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5 ;;
+esac
+case $srcdir in
+  *[\\\"\#\$\&\'\`$am_lf\ \	]*)
+    as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5 ;;
+esac
+
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+   if test "$*" = "X"; then
+      # -L didn't work.
+      set X `ls -t "$srcdir/configure" conftest.file`
+   fi
+   rm -f conftest.file
+   if test "$*" != "X $srcdir/configure conftest.file" \
+      && test "$*" != "X conftest.file $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      as_fn_error $? "ls -t appears to fail.  Make sure there is not a broken
+alias in your environment" "$LINENO" 5
+   fi
+
+   test "$2" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   as_fn_error $? "newly created file is older than distributed files!
+Check your system clock" "$LINENO" 5
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+test "$program_prefix" != NONE &&
+  program_transform_name="s&^&$program_prefix&;$program_transform_name"
+# Use a double $ so make ignores it.
+test "$program_suffix" != NONE &&
+  program_transform_name="s&\$&$program_suffix&;$program_transform_name"
+# Double any \ or $.
+# By default was `s,x,x', remove it if useless.
+ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
+program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
+
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --run true"; then
+  am_missing_run="$MISSING --run "
+else
+  am_missing_run=
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`missing' script is too old or missing" >&5
+$as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;}
+fi
+
+if test x"${install_sh}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'.  However `strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the `STRIP' environment variable to overrule this program.
+if test "$cross_compiling" != no; then
+  if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_STRIP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5
+$as_echo "$ac_ct_STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5
+$as_echo_n "checking for a thread-safe mkdir -p... " >&6; }
+if test -z "$MKDIR_P"; then
+  if test "${ac_cv_path_mkdir+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in mkdir gmkdir; do
+	 for ac_exec_ext in '' $ac_executable_extensions; do
+	   { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue
+	   case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #(
+	     'mkdir (GNU coreutils) '* | \
+	     'mkdir (coreutils) '* | \
+	     'mkdir (fileutils) '4.1*)
+	       ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext
+	       break 3;;
+	   esac
+	 done
+       done
+  done
+IFS=$as_save_IFS
+
+fi
+
+  test -d ./--version && rmdir ./--version
+  if test "${ac_cv_path_mkdir+set}" = set; then
+    MKDIR_P="$ac_cv_path_mkdir -p"
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for MKDIR_P within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    MKDIR_P="$ac_install_sh -d"
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5
+$as_echo "$MKDIR_P" >&6; }
+
+mkdir_p="$MKDIR_P"
+case $mkdir_p in
+  [\\/$]* | ?:[\\/]*) ;;
+  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+
+for ac_prog in gawk mawk nawk awk
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_AWK+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AWK"; then
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_AWK="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
+$as_echo "$AWK" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AWK" && break
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
+$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
+set x ${MAKE-make}
+ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
+if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\"" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.make <<\_ACEOF
+SHELL = /bin/sh
+all:
+	@echo '@@@%%%=$(MAKE)=@@@%%%'
+_ACEOF
+# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
+case `${MAKE-make} -f conftest.make 2>/dev/null` in
+  *@@@%%%=?*=@@@%%%*)
+    eval ac_cv_prog_make_${ac_make}_set=yes;;
+  *)
+    eval ac_cv_prog_make_${ac_make}_set=no;;
+esac
+rm -f conftest.make
+fi
+if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+  SET_MAKE=
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  am__isrc=' -I$(srcdir)'
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+
+
+# Define the identity of the package.
+ PACKAGE='pktools'
+ VERSION='2.1'
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE "$PACKAGE"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define VERSION "$VERSION"
+_ACEOF
+
+# Some tools Automake needs.
+
+ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"}
+
+
+AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"}
+
+
+AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"}
+
+
+AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"}
+
+
+MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
+
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+# Always define AMTAR for backward compatibility.
+
+AMTAR=${AMTAR-"${am_missing_run}tar"}
+
+am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
+
+
+
+
+
+
+
+
+# Check whether --with-gdal was given.
+if test "${with_gdal+set}" = set; then :
+  withval=$with_gdal; ac_gdal_config_path=$withval
+else
+  gdal_config_system=check
+fi
+
+
+        if test "x$gdal_config_system" = xcheck; then :
+  # Extract the first word of "gdal-config", so it can be a program name with args.
+set dummy gdal-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_GDAL_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $GDAL_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_GDAL_CONFIG="$GDAL_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_GDAL_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+GDAL_CONFIG=$ac_cv_path_GDAL_CONFIG
+if test -n "$GDAL_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GDAL_CONFIG" >&5
+$as_echo "$GDAL_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+else
+  # Extract the first word of "gdal-config", so it can be a program name with args.
+set dummy gdal-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_GDAL_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $GDAL_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_GDAL_CONFIG="$GDAL_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in `dirname $ac_gdal_config_path 2> /dev/null`
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_GDAL_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_GDAL_CONFIG" && ac_cv_path_GDAL_CONFIG="no"
+  ;;
+esac
+fi
+GDAL_CONFIG=$ac_cv_path_GDAL_CONFIG
+if test -n "$GDAL_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GDAL_CONFIG" >&5
+$as_echo "$GDAL_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+fi
+
+    if test ! -x "$GDAL_CONFIG"; then
+        as_fn_error $? "gdal-config does not exist or it is not an exectuable file" "$LINENO" 5
+            GDAL_CONFIG="no"
+            found_gdal="no"
+    fi
+
+    GDAL_VERSION=""
+    GDAL_CFLAGS=""
+    GDAL_LDFLAGS=""
+    GDAL_DEP_LDFLAGS=""
+    GDAL_OGR_ENABLED=""
+
+
+
+    if test "$GDAL_CONFIG" != "no"; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GDAL library" >&5
+$as_echo_n "checking for GDAL library... " >&6; }
+
+        GDAL_VERSION="`$GDAL_CONFIG --version`"
+        GDAL_CFLAGS="`$GDAL_CONFIG --cflags`"
+        GDAL_LDFLAGS="`$GDAL_CONFIG --libs`"
+        GDAL_DEP_LDFLAGS="`$GDAL_CONFIG --dep-libs`"
+
+
+$as_echo "#define HAVE_GDAL 1" >>confdefs.h
+
+
+        found_gdal="yes"
+    else
+        found_gdal="no"
+    fi
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $found_gdal" >&5
+$as_echo "$found_gdal" >&6; }
+
+    if test "$found_gdal" = "yes"; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OGR support in GDAL library" >&5
+$as_echo_n "checking for OGR support in GDAL library... " >&6; }
+
+        GDAL_OGR_ENABLED="`$GDAL_CONFIG --ogr-enabled`"
+
+$as_echo "#define HAVE_GDAL_OGR 1" >>confdefs.h
+
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GDAL_OGR_ENABLED" >&5
+$as_echo "$GDAL_OGR_ENABLED" >&6; }
+    fi
+
+
+    gdal_version_req=
+    if test "$found_gdal" = "yes" -a -n "$gdal_version_req"; then
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking if GDAL version is >= $gdal_version_req" >&5
+$as_echo_n "checking if GDAL version is >= $gdal_version_req... " >&6; }
+
+                        gdal_version_req_major=`expr $gdal_version_req : '\([0-9]*\)'`
+        gdal_version_req_minor=`expr $gdal_version_req : '[0-9]*\.\([0-9]*\)'`
+        gdal_version_req_micro=`expr $gdal_version_req : '[0-9]*\.[0-9]*\.\([0-9]*\)'`
+        if test "x$gdal_version_req_micro" = "x"; then
+            gdal_version_req_micro="0"
+        fi
+
+        gdal_version_req_number=`expr $gdal_version_req_major \* 1000000 \
+                                   \+ $gdal_version_req_minor \* 1000 \
+                                   \+ $gdal_version_req_micro`
+
+                        gdal_version_major=`expr $GDAL_VERSION : '\([0-9]*\)'`
+        gdal_version_minor=`expr $GDAL_VERSION : '[0-9]*\.\([0-9]*\)'`
+        gdal_version_micro=`expr $GDAL_VERSION : '[0-9]*\.[0-9]*\.\([0-9]*\)'`
+        if test "x$gdal_version_micro" = "x"; then
+            gdal_version_micro="0"
+        fi
+
+        gdal_version_number=`expr $gdal_version_major \* 1000000 \
+                                   \+ $gdal_version_minor \* 1000 \
+                                   \+ $gdal_version_micro`
+
+        gdal_version_check=`expr $gdal_version_number \>\= $gdal_version_req_number`
+        if test "$gdal_version_check" = "1"; then
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+        else
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+as_fn_error $? "GDAL $GDAL_VERSION found, but required version is $gdal_version_req" "$LINENO" 5
+        fi
+    fi
+
+
+
+
+
+
+
+GDAL_FOUND="no"
+if test ! -z "$GDAL_CFLAGS" -a ! -z "$GDAL_LDFLAGS"; then
+    GDAL_FOUND="yes"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $GDAL_VERSION" >&5
+$as_echo "$as_me: WARNING: $GDAL_VERSION" >&2;}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $GDAL_CFLAGS" >&5
+$as_echo "$as_me: WARNING: $GDAL_CFLAGS" >&2;}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $GDAL_LDFLAGS" >&5
+$as_echo "$as_me: WARNING: $GDAL_LDFLAGS" >&2;}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $GDAL_DEP_LDFLAGS" >&5
+$as_echo "$as_me: WARNING: $GDAL_DEP_LDFLAGS" >&2;}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $GDAL_OGR_ENABLED" >&5
+$as_echo "$as_me: WARNING: $GDAL_OGR_ENABLED" >&2;}
+
+# check for C++ compiler and the library compiler
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+if test -z "$CXX"; then
+  if test -n "$CCC"; then
+    CXX=$CCC
+  else
+    if test -n "$ac_tool_prefix"; then
+  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CXX+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CXX"; then
+  ac_cv_prog_CXX="$CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CXX=$ac_cv_prog_CXX
+if test -n "$CXX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5
+$as_echo "$CXX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CXX" && break
+  done
+fi
+if test -z "$CXX"; then
+  ac_ct_CXX=$CXX
+  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CXX"; then
+  ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CXX="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CXX=$ac_cv_prog_ac_ct_CXX
+if test -n "$ac_ct_CXX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5
+$as_echo "$ac_ct_CXX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CXX" && break
+done
+
+  if test "x$ac_ct_CXX" = x; then
+    CXX="g++"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CXX=$ac_ct_CXX
+  fi
+fi
+
+  fi
+fi
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C++ compiler works" >&5
+$as_echo_n "checking whether the C++ compiler works... " >&6; }
+ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+
+# The possible output files:
+ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
+
+ac_rmfiles=
+for ac_file in $ac_files
+do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+  esac
+done
+rm -f $ac_rmfiles
+
+if { { ac_try="$ac_link_default"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link_default") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
+# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
+# in a Makefile.  We should not override ac_cv_exeext if it was cached,
+# so that the user can short-circuit this test for compilers unknown to
+# Autoconf.
+for ac_file in $ac_files ''
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
+	;;
+    [ab].out )
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
+    *.* )
+	if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+	then :; else
+	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	fi
+	# We set ac_cv_exeext here because the later test for it is not
+	# safe: cross compilers may not add the suffix if given an `-o'
+	# argument, so we may need to know it at that point already.
+	# Even if this section looks crufty: it has the advantage of
+	# actually working.
+	break;;
+    * )
+	break;;
+  esac
+done
+test "$ac_cv_exeext" = no && ac_cv_exeext=
+
+else
+  ac_file=''
+fi
+if test -z "$ac_file"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "C++ compiler cannot create executables
+See \`config.log' for more details" "$LINENO" 5 ; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler default output file name" >&5
+$as_echo_n "checking for C++ compiler default output file name... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
+ac_exeext=$ac_cv_exeext
+
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
+$as_echo_n "checking for suffix of executables... " >&6; }
+if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	  break;;
+    * ) break;;
+  esac
+done
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details" "$LINENO" 5 ; }
+fi
+rm -f conftest conftest$ac_cv_exeext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
+$as_echo "$ac_cv_exeext" >&6; }
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files="$ac_clean_files conftest.out"
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+if test "$cross_compiling" != yes; then
+  { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+  if { ac_try='./conftest$ac_cv_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run C++ compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details" "$LINENO" 5 ; }
+    fi
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
+$as_echo_n "checking for suffix of object files... " >&6; }
+if test "${ac_cv_objext+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  for ac_file in conftest.o conftest.obj conftest.*; do
+  test -f "$ac_file" || continue;
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of object files: cannot compile
+See \`config.log' for more details" "$LINENO" 5 ; }
+fi
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
+$as_echo "$ac_cv_objext" >&6; }
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5
+$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; }
+if test "${ac_cv_cxx_compiler_gnu+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_compiler_gnu=yes
+else
+  ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_cxx_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5
+$as_echo "$ac_cv_cxx_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GXX=yes
+else
+  GXX=
+fi
+ac_test_CXXFLAGS=${CXXFLAGS+set}
+ac_save_CXXFLAGS=$CXXFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5
+$as_echo_n "checking whether $CXX accepts -g... " >&6; }
+if test "${ac_cv_prog_cxx_g+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+   ac_cxx_werror_flag=yes
+   ac_cv_prog_cxx_g=no
+   CXXFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_cv_prog_cxx_g=yes
+else
+  CXXFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+
+else
+  ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+	 CXXFLAGS="-g"
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_cv_prog_cxx_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5
+$as_echo "$ac_cv_prog_cxx_g" >&6; }
+if test "$ac_test_CXXFLAGS" = set; then
+  CXXFLAGS=$ac_save_CXXFLAGS
+elif test $ac_cv_prog_cxx_g = yes; then
+  if test "$GXX" = yes; then
+    CXXFLAGS="-g -O2"
+  else
+    CXXFLAGS="-g"
+  fi
+else
+  if test "$GXX" = yes; then
+    CXXFLAGS="-O2"
+  else
+    CXXFLAGS=
+  fi
+fi
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+DEPDIR="${am__leading_dot}deps"
+
+ac_config_commands="$ac_config_commands depfiles"
+
+
+am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+	@echo this is the am__doit target
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5
+$as_echo_n "checking for style of include used by $am_make... " >&6; }
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# Ignore all kinds of additional output from `make'.
+case `$am_make -s -f confmf 2> /dev/null` in #(
+*the\ am__doit\ target*)
+  am__include=include
+  am__quote=
+  _am_result=GNU
+  ;;
+esac
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   case `$am_make -s -f confmf 2> /dev/null` in #(
+   *the\ am__doit\ target*)
+     am__include=.include
+     am__quote="\""
+     _am_result=BSD
+     ;;
+   esac
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5
+$as_echo "$_am_result" >&6; }
+rm -f confinc confmf
+
+# Check whether --enable-dependency-tracking was given.
+if test "${enable_dependency_tracking+set}" = set; then :
+  enableval=$enable_dependency_tracking;
+fi
+
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+fi
+ if test "x$enable_dependency_tracking" != xno; then
+  AMDEP_TRUE=
+  AMDEP_FALSE='#'
+else
+  AMDEP_TRUE='#'
+  AMDEP_FALSE=
+fi
+
+
+
+depcc="$CXX"  am_compiler_list=
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
+$as_echo_n "checking dependency style of $depcc... " >&6; }
+if test "${am_cv_CXX_dependencies_compiler_type+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CXX_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  am__universal=false
+  case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    msvisualcpp | msvcmsys)
+      # This compiler won't grok `-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CXX_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CXX_dependencies_compiler_type=none
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CXX_dependencies_compiler_type" >&5
+$as_echo "$am_cv_CXX_dependencies_compiler_type" >&6; }
+CXXDEPMODE=depmode=$am_cv_CXX_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CXX_dependencies_compiler_type" = gcc3; then
+  am__fastdepCXX_TRUE=
+  am__fastdepCXX_FALSE='#'
+else
+  am__fastdepCXX_TRUE='#'
+  am__fastdepCXX_FALSE=
+fi
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_RANLIB+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+    RANLIB=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+
+# check if the source folder is correct
+
+
+
+# Check whether --with-gdal was given.
+if test "${with_gdal+set}" = set; then :
+  withval=$with_gdal; ac_gdal_config_path=$withval
+else
+  gdal_config_system=check
+fi
+
+
+        if test "x$gdal_config_system" = xcheck; then :
+  # Extract the first word of "gdal-config", so it can be a program name with args.
+set dummy gdal-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_GDAL_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $GDAL_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_GDAL_CONFIG="$GDAL_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_GDAL_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+GDAL_CONFIG=$ac_cv_path_GDAL_CONFIG
+if test -n "$GDAL_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GDAL_CONFIG" >&5
+$as_echo "$GDAL_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+else
+  # Extract the first word of "gdal-config", so it can be a program name with args.
+set dummy gdal-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_GDAL_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $GDAL_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_GDAL_CONFIG="$GDAL_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in `dirname $ac_gdal_config_path 2> /dev/null`
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_GDAL_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_GDAL_CONFIG" && ac_cv_path_GDAL_CONFIG="no"
+  ;;
+esac
+fi
+GDAL_CONFIG=$ac_cv_path_GDAL_CONFIG
+if test -n "$GDAL_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GDAL_CONFIG" >&5
+$as_echo "$GDAL_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+fi
+
+    if test ! -x "$GDAL_CONFIG"; then
+        as_fn_error $? "gdal-config does not exist or it is not an exectuable file" "$LINENO" 5
+            GDAL_CONFIG="no"
+            found_gdal="no"
+    fi
+
+    GDAL_VERSION=""
+    GDAL_CFLAGS=""
+    GDAL_LDFLAGS=""
+    GDAL_DEP_LDFLAGS=""
+    GDAL_OGR_ENABLED=""
+
+
+
+    if test "$GDAL_CONFIG" != "no"; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GDAL library" >&5
+$as_echo_n "checking for GDAL library... " >&6; }
+
+        GDAL_VERSION="`$GDAL_CONFIG --version`"
+        GDAL_CFLAGS="`$GDAL_CONFIG --cflags`"
+        GDAL_LDFLAGS="`$GDAL_CONFIG --libs`"
+        GDAL_DEP_LDFLAGS="`$GDAL_CONFIG --dep-libs`"
+
+
+$as_echo "#define HAVE_GDAL 1" >>confdefs.h
+
+
+        found_gdal="yes"
+    else
+        found_gdal="no"
+    fi
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $found_gdal" >&5
+$as_echo "$found_gdal" >&6; }
+
+    if test "$found_gdal" = "yes"; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OGR support in GDAL library" >&5
+$as_echo_n "checking for OGR support in GDAL library... " >&6; }
+
+        GDAL_OGR_ENABLED="`$GDAL_CONFIG --ogr-enabled`"
+
+$as_echo "#define HAVE_GDAL_OGR 1" >>confdefs.h
+
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GDAL_OGR_ENABLED" >&5
+$as_echo "$GDAL_OGR_ENABLED" >&6; }
+    fi
+
+
+    gdal_version_req=1.8.0
+    if test "$found_gdal" = "yes" -a -n "$gdal_version_req"; then
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking if GDAL version is >= $gdal_version_req" >&5
+$as_echo_n "checking if GDAL version is >= $gdal_version_req... " >&6; }
+
+                        gdal_version_req_major=`expr $gdal_version_req : '\([0-9]*\)'`
+        gdal_version_req_minor=`expr $gdal_version_req : '[0-9]*\.\([0-9]*\)'`
+        gdal_version_req_micro=`expr $gdal_version_req : '[0-9]*\.[0-9]*\.\([0-9]*\)'`
+        if test "x$gdal_version_req_micro" = "x"; then
+            gdal_version_req_micro="0"
+        fi
+
+        gdal_version_req_number=`expr $gdal_version_req_major \* 1000000 \
+                                   \+ $gdal_version_req_minor \* 1000 \
+                                   \+ $gdal_version_req_micro`
+
+                        gdal_version_major=`expr $GDAL_VERSION : '\([0-9]*\)'`
+        gdal_version_minor=`expr $GDAL_VERSION : '[0-9]*\.\([0-9]*\)'`
+        gdal_version_micro=`expr $GDAL_VERSION : '[0-9]*\.[0-9]*\.\([0-9]*\)'`
+        if test "x$gdal_version_micro" = "x"; then
+            gdal_version_micro="0"
+        fi
+
+        gdal_version_number=`expr $gdal_version_major \* 1000000 \
+                                   \+ $gdal_version_minor \* 1000 \
+                                   \+ $gdal_version_micro`
+
+        gdal_version_check=`expr $gdal_version_number \>\= $gdal_version_req_number`
+        if test "$gdal_version_check" = "1"; then
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+        else
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+as_fn_error $? "GDAL $GDAL_VERSION found, but required version is $gdal_version_req" "$LINENO" 5
+        fi
+    fi
+
+
+
+
+
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+          if test -n "$ac_tool_prefix"; then
+    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  fi
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl.exe
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl.exe
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CC" && break
+done
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+fi
+
+fi
+
+
+test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "no acceptable C compiler found in \$PATH
+See \`config.log' for more details" "$LINENO" 5 ; }
+
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if test "${ac_cv_c_compiler_gnu+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_compiler_gnu=yes
+else
+  ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GCC=yes
+else
+  GCC=
+fi
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if test "${ac_cv_prog_cc_g+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_c_werror_flag=$ac_c_werror_flag
+   ac_c_werror_flag=yes
+   ac_cv_prog_cc_g=no
+   CFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+else
+  CFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  ac_c_werror_flag=$ac_save_c_werror_flag
+	 CFLAGS="-g"
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_c_werror_flag=$ac_save_c_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if test "${ac_cv_prog_cc_c89+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_prog_cc_c89=no
+ac_save_CC=$CC
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+   inside strings and character constants.  */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_c89=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext
+  test "x$ac_cv_prog_cc_c89" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CC=$ac_save_CC
+
+fi
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+  x)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
+  xno)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
+  *)
+    CC="$CC $ac_cv_prog_cc_c89"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
+esac
+if test "x$ac_cv_prog_cc_c89" != xno; then :
+
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+depcc="$CC"   am_compiler_list=
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
+$as_echo_n "checking dependency style of $depcc... " >&6; }
+if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CC_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  am__universal=false
+  case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    msvisualcpp | msvcmsys)
+      # This compiler won't grok `-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CC_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CC_dependencies_compiler_type=none
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5
+$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; }
+CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then
+  am__fastdepCC_TRUE=
+  am__fastdepCC_FALSE='#'
+else
+  am__fastdepCC_TRUE='#'
+  am__fastdepCC_FALSE=
+fi
+
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
+$as_echo_n "checking how to run the C preprocessor... " >&6; }
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+  if test "${ac_cv_prog_CPP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+  break
+fi
+
+    done
+    ac_cv_prog_CPP=$CPP
+
+fi
+  CPP=$ac_cv_prog_CPP
+else
+  ac_cv_prog_CPP=$CPP
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
+$as_echo "$CPP" >&6; }
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details" "$LINENO" 5 ; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if test "${ac_cv_path_GREP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$GREP"; then
+  ac_path_GREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in grep ggrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+# Check for GNU ac_path_GREP and select it if it is found.
+  # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'GREP' >> "conftest.nl"
+    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_GREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_GREP="$ac_path_GREP"
+      ac_path_GREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_GREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_GREP"; then
+    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_GREP=$GREP
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if test "${ac_cv_path_EGREP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     if test -z "$EGREP"; then
+  ac_path_EGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in egrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+  # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'EGREP' >> "conftest.nl"
+    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_EGREP="$ac_path_EGREP"
+      ac_path_EGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_EGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_EGREP"; then
+    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_EGREP=$EGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_header_stdc=yes
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then :
+  :
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+		  inttypes.h stdint.h unistd.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
+"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+for ac_header in gdal.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "gdal.h" "ac_cv_header_gdal_h" "$ac_includes_default"
+if test "x$ac_cv_header_gdal_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_GDAL_H 1
+_ACEOF
+
+fi
+
+done
+
+
+# Checks for packages
+#PKG_CHECK_MODULES(FANN, fann >= 2.1.0, [HAVE_FANN=1], [HAVE_FANN=0])
+#AM_CONDITIONAL([USE_FANN], [test "$HAVE_FANN" -eq 1])
+
+
+# Check whether --with-fann was given.
+if test "${with_fann+set}" = set; then :
+  withval=$with_fann;
+else
+  with_fann=no
+fi
+
+
+
+
+
+
+
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+	if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
+set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_PKG_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
+$as_echo "$PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_PKG_CONFIG"; then
+  ac_pt_PKG_CONFIG=$PKG_CONFIG
+  # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_ac_pt_PKG_CONFIG+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG
+if test -n "$ac_pt_PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5
+$as_echo "$ac_pt_PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_PKG_CONFIG" = x; then
+    PKG_CONFIG=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    PKG_CONFIG=$ac_pt_PKG_CONFIG
+  fi
+else
+  PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
+fi
+
+fi
+if test -n "$PKG_CONFIG"; then
+	_pkg_min_version=0.9.0
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5
+$as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; }
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	else
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+		PKG_CONFIG=""
+	fi
+fi
+if test "x$with_fann" != xno; then :
+
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for FANN" >&5
+$as_echo_n "checking for FANN... " >&6; }
+
+if test -n "$FANN_CFLAGS"; then
+    pkg_cv_FANN_CFLAGS="$FANN_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"fann >= 2.1.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "fann >= 2.1.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_FANN_CFLAGS=`$PKG_CONFIG --cflags "fann >= 2.1.0" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$FANN_LIBS"; then
+    pkg_cv_FANN_LIBS="$FANN_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"fann >= 2.1.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "fann >= 2.1.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_FANN_LIBS=`$PKG_CONFIG --libs "fann >= 2.1.0" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        FANN_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "fann >= 2.1.0" 2>&1`
+        else
+	        FANN_PKG_ERRORS=`$PKG_CONFIG --print-errors "fann >= 2.1.0" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$FANN_PKG_ERRORS" >&5
+
+	HAVE_FANN=0
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	HAVE_FANN=0
+else
+	FANN_CFLAGS=$pkg_cv_FANN_CFLAGS
+	FANN_LIBS=$pkg_cv_FANN_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	HAVE_FANN=1
+fi
+	 if test "$HAVE_FANN" -eq 1; then
+  USE_FANN_TRUE=
+  USE_FANN_FALSE='#'
+else
+  USE_FANN_TRUE='#'
+  USE_FANN_FALSE=
+fi
+
+
+else
+
+	 if false; then
+  USE_FANN_TRUE=
+  USE_FANN_FALSE='#'
+else
+  USE_FANN_TRUE='#'
+  USE_FANN_FALSE=
+fi
+
+
+fi
+
+
+# Check whether --with-las was given.
+if test "${with_las+set}" = set; then :
+  withval=$with_las;
+else
+  with_las=no
+fi
+
+if test "x$with_las" != xno; then :
+
+	 if true; then
+  USE_LAS_TRUE=
+  USE_LAS_FALSE='#'
+else
+  USE_LAS_TRUE='#'
+  USE_LAS_FALSE=
+fi
+
+
+else
+
+	 if false; then
+  USE_LAS_TRUE=
+  USE_LAS_FALSE='#'
+else
+  USE_LAS_TRUE='#'
+  USE_LAS_FALSE=
+fi
+
+
+fi
+
+if $USE_LAS; then
+   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \"USE_LAS=true\"" >&5
+$as_echo "$as_me: WARNING: \"USE_LAS=true\"" >&2;}
+   FILECLASSES_OPT="src/fileclasses"
+
+fi
+
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GSL" >&5
+$as_echo_n "checking for GSL... " >&6; }
+
+if test -n "$GSL_CFLAGS"; then
+    pkg_cv_GSL_CFLAGS="$GSL_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gsl >= 1.14\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "gsl >= 1.14") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GSL_CFLAGS=`$PKG_CONFIG --cflags "gsl >= 1.14" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$GSL_LIBS"; then
+    pkg_cv_GSL_LIBS="$GSL_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gsl >= 1.14\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "gsl >= 1.14") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GSL_LIBS=`$PKG_CONFIG --libs "gsl >= 1.14" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        GSL_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "gsl >= 1.14" 2>&1`
+        else
+	        GSL_PKG_ERRORS=`$PKG_CONFIG --print-errors "gsl >= 1.14" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$GSL_PKG_ERRORS" >&5
+
+	HAVE_GSL=0
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	HAVE_GSL=0
+else
+	GSL_CFLAGS=$pkg_cv_GSL_CFLAGS
+	GSL_LIBS=$pkg_cv_GSL_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	HAVE_GSL=1
+fi
+ if test "$HAVE_GSL" -eq 1; then
+  USE_GSL_TRUE=
+  USE_GSL_FALSE='#'
+else
+  USE_GSL_TRUE='#'
+  USE_GSL_FALSE=
+fi
+
+
+# use the C++ compiler for the following checks
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+
+# Checks for header files.
+
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C++ preprocessor" >&5
+$as_echo_n "checking how to run the C++ preprocessor... " >&6; }
+if test -z "$CXXCPP"; then
+  if test "${ac_cv_prog_CXXCPP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+      # Double quotes because CXXCPP needs to be expanded
+    for CXXCPP in "$CXX -E" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_cxx_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_cxx_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_cxx_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+  break
+fi
+
+    done
+    ac_cv_prog_CXXCPP=$CXXCPP
+
+fi
+  CXXCPP=$ac_cv_prog_CXXCPP
+else
+  ac_cv_prog_CXXCPP=$CXXCPP
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXXCPP" >&5
+$as_echo "$CXXCPP" >&6; }
+ac_preproc_ok=false
+for ac_cxx_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_cxx_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_cxx_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "C++ preprocessor \"$CXXCPP\" fails sanity check
+See \`config.log' for more details" "$LINENO" 5 ; }
+fi
+
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_cv_header_stdc=yes
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then :
+  :
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_run "$LINENO"; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
+
+fi
+
+for ac_header in string
+do :
+  ac_fn_cxx_check_header_mongrel "$LINENO" "string" "ac_cv_header_string" "$ac_includes_default"
+if test "x$ac_cv_header_string" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_STRING 1
+_ACEOF
+
+fi
+
+done
+
+for ac_header in iostream
+do :
+  ac_fn_cxx_check_header_mongrel "$LINENO" "iostream" "ac_cv_header_iostream" "$ac_includes_default"
+if test "x$ac_cv_header_iostream" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_IOSTREAM 1
+_ACEOF
+
+fi
+
+done
+
+
+# Checks for typedefs, structures, and compiler characteristics.
+ac_fn_cxx_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default"
+if test "x$ac_cv_type_size_t" = x""yes; then :
+
+else
+
+cat >>confdefs.h <<_ACEOF
+#define size_t unsigned int
+_ACEOF
+
+fi
+
+
+# distribute additional compiler and linker flags
+# --> set these variables instead of CXXFLAGS or LDFLAGS
+
+
+
+
+# files to generate via autotools (.am or .in source files)
+ac_config_headers="$ac_config_headers config.h"
+
+ac_config_files="$ac_config_files Makefile src/base/Makefile src/algorithms/Makefile src/imageclasses/Makefile src/fileclasses/Makefile src/apps/Makefile"
+
+
+# generate the final Makefile etc.
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, we kill variables containing newlines.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(
+  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+
+  (set) 2>&1 |
+    case $as_nl`(ac_space=' '; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      # `set' does not quote correctly, so add quotes: double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \.
+      sed -n \
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;; #(
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+) |
+  sed '
+     /^ac_cv_env_/b end
+     t clear
+     :clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+  if test -w "$cache_file"; then
+    test "x$cache_file" != "x/dev/null" &&
+      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
+    cat confcache >$cache_file
+  else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+DEFS=-DHAVE_CONFIG_H
+
+ac_libobjs=
+ac_ltlibobjs=
+U=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
+  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
+  #    will be set to the directory where LIBOBJS objects are built.
+  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+ if test -n "$EXEEXT"; then
+  am__EXEEXT_TRUE=
+  am__EXEEXT_FALSE='#'
+else
+  am__EXEEXT_TRUE='#'
+  am__EXEEXT_FALSE=
+fi
+
+if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then
+  as_fn_error $? "conditional \"AMDEP\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then
+  as_fn_error $? "conditional \"am__fastdepCXX\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then
+  as_fn_error $? "conditional \"am__fastdepCC\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${USE_FANN_TRUE}" && test -z "${USE_FANN_FALSE}"; then
+  as_fn_error $? "conditional \"USE_FANN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${USE_FANN_TRUE}" && test -z "${USE_FANN_FALSE}"; then
+  as_fn_error $? "conditional \"USE_FANN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${USE_LAS_TRUE}" && test -z "${USE_LAS_FALSE}"; then
+  as_fn_error $? "conditional \"USE_LAS\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${USE_LAS_TRUE}" && test -z "${USE_LAS_FALSE}"; then
+  as_fn_error $? "conditional \"USE_LAS\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${USE_GSL_TRUE}" && test -z "${USE_GSL_FALSE}"; then
+  as_fn_error $? "conditional \"USE_GSL\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+
+: ${CONFIG_STATUS=./config.status}
+ac_write_fail=0
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+as_write_fail=0
+cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -p'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -p'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -p'
+  fi
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in #(
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+## ----------------------------------- ##
+## Main body of $CONFIG_STATUS script. ##
+## ----------------------------------- ##
+_ASEOF
+test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# Save the log message, to keep $0 and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by pktools $as_me 2.1, which was
+generated by GNU Autoconf 2.67.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+case $ac_config_headers in *"
+"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
+esac
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+config_headers="$ac_config_headers"
+config_commands="$ac_config_commands"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files and other configuration actions
+from templates according to the current configuration.  Unless the files
+and actions are specified as TAGs, all are instantiated by default.
+
+Usage: $0 [OPTION]... [TAG]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number and configuration settings, then exit
+      --config     print configuration, then exit
+  -q, --quiet, --silent
+                   do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+      --file=FILE[:TEMPLATE]
+                   instantiate the configuration file FILE
+      --header=FILE[:TEMPLATE]
+                   instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Configuration commands:
+$config_commands
+
+Report bugs to <kempenep at gmail.com>."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
+ac_cs_version="\\
+pktools config.status 2.1
+configured by $0, generated by GNU Autoconf 2.67,
+  with options \\"\$ac_cs_config\\"
+
+Copyright (C) 2010 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+INSTALL='$INSTALL'
+MKDIR_P='$MKDIR_P'
+AWK='$AWK'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=?*)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  --*=)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=
+    ac_shift=:
+    ;;
+  *)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+    $as_echo "$ac_cs_version"; exit ;;
+  --config | --confi | --conf | --con | --co | --c )
+    $as_echo "$ac_cs_config"; exit ;;
+  --debug | --debu | --deb | --de | --d | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    '') as_fn_error $? "missing file argument" ;;
+    esac
+    as_fn_append CONFIG_FILES " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    as_fn_append CONFIG_HEADERS " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --he | --h)
+    # Conflict between --help and --header
+    as_fn_error $? "ambiguous option: \`$1'
+Try \`$0 --help' for more information.";;
+  --help | --hel | -h )
+    $as_echo "$ac_cs_usage"; exit ;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) as_fn_error $? "unrecognized option: \`$1'
+Try \`$0 --help' for more information." ;;
+
+  *) as_fn_append ac_config_targets " $1"
+     ac_need_defaults=false ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  shift
+  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+  CONFIG_SHELL='$SHELL'
+  export CONFIG_SHELL
+  exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+  $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+#
+# INIT-COMMANDS
+#
+AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+  case $ac_config_target in
+    "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
+    "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
+    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+    "src/base/Makefile") CONFIG_FILES="$CONFIG_FILES src/base/Makefile" ;;
+    "src/algorithms/Makefile") CONFIG_FILES="$CONFIG_FILES src/algorithms/Makefile" ;;
+    "src/imageclasses/Makefile") CONFIG_FILES="$CONFIG_FILES src/imageclasses/Makefile" ;;
+    "src/fileclasses/Makefile") CONFIG_FILES="$CONFIG_FILES src/fileclasses/Makefile" ;;
+    "src/apps/Makefile") CONFIG_FILES="$CONFIG_FILES src/apps/Makefile" ;;
+
+  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5 ;;
+  esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+  test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+  tmp=
+  trap 'exit_status=$?
+  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
+' 0
+  trap 'as_fn_exit 1' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+  test -n "$tmp" && test -d "$tmp"
+}  ||
+{
+  tmp=./conf$$-$RANDOM
+  (umask 077 && mkdir "$tmp")
+} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr=`echo X | tr X '\015'`
+# On cygwin, bash can eat \r inside `` if the user requested igncr.
+# But we know of no other shell where ac_cr would be empty at this
+# point, so we can use a bashism as a fallback.
+if test "x$ac_cr" = x; then
+  eval ac_cr=\$\'\\r\'
+fi
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+  ac_cs_awk_cr='\\r'
+else
+  ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+  echo "cat >conf$$subs.awk <<_ACEOF" &&
+  echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+  echo "_ACEOF"
+} >conf$$subs.sh ||
+  as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  . ./conf$$subs.sh ||
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+
+  ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+  if test $ac_delim_n = $ac_delim_num; then
+    break
+  elif $ac_last_try; then
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\)..*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\)..*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+  N
+  s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$tmp/subs1.awk" <<_ACAWK &&
+  for (key in S) S_is_set[key] = 1
+  FS = ""
+
+}
+{
+  line = $ 0
+  nfields = split(line, field, "@")
+  substed = 0
+  len = length(field[1])
+  for (i = 2; i < nfields; i++) {
+    key = field[i]
+    keylen = length(key)
+    if (S_is_set[key]) {
+      value = S[key]
+      line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+      len += length(value) + length(field[++i])
+      substed = 1
+    } else
+      len += 1 + keylen
+  }
+
+  print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+  sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+  cat
+fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
+  || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
+# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=[	 ]*/{
+h
+s///
+s/^/:/
+s/[	 ]*$/:/
+s/:\$(srcdir):/:/g
+s/:\${srcdir}:/:/g
+s/:@srcdir@:/:/g
+s/^:*//
+s/:*$//
+x
+s/\(=[	 ]*\).*/\1/
+G
+s/\n//
+s/^[^=]*=[	 ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+# Set up the scripts for CONFIG_HEADERS section.
+# No need to generate them if there are no CONFIG_HEADERS.
+# This happens for instance with `./config.status Makefile'.
+if test -n "$CONFIG_HEADERS"; then
+cat >"$tmp/defines.awk" <<\_ACAWK ||
+BEGIN {
+_ACEOF
+
+# Transform confdefs.h into an awk script `defines.awk', embedded as
+# here-document in config.status, that substitutes the proper values into
+# config.h.in to produce config.h.
+
+# Create a delimiter string that does not exist in confdefs.h, to ease
+# handling of long lines.
+ac_delim='%!_!# '
+for ac_last_try in false false :; do
+  ac_t=`sed -n "/$ac_delim/p" confdefs.h`
+  if test -z "$ac_t"; then
+    break
+  elif $ac_last_try; then
+    as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+
+# For the awk script, D is an array of macro values keyed by name,
+# likewise P contains macro parameters if any.  Preserve backslash
+# newline sequences.
+
+ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
+sed -n '
+s/.\{148\}/&'"$ac_delim"'/g
+t rset
+:rset
+s/^[	 ]*#[	 ]*define[	 ][	 ]*/ /
+t def
+d
+:def
+s/\\$//
+t bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3"/p
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2"/p
+d
+:bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3\\\\\\n"\\/p
+t cont
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
+t cont
+d
+:cont
+n
+s/.\{148\}/&'"$ac_delim"'/g
+t clear
+:clear
+s/\\$//
+t bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/"/p
+d
+:bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
+b cont
+' <confdefs.h | sed '
+s/'"$ac_delim"'/"\\\
+"/g' >>$CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  for (key in D) D_is_set[key] = 1
+  FS = ""
+}
+/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
+  line = \$ 0
+  split(line, arg, " ")
+  if (arg[1] == "#") {
+    defundef = arg[2]
+    mac1 = arg[3]
+  } else {
+    defundef = substr(arg[1], 2)
+    mac1 = arg[2]
+  }
+  split(mac1, mac2, "(") #)
+  macro = mac2[1]
+  prefix = substr(line, 1, index(line, defundef) - 1)
+  if (D_is_set[macro]) {
+    # Preserve the white space surrounding the "#".
+    print prefix "define", macro P[macro] D[macro]
+    next
+  } else {
+    # Replace #undef with comments.  This is necessary, for example,
+    # in the case of _POSIX_SOURCE, which is predefined and required
+    # on some systems where configure will not decide to define it.
+    if (defundef == "undef") {
+      print "/*", prefix defundef, macro, "*/"
+      next
+    }
+  }
+}
+{ print }
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+  as_fn_error $? "could not setup config headers machinery" "$LINENO" 5
+fi # test -n "$CONFIG_HEADERS"
+
+
+eval set X "  :F $CONFIG_FILES  :H $CONFIG_HEADERS    :C $CONFIG_COMMANDS"
+shift
+for ac_tag
+do
+  case $ac_tag in
+  :[FHLC]) ac_mode=$ac_tag; continue;;
+  esac
+  case $ac_mode$ac_tag in
+  :[FHL]*:*);;
+  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5 ;;
+  :[FH]-) ac_tag=-:-;;
+  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+  esac
+  ac_save_IFS=$IFS
+  IFS=:
+  set x $ac_tag
+  IFS=$ac_save_IFS
+  shift
+  ac_file=$1
+  shift
+
+  case $ac_mode in
+  :L) ac_source=$1;;
+  :[FH])
+    ac_file_inputs=
+    for ac_f
+    do
+      case $ac_f in
+      -) ac_f="$tmp/stdin";;
+      *) # Look for the file first in the build tree, then in the source tree
+	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
+	 # because $ac_f cannot contain `:'.
+	 test -f "$ac_f" ||
+	   case $ac_f in
+	   [\\/$]*) false;;
+	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+	   esac ||
+	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5 ;;
+      esac
+      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+      as_fn_append ac_file_inputs " '$ac_f'"
+    done
+
+    # Let's still pretend it is `configure' which instantiates (i.e., don't
+    # use $as_me), people would be surprised to read:
+    #    /* config.h.  Generated by config.status.  */
+    configure_input='Generated from '`
+	  $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+	`' by configure.'
+    if test x"$ac_file" != x-; then
+      configure_input="$ac_file.  $configure_input"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+    fi
+    # Neutralize special characters interpreted by sed in replacement strings.
+    case $configure_input in #(
+    *\&* | *\|* | *\\* )
+       ac_sed_conf_input=`$as_echo "$configure_input" |
+       sed 's/[\\\\&|]/\\\\&/g'`;; #(
+    *) ac_sed_conf_input=$configure_input;;
+    esac
+
+    case $ac_tag in
+    *:-:* | *:-) cat >"$tmp/stdin" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5  ;;
+    esac
+    ;;
+  esac
+
+  ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  as_dir="$ac_dir"; as_fn_mkdir_p
+  ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+
+  case $ac_mode in
+  :F)
+  #
+  # CONFIG_FILE
+  #
+
+  case $INSTALL in
+  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+  *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
+  esac
+  ac_MKDIR_P=$MKDIR_P
+  case $MKDIR_P in
+  [\\/$]* | ?:[\\/]* ) ;;
+  */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;;
+  esac
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+ac_sed_dataroot='
+/datarootdir/ {
+  p
+  q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  ac_datarootdir_hack='
+  s&@datadir@&$datadir&g
+  s&@docdir@&$docdir&g
+  s&@infodir@&$infodir&g
+  s&@localedir@&$localedir&g
+  s&@mandir@&$mandir&g
+  s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s|@configure_input@|$ac_sed_conf_input|;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+s&@INSTALL@&$ac_INSTALL&;t t
+s&@MKDIR_P@&$ac_MKDIR_P&;t t
+$ac_datarootdir_hack
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \
+  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&5
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&2;}
+
+  rm -f "$tmp/stdin"
+  case $ac_file in
+  -) cat "$tmp/out" && rm -f "$tmp/out";;
+  *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
+  esac \
+  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ ;;
+  :H)
+  #
+  # CONFIG_HEADER
+  #
+  if test x"$ac_file" != x-; then
+    {
+      $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
+    } >"$tmp/config.h" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+    if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
+$as_echo "$as_me: $ac_file is unchanged" >&6;}
+    else
+      rm -f "$ac_file"
+      mv "$tmp/config.h" "$ac_file" \
+	|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
+    fi
+  else
+    $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
+      || as_fn_error $? "could not create -" "$LINENO" 5
+  fi
+# Compute "$ac_file"'s index in $config_headers.
+_am_arg="$ac_file"
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" ||
+$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$_am_arg" : 'X\(//\)[^/]' \| \
+	 X"$_am_arg" : 'X\(//\)$' \| \
+	 X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$_am_arg" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`/stamp-h$_am_stamp_count
+ ;;
+
+  :C)  { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
+$as_echo "$as_me: executing $ac_file commands" >&6;}
+ ;;
+  esac
+
+
+  case $ac_file$ac_mode in
+    "depfiles":C) test x"$AMDEP_TRUE" != x"" || {
+  # Autoconf 2.62 quotes --file arguments for eval, but not when files
+  # are listed without --file.  Let's play safe and only enable the eval
+  # if we detect the quoting.
+  case $CONFIG_FILES in
+  *\'*) eval set x "$CONFIG_FILES" ;;
+  *)   set x $CONFIG_FILES ;;
+  esac
+  shift
+  for mf
+  do
+    # Strip MF so we end up with the name of the file.
+    mf=`echo "$mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile or not.
+    # We used to match only the files named `Makefile.in', but
+    # some people rename them; so instead we look at the file content.
+    # Grep'ing the first line is not enough: some people post-process
+    # each Makefile.in and add a new line on top of each file to say so.
+    # Grep'ing the whole file is not good either: AIX grep has a line
+    # limit of 2048, but all sed's we know have understand at least 4000.
+    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
+      dirpart=`$as_dirname -- "$mf" ||
+$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$mf" : 'X\(//\)[^/]' \| \
+	 X"$mf" : 'X\(//\)$' \| \
+	 X"$mf" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$mf" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+    else
+      continue
+    fi
+    # Extract the definition of DEPDIR, am__include, and am__quote
+    # from the Makefile without running `make'.
+    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+    test -z "$DEPDIR" && continue
+    am__include=`sed -n 's/^am__include = //p' < "$mf"`
+    test -z "am__include" && continue
+    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+    # When using ansi2knr, U may be empty or an underscore; expand it
+    U=`sed -n 's/^U = //p' < "$mf"`
+    # Find all dependency output files, they are included files with
+    # $(DEPDIR) in their names.  We invoke sed twice because it is the
+    # simplest approach to changing $(DEPDIR) to its actual value in the
+    # expansion.
+    for file in `sed -n "
+      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+	 sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
+      # Make sure the directory exists.
+      test -f "$dirpart/$file" && continue
+      fdir=`$as_dirname -- "$file" ||
+$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$file" : 'X\(//\)[^/]' \| \
+	 X"$file" : 'X\(//\)$' \| \
+	 X"$file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      as_dir=$dirpart/$fdir; as_fn_mkdir_p
+      # echo "creating $dirpart/$file"
+      echo '# dummy' > "$dirpart/$file"
+    done
+  done
+}
+ ;;
+
+  esac
+done # for ac_tag
+
+
+as_fn_exit 0
+_ACEOF
+ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+  as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || as_fn_exit 1
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..4c2f774
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,90 @@
+AC_INIT([pktools], [2.1], [kempenep at gmail.com])
+AM_INIT_AUTOMAKE([-Wall -Werror foreign])
+AC_CONFIG_MACRO_DIR([m4])
+AX_LIB_GDAL()
+GDAL_FOUND="no"
+if test ! -z "$GDAL_CFLAGS" -a ! -z "$GDAL_LDFLAGS"; then
+    GDAL_FOUND="yes"
+fi
+AC_MSG_WARN([$GDAL_VERSION])
+AC_MSG_WARN([$GDAL_CFLAGS])
+AC_MSG_WARN([$GDAL_LDFLAGS])
+AC_MSG_WARN([$GDAL_DEP_LDFLAGS])
+AC_MSG_WARN([$GDAL_OGR_ENABLED])
+
+# check for C++ compiler and the library compiler
+AC_PROG_CXX
+AC_PROG_RANLIB
+
+# check if the source folder is correct
+AC_CONFIG_SRCDIR([src/apps/pkinfo.cc])
+AX_LIB_GDAL([1.8.0]) dnl uncomment if gdal version 1.8.0 is required
+
+AC_CHECK_HEADERS([gdal.h])
+
+# Checks for packages
+#PKG_CHECK_MODULES(FANN, fann >= 2.1.0, [HAVE_FANN=1], [HAVE_FANN=0])
+#AM_CONDITIONAL([USE_FANN], [test "$HAVE_FANN" -eq 1])
+
+AC_ARG_WITH([fann],
+	[AS_HELP_STRING([--with-fann], [use fann library] @@)],
+	[],
+	[with_fann=no])
+AS_IF([test "x$with_fann" != xno],
+	[
+	PKG_CHECK_MODULES(FANN, fann >= 2.1.0, [HAVE_FANN=1], [HAVE_FANN=0])
+	AM_CONDITIONAL([USE_FANN], [test "$HAVE_FANN" -eq 1])
+	], [
+	AM_CONDITIONAL(USE_FANN, false)
+	])
+
+AC_ARG_WITH([las],
+	[AS_HELP_STRING([--with-las], [use las library] @@)],
+	[],
+	[with_las=no])
+AS_IF([test "x$with_las" != xno],
+	[
+	AM_CONDITIONAL(USE_LAS, true)
+	], [
+	AM_CONDITIONAL(USE_LAS, false)
+	])
+
+if $USE_LAS; then
+   AC_MSG_WARN("USE_LAS=true")
+   FILECLASSES_OPT="src/fileclasses"
+   AC_SUBST([FILECLASSES_OPT])
+fi
+
+PKG_CHECK_MODULES(GSL, gsl >= 1.14, [HAVE_GSL=1], [HAVE_GSL=0])
+AM_CONDITIONAL([USE_GSL], [test "$HAVE_GSL" -eq 1])
+
+# use the C++ compiler for the following checks
+AC_LANG([C++])
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([string])
+AC_CHECK_HEADERS([iostream])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_TYPE_SIZE_T
+
+# distribute additional compiler and linker flags
+# --> set these variables instead of CXXFLAGS or LDFLAGS
+AC_SUBST([AM_CXXFLAGS])
+AC_SUBST([AM_LDFLAGS])
+AC_SUBST([LIBS])
+
+# files to generate via autotools (.am or .in source files)
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_FILES([
+Makefile
+src/base/Makefile
+src/algorithms/Makefile
+src/imageclasses/Makefile
+src/fileclasses/Makefile
+src/apps/Makefile
+])
+
+# generate the final Makefile etc.
+AC_OUTPUT
diff --git a/depcomp b/depcomp
new file mode 100755
index 0000000..df8eea7
--- /dev/null
+++ b/depcomp
@@ -0,0 +1,630 @@
+#! /bin/sh
+# depcomp - compile a program generating dependencies as side-effects
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
+# Software Foundation, Inc.
+
+# 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, 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 <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Originally written by Alexandre Oliva <oliva at dcc.unicamp.br>.
+
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: depcomp [--help] [--version] PROGRAM [ARGS]
+
+Run PROGRAMS ARGS to compile a file, generating dependencies
+as side-effects.
+
+Environment variables:
+  depmode     Dependency tracking mode.
+  source      Source file read by `PROGRAMS ARGS'.
+  object      Object file output by `PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
+  depfile     Dependency file to output.
+  tmpdepfile  Temporary file to use when outputing dependencies.
+  libtool     Whether libtool is used (yes/no).
+
+Report bugs to <bug-automake at gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "depcomp $scriptversion"
+    exit $?
+    ;;
+esac
+
+if test -z "$depmode" || test -z "$source" || test -z "$object"; then
+  echo "depcomp: Variables source, object and depmode must be set" 1>&2
+  exit 1
+fi
+
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
+tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
+
+rm -f "$tmpdepfile"
+
+# Some modes work just like other modes, but use different flags.  We
+# parameterize here, but still list the modes in the big case below,
+# to make depend.m4 easier to write.  Note that we *cannot* use a case
+# here, because this file can only contain one case statement.
+if test "$depmode" = hp; then
+  # HP compiler uses -M and no extra arg.
+  gccflag=-M
+  depmode=gcc
+fi
+
+if test "$depmode" = dashXmstdout; then
+   # This is just like dashmstdout with a different argument.
+   dashmflag=-xM
+   depmode=dashmstdout
+fi
+
+cygpath_u="cygpath -u -f -"
+if test "$depmode" = msvcmsys; then
+   # This is just like msvisualcpp but w/o cygpath translation.
+   # Just convert the backslash-escaped backslashes to single forward
+   # slashes to satisfy depend.m4
+   cygpath_u="sed s,\\\\\\\\,/,g"
+   depmode=msvisualcpp
+fi
+
+case "$depmode" in
+gcc3)
+## gcc 3 implements dependency tracking that does exactly what
+## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
+## it if -MD -MP comes after the -MF stuff.  Hmm.
+## Unfortunately, FreeBSD c89 acceptance of flags depends upon
+## the command line argument order; so add the flags where they
+## appear in depend2.am.  Note that the slowdown incurred here
+## affects only configure: in makefiles, %FASTDEP% shortcuts this.
+  for arg
+  do
+    case $arg in
+    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
+    *)  set fnord "$@" "$arg" ;;
+    esac
+    shift # fnord
+    shift # $arg
+  done
+  "$@"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  mv "$tmpdepfile" "$depfile"
+  ;;
+
+gcc)
+## There are various ways to get dependency output from gcc.  Here's
+## why we pick this rather obscure method:
+## - Don't want to use -MD because we'd like the dependencies to end
+##   up in a subdir.  Having to rename by hand is ugly.
+##   (We might end up doing this anyway to support other compilers.)
+## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
+##   -MM, not -M (despite what the docs say).
+## - Using -M directly means running the compiler twice (even worse
+##   than renaming).
+  if test -z "$gccflag"; then
+    gccflag=-MD,
+  fi
+  "$@" -Wp,"$gccflag$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+## The second -e expression handles DOS-style file names with drive letters.
+  sed -e 's/^[^:]*: / /' \
+      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
+## This next piece of magic avoids the `deleted header file' problem.
+## The problem is that when a header file which appears in a .P file
+## is deleted, the dependency causes make to die (because there is
+## typically no way to rebuild the header).  We avoid this by adding
+## dummy dependencies for each header file.  Too bad gcc doesn't do
+## this for us directly.
+  tr ' ' '
+' < "$tmpdepfile" |
+## Some versions of gcc put a space before the `:'.  On the theory
+## that the space means something, we add a space to the output as
+## well.
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+sgi)
+  if test "$libtool" = yes; then
+    "$@" "-Wp,-MDupdate,$tmpdepfile"
+  else
+    "$@" -MDupdate "$tmpdepfile"
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+
+  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
+    echo "$object : \\" > "$depfile"
+
+    # Clip off the initial element (the dependent).  Don't try to be
+    # clever and replace this with sed code, as IRIX sed won't handle
+    # lines with more than a fixed number of characters (4096 in
+    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
+    # the IRIX cc adds comments like `#:fec' to the end of the
+    # dependency line.
+    tr ' ' '
+' < "$tmpdepfile" \
+    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
+    tr '
+' ' ' >> "$depfile"
+    echo >> "$depfile"
+
+    # The second pass generates a dummy entry for each header file.
+    tr ' ' '
+' < "$tmpdepfile" \
+   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
+   >> "$depfile"
+  else
+    # The sourcefile does not contain any dependencies, so just
+    # store a dummy comment line, to avoid errors with the Makefile
+    # "include basename.Plo" scheme.
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+aix)
+  # The C for AIX Compiler uses -M and outputs the dependencies
+  # in a .u file.  In older versions, this file always lives in the
+  # current directory.  Also, the AIX compiler puts `$object:' at the
+  # start of each line; $object doesn't have directory information.
+  # Version 6 uses the directory in both cases.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$base.u
+    tmpdepfile3=$dir.libs/$base.u
+    "$@" -Wc,-M
+  else
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$dir$base.u
+    tmpdepfile3=$dir$base.u
+    "$@" -M
+  fi
+  stat=$?
+
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    # Each line is of the form `foo.o: dependent.h'.
+    # Do two passes, one to just change these to
+    # `$object: dependent.h' and one to simply `dependent.h:'.
+    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
+    # That's a tab and a space in the [].
+    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+  else
+    # The sourcefile does not contain any dependencies, so just
+    # store a dummy comment line, to avoid errors with the Makefile
+    # "include basename.Plo" scheme.
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+icc)
+  # Intel's C compiler understands `-MD -MF file'.  However on
+  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
+  # ICC 7.0 will fill foo.d with something like
+  #    foo.o: sub/foo.c
+  #    foo.o: sub/foo.h
+  # which is wrong.  We want:
+  #    sub/foo.o: sub/foo.c
+  #    sub/foo.o: sub/foo.h
+  #    sub/foo.c:
+  #    sub/foo.h:
+  # ICC 7.1 will output
+  #    foo.o: sub/foo.c sub/foo.h
+  # and will wrap long lines using \ :
+  #    foo.o: sub/foo.c ... \
+  #     sub/foo.h ... \
+  #     ...
+
+  "$@" -MD -MF "$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each line is of the form `foo.o: dependent.h',
+  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
+  # Do two passes, one to just change these to
+  # `$object: dependent.h' and one to simply `dependent.h:'.
+  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
+    sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp2)
+  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
+  # compilers, which have integrated preprocessors.  The correct option
+  # to use with these is +Maked; it writes dependencies to a file named
+  # 'foo.d', which lands next to the object file, wherever that
+  # happens to be.
+  # Much of this is similar to the tru64 case; see comments there.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir.libs/$base.d
+    "$@" -Wc,+Maked
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    "$@" +Maked
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+     rm -f "$tmpdepfile1" "$tmpdepfile2"
+     exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
+    # Add `dependent.h:' lines.
+    sed -ne '2,${
+	       s/^ *//
+	       s/ \\*$//
+	       s/$/:/
+	       p
+	     }' "$tmpdepfile" >> "$depfile"
+  else
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile" "$tmpdepfile2"
+  ;;
+
+tru64)
+   # The Tru64 compiler uses -MD to generate dependencies as a side
+   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
+   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
+   # dependencies in `foo.d' instead, so we check for that too.
+   # Subdirectories are respected.
+   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+   test "x$dir" = "x$object" && dir=
+   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+
+   if test "$libtool" = yes; then
+      # With Tru64 cc, shared objects can also be used to make a
+      # static library.  This mechanism is used in libtool 1.4 series to
+      # handle both shared and static libraries in a single compilation.
+      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
+      #
+      # With libtool 1.5 this exception was removed, and libtool now
+      # generates 2 separate objects for the 2 libraries.  These two
+      # compilations output dependencies in $dir.libs/$base.o.d and
+      # in $dir$base.o.d.  We have to check for both files, because
+      # one of the two compilations can be disabled.  We should prefer
+      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+      # automatically cleaned when .libs/ is deleted, while ignoring
+      # the former would cause a distcleancheck panic.
+      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
+      tmpdepfile2=$dir$base.o.d          # libtool 1.5
+      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
+      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
+      "$@" -Wc,-MD
+   else
+      tmpdepfile1=$dir$base.o.d
+      tmpdepfile2=$dir$base.d
+      tmpdepfile3=$dir$base.d
+      tmpdepfile4=$dir$base.d
+      "$@" -MD
+   fi
+
+   stat=$?
+   if test $stat -eq 0; then :
+   else
+      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+      exit $stat
+   fi
+
+   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+   do
+     test -f "$tmpdepfile" && break
+   done
+   if test -f "$tmpdepfile"; then
+      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
+      # That's a tab and a space in the [].
+      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+   else
+      echo "#dummy" > "$depfile"
+   fi
+   rm -f "$tmpdepfile"
+   ;;
+
+#nosideeffect)
+  # This comment above is used by automake to tell side-effect
+  # dependency tracking mechanisms from slower ones.
+
+dashmstdout)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout, regardless of -o.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  test -z "$dashmflag" && dashmflag=-M
+  # Require at least two characters before searching for `:'
+  # in the target name.  This is to cope with DOS-style filenames:
+  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
+  "$@" $dashmflag |
+    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  tr ' ' '
+' < "$tmpdepfile" | \
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+dashXmstdout)
+  # This case only exists to satisfy depend.m4.  It is never actually
+  # run, as this mode is specially recognized in the preamble.
+  exit 1
+  ;;
+
+makedepend)
+  "$@" || exit $?
+  # Remove any Libtool call
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+  # X makedepend
+  shift
+  cleared=no eat=no
+  for arg
+  do
+    case $cleared in
+    no)
+      set ""; shift
+      cleared=yes ;;
+    esac
+    if test $eat = yes; then
+      eat=no
+      continue
+    fi
+    case "$arg" in
+    -D*|-I*)
+      set fnord "$@" "$arg"; shift ;;
+    # Strip any option that makedepend may not understand.  Remove
+    # the object too, otherwise makedepend will parse it as a source file.
+    -arch)
+      eat=yes ;;
+    -*|$object)
+      ;;
+    *)
+      set fnord "$@" "$arg"; shift ;;
+    esac
+  done
+  obj_suffix=`echo "$object" | sed 's/^.*\././'`
+  touch "$tmpdepfile"
+  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  sed '1,2d' "$tmpdepfile" | tr ' ' '
+' | \
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile" "$tmpdepfile".bak
+  ;;
+
+cpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  "$@" -E |
+    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
+    sed '$ s: \\$::' > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  cat < "$tmpdepfile" >> "$depfile"
+  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvisualcpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  IFS=" "
+  for arg
+  do
+    case "$arg" in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
+	set fnord "$@"
+	shift
+	shift
+	;;
+    *)
+	set fnord "$@" "$arg"
+	shift
+	shift
+	;;
+    esac
+  done
+  "$@" -E 2>/dev/null |
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
+  echo "	" >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvcmsys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+none)
+  exec "$@"
+  ;;
+
+*)
+  echo "Unknown depmode $depmode" 1>&2
+  exit 1
+  ;;
+esac
+
+exit 0
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/install-sh b/install-sh
new file mode 100755
index 0000000..6781b98
--- /dev/null
+++ b/install-sh
@@ -0,0 +1,520 @@
+#!/bin/sh
+# install - install a program, script, or datafile
+
+scriptversion=2009-04-28.21; # UTC
+
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+
+nl='
+'
+IFS=" ""	$nl"
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit=${DOITPROG-}
+if test -z "$doit"; then
+  doit_exec=exec
+else
+  doit_exec=$doit
+fi
+
+# Put in absolute file names if you don't have them in your path;
+# or use environment vars.
+
+chgrpprog=${CHGRPPROG-chgrp}
+chmodprog=${CHMODPROG-chmod}
+chownprog=${CHOWNPROG-chown}
+cmpprog=${CMPPROG-cmp}
+cpprog=${CPPROG-cp}
+mkdirprog=${MKDIRPROG-mkdir}
+mvprog=${MVPROG-mv}
+rmprog=${RMPROG-rm}
+stripprog=${STRIPPROG-strip}
+
+posix_glob='?'
+initialize_posix_glob='
+  test "$posix_glob" != "?" || {
+    if (set -f) 2>/dev/null; then
+      posix_glob=
+    else
+      posix_glob=:
+    fi
+  }
+'
+
+posix_mkdir=
+
+# Desired mode of installed file.
+mode=0755
+
+chgrpcmd=
+chmodcmd=$chmodprog
+chowncmd=
+mvcmd=$mvprog
+rmcmd="$rmprog -f"
+stripcmd=
+
+src=
+dst=
+dir_arg=
+dst_arg=
+
+copy_on_change=false
+no_target_directory=
+
+usage="\
+Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
+
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
+
+Options:
+     --help     display this help and exit.
+     --version  display version info and exit.
+
+  -c            (ignored)
+  -C            install only if different (preserve the last data modification time)
+  -d            create directories instead of installing files.
+  -g GROUP      $chgrpprog installed files to GROUP.
+  -m MODE       $chmodprog installed files to MODE.
+  -o USER       $chownprog installed files to USER.
+  -s            $stripprog installed files.
+  -t DIRECTORY  install into DIRECTORY.
+  -T            report an error if DSTFILE is a directory.
+
+Environment variables override the default commands:
+  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
+  RMPROG STRIPPROG
+"
+
+while test $# -ne 0; do
+  case $1 in
+    -c) ;;
+
+    -C) copy_on_change=true;;
+
+    -d) dir_arg=true;;
+
+    -g) chgrpcmd="$chgrpprog $2"
+	shift;;
+
+    --help) echo "$usage"; exit $?;;
+
+    -m) mode=$2
+	case $mode in
+	  *' '* | *'	'* | *'
+'*	  | *'*'* | *'?'* | *'['*)
+	    echo "$0: invalid mode: $mode" >&2
+	    exit 1;;
+	esac
+	shift;;
+
+    -o) chowncmd="$chownprog $2"
+	shift;;
+
+    -s) stripcmd=$stripprog;;
+
+    -t) dst_arg=$2
+	shift;;
+
+    -T) no_target_directory=true;;
+
+    --version) echo "$0 $scriptversion"; exit $?;;
+
+    --)	shift
+	break;;
+
+    -*)	echo "$0: invalid option: $1" >&2
+	exit 1;;
+
+    *)  break;;
+  esac
+  shift
+done
+
+if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
+  # When -d is used, all remaining arguments are directories to create.
+  # When -t is used, the destination is already specified.
+  # Otherwise, the last argument is the destination.  Remove it from $@.
+  for arg
+  do
+    if test -n "$dst_arg"; then
+      # $@ is not empty: it contains at least $arg.
+      set fnord "$@" "$dst_arg"
+      shift # fnord
+    fi
+    shift # arg
+    dst_arg=$arg
+  done
+fi
+
+if test $# -eq 0; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
+  fi
+  # It's OK to call `install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
+
+if test -z "$dir_arg"; then
+  trap '(exit $?); exit' 1 2 13 15
+
+  # Set umask so as not to create temps with too-generous modes.
+  # However, 'strip' requires both read and write access to temps.
+  case $mode in
+    # Optimize common cases.
+    *644) cp_umask=133;;
+    *755) cp_umask=22;;
+
+    *[0-7])
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw='% 200'
+      fi
+      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
+    *)
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw=,u+rw
+      fi
+      cp_umask=$mode$u_plus_rw;;
+  esac
+fi
+
+for src
+do
+  # Protect names starting with `-'.
+  case $src in
+    -*) src=./$src;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
+  else
+
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
+    fi
+
+    if test -z "$dst_arg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
+
+    dst=$dst_arg
+    # Protect names starting with `-'.
+    case $dst in
+      -*) dst=./$dst;;
+    esac
+
+    # If destination is a directory, append the input filename; won't work
+    # if double slashes aren't ignored.
+    if test -d "$dst"; then
+      if test -n "$no_target_directory"; then
+	echo "$0: $dst_arg: Is a directory" >&2
+	exit 1
+      fi
+      dstdir=$dst
+      dst=$dstdir/`basename "$src"`
+      dstdir_status=0
+    else
+      # Prefer dirname, but fall back on a substitute if dirname fails.
+      dstdir=`
+	(dirname "$dst") 2>/dev/null ||
+	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	     X"$dst" : 'X\(//\)[^/]' \| \
+	     X"$dst" : 'X\(//\)$' \| \
+	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
+	echo X"$dst" |
+	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)[^/].*/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\).*/{
+		   s//\1/
+		   q
+		 }
+		 s/.*/./; q'
+      `
+
+      test -d "$dstdir"
+      dstdir_status=$?
+    fi
+  fi
+
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+	# Create intermediate dirs using mode 755 as modified by the umask.
+	# This is like FreeBSD 'install' as of 1997-10-28.
+	umask=`umask`
+	case $stripcmd.$umask in
+	  # Optimize common cases.
+	  *[2367][2367]) mkdir_umask=$umask;;
+	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
+
+	  *[0-7])
+	    mkdir_umask=`expr $umask + 22 \
+	      - $umask % 100 % 40 + $umask % 20 \
+	      - $umask % 10 % 4 + $umask % 2
+	    `;;
+	  *) mkdir_umask=$umask,go-w;;
+	esac
+
+	# With -d, create the new directory with the user-specified mode.
+	# Otherwise, rely on $mkdir_umask.
+	if test -n "$dir_arg"; then
+	  mkdir_mode=-m$mode
+	else
+	  mkdir_mode=
+	fi
+
+	posix_mkdir=false
+	case $umask in
+	  *[123567][0-7][0-7])
+	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
+	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
+	    ;;
+	  *)
+	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
+
+	    if (umask $mkdir_umask &&
+		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
+	    then
+	      if test -z "$dir_arg" || {
+		   # Check for POSIX incompatibilities with -m.
+		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+		   # other-writeable bit of parent directory when it shouldn't.
+		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
+		   case $ls_ld_tmpdir in
+		     d????-?r-*) different_mode=700;;
+		     d????-?--*) different_mode=755;;
+		     *) false;;
+		   esac &&
+		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
+		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
+		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+		   }
+		 }
+	      then posix_mkdir=:
+	      fi
+	      rmdir "$tmpdir/d" "$tmpdir"
+	    else
+	      # Remove any dirs left behind by ancient mkdir implementations.
+	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
+	    fi
+	    trap '' 0;;
+	esac;;
+    esac
+
+    if
+      $posix_mkdir && (
+	umask $mkdir_umask &&
+	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
+      )
+    then :
+    else
+
+      # The umask is ridiculous, or mkdir does not conform to POSIX,
+      # or it failed possibly due to a race condition.  Create the
+      # directory the slow way, step by step, checking for races as we go.
+
+      case $dstdir in
+	/*) prefix='/';;
+	-*) prefix='./';;
+	*)  prefix='';;
+      esac
+
+      eval "$initialize_posix_glob"
+
+      oIFS=$IFS
+      IFS=/
+      $posix_glob set -f
+      set fnord $dstdir
+      shift
+      $posix_glob set +f
+      IFS=$oIFS
+
+      prefixes=
+
+      for d
+      do
+	test -z "$d" && continue
+
+	prefix=$prefix$d
+	if test -d "$prefix"; then
+	  prefixes=
+	else
+	  if $posix_mkdir; then
+	    (umask=$mkdir_umask &&
+	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
+	    # Don't fail if two instances are running concurrently.
+	    test -d "$prefix" || exit 1
+	  else
+	    case $prefix in
+	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
+	      *) qprefix=$prefix;;
+	    esac
+	    prefixes="$prefixes '$qprefix'"
+	  fi
+	fi
+	prefix=$prefix/
+      done
+
+      if test -n "$prefixes"; then
+	# Don't fail if two instances are running concurrently.
+	(umask $mkdir_umask &&
+	 eval "\$doit_exec \$mkdirprog $prefixes") ||
+	  test -d "$dstdir" || exit 1
+	obsolete_mkdir_used=true
+      fi
+    fi
+  fi
+
+  if test -n "$dir_arg"; then
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
+  else
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=$dstdir/_inst.$$_
+    rmtmp=$dstdir/_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+
+    # Copy the file name to the temp name.
+    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
+    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
+    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
+
+    # If -C, don't bother to copy if it wouldn't change the file.
+    if $copy_on_change &&
+       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
+       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
+
+       eval "$initialize_posix_glob" &&
+       $posix_glob set -f &&
+       set X $old && old=:$2:$4:$5:$6 &&
+       set X $new && new=:$2:$4:$5:$6 &&
+       $posix_glob set +f &&
+
+       test "$old" = "$new" &&
+       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
+    then
+      rm -f "$dsttmp"
+    else
+      # Rename the file to the real destination.
+      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
+
+      # The rename failed, perhaps because mv can't rename something else
+      # to itself, or perhaps because mv is so ancient that it does not
+      # support -f.
+      {
+	# Now remove or move aside any old file at destination location.
+	# We try this two ways since rm can't unlink itself on some
+	# systems and the destination file might be busy for other
+	# reasons.  In this case, the final cleanup might fail but the new
+	# file should still install successfully.
+	{
+	  test ! -f "$dst" ||
+	  $doit $rmcmd -f "$dst" 2>/dev/null ||
+	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
+	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
+	  } ||
+	  { echo "$0: cannot unlink or rename $dst" >&2
+	    (exit 1); exit 1
+	  }
+	} &&
+
+	# Now rename the file to the real destination.
+	$doit $mvcmd "$dsttmp" "$dst"
+      }
+    fi || exit 1
+
+    trap '' 0
+  fi
+done
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/m4/ax_lib_gdal.m4 b/m4/ax_lib_gdal.m4
new file mode 100644
index 0000000..201c739
--- /dev/null
+++ b/m4/ax_lib_gdal.m4
@@ -0,0 +1,153 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_lib_gdal.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_LIB_GDAL([MINIMUM-VERSION])
+#
+# DESCRIPTION
+#
+# This macro provides tests of availability of GDAL/OGR library of
+# particular version or newer.
+#
+# AX_LIB_GDAL macro takes only one argument which is optional. If there is
+# no required version passed, then macro does not run version test.
+#
+# The --with-gdal option takes complete path to gdal-config utility,
+#
+# This macro calls AC_SUBST for:
+#
+# GDAL_VERSION
+# GDAL_CFLAGS
+# GDAL_LDFLAGS
+# GDAL_DEP_LDFLAGS
+# GDAL_OGR_ENABLED
+#
+# and AC_DEFINE for:
+#
+# HAVE_GDAL
+# HAVE_GDAL_OGR
+#
+# LICENSE
+#
+# Copyright (c) 2011 Mateusz Loskot <mateusz at loskot.net>
+# Copyright (c) 2011 Alessandro Candini <candini at meeo.it>
+#
+# 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.
+
+#serial 1
+
+AC_DEFUN([AX_LIB_GDAL],
+[
+    dnl If gdal-config path is not given in ---with-gdal option,
+    dnl check if it is present in the system anyway
+    AC_ARG_WITH([gdal],
+        AC_HELP_STRING([--with-gdal=@<:@ARG@:>@],
+            [Specify full path to gdal-config script]),
+        [ac_gdal_config_path=$withval],
+        [gdal_config_system=check])
+
+    dnl if gdal-config is present in the system, fill the ac_gdal_config_path variable with it full path
+    AS_IF([test "x$gdal_config_system" = xcheck],
+          [AC_PATH_PROG([GDAL_CONFIG], [gdal-config])],
+          [AC_PATH_PROG([GDAL_CONFIG], [gdal-config],
+              [no], [`dirname $ac_gdal_config_path 2> /dev/null`])]
+    )
+
+    if test ! -x "$GDAL_CONFIG"; then
+        AC_MSG_ERROR([gdal-config does not exist or it is not an exectuable file])
+            GDAL_CONFIG="no"
+            found_gdal="no"
+    fi
+
+    GDAL_VERSION=""
+    GDAL_CFLAGS=""
+    GDAL_LDFLAGS=""
+    GDAL_DEP_LDFLAGS=""
+    GDAL_OGR_ENABLED=""
+
+
+    dnl
+    dnl Check GDAL library (libgdal)
+    dnl
+
+    if test "$GDAL_CONFIG" != "no"; then
+        AC_MSG_CHECKING([for GDAL library])
+
+        GDAL_VERSION="`$GDAL_CONFIG --version`"
+        GDAL_CFLAGS="`$GDAL_CONFIG --cflags`"
+        GDAL_LDFLAGS="`$GDAL_CONFIG --libs`"
+        GDAL_DEP_LDFLAGS="`$GDAL_CONFIG --dep-libs`"
+
+        AC_DEFINE([HAVE_GDAL], [1], [Define to 1 if GDAL library are available])
+
+        found_gdal="yes"
+    else
+        found_gdal="no"
+    fi
+
+    AC_MSG_RESULT([$found_gdal])
+
+    if test "$found_gdal" = "yes"; then
+        AC_MSG_CHECKING([for OGR support in GDAL library])
+
+        GDAL_OGR_ENABLED="`$GDAL_CONFIG --ogr-enabled`"
+        AC_DEFINE([HAVE_GDAL_OGR], [1], [Define to 1 if GDAL library includes OGR support])
+
+        AC_MSG_RESULT([$GDAL_OGR_ENABLED])
+    fi
+
+    dnl
+    dnl Check if required version of GDAL is available
+    dnl
+
+    gdal_version_req=ifelse([$1], [], [], [$1])
+    if test "$found_gdal" = "yes" -a -n "$gdal_version_req"; then
+
+        AC_MSG_CHECKING([if GDAL version is >= $gdal_version_req])
+
+        dnl Decompose required version string of GDAL
+        dnl and calculate its number representation
+        gdal_version_req_major=`expr $gdal_version_req : '\([[0-9]]*\)'`
+        gdal_version_req_minor=`expr $gdal_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
+        gdal_version_req_micro=`expr $gdal_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+        if test "x$gdal_version_req_micro" = "x"; then
+            gdal_version_req_micro="0"
+        fi
+
+        gdal_version_req_number=`expr $gdal_version_req_major \* 1000000 \
+                                   \+ $gdal_version_req_minor \* 1000 \
+                                   \+ $gdal_version_req_micro`
+
+        dnl Decompose version string of installed GDAL
+        dnl and calculate its number representation
+        gdal_version_major=`expr $GDAL_VERSION : '\([[0-9]]*\)'`
+        gdal_version_minor=`expr $GDAL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
+        gdal_version_micro=`expr $GDAL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+        if test "x$gdal_version_micro" = "x"; then
+            gdal_version_micro="0"
+        fi
+
+        gdal_version_number=`expr $gdal_version_major \* 1000000 \
+                                   \+ $gdal_version_minor \* 1000 \
+                                   \+ $gdal_version_micro`
+
+        gdal_version_check=`expr $gdal_version_number \>\= $gdal_version_req_number`
+        if test "$gdal_version_check" = "1"; then
+            AC_MSG_RESULT([yes])
+        else
+            AC_MSG_RESULT([no])
+AC_MSG_ERROR([GDAL $GDAL_VERSION found, but required version is $gdal_version_req])
+        fi
+    fi
+
+    AC_SUBST(GDAL_VERSION)
+    AC_SUBST(GDAL_CFLAGS)
+    AC_SUBST(GDAL_LDFLAGS)
+    AC_SUBST(GDAL_DEP_LDFLAGS)
+    AC_SUBST(GDAL_OGR_ENABLED)
+])
diff --git a/missing b/missing
new file mode 100755
index 0000000..28055d2
--- /dev/null
+++ b/missing
@@ -0,0 +1,376 @@
+#! /bin/sh
+# Common stub for a few missing GNU programs while installing.
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
+# 2008, 2009 Free Software Foundation, Inc.
+# Originally by Fran,cois Pinard <pinard at iro.umontreal.ca>, 1996.
+
+# 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, 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 <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+if test $# -eq 0; then
+  echo 1>&2 "Try \`$0 --help' for more information"
+  exit 1
+fi
+
+run=:
+sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
+sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
+
+# In the cases where this matters, `missing' is being run in the
+# srcdir already.
+if test -f configure.ac; then
+  configure_ac=configure.ac
+else
+  configure_ac=configure.in
+fi
+
+msg="missing on your system"
+
+case $1 in
+--run)
+  # Try to run requested program, and just exit if it succeeds.
+  run=
+  shift
+  "$@" && exit 0
+  # Exit code 63 means version mismatch.  This often happens
+  # when the user try to use an ancient version of a tool on
+  # a file that requires a minimum version.  In this case we
+  # we should proceed has if the program had been absent, or
+  # if --run hadn't been passed.
+  if test $? = 63; then
+    run=:
+    msg="probably too old"
+  fi
+  ;;
+
+  -h|--h|--he|--hel|--help)
+    echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
+error status if there is no known handling for PROGRAM.
+
+Options:
+  -h, --help      display this help and exit
+  -v, --version   output version information and exit
+  --run           try to run the given command, and emulate it if it fails
+
+Supported PROGRAM values:
+  aclocal      touch file \`aclocal.m4'
+  autoconf     touch file \`configure'
+  autoheader   touch file \`config.h.in'
+  autom4te     touch the output file, or create a stub one
+  automake     touch all \`Makefile.in' files
+  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
+  flex         create \`lex.yy.c', if possible, from existing .c
+  help2man     touch the output file
+  lex          create \`lex.yy.c', if possible, from existing .c
+  makeinfo     touch the output file
+  tar          try tar, gnutar, gtar, then tar without non-portable flags
+  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
+
+Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
+\`g' are ignored when checking the name.
+
+Send bug reports to <bug-automake at gnu.org>."
+    exit $?
+    ;;
+
+  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+    echo "missing $scriptversion (GNU Automake)"
+    exit $?
+    ;;
+
+  -*)
+    echo 1>&2 "$0: Unknown \`$1' option"
+    echo 1>&2 "Try \`$0 --help' for more information"
+    exit 1
+    ;;
+
+esac
+
+# normalize program name to check for.
+program=`echo "$1" | sed '
+  s/^gnu-//; t
+  s/^gnu//; t
+  s/^g//; t'`
+
+# Now exit if we have it, but it failed.  Also exit now if we
+# don't have it and --version was passed (most likely to detect
+# the program).  This is about non-GNU programs, so use $1 not
+# $program.
+case $1 in
+  lex*|yacc*)
+    # Not GNU programs, they don't have --version.
+    ;;
+
+  tar*)
+    if test -n "$run"; then
+       echo 1>&2 "ERROR: \`tar' requires --run"
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       exit 1
+    fi
+    ;;
+
+  *)
+    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+       # We have it, but it failed.
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       # Could not run --version or --help.  This is probably someone
+       # running `$TOOL --version' or `$TOOL --help' to check whether
+       # $TOOL exists and not knowing $TOOL uses missing.
+       exit 1
+    fi
+    ;;
+esac
+
+# If it does not exist, or fails to run (possibly an outdated version),
+# try to emulate it.
+case $program in
+  aclocal*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
+         to install the \`Automake' and \`Perl' packages.  Grab them from
+         any GNU archive site."
+    touch aclocal.m4
+    ;;
+
+  autoconf*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`${configure_ac}'.  You might want to install the
+         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
+         archive site."
+    touch configure
+    ;;
+
+  autoheader*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
+         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
+         from any GNU archive site."
+    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
+    test -z "$files" && files="config.h"
+    touch_files=
+    for f in $files; do
+      case $f in
+      *:*) touch_files="$touch_files "`echo "$f" |
+				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
+      *) touch_files="$touch_files $f.in";;
+      esac
+    done
+    touch $touch_files
+    ;;
+
+  automake*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
+         You might want to install the \`Automake' and \`Perl' packages.
+         Grab them from any GNU archive site."
+    find . -type f -name Makefile.am -print |
+	   sed 's/\.am$/.in/' |
+	   while read f; do touch "$f"; done
+    ;;
+
+  autom4te*)
+    echo 1>&2 "\
+WARNING: \`$1' is needed, but is $msg.
+         You might have modified some files without having the
+         proper tools for further handling them.
+         You can get \`$1' as part of \`Autoconf' from any GNU
+         archive site."
+
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
+	touch $file
+    else
+	test -z "$file" || exec >$file
+	echo "#! /bin/sh"
+	echo "# Created by GNU Automake missing as a replacement of"
+	echo "#  $ $@"
+	echo "exit 0"
+	chmod +x $file
+	exit 1
+    fi
+    ;;
+
+  bison*|yacc*)
+    echo 1>&2 "\
+WARNING: \`$1' $msg.  You should only need it if
+         you modified a \`.y' file.  You may need the \`Bison' package
+         in order for those modifications to take effect.  You can get
+         \`Bison' from any GNU archive site."
+    rm -f y.tab.c y.tab.h
+    if test $# -ne 1; then
+        eval LASTARG="\${$#}"
+	case $LASTARG in
+	*.y)
+	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
+	    if test -f "$SRCFILE"; then
+	         cp "$SRCFILE" y.tab.c
+	    fi
+	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
+	    if test -f "$SRCFILE"; then
+	         cp "$SRCFILE" y.tab.h
+	    fi
+	  ;;
+	esac
+    fi
+    if test ! -f y.tab.h; then
+	echo >y.tab.h
+    fi
+    if test ! -f y.tab.c; then
+	echo 'main() { return 0; }' >y.tab.c
+    fi
+    ;;
+
+  lex*|flex*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified a \`.l' file.  You may need the \`Flex' package
+         in order for those modifications to take effect.  You can get
+         \`Flex' from any GNU archive site."
+    rm -f lex.yy.c
+    if test $# -ne 1; then
+        eval LASTARG="\${$#}"
+	case $LASTARG in
+	*.l)
+	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
+	    if test -f "$SRCFILE"; then
+	         cp "$SRCFILE" lex.yy.c
+	    fi
+	  ;;
+	esac
+    fi
+    if test ! -f lex.yy.c; then
+	echo 'main() { return 0; }' >lex.yy.c
+    fi
+    ;;
+
+  help2man*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+	 you modified a dependency of a manual page.  You may need the
+	 \`Help2man' package in order for those modifications to take
+	 effect.  You can get \`Help2man' from any GNU archive site."
+
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
+	touch $file
+    else
+	test -z "$file" || exec >$file
+	echo ".ab help2man is required to generate this page"
+	exit $?
+    fi
+    ;;
+
+  makeinfo*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified a \`.texi' or \`.texinfo' file, or any other file
+         indirectly affecting the aspect of the manual.  The spurious
+         call might also be the consequence of using a buggy \`make' (AIX,
+         DU, IRIX).  You might want to install the \`Texinfo' package or
+         the \`GNU make' package.  Grab either from any GNU archive site."
+    # The file to touch is that specified with -o ...
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -z "$file"; then
+      # ... or it is the one specified with @setfilename ...
+      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+      file=`sed -n '
+	/^@setfilename/{
+	  s/.* \([^ ]*\) *$/\1/
+	  p
+	  q
+	}' $infile`
+      # ... or it is derived from the source name (dir/f.texi becomes f.info)
+      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
+    fi
+    # If the file does not exist, the user really needs makeinfo;
+    # let's fail without touching anything.
+    test -f $file || exit 1
+    touch $file
+    ;;
+
+  tar*)
+    shift
+
+    # We have already tried tar in the generic part.
+    # Look for gnutar/gtar before invocation to avoid ugly error
+    # messages.
+    if (gnutar --version > /dev/null 2>&1); then
+       gnutar "$@" && exit 0
+    fi
+    if (gtar --version > /dev/null 2>&1); then
+       gtar "$@" && exit 0
+    fi
+    firstarg="$1"
+    if shift; then
+	case $firstarg in
+	*o*)
+	    firstarg=`echo "$firstarg" | sed s/o//`
+	    tar "$firstarg" "$@" && exit 0
+	    ;;
+	esac
+	case $firstarg in
+	*h*)
+	    firstarg=`echo "$firstarg" | sed s/h//`
+	    tar "$firstarg" "$@" && exit 0
+	    ;;
+	esac
+    fi
+
+    echo 1>&2 "\
+WARNING: I can't seem to be able to run \`tar' with the given arguments.
+         You may want to install GNU tar or Free paxutils, or check the
+         command line arguments."
+    exit 1
+    ;;
+
+  *)
+    echo 1>&2 "\
+WARNING: \`$1' is needed, and is $msg.
+         You might have modified some files without having the
+         proper tools for further handling them.  Check the \`README' file,
+         it often tells you about the needed prerequisites for installing
+         this package.  You may also peek at any GNU archive site, in case
+         some other package would contain this missing \`$1' program."
+    exit 1
+    ;;
+esac
+
+exit 0
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/src/algorithms/ConfusionMatrix.cc b/src/algorithms/ConfusionMatrix.cc
new file mode 100644
index 0000000..dd1fe49
--- /dev/null
+++ b/src/algorithms/ConfusionMatrix.cc
@@ -0,0 +1,258 @@
+/**********************************************************************
+ConfusionMatrix.cc: class for (classification accuracy) confusion matrix
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "ConfusionMatrix.h"
+#include <iostream>
+#include <numeric>
+
+
+ConfusionMatrix::ConfusionMatrix()
+  : m_classes(),m_results()
+{
+}
+
+ConfusionMatrix::~ConfusionMatrix()
+{
+}
+
+//constructor where class names are 0,1,...,nclass-1
+ConfusionMatrix::ConfusionMatrix(short nclass){
+  resize(nclass);
+}
+
+ConfusionMatrix::ConfusionMatrix(const vector<string>& classNames){
+  setClassNames(classNames);
+}
+
+//copy constructor
+ConfusionMatrix::ConfusionMatrix(const ConfusionMatrix& cm){
+  setClassNames(cm.m_classes);
+  setResults(cm.m_results);
+}
+
+//assignment operator
+ConfusionMatrix& ConfusionMatrix::operator=(const ConfusionMatrix& cm){
+  //check for self-assignment by comparing the address of the implicit object and parameter
+  if(this==&cm)
+    return *this;
+  else{
+    setClassNames(cm.m_classes);
+    setResults(cm.m_results);
+  }
+  return *this;
+}
+
+ConfusionMatrix& ConfusionMatrix::operator+=(const ConfusionMatrix &cm)
+{
+  if(cm.m_classes.size()!=this->m_classes.size()){
+    cerr << "error0: "<< cm.m_classes.size() << "!=" << this->m_classes.size() << endl;
+    exit(0);
+  }
+  if(cm.m_results.size()!=this->m_results.size()){
+    cerr << "error1: "<< cm.m_results.size() << "!=" << this->m_results.size() << endl;
+    exit(1);
+  }
+  for(int irow=0;irow<m_results.size();++irow){
+    if(cm.m_results[irow].size()!=this->m_results[irow].size()){
+      cerr << "error2: " << cm.m_results[irow].size() << "!=" << this->m_results[irow].size() << endl;
+      exit(2);
+    }
+    for(int icol=0;icol<m_results[irow].size();++icol)
+      this->m_results[irow][icol]+=cm.m_results[irow][icol];
+  }
+  return *this;
+}
+
+ConfusionMatrix& ConfusionMatrix::operator*=(double weight)
+{
+  for(int irow=0;irow<m_results.size();++irow){
+    for(int icol=0;icol<m_results[irow].size();++icol)
+      m_results[irow][icol]*=weight;
+  }
+  return *this;
+}
+
+ConfusionMatrix ConfusionMatrix::operator*(double weight)
+{
+  ConfusionMatrix result = *this;//make a copy of myself
+  result*=weight;
+  return result;
+}
+
+void ConfusionMatrix::resize(short nclass){
+  for(short iclass=0;iclass<nclass;++iclass){
+    ostringstream osclass;
+    osclass << iclass;
+    m_classes[iclass]=osclass.str();
+  }
+  m_results.resize(nclass,nclass);
+}
+
+void ConfusionMatrix::setClassNames(const vector<string>& classNames){
+  m_classes=classNames;
+  if(m_results.size()!=m_classes.size())
+    m_results.resize(m_classes.size(),m_classes.size());
+}
+
+void ConfusionMatrix::pushBackClassName(const string& className){
+  m_classes.push_back(className);
+  if(m_results.size()!=m_classes.size())
+    m_results.resize(m_classes.size(),m_classes.size());
+}  
+
+
+void ConfusionMatrix::setResults(const Vector2d<double>& theResults){
+  m_results=theResults;
+}
+
+void ConfusionMatrix::clearResults(){
+  m_results.clear();
+}
+
+void ConfusionMatrix::setResult(const string& theRef, const string& theClass, double theResult){
+  int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theRef));
+  int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass));
+  assert(ir>=0);
+  assert(ir<m_results.size());
+  assert(ic>=0);
+  assert(ic<m_results[ir].size());
+  m_results[ir][ic]=theResult;
+}
+
+void ConfusionMatrix::incrementResult(const string& theRef, const string& theClass, double theIncrement){
+  int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theRef));
+  int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass));
+  assert(ir>=0);
+  if(ir>=m_results.size())
+    cerr << "Error: " << theRef << " not found in class ConfusionMatrix when incrementing for class " << theClass << endl;
+  assert(ir<m_results.size());
+  assert(ic>=0);
+  assert(ic<m_results[ir].size());
+  m_results[ir][ic]+=theIncrement;
+}
+
+double ConfusionMatrix::nReference(const string& theRef) const{
+  int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theRef));
+  return accumulate(m_results[ir].begin(),m_results[ir].end(),0);
+}
+
+double ConfusionMatrix::nReference() const{
+  double nref=0;
+  for(int ir=0;ir<m_classes.size();++ir)
+    nref+=accumulate(m_results[ir].begin(),m_results[ir].end(),0);
+  return nref;
+}
+
+double ConfusionMatrix::nClassified(const string& theClass) const{
+  int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass));
+  double nclassified=0;
+  for(int iref=0;iref<m_results.size();++iref){
+    assert(ic<m_results[iref].size());
+    nclassified+=m_results[iref][ic];
+  }
+  return(nclassified);
+}
+
+double ConfusionMatrix::pa(const string& theClass, double* se95) const{
+  assert(m_results.size());
+  assert(m_results.size()==m_classes.size());
+  double producer=0;
+  int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass));
+  assert(ir>=0);
+  assert(ir<m_results.size());
+  assert(!theClass.compare(m_classes[ir]));
+  for(int iclass=0;iclass<m_results.size();++iclass){
+    assert(iclass<m_results[ir].size());
+    producer+=m_results[ir][iclass];
+  }
+  double dpa=(producer>0)? static_cast<double>(m_results[ir][ir])/producer : 0;
+  double dqa=1.0-dpa;
+  if(se95!=NULL)
+    *se95=(dpa<1&&dpa>0)? sqrt(dpa*dqa/(producer-1)) : 0;
+  return dpa;
+}
+
+int ConfusionMatrix::pa_pct(const string& theClass, double* se95) const{
+  double dpa=pa(theClass,se95);
+  if(se95!=NULL)
+    *se95=static_cast<double>(static_cast<int>(0.5+1000*(*se95)))/10.0;
+  return static_cast<int>(0.5+100.0*dpa);
+}
+    
+
+double ConfusionMatrix::ua(const string& theClass, double* se95) const{
+  assert(m_results.size());
+  assert(m_results.size()==m_classes.size());
+  double user=0;
+  int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass));
+  assert(ic>=0);
+  assert(!theClass.compare(m_classes[ic]));
+  for(int iref=0;iref<m_results.size();++iref){
+    assert(ic<m_results[iref].size());
+    user+=m_results[iref][ic];
+  }
+  double dua=(user>0)? static_cast<double>(m_results[ic][ic])/user : 0;
+  double dva=1.0-dva;
+  if(se95!=NULL)
+    *se95=(dua<1&&dua>0)? sqrt(dua*dva/(user-1)) : 0;
+  return dua;
+}
+
+int ConfusionMatrix::ua_pct(const string& theClass,double* se95) const{
+  double dua=ua(theClass,se95);
+  if(se95!=NULL)
+    *se95=static_cast<double>(static_cast<int>(0.5+1000*(*se95)))/10.0;
+  return static_cast<int>(0.5+100.0*dua);
+}
+
+double ConfusionMatrix::oa(double* se95) const{
+  double ntotal=m_results.sum();
+  double pChance=0;
+  double pCorrect=0;
+  for(int iclass=0;iclass<m_classes.size();++iclass)
+    pCorrect+=static_cast<double>(m_results[iclass][iclass])/ntotal;
+  double qCorrect=1-pCorrect;
+  if(se95!=NULL)
+    *se95=(pCorrect<1&&pCorrect>0)? sqrt(pCorrect*qCorrect/(ntotal-1)) : 0;
+  if(ntotal>0)
+    return(pCorrect);
+  else
+    return(0);
+}
+
+int ConfusionMatrix::oa_pct(double* se95) const{
+  double doa=oa(se95);
+  if(se95!=NULL)
+    *se95=static_cast<double>(static_cast<int>(0.5+1000*(*se95)))/10.0;
+  return static_cast<int>(0.5+100.0*doa);
+}
+
+double ConfusionMatrix::kappa() const{
+  double ntotal=m_results.sum();
+  double pChance=0;
+  double pCorrect=0;
+  for(int iclass=0;iclass<m_classes.size();++iclass){
+    pChance+=nClassified(m_classes[iclass])*nReference(m_classes[iclass])/ntotal/ntotal;
+    pCorrect+=static_cast<double>(m_results[iclass][iclass])/ntotal;
+  }
+  if(pChance<1)
+    return((pCorrect-pChance)/(1-pChance));
+  else
+    return(0);
+}
diff --git a/src/algorithms/ConfusionMatrix.h b/src/algorithms/ConfusionMatrix.h
new file mode 100644
index 0000000..33cf04f
--- /dev/null
+++ b/src/algorithms/ConfusionMatrix.h
@@ -0,0 +1,81 @@
+/**********************************************************************
+ConfusionMatrix.h: class for (classification accuracy) confusion matrix
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _CONFUSIONMATRIX_H_
+#define _CONFUSIONMATRIX_H_
+
+#include <sstream>
+#include <vector>
+#include "base/Vector2d.h"
+
+using namespace std;
+
+class ConfusionMatrix{
+public:
+  ConfusionMatrix();
+  ConfusionMatrix(short nclass);
+  ConfusionMatrix(const vector<string>& classNames);
+  ConfusionMatrix(const ConfusionMatrix& cm);
+  ConfusionMatrix& operator=(const ConfusionMatrix& cm);
+  void resize(short nclass);
+  void setClassNames(const vector<string>& classNames);
+  void pushBackClassName(const string& className);
+  void setResults(const Vector2d<double>& theResults);
+  void setResult(const string& theRef, const string& theClass, double theResult);
+  void incrementResult(const string& theRef, const string& theClass, double theIncrement);
+  void clearResults();
+  double nReference(const string& theRef) const;
+  double nReference() const;
+  double nClassified(const string& theRef) const;
+  int nClasses() const {return m_classes.size();};
+  string getClass(int iclass) const {assert(iclass>=0);assert(iclass<m_classes.size());return m_classes[iclass];};
+  vector<string> getClassNames() const {return m_classes;};
+  ~ConfusionMatrix();
+  double pa(const string& theClass, double* se95=NULL) const;
+  double ua(const string& theClass, double* se95=NULL) const;
+  double oa(double* se95=NULL) const;
+  int pa_pct(const string& theClass, double* se95=NULL) const;
+  int ua_pct(const string& theClass, double* se95=NULL) const;
+  int oa_pct(double* se95=NULL) const;
+  double kappa() const;
+  ConfusionMatrix& operator*=(double weight);
+  ConfusionMatrix operator*(double weight);
+  ConfusionMatrix& operator+=(const ConfusionMatrix &cm);
+  ConfusionMatrix operator+(const ConfusionMatrix &cm){
+    return ConfusionMatrix(*this)+=cm;
+  }
+  friend ostream& operator<<(ostream& os, const ConfusionMatrix &cm){
+    for(int iclass=0;iclass<cm.nClasses();++iclass)
+      os << "\t" << cm.m_classes[iclass];
+    os << endl;
+    assert(cm.m_classes.size()==cm.m_results.size());
+    for(int irow=0;irow<cm.m_results.size();++irow){
+      os << cm.m_classes[irow];
+      for(int icol=0;icol<cm.m_results[irow].size();++icol)
+        os << "\t" << cm.m_results[irow][icol];
+      os << endl;
+    }
+    return os;
+  };
+private:
+  vector<string> m_classes;
+  Vector2d<double> m_results;
+};
+
+#endif /* _CONFUSIONMATRIX_H_ */
diff --git a/src/algorithms/Egcs.cc b/src/algorithms/Egcs.cc
new file mode 100644
index 0000000..dc286b3
--- /dev/null
+++ b/src/algorithms/Egcs.cc
@@ -0,0 +1,208 @@
+/**********************************************************************
+Egcs.cc: Conversions from and to european grid coding system
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "Egcs.h"
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+#include <assert.h>
+
+Egcs::Egcs(){
+}
+
+// Egcs::Egcs(unsigned short level)
+//   : m_level(level){
+// }
+
+
+Egcs::Egcs(unsigned short level)
+{
+  m_level=level;
+}
+
+unsigned short Egcs::cell2level(const string& cellCode) const{
+  size_t pos=cellCode.find("-");
+  string TILE=cellCode.substr(0,pos);
+  unsigned short level=0;
+  int base_level=19-(TILE.size()/2-1)*3;
+  int quad_level=0;
+  if(pos!=string::npos)
+    quad_level=cellCode.size()-pos-1;
+  if(quad_level>1)
+    level=base_level-2;
+  else if(quad_level>0)
+    level=base_level-1;
+  else
+    level=base_level;
+  return level;
+}
+
+Egcs::~Egcs(){
+}
+
+unsigned short Egcs::res2level(double resolution) const{
+  double base=pow(10,log(resolution*4)/log(10));
+  double diff=base/(2*resolution);
+  return 0.5+(log(base)/log(10)*3+1-diff);
+}
+
+double Egcs::getResolution() const{
+  unsigned short exponent=(m_level+1)/3;
+  double base=pow(10,exponent);
+  if((m_level)%3==2)
+    return(base/4);
+  else if((m_level)%3==0)
+    return(base/2);
+  else
+    return(base);
+}
+
+void Egcs::force2grid(double& ulx, double& uly, double& lrx, double &lry) const{
+  double dx=getResolution();
+  double dy=dx;
+  //ulx
+  ulx=floor(ulx);
+  ulx-=static_cast<int>(ulx)%(static_cast<int>(dx));
+  //uly
+  uly=ceil(uly);
+  if(static_cast<int>(uly)%static_cast<int>(dy))
+    uly+=dy;
+  uly-=static_cast<int>(uly)%(static_cast<int>(dy));
+  //lrx
+  lrx=ceil(lrx);
+  if(static_cast<int>(lrx)%static_cast<int>(dx))
+    lrx+=dx;
+  lrx-=static_cast<int>(lrx)%(static_cast<int>(dx));
+  //lry
+  lry=floor(lry);
+  lry-=static_cast<int>(lry)%(static_cast<int>(dy));
+}
+
+void Egcs::cell2bb(const string& cellCode, int &ulx, int &uly, int &lrx, int &lry) const{
+  size_t pos=cellCode.find("-");
+  string TILE=cellCode.substr(0,pos);
+  string TILEX=TILE.substr(0,TILE.size()/2);
+  string TILEY=TILE.substr(TILE.size()/2);
+  string QUAD;
+  char QUAD1,QUAD2;
+  istringstream stilex(TILEX);
+  istringstream stiley(TILEY);
+  int llx,lly;
+  stilex >> llx;
+  stiley >> lly;
+  llx*=getBaseSize();
+  lly*=getBaseSize();
+  switch((19-m_level)%3){
+  case(0)://there should be no QUAD
+    assert(pos==string::npos);
+    break;
+  case(2)://there is a QUAD2
+    assert(pos+1!=string::npos);
+    QUAD=cellCode.substr(pos+1);
+    QUAD2=QUAD.substr(1,1).c_str()[0];
+    switch(QUAD2){
+    case('A'):
+      break;
+    case('C'):
+      lly+=getBaseSize()/4;
+      break;
+    case('D'):
+      lly+=getBaseSize()/4;
+    case('B'):
+      llx+=getBaseSize()/4;
+    break;
+    }
+  case(1)://QUAD1: deliberate fall through from case(2)!
+    if(!QUAD.size()){
+      assert(pos+1!=string::npos);
+      QUAD=cellCode.substr(pos+1);
+    }
+    QUAD1=QUAD.substr(0,1).c_str()[0];
+    switch(QUAD1){
+    case('A'):
+      break;
+    case('C'):
+      lly+=getBaseSize()/2;
+      break;
+    case('D'):
+      lly+=getBaseSize()/2;
+    case('B'):
+      llx+=getBaseSize()/2;
+      break;
+    }
+    break;
+  }
+  ulx=llx;
+  uly=static_cast<int>(lly+getSize());
+  lrx=static_cast<int>(llx+getSize());
+  lry=lly;
+}
+
+void Egcs::cell2mid(const string& cellCode, double& midX, double& midY) const{
+  int ulx,uly,lrx,lry;
+  cell2bb(cellCode,ulx,uly,lrx,lry);
+  midX=(ulx+lrx)/2.0;
+  midY=(lry+uly)/2.0;
+}
+
+string Egcs::geo2cell(double geoX, double geoY) const{
+  int ndgts=7-(m_level+1)/3;
+  double xcel=static_cast<int>(geoX)/getBaseSize();
+  double ycel=static_cast<int>(geoY)/getBaseSize();
+  ostringstream osx;
+  ostringstream osy, osxy;
+  // osx << setprecision(ndgts) << xcel;
+  // osy << setprecision(ndgts) << ycel;
+  // osx << setprecision(0) << fixed << geoX;
+  // osy << setprecision(0) << fixed << geoY;
+  osx << fixed << geoX;
+  osy << fixed << geoY;
+  string quad1="";
+  string quad2="";
+  switch((19-m_level)%3){
+  case(2):
+    if(static_cast<int>(geoX)%(getBaseSize()/2)>=getBaseSize()/2.0){
+      if(static_cast<int>(geoY)%(getBaseSize()/2)>=getBaseSize()/2.0)
+        quad2="D";
+      else
+        quad2="B";
+    }
+    else if(static_cast<int>(geoY)%getBaseSize()>=getBaseSize()/4.0)
+      quad2="C";
+    else
+      quad2="A";
+  case(1)://deliberate fall through!
+    if(static_cast<int>(geoX)%getBaseSize()>=getBaseSize()/2.0){
+      if(static_cast<int>(geoY)%getBaseSize()>=getBaseSize()/2.0)
+        quad1="-D";
+      else
+        quad1="-B";
+    }
+    else if(static_cast<int>(geoY)%getBaseSize()>=getBaseSize()/2.0)
+      quad1="-C";
+    else
+      quad1="-A";
+    break;
+  default:
+    break;
+  }
+  osxy << osx.str().substr(0,ndgts) << osy.str().substr(0,ndgts) << quad1 << quad2;
+  return osxy.str();
+}
+
diff --git a/src/algorithms/Egcs.h b/src/algorithms/Egcs.h
new file mode 100644
index 0000000..d97c63b
--- /dev/null
+++ b/src/algorithms/Egcs.h
@@ -0,0 +1,57 @@
+/**********************************************************************
+Egcs.h: Conversions from and to european grid coding system
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <math.h>
+#include <string>
+
+#ifndef _EGCS_H_
+#define _EGCS_H_
+
+using namespace std;
+
+class Egcs
+{
+public:
+  Egcs();
+  Egcs(unsigned short level);
+  /* Egcs(unsigned short level); */
+  ~Egcs();
+  unsigned short cell2level(const string& cellCode) const;
+  string geo2cell(double x, double y) const;
+  double getSize() const {return getBaseSize()*pow(2,(m_level-19)%3);};
+  void setLevel(unsigned short level){m_level=level;};
+  unsigned short getLevel() const{return m_level;};
+  unsigned short res2level(double resolution) const;
+  double getResolution() const;
+  void force2grid(double& ulx, double& uly, double& lrx, double &lry) const;
+  void cell2bb(const string& cellCode, int &ulx, int &uly, int &lrx, int &lry) const;
+  void cell2mid(const string& cellCode, double& midX, double& midY) const;
+private:
+  int getBaseSize() const {return pow(10,(m_level+1)/3);};
+  unsigned short m_level;
+// level square scheme         example
+// 19    1000km xy             32
+// 18     500km xy-q           32-A
+// 17     250km xy-qq          32-AB
+// 16     100km xxyy           3320
+// 5       25m  xxxxxyyyyy-qq  3346720658-DC
+// 1        1m  xxxxxxxyyyyyyy 33467652065889
+};
+#endif // _EGCS_H_
+
diff --git a/src/algorithms/Filter.cc b/src/algorithms/Filter.cc
new file mode 100644
index 0000000..46b8814
--- /dev/null
+++ b/src/algorithms/Filter.cc
@@ -0,0 +1,80 @@
+/**********************************************************************
+Filter.cc: class for filtering
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "Filter.h"
+#include <assert.h>
+#include <iostream>
+
+Filter::Filter(void)
+{
+}
+
+
+Filter::Filter(const vector<double> &taps)
+  : m_taps(taps)
+{
+  assert(m_taps.size()%2);
+}
+
+void Filter::setTaps(const vector<double> &taps)
+{
+  m_taps=taps;
+  assert(m_taps.size()%2);
+}
+
+void Filter::morphology(const ImgReaderGdal& input, ImgWriterGdal& output, int method, int dim, short down, int offset)
+{
+  Vector2d<double> lineInput(input.nrOfBand(),input.nrOfCol());
+  Vector2d<double> lineOutput(input.nrOfBand(),input.nrOfCol());
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  for(int y=0;y<input.nrOfRow();++y){
+    for(int iband=0;iband<input.nrOfBand();++iband)
+      input.readData(lineInput[iband],GDT_Float64,y,iband);
+    vector<double> pixelInput(input.nrOfBand());
+    vector<double> pixelOutput(input.nrOfBand());
+    for(int x=0;x<input.nrOfCol();++x){
+      pixelInput=lineInput.selectCol(x);
+      //test
+      if(y==168&&x==204){
+        cout << "m_class.size(): " << m_class.size() << endl;
+        cout << "y=" << y << ", x= " << x << endl;
+        morphology(pixelInput,pixelOutput,method,dim,down,offset,true);
+      }
+      else
+        morphology(pixelInput,pixelOutput,method,dim,down,offset);
+      for(int iband=0;iband<input.nrOfBand();++iband)
+        lineOutput[iband][x]=pixelOutput[iband];
+    }
+    for(int iband=0;iband<input.nrOfBand();++iband){
+      try{
+        output.writeData(lineOutput[iband],GDT_Float64,y,iband);
+      }
+      catch(string errorstring){
+        cerr << errorstring << "in band " << iband << ", line " << y << endl;
+      }
+    }
+    progress=(1.0+y)/output.nrOfRow();
+    pfnProgress(progress,pszMessage,pProgressArg);
+  }
+}
+
diff --git a/src/algorithms/Filter.h b/src/algorithms/Filter.h
new file mode 100644
index 0000000..15c5ffa
--- /dev/null
+++ b/src/algorithms/Filter.h
@@ -0,0 +1,278 @@
+/**********************************************************************
+Filter.h: class for filtering
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _MYFILTER_H_
+#define _MYFILTER_H_
+
+#include <vector>
+#include <iostream>
+#include "Histogram.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+
+using namespace std;
+namespace filter
+{
+  
+class Filter
+{
+public:
+  enum Type { MEDIAN=0, VAR=1 , MIN=2, MAX=3, SUM=4, MEAN=5, MINMAX=6, DILATE=7, ERODE=8, CLOSE=9, OPEN=10, HOMOG=11, SOBELX=12, SOBELY=13, SOBELXY=14, SMOOTH=15, DENSITY=16, MAJORITY=17, MIXED=18};
+  Filter(void);
+  Filter(const vector<double> &taps);
+  virtual ~Filter(){};
+  void setTaps(const vector<double> &taps);
+  void pushClass(short theClass=1){m_class.push_back(theClass);};
+  void pushMask(short theMask=0){m_mask.push_back(theMask);};
+  template<class T> void doit(const vector<T>& input, vector<T>& output, int down=1, int offset=0);
+  template<class T> void doit(T* input, int inputSize, vector<T>& output, int down=1, int offset=0);
+  template<class T> void morphology(const vector<T>& input, vector<T>& output, int method, int dim, short down=1, int offset=0, bool verbose=0);
+  void morphology(const ImgReaderGdal& input, ImgWriterGdal& output, int method, int dim, short down=1, int offset=0);
+
+private:
+  vector<double> m_taps;
+  vector<short> m_class;
+  vector<short> m_mask;
+};
+
+template<class T> void Filter::doit(const vector<T>& input, vector<T>& output, int down, int offset)
+{
+  output.resize((input.size()-offset+down-1)/down);
+  int i=0;
+  //start: extend input with mirrored version of itself
+  for(i=offset;i<m_taps.size()/2;++i){
+    if((i-offset)%down)
+      continue;
+    output[(i-offset+down-1)/down]=m_taps[m_taps.size()/2]*input[i];
+    for(int t=1;t<=m_taps.size()/2;++t)
+      output[(i-offset+down-1)/down]+=(m_taps[m_taps.size()/2+t]+m_taps[m_taps.size()/2-t])*input[i+t];
+  }
+  //main
+  for(i=offset+m_taps.size()/2;i<input.size()-m_taps.size()/2;++i){
+    if((i-offset)%down)
+      continue;
+    T leaveOut=(*(m_taps.begin()))*input[i-m_taps.size()/2];
+    T include=(m_taps.back())*input[i+m_taps.size()/2];
+    output[(i-offset+down-1)/down]=0;
+    for(int t=0;t<m_taps.size();++t)
+      output[(i-offset+down-1)/down]+=input[i-m_taps.size()/2+t]*m_taps[t];
+  }
+  //end: extend input with mirrored version of itself
+  for(i=input.size()-m_taps.size()/2;i<input.size();++i){
+    if((i-offset)%down)
+      continue;
+    output[(i-offset+down-1)/down]=m_taps[m_taps.size()/2]*input[i];
+    for(int t=1;t<=m_taps.size()/2;++t)
+      output[(i-offset+down-1)/down]+=(m_taps[m_taps.size()/2+t]+m_taps[m_taps.size()/2-t])*input[i-t];
+  }
+}
+
+template<class T> void Filter::morphology(const vector<T>& input, vector<T>& output, int method, int dim, short down, int offset, bool verbose)
+{
+  assert(dim);
+  output.resize((input.size()-offset+down-1)/down);
+  int i=0;
+  Histogram hist;
+  vector<T> histBuffer;
+  short binValue=0;
+  //start: extend input with mirrored version of itself
+  for(i=offset;i<dim/2;++i){
+    binValue=0;
+    for(int iclass=0;iclass<m_class.size();++iclass){
+      if(input[i]==m_class[iclass]){
+        binValue=m_class[0];
+        break;
+      }
+    }
+    if(m_class.size())
+      histBuffer.push_back(binValue);
+    else
+      histBuffer.push_back(input[i]);
+    for(int t=1;t<=dim/2;++t){
+      binValue=0;
+      for(int iclass=0;iclass<m_class.size();++iclass){
+        if(input[i+t]==m_class[iclass]){
+          binValue=m_class[0];
+          break;
+        }
+      }
+      if(m_class.size()){
+        histBuffer.push_back(binValue);
+        histBuffer.push_back(binValue);
+      }
+      else{
+        histBuffer.push_back(input[i+t]);
+        histBuffer.push_back(input[i+t]);
+      }
+    }
+    assert(histBuffer.size()==dim);
+    if((i-offset)%down){
+      histBuffer.clear();
+      continue;
+    }
+    switch(method){
+    case(DILATE):
+      output[(i-offset+down-1)/down]=hist.max(histBuffer);
+      break;
+    case(ERODE):
+      output[(i-offset+down-1)/down]=hist.min(histBuffer);
+      break;
+    default:
+      string errorString="method not supported";
+      throw(errorString);
+      break;
+    }
+    if(verbose){
+      cout << "buffer: ";
+      for(int ibuf=0;ibuf<histBuffer.size();++ibuf)
+        cout << histBuffer[ibuf] << " ";
+      cout << "->" << output[(i-offset+down-1)/down] << endl;
+    }
+  }
+  //main
+  histBuffer.clear();
+  for(i=offset+dim/2;i<input.size()-dim/2;++i){
+    binValue=0;
+    for(int t=0;t<dim;++t){
+      for(int iclass=0;iclass<m_class.size();++iclass){
+        if(input[i-dim/2+t]==m_class[iclass]){
+          binValue=m_class[0];
+          break;
+        }
+      }
+      if(m_class.size())
+        histBuffer.push_back(binValue);
+      else
+        histBuffer.push_back(input[i-dim/2+t]);
+    }
+    assert(histBuffer.size()==dim);
+    if((i-offset)%down){
+      histBuffer.clear();
+      continue;
+    }
+    switch(method){
+    case(DILATE):
+      output[(i-offset+down-1)/down]=hist.max(histBuffer);
+      break;
+    case(ERODE):
+      output[(i-offset+down-1)/down]=hist.min(histBuffer);
+      break;
+    default:
+      string errorString="method not supported";
+      throw(errorString);
+      break;
+    }
+    if(verbose){
+      cout << "buffer: ";
+      for(int ibuf=0;ibuf<histBuffer.size();++ibuf)
+        cout << histBuffer[ibuf] << " ";
+      cout << "->" << output[(i-offset+down-1)/down] << endl;
+    }
+    histBuffer.clear();
+  }
+  //end: extend input with mirrored version of itself
+  for(i=input.size()-dim/2;i<input.size();++i){
+      binValue=0;
+      for(int iclass=0;iclass<m_class.size();++iclass){
+        if(input[i]==m_class[iclass]){
+          binValue=m_class[0];
+          break;
+        }
+      }
+      if(m_class.size())
+        histBuffer.push_back(binValue);
+      else
+        histBuffer.push_back(input[i]);
+      for(int t=1;t<=dim/2;++t){
+        binValue=0;
+        for(int iclass=0;iclass<m_class.size();++iclass){
+          if(input[i-t]==m_class[iclass]){
+            binValue=m_class[0];
+            break;
+          }
+        }
+        if(m_class.size()){
+          histBuffer.push_back(binValue);
+          histBuffer.push_back(binValue);
+        }
+        else{
+          histBuffer.push_back(input[i-t]);
+          histBuffer.push_back(input[i-t]);
+        }
+      }
+    if((i-offset)%down){
+      histBuffer.clear();
+      continue;
+    }
+    switch(method){
+    case(DILATE):
+      output[(i-offset+down-1)/down]=hist.max(histBuffer);
+      break;
+    case(ERODE):
+      output[(i-offset+down-1)/down]=hist.min(histBuffer);
+      break;
+    default:
+      string errorString="method not supported";
+      throw(errorString);
+      break;
+    }
+    if(verbose){
+      cout << "buffer: ";
+      for(int ibuf=0;ibuf<histBuffer.size();++ibuf)
+        cout << histBuffer[ibuf] << " ";
+      cout << "->" << output[(i-offset+down-1)/down] << endl;
+    }
+  }
+}
+
+template<class T> void Filter::doit(T* input, int inputSize, vector<T>& output, int down, int offset)
+{
+  output.resize((inputSize-offset+down-1)/down);
+  int i=0;
+  //start: extend input with mirrored version of itself
+  for(i=offset;i<m_taps.size()/2;++i){
+    if((i-offset)%down)
+      continue;
+    output[(i-offset+down-1)/down]=m_taps[m_taps.size()/2]*input[i];
+    for(int t=1;t<=m_taps.size()/2;++t)
+      output[(i-offset+down-1)/down]+=(m_taps[m_taps.size()/2+t]+m_taps[m_taps.size()/2-t])*input[i+t];
+  }
+  //main
+  for(i=offset+m_taps.size()/2;i<inputSize-m_taps.size()/2;++i){
+    if((i-offset)%down)
+      continue;
+    T leaveOut=(*(m_taps.begin()))*input[i-m_taps.size()/2];
+    T include=(m_taps.back())*input[i+m_taps.size()/2];
+    output[(i-offset+down-1)/down]=0;
+    for(int t=0;t<m_taps.size();++t)
+      output[(i-offset+down-1)/down]+=input[i-m_taps.size()/2+t]*m_taps[t];
+  }
+  //end: extend input with mirrored version of itself
+  for(i=inputSize-m_taps.size()/2;i<inputSize;++i){
+    if((i-offset)%down)
+      continue;
+    output[(i-offset+down-1)/down]=m_taps[m_taps.size()/2]*input[i];
+    for(int t=1;t<=m_taps.size()/2;++t)
+      output[(i-offset+down-1)/down]+=(m_taps[m_taps.size()/2+t]+m_taps[m_taps.size()/2-t])*input[i-t];
+  }
+}
+}
+using namespace filter;
+
+#endif /* _MYFILTER_H_ */
diff --git a/src/algorithms/Filter2d.cc b/src/algorithms/Filter2d.cc
new file mode 100644
index 0000000..28f6ab5
--- /dev/null
+++ b/src/algorithms/Filter2d.cc
@@ -0,0 +1,928 @@
+/**********************************************************************
+Filter2d.cc: class for filtering images
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <sstream>
+#include <iomanip>
+#include <iostream>
+#include <cmath>
+#include "Filter2d.h"
+#include "Histogram.h"
+// #include "imageclasses/ImgUtils.h"
+
+#ifndef PI
+#define PI 3.1415926535897932384626433832795
+#endif
+
+#include <math.h>
+
+#ifndef DEG2RAD
+#define DEG2RAD(DEG) ((DEG)*((PI)/(180.0)))
+#endif
+
+Filter2d::Filter2d::Filter2d(void)
+  : m_noValue(0)
+{
+}
+
+Filter2d::Filter2d::Filter2d(const Vector2d<double> &taps)
+  : m_taps(taps), m_noValue(0)
+{
+}
+
+void Filter2d::Filter2d::setTaps(const Vector2d<double> &taps)
+{
+  m_taps=taps;
+}
+
+void Filter2d::Filter2d::smoothNoData(const ImgReaderGdal& input, ImgWriterGdal& output, int dim)
+{
+  smoothNoData(input, output,dim,dim);
+}
+
+void Filter2d::Filter2d::smooth(const ImgReaderGdal& input, ImgWriterGdal& output, int dim)
+{
+  smooth(input, output,dim,dim);
+}
+
+void Filter2d::Filter2d::smoothNoData(const ImgReaderGdal& input, ImgWriterGdal& output, int dimX, int dimY)
+{
+  m_taps.resize(dimY);
+  for(int j=0;j<dimY;++j){
+    m_taps[j].resize(dimX);
+    for(int i=0;i<dimX;++i)
+      m_taps[j][i]=1.0;
+  }
+  filter(input,output,false,true,true);
+}
+
+void Filter2d::Filter2d::smooth(const ImgReaderGdal& input, ImgWriterGdal& output, int dimX, int dimY)
+{
+  m_taps.resize(dimY);
+  for(int j=0;j<dimY;++j){
+    m_taps[j].resize(dimX);
+    for(int i=0;i<dimX;++i)
+      m_taps[j][i]=1.0;
+  }
+  filter(input,output,false,true,false);
+}
+
+    
+void Filter2d::Filter2d::filter(const ImgReaderGdal& input, ImgWriterGdal& output, bool absolute, bool normalize, bool noData)
+{
+  int dimX=m_taps[0].size();//horizontal!!!
+  int dimY=m_taps.size();//vertical!!!
+  //  byte* tmpbuf=new byte[input.rowSize()];
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  for(int iband=0;iband<input.nrOfBand();++iband){
+    Vector2d<double> inBuffer(dimY);
+    vector<double> outBuffer(input.nrOfCol());
+    int indexI=0;
+    int indexJ=0;
+    //initialize last half of inBuffer
+    for(int y=0;y<dimY;++y){
+      inBuffer[y].resize(input.nrOfCol());
+      if(y<dimY/2)
+	continue;//skip first half
+      try{
+	input.readData(inBuffer[y],GDT_Float64,indexJ,iband);
+	++indexJ;
+      }
+      catch(string errorstring){
+	cerr << errorstring << "in band " << iband << ", line " << indexJ << endl;
+      }
+    }
+    for(int y=0;y<input.nrOfRow();++y){
+      if(y){//inBuffer already initialized for y=0
+	//erase first line from inBuffer
+	inBuffer.erase(inBuffer.begin());
+	//read extra line and push back to inBuffer if not out of bounds
+	if(y+dimY/2<input.nrOfRow()){
+	  //allocate buffer
+	  inBuffer.push_back(inBuffer.back());
+	  try{
+            input.readData(inBuffer[inBuffer.size()-1],GDT_Float64,y+dimY/2,iband);
+	  }
+	  catch(string errorstring){
+	    cerr << errorstring << "in band " << iband << ", line " << y << endl;
+	  }
+	}
+      }
+      for(int x=0;x<input.nrOfCol();++x){
+	outBuffer[x]=0;
+        double norm=0;
+        bool masked=false;
+        if(noData){//only filter noData values
+          for(int imask=0;imask<m_mask.size();++imask){
+            if(inBuffer[dimY/2][x]==m_mask[imask]){
+              masked=true;
+              break;
+            }
+          }
+          if(!masked){
+            outBuffer[x]=inBuffer[dimY/2][x];
+            continue;
+          }
+        }
+        assert(!noData||masked);
+	for(int j=-dimY/2;j<(dimY+1)/2;++j){
+	  for(int i=-dimX/2;i<(dimX+1)/2;++i){
+	    indexI=x+i;
+	    indexJ=dimY/2+j;
+	    //check if out of bounds
+	    if(x<dimX/2)
+	      indexI=x+abs(i);
+	    else if(x>=input.nrOfCol()-dimX/2)
+	      indexI=x-abs(i);
+	    if(y<dimY/2)
+	      indexJ=dimY/2+abs(j);
+	    else if(y>=input.nrOfRow()-dimY/2)
+	      indexJ=dimY/2-abs(j);
+            //do not take masked values into account
+            masked=false;
+	    for(int imask=0;imask<m_mask.size();++imask){
+	      if(inBuffer[indexJ][indexI]==m_mask[imask]){
+		masked=true;
+		break;
+	      }
+	    }
+	    if(!masked){
+              outBuffer[x]+=(m_taps[dimY/2+j][dimX/2+i]*inBuffer[indexJ][indexI]);
+              norm+=m_taps[dimY/2+j][dimX/2+i];
+            }
+	  }
+        }
+        if(absolute)
+          outBuffer[x]=(normalize)? abs(outBuffer[x])/norm : abs(outBuffer[x]);
+        else if(normalize&&norm!=0)
+          outBuffer[x]=outBuffer[x]/norm;
+      }
+      //write outBuffer to file
+      try{
+        output.writeData(outBuffer,GDT_Float64,y,iband);
+      }
+      catch(string errorstring){
+	    cerr << errorstring << "in band " << iband << ", line " << y << endl;
+      }
+      progress=(1.0+y);
+      progress+=(output.nrOfRow()*iband);
+      progress/=output.nrOfBand()*output.nrOfRow();
+      pfnProgress(progress,pszMessage,pProgressArg);
+    }
+  }
+}
+
+
+void Filter2d::Filter2d::majorVoting(const string& inputFilename, const string& outputFilename,int dim,const vector<int> &prior)
+{
+  bool usePriors=true;  
+  if(prior.empty()){
+    cout << "no prior information" << endl;
+    usePriors=false;
+  }
+  else{
+    cout << "using priors ";    
+    for(int iclass=0;iclass<prior.size();++iclass)
+      cout << " " << static_cast<short>(prior[iclass]);
+    cout << endl;    
+  }  
+  ImgReaderGdal input;
+  ImgWriterGdal output;
+  input.open(inputFilename);
+  output.open(outputFilename,input);
+  int dimX=0;//horizontal!!!
+  int dimY=0;//vertical!!!
+  if(dim){
+    dimX=dim;
+    dimY=dim;
+  }
+  else{
+    dimX=m_taps[0].size();
+    dimY=m_taps.size();
+  }
+  Vector2d<double> inBuffer(dimY);
+  vector<double> outBuffer(input.nrOfCol());
+  //initialize last half of inBuffer
+  int indexI=0;
+  int indexJ=0;
+//   byte* tmpbuf=new byte[input.rowSize()];
+  for(int y=0;y<dimY;++y){
+    inBuffer[y].resize(input.nrOfCol());
+    if(y<dimY/2)
+      continue;//skip first half
+    try{
+      input.readData(inBuffer[y],GDT_Float64,indexJ++);
+    }
+    catch(string errorstring){
+      cerr << errorstring << "in line " << indexJ << endl;
+    }
+  }
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  for(int y=0;y<input.nrOfRow();++y){
+    if(y){//inBuffer already initialized for y=0
+      //erase first line from inBuffer
+      inBuffer.erase(inBuffer.begin());
+      //read extra line and push back to inBuffer if not out of bounds
+      if(y+dimY/2<input.nrOfRow()){
+	//allocate buffer
+	inBuffer.push_back(inBuffer.back());
+	try{
+          input.readData(inBuffer[inBuffer.size()-1],GDT_Float64,y+dimY/2);
+	}
+	catch(string errorstring){
+	  cerr << errorstring << "in line" << y << endl;
+	}
+      }
+    }
+    for(int x=0;x<input.nrOfCol();++x){
+      outBuffer[x]=0;
+      map<int,int> occurrence;
+      for(int j=-dimY/2;j<(dimY+1)/2;++j){
+	for(int i=-dimX/2;i<(dimX+1)/2;++i){
+	  indexI=x+i;
+	  indexJ=dimY/2+j;
+	  //check if out of bounds
+	  if(x<dimX/2)
+	    indexI=x+abs(i);
+	  else if(x>=input.nrOfCol()-dimX/2)
+	    indexI=x-abs(i);
+	  if(y<dimY/2)
+	    indexJ=dimY/2+abs(j);
+	  else if(y>=input.nrOfRow()-dimY/2)
+	    indexJ=dimY/2-abs(j);
+	  if(usePriors){
+	    occurrence[inBuffer[indexJ][indexI]]+=prior[inBuffer[indexJ][indexI]-1];
+	  }	  
+	  else
+	    ++occurrence[inBuffer[indexJ][indexI]];
+	}
+      }
+      map<int,int>::const_iterator maxit=occurrence.begin();
+      for(map<int,int>::const_iterator mit=occurrence.begin();mit!=occurrence.end();++mit){
+	if(mit->second>maxit->second)
+	  maxit=mit;
+      }
+      if(occurrence[inBuffer[dimY/2][x]]<maxit->second)//
+	outBuffer[x]=maxit->first;
+      else//favorize original value in case of ties
+	outBuffer[x]=inBuffer[dimY/2][x];
+    }
+    //write outBuffer to file
+    try{
+      output.writeData(outBuffer,GDT_Float64,y);
+    }
+    catch(string errorstring){
+      cerr << errorstring << "in line" << y << endl;
+    }
+    progress=(1.0+y)/output.nrOfRow();
+    pfnProgress(progress,pszMessage,pProgressArg);
+  }
+  input.close();
+  output.close();
+}
+
+// void Filter2d::homogeneousSpatial(const string& inputFilename, const string& outputFilename, int dim, bool disc, int noValue)
+// {
+//   ImgReaderGdal input;
+//   ImgWriterGdal output;
+//   input.open(inputFilename);
+//   output.open(outputFilename,input);
+//   int dimX=0;//horizontal!!!
+//   int dimY=0;//vertical!!!
+//   assert(dim);
+//   dimX=dim;
+//   dimY=dim;
+//   Vector2d<double> inBuffer(dimY);
+//   vector<double> outBuffer(input.nrOfCol());
+//   //initialize last half of inBuffer
+//   int indexI=0;
+//   int indexJ=0;
+//   for(int y=0;y<dimY;++y){
+//     inBuffer[y].resize(input.nrOfCol());
+//     if(y<dimY/2)
+//       continue;//skip first half
+//     try{
+//       input.readData(inBuffer[y],GDT_Float64,indexJ++);
+//     }
+//     catch(string errorstring){
+//       cerr << errorstring << "in line " << indexJ << endl;
+//     }
+//   }
+//   const char* pszMessage;
+//   void* pProgressArg=NULL;
+//   GDALProgressFunc pfnProgress=GDALTermProgress;
+//   double progress=0;
+//   pfnProgress(progress,pszMessage,pProgressArg);
+//   for(int y=0;y<input.nrOfRow();++y){
+//     if(y){//inBuffer already initialized for y=0
+//       //erase first line from inBuffer
+//       inBuffer.erase(inBuffer.begin());
+//       //read extra line and push back to inBuffer if not out of bounds
+//       if(y+dimY/2<input.nrOfRow()){
+//         //allocate buffer
+//         inBuffer.push_back(inBuffer.back());
+//         try{
+//           input.readData(inBuffer[inBuffer.size()-1],GDT_Float64,y+dimY/2);
+//         }
+//         catch(string errorstring){
+//           cerr << errorstring << "in line " << y << endl;
+//         }
+//       }
+//     }
+//     for(int x=0;x<input.nrOfCol();++x){
+//       outBuffer[x]=0;
+//       map<int,int> occurrence;
+//       for(int j=-dimY/2;j<(dimY+1)/2;++j){
+// 	for(int i=-dimX/2;i<(dimX+1)/2;++i){
+//           if(disc&&(i*i+j*j>(dim/2)*(dim/2)))
+//             continue;
+//           indexI=x+i;
+//           //check if out of bounds
+//           if(indexI<0)
+//             indexI=-indexI;
+//           else if(indexI>=input.nrOfCol())
+//             indexI=input.nrOfCol()-indexI;
+//           if(y+j<0)
+//             indexJ=-j;
+//           else if(y+j>=input.nrOfRow())
+//             indexJ=dimY/2-j;
+//           else
+//             indexJ=dimY/2+j;
+//           ++occurrence[inBuffer[indexJ][indexI]];
+// 	}
+//       }
+//       if(occurrence.size()==1)//all values in window must be the same
+// 	outBuffer[x]=inBuffer[dimY/2][x];
+//       else//favorize original value in case of ties
+// 	outBuffer[x]=noValue;
+//     }
+//     //write outBuffer to file
+//     try{
+//       output.writeData(outBuffer,GDT_Float64,y);
+//     }
+//     catch(string errorstring){
+//       cerr << errorstring << "in line" << y << endl;
+//     }
+//     progress=(1.0+y)/input.nrOfRow();
+//     pfnProgress(progress,pszMessage,pProgressArg);
+//   }
+//   input.close();
+//   output.close();
+// }
+
+void Filter2d::Filter2d::median(const string& inputFilename, const string& outputFilename,int dim, bool disc)
+{
+  ImgReaderGdal input;
+  ImgWriterGdal output;
+  input.open(inputFilename);
+  output.open(outputFilename,input);
+  doit(input,output,MEDIAN,dim,disc);
+}
+
+void Filter2d::Filter2d::var(const string& inputFilename, const string& outputFilename,int dim, bool disc)
+{
+  ImgReaderGdal input;
+  ImgWriterGdal output;
+  input.open(inputFilename);
+  output.open(outputFilename,input);
+  doit(input,output,VAR,dim,disc);
+}
+
+void Filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output, int method, int dim, short down, bool disc)
+{
+  doit(input,output,method,dim,dim,down,disc);
+}
+
+void Filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output, int method, int dimX, int dimY, short down, bool disc)
+{
+  // ImgReaderGdal input;
+  // ImgWriterGdal output;
+  // input.open(inputFilename);
+  // output.open(outputFilename,input);
+  assert(dimX);
+  assert(dimY);
+  Histogram hist;
+  for(int iband=0;iband<input.nrOfBand();++iband){
+    Vector2d<double> inBuffer(dimY,input.nrOfCol());
+    // vector<double> outBuffer(input.nrOfCol());
+    vector<double> outBuffer((input.nrOfCol()+down-1)/down);
+    //initialize last half of inBuffer
+    int indexI=0;
+    int indexJ=0;
+    // for(int y=0;y<dimY;++y){
+    for(int j=-dimY/2;j<(dimY+1)/2;++j){
+      // if(y<dimY/2)
+      //   continue;//skip first half
+      try{
+        input.readData(inBuffer[indexJ],GDT_Float64,abs(j),iband);
+      }
+      catch(string errorstring){
+	cerr << errorstring << "in line " << indexJ << endl;
+      }
+      ++indexJ;
+    }
+    const char* pszMessage;
+    void* pProgressArg=NULL;
+    GDALProgressFunc pfnProgress=GDALTermProgress;
+    double progress=0;
+    pfnProgress(progress,pszMessage,pProgressArg);
+    // for(int y=0;y<input.nrOfRow();++y){
+    for(int y=0;y<input.nrOfRow();++y){
+      if(y){//inBuffer already initialized for y=0
+	//erase first line from inBuffer
+	inBuffer.erase(inBuffer.begin());
+	//read extra line and push back to inBuffer if not out of bounds
+	if(y+dimY/2<input.nrOfRow()){
+          //allocate buffer
+          inBuffer.push_back(inBuffer.back());
+	  try{
+            input.readData(inBuffer[inBuffer.size()-1],GDT_Float64,y+dimY/2,iband);
+	  }
+	  catch(string errorstring){
+	    cerr << errorstring << "in band " << iband << ", line " << y << endl;
+	  }
+	}
+        else{
+          int over=y+dimY/2-input.nrOfRow();
+          int index=(inBuffer.size()-1)-over;
+          assert(index>=0);
+          assert(index<inBuffer.size());
+          inBuffer.push_back(inBuffer[index]);
+        }
+      }
+      if((y+1+down/2)%down)
+        continue;
+      for(int x=0;x<input.nrOfCol();++x){
+        if((x+1+down/2)%down)
+          continue;
+	// outBuffer[x]=0;
+	outBuffer[x/down]=0;
+	vector<double> windowBuffer;
+	map<int,int> occurrence;
+	for(int j=-dimY/2;j<(dimY+1)/2;++j){
+	  for(int i=-dimX/2;i<(dimX+1)/2;++i){
+	    double d2=i*i+j*j;//square distance
+            if(disc&&(d2>(dimX/2)*(dimY/2)))
+              continue;
+	    indexI=x+i;
+	    //check if out of bounds
+	    if(indexI<0)
+	      indexI=-indexI;
+	    else if(indexI>=input.nrOfCol())
+	      indexI=input.nrOfCol()-i;
+	      // indexI=input.nrOfCol()-indexI;
+	    if(y+j<0)
+	      indexJ=-j;
+	    else if(y+j>=input.nrOfRow())
+	      indexJ=dimY/2-j;
+	    else
+	      indexJ=dimY/2+j;
+	    // if(method==HOMOG||method==DENSITY||method==MAJORITY||method==MIXED){
+	    //   bool masked=false;
+	    //   for(int imask=0;imask<m_mask.size();++imask){
+	    //     if(inBuffer[indexJ][indexI]==m_mask[imask]){
+	    //       masked=true;
+	    //       break;
+	    //     }
+	    //   }
+	    //   if(!masked)
+	    //     ++occurrence[inBuffer[indexJ][indexI]];
+	    // }
+	    bool masked=false;
+	    for(int imask=0;imask<m_mask.size();++imask){
+	      if(inBuffer[indexJ][indexI]==m_mask[imask]){
+		masked=true;
+		break;
+	      }
+	    }
+	    if(!masked){
+              vector<short>::const_iterator vit=m_class.begin();
+              //todo: test if this works (only add occurrence if within defined classes)!
+              if(!m_class.size())
+                ++occurrence[inBuffer[indexJ][indexI]];
+              else{
+                while(vit!=m_class.end()){
+                  if(inBuffer[indexJ][indexI]==*(vit++))
+                    ++occurrence[inBuffer[indexJ][indexI]];
+                }
+              }
+              windowBuffer.push_back(inBuffer[indexJ][indexI]);
+            }
+	  }
+        }
+        switch(method){
+        case(MEDIAN):
+          // outBuffer[x]=hist.median(windowBuffer);
+          outBuffer[x/down]=hist.median(windowBuffer);
+          break;
+        case(VAR):{
+          // outBuffer[x]=hist.var(windowBuffer);
+          outBuffer[x/down]=hist.var(windowBuffer);
+          break;
+        }
+        case(MEAN):{
+          // outBuffer[x]=hist.mean(windowBuffer);
+          outBuffer[x/down]=hist.mean(windowBuffer);
+          break;
+        }
+        case(MIN):{
+          // outBuffer[x]=hist.min(windowBuffer);
+          outBuffer[x/down]=hist.min(windowBuffer);
+          break;
+        }
+        case(MINMAX):{
+          double min=0;
+          double max=0;
+          hist.minmax(windowBuffer,windowBuffer.begin(),windowBuffer.end(),min,max);
+          if(min!=max)
+            outBuffer[x/down]=0;
+            // outBuffer[x]=0;
+          else
+            outBuffer[x/down]=windowBuffer[dimX*dimY/2];//centre pixels
+            // outBuffer[x]=windowBuffer[dimX*dimY/2];//centre pixels
+          break;
+        }
+        case(MAX):{
+          // outBuffer[x]=hist.max(windowBuffer);
+          outBuffer[x/down]=hist.max(windowBuffer);
+          break;
+        }
+        case(SUM):{
+          // outBuffer[x]=hist.sum(windowBuffer);
+          outBuffer[x/down]=hist.sum(windowBuffer);
+          break;
+        }
+        case(HOMOG):
+	  if(occurrence.size()==1)//all values in window must be the same
+	    outBuffer[x/down]=inBuffer[dimY/2][x];
+	    // outBuffer[x]=inBuffer[dimY/2][x];
+	  else//favorize original value in case of ties
+	    outBuffer[x/down]=m_noValue;
+	    // outBuffer[x]=m_noValue;
+          break;
+        case(DENSITY):{
+	  if(windowBuffer.size()){
+	    vector<short>::const_iterator vit=m_class.begin();
+	    while(vit!=m_class.end())
+	      outBuffer[x/down]+=100.0*occurrence[*(vit++)]/windowBuffer.size();
+	      // outBuffer[x]+=100.0*occurrence[*(vit++)]/windowBuffer.size();
+	  }
+	  else
+	    outBuffer[x/down]=0;
+	    // outBuffer[x]=0;
+          break;
+	}
+        case(MAJORITY):{
+	  if(occurrence.size()){
+            map<int,int>::const_iterator maxit=occurrence.begin();
+            for(map<int,int>::const_iterator mit=occurrence.begin();mit!=occurrence.end();++mit){
+              if(mit->second>maxit->second)
+                maxit=mit;
+            }
+            if(occurrence[inBuffer[dimY/2][x]]<maxit->second)//
+              outBuffer[x/down]=maxit->first;
+            else//favorize original value in case of ties
+              outBuffer[x/down]=inBuffer[dimY/2][x];
+	  }
+	  else
+	    outBuffer[x/down]=0;
+          // outBuffer[x]=0;
+          break;
+        }
+        case(THRESHOLD):{
+          assert(m_class.size()==m_threshold.size());
+	  if(windowBuffer.size()){
+            outBuffer[x/down]=inBuffer[dimY/2][x];//initialize with original value (in case thresholds not met)
+            for(int iclass=0;iclass<m_class.size();++iclass){
+              if(100.0*(occurrence[m_class[iclass]])/windowBuffer.size()>m_threshold[iclass])
+                outBuffer[x/down]=m_class[iclass];
+            }
+          }
+          else
+	    outBuffer[x/down]=0;
+          break;
+        }
+        case(MIXED):{
+          enum Type { BF=11, CF=12, MF=13, NF=20, W=30 };
+          double nBF=occurrence[BF];
+          double nCF=occurrence[CF];
+          double nMF=occurrence[MF];
+          double nNF=occurrence[NF];
+          double nW=occurrence[W];
+	  if(windowBuffer.size()){
+            if((nBF+nCF+nMF)&&(nBF+nCF+nMF>=nNF+nW)){//forest
+              if(nBF/(nBF+nCF)>=0.75)
+                outBuffer[x/down]=BF;
+              else if(nCF/(nBF+nCF)>=0.75)
+                outBuffer[x/down]=CF;
+              else
+                outBuffer[x/down]=MF;
+            }
+            else{//non-forest
+              if(nW&&(nW>=nNF))
+                outBuffer[x/down]=W;
+              else
+                outBuffer[x/down]=NF;
+            }
+          }
+	  else
+	    outBuffer[x/down]=inBuffer[indexJ][indexI];
+            // outBuffer[x]=0;
+          break;
+        }
+        default:
+          break;
+        }
+      }
+      // progress=(1.0+y);
+      progress=(1.0+y/down);
+      progress+=(output.nrOfRow()*iband);
+      progress/=output.nrOfBand()*output.nrOfRow();
+      // assert(progress>=0);
+      // assert(progress<=1);
+      pfnProgress(progress,pszMessage,pProgressArg);
+      //write outBuffer to file
+      try{
+        output.writeData(outBuffer,GDT_Float64,y/down,iband);
+        // output.writeData(outBuffer,GDT_Float64,y,iband);
+      }
+      catch(string errorstring){
+	cerr << errorstring << "in band " << iband << ", line " << y << endl;
+      }
+    }
+  }
+  // input.close();
+  // output.close();
+}
+
+//todo: re-implement without dependency of CImg and reg libraries
+// void Filter2d::Filter2d::dwt_texture(const string& inputFilename, const string& outputFilename,int dim, int scale, int down, int iband, bool verbose)
+// {
+//   ImgReaderGdal input;
+//   ImgWriterGdal output;
+//   if(verbose)
+//     cout << "opening file " << inputFilename << endl;
+//   input.open(inputFilename);
+//   double magicX=1,magicY=1;
+//   output.open(outputFilename,(input.nrOfCol()+down-1)/down,(input.nrOfRow()+down-1)/down,scale*3,GDT_Float32,input.getImageType());
+//   if(input.isGeoRef()){
+//     output.setProjection(input.getProjection());
+//     output.copyGeoTransform(input);
+//   }
+//   if(verbose)
+//     cout << "Dimension texture (row x col x band) = " << (input.nrOfCol()+down-1)/down << " x " << (input.nrOfRow()+down-1)/down << " x " << scale*3 << endl;
+//   assert(dim%2);
+//   int dimX=dim;
+//   int dimY=dim;
+//   Vector2d<float> inBuffer(dimY,input.nrOfCol());
+//   Vector2d<float> outBuffer(scale*3,(input.nrOfCol()+down-1)/down);
+//   //initialize last half of inBuffer
+//   int indexI=0;
+//   int indexJ=0;
+//   for(int j=-dimY/2;j<(dimY+1)/2;++j){
+//     try{
+//       if(verbose)
+// 	cout << "reading input line " << abs(j) << endl;
+//       input.readData(inBuffer[indexJ],GDT_Float32,abs(j),iband);
+//       ++indexJ;
+//     }
+//     catch(string errorstring){
+//       cerr << errorstring << "in band " << iband << ", line " << indexJ << endl;
+//     }
+//   }
+//   const char* pszMessage;
+//   void* pProgressArg=NULL;
+//   GDALProgressFunc pfnProgress=GDALTermProgress;
+//   double progress=0;
+//   pfnProgress(progress,pszMessage,pProgressArg);
+//   for(int y=0;y<input.nrOfRow();y+=down){
+//     if(verbose)
+//       cout << "calculating line " << y/down << endl;
+//     if(y){//inBuffer already initialized for y=0
+//       //erase first line from inBuffer
+//       inBuffer.erase(inBuffer.begin());
+//       //read extra line and push back to inBuffer if not out of bounds
+//       if(y+dimY/2<input.nrOfRow()){
+// 	//allocate buffer
+// 	inBuffer.push_back(inBuffer.back());
+// 	try{
+// 	  if(verbose)
+// 	    cout << "reading input line " << y+dimY/2 << endl;
+//           input.readData(inBuffer[inBuffer.size()-1],GDT_Float32,y+dimY/2,iband);
+// 	}
+// 	catch(string errorstring){
+// 	  cerr << errorstring << "in band " << iband << ", line " << y << endl;
+// 	}
+//       }
+//     }
+//     for(int x=0;x<input.nrOfCol();x+=down){
+//       Vector2d<double> texture_feature(scale,3);
+//       CImg<> texture_in(dimX,dimY);
+//       int r=0;//index for row of texture_in
+//       for(int j=-dimY/2;j<(dimY+1)/2;++j){
+// 	int c=0;
+// 	for(int i=-dimX/2;i<(dimX+1)/2;++i){
+// 	  indexI=x+i;
+// 	  //check if out of bounds
+// 	  if(indexI<0)
+// 	    indexI=-indexI;
+// 	  else if(indexI>=input.nrOfCol())
+// 	    indexI=input.nrOfCol()-i;
+// 	  if(y+j<0)
+// 	    indexJ=-j;
+// 	  else if(y+j>=input.nrOfRow())
+// 	    indexJ=dimY/2-j;//indexJ=inBuffer.size()-1-j;
+// 	  else
+// 	    indexJ=dimY/2+j;
+// 	  assert(indexJ<inBuffer.size());
+// 	  assert(indexI<inBuffer[indexJ].size());
+// 	  texture_in(r,c)=inBuffer[indexJ][indexI];
+// 	  c++;
+// 	}
+// 	++r;
+//       }
+//       texture_in.dwt_texture(texture_feature,scale);
+//       for(int v=0;v<scale*3;++v)
+// 	outBuffer[v][x/down]=texture_feature[v/3][v%3];
+//     }
+//     //write outBuffer to file
+//     try{
+//       if(verbose)
+//         cout << "writing line " << y/down << endl;
+//       for(int v=0;v<scale*3;++v)
+//         output.writeData(outBuffer[v],GDT_Float32,y/down,v);
+//     }
+//     catch(string errorstring){
+//       cerr << errorstring << "in band " << iband << ", line " << y << endl;
+//     }
+//     progress=(1.0+y)/output.nrOfRow();
+//     pfnProgress(progress,pszMessage,pProgressArg);
+//   }
+//   input.close();
+//   output.close();
+// }
+
+void Filter2d::Filter2d::morphology(const ImgReaderGdal& input, ImgWriterGdal& output, int method, int dimX, int dimY, bool disc, double angle)
+{
+  assert(dimX);
+  assert(dimY);
+  Histogram hist;
+  for(int iband=0;iband<input.nrOfBand();++iband){
+    Vector2d<double> inBuffer(dimY,input.nrOfCol());
+    vector<double> outBuffer(input.nrOfCol());
+    //initialize last half of inBuffer
+    int indexI=0;
+    int indexJ=0;
+    for(int j=-dimY/2;j<(dimY+1)/2;++j){
+      try{
+	input.readData(inBuffer[indexJ],GDT_Float64,abs(j),iband);
+	++indexJ;
+      }
+      catch(string errorstring){
+	cerr << errorstring << "in line " << indexJ << endl;
+      }
+    }
+    const char* pszMessage;
+    void* pProgressArg=NULL;
+    GDALProgressFunc pfnProgress=GDALTermProgress;
+    double progress=0;
+    pfnProgress(progress,pszMessage,pProgressArg);
+    for(int y=0;y<input.nrOfRow();++y){
+      if(y){//inBuffer already initialized for y=0
+	//erase first line from inBuffer
+	inBuffer.erase(inBuffer.begin());
+	//read extra line and push back to inBuffer if not out of bounds
+	if(y+dimY/2<input.nrOfRow()){
+	  //allocate buffer
+	  inBuffer.push_back(inBuffer.back());
+	  try{
+            input.readData(inBuffer[inBuffer.size()-1],GDT_Float64,y+dimY/2,iband);
+	  }
+	  catch(string errorstring){
+	    cerr << errorstring << "in band " << iband << ", line " << y << endl;
+	  }
+	}
+      }
+      for(int x=0;x<input.nrOfCol();++x){
+	outBuffer[x]=0;
+        double currentValue=inBuffer[dimY/2][x];
+	vector<double> histBuffer;
+	bool currentMasked=false;
+	for(int imask=0;imask<m_mask.size();++imask){
+	  if(currentValue==m_mask[imask]){
+	    currentMasked=true;
+	    break;
+	  }
+	}
+	if(currentMasked){
+	  outBuffer[x]=currentValue;
+	}
+	else{
+	  for(int j=-dimY/2;j<(dimY+1)/2;++j){
+	    for(int i=-dimX/2;i<(dimX+1)/2;++i){
+	      if(disc&&(i*i+j*j>(dimX/2)*(dimY/2)))
+		continue;
+	      // if(angle>=-180){
+	      // 	double theta;
+	      // 	if(i)
+	      // 	  theta=atan(static_cast<double>(j)/(static_cast<double>(i)));
+	      // 	else if(j>0)
+	      // 	  theta=PI/2.0;
+	      // 	else if(j<0)
+	      // 	  theta=3.0*PI/2.0;
+	      // 	if(j&&(theta<DEG2RAD(angle)||theta>DEG2RAD(angle+PI)))
+	      // 	  continue;
+	      // }
+	      indexI=x+i;
+	      //check if out of bounds
+	      if(indexI<0)
+		indexI=-indexI;
+	      else if(indexI>=input.nrOfCol())
+		indexI=input.nrOfCol()-i;
+	      if(y+j<0)
+		indexJ=-j;
+	      else if(y+j>=input.nrOfRow())
+		indexJ=dimY/2-j;//indexJ=inBuffer.size()-1-j;
+	      else
+		indexJ=dimY/2+j;
+	      bool masked=false;
+	      for(int imask=0;imask<m_mask.size();++imask){
+		if(inBuffer[indexJ][indexI]==m_mask[imask]){
+		  masked=true;
+		  break;
+		}
+	      }
+	      if(!masked){
+		short binValue=0;
+		for(int iclass=0;iclass<m_class.size();++iclass){
+		  if(inBuffer[indexJ][indexI]==m_class[iclass]){
+		    binValue=1;
+		    break;
+		  }
+		}
+		if(m_class.size())
+		  histBuffer.push_back(binValue);
+		else
+		  histBuffer.push_back(inBuffer[indexJ][indexI]);
+	      }
+	    }
+	  }
+	  assert(histBuffer.size());//should never occur if not masked (?)
+	  switch(method){
+	  case(DILATE):
+	    outBuffer[x]=hist.max(histBuffer);
+	    break;
+	  case(ERODE):
+	    outBuffer[x]=hist.min(histBuffer);
+	    break;
+	  default:
+	    ostringstream ess;
+	    ess << "Error:  morphology method " << method << " not supported, choose " << DILATE << " (dilate) or " << ERODE << " (erode)" << endl;
+	    throw(ess.str());
+	    break;
+	  }
+	  if(outBuffer[x]&&m_class.size())
+	    outBuffer[x]=m_class[0];
+	  // else{
+	  //   assert(m_mask.size());
+	  //   outBuffer[x]=m_mask[0];
+	  // }
+	}
+      }
+      //write outBuffer to file
+      try{
+        output.writeData(outBuffer,GDT_Float64,y,iband);
+      }
+      catch(string errorstring){
+	cerr << errorstring << "in band " << iband << ", line " << y << endl;
+      }
+      progress=(1.0+y);
+      progress+=(output.nrOfRow()*iband);
+      progress/=output.nrOfBand()*output.nrOfRow();
+      pfnProgress(progress,pszMessage,pProgressArg);
+    }
+  }
+}
diff --git a/src/algorithms/Filter2d.h b/src/algorithms/Filter2d.h
new file mode 100644
index 0000000..d431682
--- /dev/null
+++ b/src/algorithms/Filter2d.h
@@ -0,0 +1,277 @@
+/**********************************************************************
+Filter2d.h: class for filtering images
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _MYFILTER2D_H_
+#define _MYFILTER2D_H_
+
+#include <assert.h>
+#include <limits>
+#include <vector>
+#include <string>
+#include <map>
+#include "base/Vector2d.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+
+using namespace std;
+// using namespace cimg_library;
+namespace Filter2d
+{
+  enum Type { MEDIAN=0, VAR=1 , MIN=2, MAX=3, SUM=4, MEAN=5, MINMAX=6, DILATE=7, ERODE=8, CLOSE=9, OPEN=10, HOMOG=11, SOBELX=12, SOBELY=13, SOBELXY=14, SMOOTH=15, DENSITY=16, MAJORITY=17, MIXED=18, SMOOTHNODATA=19, THRESHOLD=20};
+  
+class Filter2d
+{
+public:
+  Filter2d(void);
+  Filter2d(const Vector2d<double> &taps);
+  virtual ~Filter2d(){};
+  void setTaps(const Vector2d<double> &taps);
+  void setNoValue(double noValue=0){m_noValue=noValue;};
+  void pushClass(short theClass=1){m_class.push_back(theClass);};
+  void pushMask(short theMask=0){m_mask.push_back(theMask);};
+  void pushThreshold(double theThreshold){m_threshold.push_back(theThreshold);};
+  void setThresholds(const vector<double>& theThresholds){m_threshold=theThresholds;};
+  void setClasses(const vector<short>& theClasses){m_class=theClasses;};
+  void filter(const ImgReaderGdal& input, ImgWriterGdal& output, bool absolute=false, bool normalize=true, bool noData=false);
+  void smooth(const ImgReaderGdal& input, ImgWriterGdal& output,int dim);
+  void smooth(const ImgReaderGdal& input, ImgWriterGdal& output,int dimX, int dimY);
+  void smoothNoData(const ImgReaderGdal& input, ImgWriterGdal& output,int dim);
+  void smoothNoData(const ImgReaderGdal& input, ImgWriterGdal& output,int dimX, int dimY);
+  template<class T1, class T2> void filter(const Vector2d<T1>& inputVector, Vector2d<T2>& outputVector);
+  template<class T1, class T2> void smooth(const Vector2d<T1>& inputVector, Vector2d<T2>& outputVector,int dim);
+  template<class T1, class T2> void smooth(const Vector2d<T1>& inputVector, Vector2d<T2>& outputVector,int dimX, int dimY);
+  void majorVoting(const string& inputFilename, const string& outputFilename,int dim=0,const vector<int> &prior=vector<int>());
+  /* void homogeneousSpatial(const string& inputFilename, const string& outputFilename, int dim, bool disc=false, int noValue=0); */
+  void doit(const ImgReaderGdal& input, ImgWriterGdal& output, int method, int dim, short down=2, bool disc=false);
+  void doit(const ImgReaderGdal& input, ImgWriterGdal& output, int method, int dimX, int dimY, short down=1, bool disc=false);
+  void median(const string& inputFilename, const string& outputFilename, int dim, bool disc=false);
+  void var(const string& inputFilename, const string& outputFilename, int dim, bool disc=false);
+  void morphology(const ImgReaderGdal& input, ImgWriterGdal& output, int method, int dimX, int dimY, bool disc=false, double angle=-190);
+  template<class T> unsigned long int morphology(const Vector2d<T>& input, Vector2d<T>& output, int method, int dimX, int dimY, bool disc=false, double hThreshold=0);
+  void dwt_texture(const string& inputFilename, const string& outputFilename,int dim, int scale, int down=1, int iband=0, bool verbose=false);
+  
+private:
+  Vector2d<double> m_taps;
+  double m_noValue;
+  vector<short> m_class;
+  vector<short> m_mask;
+  vector<double> m_threshold;
+};
+
+ template<class T1, class T2> void Filter2d::smooth(const Vector2d<T1>& inputVector, Vector2d<T2>& outputVector,int dim)
+  {
+    smooth(inputVector,outputVector,dim,dim);
+  }
+
+ template<class T1, class T2> void Filter2d::smooth(const Vector2d<T1>& inputVector, Vector2d<T2>& outputVector,int dimX, int dimY)
+  {
+    m_taps.resize(dimY);
+    for(int j=0;j<dimY;++j){
+      m_taps[j].resize(dimX);
+      for(int i=0;i<dimX;++i)
+	m_taps[j][i]=1.0/dimX/dimY;
+    }
+    filter(inputVector,outputVector);
+  }
+  
+ template<class T1, class T2> void Filter2d::filter(const Vector2d<T1>& inputVector, Vector2d<T2>& outputVector)
+  {
+  outputVector.resize(inputVector.size());
+  int dimX=m_taps[0].size();//horizontal!!!
+  int dimY=m_taps.size();//vertical!!!
+  Vector2d<T1> inBuffer(dimY);
+  vector<T2> outBuffer(inputVector[0].size());
+  //initialize last half of inBuffer
+  int indexI=0;
+  int indexJ=0;
+  for(int y=0;y<dimY;++y){
+    if(y<dimY/2)
+      continue;//skip first half
+    inBuffer[y]=inputVector[indexJ++];
+  }
+  for(int y=0;y<inputVector.size();++y){
+    if(y){//inBuffer already initialized for y=0
+      //erase first line from inBuffer
+      inBuffer.erase(inBuffer.begin());
+      //read extra line and push back to inBuffer if not out of bounds
+      if(y+dimY/2<inputVector.size())
+	inBuffer.push_back(inputVector[y+dimY/2]);
+    }
+    for(int x=0;x<inputVector[0].size();++x){
+      outBuffer[x]=0;
+      for(int j=-dimY/2;j<(dimY+1)/2;++j){
+	for(int i=-dimX/2;i<(dimX+1)/2;++i){
+	  indexI=x+i;
+	  indexJ=dimY/2+j;
+	  //check if out of bounds
+	  if(x<dimX/2)
+	    indexI=x+abs(i);
+	  else if(x>=inputVector[0].size()-dimX/2)
+	    indexI=x-abs(i);
+	  if(y<dimY/2)
+	    indexJ=dimY/2+abs(j);
+	  else if(y>=inputVector.size()-dimY/2)
+	    indexJ=dimY/2-abs(j);
+	  outBuffer[x]+=(m_taps[dimY/2+j][dimX/2+i]*inBuffer[indexJ][indexI]);
+	}
+      }
+    }
+    //copy outBuffer to outputVector
+    outputVector[y]=outBuffer;
+  }
+}
+
+// class Compare_mapValue{
+// public:
+//   int operator() (const map<int,int>::value_type& v1, const map<int, int>::value_type& v2) const{
+//     return (v1.second)>(v2.second);
+//   }
+// };
+
+template<class T> unsigned long int Filter2d::morphology(const Vector2d<T>& input, Vector2d<T>& output, int method, int dimX, int dimY, bool disc, double hThreshold)
+{
+  unsigned long int nchange=0;
+  assert(dimX);
+  assert(dimY);
+  Histogram hist;
+  Vector2d<T> inBuffer(dimY,input.nCols());
+  output.clear();
+  output.resize(input.nRows(),input.nCols());
+  //initialize last half of inBuffer
+  int indexI=0;
+  int indexJ=0;
+  for(int j=-dimY/2;j<(dimY+1)/2;++j){
+    for(int i=0;i<input.nCols();++i)
+      inBuffer[indexJ][i]=input[abs(j)][i];
+    ++indexJ;
+  }
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  for(int y=0;y<input.nRows();++y){
+    if(y){//inBuffer already initialized for y=0
+      //erase first line from inBuffer
+      inBuffer.erase(inBuffer.begin());
+      //read extra line and push back to inBuffer if not out of bounds
+      if(y+dimY/2<input.nRows()){
+        //allocate buffer
+        inBuffer.push_back(inBuffer.back());
+        for(int i=0;i<input.nCols();++i)
+          inBuffer[inBuffer.size()-1][i]=input[y+dimY/2][i];
+      }
+    }
+    for(int x=0;x<input.nCols();++x){
+      output[y][x]=0;
+      double currentValue=inBuffer[dimY/2][x];
+      vector<double> histBuffer;
+      bool currentMasked=false;
+      for(int imask=0;imask<m_mask.size();++imask){
+        if(currentValue==m_mask[imask]){
+          currentMasked=true;
+          break;
+        }
+      }
+      output[y][x]=currentValue;//introduced due to hThrehold
+      if(currentMasked){
+        output[y][x]=currentValue;
+      }
+      else{
+        for(int j=-dimY/2;j<(dimY+1)/2;++j){
+          for(int i=-dimX/2;i<(dimX+1)/2;++i){
+            if(disc&&(i*i+j*j>(dimX/2)*(dimY/2)))
+              continue;
+            indexI=x+i;
+            //check if out of bounds
+            if(indexI<0)
+              indexI=-indexI;
+            else if(indexI>=input.nCols())
+              indexI=input.nCols()-i;
+            if(y+j<0)
+              indexJ=-j;
+            else if(y+j>=input.nRows())
+              indexJ=dimY/2-j;//indexJ=inBuffer.size()-1-j;
+            else
+              indexJ=dimY/2+j;
+            if(inBuffer[indexJ][indexI]==m_noValue)
+              continue;
+            bool masked=false;
+            for(int imask=0;imask<m_mask.size();++imask){
+              if(inBuffer[indexJ][indexI]==m_mask[imask]){
+                masked=true;
+                break;
+              }
+            }
+            if(!masked){
+              short binValue=0;
+              for(int iclass=0;iclass<m_class.size();++iclass){
+                if(inBuffer[indexJ][indexI]==m_class[iclass]){
+                  binValue=1;
+                  break;
+                }
+              }
+              if(m_class.size())
+                histBuffer.push_back(binValue);
+              else
+                histBuffer.push_back(inBuffer[indexJ][indexI]);
+            }
+          }
+        }
+        if(histBuffer.size()){
+          switch(method){
+          case(DILATE):
+            if(output[y][x]<hist.max(histBuffer)-hThreshold){
+              output[y][x]=hist.max(histBuffer);
+              ++nchange;
+            }
+            break;
+          case(ERODE):
+            if(output[y][x]>hist.min(histBuffer)+hThreshold){
+              output[y][x]=hist.min(histBuffer);
+              ++nchange;
+            }
+            break;
+          default:
+            ostringstream ess;
+            ess << "Error:  morphology method " << method << " not supported, choose " << DILATE << " (dilate) or " << ERODE << " (erode)" << endl;
+            throw(ess.str());
+            break;
+          }
+          if(output[y][x]&&m_class.size())
+            output[y][x]=m_class[0];
+          // else{
+          //   assert(m_mask.size());
+          //   output[x]=m_mask[0];
+          // }
+        }
+        else
+          output[y][x]=m_noValue;
+      }
+    }
+    progress=(1.0+y);
+    progress/=output.nRows();
+    pfnProgress(progress,pszMessage,pProgressArg);
+  }
+  return nchange;
+}
+
+}
+
+#endif /* _MYFILTER_H_ */
diff --git a/src/algorithms/Histogram.cc b/src/algorithms/Histogram.cc
new file mode 100644
index 0000000..cd51498
--- /dev/null
+++ b/src/algorithms/Histogram.cc
@@ -0,0 +1,63 @@
+/**********************************************************************
+Histogram.cc: class for statistical operations on vectors
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "Histogram.h"
+
+
+Histogram::Histogram(){
+}
+
+void Histogram::signature(double m1, double m2, double& k, double& alpha, double& beta, double e)
+{
+  double y=m1*m1/m2;
+  beta=F_1(y,0.1,10.0,e);
+  double fb=F(beta);
+  double g=exp(lgamma(1.0/beta));
+  alpha=m1*g/exp(lgamma(2.0/beta));
+  k=beta/(2*alpha*g);
+//   cout << "y, alpha, beta: " << y << ", " << alpha << ", " << beta << endl;
+}
+
+double Histogram::F(double x)
+{
+  double g2=exp(lgamma(2.0/x));
+  return(g2*g2/exp(lgamma(3.0/x))/exp(lgamma(1.0/x)));
+}
+
+//x1 is under estimate, x2 is over estimate, e is error
+double Histogram::F_1(double y, double x1, double x2, double e)
+{
+  double f1=F(x1);
+  double f2=F(x2);
+  assert(f1!=f2);
+  double x=x1+(x2-x1)*(y-f1)/(f2-f1);
+  double f=F(x);
+  while(f-y>=e||y-f>=e){
+    if(f<y)
+      x1=x;
+    else 
+      x2=x;
+    if(x1==x2)
+      return x1;
+    assert(f1!=f2);
+    x=x1+(x2-x1)*(y-f1)/(f2-f1);
+    f=F(x);
+  }
+  return x;
+}
diff --git a/src/algorithms/Histogram.h b/src/algorithms/Histogram.h
new file mode 100644
index 0000000..4b37e66
--- /dev/null
+++ b/src/algorithms/Histogram.h
@@ -0,0 +1,456 @@
+/**********************************************************************
+Histogram.h: class for statistical operations on vectors
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _HISTOGRAM_H_
+#define _HISTOGRAM_H_
+
+#include <iostream>
+#include <vector>
+#include <math.h>
+#include <assert.h>
+#include <string>
+#include <sstream>
+#include <fstream>
+#include <algorithm>
+#include <gsl/gsl_fit.h>
+//#include <gsl/gsl_errno.h>
+
+/* #include "newmat/newmat.h" */
+/* #include "newmat/newmatap.h" */
+/* #include "newmat/newmatio.h" */
+
+using namespace std;
+// using namespace NEWMAT;
+
+namespace histogram
+{
+      
+class Histogram{
+public:
+  Histogram(void);
+  virtual ~Histogram(void){};
+  template<class T> T max(const vector<T>& v) const;
+  template<class T> T min(const vector<T>& v) const;
+//   template<class T> typename vector<T>::const_iterator max(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const;
+  template<class T> typename vector<T>::const_iterator max(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const;
+  template<class T> typename vector<T>::iterator max(const vector<T>& v, typename vector<T>::iterator begin, typename vector<T>::iterator end) const;
+  template<class T> typename vector<T>::const_iterator absmax(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const;
+  template<class T> typename vector<T>::const_iterator min(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const;
+  template<class T> typename vector<T>::iterator min(const vector<T>& v, typename vector<T>::iterator begin, typename vector<T>::iterator end) const;
+  template<class T> typename vector<T>::const_iterator absmin(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const;
+  template<class T> void minmax(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T& theMin, T& theMax) const;  
+  template<class T> T sum(const vector<T>& v) const;
+  template<class T> double mean(const vector<T>& v) const;
+  template<class T> T median(const vector<T>& v) const;
+  template<class T> double var(const vector<T>& v) const;
+  template<class T> double moment(const vector<T>& v, int n) const;
+  template<class T> double cmoment(const vector<T>& v, int n) const;
+  template<class T> void meanVar(const vector<T>& v, double& m1, double& v1) const;
+  template<class T1, class T2> void  scale2byte(const vector<T1>& input, vector<T2>& output, unsigned char lbound=0, unsigned char ubound=255) const;
+  template<class T> void distribution(const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end,  vector<int>& output, int nbin, T &minimum=0.0, T &maximum=0.0, const string &filename="");
+  template<class T> void cumulative (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<int>& output, int nbin, T &minimum, T &maximum);
+  template<class T> void  percentiles (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<T>& output, int nbin=10, T &minimum=0.0, T &maximum=0.0, const string &filename="");
+  template<class T> void signature(const vector<T>& input, double& k, double& alpha, double& beta, double e);
+  void signature(double m1, double m2, double& k, double& alpha, double& beta, double e);
+  template<class T> void normalize(const vector<T>& input, vector<double>& output);
+  template<class T> void normalize_pct(vector<T>& input);
+  template<class T> double rmse(const vector<T>& x, const vector<T>& y) const;
+  template<class T> double correlation(const vector<T>& x, const vector<T>& y, int delay=0) const;
+  template<class T> double cross_correlation(const vector<T>& x, const vector<T>& y, int maxdelay, vector<T>& z) const;
+  template<class T> double linear_regression(const vector<T>& x, const vector<T>& y, double &c0, double &c1) const;
+private:
+  double F(double x);
+  double F_1(double y, double x1, double x2, double e);
+};
+
+// template<class T> typename vector<T>::const_iterator Histogram::max(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
+// {
+//   typename vector<T>::const_iterator tmpIt=begin;
+//   for (typename vector<T>::const_iterator it = begin; it!=end; ++it){
+//     if(*tmpIt<*it)
+//       tmpIt=it;
+//   }
+//   return tmpIt;
+// }
+
+template<class T> typename vector<T>::iterator Histogram::max(const vector<T>& v, typename vector<T>::iterator begin, typename vector<T>::iterator end) const
+{
+  typename vector<T>::iterator tmpIt=begin;
+  for (typename vector<T>::iterator it = begin; it!=end; ++it){
+    if(*tmpIt<*it)
+      tmpIt=it;
+  }
+  return tmpIt;
+}
+
+template<class T> T Histogram::max(const vector<T>& v) const
+{
+  T maxValue=*(v.begin());
+  for (typename vector<T>::const_iterator it = v.begin(); it!=v.end(); ++it){
+    if(maxValue<*it)
+      maxValue=*it;
+  }
+  return maxValue;
+}
+
+template<class T> T Histogram::min(const vector<T>& v) const
+{
+  T minValue=*(v.begin());
+  for (typename vector<T>::const_iterator it = v.begin(); it!=v.end(); ++it){
+    if(minValue>*it)
+      minValue=*it;
+  }
+  return minValue;
+}
+
+template<class T> typename vector<T>::const_iterator Histogram::absmax(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
+{
+  typename vector<T>::const_iterator tmpIt=begin;
+  for (typename vector<T>::const_iterator it = begin; it!=end; ++it){
+    if(abs(*tmpIt)<abs(*it))
+      tmpIt=it;
+  }
+  return tmpIt;
+}
+
+template<class T> typename vector<T>::const_iterator Histogram::min(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
+{
+  typename vector<T>::const_iterator tmpIt=begin;
+  for (typename vector<T>::const_iterator it = begin; it!=end; ++it){
+    if(*tmpIt>*it)
+      tmpIt=it;
+  }
+  return tmpIt;
+}
+
+template<class T> typename vector<T>::const_iterator Histogram::absmin(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
+{
+  typename vector<T>::const_iterator tmpIt=begin;
+  for (typename vector<T>::const_iterator it = begin; it!=end; ++it){
+    if(abs(*tmpIt)>abs(*it))
+      tmpIt=it;
+  }
+}
+
+template<class T> void Histogram::minmax(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T& theMin, T& theMax) const
+{
+  theMin=*begin;
+  theMax=*begin;
+  for (typename vector<T>::const_iterator it = begin; it!=end; ++it){
+    if(theMin>*it)
+      theMin=*it;
+    if(theMax<*it)
+      theMax=*it;
+  }
+}
+
+template<class T> T Histogram::sum(const vector<T>& v) const
+{
+  typename vector<T>::const_iterator it;
+  T tmpSum=0;
+  for (it = v.begin(); it!= v.end(); ++it)
+    tmpSum+=*it;
+  return tmpSum;
+}
+
+template<class T> double Histogram::mean(const vector<T>& v) const
+{
+  assert(v.size());
+  return static_cast<double>(sum(v))/v.size();
+}
+
+template<class T> T Histogram::median(const vector<T>& v) const
+{
+  vector<T> tmpV=v;
+  sort(tmpV.begin(),tmpV.end());
+  if(tmpV.size()%2)
+    return tmpV[tmpV.size()/2];
+  else
+    return 0.5*(tmpV[tmpV.size()/2-1]+tmpV[tmpV.size()/2]);
+}
+
+template<class T> double Histogram::var(const vector<T>& v) const
+{
+  typename vector<T>::const_iterator it;
+  double v1=0;
+  double m1=mean(v);
+  double n=v.size();
+  assert(n>1);
+  for (it = v.begin(); it!= v.end(); ++it)
+    v1+=(*it-m1)*(*it-m1);
+  v1/=(n-1);
+//   if(v1<0){
+//     for (it = v.begin(); it!= v.end(); ++it)
+//       cout << *it << " ";
+//     cout << endl;
+//   }
+  assert(v1>=0);
+  return v1;
+}
+
+template<class T> double Histogram::moment(const vector<T>& v, int n) const
+{
+  assert(v.size());
+  typename vector<T>::const_iterator it;
+  double m=0;
+//   double m1=mean(v);
+  for(it = v.begin(); it!= v.end(); ++it){
+    m+=pow((*it),n);
+  }
+  return m/v.size();
+}
+
+template<class T> double Histogram::cmoment(const vector<T>& v, int n) const
+{
+  assert(v.size());
+  typename vector<T>::const_iterator it;
+  double m=0;
+  double m1=mean(v);
+  for(it = v.begin(); it!= v.end(); ++it){
+    m+=pow((*it-m1),n);
+  }
+  return m/v.size();
+}
+
+template<class T> void Histogram::meanVar(const vector<T>& v, double& m1, double& v1) const
+{
+  typename vector<T>::const_iterator it;
+  v1=0;
+  m1=mean(v);
+  double n=v.size();
+  assert(n>1);
+  for (it = v.begin(); it!= v.end(); ++it)
+    v1+=(*(it)-m1)*(*(it)-m1);
+  v1/=(n-1);
+  assert(v1>=0);
+}
+
+template<class T1, class T2> void Histogram::scale2byte(const vector<T1>& input, vector<T2>& output, unsigned char lbound,  unsigned char ubound) const
+{
+  output.resize(input.size());
+  T1 minimum=min(input);
+  T1 maximum=max(input);
+  assert(maximum>minimum);
+  double scale=(ubound-lbound)/(maximum-minimum);
+  for (int i=0;i<input.size();++i)
+    output[i]=scale*(input[i]-(minimum))+lbound;
+}
+
+template<class T> void  Histogram::distribution (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<int>& output, int nbin, T &minimum, T &maximum, const string &filename)
+{
+  if(maximum<=minimum)
+    minmax(input,begin,end,minimum,maximum);
+  // if(!minimum)
+  //   minimum=*(min(input,begin,end));
+  // if(!maximum)
+  //   maximum=*(max(input,begin,end));
+  assert(maximum>minimum);
+  assert(nbin>1);
+  assert(input.size());
+  if(output.size()!=nbin){
+    output.resize(nbin);
+    for(int i=0;i<nbin;output[i++]=0);
+  }
+  typename vector<T>::const_iterator it;
+  for(it=begin;it!=end;++it){
+    if(*it==maximum)
+      ++output[nbin-1];
+    else if(*it>=minimum && *it<maximum)
+      ++output[static_cast<int>(static_cast<double>((*it)-minimum)/(maximum-minimum)*nbin)];
+  }
+  if(!filename.empty()){
+    ofstream outputfile;
+    outputfile.open(filename.c_str());
+    if(!outputfile){
+      ostringstream s;
+      s<<"error opening distribution file , " << filename;
+      throw(s.str());
+    }
+    for(int bin=0;bin<nbin;++bin)
+      outputfile << (maximum-minimum)*bin/(nbin-1)+minimum << " " << static_cast<double>(output[bin])/input.size() << endl;
+    outputfile.close();
+  }
+}
+
+template<class T> void  Histogram::percentiles (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<T>& output, int nbin, T &minimum, T &maximum, const string &filename)
+{
+  if(maximum<=minimum)
+    minmax(input,begin,end,minimum,maximum);
+  // if(!minimum)
+  //   minimum=*(min(input,begin,end));
+  // if(!maximum)
+  //   maximum=*(max(input,begin,end));
+  assert(maximum>minimum);
+  assert(nbin>1);
+  assert(input.size());
+  output.resize(nbin);
+  std::vector<T> inputSort;
+  inputSort.assign(begin,end);
+  typename std::vector<T>::iterator vit=inputSort.begin();
+  while(vit!=inputSort.end()){
+    if(*vit<minimum||*vit>maximum)
+      inputSort.erase(vit);
+    else
+      ++vit;
+  }
+  std::sort(inputSort.begin(),inputSort.end());
+  vit=inputSort.begin();
+  std::vector<T> inputBin;
+  for(int ibin=0;ibin<nbin;++ibin){
+    inputBin.clear();
+    while(inputBin.size()<inputSort.size()/nbin&&vit!=inputSort.end()){
+      inputBin.push_back(*vit);
+      ++vit;
+    }
+    if(inputBin.size())
+      output[ibin]=median(inputBin);
+  }
+  if(!filename.empty()){
+    ofstream outputfile;
+    outputfile.open(filename.c_str());
+    if(!outputfile){
+      ostringstream s;
+      s<<"error opening distribution file , " << filename;
+      throw(s.str());
+    }
+    for(int ibin=0;ibin<nbin;++ibin)
+      outputfile << ibin*100.0/nbin << " " << static_cast<double>(output[ibin])/input.size() << endl;
+    outputfile.close();
+  }
+}
+
+// template<class T> void  Histogram::cumulative (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<int>& output, int nbin, T &minimum, T &maximum)
+// {
+//   assert(nbin>1);
+//   assert(input.size());
+//   distribution(input,output,nbin,minimum,maximum);
+//   for(vector<int>::iterator it=begin+1;it!=end;++it)
+//     *it+=*(it-1);
+//   if(!filename.empty()){
+//     ofstream outputfile;
+//     outputfile.open(filename.c_str());
+//     if(!outputfile){
+//       ostringstream s;
+//       s<<"error opening cumulative file , " << filename;
+//       throw(s.str());
+//     }
+//     for(int bin=0;bin<nbin;++bin)
+//       outputfile << (maximum-minimum)*bin/(nbin-1)+minimum << " " << static_cast<double>(output[bin])/input.size() << endl;
+//     outputfile.close();
+//   }
+// }
+
+template<class T> void Histogram::signature(const vector<T>& input, double&k, double& alpha, double& beta, double e)
+{
+  double m1=moment(input,1);
+  double m2=moment(input,2);
+  signature(m1,m2,k,alpha,beta,e);
+}
+
+template<class T> void Histogram::normalize(const vector<T>& input, vector<double>& output){
+  double total=sum(input);
+  if(total){
+    output.resize(input.size());
+    for(int index=0;index<input.size();++index)
+      output[index]=input[index]/total;
+  }
+  else
+    output=input;
+}
+
+template<class T> void Histogram::normalize_pct(vector<T>& input){
+  double total=sum(input);
+  if(total){
+    typename vector<T>::iterator it;
+    for(it=input.begin();it!=input.end();++it)
+      *it=100.0*(*it)/total;
+  }
+}
+ 
+template<class T> double Histogram::rmse(const vector<T>& x, const vector<T>& y) const{
+  assert(x.size()==y.size());
+  assert(x.size());
+  double mse=0;
+  for(int isample=0;isample<x.size();++isample){
+    double e=x[isample]-y[isample];
+    mse+=e*e/x.size();
+  }
+  return sqrt(mse);
+}
+
+template<class T> double Histogram::correlation(const vector<T>& x, const vector<T>& y, int delay) const{
+  double meanX=0;
+  double meanY=0;
+  double varX=0;
+  double varY=0;
+  double sXY=0;
+  meanVar(x,meanX,varX);
+  meanVar(y,meanY,varY);
+  double denom = sqrt(varX*varY);
+  if(denom){
+    //Calculate the correlation series
+    sXY = 0;
+    for (int i=0;i<x.size();++i) {
+      int j = i + delay;
+      if (j < 0 || j >= y.size())
+        continue;
+      else{
+        assert(i>=0&&i<x.size());
+        assert(j>=0&&j<y.size());
+        sXY += (x[i] - meanX) * (y[j] - meanY);
+      }
+    }
+    double minSize=(x.size()<y.size())?x.size():y.size();
+    return(sXY / denom / (minSize-1));
+  }
+  else
+    return 0;
+}
+
+template<class T> double Histogram::cross_correlation(const vector<T>& x, const vector<T>& y, int maxdelay, vector<T>& z) const{
+  z.clear();
+  double sumCorrelation=0;
+  for (int delay=-maxdelay;delay<maxdelay;delay++) {
+    z.push_back(correlation(x,y,delay));
+    sumCorrelation+=z.back();
+  }
+  return sumCorrelation;
+}
+
+  template<class T> double Histogram::linear_regression(const vector<T>& x, const vector<T>& y, double &c0, double &c1) const{
+  assert(x.size()==y.size());
+  assert(x.size());
+  double cov00;
+  double cov01;
+  double  cov11;
+  double sumsq;
+  gsl_fit_linear(&(x[0]),1,&(y[0]),1,x.size(),&c0,&c1,&cov00,&cov01,&cov11,&sumsq);
+  return (1-sumsq/var(y)/(y.size()-1));
+}
+
+}
+
+
+//alternatively: use GNU scientific library:
+// gsl_stats_correlation (const double data1[], const size_t stride1, const double data2[], const size_t stride2, const size_t n)
+
+
+using namespace histogram;
+
+#endif /* _HISTOGRAM_H_ */
diff --git a/src/algorithms/Makefile.am b/src/algorithms/Makefile.am
new file mode 100644
index 0000000..acd551d
--- /dev/null
+++ b/src/algorithms/Makefile.am
@@ -0,0 +1,19 @@
+AM_LDFLAGS = $(GDAL_LDFLAGS) @AM_LDFLAGS@
+AM_CXXFLAGS = -I$(top_srcdir)/src $(GDAL_CFLAGS) @AM_CXXFLAGS@
+
+###############################################################################
+# THE LIBRARIES TO BUILD
+###############################################################################
+
+# the library names to build (note we are building static libs only)
+noinst_LIBRARIES = libalgorithms.a
+
+# where to install the headers on the system
+libalgorithms_adir = $(includedir)/algorithms
+
+# the list of header files that belong to the library (to be installed later)
+libalgorithms_a_HEADERS = Egcs.h  Filter2d.h  Filter.h  Histogram.h ConfusionMatrix.h myfann_cpp.h
+
+# the sources to add to the library and to add to the source distribution
+libalgorithms_a_SOURCES = $(libalgorithms_a_HEADERS) Egcs.cc  Filter2d.cc  Filter.cc  Histogram.cc ConfusionMatrix.cc
+###############################################################################
diff --git a/src/algorithms/Makefile.in b/src/algorithms/Makefile.in
new file mode 100644
index 0000000..cbca0ca
--- /dev/null
+++ b/src/algorithms/Makefile.in
@@ -0,0 +1,513 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+subdir = src/algorithms
+DIST_COMMON = $(libalgorithms_a_HEADERS) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_gdal.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LIBRARIES = $(noinst_LIBRARIES)
+AR = ar
+ARFLAGS = cru
+libalgorithms_a_AR = $(AR) $(ARFLAGS)
+libalgorithms_a_LIBADD =
+am__objects_1 =
+am_libalgorithms_a_OBJECTS = $(am__objects_1) Egcs.$(OBJEXT) \
+	Filter2d.$(OBJEXT) Filter.$(OBJEXT) Histogram.$(OBJEXT) \
+	ConfusionMatrix.$(OBJEXT)
+libalgorithms_a_OBJECTS = $(am_libalgorithms_a_OBJECTS)
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+	-o $@
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(libalgorithms_a_SOURCES)
+DIST_SOURCES = $(libalgorithms_a_SOURCES)
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(libalgorithms_adir)"
+HEADERS = $(libalgorithms_a_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_CXXFLAGS = -I$(top_srcdir)/src $(GDAL_CFLAGS) @AM_CXXFLAGS@
+AM_LDFLAGS = $(GDAL_LDFLAGS) @AM_LDFLAGS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FANN_CFLAGS = @FANN_CFLAGS@
+FANN_LIBS = @FANN_LIBS@
+FILECLASSES_OPT = @FILECLASSES_OPT@
+GDAL_CFLAGS = @GDAL_CFLAGS@
+GDAL_CONFIG = @GDAL_CONFIG@
+GDAL_DEP_LDFLAGS = @GDAL_DEP_LDFLAGS@
+GDAL_LDFLAGS = @GDAL_LDFLAGS@
+GDAL_OGR_ENABLED = @GDAL_OGR_ENABLED@
+GDAL_VERSION = @GDAL_VERSION@
+GREP = @GREP@
+GSL_CFLAGS = @GSL_CFLAGS@
+GSL_LIBS = @GSL_LIBS@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+
+###############################################################################
+# THE LIBRARIES TO BUILD
+###############################################################################
+
+# the library names to build (note we are building static libs only)
+noinst_LIBRARIES = libalgorithms.a
+
+# where to install the headers on the system
+libalgorithms_adir = $(includedir)/algorithms
+
+# the list of header files that belong to the library (to be installed later)
+libalgorithms_a_HEADERS = Egcs.h  Filter2d.h  Filter.h  Histogram.h ConfusionMatrix.h myfann_cpp.h
+
+# the sources to add to the library and to add to the source distribution
+libalgorithms_a_SOURCES = $(libalgorithms_a_HEADERS) Egcs.cc  Filter2d.cc  Filter.cc  Histogram.cc ConfusionMatrix.cc
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cc .o .obj
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/algorithms/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign src/algorithms/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLIBRARIES:
+	-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
+libalgorithms.a: $(libalgorithms_a_OBJECTS) $(libalgorithms_a_DEPENDENCIES) 
+	-rm -f libalgorithms.a
+	$(libalgorithms_a_AR) libalgorithms.a $(libalgorithms_a_OBJECTS) $(libalgorithms_a_LIBADD)
+	$(RANLIB) libalgorithms.a
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ConfusionMatrix.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Egcs.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Filter.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Filter2d.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Histogram.Po at am__quote@
+
+.cc.o:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+install-libalgorithms_aHEADERS: $(libalgorithms_a_HEADERS)
+	@$(NORMAL_INSTALL)
+	test -z "$(libalgorithms_adir)" || $(MKDIR_P) "$(DESTDIR)$(libalgorithms_adir)"
+	@list='$(libalgorithms_a_HEADERS)'; test -n "$(libalgorithms_adir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libalgorithms_adir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(libalgorithms_adir)" || exit $$?; \
+	done
+
+uninstall-libalgorithms_aHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(libalgorithms_a_HEADERS)'; test -n "$(libalgorithms_adir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(libalgorithms_adir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(libalgorithms_adir)" && rm -f $$files
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LIBRARIES) $(HEADERS)
+installdirs:
+	for dir in "$(DESTDIR)$(libalgorithms_adir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-libalgorithms_aHEADERS
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-libalgorithms_aHEADERS
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+	clean-noinstLIBRARIES ctags distclean distclean-compile \
+	distclean-generic distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-libalgorithms_aHEADERS install-man \
+	install-pdf install-pdf-am install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am uninstall-libalgorithms_aHEADERS
+
+###############################################################################
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/algorithms/myfann_cpp.h b/src/algorithms/myfann_cpp.h
new file mode 100644
index 0000000..323ed70
--- /dev/null
+++ b/src/algorithms/myfann_cpp.h
@@ -0,0 +1,3670 @@
+#ifndef FANN_CPP_H_INCLUDED
+#define FANN_CPP_H_INCLUDED
+
+/*
+ *
+ *  Fast Artificial Neural Network (fann) C++ Wrapper
+ *  Copyright (C) 2004-2006 created by freegoldbar (at) yahoo dot com
+ *
+ *  This wrapper is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This wrapper 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+/*
+ *  Title: FANN Wrapper for C++
+ *
+ *  Overview:
+ *
+ *  The Fann Wrapper for C++ provides two classes: <neural_net>
+ *  and <training_data>. To use the wrapper include
+ *  doublefann.h, floatfann.h or fixedfann.h before the
+ *  fann_cpp.h header file. To get started see xor_sample.cpp
+ *  in the examples directory. The license is LGPL. Copyright (C)
+ *  2004-2006 created by <freegoldbar at yahoo.com>.
+ *
+ *  Note:  Notes and differences from C API
+ *
+ *  -  The Fann Wrapper for C++ is a minimal wrapper without use of
+ *       templates or exception handling for efficient use in any environment.
+ *       Benefits include stricter type checking, simpler memory
+ *       management and possibly code completion in program editor.
+ *  -  Method names are the same as the function names in the C
+ *       API except the fann_ prefix has been removed. Enums in the
+ *       namespace are similarly defined without the FANN_ prefix.
+ *  -  The arguments to the methods are the same as the C API
+ *       except that the struct fann *ann/struct fann_train_data *data
+ *       arguments are encapsulated so they are not present in the
+ *       method signatures or are translated into class references.
+ *  -  The various create methods return a boolean set to true to
+ *       indicate that the neural network was created, false otherwise.
+ *       The same goes for the read_train_from_file method.
+ *  -  The neural network and training data is automatically cleaned
+ *       up in the destructors and create/read methods.
+ *  -  To make the destructors virtual define USE_VIRTUAL_DESTRUCTOR
+ *       before including the header file.
+ *  -  Additional methods are available on the training_data class to
+ *       give access to the underlying training data. They are get_input,
+ *       get_output and set_train_data. Finally fann_duplicate_train_data
+ *       has been replaced by a copy constructor.
+ *
+ *  Note: Changes
+ *
+ *  Version 2.1.0:
+ *     - General update to fann C library 2.1.0 with support for new functionality
+ *     - Due to changes in the C API the C++ API is not fully backward compatible:
+ *        The create methods have changed names and parameters.
+ *        The training callback function has different parameters and a set_callback.
+ *        Some <training_data> methods have updated names.
+ *        Get activation function and steepness is available for neurons, not layers.
+ *     - Extensions are now part of fann so there is no fann_extensions.h
+ *
+ *  Version 1.2.0:
+ *     - Changed char pointers to const std::string references
+ *     - Added const_casts where the C API required it
+ *     - Initialized enums from the C enums instead of numeric constants
+ *     - Added a method set_train_data that copies and allocates training
+ *     - data in a way that is compatible with the way the C API deallocates
+ *     - the data thus making it possible to change training data.
+ *     - The get_rprop_increase_factor method did not return its value
+ *
+ *  Version 1.0.0:
+ *     - Initial version
+ *
+ */
+
+#include <iostream>
+#include <stdarg.h>
+#include <string>
+#include <vector>
+#include <cassert>
+#include "Vector2d.h"
+
+/* Namespace: FANN
+    The FANN namespace groups the C++ wrapper definitions */
+namespace FANN
+{
+    /* Enum: error_function_enum
+	    Error function used during training.
+    	
+	    ERRORFUNC_LINEAR - Standard linear error function.
+	    ERRORFUNC_TANH - Tanh error function, usually better 
+		    but can require a lower learning rate. This error function agressively targets outputs that
+		    differ much from the desired, while not targetting outputs that only differ a little that much.
+		    This activation function is not recommended for cascade training and incremental training.
+
+	    See also:
+		    <neural_net::set_train_error_function>, <neural_net::get_train_error_function>
+    */
+    enum error_function_enum {
+        ERRORFUNC_LINEAR = FANN_ERRORFUNC_LINEAR,
+        ERRORFUNC_TANH
+    };
+
+    /* Enum: stop_function_enum
+	    Stop criteria used during training.
+
+	    STOPFUNC_MSE - Stop criteria is Mean Square Error (MSE) value.
+	    STOPFUNC_BIT - Stop criteria is number of bits that fail. The number of bits; means the
+		    number of output neurons which differ more than the bit fail limit 
+		    (see <neural_net::get_bit_fail_limit>, <neural_net::set_bit_fail_limit>). 
+		    The bits are counted in all of the training data, so this number can be higher than
+		    the number of training data.
+
+	    See also:
+		    <neural_net::set_train_stop_function>, <neural_net::get_train_stop_function>
+    */
+    enum stop_function_enum
+    {
+	    STOPFUNC_MSE = FANN_STOPFUNC_MSE,
+	    STOPFUNC_BIT
+    };
+
+    /* Enum: training_algorithm_enum
+	    The Training algorithms used when training on <training_data> with functions like
+	    <neural_net::train_on_data> or <neural_net::train_on_file>. The incremental training
+        looks alters the weights after each time it is presented an input pattern, while batch
+        only alters the weights once after it has been presented to all the patterns.
+
+	    TRAIN_INCREMENTAL -  Standard backpropagation algorithm, where the weights are 
+		    updated after each training pattern. This means that the weights are updated many 
+		    times during a single epoch. For this reason some problems, will train very fast with 
+		    this algorithm, while other more advanced problems will not train very well.
+	    TRAIN_BATCH -  Standard backpropagation algorithm, where the weights are updated after 
+		    calculating the mean square error for the whole training set. This means that the weights 
+		    are only updated once during a epoch. For this reason some problems, will train slower with 
+		    this algorithm. But since the mean square error is calculated more correctly than in 
+		    incremental training, some problems will reach a better solutions with this algorithm.
+	    TRAIN_RPROP - A more advanced batch training algorithm which achieves good results 
+		    for many problems. The RPROP training algorithm is adaptive, and does therefore not 
+		    use the learning_rate. Some other parameters can however be set to change the way the 
+		    RPROP algorithm works, but it is only recommended for users with insight in how the RPROP 
+		    training algorithm works. The RPROP training algorithm is described by 
+		    [Riedmiller and Braun, 1993], but the actual learning algorithm used here is the 
+		    iRPROP- training algorithm which is described by [Igel and Husken, 2000] which 
+    	    is an variety of the standard RPROP training algorithm.
+	    TRAIN_QUICKPROP - A more advanced batch training algorithm which achieves good results 
+		    for many problems. The quickprop training algorithm uses the learning_rate parameter 
+		    along with other more advanced parameters, but it is only recommended to change these 
+		    advanced parameters, for users with insight in how the quickprop training algorithm works.
+		    The quickprop training algorithm is described by [Fahlman, 1988].
+    	
+	    See also:
+		    <neural_net::set_training_algorithm>, <neural_net::get_training_algorithm>
+    */
+    enum training_algorithm_enum {
+        TRAIN_INCREMENTAL = FANN_TRAIN_INCREMENTAL,
+        TRAIN_BATCH,
+        TRAIN_RPROP,
+        TRAIN_QUICKPROP
+    };
+
+    /* Enum: activation_function_enum
+       
+	    The activation functions used for the neurons during training. The activation functions
+	    can either be defined for a group of neurons by <neural_net::set_activation_function_hidden>
+        and <neural_net::set_activation_function_output> or it can be defined for a single neuron by
+        <neural_net::set_activation_function>.
+
+	    The steepness of an activation function is defined in the same way by 
+	    <neural_net::set_activation_steepness_hidden>, <neural_net::set_activation_steepness_output>
+        and <neural_net::set_activation_steepness>.
+       
+       The functions are described with functions where:
+       * x is the input to the activation function,
+       * y is the output,
+       * s is the steepness and
+       * d is the derivation.
+
+       FANN_LINEAR - Linear activation function. 
+         * span: -inf < y < inf
+	     * y = x*s, d = 1*s
+	     * Can NOT be used in fixed point.
+
+       FANN_THRESHOLD - Threshold activation function.
+	     * x < 0 -> y = 0, x >= 0 -> y = 1
+	     * Can NOT be used during training.
+
+       FANN_THRESHOLD_SYMMETRIC - Threshold activation function.
+	     * x < 0 -> y = 0, x >= 0 -> y = 1
+	     * Can NOT be used during training.
+
+       FANN_SIGMOID - Sigmoid activation function.
+	     * One of the most used activation functions.
+	     * span: 0 < y < 1
+	     * y = 1/(1 + exp(-2*s*x))
+	     * d = 2*s*y*(1 - y)
+
+       FANN_SIGMOID_STEPWISE - Stepwise linear approximation to sigmoid.
+	     * Faster than sigmoid but a bit less precise.
+
+       FANN_SIGMOID_SYMMETRIC - Symmetric sigmoid activation function, aka. tanh.
+	     * One of the most used activation functions.
+	     * span: -1 < y < 1
+	     * y = tanh(s*x) = 2/(1 + exp(-2*s*x)) - 1
+	     * d = s*(1-(y*y))
+
+       FANN_SIGMOID_SYMMETRIC - Stepwise linear approximation to symmetric sigmoid.
+	     * Faster than symmetric sigmoid but a bit less precise.
+
+       FANN_GAUSSIAN - Gaussian activation function.
+	     * 0 when x = -inf, 1 when x = 0 and 0 when x = inf
+	     * span: 0 < y < 1
+	     * y = exp(-x*s*x*s)
+	     * d = -2*x*s*y*s
+
+       FANN_GAUSSIAN_SYMMETRIC - Symmetric gaussian activation function.
+	     * -1 when x = -inf, 1 when x = 0 and 0 when x = inf
+	     * span: -1 < y < 1
+	     * y = exp(-x*s*x*s)*2-1
+	     * d = -2*x*s*(y+1)*s
+    	 
+       FANN_ELLIOT - Fast (sigmoid like) activation function defined by David Elliott
+	     * span: 0 < y < 1
+	     * y = ((x*s) / 2) / (1 + |x*s|) + 0.5
+	     * d = s*1/(2*(1+|x*s|)*(1+|x*s|))
+    	 
+       FANN_ELLIOT_SYMMETRIC - Fast (symmetric sigmoid like) activation function defined by David Elliott
+	     * span: -1 < y < 1   
+	     * y = (x*s) / (1 + |x*s|)
+	     * d = s*1/((1+|x*s|)*(1+|x*s|))
+
+	    FANN_LINEAR_PIECE - Bounded linear activation function.
+	     * span: 0 < y < 1
+	     * y = x*s, d = 1*s
+    	 
+	    FANN_LINEAR_PIECE_SYMMETRIC - Bounded Linear activation function.
+	     * span: -1 < y < 1
+	     * y = x*s, d = 1*s
+	
+        FANN_SIN_SYMMETRIC - Periodical sinus activation function.
+         * span: -1 <= y <= 1
+         * y = sin(x*s)
+         * d = s*cos(x*s)
+         
+        FANN_COS_SYMMETRIC - Periodical cosinus activation function.
+         * span: -1 <= y <= 1
+         * y = cos(x*s)
+         * d = s*-sin(x*s)
+    	 
+	    See also:
+		    <neural_net::set_activation_function_hidden>,
+		    <neural_net::set_activation_function_output>
+    */
+    enum activation_function_enum {
+        LINEAR = FANN_LINEAR,
+        THRESHOLD,
+        THRESHOLD_SYMMETRIC,
+        SIGMOID,
+        SIGMOID_STEPWISE,
+        SIGMOID_SYMMETRIC,
+        SIGMOID_SYMMETRIC_STEPWISE,
+        GAUSSIAN,
+        GAUSSIAN_SYMMETRIC,
+        GAUSSIAN_STEPWISE,
+        ELLIOT,
+        ELLIOT_SYMMETRIC,
+        LINEAR_PIECE,
+        LINEAR_PIECE_SYMMETRIC,
+	    SIN_SYMMETRIC,
+	    COS_SYMMETRIC
+    };
+
+    /* Enum: network_type_enum
+
+        Definition of network types used by <neural_net::get_network_type>
+
+        LAYER - Each layer only has connections to the next layer
+        SHORTCUT - Each layer has connections to all following layers
+
+       See Also:
+          <neural_net::get_network_type>, <fann_get_network_type>
+
+       This enumeration appears in FANN >= 2.1.0
+    */
+    enum network_type_enum
+    {
+        LAYER = FANN_NETTYPE_LAYER,
+        SHORTCUT
+    };
+
+    /* Type: connection
+
+        Describes a connection between two neurons and its weight
+
+        from_neuron - Unique number used to identify source neuron
+        to_neuron - Unique number used to identify destination neuron
+        weight - The numerical value of the weight
+
+        See Also:
+            <neural_net::get_connection_array>, <neural_net::set_weight_array>
+
+       This structure appears in FANN >= 2.1.0
+    */
+    typedef struct fann_connection connection;
+
+    /* Forward declaration of class neural_net and training_data */
+    class neural_net;
+    class training_data;
+
+    /* Type: callback_type
+       This callback function can be called during training when using <neural_net::train_on_data>, 
+       <neural_net::train_on_file> or <neural_net::cascadetrain_on_data>.
+    	
+        >typedef int (*callback_type) (neural_net &net, training_data &train,
+        >    unsigned int max_epochs, unsigned int epochs_between_reports,
+        >    float desired_error, unsigned int epochs, void *user_data);
+    	
+	    The callback can be set by using <neural_net::set_callback> and is very usefull for doing custom 
+	    things during training. It is recommended to use this function when implementing custom 
+	    training procedures, or when visualizing the training in a GUI etc. The parameters which the
+	    callback function takes is the parameters given to the <neural_net::train_on_data>, plus an epochs
+	    parameter which tells how many epochs the training have taken so far.
+    	
+	    The callback function should return an integer, if the callback function returns -1, the training
+	    will terminate.
+    	
+	    Example of a callback function that prints information to cout:
+            >int print_callback(FANN::neural_net &net, FANN::training_data &train,
+            >    unsigned int max_epochs, unsigned int epochs_between_reports,
+            >    float desired_error, unsigned int epochs, void *user_data)
+            >{
+            >    cout << "Epochs     " << setw(8) << epochs << ". "
+            >         << "Current Error: " << left << net.get_MSE() << right << endl;
+            >    return 0;
+            >}
+    	
+	    See also:
+		    <neural_net::set_callback>, <fann_callback_type>
+     */ 
+    typedef int (*callback_type) (neural_net &net, training_data &train,
+        unsigned int max_epochs, unsigned int epochs_between_reports,
+        float desired_error, unsigned int epochs, void *user_data);
+
+    /*************************************************************************/
+
+    /* Class: training_data
+
+        Encapsulation of a training data set <struct fann_train_data> and
+        associated C API functions.
+    */
+    class training_data
+    {
+    public:
+        /* Constructor: training_data
+        
+            Default constructor creates an empty neural net.
+            Use <read_train_from_file>, <set_train_data> or <create_train_from_callback> to initialize.
+        */
+        training_data() : train_data(NULL)
+        {
+        }
+
+        /* Constructor: training_data
+        
+            Copy constructor constructs a copy of the training data.
+            Corresponds to the C API <fann_duplicate_train_data> function.
+        */
+        training_data(const training_data &data)
+        {
+            destroy_train();
+            if (data.train_data != NULL)
+            {
+                train_data = fann_duplicate_train_data(data.train_data);
+            }
+        }
+
+        /* Destructor: ~training_data
+
+            Provides automatic cleanup of data.
+            Define USE_VIRTUAL_DESTRUCTOR if you need the destructor to be virtual.
+
+            See also:
+                <destroy>
+        */
+#ifdef USE_VIRTUAL_DESTRUCTOR
+        virtual
+#endif
+        ~training_data()
+        {
+            destroy_train();
+        }
+
+        /* Method: destroy
+        
+            Destructs the training data. Called automatically by the destructor.
+
+            See also:
+                <~training_data>
+        */
+        void destroy_train()
+        {
+            if (train_data != NULL)
+            {
+                fann_destroy_train(train_data);
+                train_data = NULL;
+            }
+        }
+
+        /* Method: read_train_from_file
+           Reads a file that stores training data.
+           
+           The file must be formatted like:
+           >num_train_data num_input num_output
+           >inputdata seperated by space
+           >outputdata seperated by space
+           >
+           >.
+           >.
+           >.
+           >
+           >inputdata seperated by space
+           >outputdata seperated by space
+           
+           See also:
+   	        <neural_net::train_on_data>, <save_train>, <fann_read_train_from_file>
+
+            This function appears in FANN >= 1.0.0
+        */ 
+        bool read_train_from_file(const std::string &filename)
+        {
+            destroy_train();
+            train_data = fann_read_train_from_file(filename.c_str());
+            return (train_data != NULL);
+        }
+
+        /* Method: save_train
+           
+           Save the training structure to a file, with the format as specified in <read_train_from_file>
+
+           Return:
+           The function returns true on success and false on failure.
+              
+           See also:
+   	        <read_train_from_file>, <save_train_to_fixed>, <fann_save_train>
+        	
+           This function appears in FANN >= 1.0.0.   	
+         */ 
+        bool save_train(const std::string &filename)
+        {
+            if (train_data == NULL)
+            {
+                return false;
+            }
+            if (fann_save_train(train_data, filename.c_str()) == -1)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        /* Method: save_train_to_fixed
+           
+           Saves the training structure to a fixed point data file.
+         
+           This function is very usefull for testing the quality of a fixed point network.
+           
+           Return:
+           The function returns true on success and false on failure.
+           
+           See also:
+   	        <save_train>, <fann_save_train_to_fixed>
+
+           This function appears in FANN >= 1.0.0.   	
+         */ 
+        bool save_train_to_fixed(const std::string &filename, unsigned int decimal_point)
+        {
+            if (train_data == NULL)
+            {
+                return false;
+            }
+            if (fann_save_train_to_fixed(train_data, filename.c_str(), decimal_point) == -1)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        /* Method: shuffle_train_data
+           
+           Shuffles training data, randomizing the order. 
+           This is recommended for incremental training, while it have no influence during batch training.
+           
+           This function appears in FANN >= 1.1.0.
+         */ 
+        void shuffle_train_data()
+        {
+            if (train_data != NULL)
+            {
+                fann_shuffle_train_data(train_data);
+            }
+        }
+
+        /* Method: merge_train_data
+           
+           Merges the data into the data contained in the <training_data>.
+           
+           This function appears in FANN >= 1.1.0.
+         */ 
+        void merge_train_data(const training_data &data)
+        {
+            fann_train_data *new_data = fann_merge_train_data(train_data, data.train_data);
+            if (new_data != NULL)
+            {
+                destroy_train();
+                train_data = new_data;
+            }
+        }
+
+        /* Method: length_train_data
+           
+           Returns the number of training patterns in the <training_data>.
+
+           See also:
+           <num_input_train_data>, <num_output_train_data>, <fann_length_train_data>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        unsigned int length_train_data()
+        {
+            if (train_data == NULL)
+            {
+                return 0;
+            }
+            else
+            {
+                return fann_length_train_data(train_data);
+            }
+        }
+
+        /* Method: num_input_train_data
+
+           Returns the number of inputs in each of the training patterns in the <training_data>.
+           
+           See also:
+           <num_output_train_data>, <length_train_data>, <fann_num_input_train_data>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        unsigned int num_input_train_data()
+        {
+            if (train_data == NULL)
+            {
+                return 0;
+            }
+            else
+            {
+                return fann_num_input_train_data(train_data);
+            }
+        }
+
+        /* Method: num_output_train_data
+           
+           Returns the number of outputs in each of the training patterns in the <struct fann_train_data>.
+           
+           See also:
+           <num_input_train_data>, <length_train_data>, <fann_num_output_train_data>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        unsigned int num_output_train_data()
+        {
+            if (train_data == NULL)
+            {
+                return 0;
+            }
+            else
+            {
+                return fann_num_output_train_data(train_data);
+            }
+        }
+
+        /* Grant access to the encapsulated data since many situations
+            and applications creates the data from sources other than files
+            or uses the training data for testing and related functions */
+
+        /* Method: get_input
+        
+            Returns:
+                A pointer to the array of input training data
+
+            See also:
+                <get_output>, <set_train_data>
+        */
+        fann_type **get_input()
+        {
+            if (train_data == NULL)
+            {
+                return NULL;
+            }
+            else
+            {
+                return train_data->input;
+            }
+        }
+
+        /* Method: get_output
+        
+            Returns:
+                A pointer to the array of output training data
+
+            See also:
+                <get_input>, <set_train_data>
+        */
+        fann_type **get_output()
+        {
+            if (train_data == NULL)
+            {
+                return NULL;
+            }
+            else
+            {
+                return train_data->output;
+            }
+        }
+
+        /* Method: set_train_data
+
+            Set the training data to the input and output data provided.
+
+            A copy of the data is made so there are no restrictions on the
+            allocation of the input/output data and the caller is responsible
+            for the deallocation of the data pointed to by input and output.
+
+           Parameters:
+             num_data      - The number of training data
+             num_input     - The number of inputs per training data
+             num_output    - The number of ouputs per training data
+             input      - The set of inputs (a pointer to an array of pointers to arrays of floating point data)
+             output     - The set of desired outputs (a pointer to an array of pointers to arrays of floating point data)
+
+            See also:
+                <get_input>, <get_output>
+        */
+        void set_train_data(unsigned int num_data,
+            unsigned int num_input, fann_type **input,
+            unsigned int num_output, fann_type **output)
+        {
+            // Uses the allocation method used in fann
+            struct fann_train_data *data =
+                (struct fann_train_data *)malloc(sizeof(struct fann_train_data));
+            data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
+            data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
+
+            data->num_data = num_data;
+            data->num_input = num_input;
+            data->num_output = num_output;
+
+        	fann_type *data_input = (fann_type *)calloc(num_input*num_data, sizeof(fann_type));
+        	fann_type *data_output = (fann_type *)calloc(num_output*num_data, sizeof(fann_type));
+
+            for (unsigned int i = 0; i < num_data; ++i)
+            {
+                data->input[i] = data_input;
+                data_input += num_input;
+                for (unsigned int j = 0; j < num_input; ++j)
+                {
+                    data->input[i][j] = input[i][j];
+                }
+                data->output[i] = data_output;
+		        data_output += num_output;
+                for (unsigned int j = 0; j < num_output; ++j)
+                {
+                    data->output[i][j] = output[i][j];
+                }
+            }
+            set_train_data(data);
+        }
+      
+      
+
+      void set_train_data(const std::vector< std::vector<fann_type> >& input,
+                          const std::vector< std::vector<fann_type> >& output)
+        {
+          unsigned int num_data=input.size();
+          assert(num_data);
+          assert(input.size()==output.size());
+          unsigned int num_input=input[0].size();
+          unsigned int num_output=output[0].size();
+          
+            // Uses the allocation method used in fann
+            struct fann_train_data *data =
+                (struct fann_train_data *)malloc(sizeof(struct fann_train_data));
+            data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
+            data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
+
+            data->num_data = num_data;
+            data->num_input = num_input;
+            data->num_output = num_output;
+
+        	fann_type *data_input = (fann_type *)calloc(num_input*num_data, sizeof(fann_type));
+        	fann_type *data_output = (fann_type *)calloc(num_output*num_data, sizeof(fann_type));
+
+            for (unsigned int i = 0; i < num_data; ++i)
+            {
+                data->input[i] = data_input;
+                data_input += num_input;
+                for (unsigned int j = 0; j < num_input; ++j)
+                {
+                    data->input[i][j] = input[i][j];
+                }
+                data->output[i] = data_output;
+		        data_output += num_output;
+                for (unsigned int j = 0; j < num_output; ++j)
+                {
+                    data->output[i][j] = output[i][j];
+                }
+            }
+            set_train_data(data);
+        }
+      
+      void set_train_data(const std::vector< std::vector< std::vector<fann_type> > >& input, unsigned int num_data)
+      {
+          assert(num_data);
+          assert(input.size());
+          unsigned int num_class=input.size();
+          assert(input[0].size());
+          unsigned int num_input=input[0][0].size();
+          unsigned int num_output=num_class;
+          //test
+//           unsigned int num_output=1;
+          
+            // Uses the allocation method used in fann
+            struct fann_train_data *data =
+                (struct fann_train_data *)malloc(sizeof(struct fann_train_data));
+            data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
+            data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
+
+            data->num_data = num_data;
+            data->num_input = num_input;
+            data->num_output = num_output;
+
+            fann_type *data_input = (fann_type *)calloc(num_input*num_data, sizeof(fann_type));
+            fann_type *data_output = (fann_type *)calloc(num_output*num_data, sizeof(fann_type));
+
+            unsigned int isample=0;
+            for(int iclass=0;iclass<num_class;++iclass){
+              for(int csample=0;csample<input[iclass].size();++csample){
+                data->input[isample] = data_input;
+                data_input += num_input;
+                for(int iband=0;iband<input[iclass][csample].size();++iband){
+                  assert(input[iclass][csample].size()==num_input);
+                  data->input[isample][iband] = input[iclass][csample][iband];
+                }
+                data->output[isample] = data_output;
+                data_output += num_output;
+                for(int ic=0;ic<num_output;++ic){
+                  //for single neuron output:
+//                   data->output[isample][ic]=2.0/(num_class-1)*(iclass-(num_class-1)/2.0);
+                  if(ic==iclass)
+                    data->output[isample][ic] = 1;
+                  else
+                    data->output[isample][ic] = -1;
+                }
+                ++isample;
+              }
+            }
+            set_train_data(data);
+      }
+
+      void set_train_data(const std::vector< Vector2d<fann_type> >& input, unsigned int num_data)
+      {
+          assert(num_data);
+          assert(input.size());
+          unsigned int num_class=input.size();
+          assert(input[0].size());
+          unsigned int num_input=input[0][0].size();
+          unsigned int num_output=num_class;
+          //test
+//           unsigned int num_output=1;
+          
+            // Uses the allocation method used in fann
+            struct fann_train_data *data =
+                (struct fann_train_data *)malloc(sizeof(struct fann_train_data));
+            data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
+            data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
+
+            data->num_data = num_data;
+            data->num_input = num_input;
+            data->num_output = num_output;
+
+            fann_type *data_input = (fann_type *)calloc(num_input*num_data, sizeof(fann_type));
+            fann_type *data_output = (fann_type *)calloc(num_output*num_data, sizeof(fann_type));
+
+            unsigned int isample=0;
+            for(int iclass=0;iclass<num_class;++iclass){
+              for(int csample=0;csample<input[iclass].size();++csample){
+                data->input[isample] = data_input;
+                data_input += num_input;
+                for(int iband=0;iband<input[iclass][csample].size();++iband){
+                  assert(input[iclass][csample].size()==num_input);
+                  data->input[isample][iband] = input[iclass][csample][iband];
+                }
+                data->output[isample] = data_output;
+                data_output += num_output;
+                for(int ic=0;ic<num_output;++ic){
+                  //for single neuron output:
+//                   data->output[isample][ic]=2.0/(num_class-1)*(iclass-(num_class-1)/2.0);
+                  if(ic==iclass)
+                    data->output[isample][ic] = 1;
+                  else
+                    data->output[isample][ic] = -1;
+                }
+                ++isample;
+              }
+            }
+            set_train_data(data);
+      }
+      
+
+private:
+        /* Set the training data to the struct fann_training_data pointer.
+            The struct has to be allocated with malloc to be compatible
+            with fann_destroy. */
+        void set_train_data(struct fann_train_data *data)
+        {
+            destroy_train();
+            train_data = data;
+        }
+
+public:
+        /*********************************************************************/
+
+        /* Method: create_train_from_callback
+           Creates the training data struct from a user supplied function.
+           As the training data are numerable (data 1, data 2...), the user must write
+           a function that receives the number of the training data set (input,output)
+           and returns the set.
+
+           Parameters:
+             num_data      - The number of training data
+             num_input     - The number of inputs per training data
+             num_output    - The number of ouputs per training data
+             user_function - The user suplied function
+
+           Parameters for the user function:
+             num        - The number of the training data set
+             num_input  - The number of inputs per training data
+             num_output - The number of ouputs per training data
+             input      - The set of inputs
+             output     - The set of desired outputs
+          
+           See also:
+             <training_data::read_train_from_file>, <neural_net::train_on_data>,
+             <fann_create_train_from_callback>
+
+            This function appears in FANN >= 2.1.0
+        */ 
+        void create_train_from_callback(unsigned int num_data,
+                                                  unsigned int num_input,
+                                                  unsigned int num_output,
+                                                  void (FANN_API *user_function)( unsigned int,
+                                                                         unsigned int,
+                                                                         unsigned int,
+                                                                         fann_type * ,
+                                                                         fann_type * ))
+        {
+            destroy_train();
+            train_data = fann_create_train_from_callback(num_data, num_input, num_output, user_function);
+        }
+
+        /* Method: scale_input_train_data
+           
+           Scales the inputs in the training data to the specified range.
+
+           See also:
+   	        <scale_output_train_data>, <scale_train_data>, <fann_scale_input_train_data>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        void scale_input_train_data(fann_type new_min, fann_type new_max)
+        {
+            if (train_data != NULL)
+            {
+                fann_scale_input_train_data(train_data, new_min, new_max);
+            }
+        }
+
+        /* Method: scale_output_train_data
+           
+           Scales the outputs in the training data to the specified range.
+
+           See also:
+   	        <scale_input_train_data>, <scale_train_data>, <fann_scale_output_train_data>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        void scale_output_train_data(fann_type new_min, fann_type new_max)
+        {
+            if (train_data != NULL)
+            {
+                fann_scale_output_train_data(train_data, new_min, new_max);
+            }
+        }
+
+        /* Method: scale_train_data
+           
+           Scales the inputs and outputs in the training data to the specified range.
+           
+           See also:
+   	        <scale_output_train_data>, <scale_input_train_data>, <fann_scale_train_data>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        void scale_train_data(fann_type new_min, fann_type new_max)
+        {
+            if (train_data != NULL)
+            {
+                fann_scale_train_data(train_data, new_min, new_max);
+            }
+        }
+
+        /* Method: subset_train_data
+           
+           Changes the training data to a subset, starting at position *pos* 
+           and *length* elements forward. Use the copy constructor to work
+           on a new copy of the training data.
+           
+            >FANN::training_data full_data_set;
+            >full_data_set.read_train_from_file("somefile.train");
+            >FANN::training_data *small_data_set = new FANN::training_data(full_data_set);
+            >small_data_set->subset_train_data(0, 2); // Only use first two
+            >// Use small_data_set ...
+            >delete small_data_set;
+
+           See also:
+   	        <fann_subset_train_data>
+
+           This function appears in FANN >= 2.0.0.
+         */
+        void subset_train_data(unsigned int pos, unsigned int length)
+        {
+            if (train_data != NULL)
+            {
+                struct fann_train_data *temp = fann_subset_train_data(train_data, pos, length);
+                destroy_train();
+                train_data = temp;
+            }
+        }
+
+        /*********************************************************************/
+
+    protected:
+        /* The neural_net class has direct access to the training data */
+        friend class neural_net;
+
+        /* Pointer to the encapsulated training data */
+        struct fann_train_data* train_data;
+    };
+
+    /*************************************************************************/
+
+    /* Class: neural_net
+
+        Encapsulation of a neural network <struct fann> and
+        associated C API functions.
+    */
+    class neural_net
+    {
+    public:
+        /* Constructor: neural_net
+        
+            Default constructor creates an empty neural net.
+            Use one of the create functions to create the neural network.
+
+            See also:
+		        <create_standard>, <create_sparse>, <create_shortcut>,
+		        <create_standard_array>, <create_sparse_array>, <create_shortcut_array>
+        */
+        neural_net() : ann(NULL)
+        {
+        }
+
+        /* Destructor: ~neural_net
+
+            Provides automatic cleanup of data.
+            Define USE_VIRTUAL_DESTRUCTOR if you need the destructor to be virtual.
+
+            See also:
+                <destroy>
+        */
+#ifdef USE_VIRTUAL_DESTRUCTOR
+        virtual
+#endif
+        ~neural_net()
+        {
+            destroy();
+        }
+
+        /* Method: destroy
+        
+            Destructs the entire network. Called automatically by the destructor.
+
+            See also:
+                <~neural_net>
+        */
+        void destroy()
+        {
+            if (ann != NULL)
+            {
+                user_context *user_data = static_cast<user_context *>(fann_get_user_data(ann));
+                if (user_data != NULL)
+                    delete user_data;
+
+                fann_destroy(ann);
+                ann = NULL;
+            }
+        }
+
+        /* Method: create_standard
+        	
+	        Creates a standard fully connected backpropagation neural network.
+
+	        There will be a bias neuron in each layer (except the output layer),
+	        and this bias neuron will be connected to all neurons in the next layer.
+	        When running the network, the bias nodes always emits 1.
+        	
+	        Parameters:
+		        num_layers - The total number of layers including the input and the output layer.
+		        ... - Integer values determining the number of neurons in each layer starting with the 
+			        input layer and ending with the output layer.
+        			
+	        Returns:
+		        Boolean true if the network was created, false otherwise.
+
+            Example:
+                >const unsigned int num_layers = 3;
+                >const unsigned int num_input = 2;
+                >const unsigned int num_hidden = 3;
+                >const unsigned int num_output = 1;
+                >
+                >FANN::neural_net net;
+                >net.create_standard(num_layers, num_input, num_hidden, num_output);
+
+	        See also:
+		        <create_standard_array>, <create_sparse>, <create_shortcut>,
+		        <fann_create_standard_array>
+
+	        This function appears in FANN >= 2.0.0.
+        */ 
+        bool create_standard(unsigned int num_layers, ...)
+        {
+            va_list layers;
+            va_start(layers, num_layers);
+            bool status = create_standard_array(num_layers,
+                reinterpret_cast<const unsigned int *>(layers));
+            va_end(layers);
+            return status;
+        }
+
+        /* Method: create_standard_array
+
+           Just like <create_standard>, but with an array of layer sizes
+           instead of individual parameters.
+
+	        See also:
+		        <create_standard>, <create_sparse>, <create_shortcut>,
+		        <fann_create_standard>
+
+	        This function appears in FANN >= 2.0.0.
+        */ 
+        bool create_standard_array(unsigned int num_layers, const unsigned int * layers)
+        {
+            destroy();
+            ann = fann_create_standard_array(num_layers, layers);
+            return (ann != NULL);
+        }
+
+        /* Method: create_sparse
+
+	        Creates a standard backpropagation neural network, which is not fully connected.
+
+	        Parameters:
+		        connection_rate - The connection rate controls how many connections there will be in the
+   			        network. If the connection rate is set to 1, the network will be fully
+   			        connected, but if it is set to 0.5 only half of the connections will be set.
+			        A connection rate of 1 will yield the same result as <fann_create_standard>
+		        num_layers - The total number of layers including the input and the output layer.
+		        ... - Integer values determining the number of neurons in each layer starting with the 
+			        input layer and ending with the output layer.
+        			
+	        Returns:
+		        Boolean true if the network was created, false otherwise.
+
+	        See also:
+		        <create_standard>, <create_sparse_array>, <create_shortcut>,
+		        <fann_create_sparse>
+
+	        This function appears in FANN >= 2.0.0.
+        */
+        bool create_sparse(float connection_rate, unsigned int num_layers, ...)
+        {
+            va_list layers;
+            va_start(layers, num_layers);
+            bool status = create_sparse_array(connection_rate, num_layers,
+                reinterpret_cast<const unsigned int *>(layers));
+            va_end(layers);
+            return status;
+        }
+
+        /* Method: create_sparse_array
+           Just like <create_sparse>, but with an array of layer sizes
+           instead of individual parameters.
+
+           See <create_sparse> for a description of the parameters.
+
+	        See also:
+		        <create_standard>, <create_sparse>, <create_shortcut>,
+		        <fann_create_sparse_array>
+
+	        This function appears in FANN >= 2.0.0.
+        */
+        bool create_sparse_array(float connection_rate,
+            unsigned int num_layers, const unsigned int * layers)
+        {
+            destroy();
+            ann = fann_create_sparse_array(connection_rate, num_layers, layers);
+            return (ann != NULL);
+        }
+
+        /* Method: create_shortcut
+
+	        Creates a standard backpropagation neural network, which is not fully connected and which
+	        also has shortcut connections.
+
+ 	        Shortcut connections are connections that skip layers. A fully connected network with shortcut 
+	        connections, is a network where all neurons are connected to all neurons in later layers. 
+	        Including direct connections from the input layer to the output layer.
+
+	        See <create_standard> for a description of the parameters.
+
+	        See also:
+		        <create_standard>, <create_sparse>, <create_shortcut_array>,
+		        <fann_create_shortcut>
+
+	        This function appears in FANN >= 2.0.0.
+        */ 
+        bool create_shortcut(unsigned int num_layers, ...)
+        {
+            va_list layers;
+            va_start(layers, num_layers);
+            bool status = create_shortcut_array(num_layers,
+                reinterpret_cast<const unsigned int *>(layers));
+            va_end(layers);
+            return status;
+        }
+
+        /* Method: create_shortcut_array
+
+           Just like <create_shortcut>, but with an array of layer sizes
+           instead of individual parameters.
+
+	        See <create_standard_array> for a description of the parameters.
+
+	        See also:
+		        <create_standard>, <create_sparse>, <create_shortcut>,
+		        <fann_create_shortcut_array>
+
+	        This function appears in FANN >= 2.0.0.
+        */
+        bool create_shortcut_array(unsigned int num_layers,
+            const unsigned int * layers)
+        {
+            destroy();
+            ann = fann_create_shortcut_array(num_layers, layers);
+            return (ann != NULL);
+        }
+
+        /* Method: run
+
+	        Will run input through the neural network, returning an array of outputs, the number of which being 
+	        equal to the number of neurons in the output layer.
+
+	        See also:
+		        <test>, <fann_run>
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        fann_type* run(fann_type *input)
+        {
+            if (ann == NULL)
+            {
+                return NULL;
+            }
+//             for(int iband=0;iband<get_num_input();++iband)
+//               std::cout << (input)[iband] << " ";
+//             std::cout << std::endl;
+            return fann_run(ann, input);
+        }
+
+      std::vector<fann_type> run(std::vector<fann_type> input)
+        {
+          std::vector<fann_type> vresult;
+            if (ann == NULL)
+            {
+                return vresult;
+            }
+            vresult.resize(get_num_output());
+            fann_type* result;
+            result=fann_run(ann,&(input[0]));
+            for(int iout=0;iout<get_num_output();++iout)
+              vresult[iout]=*(result++);
+            return vresult;
+        }
+
+        /* Method: randomize_weights
+
+	        Give each connection a random weight between *min_weight* and *max_weight*
+           
+	        From the beginning the weights are random between -0.1 and 0.1.
+
+	        See also:
+		        <init_weights>, <fann_randomize_weights>
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        void randomize_weights(fann_type min_weight, fann_type max_weight)
+        {
+            if (ann != NULL)
+            {
+                fann_randomize_weights(ann, min_weight, max_weight);
+            }
+        }
+
+        /* Method: init_weights
+
+  	        Initialize the weights using Widrow + Nguyen's algorithm.
+        	
+ 	        This function behaves similarly to fann_randomize_weights. It will use the algorithm developed 
+	        by Derrick Nguyen and Bernard Widrow to set the weights in such a way 
+	        as to speed up training. This technique is not always successful, and in some cases can be less 
+	        efficient than a purely random initialization.
+
+	        The algorithm requires access to the range of the input data (ie, largest and smallest input), 
+	        and therefore accepts a second argument, data, which is the training data that will be used to 
+	        train the network.
+
+	        See also:
+		        <randomize_weights>, <training_data::read_train_from_file>,
+                <fann_init_weights>
+
+	        This function appears in FANN >= 1.1.0.
+        */ 
+        void init_weights(const training_data &data)
+        {
+            if ((ann != NULL) && (data.train_data != NULL))
+            {
+                fann_init_weights(ann, data.train_data);
+            }
+        }
+
+        /* Method: print_connections
+
+	        Will print the connections of the ann in a compact matrix, for easy viewing of the internals 
+	        of the ann.
+
+	        The output from fann_print_connections on a small (2 2 1) network trained on the xor problem
+	        >Layer / Neuron 012345
+	        >L   1 / N    3 BBa...
+	        >L   1 / N    4 BBA...
+	        >L   1 / N    5 ......
+	        >L   2 / N    6 ...BBA
+	        >L   2 / N    7 ......
+        		  
+	        This network have five real neurons and two bias neurons. This gives a total of seven neurons 
+	        named from 0 to 6. The connections between these neurons can be seen in the matrix. "." is a 
+	        place where there is no connection, while a character tells how strong the connection is on a 
+	        scale from a-z. The two real neurons in the hidden layer (neuron 3 and 4 in layer 1) has 
+	        connection from the three neurons in the previous layer as is visible in the first two lines. 
+	        The output neuron (6) has connections form the three neurons in the hidden layer 3 - 5 as is 
+	        visible in the fourth line.
+
+	        To simplify the matrix output neurons is not visible as neurons that connections can come from, 
+	        and input and bias neurons are not visible as neurons that connections can go to.
+
+	        This function appears in FANN >= 1.2.0.
+        */ 
+        void print_connections()
+        {
+            if (ann != NULL)
+            {
+                fann_print_connections(ann);
+            }
+        }
+
+        /* Method: create_from_file
+           
+           Constructs a backpropagation neural network from a configuration file,
+           which have been saved by <save>.
+           
+           See also:
+   	        <save>, <save_to_fixed>, <fann_create_from_file>
+           	
+           This function appears in FANN >= 1.0.0.
+         */
+        bool create_from_file(const std::string &configuration_file)
+        {
+            destroy();
+            ann = fann_create_from_file(configuration_file.c_str());
+            return (ann != NULL);
+        }
+
+        /* Method: save
+
+           Save the entire network to a configuration file.
+           
+           The configuration file contains all information about the neural network and enables 
+           <create_from_file> to create an exact copy of the neural network and all of the
+           parameters associated with the neural network.
+           
+           These two parameters (<set_callback>, <set_error_log>) are *NOT* saved 
+           to the file because they cannot safely be ported to a different location. Also temporary
+           parameters generated during training like <get_MSE> is not saved.
+           
+           Return:
+           The function returns 0 on success and -1 on failure.
+           
+           See also:
+            <create_from_file>, <save_to_fixed>, <fann_save>
+
+           This function appears in FANN >= 1.0.0.
+         */
+        bool save(const std::string &configuration_file)
+        {
+            if (ann == NULL)
+            {
+                return false;
+            }
+            if (fann_save(ann, configuration_file.c_str()) == -1)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        /* Method: save_to_fixed
+
+           Saves the entire network to a configuration file.
+           But it is saved in fixed point format no matter which
+           format it is currently in.
+
+           This is usefull for training a network in floating points,
+           and then later executing it in fixed point.
+
+           The function returns the bit position of the fix point, which
+           can be used to find out how accurate the fixed point network will be.
+           A high value indicates high precision, and a low value indicates low
+           precision.
+
+           A negative value indicates very low precision, and a very
+           strong possibility for overflow.
+           (the actual fix point will be set to 0, since a negative
+           fix point does not make sence).
+
+           Generally, a fix point lower than 6 is bad, and should be avoided.
+           The best way to avoid this, is to have less connections to each neuron,
+           or just less neurons in each layer.
+
+           The fixed point use of this network is only intended for use on machines that
+           have no floating point processor, like an iPAQ. On normal computers the floating
+           point version is actually faster.
+
+           See also:
+            <create_from_file>, <save>, <fann_save_to_fixed>
+
+           This function appears in FANN >= 1.0.0.
+        */ 
+        int save_to_fixed(const std::string &configuration_file)
+        {
+            int fixpoint = 0;
+            if (ann != NULL)
+            {
+                fixpoint = fann_save_to_fixed(ann, configuration_file.c_str());
+            }
+            return fixpoint;
+        }
+
+#ifndef FIXEDFANN
+        /* Method: train
+
+           Train one iteration with a set of inputs, and a set of desired outputs.
+           This training is always incremental training (see <FANN::training_algorithm_enum>),
+           since only one pattern is presented.
+           
+           Parameters:
+   	        ann - The neural network structure
+   	        input - an array of inputs. This array must be exactly <fann_get_num_input> long.
+   	        desired_output - an array of desired outputs. This array must be exactly <fann_get_num_output> long.
+           	
+   	        See also:
+   		        <train_on_data>, <train_epoch>, <fann_train>
+           	
+   	        This function appears in FANN >= 1.0.0.
+         */ 
+        void train(fann_type *input, fann_type *desired_output)
+        {
+            if (ann != NULL)
+            {
+                fann_train(ann, input, desired_output);
+            }
+        }
+
+        /* Method: train_epoch
+            Train one epoch with a set of training data.
+           
+            Train one epoch with the training data stored in data. One epoch is where all of 
+            the training data is considered exactly once.
+
+	        This function returns the MSE error as it is calculated either before or during 
+	        the actual training. This is not the actual MSE after the training epoch, but since 
+	        calculating this will require to go through the entire training set once more, it is 
+	        more than adequate to use this value during training.
+
+	        The training algorithm used by this function is chosen by the <fann_set_training_algorithm> 
+	        function.
+        	
+	        See also:
+		        <train_on_data>, <test_data>, <fann_train_epoch>
+        		
+	        This function appears in FANN >= 1.2.0.
+         */ 
+        float train_epoch(const training_data &data)
+        {
+            float mse = 0.0f;
+            if ((ann != NULL) && (data.train_data != NULL))
+            {
+                mse = fann_train_epoch(ann, data.train_data);
+            }
+            return mse;
+        }
+
+        /* Method: train_on_data
+
+           Trains on an entire dataset, for a period of time. 
+           
+           This training uses the training algorithm chosen by <set_training_algorithm>,
+           and the parameters set for these training algorithms.
+           
+           Parameters:
+   		        ann - The neural network
+   		        data - The data, which should be used during training
+   		        max_epochs - The maximum number of epochs the training should continue
+   		        epochs_between_reports - The number of epochs between printing a status report to stdout.
+   			        A value of zero means no reports should be printed.
+   		        desired_error - The desired <get_MSE> or <get_bit_fail>, depending on which stop function
+   			        is chosen by <set_train_stop_function>.
+
+	        Instead of printing out reports every epochs_between_reports, a callback function can be called 
+	        (see <set_callback>).
+        	
+	        See also:
+		        <train_on_file>, <train_epoch>, <fann_train_on_data>
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        void train_on_data(const training_data &data, unsigned int max_epochs,
+            unsigned int epochs_between_reports, float desired_error)
+        {
+            if ((ann != NULL) && (data.train_data != NULL))
+            {
+                fann_train_on_data(ann, data.train_data, max_epochs,
+                    epochs_between_reports, desired_error);
+            }
+        }
+
+        /* Method: train_on_file
+           
+           Does the same as <train_on_data>, but reads the training data directly from a file.
+           
+           See also:
+   		        <train_on_data>, <fann_train_on_file>
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        void train_on_file(const std::string &filename, unsigned int max_epochs,
+            unsigned int epochs_between_reports, float desired_error)
+        {
+            if (ann != NULL)
+            {
+                fann_train_on_file(ann, filename.c_str(),
+                    max_epochs, epochs_between_reports, desired_error);
+            }
+        }
+#endif /* NOT FIXEDFANN */
+
+        /* Method: test
+
+           Test with a set of inputs, and a set of desired outputs.
+           This operation updates the mean square error, but does not
+           change the network in any way.
+           
+           See also:
+   		        <test_data>, <train>, <fann_test>
+           
+           This function appears in FANN >= 1.0.0.
+        */ 
+        fann_type * test(fann_type *input, fann_type *desired_output)
+        {
+            fann_type * output = NULL;
+            if (ann != NULL)
+            {
+                output = fann_test(ann, input, desired_output);
+            }
+            return output;
+        }
+
+        /* Method: test_data
+          
+           Test a set of training data and calculates the MSE for the training data. 
+           
+           This function updates the MSE and the bit fail values.
+           
+           See also:
+ 	        <test>, <get_MSE>, <get_bit_fail>, <fann_test_data>
+
+	        This function appears in FANN >= 1.2.0.
+         */ 
+        float test_data(const training_data &data)
+        {
+            float mse = 0.0f;
+            if ((ann != NULL) && (data.train_data != NULL))
+            {
+                mse = fann_test_data(ann, data.train_data);
+            }
+            return mse;
+        }
+
+        /* Method: get_MSE
+           Reads the mean square error from the network.
+           
+           Reads the mean square error from the network. This value is calculated during 
+           training or testing, and can therefore sometimes be a bit off if the weights 
+           have been changed since the last calculation of the value.
+           
+           See also:
+   	        <test_data>, <fann_get_MSE>
+
+	        This function appears in FANN >= 1.1.0.
+         */ 
+        float get_MSE()
+        {
+            float mse = 0.0f;
+            if (ann != NULL)
+            {
+                mse = fann_get_MSE(ann);
+            }
+            return mse;
+        }
+
+        /* Method: reset_MSE
+
+           Resets the mean square error from the network.
+   
+           This function also resets the number of bits that fail.
+           
+           See also:
+   	        <get_MSE>, <get_bit_fail_limit>, <fann_reset_MSE>
+           
+            This function appears in FANN >= 1.1.0
+         */ 
+        void reset_MSE()
+        {
+            if (ann != NULL)
+            {
+                fann_reset_MSE(ann);
+            }
+        }
+
+        /* Method: set_callback
+           
+           Sets the callback function for use during training. The user_data is passed to
+           the callback. It can point to arbitrary data that the callback might require and
+           can be NULL if it is not used.
+         	
+           See <FANN::callback_type> for more information about the callback function.
+           
+           The default callback function simply prints out some status information.
+
+           This function appears in FANN >= 2.0.0.
+         */
+        void set_callback(callback_type callback, void *user_data)
+        {
+            if (ann != NULL)
+            {
+                // Allocated data is also deleted in the destroy method called by the destructor
+                user_context *user_instance = static_cast<user_context *>(fann_get_user_data(ann));
+                if (user_instance != NULL)
+                    delete user_instance;
+
+                user_instance = new user_context();
+                user_instance->user_callback = callback;
+                user_instance->user_data = user_data;
+                user_instance->net = this;
+                fann_set_user_data(ann, user_instance);
+
+                if (callback != NULL)
+                    fann_set_callback(ann, &FANN::neural_net::internal_callback);
+                else
+                    fann_set_callback(ann, NULL);
+            }
+        }
+
+        /* Method: print_parameters
+
+  	        Prints all of the parameters and options of the neural network
+
+            See also:
+                <fann_print_parameters>
+
+	        This function appears in FANN >= 1.2.0.
+        */ 
+        void print_parameters()
+        {
+            if (ann != NULL)
+            {
+                fann_print_parameters(ann);
+            }
+        }
+
+        /* Method: get_training_algorithm
+
+           Return the training algorithm as described by <FANN::training_algorithm_enum>.
+           This training algorithm is used by <train_on_data> and associated functions.
+           
+           Note that this algorithm is also used during <cascadetrain_on_data>, although only
+           FANN::TRAIN_RPROP and FANN::TRAIN_QUICKPROP is allowed during cascade training.
+           
+           The default training algorithm is FANN::TRAIN_RPROP.
+           
+           See also:
+            <set_training_algorithm>, <FANN::training_algorithm_enum>,
+            <fann_get_training_algorithm>
+
+           This function appears in FANN >= 1.0.0.   	
+         */ 
+        training_algorithm_enum get_training_algorithm()
+        {
+            fann_train_enum training_algorithm = FANN_TRAIN_INCREMENTAL;
+            if (ann != NULL)
+            {
+                training_algorithm = fann_get_training_algorithm(ann);
+            }
+            return static_cast<training_algorithm_enum>(training_algorithm);
+        }
+
+        /* Method: set_training_algorithm
+
+           Set the training algorithm.
+           
+           More info available in <get_training_algorithm>
+
+           This function appears in FANN >= 1.0.0.   	
+         */ 
+        void set_training_algorithm(training_algorithm_enum training_algorithm)
+        {
+            if (ann != NULL)
+            {
+                fann_set_training_algorithm(ann,
+					static_cast<fann_train_enum>(training_algorithm));
+            }
+        }
+
+        /* Method: get_learning_rate
+
+           Return the learning rate.
+           
+           The learning rate is used to determine how aggressive training should be for some of the
+           training algorithms (FANN::TRAIN_INCREMENTAL, FANN::TRAIN_BATCH, FANN::TRAIN_QUICKPROP).
+           Do however note that it is not used in FANN::TRAIN_RPROP.
+           
+           The default learning rate is 0.7.
+           
+           See also:
+   	        <set_learning_rate>, <set_training_algorithm>,
+            <fann_get_learning_rate>
+           
+           This function appears in FANN >= 1.0.0.   	
+         */ 
+        float get_learning_rate()
+        {
+            float learning_rate = 0.0f;
+            if (ann != NULL)
+            {
+                learning_rate = fann_get_learning_rate(ann);
+            }
+            return learning_rate;
+        }
+
+        /* Method: set_learning_rate
+
+           Set the learning rate.
+           
+           More info available in <get_learning_rate>
+
+           This function appears in FANN >= 1.0.0.   	
+         */ 
+        void set_learning_rate(float learning_rate)
+        {
+            if (ann != NULL)
+            {
+                fann_set_learning_rate(ann, learning_rate);
+            }
+        }
+
+        /*************************************************************************************************************/
+
+        /* Method: get_activation_function
+
+           Get the activation function for neuron number *neuron* in layer number *layer*, 
+           counting the input layer as layer 0. 
+           
+           It is not possible to get activation functions for the neurons in the input layer.
+           
+           Information about the individual activation functions is available at <FANN::activation_function_enum>.
+
+           Returns:
+            The activation function for the neuron or -1 if the neuron is not defined in the neural network.
+           
+           See also:
+   	        <set_activation_function_layer>, <set_activation_function_hidden>,
+   	        <set_activation_function_output>, <set_activation_steepness>,
+            <set_activation_function>, <fann_get_activation_function>
+
+           This function appears in FANN >= 2.1.0
+         */ 
+        activation_function_enum get_activation_function(int layer, int neuron)
+        {
+            unsigned int activation_function = 0;
+            if (ann != NULL)
+            {
+                activation_function = fann_get_activation_function(ann, layer, neuron);
+            }
+            return static_cast<activation_function_enum>(activation_function);
+        }
+
+        /* Method: set_activation_function
+
+           Set the activation function for neuron number *neuron* in layer number *layer*, 
+           counting the input layer as layer 0. 
+           
+           It is not possible to set activation functions for the neurons in the input layer.
+           
+           When choosing an activation function it is important to note that the activation 
+           functions have different range. FANN::SIGMOID is e.g. in the 0 - 1 range while 
+           FANN::SIGMOID_SYMMETRIC is in the -1 - 1 range and FANN::LINEAR is unbound.
+           
+           Information about the individual activation functions is available at <FANN::activation_function_enum>.
+           
+           The default activation function is FANN::SIGMOID_STEPWISE.
+           
+           See also:
+   	        <set_activation_function_layer>, <set_activation_function_hidden>,
+   	        <set_activation_function_output>, <set_activation_steepness>,
+            <get_activation_function>, <fann_set_activation_function>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        void set_activation_function(activation_function_enum activation_function, int layer, int neuron)
+        {
+            if (ann != NULL)
+            {
+                fann_set_activation_function(ann,
+					static_cast<fann_activationfunc_enum>(activation_function), layer, neuron);
+            }
+        }
+
+        /* Method: set_activation_function_layer
+
+           Set the activation function for all the neurons in the layer number *layer*, 
+           counting the input layer as layer 0. 
+           
+           It is not possible to set activation functions for the neurons in the input layer.
+
+           See also:
+   	        <set_activation_function>, <set_activation_function_hidden>,
+   	        <set_activation_function_output>, <set_activation_steepness_layer>,
+            <fann_set_activation_function_layer>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        void set_activation_function_layer(activation_function_enum activation_function, int layer)
+        {
+            if (ann != NULL)
+            {
+                fann_set_activation_function_layer(ann,
+					static_cast<fann_activationfunc_enum>(activation_function), layer);
+            }
+        }
+
+        /* Method: set_activation_function_hidden
+
+           Set the activation function for all of the hidden layers.
+
+           See also:
+   	        <set_activation_function>, <set_activation_function_layer>,
+   	        <set_activation_function_output>, <set_activation_steepness_hidden>,
+            <fann_set_activation_function_hidden>
+
+           This function appears in FANN >= 1.0.0.
+         */ 
+        void set_activation_function_hidden(activation_function_enum activation_function)
+        {
+            if (ann != NULL)
+            {
+                fann_set_activation_function_hidden(ann,
+					static_cast<fann_activationfunc_enum>(activation_function));
+            }
+        }
+
+        /* Method: set_activation_function_output
+
+           Set the activation function for the output layer.
+
+           See also:
+   	        <set_activation_function>, <set_activation_function_layer>,
+   	        <set_activation_function_hidden>, <set_activation_steepness_output>,
+            <fann_set_activation_function_output>
+
+           This function appears in FANN >= 1.0.0.
+         */ 
+        void set_activation_function_output(activation_function_enum activation_function)
+        {
+            if (ann != NULL)
+            {
+                fann_set_activation_function_output(ann,
+					static_cast<fann_activationfunc_enum>(activation_function));
+            }
+        }
+
+        /* Method: get_activation_steepness
+
+           Get the activation steepness for neuron number *neuron* in layer number *layer*, 
+           counting the input layer as layer 0. 
+           
+           It is not possible to get activation steepness for the neurons in the input layer.
+           
+           The steepness of an activation function says something about how fast the activation function 
+           goes from the minimum to the maximum. A high value for the activation function will also
+           give a more agressive training.
+           
+           When training neural networks where the output values should be at the extremes (usually 0 and 1, 
+           depending on the activation function), a steep activation function can be used (e.g. 1.0).
+           
+           The default activation steepness is 0.5.
+           
+           Returns:
+            The activation steepness for the neuron or -1 if the neuron is not defined in the neural network.
+           
+           See also:
+   	        <set_activation_steepness_layer>, <set_activation_steepness_hidden>,
+   	        <set_activation_steepness_output>, <set_activation_function>,
+            <set_activation_steepness>, <fann_get_activation_steepness>
+
+           This function appears in FANN >= 2.1.0
+         */ 
+        fann_type get_activation_steepness(int layer, int neuron)
+        {
+            fann_type activation_steepness = 0;
+            if (ann != NULL)
+            {
+                activation_steepness = fann_get_activation_steepness(ann, layer, neuron);
+            }
+            return activation_steepness;
+        }
+
+        /* Method: set_activation_steepness
+
+           Set the activation steepness for neuron number *neuron* in layer number *layer*, 
+           counting the input layer as layer 0. 
+           
+           It is not possible to set activation steepness for the neurons in the input layer.
+           
+           The steepness of an activation function says something about how fast the activation function 
+           goes from the minimum to the maximum. A high value for the activation function will also
+           give a more agressive training.
+           
+           When training neural networks where the output values should be at the extremes (usually 0 and 1, 
+           depending on the activation function), a steep activation function can be used (e.g. 1.0).
+           
+           The default activation steepness is 0.5.
+           
+           See also:
+   	        <set_activation_steepness_layer>, <set_activation_steepness_hidden>,
+   	        <set_activation_steepness_output>, <set_activation_function>,
+            <get_activation_steepness>, <fann_set_activation_steepness>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        void set_activation_steepness(fann_type steepness, int layer, int neuron)
+        {
+            if (ann != NULL)
+            {
+                fann_set_activation_steepness(ann, steepness, layer, neuron);
+            }
+        }
+
+        /* Method: set_activation_steepness_layer
+
+           Set the activation steepness all of the neurons in layer number *layer*, 
+           counting the input layer as layer 0. 
+           
+           It is not possible to set activation steepness for the neurons in the input layer.
+           
+           See also:
+   	        <set_activation_steepness>, <set_activation_steepness_hidden>,
+   	        <set_activation_steepness_output>, <set_activation_function_layer>,
+            <fann_set_activation_steepness_layer>
+
+           This function appears in FANN >= 2.0.0.
+         */ 
+        void set_activation_steepness_layer(fann_type steepness, int layer)
+        {
+            if (ann != NULL)
+            {
+                fann_set_activation_steepness_layer(ann, steepness, layer);
+            }
+        }
+
+        /* Method: set_activation_steepness_hidden
+
+           Set the steepness of the activation steepness in all of the hidden layers.
+
+           See also:
+   	        <set_activation_steepness>, <set_activation_steepness_layer>,
+   	        <set_activation_steepness_output>, <set_activation_function_hidden>,
+            <fann_set_activation_steepness_hidden>
+
+           This function appears in FANN >= 1.2.0.
+         */ 
+        void set_activation_steepness_hidden(fann_type steepness)
+        {
+            if (ann != NULL)
+            {
+                fann_set_activation_steepness_hidden(ann, steepness);
+            }
+        }
+
+        /* Method: set_activation_steepness_output
+
+           Set the steepness of the activation steepness in the output layer.
+
+           See also:
+   	        <set_activation_steepness>, <set_activation_steepness_layer>,
+   	        <set_activation_steepness_hidden>, <set_activation_function_output>,
+            <fann_set_activation_steepness_output>
+
+           This function appears in FANN >= 1.2.0.
+         */ 
+        void set_activation_steepness_output(fann_type steepness)
+        {
+            if (ann != NULL)
+            {
+                fann_set_activation_steepness_output(ann, steepness);
+            }
+        }
+
+        /*************************************************************************************************************/
+
+        /* Method: get_train_error_function
+
+           Returns the error function used during training.
+
+           The error functions is described further in <FANN::error_function_enum>
+           
+           The default error function is FANN::ERRORFUNC_TANH
+           
+           See also:
+   	        <set_train_error_function>, <fann_get_train_error_function>
+              
+           This function appears in FANN >= 1.2.0.
+          */ 
+        error_function_enum get_train_error_function()
+        {
+            fann_errorfunc_enum train_error_function = FANN_ERRORFUNC_LINEAR;
+            if (ann != NULL)
+            {
+                train_error_function = fann_get_train_error_function(ann);
+            }
+            return static_cast<error_function_enum>(train_error_function);
+        }
+
+        /* Method: set_train_error_function
+
+           Set the error function used during training.
+           
+           The error functions is described further in <FANN::error_function_enum>
+           
+           See also:
+   	        <get_train_error_function>, <fann_set_train_error_function>
+              
+           This function appears in FANN >= 1.2.0.
+         */ 
+        void set_train_error_function(error_function_enum train_error_function)
+        {
+            if (ann != NULL)
+            {
+                fann_set_train_error_function(ann,
+					static_cast<fann_errorfunc_enum>(train_error_function));
+            }
+        }
+
+        /* Method: get_quickprop_decay
+
+           The decay is a small negative valued number which is the factor that the weights 
+           should become smaller in each iteration during quickprop training. This is used 
+           to make sure that the weights do not become too high during training.
+           
+           The default decay is -0.0001.
+           
+           See also:
+   	        <set_quickprop_decay>, <fann_get_quickprop_decay>
+
+           This function appears in FANN >= 1.2.0.
+         */
+        float get_quickprop_decay()
+        {
+            float quickprop_decay = 0.0f;
+            if (ann != NULL)
+            {
+                quickprop_decay = fann_get_quickprop_decay(ann);
+            }
+            return quickprop_decay;
+        }
+
+        /* Method: set_quickprop_decay
+           
+           Sets the quickprop decay factor.
+           
+           See also:
+   	        <get_quickprop_decay>, <fann_set_quickprop_decay>
+
+           This function appears in FANN >= 1.2.0.
+        */ 
+        void set_quickprop_decay(float quickprop_decay)
+        {
+            if (ann != NULL)
+            {
+                fann_set_quickprop_decay(ann, quickprop_decay);
+            }
+        }
+
+        /* Method: get_quickprop_mu
+
+           The mu factor is used to increase and decrease the step-size during quickprop training. 
+           The mu factor should always be above 1, since it would otherwise decrease the step-size 
+           when it was suppose to increase it.
+           
+           The default mu factor is 1.75. 
+           
+           See also:
+   	        <set_quickprop_mu>, <fann_get_quickprop_mu>
+
+           This function appears in FANN >= 1.2.0.
+        */ 
+        float get_quickprop_mu()
+        {
+            float quickprop_mu = 0.0f;
+            if (ann != NULL)
+            {
+                quickprop_mu = fann_get_quickprop_mu(ann);
+            }
+            return quickprop_mu;
+        }
+
+        /* Method: set_quickprop_mu
+
+            Sets the quickprop mu factor.
+           
+           See also:
+   	        <get_quickprop_mu>, <fann_set_quickprop_mu>
+
+           This function appears in FANN >= 1.2.0.
+        */ 
+        void set_quickprop_mu(float quickprop_mu)
+        {
+            if (ann != NULL)
+            {
+                fann_set_quickprop_mu(ann, quickprop_mu);
+            }
+        }
+
+        /* Method: get_rprop_increase_factor
+
+           The increase factor is a value larger than 1, which is used to 
+           increase the step-size during RPROP training.
+
+           The default increase factor is 1.2.
+           
+           See also:
+   	        <set_rprop_increase_factor>, <fann_get_rprop_increase_factor>
+
+           This function appears in FANN >= 1.2.0.
+        */ 
+        float get_rprop_increase_factor()
+        {
+            float factor = 0.0f;
+            if (ann != NULL)
+            {
+                factor = fann_get_rprop_increase_factor(ann);
+            }
+            return factor;
+        }
+
+        /* Method: set_rprop_increase_factor
+
+           The increase factor used during RPROP training.
+
+           See also:
+   	        <get_rprop_increase_factor>, <fann_set_rprop_increase_factor>
+
+           This function appears in FANN >= 1.2.0.
+        */ 
+        void set_rprop_increase_factor(float rprop_increase_factor)
+        {
+            if (ann != NULL)
+            {
+                fann_set_rprop_increase_factor(ann, rprop_increase_factor);
+            }
+        }
+
+        /* Method: get_rprop_decrease_factor
+
+           The decrease factor is a value smaller than 1, which is used to decrease the step-size during RPROP training.
+
+           The default decrease factor is 0.5.
+
+           See also:
+            <set_rprop_decrease_factor>, <fann_get_rprop_decrease_factor>
+
+           This function appears in FANN >= 1.2.0.
+        */ 
+        float get_rprop_decrease_factor()
+        {
+            float factor = 0.0f;
+            if (ann != NULL)
+            {
+                factor = fann_get_rprop_decrease_factor(ann);
+            }
+            return factor;
+        }
+
+        /* Method: set_rprop_decrease_factor
+
+           The decrease factor is a value smaller than 1, which is used to decrease the step-size during RPROP training.
+
+           See also:
+            <get_rprop_decrease_factor>, <fann_set_rprop_decrease_factor>
+
+           This function appears in FANN >= 1.2.0.
+        */
+        void set_rprop_decrease_factor(float rprop_decrease_factor)
+        {
+            if (ann != NULL)
+            {
+                fann_set_rprop_decrease_factor(ann, rprop_decrease_factor);
+            }
+        }
+
+        /* Method: get_rprop_delta_min
+
+           The minimum step-size is a small positive number determining how small the minimum step-size may be.
+
+           The default value delta min is 0.0.
+
+           See also:
+   	        <set_rprop_delta_min>, <fann_get_rprop_delta_min>
+           	
+           This function appears in FANN >= 1.2.0.
+        */ 
+        float get_rprop_delta_min()
+        {
+            float delta = 0.0f;
+            if (ann != NULL)
+            {
+                delta = fann_get_rprop_delta_min(ann);
+            }
+            return delta;
+        }
+
+        /* Method: set_rprop_delta_min
+
+           The minimum step-size is a small positive number determining how small the minimum step-size may be.
+
+           See also:
+   	        <get_rprop_delta_min>, <fann_set_rprop_delta_min>
+           	
+           This function appears in FANN >= 1.2.0.
+        */ 
+        void set_rprop_delta_min(float rprop_delta_min)
+        {
+            if (ann != NULL)
+            {
+                fann_set_rprop_delta_min(ann, rprop_delta_min);
+            }
+        }
+
+        /* Method: get_rprop_delta_max
+
+           The maximum step-size is a positive number determining how large the maximum step-size may be.
+
+           The default delta max is 50.0.
+
+           See also:
+   	        <set_rprop_delta_max>, <get_rprop_delta_min>, <fann_get_rprop_delta_max>
+
+           This function appears in FANN >= 1.2.0.
+        */ 
+        float get_rprop_delta_max()
+        {
+            float delta = 0.0f;
+            if (ann != NULL)
+            {
+                delta = fann_get_rprop_delta_max(ann);
+            }
+            return delta;
+        }
+
+        /* Method: set_rprop_delta_max
+
+           The maximum step-size is a positive number determining how large the maximum step-size may be.
+
+           See also:
+   	        <get_rprop_delta_max>, <get_rprop_delta_min>, <fann_set_rprop_delta_max>
+
+           This function appears in FANN >= 1.2.0.
+        */
+        void set_rprop_delta_max(float rprop_delta_max)
+        {
+            if (ann != NULL)
+            {
+                fann_set_rprop_delta_max(ann, rprop_delta_max);
+            }
+        }
+
+        /* Method: get_num_input
+
+           Get the number of input neurons.
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        unsigned int get_num_input()
+        {
+            unsigned int num_input = 0;
+            if (ann != NULL)
+            {
+                num_input = fann_get_num_input(ann);
+            }
+            return num_input;
+        }
+
+        /* Method: get_num_output
+
+           Get the number of output neurons.
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        unsigned int get_num_output()
+        {
+            unsigned int num_output = 0;
+            if (ann != NULL)
+            {
+                num_output = fann_get_num_output(ann);
+            }
+            return num_output;
+        }
+
+        /* Method: get_total_neurons
+
+           Get the total number of neurons in the entire network. This number does also include the 
+	        bias neurons, so a 2-4-2 network has 2+4+2 +2(bias) = 10 neurons.
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        unsigned int get_total_neurons()
+        {
+            if (ann == NULL)
+            {
+                return 0;
+            }
+            return fann_get_total_neurons(ann);
+        }
+
+        /* Method: get_total_connections
+
+           Get the total number of connections in the entire network.
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        unsigned int get_total_connections()
+        {
+            if (ann == NULL)
+            {
+                return 0;
+            }
+            return fann_get_total_connections(ann);
+        }
+
+#ifdef FIXEDFANN
+        /* Method: get_decimal_point
+
+	        Returns the position of the decimal point in the ann.
+
+	        This function is only available when the ANN is in fixed point mode.
+
+	        The decimal point is described in greater detail in the tutorial <Fixed Point Usage>.
+
+	        See also:
+		        <Fixed Point Usage>, <get_multiplier>, <save_to_fixed>,
+                <training_data::save_train_to_fixed>, <fann_get_decimal_point>
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        unsigned int get_decimal_point()
+        {
+            if (ann == NULL)
+            {
+                return 0;
+            }
+            return fann_get_decimal_point(ann);
+        }
+
+        /* Method: get_multiplier
+
+            Returns the multiplier that fix point data is multiplied with.
+
+	        This function is only available when the ANN is in fixed point mode.
+
+	        The multiplier is the used to convert between floating point and fixed point notation. 
+	        A floating point number is multiplied with the multiplier in order to get the fixed point
+	        number and visa versa.
+
+	        The multiplier is described in greater detail in the tutorial <Fixed Point Usage>.
+
+	        See also:
+		        <Fixed Point Usage>, <get_decimal_point>, <save_to_fixed>,
+                <training_data::save_train_to_fixed>, <fann_get_multiplier>
+
+	        This function appears in FANN >= 1.0.0.
+        */ 
+        unsigned int get_multiplier()
+        {
+            if (ann == NULL)
+            {
+                return 0;
+            }
+            return fann_get_multiplier(ann);
+        }
+#endif /* FIXEDFANN */
+
+        /*********************************************************************/
+
+        /* Method: get_network_type
+
+            Get the type of neural network it was created as.
+
+	        Returns:
+                The neural network type from enum <FANN::network_type_enum>
+
+            See Also:
+                <fann_get_network_type>
+
+           This function appears in FANN >= 2.1.0
+        */
+        network_type_enum get_network_type()
+        {
+            fann_nettype_enum network_type = FANN_NETTYPE_LAYER;
+            if (ann != NULL)
+            {
+                network_type = fann_get_network_type(ann);
+            }
+            return static_cast<network_type_enum>(network_type);
+        }
+
+        /* Method: get_connection_rate
+
+            Get the connection rate used when the network was created
+
+	        Returns:
+                The connection rate
+
+            See also:
+                <fann_get_connection_rate>
+
+           This function appears in FANN >= 2.1.0
+        */
+        float get_connection_rate()
+        {
+            if (ann == NULL)
+            {
+                return 0;
+            }
+            return fann_get_connection_rate(ann);
+        }
+
+        /* Method: get_num_layers
+
+            Get the number of layers in the network
+
+	        Returns:
+		        The number of layers in the neural network
+
+            See also:
+                <fann_get_num_layers>
+
+           This function appears in FANN >= 2.1.0
+        */
+        unsigned int get_num_layers()
+        {
+            if (ann == NULL)
+            {
+                return 0;
+            }
+            return fann_get_num_layers(ann);
+        }
+
+        /* Method: get_layer_array
+
+            Get the number of neurons in each layer in the network.
+
+            Bias is not included so the layers match the create methods.
+
+            The layers array must be preallocated to at least
+            sizeof(unsigned int) * get_num_layers() long.
+
+            See also:
+                <fann_get_layer_array>
+
+           This function appears in FANN >= 2.1.0
+        */
+        void get_layer_array(unsigned int *layers)
+        {
+            if (ann != NULL)
+            {
+                fann_get_layer_array(ann, layers);
+            }
+        }
+
+        void get_layer_array(std::vector<unsigned int> vlayers)
+        {
+          vlayers.clear();
+          if (ann != NULL){
+            vlayers.resize(get_num_layers());
+            unsigned int* layers=(unsigned int *)calloc(get_num_layers(),sizeof(unsigned int));
+            fann_get_layer_array(ann, layers);
+            for(int ilayer=0;ilayer<get_num_layers();++ilayer)
+              vlayers[ilayer]=*(layers++);
+          }
+        }
+
+        /* Method: get_bias_array
+
+            Get the number of bias in each layer in the network.
+
+            The bias array must be preallocated to at least
+            sizeof(unsigned int) * get_num_layers() long.
+
+            See also:
+                <fann_get_bias_array>
+
+            This function appears in FANN >= 2.1.0
+        */
+        void get_bias_array(unsigned int *bias)
+        {
+            if (ann != NULL)
+            {
+                fann_get_bias_array(ann, bias);
+            }
+        }
+
+        /* Method: get_connection_array
+
+            Get the connections in the network.
+
+            The connections array must be preallocated to at least
+            sizeof(struct fann_connection) * get_total_connections() long.
+
+            See also:
+                <fann_get_connection_array>
+
+           This function appears in FANN >= 2.1.0
+        */
+        void get_connection_array(connection *connections)
+        {
+            if (ann != NULL)
+            {
+                fann_get_connection_array(ann, connections);
+            }
+        }
+
+      void get_connection_array(std::vector<connection>& convector)
+        {
+          convector.clear();
+          if (ann != NULL)
+            {
+              convector.resize(get_total_connections());
+              connection* connections=(connection*)calloc(get_total_connections(),sizeof(connection));
+              fann_get_connection_array(ann, connections);
+              for(int icon=0;icon<get_total_connections();++icon)
+                convector[icon]=*(connections++);
+            }
+        }
+
+        /* Method: set_weight_array
+
+            Set connections in the network.
+
+            Only the weights can be changed, connections and weights are ignored
+            if they do not already exist in the network.
+
+            The array must have sizeof(struct fann_connection) * num_connections size.
+
+            See also:
+                <fann_set_weight_array>
+
+           This function appears in FANN >= 2.1.0
+        */
+      void set_weight_array(connection *connections, unsigned int num_connections)
+        {
+            if (ann != NULL)
+            {
+                fann_set_weight_array(ann, connections, num_connections);
+            }
+        }
+
+      void set_weight_array(std::vector<connection> convector)
+        {
+            if (ann != NULL)
+            {
+              unsigned int num_connections=convector.size();
+              connection* connections=(connection*)calloc(num_connections,sizeof(connection));
+              connections=&(convector[0]);
+              fann_set_weight_array(ann, connections, num_connections);
+            }
+        }
+
+        /* Method: set_weight
+
+            Set a connection in the network.
+
+            Only the weights can be changed. The connection/weight is
+            ignored if it does not already exist in the network.
+
+            See also:
+                <fann_set_weight>
+
+           This function appears in FANN >= 2.1.0
+        */
+        void set_weight(unsigned int from_neuron, unsigned int to_neuron, fann_type weight)
+        {
+            if (ann != NULL)
+            {
+                fann_set_weight(ann, from_neuron, to_neuron, weight);
+            }
+        }
+
+        /*********************************************************************/
+
+        /* Method: get_learning_momentum
+
+           Get the learning momentum.
+           
+           The learning momentum can be used to speed up FANN::TRAIN_INCREMENTAL training.
+           A too high momentum will however not benefit training. Setting momentum to 0 will
+           be the same as not using the momentum parameter. The recommended value of this parameter
+           is between 0.0 and 1.0.
+
+           The default momentum is 0.
+           
+           See also:
+           <set_learning_momentum>, <set_training_algorithm>
+
+           This function appears in FANN >= 2.0.0.   	
+         */ 
+        float get_learning_momentum()
+        {
+            float learning_momentum = 0.0f;
+            if (ann != NULL)
+            {
+                learning_momentum = fann_get_learning_momentum(ann);
+            }
+            return learning_momentum;
+        }
+
+        /* Method: set_learning_momentum
+
+           Set the learning momentum.
+
+           More info available in <get_learning_momentum>
+
+           This function appears in FANN >= 2.0.0.   	
+         */ 
+        void set_learning_momentum(float learning_momentum)
+        {
+            if (ann != NULL)
+            {
+                fann_set_learning_momentum(ann, learning_momentum);
+            }
+        }
+
+        /* Method: get_train_stop_function
+
+           Returns the the stop function used during training.
+           
+           The stop function is described further in <FANN::stop_function_enum>
+           
+           The default stop function is FANN::STOPFUNC_MSE
+           
+           See also:
+   	        <get_train_stop_function>, <get_bit_fail_limit>
+              
+           This function appears in FANN >= 2.0.0.
+         */ 
+        stop_function_enum get_train_stop_function()
+        {
+            enum fann_stopfunc_enum stopfunc = FANN_STOPFUNC_MSE;
+            if (ann != NULL)
+            {
+                stopfunc = fann_get_train_stop_function(ann);
+            }
+            return static_cast<stop_function_enum>(stopfunc);
+        }
+
+        /* Method: set_train_stop_function
+
+           Set the stop function used during training.
+
+           The stop function is described further in <FANN::stop_function_enum>
+           
+           See also:
+   	        <get_train_stop_function>
+              
+           This function appears in FANN >= 2.0.0.
+         */ 
+        void set_train_stop_function(stop_function_enum train_stop_function)
+        {
+            if (ann != NULL)
+            {
+                fann_set_train_stop_function(ann,
+                    static_cast<enum fann_stopfunc_enum>(train_stop_function));
+            }
+        }
+
+        /* Method: get_bit_fail_limit
+
+           Returns the bit fail limit used during training.
+           
+           The bit fail limit is used during training when the <FANN::stop_function_enum> is set to FANN_STOPFUNC_BIT.
+
+           The limit is the maximum accepted difference between the desired output and the actual output during
+           training. Each output that diverges more than this limit is counted as an error bit.
+           This difference is divided by two when dealing with symmetric activation functions,
+           so that symmetric and not symmetric activation functions can use the same limit.
+           
+           The default bit fail limit is 0.35.
+           
+           See also:
+   	        <set_bit_fail_limit>
+           
+           This function appears in FANN >= 2.0.0.
+         */ 
+        fann_type get_bit_fail_limit()
+        {
+            fann_type bit_fail_limit = 0.0f;
+
+            if (ann != NULL)
+            {
+                bit_fail_limit = fann_get_bit_fail_limit(ann);
+            }
+            return bit_fail_limit;
+        }
+
+        /* Method: set_bit_fail_limit
+
+           Set the bit fail limit used during training.
+          
+           See also:
+   	        <get_bit_fail_limit>
+           
+           This function appears in FANN >= 2.0.0.
+         */
+        void set_bit_fail_limit(fann_type bit_fail_limit)
+        {
+            if (ann != NULL)
+            {
+                fann_set_bit_fail_limit(ann, bit_fail_limit);
+            }
+        }
+
+        /* Method: get_bit_fail
+        	
+	        The number of fail bits; means the number of output neurons which differ more 
+	        than the bit fail limit (see <get_bit_fail_limit>, <set_bit_fail_limit>). 
+	        The bits are counted in all of the training data, so this number can be higher than
+	        the number of training data.
+        	
+	        This value is reset by <reset_MSE> and updated by all the same functions which also
+	        updates the MSE value (e.g. <test_data>, <train_epoch>)
+        	
+	        See also:
+		        <FANN::stop_function_enum>, <get_MSE>
+
+	        This function appears in FANN >= 2.0.0
+        */
+        unsigned int get_bit_fail()
+        {
+            unsigned int bit_fail = 0;
+            if (ann != NULL)
+            {
+                bit_fail = fann_get_bit_fail(ann);
+            }
+            return bit_fail;
+        }
+
+        /*********************************************************************/
+
+        /* Method: cascadetrain_on_data
+
+           Trains on an entire dataset, for a period of time using the Cascade2 training algorithm.
+           This algorithm adds neurons to the neural network while training, which means that it
+           needs to start with an ANN without any hidden layers. The neural network should also use
+           shortcut connections, so <create_shortcut> should be used to create the ANN like this:
+           >net.create_shortcut(2, train_data.num_input_train_data(), train_data.num_output_train_data());
+           
+           This training uses the parameters set using the set_cascade_..., but it also uses another
+           training algorithm as it's internal training algorithm. This algorithm can be set to either
+           FANN::TRAIN_RPROP or FANN::TRAIN_QUICKPROP by <set_training_algorithm>, and the parameters 
+           set for these training algorithms will also affect the cascade training.
+           
+           Parameters:
+   		        data - The data, which should be used during training
+   		        max_neuron - The maximum number of neurons to be added to neural network
+   		        neurons_between_reports - The number of neurons between printing a status report to stdout.
+   			        A value of zero means no reports should be printed.
+   		        desired_error - The desired <fann_get_MSE> or <fann_get_bit_fail>, depending on which stop function
+   			        is chosen by <fann_set_train_stop_function>.
+
+	        Instead of printing out reports every neurons_between_reports, a callback function can be called 
+	        (see <set_callback>).
+        	
+	        See also:
+		        <train_on_data>, <cascadetrain_on_file>, <fann_cascadetrain_on_data>
+
+	        This function appears in FANN >= 2.0.0. 
+        */
+        void cascadetrain_on_data(const training_data &data, unsigned int max_neurons,
+            unsigned int neurons_between_reports, float desired_error)
+        {
+            if ((ann != NULL) && (data.train_data != NULL))
+            {
+                fann_cascadetrain_on_data(ann, data.train_data, max_neurons,
+                    neurons_between_reports, desired_error);
+            }
+        }
+
+        /* Method: cascadetrain_on_file
+           
+           Does the same as <cascadetrain_on_data>, but reads the training data directly from a file.
+           
+           See also:
+   		        <fann_cascadetrain_on_data>, <fann_cascadetrain_on_file>
+
+	        This function appears in FANN >= 2.0.0.
+        */ 
+        void cascadetrain_on_file(const std::string &filename, unsigned int max_neurons,
+            unsigned int neurons_between_reports, float desired_error)
+        {
+            if (ann != NULL)
+            {
+                fann_cascadetrain_on_file(ann, filename.c_str(),
+                    max_neurons, neurons_between_reports, desired_error);
+            }
+        }
+
+        /* Method: get_cascade_output_change_fraction
+
+           The cascade output change fraction is a number between 0 and 1 determining how large a fraction
+           the <get_MSE> value should change within <get_cascade_output_stagnation_epochs> during
+           training of the output connections, in order for the training not to stagnate. If the training 
+           stagnates, the training of the output connections will be ended and new candidates will be prepared.
+           
+           This means:
+           If the MSE does not change by a fraction of <get_cascade_output_change_fraction> during a 
+           period of <get_cascade_output_stagnation_epochs>, the training of the output connections
+           is stopped because the training has stagnated.
+
+           If the cascade output change fraction is low, the output connections will be trained more and if the
+           fraction is high they will be trained less.
+           
+           The default cascade output change fraction is 0.01, which is equalent to a 1% change in MSE.
+
+           See also:
+   		        <set_cascade_output_change_fraction>, <get_MSE>,
+                <get_cascade_output_stagnation_epochs>, <fann_get_cascade_output_change_fraction>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        float get_cascade_output_change_fraction()
+        {
+            float change_fraction = 0.0f;
+            if (ann != NULL)
+            {
+                change_fraction = fann_get_cascade_output_change_fraction(ann);
+            }
+            return change_fraction;
+        }
+
+        /* Method: set_cascade_output_change_fraction
+
+           Sets the cascade output change fraction.
+           
+           See also:
+   		        <get_cascade_output_change_fraction>, <fann_set_cascade_output_change_fraction>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_output_change_fraction(float cascade_output_change_fraction)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_output_change_fraction(ann, cascade_output_change_fraction);
+            }
+        }
+
+        /* Method: get_cascade_output_stagnation_epochs
+
+           The number of cascade output stagnation epochs determines the number of epochs training is allowed to
+           continue without changing the MSE by a fraction of <get_cascade_output_change_fraction>.
+           
+           See more info about this parameter in <get_cascade_output_change_fraction>.
+           
+           The default number of cascade output stagnation epochs is 12.
+
+           See also:
+   		        <set_cascade_output_stagnation_epochs>, <get_cascade_output_change_fraction>,
+                <fann_get_cascade_output_stagnation_epochs>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        unsigned int get_cascade_output_stagnation_epochs()
+        {
+            unsigned int stagnation_epochs = 0;
+            if (ann != NULL)
+            {
+                stagnation_epochs = fann_get_cascade_output_stagnation_epochs(ann);
+            }
+            return stagnation_epochs;
+        }
+
+        /* Method: set_cascade_output_stagnation_epochs
+
+           Sets the number of cascade output stagnation epochs.
+           
+           See also:
+   		        <get_cascade_output_stagnation_epochs>, <fann_set_cascade_output_stagnation_epochs>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_output_stagnation_epochs(unsigned int cascade_output_stagnation_epochs)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_output_stagnation_epochs(ann, cascade_output_stagnation_epochs);
+            }
+        }
+
+        /* Method: get_cascade_candidate_change_fraction
+
+           The cascade candidate change fraction is a number between 0 and 1 determining how large a fraction
+           the <get_MSE> value should change within <get_cascade_candidate_stagnation_epochs> during
+           training of the candidate neurons, in order for the training not to stagnate. If the training 
+           stagnates, the training of the candidate neurons will be ended and the best candidate will be selected.
+           
+           This means:
+           If the MSE does not change by a fraction of <get_cascade_candidate_change_fraction> during a 
+           period of <get_cascade_candidate_stagnation_epochs>, the training of the candidate neurons
+           is stopped because the training has stagnated.
+
+           If the cascade candidate change fraction is low, the candidate neurons will be trained more and if the
+           fraction is high they will be trained less.
+           
+           The default cascade candidate change fraction is 0.01, which is equalent to a 1% change in MSE.
+
+           See also:
+   		        <set_cascade_candidate_change_fraction>, <get_MSE>,
+                <get_cascade_candidate_stagnation_epochs>, <fann_get_cascade_candidate_change_fraction>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        float get_cascade_candidate_change_fraction()
+        {
+            float change_fraction = 0.0f;
+            if (ann != NULL)
+            {
+                change_fraction = fann_get_cascade_candidate_change_fraction(ann);
+            }
+            return change_fraction;
+        }
+
+        /* Method: set_cascade_candidate_change_fraction
+
+           Sets the cascade candidate change fraction.
+           
+           See also:
+   		        <get_cascade_candidate_change_fraction>,
+                <fann_set_cascade_candidate_change_fraction>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_candidate_change_fraction(float cascade_candidate_change_fraction)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_candidate_change_fraction(ann, cascade_candidate_change_fraction);
+            }
+        }
+
+        /* Method: get_cascade_candidate_stagnation_epochs
+
+           The number of cascade candidate stagnation epochs determines the number of epochs training is allowed to
+           continue without changing the MSE by a fraction of <get_cascade_candidate_change_fraction>.
+           
+           See more info about this parameter in <get_cascade_candidate_change_fraction>.
+
+           The default number of cascade candidate stagnation epochs is 12.
+
+           See also:
+   		        <set_cascade_candidate_stagnation_epochs>, <get_cascade_candidate_change_fraction>,
+                <fann_get_cascade_candidate_stagnation_epochs>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        unsigned int get_cascade_candidate_stagnation_epochs()
+        {
+            unsigned int stagnation_epochs = 0;
+            if (ann != NULL)
+            {
+                stagnation_epochs = fann_get_cascade_candidate_stagnation_epochs(ann);
+            }
+            return stagnation_epochs;
+        }
+
+        /* Method: set_cascade_candidate_stagnation_epochs
+
+           Sets the number of cascade candidate stagnation epochs.
+           
+           See also:
+   		        <get_cascade_candidate_stagnation_epochs>,
+                <fann_set_cascade_candidate_stagnation_epochs>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_candidate_stagnation_epochs(unsigned int cascade_candidate_stagnation_epochs)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_candidate_stagnation_epochs(ann, cascade_candidate_stagnation_epochs);
+            }
+        }
+
+        /* Method: get_cascade_weight_multiplier
+
+           The weight multiplier is a parameter which is used to multiply the weights from the candidate neuron
+           before adding the neuron to the neural network. This parameter is usually between 0 and 1, and is used
+           to make the training a bit less aggressive.
+
+           The default weight multiplier is 0.4
+
+           See also:
+   		        <set_cascade_weight_multiplier>, <fann_get_cascade_weight_multiplier>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        fann_type get_cascade_weight_multiplier()
+        {
+            fann_type weight_multiplier = 0;
+            if (ann != NULL)
+            {
+                weight_multiplier = fann_get_cascade_weight_multiplier(ann);
+            }
+            return weight_multiplier;
+        }
+
+        /* Method: set_cascade_weight_multiplier
+           
+           Sets the weight multiplier.
+           
+           See also:
+   		        <get_cascade_weight_multiplier>, <fann_set_cascade_weight_multiplier>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_weight_multiplier(fann_type cascade_weight_multiplier)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_weight_multiplier(ann, cascade_weight_multiplier);
+            }
+        }
+
+        /* Method: get_cascade_candidate_limit
+
+           The candidate limit is a limit for how much the candidate neuron may be trained.
+           The limit is a limit on the proportion between the MSE and candidate score.
+           
+           Set this to a lower value to avoid overfitting and to a higher if overfitting is
+           not a problem.
+           
+           The default candidate limit is 1000.0
+
+           See also:
+   		        <set_cascade_candidate_limit>, <fann_get_cascade_candidate_limit>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        fann_type get_cascade_candidate_limit()
+        {
+            fann_type candidate_limit = 0;
+            if (ann != NULL)
+            {
+                candidate_limit = fann_get_cascade_candidate_limit(ann);
+            }
+            return candidate_limit;
+        }
+
+        /* Method: set_cascade_candidate_limit
+
+           Sets the candidate limit.
+          
+           See also:
+   		        <get_cascade_candidate_limit>, <fann_set_cascade_candidate_limit>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_candidate_limit(fann_type cascade_candidate_limit)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_candidate_limit(ann, cascade_candidate_limit);
+            }
+        }
+
+        /* Method: get_cascade_max_out_epochs
+
+           The maximum out epochs determines the maximum number of epochs the output connections
+           may be trained after adding a new candidate neuron.
+           
+           The default max out epochs is 150
+
+           See also:
+   		        <set_cascade_max_out_epochs>, <fann_get_cascade_max_out_epochs>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        unsigned int get_cascade_max_out_epochs()
+        {
+            unsigned int max_out_epochs = 0;
+            if (ann != NULL)
+            {
+                max_out_epochs = fann_get_cascade_max_out_epochs(ann);
+            }
+            return max_out_epochs;
+        }
+
+        /* Method: set_cascade_max_out_epochs
+
+           Sets the maximum out epochs.
+
+           See also:
+   		        <get_cascade_max_out_epochs>, <fann_set_cascade_max_out_epochs>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_max_out_epochs(unsigned int cascade_max_out_epochs)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_max_out_epochs(ann, cascade_max_out_epochs);
+            }
+        }
+
+        /* Method: get_cascade_max_cand_epochs
+
+           The maximum candidate epochs determines the maximum number of epochs the input 
+           connections to the candidates may be trained before adding a new candidate neuron.
+           
+           The default max candidate epochs is 150
+
+           See also:
+   		        <set_cascade_max_cand_epochs>, <fann_get_cascade_max_cand_epochs>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        unsigned int get_cascade_max_cand_epochs()
+        {
+            unsigned int max_cand_epochs = 0;
+            if (ann != NULL)
+            {
+                max_cand_epochs = fann_get_cascade_max_cand_epochs(ann);
+            }
+            return max_cand_epochs;
+        }
+
+        /* Method: set_cascade_max_cand_epochs
+
+           Sets the max candidate epochs.
+          
+           See also:
+   		        <get_cascade_max_cand_epochs>, <fann_set_cascade_max_cand_epochs>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_max_cand_epochs(unsigned int cascade_max_cand_epochs)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_max_cand_epochs(ann, cascade_max_cand_epochs);
+            }
+        }
+
+        /* Method: get_cascade_num_candidates
+
+           The number of candidates used during training (calculated by multiplying <get_cascade_activation_functions_count>,
+           <get_cascade_activation_steepnesses_count> and <get_cascade_num_candidate_groups>). 
+
+           The actual candidates is defined by the <get_cascade_activation_functions> and 
+           <get_cascade_activation_steepnesses> arrays. These arrays define the activation functions 
+           and activation steepnesses used for the candidate neurons. If there are 2 activation functions
+           in the activation function array and 3 steepnesses in the steepness array, then there will be 
+           2x3=6 different candidates which will be trained. These 6 different candidates can be copied into
+           several candidate groups, where the only difference between these groups is the initial weights.
+           If the number of groups is set to 2, then the number of candidate neurons will be 2x3x2=12. The 
+           number of candidate groups is defined by <set_cascade_num_candidate_groups>.
+
+           The default number of candidates is 6x4x2 = 48
+
+           See also:
+   		        <get_cascade_activation_functions>, <get_cascade_activation_functions_count>, 
+   		        <get_cascade_activation_steepnesses>, <get_cascade_activation_steepnesses_count>,
+   		        <get_cascade_num_candidate_groups>, <fann_get_cascade_num_candidates>
+
+	        This function appears in FANN >= 2.0.0.
+         */ 
+        unsigned int get_cascade_num_candidates()
+        {
+            unsigned int num_candidates = 0;
+            if (ann != NULL)
+            {
+                num_candidates = fann_get_cascade_num_candidates(ann);
+            }
+            return num_candidates;
+        }
+
+        /* Method: get_cascade_activation_functions_count
+
+           The number of activation functions in the <get_cascade_activation_functions> array.
+
+           The default number of activation functions is 6.
+
+           See also:
+   		        <get_cascade_activation_functions>, <set_cascade_activation_functions>,
+                <fann_get_cascade_activation_functions_count>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        unsigned int get_cascade_activation_functions_count()
+        {
+            unsigned int activation_functions_count = 0;
+            if (ann != NULL)
+            {
+                activation_functions_count = fann_get_cascade_activation_functions_count(ann);
+            }
+            return activation_functions_count;
+        }
+
+        /* Method: get_cascade_activation_functions
+
+           The cascade activation functions array is an array of the different activation functions used by
+           the candidates. 
+           
+           See <get_cascade_num_candidates> for a description of which candidate neurons will be 
+           generated by this array.
+           
+           See also:
+   		        <get_cascade_activation_functions_count>, <set_cascade_activation_functions>,
+   		        <FANN::activation_function_enum>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        activation_function_enum * get_cascade_activation_functions()
+        {
+            enum fann_activationfunc_enum *activation_functions = NULL;
+            if (ann != NULL)
+            {
+                activation_functions = fann_get_cascade_activation_functions(ann);
+            }
+            return reinterpret_cast<activation_function_enum *>(activation_functions);
+        }
+
+        /* Method: set_cascade_activation_functions
+
+           Sets the array of cascade candidate activation functions. The array must be just as long
+           as defined by the count.
+
+           See <get_cascade_num_candidates> for a description of which candidate neurons will be 
+           generated by this array.
+
+           See also:
+   		        <get_cascade_activation_steepnesses_count>, <get_cascade_activation_steepnesses>,
+                <fann_set_cascade_activation_functions>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_activation_functions(activation_function_enum *cascade_activation_functions,
+            unsigned int cascade_activation_functions_count)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_activation_functions(ann,
+                    reinterpret_cast<enum fann_activationfunc_enum *>(cascade_activation_functions),
+                    cascade_activation_functions_count);
+            }
+        }
+
+        /* Method: get_cascade_activation_steepnesses_count
+
+           The number of activation steepnesses in the <get_cascade_activation_functions> array.
+
+           The default number of activation steepnesses is 4.
+
+           See also:
+   		        <get_cascade_activation_steepnesses>, <set_cascade_activation_functions>,
+                <fann_get_cascade_activation_steepnesses_count>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        unsigned int get_cascade_activation_steepnesses_count()
+        {
+            unsigned int activation_steepness_count = 0;
+            if (ann != NULL)
+            {
+                activation_steepness_count = fann_get_cascade_activation_steepnesses_count(ann);
+            }
+            return activation_steepness_count;
+        }
+
+        /* Method: get_cascade_activation_steepnesses
+
+           The cascade activation steepnesses array is an array of the different activation functions used by
+           the candidates.
+
+           See <get_cascade_num_candidates> for a description of which candidate neurons will be 
+           generated by this array.
+
+           The default activation steepnesses is {0.25, 0.50, 0.75, 1.00}
+
+           See also:
+   		        <set_cascade_activation_steepnesses>, <get_cascade_activation_steepnesses_count>,
+                <fann_get_cascade_activation_steepnesses>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        fann_type *get_cascade_activation_steepnesses()
+        {
+            fann_type *activation_steepnesses = NULL;
+            if (ann != NULL)
+            {
+                activation_steepnesses = fann_get_cascade_activation_steepnesses(ann);
+            }
+            return activation_steepnesses;
+        }																
+
+        /* Method: set_cascade_activation_steepnesses
+
+           Sets the array of cascade candidate activation steepnesses. The array must be just as long
+           as defined by the count.
+
+           See <get_cascade_num_candidates> for a description of which candidate neurons will be 
+           generated by this array.
+
+           See also:
+   		        <get_cascade_activation_steepnesses>, <get_cascade_activation_steepnesses_count>,
+                <fann_set_cascade_activation_steepnesses>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_activation_steepnesses(fann_type *cascade_activation_steepnesses,
+            unsigned int cascade_activation_steepnesses_count)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_activation_steepnesses(ann,
+                    cascade_activation_steepnesses, cascade_activation_steepnesses_count);
+            }
+        }
+
+        /* Method: get_cascade_num_candidate_groups
+
+           The number of candidate groups is the number of groups of identical candidates which will be used
+           during training.
+           
+           This number can be used to have more candidates without having to define new parameters for the candidates.
+           
+           See <get_cascade_num_candidates> for a description of which candidate neurons will be 
+           generated by this parameter.
+           
+           The default number of candidate groups is 2
+
+           See also:
+   		        <set_cascade_num_candidate_groups>, <fann_get_cascade_num_candidate_groups>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        unsigned int get_cascade_num_candidate_groups()
+        {
+            unsigned int num_candidate_groups = 0;
+            if (ann != NULL)
+            {
+                num_candidate_groups = fann_get_cascade_num_candidate_groups(ann);
+            }
+            return num_candidate_groups;
+        }
+
+        /* Method: set_cascade_num_candidate_groups
+
+           Sets the number of candidate groups.
+
+           See also:
+   		        <get_cascade_num_candidate_groups>, <fann_set_cascade_num_candidate_groups>
+
+	        This function appears in FANN >= 2.0.0.
+         */
+        void set_cascade_num_candidate_groups(unsigned int cascade_num_candidate_groups)
+        {
+            if (ann != NULL)
+            {
+                fann_set_cascade_num_candidate_groups(ann, cascade_num_candidate_groups);
+            }
+        }
+
+        /*********************************************************************/
+
+#ifndef FIXEDFANN
+        /* Method: scale_train
+
+           Scale input and output data based on previously calculated parameters.
+
+           See also:
+   		        <descale_train>, <fann_scale_train>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        void scale_train(training_data &data)
+        {
+            if (ann != NULL)
+            {
+                fann_scale_train(ann, data.train_data);
+            }
+        }
+
+        /* Method: descale_train
+
+           Descale input and output data based on previously calculated parameters.
+
+           See also:
+   		        <scale_train>, <fann_descale_train>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        void descale_train(training_data &data)
+        {
+            if (ann != NULL)
+            {
+                fann_descale_train(ann, data.train_data);
+            }
+        }
+
+        /* Method: set_input_scaling_params
+
+           Calculate scaling parameters for future use based on training data.
+
+           See also:
+   		        <set_output_scaling_params>, <fann_set_input_scaling_params>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        bool set_input_scaling_params(const training_data &data, float new_input_min, float new_input_max)
+        {
+            bool status = false;
+            if (ann != NULL)
+            {
+                status = (fann_set_input_scaling_params(ann, data.train_data, new_input_min, new_input_max) != -1);
+            }
+            return status;
+        }
+
+        /* Method: set_output_scaling_params
+
+           Calculate scaling parameters for future use based on training data.
+
+           See also:
+   		        <set_input_scaling_params>, <fann_set_output_scaling_params>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        bool set_output_scaling_params(const training_data &data, float new_output_min, float new_output_max)
+        {
+            bool status = false;
+            if (ann != NULL)
+            {
+                status = (fann_set_output_scaling_params(ann, data.train_data, new_output_min, new_output_max) != -1);
+            }
+            return status;
+        }
+
+        /* Method: set_scaling_params
+
+           Calculate scaling parameters for future use based on training data.
+
+           See also:
+   		        <clear_scaling_params>, <fann_set_scaling_params>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        bool set_scaling_params(const training_data &data,
+	        float new_input_min, float new_input_max, float new_output_min, float new_output_max)
+        {
+            bool status = false;
+            if (ann != NULL)
+            {
+                status = (fann_set_scaling_params(ann, data.train_data,
+                    new_input_min, new_input_max, new_output_min, new_output_max) != -1);
+            }
+            return status;
+        }
+
+        /* Method: clear_scaling_params
+
+           Clears scaling parameters.
+
+           See also:
+   		        <set_scaling_params>, <fann_clear_scaling_params>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        bool clear_scaling_params()
+        {
+            bool status = false;
+            if (ann != NULL)
+            {
+                status = (fann_clear_scaling_params(ann) != -1);
+            }
+            return status;
+        }
+
+        /* Method: scale_input
+
+           Scale data in input vector before feed it to ann based on previously calculated parameters.
+
+           See also:
+   		        <descale_input>, <scale_output>, <fann_scale_input>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        void scale_input(fann_type *input_vector)
+        {
+            if (ann != NULL)
+            {
+                fann_scale_input(ann, input_vector );
+            }
+        }
+
+        /* Method: scale_output
+
+           Scale data in output vector before feed it to ann based on previously calculated parameters.
+
+           See also:
+   		        <descale_output>, <scale_input>, <fann_scale_output>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        void scale_output(fann_type *output_vector)
+        {
+            if (ann != NULL)
+            {
+                fann_scale_output(ann, output_vector );
+            }
+        }
+
+        /* Method: descale_input
+
+           Scale data in input vector after get it from ann based on previously calculated parameters.
+
+           See also:
+   		        <scale_input>, <descale_output>, <fann_descale_input>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        void descale_input(fann_type *input_vector)
+        {
+            if (ann != NULL)
+            {
+                fann_descale_input(ann, input_vector );
+            }
+        }
+
+        /* Method: descale_output
+
+           Scale data in output vector after get it from ann based on previously calculated parameters.
+
+           See also:
+   		        <scale_output>, <descale_input>, <fann_descale_output>
+
+	        This function appears in FANN >= 2.1.0.
+         */
+        void descale_output(fann_type *output_vector)
+        {
+            if (ann != NULL)
+            {
+                fann_descale_output(ann, output_vector );
+            }
+        }
+
+#endif /* FIXEDFANN */
+
+        /*********************************************************************/
+
+        /* Method: set_error_log
+
+           Change where errors are logged to.
+           
+           If log_file is NULL, no errors will be printed.
+           
+           If neural_net is empty i.e. ann is NULL, the default log will be set.
+           The default log is the log used when creating a neural_net.
+           This default log will also be the default for all new structs
+           that are created.
+           
+           The default behavior is to log them to stderr.
+           
+           See also:
+                <struct fann_error>, <fann_set_error_log>
+           
+           This function appears in FANN >= 1.1.0.   
+         */ 
+        void set_error_log(FILE *log_file)
+        {
+            fann_set_error_log(reinterpret_cast<struct fann_error *>(ann), log_file);
+        }
+
+        /* Method: get_errno
+
+           Returns the last error number.
+           
+           See also:
+            <fann_errno_enum>, <fann_reset_errno>, <fann_get_errno>
+            
+           This function appears in FANN >= 1.1.0.   
+         */ 
+        unsigned int get_errno()
+        {
+            return fann_get_errno(reinterpret_cast<struct fann_error *>(ann));
+        }
+
+        /* Method: reset_errno
+
+           Resets the last error number.
+           
+           This function appears in FANN >= 1.1.0.   
+         */ 
+        void reset_errno()
+        {
+            fann_reset_errno(reinterpret_cast<struct fann_error *>(ann));
+        }
+
+        /* Method: reset_errstr
+
+           Resets the last error string.
+
+           This function appears in FANN >= 1.1.0.   
+         */ 
+        void reset_errstr()
+        {
+            fann_reset_errstr(reinterpret_cast<struct fann_error *>(ann));
+        }
+
+        /* Method: get_errstr
+
+           Returns the last errstr.
+          
+           This function calls <fann_reset_errno> and <fann_reset_errstr>
+
+           This function appears in FANN >= 1.1.0.   
+         */ 
+        std::string get_errstr()
+        {
+            return std::string(fann_get_errstr(reinterpret_cast<struct fann_error *>(ann)));
+        }
+
+        /* Method: print_error
+
+           Prints the last error to stderr.
+
+           This function appears in FANN >= 1.1.0.   
+         */ 
+        void print_error()
+        {
+            fann_print_error(reinterpret_cast<struct fann_error *>(ann));
+        }
+
+        /*********************************************************************/
+
+    private:
+        // Structure used by set_callback to hold information about a user callback
+        typedef struct user_context_type
+        {
+            callback_type user_callback; // Pointer to user callback function
+            void *user_data; // Arbitrary data pointer passed to the callback
+            neural_net *net; // This pointer for the neural network
+        } user_context;
+
+        // Internal callback used to convert from pointers to class references
+        static int FANN_API internal_callback(struct fann *ann, struct fann_train_data *train, 
+            unsigned int max_epochs, unsigned int epochs_between_reports, float desired_error, unsigned int epochs)
+        {
+            user_context *user_data = static_cast<user_context *>(fann_get_user_data(ann));
+            if (user_data != NULL)
+            {
+                FANN::training_data data;
+                data.train_data = train;
+
+                int result = (*user_data->user_callback)(*user_data->net,
+                    data, max_epochs, epochs_between_reports, desired_error, epochs, user_data);
+
+                data.train_data = NULL; // Prevent automatic cleanup
+                return result;
+            }
+            else
+            {
+                return -1; // This should not occur except if out of memory
+            }
+        }
+    protected:
+        // Pointer the encapsulated fann neural net structure
+        struct fann *ann;
+    };
+
+    /*************************************************************************/
+};
+
+#endif /* FANN_CPP_H_INCLUDED */
diff --git a/src/apps/Makefile.am b/src/apps/Makefile.am
new file mode 100644
index 0000000..005a0b0
--- /dev/null
+++ b/src/apps/Makefile.am
@@ -0,0 +1,45 @@
+AM_CXXFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/base $(GDAL_CFLAGS) @AM_CXXFLAGS@
+AM_LDFLAGS = $(GDAL_LDFLAGS) $(top_builddir)/src/algorithms/libalgorithms.a $(top_builddir)/src/imageclasses/libimageClasses.a @AM_LDFLAGS@
+LDADD = $(GDAL_LDFLAGS) $(top_builddir)/src/algorithms/libalgorithms.a $(top_builddir)/src/imageclasses/libimageClasses.a
+###############################################################################
+# THE PROGRAMS TO BUILD
+###############################################################################
+
+# the program to build (the names of the final binaries)
+bin_PROGRAMS = pkinfo pkcrop pkreclass pkgetmask pksetmask pkcreatect pkdumpimg pkdumpogr pksieve pkstat pkstatogr pkegcs pkextract pkfillnodata pkfilter pkmosaic pkndvi pkpolygonize pkascii2img pkdiff
+if USE_FANN
+bin_PROGRAMS += pkclassify_nn
+pkclassify_nn_SOURCES = $(top_srcdir)/src/algorithms/myfann_cpp.h pkclassify_nn.h pkclassify_nn.cc
+pkclassify_nn_CXXFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/base $(FANN_CFLAGS) -I$(top_srcdir)/src/algorithms $(AM_CXXFLAGS)
+pkclassify_nn_LDADD = $(FANN_LIBS) $(FANN_CFLAGS) $(AM_LDFLAGS)
+endif
+if USE_LAS
+bin_PROGRAMS += pklas2img
+pklas2img_SOURCES = pklas2img.cc
+pklas2img_LDADD = -L$(top_builddir)/src/fileclasses -lfileClasses -llas $(AM_LDFLAGS)
+endif
+# list of sources for the binaries
+pkinfo_SOURCES = pkinfo.cc
+pkcrop_SOURCES = pkcrop.cc
+pkreclass_SOURCES = pkreclass.cc
+pkgetmask_SOURCES = pkgetmask.cc
+pksetmask_SOURCES = pksetmask.cc
+pkcreatect_SOURCES = pkcreatect.cc
+pkdumpimg_SOURCES = pkdumpimg.cc
+pkdumpogr_SOURCES = pkdumpogr.h pkdumpogr.cc
+pksieve_SOURCES = pksieve.cc
+pkstat_SOURCES = $(top_srcdir)/src/algorithms/Histogram.h pkstat.cc
+pkstat_LDADD = $(GSL_LIBS) $(AM_LDFLAGS)
+pkstatogr_SOURCES = pkstatogr.cc
+pkegcs_SOURCES = pkegcs.cc
+pkegcs_LDADD = -lgdal $(AM_LDFLAGS) -lgdal
+pkextract_SOURCES = pkextract.cc
+pkfillnodata_SOURCES = pkfillnodata.cc
+pkfilter_SOURCES = pkfilter.cc
+pkfilter_LDADD = -lgdal $(AM_LDFLAGS) -lgdal
+pkmosaic_SOURCES = pkmosaic.cc
+pkndvi_SOURCES = pkndvi.cc
+pkpolygonize_SOURCES = pkpolygonize.cc
+pkascii2img_SOURCES = pkascii2img.cc
+pkdiff_SOURCES = pkdiff.cc
+###############################################################################
diff --git a/src/apps/Makefile.in b/src/apps/Makefile.in
new file mode 100644
index 0000000..4a93c87
--- /dev/null
+++ b/src/apps/Makefile.in
@@ -0,0 +1,759 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+bin_PROGRAMS = pkinfo$(EXEEXT) pkcrop$(EXEEXT) pkreclass$(EXEEXT) \
+	pkgetmask$(EXEEXT) pksetmask$(EXEEXT) pkcreatect$(EXEEXT) \
+	pkdumpimg$(EXEEXT) pkdumpogr$(EXEEXT) pksieve$(EXEEXT) \
+	pkstat$(EXEEXT) pkstatogr$(EXEEXT) pkegcs$(EXEEXT) \
+	pkextract$(EXEEXT) pkfillnodata$(EXEEXT) pkfilter$(EXEEXT) \
+	pkmosaic$(EXEEXT) pkndvi$(EXEEXT) pkpolygonize$(EXEEXT) \
+	pkascii2img$(EXEEXT) pkdiff$(EXEEXT) $(am__EXEEXT_1) \
+	$(am__EXEEXT_2)
+ at USE_FANN_TRUE@am__append_1 = pkclassify_nn
+ at USE_LAS_TRUE@am__append_2 = pklas2img
+subdir = src/apps
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_gdal.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+ at USE_FANN_TRUE@am__EXEEXT_1 = pkclassify_nn$(EXEEXT)
+ at USE_LAS_TRUE@am__EXEEXT_2 = pklas2img$(EXEEXT)
+am__installdirs = "$(DESTDIR)$(bindir)"
+PROGRAMS = $(bin_PROGRAMS)
+am_pkascii2img_OBJECTS = pkascii2img.$(OBJEXT)
+pkascii2img_OBJECTS = $(am_pkascii2img_OBJECTS)
+pkascii2img_LDADD = $(LDADD)
+am__DEPENDENCIES_1 =
+pkascii2img_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am__pkclassify_nn_SOURCES_DIST =  \
+	$(top_srcdir)/src/algorithms/myfann_cpp.h pkclassify_nn.h \
+	pkclassify_nn.cc
+ at USE_FANN_TRUE@am_pkclassify_nn_OBJECTS =  \
+ at USE_FANN_TRUE@	pkclassify_nn-pkclassify_nn.$(OBJEXT)
+pkclassify_nn_OBJECTS = $(am_pkclassify_nn_OBJECTS)
+am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+ at USE_FANN_TRUE@pkclassify_nn_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+ at USE_FANN_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
+pkclassify_nn_LINK = $(CXXLD) $(pkclassify_nn_CXXFLAGS) $(CXXFLAGS) \
+	$(AM_LDFLAGS) $(LDFLAGS) -o $@
+am_pkcreatect_OBJECTS = pkcreatect.$(OBJEXT)
+pkcreatect_OBJECTS = $(am_pkcreatect_OBJECTS)
+pkcreatect_LDADD = $(LDADD)
+pkcreatect_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkcrop_OBJECTS = pkcrop.$(OBJEXT)
+pkcrop_OBJECTS = $(am_pkcrop_OBJECTS)
+pkcrop_LDADD = $(LDADD)
+pkcrop_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkdiff_OBJECTS = pkdiff.$(OBJEXT)
+pkdiff_OBJECTS = $(am_pkdiff_OBJECTS)
+pkdiff_LDADD = $(LDADD)
+pkdiff_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkdumpimg_OBJECTS = pkdumpimg.$(OBJEXT)
+pkdumpimg_OBJECTS = $(am_pkdumpimg_OBJECTS)
+pkdumpimg_LDADD = $(LDADD)
+pkdumpimg_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkdumpogr_OBJECTS = pkdumpogr.$(OBJEXT)
+pkdumpogr_OBJECTS = $(am_pkdumpogr_OBJECTS)
+pkdumpogr_LDADD = $(LDADD)
+pkdumpogr_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkegcs_OBJECTS = pkegcs.$(OBJEXT)
+pkegcs_OBJECTS = $(am_pkegcs_OBJECTS)
+pkegcs_DEPENDENCIES = $(am__DEPENDENCIES_2)
+am_pkextract_OBJECTS = pkextract.$(OBJEXT)
+pkextract_OBJECTS = $(am_pkextract_OBJECTS)
+pkextract_LDADD = $(LDADD)
+pkextract_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkfillnodata_OBJECTS = pkfillnodata.$(OBJEXT)
+pkfillnodata_OBJECTS = $(am_pkfillnodata_OBJECTS)
+pkfillnodata_LDADD = $(LDADD)
+pkfillnodata_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkfilter_OBJECTS = pkfilter.$(OBJEXT)
+pkfilter_OBJECTS = $(am_pkfilter_OBJECTS)
+pkfilter_DEPENDENCIES = $(am__DEPENDENCIES_2)
+am_pkgetmask_OBJECTS = pkgetmask.$(OBJEXT)
+pkgetmask_OBJECTS = $(am_pkgetmask_OBJECTS)
+pkgetmask_LDADD = $(LDADD)
+pkgetmask_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkinfo_OBJECTS = pkinfo.$(OBJEXT)
+pkinfo_OBJECTS = $(am_pkinfo_OBJECTS)
+pkinfo_LDADD = $(LDADD)
+pkinfo_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am__pklas2img_SOURCES_DIST = pklas2img.cc
+ at USE_LAS_TRUE@am_pklas2img_OBJECTS = pklas2img.$(OBJEXT)
+pklas2img_OBJECTS = $(am_pklas2img_OBJECTS)
+ at USE_LAS_TRUE@pklas2img_DEPENDENCIES = $(am__DEPENDENCIES_2)
+am_pkmosaic_OBJECTS = pkmosaic.$(OBJEXT)
+pkmosaic_OBJECTS = $(am_pkmosaic_OBJECTS)
+pkmosaic_LDADD = $(LDADD)
+pkmosaic_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkndvi_OBJECTS = pkndvi.$(OBJEXT)
+pkndvi_OBJECTS = $(am_pkndvi_OBJECTS)
+pkndvi_LDADD = $(LDADD)
+pkndvi_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkpolygonize_OBJECTS = pkpolygonize.$(OBJEXT)
+pkpolygonize_OBJECTS = $(am_pkpolygonize_OBJECTS)
+pkpolygonize_LDADD = $(LDADD)
+pkpolygonize_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkreclass_OBJECTS = pkreclass.$(OBJEXT)
+pkreclass_OBJECTS = $(am_pkreclass_OBJECTS)
+pkreclass_LDADD = $(LDADD)
+pkreclass_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pksetmask_OBJECTS = pksetmask.$(OBJEXT)
+pksetmask_OBJECTS = $(am_pksetmask_OBJECTS)
+pksetmask_LDADD = $(LDADD)
+pksetmask_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pksieve_OBJECTS = pksieve.$(OBJEXT)
+pksieve_OBJECTS = $(am_pksieve_OBJECTS)
+pksieve_LDADD = $(LDADD)
+pksieve_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+am_pkstat_OBJECTS = pkstat.$(OBJEXT)
+pkstat_OBJECTS = $(am_pkstat_OBJECTS)
+pkstat_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
+am_pkstatogr_OBJECTS = pkstatogr.$(OBJEXT)
+pkstatogr_OBJECTS = $(am_pkstatogr_OBJECTS)
+pkstatogr_LDADD = $(LDADD)
+pkstatogr_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(top_builddir)/src/algorithms/libalgorithms.a \
+	$(top_builddir)/src/imageclasses/libimageClasses.a
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+	-o $@
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(pkascii2img_SOURCES) $(pkclassify_nn_SOURCES) \
+	$(pkcreatect_SOURCES) $(pkcrop_SOURCES) $(pkdiff_SOURCES) \
+	$(pkdumpimg_SOURCES) $(pkdumpogr_SOURCES) $(pkegcs_SOURCES) \
+	$(pkextract_SOURCES) $(pkfillnodata_SOURCES) \
+	$(pkfilter_SOURCES) $(pkgetmask_SOURCES) $(pkinfo_SOURCES) \
+	$(pklas2img_SOURCES) $(pkmosaic_SOURCES) $(pkndvi_SOURCES) \
+	$(pkpolygonize_SOURCES) $(pkreclass_SOURCES) \
+	$(pksetmask_SOURCES) $(pksieve_SOURCES) $(pkstat_SOURCES) \
+	$(pkstatogr_SOURCES)
+DIST_SOURCES = $(pkascii2img_SOURCES) \
+	$(am__pkclassify_nn_SOURCES_DIST) $(pkcreatect_SOURCES) \
+	$(pkcrop_SOURCES) $(pkdiff_SOURCES) $(pkdumpimg_SOURCES) \
+	$(pkdumpogr_SOURCES) $(pkegcs_SOURCES) $(pkextract_SOURCES) \
+	$(pkfillnodata_SOURCES) $(pkfilter_SOURCES) \
+	$(pkgetmask_SOURCES) $(pkinfo_SOURCES) \
+	$(am__pklas2img_SOURCES_DIST) $(pkmosaic_SOURCES) \
+	$(pkndvi_SOURCES) $(pkpolygonize_SOURCES) $(pkreclass_SOURCES) \
+	$(pksetmask_SOURCES) $(pksieve_SOURCES) $(pkstat_SOURCES) \
+	$(pkstatogr_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_CXXFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/base $(GDAL_CFLAGS) @AM_CXXFLAGS@
+AM_LDFLAGS = $(GDAL_LDFLAGS) $(top_builddir)/src/algorithms/libalgorithms.a $(top_builddir)/src/imageclasses/libimageClasses.a @AM_LDFLAGS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FANN_CFLAGS = @FANN_CFLAGS@
+FANN_LIBS = @FANN_LIBS@
+FILECLASSES_OPT = @FILECLASSES_OPT@
+GDAL_CFLAGS = @GDAL_CFLAGS@
+GDAL_CONFIG = @GDAL_CONFIG@
+GDAL_DEP_LDFLAGS = @GDAL_DEP_LDFLAGS@
+GDAL_LDFLAGS = @GDAL_LDFLAGS@
+GDAL_OGR_ENABLED = @GDAL_OGR_ENABLED@
+GDAL_VERSION = @GDAL_VERSION@
+GREP = @GREP@
+GSL_CFLAGS = @GSL_CFLAGS@
+GSL_LIBS = @GSL_LIBS@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+LDADD = $(GDAL_LDFLAGS) $(top_builddir)/src/algorithms/libalgorithms.a $(top_builddir)/src/imageclasses/libimageClasses.a
+ at USE_FANN_TRUE@pkclassify_nn_SOURCES = $(top_srcdir)/src/algorithms/myfann_cpp.h pkclassify_nn.h pkclassify_nn.cc
+ at USE_FANN_TRUE@pkclassify_nn_CXXFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/base $(FANN_CFLAGS) -I$(top_srcdir)/src/algorithms $(AM_CXXFLAGS)
+ at USE_FANN_TRUE@pkclassify_nn_LDADD = $(FANN_LIBS) $(FANN_CFLAGS) $(AM_LDFLAGS)
+ at USE_LAS_TRUE@pklas2img_SOURCES = pklas2img.cc
+ at USE_LAS_TRUE@pklas2img_LDADD = -L$(top_builddir)/src/fileclasses -lfileClasses -llas $(AM_LDFLAGS)
+# list of sources for the binaries
+pkinfo_SOURCES = pkinfo.cc
+pkcrop_SOURCES = pkcrop.cc
+pkreclass_SOURCES = pkreclass.cc
+pkgetmask_SOURCES = pkgetmask.cc
+pksetmask_SOURCES = pksetmask.cc
+pkcreatect_SOURCES = pkcreatect.cc
+pkdumpimg_SOURCES = pkdumpimg.cc
+pkdumpogr_SOURCES = pkdumpogr.h pkdumpogr.cc
+pksieve_SOURCES = pksieve.cc
+pkstat_SOURCES = $(top_srcdir)/src/algorithms/Histogram.h pkstat.cc
+pkstat_LDADD = $(GSL_LIBS) $(AM_LDFLAGS)
+pkstatogr_SOURCES = pkstatogr.cc
+pkegcs_SOURCES = pkegcs.cc
+pkegcs_LDADD = -lgdal $(AM_LDFLAGS) -lgdal
+pkextract_SOURCES = pkextract.cc
+pkfillnodata_SOURCES = pkfillnodata.cc
+pkfilter_SOURCES = pkfilter.cc
+pkfilter_LDADD = -lgdal $(AM_LDFLAGS) -lgdal
+pkmosaic_SOURCES = pkmosaic.cc
+pkndvi_SOURCES = pkndvi.cc
+pkpolygonize_SOURCES = pkpolygonize.cc
+pkascii2img_SOURCES = pkascii2img.cc
+pkdiff_SOURCES = pkdiff.cc
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cc .o .obj
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/apps/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign src/apps/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-binPROGRAMS: $(bin_PROGRAMS)
+	@$(NORMAL_INSTALL)
+	test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	for p in $$list; do echo "$$p $$p"; done | \
+	sed 's/$(EXEEXT)$$//' | \
+	while read p p1; do if test -f $$p; \
+	  then echo "$$p"; echo "$$p"; else :; fi; \
+	done | \
+	sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
+	    -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+	sed 'N;N;N;s,\n, ,g' | \
+	$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+	  { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+	    if ($$2 == $$4) files[d] = files[d] " " $$1; \
+	    else { print "f", $$3 "/" $$4, $$1; } } \
+	  END { for (d in files) print "f", d, files[d] }' | \
+	while read type dir files; do \
+	    if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+	    test -z "$$files" || { \
+	      echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+	      $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+	    } \
+	; done
+
+uninstall-binPROGRAMS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	files=`for p in $$list; do echo "$$p"; done | \
+	  sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+	      -e 's/$$/$(EXEEXT)/' `; \
+	test -n "$$list" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+pkascii2img$(EXEEXT): $(pkascii2img_OBJECTS) $(pkascii2img_DEPENDENCIES) 
+	@rm -f pkascii2img$(EXEEXT)
+	$(CXXLINK) $(pkascii2img_OBJECTS) $(pkascii2img_LDADD) $(LIBS)
+pkclassify_nn$(EXEEXT): $(pkclassify_nn_OBJECTS) $(pkclassify_nn_DEPENDENCIES) 
+	@rm -f pkclassify_nn$(EXEEXT)
+	$(pkclassify_nn_LINK) $(pkclassify_nn_OBJECTS) $(pkclassify_nn_LDADD) $(LIBS)
+pkcreatect$(EXEEXT): $(pkcreatect_OBJECTS) $(pkcreatect_DEPENDENCIES) 
+	@rm -f pkcreatect$(EXEEXT)
+	$(CXXLINK) $(pkcreatect_OBJECTS) $(pkcreatect_LDADD) $(LIBS)
+pkcrop$(EXEEXT): $(pkcrop_OBJECTS) $(pkcrop_DEPENDENCIES) 
+	@rm -f pkcrop$(EXEEXT)
+	$(CXXLINK) $(pkcrop_OBJECTS) $(pkcrop_LDADD) $(LIBS)
+pkdiff$(EXEEXT): $(pkdiff_OBJECTS) $(pkdiff_DEPENDENCIES) 
+	@rm -f pkdiff$(EXEEXT)
+	$(CXXLINK) $(pkdiff_OBJECTS) $(pkdiff_LDADD) $(LIBS)
+pkdumpimg$(EXEEXT): $(pkdumpimg_OBJECTS) $(pkdumpimg_DEPENDENCIES) 
+	@rm -f pkdumpimg$(EXEEXT)
+	$(CXXLINK) $(pkdumpimg_OBJECTS) $(pkdumpimg_LDADD) $(LIBS)
+pkdumpogr$(EXEEXT): $(pkdumpogr_OBJECTS) $(pkdumpogr_DEPENDENCIES) 
+	@rm -f pkdumpogr$(EXEEXT)
+	$(CXXLINK) $(pkdumpogr_OBJECTS) $(pkdumpogr_LDADD) $(LIBS)
+pkegcs$(EXEEXT): $(pkegcs_OBJECTS) $(pkegcs_DEPENDENCIES) 
+	@rm -f pkegcs$(EXEEXT)
+	$(CXXLINK) $(pkegcs_OBJECTS) $(pkegcs_LDADD) $(LIBS)
+pkextract$(EXEEXT): $(pkextract_OBJECTS) $(pkextract_DEPENDENCIES) 
+	@rm -f pkextract$(EXEEXT)
+	$(CXXLINK) $(pkextract_OBJECTS) $(pkextract_LDADD) $(LIBS)
+pkfillnodata$(EXEEXT): $(pkfillnodata_OBJECTS) $(pkfillnodata_DEPENDENCIES) 
+	@rm -f pkfillnodata$(EXEEXT)
+	$(CXXLINK) $(pkfillnodata_OBJECTS) $(pkfillnodata_LDADD) $(LIBS)
+pkfilter$(EXEEXT): $(pkfilter_OBJECTS) $(pkfilter_DEPENDENCIES) 
+	@rm -f pkfilter$(EXEEXT)
+	$(CXXLINK) $(pkfilter_OBJECTS) $(pkfilter_LDADD) $(LIBS)
+pkgetmask$(EXEEXT): $(pkgetmask_OBJECTS) $(pkgetmask_DEPENDENCIES) 
+	@rm -f pkgetmask$(EXEEXT)
+	$(CXXLINK) $(pkgetmask_OBJECTS) $(pkgetmask_LDADD) $(LIBS)
+pkinfo$(EXEEXT): $(pkinfo_OBJECTS) $(pkinfo_DEPENDENCIES) 
+	@rm -f pkinfo$(EXEEXT)
+	$(CXXLINK) $(pkinfo_OBJECTS) $(pkinfo_LDADD) $(LIBS)
+pklas2img$(EXEEXT): $(pklas2img_OBJECTS) $(pklas2img_DEPENDENCIES) 
+	@rm -f pklas2img$(EXEEXT)
+	$(CXXLINK) $(pklas2img_OBJECTS) $(pklas2img_LDADD) $(LIBS)
+pkmosaic$(EXEEXT): $(pkmosaic_OBJECTS) $(pkmosaic_DEPENDENCIES) 
+	@rm -f pkmosaic$(EXEEXT)
+	$(CXXLINK) $(pkmosaic_OBJECTS) $(pkmosaic_LDADD) $(LIBS)
+pkndvi$(EXEEXT): $(pkndvi_OBJECTS) $(pkndvi_DEPENDENCIES) 
+	@rm -f pkndvi$(EXEEXT)
+	$(CXXLINK) $(pkndvi_OBJECTS) $(pkndvi_LDADD) $(LIBS)
+pkpolygonize$(EXEEXT): $(pkpolygonize_OBJECTS) $(pkpolygonize_DEPENDENCIES) 
+	@rm -f pkpolygonize$(EXEEXT)
+	$(CXXLINK) $(pkpolygonize_OBJECTS) $(pkpolygonize_LDADD) $(LIBS)
+pkreclass$(EXEEXT): $(pkreclass_OBJECTS) $(pkreclass_DEPENDENCIES) 
+	@rm -f pkreclass$(EXEEXT)
+	$(CXXLINK) $(pkreclass_OBJECTS) $(pkreclass_LDADD) $(LIBS)
+pksetmask$(EXEEXT): $(pksetmask_OBJECTS) $(pksetmask_DEPENDENCIES) 
+	@rm -f pksetmask$(EXEEXT)
+	$(CXXLINK) $(pksetmask_OBJECTS) $(pksetmask_LDADD) $(LIBS)
+pksieve$(EXEEXT): $(pksieve_OBJECTS) $(pksieve_DEPENDENCIES) 
+	@rm -f pksieve$(EXEEXT)
+	$(CXXLINK) $(pksieve_OBJECTS) $(pksieve_LDADD) $(LIBS)
+pkstat$(EXEEXT): $(pkstat_OBJECTS) $(pkstat_DEPENDENCIES) 
+	@rm -f pkstat$(EXEEXT)
+	$(CXXLINK) $(pkstat_OBJECTS) $(pkstat_LDADD) $(LIBS)
+pkstatogr$(EXEEXT): $(pkstatogr_OBJECTS) $(pkstatogr_DEPENDENCIES) 
+	@rm -f pkstatogr$(EXEEXT)
+	$(CXXLINK) $(pkstatogr_OBJECTS) $(pkstatogr_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkascii2img.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkclassify_nn-pkclassify_nn.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkcreatect.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkcrop.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkdiff.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkdumpimg.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkdumpogr.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkegcs.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkextract.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkfillnodata.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkfilter.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkgetmask.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkinfo.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pklas2img.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkmosaic.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkndvi.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkpolygonize.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkreclass.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pksetmask.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pksieve.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkstat.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pkstatogr.Po at am__quote@
+
+.cc.o:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+pkclassify_nn-pkclassify_nn.o: pkclassify_nn.cc
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pkclassify_nn_CXXFLAGS) $(CXXFLAGS) -MT pkclassify_nn-pkclassify_nn.o -MD -MP -MF $(DEPDIR)/pkclassify_nn-pkclassify_nn.Tpo -c -o pkclassify_nn-pkclassify_nn.o `test -f 'pkclassify_nn.cc' || echo '$(srcdir)/'`pkclassify_nn.cc
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/pkclassify_nn-pkclassify_nn.Tpo $(DEPDIR)/pkclassify_nn-pkclassify_nn.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='pkclassify_nn.cc' object='pkclassify_nn-pkclassify_nn.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pkclassify_nn_CXXFLAGS) $(CXXFLAGS) -c -o pkclassify_nn-pkclassify_nn.o `test -f 'pkclassify_nn.cc' || echo '$(srcdir)/'`pkclassify_nn.cc
+
+pkclassify_nn-pkclassify_nn.obj: pkclassify_nn.cc
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pkclassify_nn_CXXFLAGS) $(CXXFLAGS) -MT pkclassify_nn-pkclassify_nn.obj -MD -MP -MF $(DEPDIR)/pkclassify_nn-pkclassify_nn.Tpo -c -o pkclassify_nn-pkclassify_nn.obj `if test -f 'pkclassify_nn.cc'; then $(CYGPATH_W) 'pkclassify_nn.cc'; else $(CYGPATH_W) '$(srcdir)/pkclassify_nn.cc'; fi`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/pkclassify_nn-pkclassify_nn.Tpo $(DEPDIR)/pkclassify_nn-pkclassify_nn.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='pkclassify_nn.cc' object='pkclassify_nn-pkclassify_nn.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pkclassify_nn_CXXFLAGS) $(CXXFLAGS) -c -o pkclassify_nn-pkclassify_nn.obj `if test -f 'pkclassify_nn.cc'; then $(CYGPATH_W) 'pkclassify_nn.cc'; else $(CYGPATH_W) '$(srcdir)/pkclassify_nn.cc'; fi`
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+	for dir in "$(DESTDIR)$(bindir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
+	clean-generic ctags distclean distclean-compile \
+	distclean-generic distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-binPROGRAMS \
+	install-data install-data-am install-dvi install-dvi-am \
+	install-exec install-exec-am install-html install-html-am \
+	install-info install-info-am install-man install-pdf \
+	install-pdf-am install-ps install-ps-am install-strip \
+	installcheck installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
+	uninstall-am uninstall-binPROGRAMS
+
+###############################################################################
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/apps/pkascii2img.cc b/src/apps/pkascii2img.cc
new file mode 100644
index 0000000..60e3673
--- /dev/null
+++ b/src/apps/pkascii2img.cc
@@ -0,0 +1,168 @@
+/**********************************************************************
+pkascii2img.cc: program to create raster image based on ascii file
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <string>
+#include <fstream>
+#include "Optionpk.h"
+#include <assert.h>
+#include "imageclasses/ImgWriterGdal.h"
+
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","introduce -uli -ulj to crop based on image coordinates",false);
+  Optionpk<std::string> input_opt("i","input","input ASCII file","");
+  Optionpk<string> output_opt("o", "output", "Output image file", "");
+  Optionpk<string> dataType_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "");
+  Optionpk<string> imageType_opt("of", "oformat", "image type string (default: GTiff, see also gdal_translate)", "GTiff");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "");
+  Optionpk<double> ulx_opt("ulx", "ulx", "Upper left x value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double> uly_opt("uly", "uly", "Upper left y value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double> dx_opt("dx", "dx", "Output resolution in x (in meter) (default is 0.0: keep original resolution)", 0.0);
+  Optionpk<double> dy_opt("dy", "dy", "Output resolution in y (in meter) (default is 0.0: keep original resolution)", 0.0);
+  Optionpk<string> projection_opt("p", "projection", "projection string (default is empty: no projection)", "");
+  Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<string> description_opt("d", "description", "Set image description", "");
+  Optionpk<bool> verbose_opt("v", "verbose", "verbose (false)", false);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  input_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  dataType_opt.retrieveOption(argc,argv);
+  imageType_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  ulx_opt.retrieveOption(argc,argv);
+  uly_opt.retrieveOption(argc,argv);
+  dx_opt.retrieveOption(argc,argv);
+  dy_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  projection_opt.retrieveOption(argc,argv);
+  description_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << "usage: pkascii2img -i asciifile -o imgfile [OPTIONS]" << endl;
+    exit(0);
+  }
+  ImgWriterGdal imgWriter;
+  ifstream ifile(input_opt[0].c_str(),ios::in);
+  //get number of lines
+  string line;
+  int nrow=0;
+  int ncol=0;
+  int irow=0;
+  string interleave="BAND";
+  vector< vector<double> > data;
+  vector<double> row;
+  double value;
+  try{
+    while(getline(ifile,line)){
+      row.clear();
+      //read data from ascii file
+      istringstream ist(line);
+      while(ist>>value)
+        row.push_back(value);
+      if(!ncol){
+        ncol=row.size();
+        data.push_back(row);
+      }
+      else
+        data.push_back(row);
+      if(verbose_opt[0]){
+        for(int icol=0;icol<row.size();++icol)
+          cout << row[icol] << " ";
+        cout << endl;
+      }
+      ++irow;
+    }
+    nrow=irow;
+    assert(ncol);
+    assert(nrow);
+    if(verbose_opt[0]){
+      cout << "nrow: " << nrow << endl;
+      cout << "ncol: " << ncol << endl;
+    }
+  }
+  catch(string theError){
+    cout << theError << endl;
+  }
+
+  GDALDataType dataType=GDT_Unknown;
+  if(verbose_opt[0])
+    cout << "possible output data types: ";
+  for(int iType = 0; iType < GDT_TypeCount; ++iType){
+    if(verbose_opt[0])
+      cout << " " << GDALGetDataTypeName((GDALDataType)iType);
+    if( GDALGetDataTypeName((GDALDataType)iType) != NULL
+        && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
+                 dataType_opt[0].c_str()))
+      dataType=(GDALDataType) iType;
+  }
+  if(verbose_opt[0])
+    cout << endl;
+  if(verbose_opt[0]){
+    if(dataType==GDT_Unknown)
+      cout << "Unknown output pixel type: " << dataType_opt[0] << endl;
+    else
+      cout << "Output pixel type:  " << GDALGetDataTypeName(dataType) << endl;
+  }
+
+  imgWriter.open(output_opt[0],ncol,nrow,1,dataType,imageType_opt[0],option_opt);
+  if(description_opt[0]!="")
+    imgWriter.setImageDescription(description_opt[0]);
+  if(projection_opt[0]!=""){
+    if(verbose_opt[0])
+      cout << output_opt[0] << " is georeferenced." << endl;
+    imgWriter.setGeoTransform(ulx_opt[0],uly_opt[0],dx_opt[0],dy_opt[0],0,0);
+    imgWriter.setProjectionProj4(projection_opt[0]);
+  }
+  else{
+    if(verbose_opt[0])
+      cout << output_opt[0] << " is not georeferenced." << endl;
+    assert(!imgWriter.isGeoRef());
+  }
+  if(colorTable_opt[0]!=""){
+    assert(imgWriter.getDataType()==GDT_Byte);
+    imgWriter.setColorTable(colorTable_opt[0]);
+  }
+  assert(data.size()==nrow);
+  for(irow=0;irow<nrow;++irow)
+    imgWriter.writeData(data[irow],GDT_Float64,irow);
+  imgWriter.close();
+}
+
diff --git a/src/apps/pkclassify_nn.cc b/src/apps/pkclassify_nn.cc
new file mode 100644
index 0000000..a9ce801
--- /dev/null
+++ b/src/apps/pkclassify_nn.cc
@@ -0,0 +1,941 @@
+/**********************************************************************
+pkclassify_nn.cc: classify raster image using Artificial Neural Network
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "pkclassify_nn.h"
+#include <vector>
+#include <map>
+#include <algorithm>
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "imageclasses/ImgReaderOgr.h"
+#include "imageclasses/ImgWriterOgr.h"
+#include "base/Optionpk.h"
+#include "floatfann.h"
+#include "myfann_cpp.h"
+
+int main(int argc, char *argv[])
+{
+  map<short,int> reclassMap;
+  vector<int> vreclass;
+  vector<double> priors;
+  
+  //--------------------------- command line options ------------------------------------
+
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<string> input_opt("i", "input", "input image",""); 
+  Optionpk<string> training_opt("t", "training", "training shape file. A single shape file contains all training features for all classes. Use multiple training files for bootstrap aggregation (alternative to the bag and bsize options, where a random subset is taken from a single training file)",""); 
+  Optionpk<string> label_opt("\0", "label", "identifier for class label in training shape file. (default is label)","label"); 
+  Optionpk<string> query_opt("q", "sql", "field name for sql query statement for selecting training pixels: select * from layer where fieldname=1 (default: empty)",""); 
+  Optionpk<unsigned short> reclass_opt("\0", "rc", "reclass code (e.g. --rc=12 --rc=23 to reclass first two classes to 12 and 23 resp.). Default is 0: do not reclass", 0);
+  Optionpk<unsigned int> balance_opt("\0", "balance", "balance the input data to this number of samples for each class (default 0: do not balance)", 0);
+  Optionpk<int> minSize_opt("m", "min", "if number of training pixels is less then min, do not take this class into account (default is 0: consider all classes", 0);
+  Optionpk<double> start_opt("s", "start", "start band sequence number (set to 0)",0); 
+  Optionpk<double> end_opt("e", "end", "end band sequence number (set to 0 for all bands)", 0); 
+  Optionpk<double> offset_opt("\0", "offset", "offset value for each spectral band input features: refl[band]=(DN[band]-offset[band])/scale[band]", 0.0);
+  Optionpk<double> scale_opt("\0", "scale", "scale value for each spectral band input features: refl=(DN[band]-offset[band])/scale[band] (use 0 if scale min and max in each band to -1.0 and 1.0)", 0.0);
+  Optionpk<unsigned short> aggreg_opt("a", "aggreg", "how to combine aggregated classifiers, see also rc option (0: sum rule, 1: max rule). Default is max rule (1)",1); 
+  Optionpk<double> priors_opt("p", "prior", "prior probabilities for each class (e.g., -p 0.3 -p 0.3 -p 0.2 ), default set to equal priors)", 0.0); 
+  Optionpk<unsigned int> nneuron_opt("\0", "nneuron", "number of neurons in hidden layers in neural network (multiple hidden layers are set by defining multiple number of neurons: -n 15 -n 1, default is one hidden layer with 5 neurons)", 5); 
+  Optionpk<float> connection_opt("\0", "connection", "connection reate (default: 1.0 for a fully connected network)", 1.0); 
+  Optionpk<float> weights_opt("w", "weights", "weights for neural network. Apply to fully connected network only, starting from first input neuron to last output neuron, including the bias neurons (last neuron in each but last layer)", 0.0); 
+  Optionpk<float> learning_opt("l", "learning", "learning rate (default: 0.7)", 0.7); 
+  Optionpk<unsigned int> maxit_opt("\0", "maxit", "number of maximum iterations (epoch) (default: 500)", 500); 
+  Optionpk<bool> random_opt("r", "random", "random seed for selecting balanced sample: set to 1 for random (default), set to 0 for reproducable accuracy result for each new run", true);
+  Optionpk<unsigned short> comb_opt("c", "comb", "how to combine bootstrap aggregation classifiers (0: sum rule, 1: product rule, 2: max rule). Also used to aggregate classes with rc option. Default is sum rule (0)",0); 
+  Optionpk<unsigned short> bag_opt("\0", "bag", "Number of bootstrap aggregations (default is no bagging: 1)", 1);
+  Optionpk<int> bagSize_opt("\0", "bsize", "Percentage of features used from available training features for each bootstrap aggregation (default for no bagging: 100)", 100);
+  Optionpk<string> classBag_opt("\0", "class", "output for each individual bootstrap aggregation (default is blank)",""); 
+  Optionpk<string> mask_opt("\0", "mask", "mask image (see also mvalue option (default is no mask)",""); 
+  Optionpk<short> maskValue_opt("\0", "mvalue", "mask value(s) not to consider for classification (use negative values if only these values should be taken into account). Values will be taken over in classification image. Default is 0", 0);
+  Optionpk<unsigned short> flag_opt("f", "flag", "flag to put where image is invalid. Default is 0", 0);
+  Optionpk<string> output_opt("o", "output", "output classification image",""); 
+  Optionpk<string>  otype_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "");
+  Optionpk<string>  oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<string> colorTable_opt("\0", "ct", "colour table in ascii format having 5 columns: id R G B ALFA (0: transparent, 255: solid)",""); 
+  Optionpk<string> prob_opt("\0", "prob", "probability image. Default is no probability image",""); 
+  Optionpk<short> verbose_opt("v", "verbose", "set to: 0 (results only), 1 (confusion matrix), 2 (debug)",0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+
+  input_opt.retrieveOption(argc,argv);
+  input_opt.retrieveOption(argc,argv);
+  training_opt.retrieveOption(argc,argv);
+  label_opt.retrieveOption(argc,argv);
+  query_opt.retrieveOption(argc,argv);
+  reclass_opt.retrieveOption(argc,argv);
+  balance_opt.retrieveOption(argc,argv);
+  minSize_opt.retrieveOption(argc,argv);
+  start_opt.retrieveOption(argc,argv);
+  end_opt.retrieveOption(argc,argv);
+  offset_opt.retrieveOption(argc,argv);
+  scale_opt.retrieveOption(argc,argv);
+  aggreg_opt.retrieveOption(argc,argv);
+  priors_opt.retrieveOption(argc,argv);
+  nneuron_opt.retrieveOption(argc,argv);
+  connection_opt.retrieveOption(argc,argv);
+  weights_opt.retrieveOption(argc,argv);
+  learning_opt.retrieveOption(argc,argv);
+  maxit_opt.retrieveOption(argc,argv);
+  random_opt.retrieveOption(argc,argv);
+  comb_opt.retrieveOption(argc,argv);
+  bag_opt.retrieveOption(argc,argv);
+  bagSize_opt.retrieveOption(argc,argv);
+  classBag_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  maskValue_opt.retrieveOption(argc,argv);
+  flag_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  otype_opt.retrieveOption(argc,argv);
+  oformat_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  prob_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+
+  if(verbose_opt[0]>=1){
+    cout << "image filename: " << input_opt[0] << endl;
+    if(mask_opt[0]!="")
+      cout << "mask filename: " << mask_opt[0] << endl;
+    if(training_opt[0]!=""){
+      cout << "training shape file: " << endl;
+      for(int ifile=0;ifile<training_opt.size();++ifile)
+        cout << training_opt[ifile] << endl;
+    }
+    else
+      cerr << "no training file set!" << endl;
+    cout << "verbose: " << verbose_opt[0] << endl;
+  }
+  unsigned short nbag=(training_opt.size()>1)?training_opt.size():bag_opt[0];
+  if(verbose_opt[0]>=1)
+    cout << "number of bootstrap aggregations: " << nbag << endl;
+  
+  unsigned int totalSamples=0;
+  int nreclass=0;
+  vector<int> vcode;//unique class codes in recode string
+  vector<FANN::neural_net> net(nbag);//the neural network
+
+  unsigned int nclass=0;
+  int nband=0;
+  int startBand=2;//first two bands represent X and Y pos
+
+  vector< vector<double> > offset(nbag);
+  vector< vector<double> > scale(nbag);
+  vector< Vector2d<float> > trainingPixels;//[class][sample][band]
+
+  if(reclass_opt.size()>1){
+    vreclass.resize(reclass_opt.size());
+    for(int iclass=0;iclass<reclass_opt.size();++iclass){
+      reclassMap[iclass]=reclass_opt[iclass];
+      vreclass[iclass]=reclass_opt[iclass];
+    }
+  }
+  if(priors_opt.size()>1){//priors from argument list
+    priors.resize(priors_opt.size());
+    double normPrior=0;
+    for(int iclass=0;iclass<priors_opt.size();++iclass){
+      priors[iclass]=priors_opt[iclass];
+      normPrior+=priors[iclass];
+    }
+    //normalize
+    for(int iclass=0;iclass<priors_opt.size();++iclass)
+      priors[iclass]/=normPrior;
+  }
+
+  //----------------------------------- Training -------------------------------
+  vector<string> fields;
+  for(int ibag=0;ibag<nbag;++ibag){
+    //organize training data
+    if(ibag<training_opt.size()){//if bag contains new training pixels
+      trainingPixels.clear();
+      map<int,Vector2d<float> > trainingMap;
+      if(verbose_opt[0]>=1)
+        cout << "reading imageShape file " << training_opt[0] << endl;
+      try{
+        totalSamples=readDataImageShape(training_opt[ibag],trainingMap,fields,start_opt[0],end_opt[0],label_opt[0],query_opt[0],verbose_opt[0]);
+        if(trainingMap.size()<2){
+          string errorstring="Error: could not read at least two classes from training file";
+          throw(errorstring);
+        }
+      }
+      catch(string error){
+        cerr << error << endl;
+        exit(1);
+      }
+      catch(...){
+        cerr << "error catched" << endl;
+        exit(1);
+      }
+      //delete class 0
+      if(verbose_opt[0]>=1)
+        cout << "erasing class 0 from training set (" << trainingMap[0].size() << " from " << totalSamples << ") samples" << endl;
+      totalSamples-=trainingMap[0].size();
+      trainingMap.erase(0);
+      //convert map to vector
+      short iclass=0;
+      if(reclass_opt.size()==1){//no reclass option, read classes from shape
+        reclassMap.clear();
+        vreclass.clear();
+      }
+      if(verbose_opt[0]>1)
+        cout << "training pixels: " << endl;
+      map<int,Vector2d<float> >::iterator mapit=trainingMap.begin();
+      while(mapit!=trainingMap.end()){
+//       for(map<int,Vector2d<float> >::const_iterator mapit=trainingMap.begin();mapit!=trainingMap.end();++mapit){
+        //delete small classes
+        if((mapit->second).size()<minSize_opt[0]){
+          trainingMap.erase(mapit);
+          continue;
+          //todo: beware of reclass option: delete this reclass if no samples are left in this classes!!
+        }
+        if(reclass_opt.size()==1){//no reclass option, read classes from shape
+          reclassMap[iclass]=(mapit->first);
+          vreclass.push_back(mapit->first);
+        }
+        trainingPixels.push_back(mapit->second);
+        if(verbose_opt[0]>1)
+          cout << mapit->first << ": " << (mapit->second).size() << " samples" << endl;
+        ++iclass;
+        ++mapit;
+      }
+      if(!ibag){
+        nclass=trainingPixels.size();
+        nband=(training_opt[0]!="")?trainingPixels[0][0].size()-2:trainingPixels[0][0].size();//X and Y
+      }
+      else{
+        assert(nclass==trainingPixels.size());
+        assert(nband==(training_opt[0]!="")?trainingPixels[0][0].size()-2:trainingPixels[0][0].size());
+      }
+      assert(reclassMap.size()==nclass);
+
+      //do not remove outliers here: could easily be obtained through ogr2ogr -where 'B2<110' output.shp input.shp
+      //balance training data
+      if(balance_opt[0]>0){
+        if(random)
+          srand(time(NULL));
+        totalSamples=0;
+        for(int iclass=0;iclass<nclass;++iclass){
+          if(trainingPixels[iclass].size()>balance_opt[0]){
+            while(trainingPixels[iclass].size()>balance_opt[0]){
+              int index=rand()%trainingPixels[iclass].size();
+              trainingPixels[iclass].erase(trainingPixels[iclass].begin()+index);
+            }
+          }
+          else{
+            int oldsize=trainingPixels[iclass].size();
+            for(int isample=trainingPixels[iclass].size();isample<balance_opt[0];++isample){
+              int index = rand()%oldsize;
+              trainingPixels[iclass].push_back(trainingPixels[iclass][index]);
+            }
+          }
+          totalSamples+=trainingPixels[iclass].size();
+        }
+        assert(totalSamples==nclass*balance_opt[0]);
+      }
+    
+      //set scale and offset
+      offset[ibag].resize(nband);
+      scale[ibag].resize(nband);
+      if(offset_opt.size()>1)
+        assert(offset_opt.size()==nband);
+      if(scale_opt.size()>1)
+        assert(scale_opt.size()==nband);
+      Histogram hist;
+      for(int iband=0;iband<nband;++iband){
+        if(verbose_opt[0]>=1)
+          cout << "scaling for band" << iband << endl;
+        offset[ibag][iband]=(offset_opt.size()==1)?offset_opt[0]:offset_opt[iband];
+        scale[ibag][iband]=(scale_opt.size()==1)?scale_opt[0]:scale_opt[iband];
+        //search for min and maximum
+        if(scale[ibag][iband]<=0){
+          float theMin=trainingPixels[0][0][iband+startBand];
+          float theMax=trainingPixels[0][0][iband+startBand];
+          for(int iclass=0;iclass<nclass;++iclass){
+            for(int isample=0;isample<trainingPixels[iclass].size();++isample){
+              if(theMin>trainingPixels[iclass][isample][iband+startBand])
+                theMin=trainingPixels[iclass][isample][iband+startBand];
+              if(theMax<trainingPixels[iclass][isample][iband+startBand])
+                theMax=trainingPixels[iclass][isample][iband+startBand];
+            }
+          }
+          offset[ibag][iband]=theMin+(theMax-theMin)/2.0;
+          scale[ibag][iband]=(theMax-theMin)/2.0;
+          if(verbose_opt[0]>=1){
+            cout << "Extreme image values for band " << iband << ": [" << theMin << "," << theMax << "]" << endl;
+            cout << "Using offset, scale: " << offset[ibag][iband] << ", " << scale[ibag][iband] << endl;
+          }
+        }
+      }
+    }
+    else{//use same offset and scale 
+      offset[ibag].resize(nband);
+      scale[ibag].resize(nband);
+      for(int iband=0;iband<nband;++iband){
+        offset[ibag][iband]=offset[0][iband];
+        scale[ibag][iband]=scale[0][iband];
+      }
+    }
+      
+    if(!ibag){
+      //recode vreclass to ordered vector, starting from 0 to nreclass
+      vcode.clear();
+      if(verbose_opt[0]>=1){
+        cout << "before recoding: " << endl;
+        for(int iclass = 0; iclass < vreclass.size(); iclass++)
+          cout << " " << vreclass[iclass];
+        cout << endl; 
+      }
+      vector<int> vord=vreclass;//ordered vector, starting from 0 to nreclass
+      int iclass=0;
+      map<short,int> mreclass;
+      for(int ic=0;ic<vreclass.size();++ic){
+        if(mreclass.find(vreclass[ic])==mreclass.end())
+          mreclass[vreclass[ic]]=iclass++;
+      }
+      for(int ic=0;ic<vreclass.size();++ic)
+        vord[ic]=mreclass[vreclass[ic]];
+      //construct uniqe class codes
+      while(!vreclass.empty()){
+        vcode.push_back(*(vreclass.begin()));
+        //delete all these entries from vreclass
+        vector<int>::iterator vit;
+        while((vit=find(vreclass.begin(),vreclass.end(),vcode.back()))!=vreclass.end())
+          vreclass.erase(vit);
+      }
+      if(verbose_opt[0]>=1){
+        cout << "recode values: " << endl;
+        for(int icode=0;icode<vcode.size();++icode)
+          cout << vcode[icode] << " ";
+        cout << endl;
+      }
+      vreclass=vord;
+      if(verbose_opt[0]>=1){
+        cout << "after recoding: " << endl;
+        for(int iclass = 0; iclass < vord.size(); iclass++)
+          cout << " " << vord[iclass];
+        cout << endl; 
+      }
+      
+      vector<int> vuniqueclass=vreclass;
+      //remove duplicate elements from vuniqueclass
+      sort( vuniqueclass.begin(), vuniqueclass.end() );
+      vuniqueclass.erase( unique( vuniqueclass.begin(), vuniqueclass.end() ), vuniqueclass.end() );
+      nreclass=vuniqueclass.size();
+      if(verbose_opt[0]>=1){
+        cout << "unique classes: " << endl;
+        for(int iclass = 0; iclass < vuniqueclass.size(); iclass++)
+          cout << " " << vuniqueclass[iclass];
+        cout << endl; 
+        cout << "number of reclasses: " << nreclass << endl;
+      }
+    
+      if(priors_opt.size()==1){//default: equal priors for each class
+        priors.resize(nclass);
+        for(int iclass=0;iclass<nclass;++iclass)
+          priors[iclass]=1.0/nclass;
+      }
+      assert(priors_opt.size()==1||priors_opt.size()==nclass);
+    
+      if(verbose_opt[0]>=1){
+        cout << "number of bands: " << nband << endl;
+        cout << "number of classes: " << nclass << endl;
+        cout << "priors:";
+        for(int iclass=0;iclass<nclass;++iclass)
+          cout << " " << priors[iclass];
+        cout << endl;
+      }
+    }
+
+    //Calculate features of trainig set
+    vector< Vector2d<float> > trainingFeatures(nclass);
+    for(int iclass=0;iclass<nclass;++iclass){
+      int nctraining=0;
+      if(verbose_opt[0]>=1)
+        cout << "calculating features for class " << iclass << endl;
+      if(random)
+        srand(time(NULL));
+      nctraining=(bagSize_opt[0]<100)? trainingPixels[iclass].size()/100.0*bagSize_opt[0] : trainingPixels[iclass].size();//bagSize_opt[0] given in % of training size
+      if(nctraining<=0)
+        nctraining=1;
+      assert(nctraining<=trainingPixels[iclass].size());
+      int index=0;
+      if(bagSize_opt[0]<100)
+        random_shuffle(trainingPixels[iclass].begin(),trainingPixels[iclass].end());
+      
+      trainingFeatures[iclass].resize(nctraining);
+      for(int isample=0;isample<nctraining;++isample){
+        //scale pixel values according to scale and offset!!!
+        for(int iband=0;iband<nband;++iband){
+          float value=trainingPixels[iclass][isample][iband+startBand];
+          trainingFeatures[iclass][isample].push_back((value-offset[ibag][iband])/scale[ibag][iband]);
+        }
+      }
+      assert(trainingFeatures[iclass].size()==nctraining);
+    }
+    
+    int nFeatures=0;
+    nFeatures=trainingFeatures[0][0].size();
+    unsigned int ntraining=0;
+    for(int iclass=0;iclass<nclass;++iclass){
+      if(verbose_opt[0]>=1)
+        cout << "training sample size for class " << vcode[iclass] << ": " << trainingFeatures[iclass].size() << endl;
+      ntraining+=trainingFeatures[iclass].size();
+    }
+    const unsigned int num_layers = nneuron_opt.size()+2;
+    const float desired_error = 0.0003;
+    const unsigned int iterations_between_reports = (verbose_opt[0]>=1)?100:maxit_opt[0]+1;
+    if(verbose_opt[0]>=1){
+      cout << "creating artificial neural network with " << nneuron_opt.size() << " hidden layer, having " << endl;
+      for(int ilayer=0;ilayer<nneuron_opt.size();++ilayer)
+        cout << nneuron_opt[ilayer] << " ";
+      cout << "neurons" << endl;
+    }
+    switch(num_layers){
+    case(3):
+      net[ibag].create_sparse(connection_opt[0],num_layers, nFeatures, nneuron_opt[0], nclass);
+      break;
+    case(4):
+      net[ibag].create_sparse(connection_opt[0],num_layers, nFeatures, nneuron_opt[0], nneuron_opt[1], nclass);
+      break;
+    default:
+      cerr << "Only 1 or 2 hidden layers are supported!" << endl;
+      exit(1);
+      break;
+    }
+    if(verbose_opt[0]>=1)
+      cout << "network created" << endl;
+  
+    net[ibag].set_learning_rate(learning_opt[0]);
+
+    //   net.set_activation_steepness_hidden(1.0);
+    //   net.set_activation_steepness_output(1.0);
+    
+    net[ibag].set_activation_function_hidden(FANN::SIGMOID_SYMMETRIC_STEPWISE);
+    net[ibag].set_activation_function_output(FANN::SIGMOID_SYMMETRIC_STEPWISE);
+
+    // Set additional properties such as the training algorithm
+    //   net.set_training_algorithm(FANN::TRAIN_QUICKPROP);
+
+    // Output network type and parameters
+    if(verbose_opt[0]>=1){
+      cout << endl << "Network Type                         :  ";
+      switch (net[ibag].get_network_type())
+        {
+        case FANN::LAYER:
+          cout << "LAYER" << endl;
+          break;
+        case FANN::SHORTCUT:
+          cout << "SHORTCUT" << endl;
+          break;
+        default:
+          cout << "UNKNOWN" << endl;
+          break;
+        }
+      net[ibag].print_parameters();
+    }
+      
+
+    FANN::training_data trainingData;
+  
+    if(verbose_opt[0]>=1)
+      cout << endl << "Set training data" << endl;
+    trainingData.set_train_data(trainingFeatures,ntraining);
+    //     trainingData.set_train_data(trainingFeatures,totalSamples);
+
+    if(verbose_opt[0]>=1)
+      cout << endl << "Training network" << endl;
+    net[ibag].init_weights(trainingData);
+    
+    if(verbose_opt[0]>=1){
+      cout << "Max Epochs " << setw(8) << maxit_opt[0] << ". "
+           << "Desired Error: " << left << desired_error << right << endl;
+    }
+    //   net.set_callback(print_callback, NULL);
+    if(weights_opt.size()==net[ibag].get_total_connections()){
+      vector<fann_connection> convector;
+      net[ibag].get_connection_array(convector);
+      for(int i_connection=0;i_connection<net[ibag].get_total_connections();++i_connection)
+        convector[i_connection].weight=weights_opt[i_connection];
+      net[ibag].set_weight_array(convector);
+    }
+    else
+      net[ibag].train_on_data(trainingData, maxit_opt[0],
+                              iterations_between_reports, desired_error);
+    if(verbose_opt[0]>=2){
+      net[ibag].print_connections();
+      vector<fann_connection> convector;
+      net[ibag].get_connection_array(convector);
+      for(int i_connection=0;i_connection<net[ibag].get_total_connections();++i_connection)
+        cout << "connection " << i_connection << ": " << convector[i_connection].weight << endl;
+
+    }
+  }
+
+  //--------------------------------- end of training -----------------------------------
+
+
+  //-------------------------------- open image file ------------------------------------
+  if(input_opt[0].find(".shp")==string::npos){
+    ImgReaderGdal testImage;
+    try{
+      if(verbose_opt[0]>=1)
+        cout << "opening image " << input_opt[0] << endl; 
+      testImage.open(input_opt[0]);
+    }
+    catch(string error){
+      cerr << error << endl;
+      exit(2);
+    }
+    ImgReaderGdal maskReader;
+    if(mask_opt[0]!=""){
+      try{
+        if(verbose_opt[0]>=1)
+          cout << "opening mask image file " << mask_opt[0] << endl;
+        maskReader.open(mask_opt[0]);
+        assert(maskReader.nrOfCol()==testImage.nrOfCol());
+        assert(maskReader.nrOfRow()==testImage.nrOfRow());
+      }
+      catch(string error){
+        cerr << error << endl;
+        exit(2);
+      }
+      catch(...){
+        cerr << "error catched" << endl;
+        exit(1);
+      }
+    }
+    int nrow=testImage.nrOfRow();
+    int ncol=testImage.nrOfCol();
+    vector<char> classOut(ncol);//classified line for writing to image file
+
+    //   assert(nband==testImage.nrOfBand());
+    ImgWriterGdal classImageBag;
+    ImgWriterGdal classImageOut;
+    ImgWriterGdal probImage;
+    string imageType=testImage.getImageType();
+    if(oformat_opt[0]!="")//default
+      imageType=oformat_opt[0];
+    try{
+      if(verbose_opt[0]>=1)
+        cout << "opening class image for writing output " << output_opt[0] << endl;
+      if(classBag_opt[0]!=""){
+        classImageBag.open(output_opt[0],ncol,nrow,nbag,GDT_Byte,imageType,option_opt);
+        classImageBag.copyGeoTransform(testImage);
+        classImageBag.setProjection(testImage.getProjection());
+      }
+      classImageOut.open(output_opt[0],ncol,nrow,1,GDT_Byte,imageType,option_opt);
+      classImageOut.copyGeoTransform(testImage);
+      classImageOut.setProjection(testImage.getProjection());
+      if(colorTable_opt[0]!="")
+        classImageOut.setColorTable(colorTable_opt[0],0);
+      if(prob_opt[0]!=""){
+        probImage.open(prob_opt[0],ncol,nrow,nreclass,GDT_Byte,imageType,option_opt);
+        probImage.copyGeoTransform(testImage);
+        probImage.setProjection(testImage.getProjection());
+      }
+    }
+    catch(string error){
+      cerr << error << endl;
+    }
+  
+    const char* pszMessage;
+    void* pProgressArg=NULL;
+    GDALProgressFunc pfnProgress=GDALTermProgress;
+    float progress=0;
+    if(!verbose_opt[0])
+      pfnProgress(progress,pszMessage,pProgressArg);
+    for(int iline=0;iline<nrow;++iline){
+      vector<float> buffer(ncol);
+      vector<short> lineMask;
+      if(mask_opt[0]!="")
+        lineMask.resize(maskReader.nrOfCol());
+      Vector2d<float> hpixel(ncol,nband);
+      Vector2d<float> fpixel(ncol);
+      Vector2d<float> prOut(nreclass,ncol);//posterior prob for each reclass
+      Vector2d<char> classBag;//classified line for writing to image file
+      if(classBag_opt[0]!="")
+        classBag.resize(nbag,ncol);
+      //read all bands of all pixels in this line in hline
+      for(int iband=start_opt[0];iband<start_opt[0]+nband;++iband){
+        if(verbose_opt[0]==2)
+          cout << "reading band " << iband << endl;
+        assert(iband>=0);
+        assert(iband<testImage.nrOfBand());
+        try{
+          testImage.readData(buffer,GDT_Float32,iline,iband);
+        }
+        catch(string theError){
+          cerr << "Error reading " << input_opt[0] << ": " << theError << endl;
+          exit(3);
+        }
+        catch(...){
+          cerr << "error catched" << endl;
+          exit(3);
+        }
+        for(int icol=0;icol<ncol;++icol)
+          hpixel[icol][iband-start_opt[0]]=buffer[icol];
+      }
+
+      assert(nband==hpixel[0].size());
+      if(verbose_opt[0]==2)
+        cout << "used bands: " << nband << endl;
+      //read mask
+      if(!lineMask.empty()){
+        try{
+          maskReader.readData(lineMask,GDT_Int16,iline);
+        }
+        catch(string theError){
+          cerr << "Error reading " << mask_opt[0] << ": " << theError << endl;
+          exit(3);
+        }
+        catch(...){
+          cerr << "error catched" << endl;
+          exit(3);
+        }
+      }
+    
+      //process per pixel
+      for(int icol=0;icol<ncol;++icol){
+        bool masked=false;
+        if(!lineMask.empty()){
+          short theMask=0;
+          for(short ivalue=0;ivalue<maskValue_opt.size();++ivalue){
+            if(maskValue_opt[ivalue]>=0){//values set in maskValue_opt are invalid
+              if(lineMask[icol]==maskValue_opt[ivalue]){
+                theMask=(flag_opt.size()==maskValue_opt.size())? flag_opt[ivalue] : flag_opt[0];// lineMask[icol];
+                masked=true;
+                break;
+              }
+            }
+            else{//only values set in maskValue_opt are valid
+              if(lineMask[icol]!=-maskValue_opt[ivalue]){
+                  theMask=(flag_opt.size()==maskValue_opt.size())? flag_opt[ivalue] : flag_opt[0];// lineMask[icol];
+                masked=true;
+              }
+              else{
+                masked=false;
+                break;
+              }
+            }
+          }
+          if(masked){
+            if(classBag_opt[0]!="")
+              for(int ibag=0;ibag<nbag;++ibag)
+                classBag[ibag][icol]=theMask;
+            classOut[icol]=theMask;
+            continue;
+          }
+        }
+        bool valid=false;
+        for(int iband=0;iband<nband;++iband){
+          if(hpixel[icol][iband]){
+            valid=true;
+            break;
+          }
+        }
+        if(!valid){
+          if(classBag_opt[0]!="")
+            for(int ibag=0;ibag<nbag;++ibag)
+              classBag[ibag][icol]=flag_opt[0];
+          classOut[icol]=flag_opt[0];
+          continue;//next column
+        }
+        for(int iclass=0;iclass<nreclass;++iclass)
+          prOut[iclass][icol]=0;
+        //----------------------------------- classification -------------------
+        for(int ibag=0;ibag<nbag;++ibag){
+          //calculate image features
+          fpixel[icol].clear();
+          for(int iband=0;iband<nband;++iband)
+            fpixel[icol].push_back((hpixel[icol][iband]-offset[ibag][iband])/scale[ibag][iband]);
+          vector<float> result(nclass);
+          result=net[ibag].run(fpixel[icol]);
+          int maxClass=0;
+          float maxP=0;
+          vector<float> pValues(nclass);
+          vector<float> prValues(nreclass);
+          vector<float> priorsReclass(nreclass);
+          for(int iclass=0;iclass<nclass;++iclass){
+            float pv=(result[iclass]+1.0)/2.0;//bring back to scale [0,1]
+            pv*=priors[iclass];
+            pValues[iclass]=pv;
+          }
+          float normReclass=0;
+          for(int iclass=0;iclass<nreclass;++iclass){
+            prValues[iclass]=0;
+            priorsReclass[iclass]=0;
+            float maxPaggreg=0;
+            for(int ic=0;ic<nclass;++ic){
+              if(vreclass[ic]==iclass){
+                priorsReclass[iclass]+=priors[ic];
+                switch(aggreg_opt[0]){
+                default:
+                case(0)://sum rule (sum posterior probabilities of aggregated individual classes)
+                  prValues[iclass]+=pValues[ic];
+                  break;
+                case(1)://max rule (look for maximum post probability of aggregated individual classes)
+                  if(pValues[ic]>maxPaggreg){
+                    maxPaggreg=pValues[ic];
+                    prValues[iclass]=maxPaggreg;
+                  }
+                  break;
+                }
+              }
+            }
+          }
+        
+          for(int iclass=0;iclass<nreclass;++iclass)
+            normReclass+=prValues[iclass];
+        
+          //calculate posterior prob of bag 
+          if(classBag_opt[0]!=""){
+            //search for max prob within bag
+            maxP=0;
+            classBag[ibag][icol]=0;
+          }
+          for(int iclass=0;iclass<nreclass;++iclass){
+            float prv=prValues[iclass];
+            prv/=normReclass;
+            //           prv*=100.0;
+            prValues[iclass]=prv;
+            switch(comb_opt[0]){
+            default:
+            case(0)://sum rule
+              prOut[iclass][icol]+=prValues[iclass]+static_cast<float>(1.0-nbag)/nbag*priorsReclass[iclass];//add probabilities for each bag
+              break;
+            case(1)://product rule
+              prOut[iclass][icol]*=pow(priorsReclass[iclass],static_cast<float>(1.0-nbag)/nbag)*prValues[iclass];//add probabilities for each bag
+              break;
+            case(2)://max rule
+              if(prValues[iclass]>prOut[iclass][icol])
+                prOut[iclass][icol]=prValues[iclass];
+              break;
+            }
+            if(classBag_opt[0]!=""){
+              //search for max prob within bag
+              if(prValues[iclass]>maxP){
+                maxP=prValues[iclass];
+                classBag[ibag][icol]=vcode[iclass];
+              }
+            }
+          }
+        }//ibag
+        //search for max class prob
+        float maxBag=0;
+        float normBag=0;
+        for(int iclass=0;iclass<nreclass;++iclass){
+          if(prOut[iclass][icol]>maxBag){
+            maxBag=prOut[iclass][icol];
+            classOut[icol]=vcode[iclass];
+          }
+          normBag+=prOut[iclass][icol];
+        }
+        //       assert(classOut[icol]);
+        //normalize prOut and convert to percentage
+        for(int iclass=0;iclass<nreclass;++iclass){
+          float prv=prOut[iclass][icol];
+          prv/=normBag;
+          prv*=100.0;
+          prOut[iclass][icol]=static_cast<short>(prv+0.5);
+        }
+      }//icol
+      //----------------------------------- write output ------------------------------------------
+      if(classBag_opt[0]!="")
+        for(int ibag=0;ibag<nbag;++ibag)
+          classImageBag.writeData(classBag[ibag],GDT_Byte,iline,ibag);
+      if(prob_opt[0]!=""){
+        for(int iclass=0;iclass<nreclass;++iclass)
+          probImage.writeData(prOut[iclass],GDT_Float32,iline,iclass);
+      }
+      classImageOut.writeData(classOut,GDT_Byte,iline);
+      if(!verbose_opt[0]){
+        progress=static_cast<float>(iline+1.0)/classImageOut.nrOfRow();
+        pfnProgress(progress,pszMessage,pProgressArg);
+      }
+    }
+    testImage.close();
+    if(prob_opt[0]!="")
+      probImage.close();
+    if(classBag_opt[0]!="")
+      classImageBag.close();
+    classImageOut.close();
+  }
+  else{//classify shape file
+    for(int ivalidation=0;ivalidation<input_opt.size();++ivalidation){
+      assert(output_opt.size()==input_opt.size());
+      if(verbose_opt[0])
+        cout << "opening img reader " << input_opt[ivalidation] << endl;
+      ImgReaderOgr imgReaderOgr(input_opt[ivalidation]);
+      if(verbose_opt[0])
+        cout << "opening img writer and copying fields from img reader" << output_opt[ivalidation] << endl;
+      ImgWriterOgr imgWriterOgr(output_opt[ivalidation],imgReaderOgr,false);
+      if(verbose_opt[0])
+        cout << "creating field class" << endl;
+      imgWriterOgr.createField("class",OFTInteger);
+      OGRFeature *poFeature;
+      unsigned int ifeature=0;
+      while( (poFeature = imgReaderOgr.getLayer()->GetNextFeature()) != NULL ){
+        if(verbose_opt[0]>1)
+          cout << "feature " << ifeature << endl;
+        if( poFeature == NULL )
+          break;
+        OGRFeature *poDstFeature = NULL;
+        poDstFeature=imgWriterOgr.createFeature();
+        if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE ){
+          CPLError( CE_Failure, CPLE_AppDefined,
+                    "Unable to translate feature %d from layer %s.\n",
+                    poFeature->GetFID(), imgWriterOgr.getLayerName().c_str() );
+          OGRFeature::DestroyFeature( poFeature );
+          OGRFeature::DestroyFeature( poDstFeature );
+        }
+        vector<float> validationPixel;
+        vector<float> validationFeature;
+        
+        imgReaderOgr.readData(validationPixel,OFTReal,fields,poFeature);
+        OGRFeature::DestroyFeature( poFeature );
+//         assert(validationPixel.size()>=start_opt[0]+nband);
+        assert(validationPixel.size()==nband);
+        vector<float> prOut(nreclass);//posterior prob for each reclass
+        for(int iclass=0;iclass<nreclass;++iclass)
+          prOut[iclass]=0;
+        for(int ibag=0;ibag<nbag;++ibag){
+//           for(int iband=start_opt[0];iband<start_opt[0]+nband;++iband){
+          for(int iband=0;iband<nband;++iband){
+//             validationFeature.push_back((validationPixel[iband]-offset[ibag][iband-start_opt[0]])/scale[ibag][iband-start_opt[0]]);
+            validationFeature.push_back((validationPixel[iband]-offset[ibag][iband])/scale[ibag][iband]);
+            if(verbose_opt[0]==2)
+              cout << " " << validationFeature.back();
+          }
+          if(verbose_opt[0]==2)
+            cout << endl;
+          vector<float> result(nclass);
+          result=net[ibag].run(validationFeature);
+          int maxClass=0;
+          float maxP=0;
+          vector<float> pValues(nclass);
+          vector<float> prValues(nreclass);
+          vector<float> priorsReclass(nreclass);
+          for(int iclass=0;iclass<nclass;++iclass){
+            float pv=(result[iclass]+1.0)/2.0;//bring back to scale [0,1]
+            pv*=priors[iclass];
+            pValues[iclass]=pv;
+          }
+          float normReclass=0;
+          for(int iclass=0;iclass<nreclass;++iclass){
+            prValues[iclass]=0;
+            priorsReclass[iclass]=0;
+            float maxPaggreg=0;
+            for(int ic=0;ic<nclass;++ic){
+              if(vreclass[ic]==iclass){
+                priorsReclass[iclass]+=priors[ic];
+                switch(aggreg_opt[0]){
+                default:
+                case(0)://sum rule (sum posterior probabilities of aggregated individual classes)
+                  prValues[iclass]+=pValues[ic];
+                  break;
+                case(1)://max rule (look for maximum post probability of aggregated individual classes)
+                  if(pValues[ic]>maxPaggreg){
+                    maxPaggreg=pValues[ic];
+                    prValues[iclass]=maxPaggreg;
+                  }
+                  break;
+                }
+              }
+            }
+          }
+          for(int iclass=0;iclass<nreclass;++iclass)
+            normReclass+=prValues[iclass];
+          //calculate posterior prob of bag 
+          for(int iclass=0;iclass<nreclass;++iclass){
+            float prv=prValues[iclass];
+            prv/=normReclass;
+            //           prv*=100.0;
+            prValues[iclass]=prv;
+            switch(comb_opt[0]){
+            default:
+            case(0)://sum rule
+              prOut[iclass]+=prValues[iclass]+static_cast<float>(1.0-nbag)/nbag*priorsReclass[iclass];//add probabilities for each bag
+              break;
+            case(1)://product rule
+              prOut[iclass]*=pow(priorsReclass[iclass],static_cast<float>(1.0-nbag)/nbag)*prValues[iclass];//add probabilities for each bag
+              break;
+            case(2)://max rule
+              if(prValues[iclass]>prOut[iclass])
+                prOut[iclass]=prValues[iclass];
+              break;
+            }
+          }
+        }//for ibag
+        //search for max class prob
+        float maxBag=0;
+        float normBag=0;
+        char classOut=0;
+        for(int iclass=0;iclass<nreclass;++iclass){
+          if(prOut[iclass]>maxBag){
+            maxBag=prOut[iclass];
+            classOut=vcode[iclass];
+          }
+          normBag+=prOut[iclass];
+        }
+        //normalize prOut and convert to percentage
+        for(int iclass=0;iclass<nreclass;++iclass){
+          float prv=prOut[iclass];
+          prv/=normBag;
+          prv*=100.0;
+          prOut[iclass]=static_cast<short>(prv+0.5);
+        }
+        poDstFeature->SetField("class",classOut);
+        poDstFeature->SetFID( poFeature->GetFID() );
+        CPLErrorReset();
+        if(imgWriterOgr.createFeature( poDstFeature ) != OGRERR_NONE){
+          CPLError( CE_Failure, CPLE_AppDefined,
+                    "Unable to translate feature %d from layer %s.\n",
+                    poFeature->GetFID(), imgWriterOgr.getLayerName().c_str() );
+          OGRFeature::DestroyFeature( poDstFeature );
+          OGRFeature::DestroyFeature( poDstFeature );
+        }
+        ++ifeature;
+      }
+      imgReaderOgr.close();
+      imgWriterOgr.close();
+    }
+  }
+  return 0;
+}
diff --git a/src/apps/pkclassify_nn.h b/src/apps/pkclassify_nn.h
new file mode 100644
index 0000000..4e11dea
--- /dev/null
+++ b/src/apps/pkclassify_nn.h
@@ -0,0 +1,131 @@
+/**********************************************************************
+pkclassify_nn.h: classify raster image using Artificial Neural Network
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <map>
+#include "imageclasses/ImgReaderOgr.h"
+#include "base/Vector2d.h"
+
+#ifndef _PKCLASSIFY_NN_H_
+#define _PKCLASSIFY_NN_H_
+
+using namespace std;
+
+template<typename T> unsigned int readDataImageShape(const string &filename,
+                                                     map<int,Vector2d<T> > &mapPixels, //[classNr][pixelNr][bandNr],
+                                                     vector<string>& fields,
+                                                     double start,
+                                                     double end,
+                                                     const string& label,
+                                                     const string& query="",
+                                                     int verbose=false);
+
+
+template<typename T> unsigned int readDataImageShape(const string &filename,
+                                                     map<int,Vector2d<T> > &mapPixels, //[classNr][pixelNr][bandNr],
+                                                     vector<string>& fields,
+                                                     double start,
+                                                     double end,
+                                                     const string& label,
+                                                     const string& query,
+                                                     int verbose)
+{
+  mapPixels.clear();
+  int nsample=0;
+  int totalSamples=0;  
+  int nband=0;
+  if(verbose)
+    cout << "reading shape file " << filename  << endl;
+  ImgReaderOgr imgReaderShape;
+  try{
+    imgReaderShape.open(filename);
+    bool queryFound=false;
+    //only retain bands in fields
+    imgReaderShape.getFields(fields);
+    vector<string>::iterator fit=fields.begin();
+    if(verbose)
+      cout << "reading fields: ";
+    while(fit!=fields.end()){
+      if(verbose)
+        cout << *fit << " ";
+      size_t pos=(*fit).find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ");
+      if(pos==string::npos){
+        if(query!=""){
+          if((*fit).find(query)!=string::npos)
+            queryFound=true;
+        }
+        fields.erase(fit);
+      }
+      else{
+        string fieldname=(*fit).substr(pos);
+          int iband=atoi(fieldname.c_str());
+          if((start||end)&&(iband<start||iband>end))
+            fields.erase(fit);
+          else
+            ++fit;
+      }
+    }
+    if(verbose)
+      cout << endl;
+    if(verbose){
+      cout << "fields:";
+      for(vector<string>::iterator fit=fields.begin();fit!=fields.end();++fit)
+        cout << " " << *fit;
+      cout << endl;
+    }
+    if(!nband){
+      if(queryFound){
+        ostringstream qs;
+        qs << "select * from " << imgReaderShape.getLayerName() << " where " << query << "=1";
+        if(verbose)
+          cout << "reading with sql: " << qs.str() << endl;
+        nband=imgReaderShape.readSql(mapPixels,OFTReal,fields,label,qs.str(),NULL,0,true,false);
+      }
+      else{
+        if(verbose)
+          cout << "reading data" << endl;
+        nband=imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,true,verbose==2);
+      }
+    }
+    else{
+      if(queryFound){
+        ostringstream qs;
+        qs << "select * from " << imgReaderShape.getLayerName() << " where " << query << "=1";
+        if(verbose)
+          cout << "reading with sql: " << qs.str() << endl;
+        assert(nband==imgReaderShape.readSql(mapPixels,OFTReal,fields,label,qs.str(),NULL,0,true,false));
+      }
+      else        
+        assert(nband==imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,true,false));
+    }
+  }
+  catch(string e){
+    ostringstream estr;
+    estr << e << " " << filename;
+    throw(estr.str());
+  }
+  nsample=imgReaderShape.getFeatureCount();
+  totalSamples+=nsample;
+  if(verbose)
+    cout << ": " << nsample << " samples read with " << nband << " bands" << endl;
+  imgReaderShape.close();
+  if(verbose)
+    cout << "total number of samples read " << totalSamples << endl;
+  return totalSamples;
+}
+#endif //_PKCLASSIFY_NN_H_
diff --git a/src/apps/pkcreatect.cc b/src/apps/pkcreatect.cc
new file mode 100644
index 0000000..da2aeeb
--- /dev/null
+++ b/src/apps/pkcreatect.cc
@@ -0,0 +1,207 @@
+/**********************************************************************
+pkcreatect.cc: program to create and import colour table to GTiff image
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <iostream>
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "base/Optionpk.h"
+
+using namespace std;
+
+int main(int argc,char **argv) {
+
+  short red=-1;
+  short green=-1;
+  short blue=-1;
+
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","",false);
+  Optionpk<string>  input_opt("i", "input", "Input image file", "");
+  Optionpk<string>  output_opt("o", "output", "Output image file", "");
+  Optionpk<string>  legend_opt("l", "legend", "Create legend as png file", "");
+  Optionpk<short>  dim_opt("d", "dim", "number of columns and rows in legend (Default is 100 cols x max-min+1 rows", 100);
+  Optionpk<double>  min_opt("m", "min", "minimum value", 0);
+  Optionpk<double>  max_opt("M", "max", "maximum value", 100);
+  Optionpk<bool>  grey_opt("g", "grey", "grey scale (default is false)", false);
+  Optionpk<string>  colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "GTiff");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<string>  description_opt("\0", "description", "Set image description", "");
+  Optionpk<bool>  verbose_opt("v", "verbose", "verbose", false);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  input_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  legend_opt.retrieveOption(argc,argv);
+  dim_opt.retrieveOption(argc,argv);
+  min_opt.retrieveOption(argc,argv);
+  max_opt.retrieveOption(argc,argv);
+  grey_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  description_opt.retrieveOption(argc,argv);
+  oformat_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << "usage: pkcreatect -i inputimage -o outputimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  GDALColorTable colorTable;
+  GDALColorEntry sEntry;
+  if(colorTable_opt[0]==""){
+    sEntry.c4=255;
+    for(int i=min_opt[0];i<=max_opt[0];++i){
+      if(grey_opt[0]){
+        sEntry.c1=255*(i-min_opt[0])/(max_opt[0]-min_opt[0]);
+        sEntry.c2=255*(i-min_opt[0])/(max_opt[0]-min_opt[0]);
+        sEntry.c3=255*(i-min_opt[0])/(max_opt[0]-min_opt[0]);
+      }
+      else{//hot to cold colour ramp
+        sEntry.c1=255;
+        sEntry.c2=255;
+        sEntry.c3=255;
+        double delta=max_opt[0]-min_opt[0];
+        if(i<(min_opt[0]+0.25*delta)){
+          sEntry.c1=0;
+          sEntry.c2=255*4*(i-min_opt[0])/delta;
+        }
+        else if(i<(min_opt[0]+0.5*delta)){
+          sEntry.c1=0;
+          sEntry.c3=255*(1+4*(min_opt[0]+0.25*delta-i)/delta);
+        }
+        else if(i<(min_opt[0]+0.75*delta)){
+          sEntry.c1=255*4*(i-min_opt[0]-0.5*delta)/delta;
+          sEntry.c3=0;
+        }
+        else{
+          sEntry.c2=255*(1+4*(min_opt[0]+0.75*delta-i)/delta);
+          sEntry.c3=0;
+        }
+      }
+      colorTable.SetColorEntry(i,&sEntry);
+      if(output_opt[0]=="")
+        cout << i << " " << sEntry.c1 << " " << sEntry.c2 << " " << sEntry.c3 << " " << sEntry.c4 << endl;
+    }
+  }
+  ImgWriterGdal legendWriter;
+  short ncol=dim_opt[0];
+  short nrow;
+  if(legend_opt[0]!=""){
+    if(dim_opt.size()>1)
+      nrow=dim_opt[1];
+    else{
+      nrow=max_opt[0]-min_opt[0]+1;
+      ncol=dim_opt[0];
+    }
+    vector<string> pngOption;
+    // pngOption.push_back("-co worldfile=no");
+    pngOption.push_back("");
+    legendWriter.open(legend_opt[0],ncol,nrow,1,GDT_Byte,oformat_opt[0],option_opt);
+    if(colorTable_opt[0]!=""){
+      if(colorTable_opt[0]!="none")
+        legendWriter.setColorTable(colorTable_opt[0]);
+    }
+    else
+      legendWriter.setColorTable(&colorTable);
+    if(legend_opt[0]!=""){
+      for(int irow=0;irow<legendWriter.nrOfRow();++irow){
+        vector<char> buffer(legendWriter.nrOfCol());
+        for(int icol=0;icol<legendWriter.nrOfCol();++icol)
+          buffer[icol]=min_opt[0]+irow*static_cast<short>(max_opt[0]-min_opt[0]+1)/legendWriter.nrOfRow();
+        legendWriter.writeData(buffer,GDT_Byte,legendWriter.nrOfRow()-1-irow);
+      }
+    }
+  }
+
+  // const char* pszMessage;
+  // void* pProgressArg=NULL;
+  // GDALProgressFunc pfnProgress=GDALTermProgress;
+  // double progress=0;
+  // pfnProgress(progress,pszMessage,pProgressArg);
+  if(input_opt[0]!=""&&output_opt[0]!=""){
+    ImgReaderGdal imgReader(input_opt[0]);
+    ImgWriterGdal imgWriter;
+    imgWriter.open(output_opt[0],imgReader.nrOfCol(),imgReader.nrOfRow(),1,GDT_Byte,oformat_opt[0],option_opt);
+
+    imgWriter.copyGeoTransform(imgReader);
+    if(colorTable_opt[0]!=""){
+      if(colorTable_opt[0]!="none")
+        imgWriter.setColorTable(colorTable_opt[0]);
+    }
+    else
+      imgWriter.setColorTable(&colorTable);
+    if(description_opt[0]!="")
+      imgWriter.setImageDescription(description_opt[0]);
+    switch(imgReader.getDataType()){
+    case(GDT_Byte):{
+      vector<char> buffer;
+      for(int irow=0;irow<imgReader.nrOfRow();++irow){
+        imgReader.readData(buffer,GDT_Byte,irow);
+        imgWriter.writeData(buffer,GDT_Byte,irow);
+      }
+      break;
+    }
+    case(GDT_Int16):{
+      vector<short> buffer;
+      cout << "Warning: copying short to unsigned short without conversion, use gdal_translate -scale if needed..." << endl;
+      for(int irow=0;irow<imgReader.nrOfRow();++irow){
+        imgReader.readData(buffer,GDT_Int16,irow,0);
+        imgWriter.writeData(buffer,GDT_Int16,irow,0);
+      }
+      break;
+    }
+    case(GDT_UInt16):{
+      vector<unsigned short> buffer;
+      for(int irow=0;irow<imgReader.nrOfRow();++irow){
+        imgReader.readData(buffer,GDT_UInt16,irow,0);
+        imgWriter.writeData(buffer,GDT_UInt16,irow,0);
+      }
+      break;
+    }
+    default:
+      cerr << "data type " << imgReader.getDataType() << " not supported for adding a colortable" << endl;
+      break;
+    }
+    imgReader.close();
+    imgWriter.close();
+  }
+  if(legend_opt[0]!="")
+    legendWriter.close();
+}
+
diff --git a/src/apps/pkcrop.cc b/src/apps/pkcrop.cc
new file mode 100644
index 0000000..38a762c
--- /dev/null
+++ b/src/apps/pkcrop.cc
@@ -0,0 +1,475 @@
+/**********************************************************************
+pkcrop.cc: perform raster data operations on image such as crop, extract and stack bands
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************/
+#include <assert.h>
+#include <string>
+#include <list>
+#include <iostream>
+#include "imageclasses/ImgWriterGdal.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgReaderOgr.h"
+#include "base/Optionpk.h"
+#include "algorithms/Egcs.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","introduce -uli -ulj to crop based on image coordinates",false);
+  Optionpk<string>  input_opt("i", "input", "Input image file(s). If input contains multiple images, a multi-band output is created", "");
+  Optionpk<string>  output_opt("o", "output", "Output image file", "");
+  Optionpk<string>  projection_opt("p", "projection", "projection in EPSG format (leave blank to copy from input file, use EPSG:3035 to use European projection and to force to European grid", "");
+  Optionpk<string>  extent_opt("e", "extent", "get boundary from extent from polygons in vector file", "");
+  Optionpk<bool> mask_opt("m","mask","mask values out of polygon in extent file to flag option (tip: for better performance, use gdal_rasterize -i -burn 0 -l extent extent.shp output (with output the result of pkcrop)",false);
+  Optionpk<double>  ulx_opt("ulx", "ulx", "Upper left x value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double>  uly_opt("uly", "uly", "Upper left y value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double>  lrx_opt("lrx", "lrx", "Lower right x value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double>  lry_opt("lry", "lry", "Lower right y value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double>  dx_opt("dx", "dx", "Output resolution in x (in meter) (0.0: keep original resolution)", 0.0);
+  Optionpk<double>  dy_opt("dy", "dy", "Output resolution in y (in meter) (0.0: keep original resolution)", 0.0);
+  Optionpk<int>  band_opt("b", "band", "band index to crop (-1: crop all bands)", -1);
+  Optionpk<double> scale_opt("s", "scale", "output=scale*input+offset", 1);
+  Optionpk<double> offset_opt("\0", "offset", "output=scale*input+offset", 0);
+  Optionpk<string>  otype_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "");
+  Optionpk<string>  oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "");
+  Optionpk<string>  colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<short>  flag_opt("f", "flag", "Flag value to put in image if out of bounds.", 0);
+  Optionpk<string>  resample_opt("r", "resampling-method", "Resampling method (near: nearest neighbour, bilinear: bi-linear interpolation).", "near");
+  Optionpk<string>  description_opt("\0", "description", "Set image description", "");
+  Optionpk<bool>  verbose_opt("v", "verbose", "verbose", false);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  input_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  projection_opt.retrieveOption(argc,argv);
+  extent_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  ulx_opt.retrieveOption(argc,argv);
+  uly_opt.retrieveOption(argc,argv);
+  lrx_opt.retrieveOption(argc,argv);
+  lry_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  scale_opt.retrieveOption(argc,argv);
+  offset_opt.retrieveOption(argc,argv);
+  otype_opt.retrieveOption(argc,argv);
+  oformat_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  dx_opt.retrieveOption(argc,argv);
+  dy_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  flag_opt.retrieveOption(argc,argv);
+  resample_opt.retrieveOption(argc,argv);
+  description_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  if(help_opt[0]){
+    cout << "usage: pkcrop -i inputimage -o outputimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  RESAMPLE theResample;
+  if(resample_opt[0]=="near"){
+    theResample=NEAR;
+    if(verbose_opt[0])
+      cout << "resampling: nearest neighbour" << endl;
+  }
+  else if(resample_opt[0]=="bilinear"){
+    theResample=BILINEAR;
+    if(verbose_opt[0])
+      cout << "resampling: bilinear interpolation" << endl;
+  }
+  else{
+    std::cout << "Error: resampling method " << resample_opt[0] << " not supported" << std::endl;
+    exit(1);
+  }
+
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  ImgReaderGdal imgReader;
+  ImgWriterGdal imgWriter;
+  GDALDataType theType=GDT_Unknown;
+  if(verbose_opt[0])
+    cout << "possible output data types: ";
+  for(int iType = 0; iType < GDT_TypeCount; ++iType){
+    if(verbose_opt[0])
+      cout << " " << GDALGetDataTypeName((GDALDataType)iType);
+    if( GDALGetDataTypeName((GDALDataType)iType) != NULL
+        && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
+                 otype_opt[0].c_str()))
+      theType=(GDALDataType) iType;
+  }
+  if(verbose_opt[0]){
+    cout << endl;
+    if(theType==GDT_Unknown)
+      cout << "Unknown output pixel type: " << otype_opt[0] << endl;
+    else
+      cout << "Output pixel type:  " << GDALGetDataTypeName(theType) << endl;
+  }
+  double dx=dx_opt[0];
+  double dy=dy_opt[0];
+  //bounding box of cropped image
+  double cropulx=ulx_opt[0];
+  double cropuly=uly_opt[0];
+  double croplrx=lrx_opt[0];
+  double croplry=lry_opt[0];
+  //get bounding box from extentReader if defined
+  ImgReaderOgr extentReader;
+  if(extent_opt[0]!=""){
+    for(int iextent=0;iextent<extent_opt.size();++iextent){
+      extentReader.open(extent_opt[iextent]);
+      if(!(extentReader.getExtent(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))){
+        cerr << "Error: could not get extent from " << extent_opt[0] << endl;
+        exit(1);
+      }
+      if(ulx_opt[0]<cropulx)
+        cropulx=ulx_opt[0];
+      if(uly_opt[0]>cropuly)
+        cropuly=uly_opt[0];
+      if(lry_opt[0]<croplry)
+        croplry=lry_opt[0];
+      if(lrx_opt[0]>croplrx)
+        croplrx=lrx_opt[0];
+      extentReader.close();
+    }
+    if(mask_opt[0])
+      extentReader.open(extent_opt[0]);
+  }
+  if(verbose_opt[0])
+    cout << "--ulx=" << ulx_opt[0] << " --uly=" << uly_opt[0] << " --lrx=" << lrx_opt[0] << " --lry=" << lry_opt[0] << endl;
+  //determine number of output bands
+  int ncropband=0;//total number of bands to write
+  int writeBand=0;//write band
+  for(int iimg=0;iimg<input_opt.size();++iimg){
+    imgReader.open(input_opt[iimg]);
+    if(band_opt[0]>=0)
+      ncropband+=band_opt.size();
+    else
+      ncropband+=imgReader.nrOfBand();
+    imgReader.close();
+  }
+  for(int iimg=0;iimg<input_opt.size();++iimg){
+    if(verbose_opt[0])
+      cout << "opening image " << input_opt[iimg] << endl;
+    imgReader.open(input_opt[iimg]);
+    //if output type not set, get type from input image
+    if(theType==GDT_Unknown){
+      theType=imgReader.getDataType();
+      if(verbose_opt[0])
+        cout << "Using data type from input image: " << GDALGetDataTypeName(theType) << endl;
+    }
+    int nrow=imgReader.nrOfRow();
+    int ncol=imgReader.nrOfCol();
+    int ncropcol=0;
+    int ncroprow=0;
+    if(!dx||!dy){
+      dx=imgReader.getDeltaX();
+      dy=imgReader.getDeltaY();
+    }
+    if(verbose_opt[0])
+      cout << "size of " << input_opt[iimg] << ": " << ncol << " cols, "<< nrow << " rows" << endl;
+    double uli,ulj,lri,lrj;//image coordinates
+    if(ulx_opt[0]>=lrx_opt[0]){//default bounding box: no cropping
+      uli=0;
+      lri=imgReader.nrOfCol()-1;
+      ulj=0;
+      lrj=imgReader.nrOfRow()-1;
+      ncropcol=imgReader.nrOfCol();
+      ncroprow=imgReader.nrOfRow();
+      imgReader.getBoundingBox(cropulx,cropuly,croplrx,croplry);
+      double magicX=1,magicY=1;
+      // imgReader.getMagicPixel(magicX,magicY);
+      if(!imgReader.getProjection().compare("ETRS-LAEA")||!projection_opt[0].compare("EPSG:3035")||!projection_opt[0].compare("epsg:3035")){
+	//force to LAEA grid
+	Egcs egcs;
+        egcs.setLevel(egcs.res2level(dx));
+	egcs.force2grid(cropulx,cropuly,croplrx,croplry);
+	imgReader.geo2image(cropulx+(magicX-1.0)*imgReader.getDeltaX(),cropuly-(magicY-1.0)*imgReader.getDeltaY(),uli,ulj);
+	imgReader.geo2image(croplrx+(magicX-2.0)*imgReader.getDeltaX(),croplry-(magicY-2.0)*imgReader.getDeltaY(),lri,lrj);
+      }
+      imgReader.geo2image(cropulx+(magicX-1.0)*imgReader.getDeltaX(),cropuly-(magicY-1.0)*imgReader.getDeltaY(),uli,ulj);
+      imgReader.geo2image(croplrx+(magicX-2.0)*imgReader.getDeltaX(),croplry-(magicY-2.0)*imgReader.getDeltaY(),lri,lrj);
+      ncropcol=ceil((croplrx-cropulx)/dx);
+      ncroprow=ceil((cropuly-croplry)/dy);
+    }
+    else{
+      double magicX=1,magicY=1;
+      // imgReader.getMagicPixel(magicX,magicY);
+      cropulx=ulx_opt[0];
+      cropuly=uly_opt[0];
+      croplrx=lrx_opt[0];
+      croplry=lry_opt[0];
+      if(!imgReader.getProjection().compare("ETRS-LAEA")||!projection_opt[0].compare("EPSG:3035")||!projection_opt[0].compare("epsg:3035")){
+	//force to LAEA grid
+	Egcs egcs;
+        egcs.setLevel(egcs.res2level(dx));
+	egcs.force2grid(cropulx,cropuly,croplrx,croplry);
+	imgReader.geo2image(cropulx+(magicX-1.0)*imgReader.getDeltaX(),cropuly-(magicY-1.0)*imgReader.getDeltaY(),uli,ulj);
+	imgReader.geo2image(croplrx+(magicX-2.0)*imgReader.getDeltaX(),croplry-(magicY-2.0)*imgReader.getDeltaY(),lri,lrj);
+      }
+      imgReader.geo2image(cropulx+(magicX-1.0)*imgReader.getDeltaX(),cropuly-(magicY-1.0)*imgReader.getDeltaY(),uli,ulj);
+      imgReader.geo2image(croplrx+(magicX-2.0)*imgReader.getDeltaX(),croplry-(magicY-2.0)*imgReader.getDeltaY(),lri,lrj);
+
+      ncropcol=ceil((croplrx-cropulx)/dx);
+      ncroprow=ceil((cropuly-croplry)/dy);
+      uli=floor(uli);
+      ulj=floor(ulj);
+      lri=floor(lri);
+      lrj=floor(lrj);
+    }
+
+    double dcropcol=0;
+    double dcroprow=0;
+    double deltaX=imgReader.getDeltaX();
+    double deltaY=imgReader.getDeltaY();
+    dcropcol=(lri-uli+1)/(dx/deltaX);
+    dcroprow=(lrj-ulj+1)/(dy/deltaY);
+    if(!imgWriter.nrOfBand()){//not opened yet
+      if(verbose_opt[0]){
+	cout << "cropulx: " << cropulx << endl;
+	cout << "cropuly: " << cropuly << endl;
+	cout << "croplrx: " << croplrx << endl;
+	cout << "croplry: " << croplry << endl;
+	cout << "ncropcol: " << ncropcol << endl;
+	cout << "ncroprow: " << ncroprow << endl;
+	cout << "cropulx+ncropcol*dx: " << cropulx+ncropcol*dx << endl;
+	cout << "cropuly-ncroprow*dy: " << cropuly-ncroprow*dy << endl;
+	cout << "upper left column of input image: " << uli << endl;
+	cout << "upper left row of input image: " << ulj << endl;
+	cout << "lower right column of input image: " << lri << endl;
+	cout << "lower right row of input image: " << lrj << endl;
+	cout << "new number of cols: " << ncropcol << endl;
+	cout << "new number of rows: " << ncroprow << endl;
+	cout << "new number of bands: " << ncropband << endl;
+      }
+      // string theCompression;
+      // if(compress_opt[0]!="")//default
+      //   theCompression=compress_opt[0];
+      // else
+      //   theCompression=imgReader.getCompression();
+      // string theInterleave;
+      // if(interleave_opt[0]!="")//default
+      //   theInterleave=interleave_opt[0];
+      // else
+      //   theInterleave=imgReader.getInterleave();
+      string imageType=imgReader.getImageType();
+      if(oformat_opt[0]!="")//default
+        imageType=oformat_opt[0];
+      try{
+        imgWriter.open(output_opt[0],ncropcol,ncroprow,ncropband,theType,imageType,option_opt);
+      }
+      catch(string errorstring){
+        cout << errorstring << endl;
+        exit(4);
+      }
+      if(description_opt[0]!="")
+	imgWriter.setImageDescription(description_opt[0]);
+      imgWriter.setGeoTransform(cropulx,cropuly,dx,dy,0,0);
+      if(projection_opt[0]!=""){
+	if(verbose_opt[0])
+	  cout << "projection: " << projection_opt[0] << endl;
+	imgWriter.setProjectionProj4(projection_opt[0]);
+      }
+      else if(imgReader.isGeoRef())
+	imgWriter.setProjection(imgReader.getProjection());
+      if(colorTable_opt[0]!=""){
+        if(verbose_opt[0])
+          cout << "set colortable " << colorTable_opt[0] << endl;
+        assert(imgWriter.getDataType()==GDT_Byte);
+        imgWriter.setColorTable(colorTable_opt[0]);
+      }
+      else if(imgReader.getColorTable()!=NULL){
+        if(verbose_opt[0])
+          cout << "set colortable from input image" << endl;
+        imgWriter.setColorTable(imgReader.getColorTable());
+      }
+    }
+    double startCol=uli;
+    double endCol=lri;
+    if(uli<0)
+      startCol=0;
+    else if(uli>=imgReader.nrOfCol())
+      startCol=imgReader.nrOfCol()-1;
+    if(lri<0)
+      endCol=0;
+    else if(lri>=imgReader.nrOfCol())
+      endCol=imgReader.nrOfCol()-1;
+    int readncol=endCol-startCol+1;
+    //test
+    // vector<double> readBuffer(readncol);
+    vector<double> readBuffer(readncol+1);
+    int nband=(band_opt[0]<0)?imgReader.nrOfBand():band_opt.size();
+    for(int iband=0;iband<nband;++iband){
+      int readBand=(band_opt[0]<0)?iband:band_opt[iband];
+      if(verbose_opt[0]){
+	cout << "extracting band " << readBand << endl;
+	pfnProgress(progress,pszMessage,pProgressArg);
+      }
+      double readRow=0;
+      double readCol=0;
+      double lowerCol=0;
+      double upperCol=0;
+      for(int irow=0;irow<ncroprow;++irow){
+	double x=0;
+	double y=0;
+	//convert irow to geo
+	imgWriter.image2geo(0,irow,x,y);
+	//lookup corresponding row for irow in this file
+	imgReader.geo2image(x,y,readCol,readRow);
+	// double lowerCol=0;
+	// double upperCol=0;
+	vector<double> writeBuffer;
+	if(readRow<0||readRow>=imgReader.nrOfRow()){
+	  //if(readRow<0)
+	  //readRow=0;
+	  //else if(readRow>=imgReader.nrOfRow())
+	  //readRow=imgReader.nrOfRow()-1;
+	  for(int ib=0;ib<ncropcol;++ib)
+	    writeBuffer.push_back(flag_opt[0]);
+	}
+	else{
+	  try{
+            if(endCol<imgReader.nrOfCol()-1)
+              imgReader.readData(readBuffer,GDT_Float64,startCol,endCol+1,readRow,readBand,theResample);
+            else
+              imgReader.readData(readBuffer,GDT_Float64,startCol,endCol,readRow,readBand,theResample);
+            //test
+	    // imgReader.readData(readBuffer,GDT_Float64,startCol,endCol,readRow,readBand,theResample);
+	    for(int ib=0;ib<ncropcol;++ib){
+	      assert(imgWriter.image2geo(ib,irow,x,y));
+	      //lookup corresponding row for irow in this file
+	      imgReader.geo2image(x,y,readCol,readRow);
+	      if(readCol<0||readCol>=imgReader.nrOfCol()){
+	      // if(readCol<0||readCol>=imgReader.nrOfCol()){
+		//               if(readCol<0)
+		//                 readCol=0;
+		//               else if(readCol>=imgReader.nrOfCol())
+		//                 readCol=imgReader.nrOfCol()-1;
+		writeBuffer.push_back(flag_opt[0]);
+	      }
+	      else{
+                bool valid=true;
+                if(mask_opt[0]&&extent_opt[0]!=""){
+                  valid=false;
+                  OGRPoint thePoint;
+                  thePoint.setX(x);
+                  thePoint.setY(y);
+                  OGRLayer  *readLayer;
+                  readLayer = extentReader.getDataSource()->GetLayer(0);
+                  readLayer->ResetReading();
+                  OGRFeature *readFeature;
+                  while( (readFeature = readLayer->GetNextFeature()) != NULL ){
+                    OGRGeometry *poGeometry;
+                    poGeometry = readFeature->GetGeometryRef();
+                    assert(poGeometry!=NULL);
+                    //check if point is on surface
+                    OGRPolygon readPolygon = *((OGRPolygon *) poGeometry);
+                    readPolygon.closeRings();
+                    if(readPolygon.Contains(&thePoint)){
+                      valid=true;
+                      break;
+                    }
+                    else
+                      continue;
+                  }
+                }
+                if(!valid)
+                  writeBuffer.push_back(flag_opt[0]);
+                else{
+                  switch(theResample){
+                  case(BILINEAR):
+                    lowerCol=readCol-0.5;
+                    lowerCol=static_cast<int>(lowerCol);
+                    upperCol=readCol+0.5;
+                    upperCol=static_cast<int>(upperCol);
+                    if(lowerCol<0)
+                      lowerCol=0;
+                    if(upperCol>=imgReader.nrOfCol())
+                      upperCol=imgReader.nrOfCol()-1;
+                    writeBuffer.push_back((readCol-0.5-lowerCol)*(readBuffer[upperCol-startCol]*scale_opt[0]+offset_opt[0])+(1-readCol+0.5+lowerCol)*(readBuffer[lowerCol-startCol]*scale_opt[0]+offset_opt[0]));
+                    break;
+                  default:
+                    readCol=static_cast<int>(readCol);
+                    readCol-=startCol;//we only start reading from startCol
+                    writeBuffer.push_back(readBuffer[readCol]*scale_opt[0]+offset_opt[0]);
+                    break;
+                  }
+                }
+	      }
+	    }
+	  }
+	  catch(string errorstring){
+	    cout << errorstring << endl;
+	    exit(2);
+	  }
+	}
+	assert(writeBuffer.size()==ncropcol);
+	assert(writeBuffer.size()==imgWriter.nrOfCol());
+	try{
+	  imgWriter.writeData(writeBuffer,GDT_Float64,irow,writeBand);
+	}
+	catch(string errorstring){
+	  cout << errorstring << endl;
+	  exit(3);
+	}
+	if(verbose_opt[0]){
+	  progress=(1.0+irow);
+	  progress/=imgWriter.nrOfRow();
+	  pfnProgress(progress,pszMessage,pProgressArg);
+	}
+	else{
+	  progress=(1.0+irow);
+	  progress+=(imgWriter.nrOfRow()*writeBand);
+	  progress/=imgWriter.nrOfBand()*imgWriter.nrOfRow();
+	  assert(progress>=0);
+	  assert(progress<=1);
+	  pfnProgress(progress,pszMessage,pProgressArg);
+	}
+      }
+      ++writeBand;
+    }
+    imgReader.close();
+  }
+  if(extent_opt[0]!=""){
+    extentReader.close();
+  }
+  imgWriter.close();
+}
diff --git a/src/apps/pkdiff.cc b/src/apps/pkdiff.cc
new file mode 100644
index 0000000..6ff83b7
--- /dev/null
+++ b/src/apps/pkdiff.cc
@@ -0,0 +1,732 @@
+/**********************************************************************
+pkdiff.cc: program to compare two raster image files
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <assert.h>
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "imageclasses/ImgReaderOgr.h"
+#include "imageclasses/ImgWriterOgr.h"
+#include "Optionpk.h"
+#include "algorithms/ConfusionMatrix.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","todo: support different data types",false);
+  Optionpk<string> input_opt("i", "input", "Input image file.", "");
+  Optionpk<string> reference_opt("r", "reference", "Reference image file", "");
+  Optionpk<string> output_opt("o", "output", "Output image file. Default is empty: no output image, only report difference or identical.", "");
+  Optionpk<string> mask_opt("m", "mask", "Mask image file. A single mask is supported only, but several mask values can be used. See also mflag option. (default is empty)", "");
+  Optionpk<string> colorTable_opt("\0", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<short> valueE_opt("\0", "correct", "Value for correct pixels (0)", 0);
+  Optionpk<short> valueO_opt("\0", "omission", "Value for omission errors: input label > reference label (default value is 1)", 1);
+  Optionpk<short> valueC_opt("\0", "commission", "Value for commission errors: input label < reference label (default value is 2)", 2);
+  Optionpk<short> flag_opt("f", "flag", "No value flag(s)", 0);
+  Optionpk<short> mflag_opt("m", "mflag", "Mask value(s) for invalid data (positive value), or for valid data (negative value). Default is 0", 0);
+  Optionpk<short> band_opt("b", "band", "Band to extract (0)", 0);
+  Optionpk<bool> confusion_opt("cm", "confusion", "create confusion matrix (to std out) (default value is 0)", false);
+  Optionpk<short> lzw_opt("\0", "lzw", "compression (default value is 1)", 1);
+  Optionpk<string> labelref_opt("lr", "lref", "name of the reference label in case reference is shape file(default is label)", "label");
+  Optionpk<string> labelclass_opt("lc", "lclass", "name of the classified label in case output is shape file (default is class)", "class");
+  Optionpk<short> class_opt("c", "class", "numeric classes used (must cover range in input and reference raster image. Leave empty if range must be read from first input image (default)", 0);
+  Optionpk<short> boundary_opt("\0", "boundary", "boundary for selecting the sample (default: 1)", 1);
+  Optionpk<bool> disc_opt("\0", "circular", "use circular disc kernel boundary)", false);
+  Optionpk<bool> homogeneous_opt("\0", "homogeneous", "only take homogeneous regions into account", false);
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<short> verbose_opt("v", "verbose", "verbose (default value is 0)", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  input_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  reference_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  valueE_opt.retrieveOption(argc,argv);
+  valueO_opt.retrieveOption(argc,argv);
+  valueC_opt.retrieveOption(argc,argv);
+  flag_opt.retrieveOption(argc,argv);
+  mflag_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  confusion_opt.retrieveOption(argc,argv);
+  lzw_opt.retrieveOption(argc,argv);
+  labelref_opt.retrieveOption(argc,argv);
+  labelclass_opt.retrieveOption(argc,argv);
+  class_opt.retrieveOption(argc,argv);
+  boundary_opt.retrieveOption(argc,argv);
+  disc_opt.retrieveOption(argc,argv);
+  homogeneous_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << "usage: pkdiff -i inputimage -r referenceimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  ImgReaderGdal inputReader;
+  ImgReaderGdal maskReader;
+
+  if(verbose_opt[0]){
+    cout << "flag(s) set to";
+    for(int iflag=0;iflag<flag_opt.size();++iflag)
+      cout << " " << flag_opt[iflag];
+    cout << endl;
+  }
+  if(mask_opt[0]!="")
+    assert(mask_opt.size()==input_opt.size());
+  vector<short> inputRange;
+  vector<short> referenceRange;
+  if(class_opt.size()>1)
+    inputRange=class_opt;
+  else{
+    try{
+      if(verbose_opt[0])
+        cout << "opening input image file " << input_opt[0] << endl;
+      inputReader.open(input_opt[0]);//,imagicX_opt[0],imagicY_opt[0]);
+    }
+    catch(string error){
+      cerr << error << endl;
+      exit(1);
+    }
+    inputReader.getRange(inputRange,band_opt[0]);
+    inputReader.close();
+  }
+  
+  for(int iflag=0;iflag<flag_opt.size();++iflag){
+    vector<short>::iterator fit;
+    fit=find(inputRange.begin(),inputRange.end(),flag_opt[iflag]);
+    if(fit!=inputRange.end())
+      inputRange.erase(fit);
+  }
+  int nclass=inputRange.size();
+  vector<string> classNames;
+  if(verbose_opt[0]){
+    cout << "nclass (inputRange.size()): " << nclass << endl;
+    cout << "input range: " << endl;
+  }
+  for(int rc=0;rc<inputRange.size();++rc){
+    classNames.push_back(type2string(inputRange[rc]));
+    if(verbose_opt[0])
+      cout << inputRange[rc] << endl;
+  }
+  ConfusionMatrix cm(classNames);
+  if(verbose_opt[0]){
+    cout << "class names: " << endl;
+    for(int iclass=0;iclass<cm.nClasses();++iclass)
+      cout << iclass << " " << cm.getClass(iclass) << endl;
+  }
+  unsigned int ntotalValidation=0;
+  unsigned int nflagged=0;
+  Vector2d<int> resultClass(nclass,nclass);
+  vector<float> user(nclass);
+  vector<float> producer(nclass);
+  vector<unsigned int> nvalidation(nclass);
+
+  //initialize
+  for(int rc=0;rc<nclass;++rc){
+    for(int ic=0;ic<nclass;++ic)
+      resultClass[rc][ic]=0;
+    nvalidation[rc]=0;
+  }
+  
+  bool isDifferent=false;
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+  if(!verbose_opt[0])
+    pfnProgress(progress,pszMessage,pProgressArg);
+  if(reference_opt[0].find(".shp")!=string::npos){
+    for(int iinput=0;iinput<input_opt.size();++iinput){
+      if(output_opt[0]!="")
+        assert(reference_opt.size()==output_opt.size());
+      for(int iref=0;iref<reference_opt.size();++iref){
+        if(verbose_opt[0])
+          cout << "reference is " << reference_opt[iref] << endl;
+        assert(reference_opt[iref].find(".shp")!=string::npos);
+        ImgReaderOgr referenceReader;
+        try{
+          inputReader.open(input_opt[iinput]);//,imagicX_opt[0],imagicY_opt[0]);
+          if(mask_opt[0]!=""){
+            maskReader.open(mask_opt[iinput]);
+            assert(inputReader.nrOfCol()==maskReader.nrOfCol());
+            assert(inputReader.nrOfRow()==maskReader.nrOfRow());
+          }
+          referenceReader.open(reference_opt[iref]);
+        }
+        catch(string error){
+          cerr << error << endl;
+          exit(1);
+        }
+        referenceRange=inputRange;
+
+        ImgWriterOgr ogrWriter;
+        OGRLayer *writeLayer;
+        if(output_opt[0]!=""){
+          if(verbose_opt[0])
+            cout << "creating output vector file " << output_opt[0] << endl;
+          assert(output_opt[0].find(".shp")!=string::npos);
+          try{
+            ogrWriter.open(output_opt[iref]);
+          }
+          catch(string error){
+            cerr << error << endl;
+            exit(1);
+          }
+          char     **papszOptions=NULL;
+          string layername=output_opt[0].substr(0,output_opt[0].find(".shp"));
+          if(verbose_opt[0])
+            cout << "creating layer: " << layername << endl;
+          if(ogrWriter.createLayer(layername, "EPSG:3035", wkbPoint, papszOptions)==NULL)
+            cout << "Error: create layer failed!" << endl;
+          else if(verbose_opt[0])
+            cout << "created layer" << endl;
+          if(verbose_opt[0])
+            cout << "copy fields from " << reference_opt[iref] << endl;
+          ogrWriter.copyFields(referenceReader);
+          //create extra field for classified label
+          short theDim=boundary_opt[0];
+          for(int windowJ=-theDim/2;windowJ<(theDim+1)/2;++windowJ){
+            for(int windowI=-theDim/2;windowI<(theDim+1)/2;++windowI){
+              if(disc_opt[0]&&(windowI*windowI+windowJ*windowJ>(theDim/2)*(theDim/2)))
+                continue;
+              ostringstream fs;
+              if(theDim>1)
+                fs << labelclass_opt[0] << "_" << windowJ << "_" << windowI;
+              else
+                fs << labelclass_opt[0];
+              if(verbose_opt[0])
+                cout << "creating field " << fs.str() << endl;
+              ogrWriter.createField(fs.str(),OFTInteger);
+            }
+          }
+          writeLayer=ogrWriter.getDataSource()->GetLayer(0);
+        }
+        OGRLayer  *readLayer;
+        readLayer = referenceReader.getDataSource()->GetLayer(0);
+        readLayer->ResetReading();
+        OGRFeature *readFeature;
+        int isample=0;
+        while( (readFeature = readLayer->GetNextFeature()) != NULL ){
+          if(verbose_opt[0])
+            cout << "sample " << ++isample << endl;
+          //get x and y from readFeature
+          double x,y;
+          OGRGeometry *poGeometry;
+          poGeometry = readFeature->GetGeometryRef();
+          assert( poGeometry != NULL && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint );
+          OGRPoint *poPoint = (OGRPoint *) poGeometry;
+          //         writeFeature->SetGeometry(poPoint);
+          x=poPoint->getX();
+          y=poPoint->getY();
+          short inputValue;
+          vector<short> inputValues;
+          bool isHomogeneous=true;
+          short maskValue;
+          short outputValue;
+          //read referenceValue from feature
+          short referenceValue=readFeature->GetFieldAsInteger(readFeature->GetFieldIndex(labelref_opt[0].c_str()));
+          if(verbose_opt[0])
+            cout << "reference value: " << referenceValue << endl;
+          bool pixelFlagged=false;
+          bool maskFlagged=false;
+          for(int iflag=0;iflag<flag_opt.size();++iflag){
+            if(referenceValue==flag_opt[iflag])
+              pixelFlagged=true;
+          }
+          if(pixelFlagged)
+            continue;
+          double i_centre,j_centre;
+          //input reader is georeferenced!
+          inputReader.geo2image(x,y,i_centre,j_centre);
+          //       else{
+          //         i_centre=x;
+          //         j_centre=y;
+          //       }
+          //nearest neighbour
+          j_centre=static_cast<int>(j_centre);
+          i_centre=static_cast<int>(i_centre);
+          //check if j_centre is out of bounds
+          if(static_cast<int>(j_centre)<0||static_cast<int>(j_centre)>=inputReader.nrOfRow())
+            continue;
+          //check if i_centre is out of bounds
+          if(static_cast<int>(i_centre)<0||static_cast<int>(i_centre)>=inputReader.nrOfCol())
+            continue;
+          OGRFeature *writeFeature;
+          if(output_opt[0]!=""){
+            writeFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
+            if(verbose_opt[0])
+              cout << "copying fields from " << reference_opt[0] << endl;
+            if(writeFeature->SetFrom(readFeature)!= OGRERR_NONE)
+              cerr << "writing feature failed" << endl;
+          }
+          bool windowAllFlagged=true;
+          bool windowHasFlag=false;
+          short theDim=boundary_opt[0];
+          for(int windowJ=-theDim/2;windowJ<(theDim+1)/2;++windowJ){
+            for(int windowI=-theDim/2;windowI<(theDim+1)/2;++windowI){
+              if(disc_opt[0]&&(windowI*windowI+windowJ*windowJ>(theDim/2)*(theDim/2)))
+                continue;
+              int j=j_centre+windowJ;
+              //check if j is out of bounds
+              if(static_cast<int>(j)<0||static_cast<int>(j)>=inputReader.nrOfRow())
+                continue;
+              int i=i_centre+windowI;
+              //check if i is out of bounds
+              if(static_cast<int>(i)<0||static_cast<int>(i)>=inputReader.nrOfCol())
+                continue;
+              if(verbose_opt[0])
+                cout << setprecision(12) << "reading image value at x,y " << x << "," << y << " (" << i << "," << j << "), ";
+              inputReader.readData(inputValue,GDT_Int16,i,j,band_opt[0]);
+              inputValues.push_back(inputValue);
+              if(inputValues.back()!=*(inputValues.begin()))
+                isHomogeneous=false;
+              if(verbose_opt[0])
+                cout << "input value: " << inputValue << endl;
+              pixelFlagged=false;
+              for(int iflag=0;iflag<flag_opt.size();++iflag){
+                if(inputValue==flag_opt[iflag]){
+                  pixelFlagged=true;
+                  break;
+                }
+              }
+              maskFlagged=false;//(mflag_opt[ivalue]>=0)?false:true;
+              if(mask_opt[0]!=""){
+                maskReader.readData(maskValue,GDT_Int16,i,j,band_opt[0]);
+                for(int ivalue=0;ivalue<mflag_opt.size();++ivalue){
+                  if(mflag_opt[ivalue]>=0){//values set in mflag_opt are invalid
+                    if(maskValue==mflag_opt[ivalue]){
+                      maskFlagged=true;
+                      break;
+                    }
+                  }
+                  else{//only values set in mflag_opt are valid
+                    if(maskValue!=-mflag_opt[ivalue])
+                      maskFlagged=true;
+                    else{
+                      maskFlagged=false;
+                      break;
+                    }
+                  }
+                }
+              }
+              pixelFlagged=pixelFlagged||maskFlagged;
+              if(pixelFlagged)
+                windowHasFlag=true;
+              else
+                windowAllFlagged=false;//at least one good pixel in neighborhood
+            }
+          }
+          //at this point we know the values for the entire window
+          if(homogeneous_opt[0]){//only centre pixel
+            int j=j_centre;
+            int i=i_centre;
+            //flag if not all pixels are homogeneous or if at least one pixel flagged
+          
+            if(!windowHasFlag&&isHomogeneous){
+              if(output_opt[0]!="")
+                writeFeature->SetField(labelclass_opt[0].c_str(),static_cast<int>(inputValue));
+              ++ntotalValidation;
+              int rc=distance(referenceRange.begin(),find(referenceRange.begin(),referenceRange.end(),referenceValue));
+              int ic=distance(inputRange.begin(),find(inputRange.begin(),inputRange.end(),inputValue));
+              assert(rc<nclass);
+              assert(ic<nclass);
+              ++nvalidation[rc];
+              ++resultClass[rc][ic];
+              if(verbose_opt[0]>1)
+                cout << "increment: " << rc << " " << referenceRange[rc] << " " << ic << " " << inputRange[ic] << endl;
+              cm.incrementResult(cm.getClass(rc),cm.getClass(ic),1);
+              if(inputValue==referenceValue){//correct
+                if(valueE_opt[0]!=flag_opt[0])
+                  outputValue=valueE_opt[0];
+                else
+                  outputValue=inputValue;
+              }
+              else if(inputValue>referenceValue)//1=forest,2=non-forest
+                outputValue=valueO_opt[0];//omission error
+              else
+                outputValue=valueC_opt[0];//commission error
+            }
+          }
+          else{
+            for(int windowJ=-theDim/2;windowJ<(theDim+1)/2;++windowJ){
+              for(int windowI=-theDim/2;windowI<(theDim+1)/2;++windowI){
+                if(disc_opt[0]&&(windowI*windowI+windowJ*windowJ>(theDim/2)*(theDim/2)))
+                  continue;
+                int j=j_centre+windowJ;
+                //check if j is out of bounds
+                if(static_cast<int>(j)<0||static_cast<int>(j)>=inputReader.nrOfRow())
+                  continue;
+                int i=i_centre+windowI;
+                //check if i is out of bounds
+                if(static_cast<int>(i)<0||static_cast<int>(i)>=inputReader.nrOfCol())
+                  continue;
+                if(!windowAllFlagged){
+                  ostringstream fs;
+                  if(theDim>1)
+                    fs << labelclass_opt[0] << "_" << windowJ << "_" << windowI;
+                  else
+                    fs << labelclass_opt[0];
+                  if(output_opt[0]!="")
+                    writeFeature->SetField(fs.str().c_str(),static_cast<int>(inputValue));
+                  if(!windowJ&&!windowI){//centre pixel
+                    ++ntotalValidation;
+                    int rc=distance(referenceRange.begin(),find(referenceRange.begin(),referenceRange.end(),referenceValue));
+                    int ic=distance(inputRange.begin(),find(inputRange.begin(),inputRange.end(),inputValue));
+                    assert(rc<nclass);
+                    assert(ic<nclass);
+                    ++nvalidation[rc];
+                    ++resultClass[rc][ic];
+                    if(verbose_opt[0]>1)
+                      cout << "increment: " << rc << " " << referenceRange[rc] << " " << ic << " " << inputRange[ic] << endl;
+                    cm.incrementResult(cm.getClass(rc),cm.getClass(ic),1);
+
+                    if(inputValue==referenceValue){//correct
+                      if(valueE_opt[0]!=flag_opt[0])
+                        outputValue=valueE_opt[0];
+                      else
+                        outputValue=inputValue;
+                    }
+                    else if(inputValue>referenceValue)//1=forest,2=non-forest
+                      outputValue=valueO_opt[0];//omission error
+                    else
+                      outputValue=valueC_opt[0];//commission error
+                  }
+                }
+              }
+            }
+          }
+          if(output_opt[0]!=""){
+            if(!windowAllFlagged){
+              if(verbose_opt[0])
+                cout << "creating feature" << endl;
+              if(writeLayer->CreateFeature( writeFeature ) != OGRERR_NONE ){
+                string errorString="Failed to create feature in shapefile";
+                throw(errorString);
+              }
+            }
+            OGRFeature::DestroyFeature( writeFeature );
+          }
+        }
+        if(output_opt[0]!="")
+          ogrWriter.close();
+        referenceReader.close();
+        inputReader.close();
+        if(mask_opt[0]!="")
+          maskReader.close();
+      }
+    }
+  }
+  else{
+    ImgWriterGdal imgWriter;
+    try{
+      inputReader.open(input_opt[0]);//,imagicX_opt[0],imagicY_opt[0]);
+      if(mask_opt[0]!="")
+        maskReader.open(mask_opt[0]);
+      if(output_opt[0]!=""){
+        if(verbose_opt[0])
+          cout << "opening output image " << output_opt[0] << endl;
+        string compression=(lzw_opt[0])? "LZW":"NONE";
+        imgWriter.open(output_opt[0],inputReader.nrOfCol(),inputReader.nrOfRow(),1,inputReader.getDataType(),inputReader.getImageType(),option_opt);
+
+        if(inputReader.isGeoRef()){
+          imgWriter.copyGeoTransform(inputReader);
+        }
+        if(colorTable_opt[0]!="")
+          imgWriter.setColorTable(colorTable_opt[0]);
+        else if(inputReader.getColorTable()!=NULL){
+          if(verbose_opt[0])
+            cout << "set colortable from input image" << endl;
+          imgWriter.setColorTable(inputReader.getColorTable());
+        }
+      }
+      else if(verbose_opt[0])
+        cout << "no output image defined" << endl;
+        
+    }
+    catch(string error){
+      cout << error << endl;
+      exit(2);
+    }
+    //todo: support different data types!
+    vector<short> lineInput(inputReader.nrOfCol());
+    vector<short> lineMask(maskReader.nrOfCol());
+    vector<short> lineOutput(inputReader.nrOfCol());
+    int irow=0;
+    int icol=0;
+    double oldreferencerow=-1;
+    ImgReaderGdal referenceReader;
+    try{
+      referenceReader.open(reference_opt[0]);//,rmagicX_opt[0],rmagicY_opt[0]);
+    }
+    catch(string error){
+      cerr << error << endl;
+      exit(1);
+    }
+    if(inputReader.isGeoRef()){
+      assert(referenceReader.isGeoRef());
+      if(inputReader.getProjection()!=referenceReader.getProjection())
+        cout << "projection of input image and reference image are different!" << endl;
+    }
+    vector<short> lineReference(referenceReader.nrOfCol());
+    referenceReader.getRange(referenceRange,band_opt[0]);
+    for(int iflag=0;iflag<flag_opt.size();++iflag){
+      vector<short>::iterator fit;
+      fit=find(referenceRange.begin(),referenceRange.end(),flag_opt[iflag]);
+      if(fit!=referenceRange.end())
+        referenceRange.erase(fit);
+    }
+    if(verbose_opt[0]){
+      cout << "reference range: " << endl;
+      for(int rc=0;rc<referenceRange.size();++rc)
+        cout << referenceRange[rc] << endl;
+    }
+    if(referenceRange.size()!=inputRange.size()){
+      if(confusion_opt[0]||output_opt[0]!=""){
+        cout << "reference range is not equal to input range!" << endl;
+        cout << "Kappa: " << 0 << endl;    
+        cout << "total weighted: " << 0 << endl;
+      }
+      else
+        cout << "reference range is not equal to input range!" << endl;
+        cout << input_opt[0] << " and " << reference_opt[0] << " are different" << endl;
+      exit(1);
+    }
+
+    for(irow=0;irow<inputReader.nrOfRow()&&!isDifferent;++irow){
+      //read line in lineInput, lineReference and lineMask
+      inputReader.readData(lineInput,GDT_Int16,irow,band_opt[0]);
+      if(mask_opt[0]!="")
+        maskReader.readData(lineMask,GDT_Int16,irow,band_opt[0]);
+      double x,y;//geo coordinates
+      double ireference,jreference;//image coordinates in reference image
+      for(icol=0;icol<inputReader.nrOfCol();++icol){
+        //find col in reference
+        inputReader.image2geo(icol,irow,x,y);
+        referenceReader.geo2image(x,y,ireference,jreference);
+        if(ireference<0||ireference>=referenceReader.nrOfCol()){
+          cerr << ireference << " out of reference range!" << endl;
+          cerr << x << " " << y << " " << icol << " " << irow << endl;
+          cerr << x << " " << y << " " << ireference << " " << jreference << endl;
+          exit(1);
+        }
+        if(jreference!=oldreferencerow){
+          if(jreference<0||jreference>=referenceReader.nrOfRow()){
+            cerr << jreference << " out of reference range!" << endl;
+            cerr << x << " " << y << " " << icol << " " << irow << endl;
+            cerr << x << " " << y << " " << ireference << " " << jreference << endl;
+            exit(1);
+          }
+          else{
+            referenceReader.readData(lineReference,GDT_Int16,static_cast<int>(jreference),band_opt[0]);
+            oldreferencerow=jreference;
+          }
+        }
+        bool flagged=false;
+        for(int iflag=0;iflag<flag_opt.size();++iflag){
+          if((lineInput[icol]==flag_opt[iflag])||(lineReference[ireference]==flag_opt[iflag])){
+            lineOutput[icol]=flag_opt[iflag];
+            flagged=true;
+            break;
+          }
+        }
+        if(mask_opt[0]!=""){
+          for(int ivalue=0;ivalue<mflag_opt.size();++ivalue){
+            if(lineMask[icol]==mflag_opt[ivalue]){
+              flagged=true;
+              break;
+            }
+          }
+        }
+        if(!flagged){
+          ++ntotalValidation;
+          int rc=distance(referenceRange.begin(),find(referenceRange.begin(),referenceRange.end(),lineReference[ireference]));
+          int ic=distance(inputRange.begin(),find(inputRange.begin(),inputRange.end(),lineInput[icol]));
+          assert(rc<nclass);
+          assert(ic<nclass);
+          ++nvalidation[rc];
+          ++resultClass[rc][ic];
+          if(verbose_opt[0]>1)
+            cout << "increment: " << rc << " " << referenceRange[rc] << " " << ic << " " << inputRange[ic] << endl;
+          cm.incrementResult(cm.getClass(rc),cm.getClass(ic),1);
+          if(lineInput[icol]==lineReference[ireference]){//correct
+            if(valueE_opt[0]!=flag_opt[0])
+              lineOutput[icol]=valueE_opt[0];
+            else
+              lineOutput[icol]=lineInput[icol];
+          }
+          else{//error
+            if(output_opt[0]==""&&!confusion_opt[0]){
+              isDifferent=true;
+              break;
+            }
+            if(lineInput[icol]<20){//forest
+              if(lineReference[icol]>=20)//gain
+                lineOutput[icol]=lineInput[icol]*10+1;//GAIN is 111,121,131
+              else//forest type changed: mixed
+                lineOutput[icol]=130;//MIXED FOREST
+            }
+            else if(lineReference[icol]<20){//loss
+              lineOutput[icol]=20*10+lineReference[icol];//LOSS is 211 212 213
+            }
+            else//no forest
+              lineOutput[icol]=20*10;//NON FOREST is 200
+            // if(lineInput[icol]>lineReference[ireference])//1=forest,2=non-forest
+            //   lineOutput[icol]=valueO_opt[0];//omission error
+            // else
+            //   lineOutput[icol]=valueC_opt[0];//commission error
+          }
+        }
+        else{
+          ++nflagged;
+          lineOutput[icol]=flag_opt[0];
+        }
+      }
+      if(output_opt[0]!=""){
+        try{
+          imgWriter.writeData(lineOutput,GDT_Int16,irow);
+        }
+        catch(string errorstring){
+          cerr << "lineOutput.size(): " << lineOutput.size() << endl;
+          cerr << "imgWriter.nrOfCol(): " << imgWriter.nrOfCol() << endl;
+          cerr << errorstring << endl;
+          exit(1);
+        }
+      }
+      else if(isDifferent&&!confusion_opt[0]){//we can break off here, files are different...
+        if(!verbose_opt[0])
+          pfnProgress(1.0,pszMessage,pProgressArg);
+        break;
+      }
+      progress=static_cast<float>(irow+1.0)/inputReader.nrOfRow();
+      if(!verbose_opt[0])
+        pfnProgress(progress,pszMessage,pProgressArg);
+    }
+    if(output_opt[0]!="")
+      imgWriter.close();
+    else if(!confusion_opt[0]){
+      if(isDifferent)
+        cout << input_opt[0] << " and " << reference_opt[0] << " are different" << endl;
+      else
+        cout << input_opt[0] << " and " << reference_opt[0] << " are identical" << endl;
+    }
+    referenceReader.close();
+    inputReader.close();
+    if(mask_opt[0]!="")
+      maskReader.close();
+  }
+
+  if(confusion_opt[0]){
+    // double totalResult=0;
+    // cout << " ";
+    // for(int ic=0;ic<inputRange.size();++ic)
+    //   cout << inputRange[ic] << " ";
+    // cout << endl;
+    // unsigned int ntotal=0;
+    // vector<unsigned int> ntotalclass(referenceRange.size());
+    // for(int rc=0;rc<referenceRange.size();++rc){
+    //   ntotalclass[rc]=0;
+    //   cout << referenceRange[rc] << " ";
+    //   //initialize
+    //   for(int ic=0;ic<inputRange.size();++ic){
+    //     unsigned int result=0;
+    //     user[ic]=0;
+    //     producer[ic]=0;	
+    //     for(int k=0;k<nclass;++k){
+    //       user[ic]+=resultClass[k][ic];
+    //       producer[ic]+=resultClass[ic][k];
+    //     }	  
+    //     result=resultClass[rc][ic];
+    //     ntotal+=result;
+    //     ntotalclass[rc]+=result;
+    //     if(ic==rc){
+    //       totalResult+=result;
+    //     }
+    //     cout << result << " ";
+    //   }
+    //   cout << endl;
+    // }
+    // if(verbose_opt[0]){
+    //   cout << "totalResult: " << totalResult << endl;
+    //   cout << "ntotalValidation: " << ntotalValidation << endl;
+    //   cout << "nflagged: " << nflagged << endl;
+    //   cout << "ntotal: " << ntotal << endl;
+    // }
+    // totalResult*=100.0/ntotal;
+    // int nclass0=0;//number of classes without any reference
+    // for(int rc=0;rc<referenceRange.size();++rc)
+    //   if(!nvalidation[rc])
+    //     ++nclass0;
+    // double pChance=0;
+    // double pCorrect=0;
+    // double totalEntries=0;
+    // cout << "class #samples userAcc prodAcc" << endl;    
+    // for(int rc=0;rc<referenceRange.size();++rc){
+    //   totalEntries+=user[rc];
+    //   pChance+=user[rc]*producer[rc];
+    //   pCorrect+=resultClass[rc][rc];
+    //   cout << referenceRange[rc] << " " << nvalidation[rc] << " ";
+    //   cout << 100.0*resultClass[rc][rc]/user[rc] << " "//user accuracy
+    //        << 100.0*resultClass[rc][rc]/producer[rc] << " " << endl;//producer accuracy
+    // }
+    // pCorrect/=totalEntries;
+    // pChance/=totalEntries*totalEntries;    
+    // double kappa=pCorrect-pChance;
+    // kappa/=1-pChance;
+    // cout << "Kappa: " << kappa << endl;    
+    // cout << "total weighted: " << static_cast<int>(0.5+totalResult) << endl;
+    assert(cm.nReference());
+    cout << cm << endl;
+    cout << "class #samples userAcc prodAcc" << endl;
+    double se95_ua=0;
+    double se95_pa=0;
+    double se95_oa=0;
+    double dua=0;
+    double dpa=0;
+    double doa=0;
+    for(int iclass=0;iclass<cm.nClasses();++iclass){
+      dua=cm.ua_pct(classNames[iclass],&se95_ua);
+      dpa=cm.pa_pct(classNames[iclass],&se95_pa);
+      cout << cm.getClass(iclass) << " " << cm.nReference(cm.getClass(iclass)) << " " << dua << " (" << se95_ua << ")" << " " << dpa << " (" << se95_pa << ")" << endl;
+    }
+    doa=cm.oa_pct(&se95_oa);
+    cout << "Kappa: " << cm.kappa() << endl;
+    cout << "Overall Accuracy: " << doa << " (" << se95_oa << ")"  << endl;
+  }
+}
diff --git a/src/apps/pkdumpimg.cc b/src/apps/pkdumpimg.cc
new file mode 100644
index 0000000..39572d1
--- /dev/null
+++ b/src/apps/pkdumpimg.cc
@@ -0,0 +1,320 @@
+/**********************************************************************
+pkdumpimg.cc: program to dump image content to ascii or std out
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <string>
+#include <fstream>
+#include <vector>
+#include <iostream>
+#include <assert.h>
+#include "Optionpk.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "imageclasses/ImgWriterOgr.h"
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","introduce -uli -ulj to crop based on image coordinates",false);
+  Optionpk<std::string> input_opt("i","input","input image file","");
+  Optionpk<string> output_opt("o", "output", "Output ascii file (Default is empty: use stdout", "");
+  Optionpk<string> otype_opt("ot", "otype", "Data type for output ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "");
+  Optionpk<string> oformat_opt("of", "oformat", "Output format (matrix form or list (x,y,z) form. Default is matrix form", "matrix");
+  Optionpk<int> band_opt("b", "band", "band index to crop (-1: crop all bands)", 0);
+  Optionpk<string> extent_opt("e", "extent", "get boundary from extent from polygons in vector file", "");
+  Optionpk<double> ulx_opt("ulx", "ulx", "Upper left x value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double> uly_opt("uly", "uly", "Upper left y value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double> lrx_opt("lrx", "lrx", "Lower left x value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double> lry_opt("lry", "lry", "Lower left y value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double> dx_opt("dx", "dx", "Output resolution in x (in meter) (0.0: keep original resolution)", 0.0);
+  Optionpk<double> dy_opt("dy", "dy", "Output resolution in y (in meter) (0.0: keep original resolution)", 0.0);
+  Optionpk<string> resample_opt("r", "resampling-method", "Resampling method (near: nearest neighbour, bilinear: bi-linear interpolation).", "near");
+  Optionpk<short> flag_opt("f", "flag", "Flag value to put in image if out of bounds.", 0);
+  Optionpk<short> verbose_opt("v", "verbose", "verbose (Default: 0)", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  input_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  otype_opt.retrieveOption(argc,argv);
+  oformat_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  extent_opt.retrieveOption(argc,argv);
+  ulx_opt.retrieveOption(argc,argv);
+  uly_opt.retrieveOption(argc,argv);
+  lrx_opt.retrieveOption(argc,argv);
+  lry_opt.retrieveOption(argc,argv);
+  dx_opt.retrieveOption(argc,argv);
+  dy_opt.retrieveOption(argc,argv);
+  resample_opt.retrieveOption(argc,argv);
+  flag_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << "usage: pkdumpimg -i imgfile [-o asciifile] [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  ofstream outputStream;
+  if(!output_opt[0].empty())
+    outputStream.open(output_opt[0].c_str());
+  
+  RESAMPLE theResample;
+  if(resample_opt[0]=="near"){
+    theResample=NEAR;
+    if(verbose_opt[0])
+      cout << "resampling: nearest neighbour" << endl;
+  }
+  else if(resample_opt[0]=="bilinear"){
+    theResample=BILINEAR;
+    if(verbose_opt[0])
+      cout << "resampling: bilinear interpolation" << endl;
+  }
+  else{
+    std::cout << "Error: resampling method " << resample_opt[0] << " not supported" << std::endl;
+    exit(1);
+  }
+
+  ImgWriterGdal imgWriter;
+  GDALDataType theType;
+
+  ImgReaderGdal imgReader(input_opt[0]);
+  ImgWriterGdal virtualWriter;//only for coordinate conversion (no output file defined)
+  
+  int nband=imgReader.nrOfBand();
+  //get number of lines
+  int nrow=imgReader.nrOfRow();
+  int ncol=imgReader.nrOfCol();
+  int ncropcol=0;
+  int ncroprow=0;
+  double dx=dx_opt[0];
+  double dy=dy_opt[0];
+  if(!dx||!dy){
+    dx=imgReader.getDeltaX();
+    dy=imgReader.getDeltaY();
+  }
+  //bounding box of cropped image
+  double cropulx=ulx_opt[0];
+  double cropuly=uly_opt[0];
+  double croplrx=lrx_opt[0];
+  double croplry=lry_opt[0];
+  //get bounding box from extentReader if defined
+  ImgReaderOgr extentReader;
+  if(extent_opt[0]!=""){
+    for(int iextent=0;iextent<extent_opt.size();++iextent){
+      extentReader.open(extent_opt[iextent]);
+      if(!(extentReader.getExtent(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))){
+        cerr << "Error: could not get extent from " << extent_opt[0] << endl;
+        exit(1);
+      }
+      if(ulx_opt[0]<cropulx)
+        cropulx=ulx_opt[0];
+      if(uly_opt[0]>cropuly)
+        cropuly=uly_opt[0];
+      if(lry_opt[0]<croplry)
+        croplry=lry_opt[0];
+      if(lrx_opt[0]>croplrx)
+        croplrx=lrx_opt[0];
+      extentReader.close();
+    }
+  }
+  double uli,ulj,lri,lrj;//image coordinates
+  if(ulx_opt[0]>=lrx_opt[0]){//default bounding box: no cropping
+    uli=0;
+    lri=imgReader.nrOfCol()-1;
+    ulj=0;
+    lrj=imgReader.nrOfRow()-1;
+    ncropcol=imgReader.nrOfCol();
+    ncroprow=imgReader.nrOfRow();
+    imgReader.getBoundingBox(cropulx,cropuly,croplrx,croplry);
+    imgReader.geo2image(cropulx,cropuly,uli,ulj);
+    imgReader.geo2image(croplrx,croplry,lri,lrj);
+    ncropcol=ceil((croplrx-cropulx)/dx);
+    ncroprow=ceil((cropuly-croplry)/dy);
+  }
+  else{
+    imgReader.geo2image(cropulx,cropuly,uli,ulj);
+    imgReader.geo2image(croplrx,croplry,lri,lrj);
+    ncropcol=ceil((croplrx-cropulx)/dx);
+    ncroprow=ceil((cropuly-croplry)/dy);
+    uli=floor(uli);
+    ulj=floor(ulj);
+    lri=floor(lri);
+    lrj=floor(lrj);
+  }
+  double startCol=uli;
+  double endCol=lri;
+  double dcropcol=0;
+  double dcroprow=0;
+  double deltaX=imgReader.getDeltaX();
+  double deltaY=imgReader.getDeltaY();
+  dcropcol=(lri-uli+1)/(dx/deltaX);
+  dcroprow=(lrj-ulj+1)/(dy/deltaY);
+  if(verbose_opt[0]){
+    cout << "cropulx: " << cropulx << endl;
+    cout << "cropuly: " << cropuly << endl;
+    cout << "croplrx: " << croplrx << endl;
+    cout << "croplry: " << croplry << endl;
+    cout << "ncropcol: " << ncropcol << endl;
+    cout << "ncroprow: " << ncroprow << endl;
+    cout << "cropulx+ncropcol*dx: " << cropulx+ncropcol*dx << endl;
+    cout << "cropuly-ncroprow*dy: " << cropuly-ncroprow*dy << endl;
+    cout << "selected upper left column in input image: " << uli << endl;
+    cout << "selected upper left row of input image: " << ulj << endl;
+    cout << "selected lower right column in input image: " << lri << endl;
+    cout << "selected lower right row in input image: " << lrj << endl;
+    cout << "new number of cols: " << ncropcol << endl;
+    cout << "new number of rows: " << ncroprow << endl;
+  }
+
+  imgWriter.setGeoTransform(cropulx,cropuly,dx,dy,0,0);
+  // imgWriter.setProjection(imgReader.getProjection());
+
+  double readRow=0;
+  double readCol=0;
+  double lowerCol=0;
+  double upperCol=0;
+  int readncol=endCol-startCol+1;
+  //test
+  // vector<double> readBuffer(readncol);
+  vector<double> readBuffer(readncol+1);
+  assert(band_opt[0]>=0);
+  assert(band_opt[0]<imgReader.nrOfBand());
+  assert(imgWriter.isGeoRef());
+  for(int irow=0;irow<ncroprow;++irow){
+    if(verbose_opt[0])
+      std::cout << irow << std::endl;
+    double x=0;
+    double y=0;
+    //convert irow to geo
+    imgWriter.image2geo(0,irow,x,y);
+    //lookup corresponding row for irow in this file
+    imgReader.geo2image(x,y,readCol,readRow);
+    if(readRow<0||readRow>=imgReader.nrOfRow()){
+      if(verbose_opt[0]>1)
+        std::cout << "skipping row " << readRow << std::endl;
+      continue;
+    }
+    try{
+      //test
+      // imgReader.readData(readBuffer,GDT_Float64,startCol,endCol,readRow,band_opt[0],theResample);
+      if(endCol<imgReader.nrOfCol()-1)
+        imgReader.readData(readBuffer,GDT_Float64,startCol,endCol+1,readRow,band_opt[0],theResample);
+      else
+        imgReader.readData(readBuffer,GDT_Float64,startCol,endCol,readRow,band_opt[0],theResample);
+      for(int ib=0;ib<ncropcol;++ib){
+        assert(imgWriter.image2geo(ib,irow,x,y));
+        //lookup corresponding row for irow in this file
+        imgReader.geo2image(x,y,readCol,readRow);
+        if(readCol<0||readCol>=imgReader.nrOfCol()){
+          if(oformat_opt[0]=="matrix"){
+            if(output_opt[0].empty())
+              std::cout << flag_opt[0] << " ";
+            else
+              outputStream << flag_opt[0] << " ";
+          }
+          else{
+            if(output_opt[0].empty())
+              std::cout << x << " " << y << " " << flag_opt[0] << endl;
+            else
+              outputStream << x << " " << y << " " << flag_opt[0] << endl;
+          }
+        }
+        else{
+          switch(theResample){
+          case(BILINEAR):
+            lowerCol=readCol-0.5;
+            lowerCol=static_cast<int>(lowerCol);
+            upperCol=readCol+0.5;
+            upperCol=static_cast<int>(upperCol);
+            if(lowerCol<0)
+              lowerCol=0;
+            if(upperCol>=imgReader.nrOfCol())
+              upperCol=imgReader.nrOfCol()-1;
+            if(oformat_opt[0]=="matrix"){
+              if(output_opt[0].empty())
+                std::cout << (readCol-0.5-lowerCol)*readBuffer[upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[lowerCol-startCol] << " ";
+              else
+                outputStream << (readCol-0.5-lowerCol)*readBuffer[upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[lowerCol-startCol] << " ";
+            }
+            else{
+              if(output_opt[0].empty())
+                std::cout << x << " " << y << " " << (readCol-0.5-lowerCol)*readBuffer[upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[lowerCol-startCol] << " " << endl;
+              else
+                outputStream << x << " " << y << " " << (readCol-0.5-lowerCol)*readBuffer[upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[lowerCol-startCol] << " " << endl;
+
+            }
+            break;
+          default:
+            readCol=static_cast<int>(readCol);
+            readCol-=startCol;//we only start reading from startCol
+            assert(readCol>=0);
+            if(readCol>=readBuffer.size())
+              std::cout << "Error: " << readCol << " >= " << readBuffer.size() << std::endl;
+            assert(readCol<readBuffer.size());
+            if(oformat_opt[0]=="matrix"){
+              if(output_opt[0].empty())
+                std::cout << readBuffer[readCol] << " ";
+              else
+                outputStream << readBuffer[readCol] << " ";
+            }
+            else{
+              if(output_opt[0].empty())
+                std::cout << x << " " << y << " " << readBuffer[readCol] << std::endl;
+              else
+                outputStream << x << " " << y << " " << readBuffer[readCol] << std::endl;
+            }
+            break;
+          }
+        }
+      }
+    }
+    catch(string errorstring){
+      cout << errorstring << endl;
+      exit(1);
+    }
+    if(oformat_opt[0]=="matrix"){
+      if(output_opt[0].empty())
+        std::cout << std::endl;
+      else
+        outputStream << std::endl;
+    }
+  }
+  if(extent_opt[0]!=""){
+    extentReader.close();
+  }
+  imgReader.close();
+  if(!output_opt[0].empty())
+    outputStream.close();
+}
diff --git a/src/apps/pkdumpogr.cc b/src/apps/pkdumpogr.cc
new file mode 100644
index 0000000..d449b89
--- /dev/null
+++ b/src/apps/pkdumpogr.cc
@@ -0,0 +1,202 @@
+/**********************************************************************
+pkdumpogr.cc: dump ogr file to text file or standard output
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <math.h>
+#include <string>
+#include <fstream>
+#include <assert.h>
+#include "base/Optionpk.h"
+#include "imageclasses/ImgReaderOgr.h"
+#include "algorithms/Histogram.h"
+#include "pkdumpogr.h"
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","",false);
+  Optionpk<string> input_opt("i", "input", "Input shape file", "");
+  Optionpk<string> output_opt("o", "output", "Output ASCII file", "");
+  Optionpk<string> attribute_opt("n", "name", "names of the attributes to select. Each attribute is stored in a separate band. Default is ALL: write all attributes", "ALL");
+  Optionpk<bool> pos_opt("pos","pos","include position (x and y)",false);
+  Optionpk<bool> transpose_opt("t","transpose","transpose output (does not work for -n ALL ",false);
+  Optionpk<short> verbose_opt("v", "verbose", "verbose (Default: 0)", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  input_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  attribute_opt.retrieveOption(argc,argv);
+  pos_opt.retrieveOption(argc,argv);
+  transpose_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  if(help_opt[0]){
+    cout << "usage: pkdumpogr -i inputimage -o outputimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  ImgReaderOgr imgReader;
+  try{
+    imgReader.open(input_opt[0]);
+  }
+  catch(string errorstring){
+    cerr << errorstring << endl;
+  }
+  ofstream outputFile;
+  if(output_opt[0]!="")
+    outputFile.open(output_opt[0].c_str(),ios::out);
+
+  ImgReaderOgr inputReader(input_opt[0]);
+  if(attribute_opt[0]!="ALL"){
+    vector<double> xvector;
+    vector<double> yvector;
+    inputReader.readXY(xvector,yvector);
+    Vector2d<double> theData(attribute_opt.size());
+    for(int ifield=0;ifield<attribute_opt.size();++ifield){
+      if(verbose_opt[0])
+        cout << "field: " << ifield << endl;
+      theData[ifield].clear();
+      inputReader.readData(theData[ifield],OFTReal,attribute_opt[ifield],0,verbose_opt[0]);
+    }
+    if(verbose_opt[0]){
+      std::cout << "number of fields: " << theData.size() << std::endl;
+      std::cout << "number of samples: " << theData[0].size() << std::endl;
+    }
+    if(transpose_opt[0]){
+      if(pos_opt[0]){
+        if(output_opt[0]!=""){
+          outputFile << "X" << " ";
+          for(int isample=0;isample<xvector.size();++isample){
+            outputFile << xvector[isample];
+            if(isample<xvector.size()-1)
+              outputFile << " ";
+            else
+              outputFile << std::endl;
+          }
+          outputFile << "Y" << " ";
+          for(int isample=0;isample<yvector.size();++isample){
+            outputFile << yvector[isample];
+            if(isample<yvector.size()-1)
+              outputFile << " ";
+            else
+              outputFile << std::endl;
+          }
+        }
+        else{
+          std::cout << "X" << " ";
+          for(int isample=0;isample<xvector.size();++isample){
+            std::cout << xvector[isample];
+            if(isample<xvector.size()-1)
+              std::cout << " ";
+            else
+              std::cout << std::endl;
+          }
+          std::cout << "Y" << " ";
+          for(int isample=0;isample<yvector.size();++isample){
+            std::cout << yvector[isample];
+            if(isample<yvector.size()-1)
+              std::cout << " ";
+            else
+              std::cout << std::endl;
+          }
+        }
+      }
+      for(int ifield=0;ifield<theData.size();++ifield){
+        if(output_opt[0]!=""){
+          outputFile << ifield << " ";
+          for(int isample=0;isample<theData[0].size();++isample){
+            outputFile << theData[ifield][isample];
+            if(isample<theData[0].size()-1)
+              outputFile << " ";
+            else
+              outputFile << std::endl;
+          }
+        }
+        else{
+          std::cout << ifield << " ";
+          for(int isample=0;isample<theData[0].size();++isample){
+            std::cout << theData[ifield][isample];
+            if(isample<theData[0].size()-1)
+              std::cout << " ";
+            else
+              std::cout << std::endl;
+          }
+        }
+      }
+    }
+    else{
+      for(int isample=0;isample<theData[0].size();++isample){
+        if(output_opt[0]!=""){
+          outputFile << isample << " ";
+          if(pos_opt[0])
+            outputFile << xvector[isample] << " " << yvector[isample] << " ";
+          for(int ifield=0;ifield<theData.size();++ifield){
+            outputFile << theData[ifield][isample];
+            if(ifield<theData.size()-1)
+              outputFile << " ";
+            else
+              outputFile << std::endl;
+          }
+        }
+        else{
+          std::cout << isample << " ";
+          if(pos_opt[0])
+            std::cout  << xvector[isample] << " " << yvector[isample] << " ";
+          for(int ifield=0;ifield<theData.size();++ifield){
+            std::cout << theData[ifield][isample];
+            if(ifield<theData.size()-1)
+              std::cout << " ";
+            else
+              std::cout << std::endl;
+          }
+        }
+      }
+    }
+    if(output_opt[0]!="")
+      outputFile.close();
+  }
+  else{
+    if(output_opt[0]!=""){
+      ofstream outputFile(output_opt[0].c_str(),ios::out);
+      outputFile << imgReader;
+      outputFile.close();
+    }
+    else
+      std::cout << imgReader;
+  }
+  imgReader.close();
+}
+
diff --git a/src/apps/pkdumpogr.h b/src/apps/pkdumpogr.h
new file mode 100644
index 0000000..4fd4a13
--- /dev/null
+++ b/src/apps/pkdumpogr.h
@@ -0,0 +1,131 @@
+/**********************************************************************
+pkdumpogr.h: dump ogr file to text file or standard output
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <map>
+#include "base/Vector2d.h"
+#include "imageclasses/ImgReaderOgr.h"
+
+#ifndef _PKDUMPOGR_H_
+#define _PKDUMPOGR_H_
+
+using namespace std;
+
+template<typename T> unsigned int readDataImageShape(const string &filename,
+                                                     map<int,Vector2d<T> > &mapPixels, //[classNr][pixelNr][bandNr],
+                                                     vector<string>& fields,
+                                                     double start,
+                                                     double end,
+                                                     const string& label,
+                                                     const string& query="",
+                                                     int verbose=false);
+
+
+template<typename T> unsigned int readDataImageShape(const string &filename,
+                                                     map<int,Vector2d<T> > &mapPixels, //[classNr][pixelNr][bandNr],
+                                                     vector<string>& fields,
+                                                     double start,
+                                                     double end,
+                                                     const string& label,
+                                                     const string& query,
+                                                     int verbose)
+{
+  mapPixels.clear();
+  int nsample=0;
+  int totalSamples=0;  
+  int nband=0;
+  if(verbose)
+    cout << "reading shape file " << filename  << endl;
+  ImgReaderOgr imgReaderShape;
+  try{
+    imgReaderShape.open(filename);
+    bool queryFound=false;
+    //only retain bands in fields
+    imgReaderShape.getFields(fields);
+    vector<string>::iterator fit=fields.begin();
+    if(verbose)
+      cout << "reading fields: ";
+    while(fit!=fields.end()){
+      if(verbose)
+        cout << *fit << " ";
+      size_t pos=(*fit).find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ");
+      if(pos==string::npos){
+        if(query!=""){
+          if((*fit).find(query)!=string::npos)
+            queryFound=true;
+        }
+        fields.erase(fit);
+      }
+      else{
+        string fieldname=(*fit).substr(pos);
+          int iband=atoi(fieldname.c_str());
+          if((start||end)&&(iband<start||iband>end))
+            fields.erase(fit);
+          else
+            ++fit;
+      }
+    }
+    if(verbose)
+      cout << endl;
+    if(verbose){
+      cout << "fields:";
+      for(vector<string>::iterator fit=fields.begin();fit!=fields.end();++fit)
+        cout << " " << *fit;
+      cout << endl;
+    }
+    if(!nband){
+      if(queryFound){
+        ostringstream qs;
+        qs << "select * from " << imgReaderShape.getLayerName() << " where " << query << "=1";
+        if(verbose)
+          cout << "reading with sql: " << qs.str() << endl;
+        nband=imgReaderShape.readSql(mapPixels,OFTReal,fields,label,qs.str(),NULL,0,true,false);
+      }
+      else{
+        if(verbose)
+          cout << "reading data" << endl;
+        nband=imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,true,verbose==2);
+      }
+    }
+    else{
+      if(queryFound){
+        ostringstream qs;
+        qs << "select * from " << imgReaderShape.getLayerName() << " where " << query << "=1";
+        if(verbose)
+          cout << "reading with sql: " << qs.str() << endl;
+        assert(nband==imgReaderShape.readSql(mapPixels,OFTReal,fields,label,qs.str(),NULL,0,true,false));
+      }
+      else        
+        assert(nband==imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,true,false));
+    }
+  }
+  catch(string e){
+    ostringstream estr;
+    estr << e << " " << filename;
+    throw(estr.str());
+  }
+  nsample=imgReaderShape.getFeatureCount();
+  totalSamples+=nsample;
+  if(verbose)
+    cout << ": " << nsample << " samples read with " << nband << " bands" << endl;
+  imgReaderShape.close();
+  if(verbose)
+    cout << "total number of samples read " << totalSamples << endl;
+  return totalSamples;
+}
+#endif //_PKDUMPOGR_H_
diff --git a/src/apps/pkegcs.cc b/src/apps/pkegcs.cc
new file mode 100644
index 0000000..2aa49a3
--- /dev/null
+++ b/src/apps/pkegcs.cc
@@ -0,0 +1,108 @@
+/**********************************************************************
+pkegcs.cc: Utility for raster files in European Grid Coordinate System
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "base/Optionpk.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "algorithms/Egcs.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<string> image_opt("i","image","input image to analyse","");
+  Optionpk<unsigned short>  band_opt("b", "band", "Band specific information", 0);
+  Optionpk<string> cell2bb_opt("c2b","cell2bb","convert cell code to geo coordinates of boundingbox (e.g. 32-AB)","");
+  Optionpk<string> cell2mid_opt("c2m","cell2mid","convert cell code to centre in geo coordinates (e.g. 32-AB)","");
+  Optionpk<bool> refpixel_opt("\0", "ref", "get reference pixel (lower left corner of centre of gravity pixel)", false);
+  Optionpk<double> maskValue_opt("m", "mask", "mask value(s) for no data to calculate reference pixel in image (Default is 0)",0);
+  Optionpk<int> dx_opt("dx","dx","resolution (default is 250m)",250);
+  Optionpk<bool> geo2cell_opt("g2c", "geo2cell", "get cell code for coordinates in x_opt and y_opt given the resolution in dx_opt", false);
+  Optionpk<double> x_opt("x","x","x coordinate in epsg:3035",0);
+  Optionpk<double> y_opt("y","y","y coordinate in epsg:3035",0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+
+  image_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  cell2bb_opt.retrieveOption(argc,argv);
+  cell2mid_opt.retrieveOption(argc,argv);
+  geo2cell_opt.retrieveOption(argc,argv);
+  refpixel_opt.retrieveOption(argc,argv);
+  maskValue_opt.retrieveOption(argc,argv);
+  dx_opt.retrieveOption(argc,argv);
+  x_opt.retrieveOption(argc,argv);
+  y_opt.retrieveOption(argc,argv);
+  
+  Egcs egcs;
+  if(cell2bb_opt[0]!=""){
+    int theULX, theULY, theLRX, theLRY;
+    egcs.setLevel(egcs.cell2level(cell2bb_opt[0]));
+    egcs.cell2bb(cell2bb_opt[0],theULX,theULY,theLRX,theLRY);
+    cout << setprecision(12) << "--ulx=" << theULX << " --uly=" << theULY << " --lrx=" << theLRX << " --lry=" << theLRY << endl;
+  }
+  if(cell2mid_opt[0]!=""){
+    double midX, midY;
+    egcs.setLevel(egcs.cell2level(cell2mid_opt[0]));
+    egcs.cell2mid(cell2mid_opt[0],midX,midY);
+    cout << setprecision(12) << "-x=" << midX << " -y=" << midY << endl;
+  }
+  if(geo2cell_opt[0]){
+    egcs.setLevel(egcs.res2level(dx_opt[0]));
+    cout << egcs.geo2cell(x_opt[0],y_opt[0]) << endl;
+  }
+  if(image_opt[0]!=""){
+    ImgReaderGdal imgReader;
+    imgReader.open(image_opt[0]);
+    if(refpixel_opt[0]){
+      assert(band_opt[0]<imgReader.nrOfBand());
+      for(int inodata=0;inodata<maskValue_opt.size();++inodata)
+        imgReader.pushNoDataValue(maskValue_opt[inodata],band_opt[0]);
+      // if(verbose_opt[0]){
+      //   vector<double> noData;
+      //   imgReader.getNoDataValues(noData,band_opt[0]);
+      //   cout << "number of no data values: " << noData.size() << endl;
+      // }
+      double refX,refY;
+      //get centre of reference (centre of gravity) pixel in image
+      imgReader.getRefPix(refX,refY,band_opt[0]);
+      cout << setprecision(12) << "--x " << refX << " --y " << refY << endl;
+      egcs.setLevel(egcs.res2level(imgReader.getDeltaX()));
+      // unsigned short theLevel=egcs.getLevel(imgReader.getDeltaX());
+      // egcs.setLevel(theLevel);
+      cout << "cell code at level " << egcs.getLevel() << " (resolution is " << egcs.getResolution() << "): " << egcs.geo2cell(refX,refY) << endl;
+    }
+  }
+}
diff --git a/src/apps/pkextract.cc b/src/apps/pkextract.cc
new file mode 100644
index 0000000..fc98a2b
--- /dev/null
+++ b/src/apps/pkextract.cc
@@ -0,0 +1,2196 @@
+/**********************************************************************
+pkextract.cc: extract pixel values from raster image from a (vector or raster) sample
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <assert.h>
+#include <math.h>
+#include <sstream>
+#include <string>
+#include <algorithm>
+#include <ctime>
+#include <vector>
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterOgr.h"
+#include "base/Optionpk.h"
+#include "algorithms/Histogram.h"
+
+using namespace std;
+
+#ifndef PI
+#define PI 3.1415926535897932384626433832795
+#endif
+
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","",false);
+  Optionpk<string> image_opt("i", "image", "Input image file", "");
+  Optionpk<string> sample_opt("s", "sample", "Input sample file (shape) or class file (e.g. Corine CLC) if class option is set", "");
+  Optionpk<string> mask_opt("m", "mask", "Mask image file", "");
+  Optionpk<int> invalid_opt("f", "flag", "Mask value where image is invalid. If a single mask is used, more flags can be set. If more masks are used, use one value for each mask. Default value is 1", 1);
+  Optionpk<int> class_opt("c", "class", "Class(es) to extract from input sample image. Use -1 to process every class in sample image, or 0 to extract all non-flagged pixels from sample file", 0);
+  Optionpk<string> output_opt("o", "output", "Output sample file (image file)", "");
+  Optionpk<bool> keepFeatures_opt("k", "keep", "Keep original features in output vector file", false);
+  Optionpk<string> fieldname_opt("n", "fname", "Field name of output shape file (default is B)", "B");
+  Optionpk<string> bufferOutput_opt("bu", "bu", "Buffer output shape file", "");
+  Optionpk<short> geo_opt("g", "geo", "geo coordinates (default is 1)", 1);
+  Optionpk<short> down_opt("d", "down", "down sampling factor. Can be used to create grid points", 1);
+  Optionpk<float> threshold_opt("t", "threshold", "threshold for selecting samples (randomly). Provide probability in percentage (>0) or absolute (<0). Use multiple threshold values (e.g. -t 80 -t 60) is more classes are to be extracted with random selection. Default value is 100: select all pixels for selected class(es)", 100);
+  Optionpk<double> min_opt("min", "min", "minimum number of samples to select (0)", 0);
+  Optionpk<short> boundary_opt("bo", "boundary", "boundary for selecting the sample (default: 1)", 1);
+  Optionpk<short> rbox_opt("rb", "rbox", "rectangular boundary box (total width in m) to draw around the selected pixel. Can not combined with class option. Use multiple rbox options for multiple boundary boxes (default is 0: no box)", 0);
+  Optionpk<short> cbox_opt("\0", "cbox", "circular boundary (diameter in m) to draw around the selected pixel. Can not combined with class option. Use multiple cbox options for multiple boundary boxes (default is 0: no box)", 0);
+  Optionpk<short> disc_opt("\0", "circular", "circular disc kernel boundary (default is 0)", 0);
+  Optionpk<string> ftype_opt("\0", "ftype", "Field type (only Real or Integer, default is Real)", "Real");
+  Optionpk<string> ltype_opt("\0", "ltype", "Label type: In16 (default) or String", "Integer");
+  Optionpk<string> label_opt("\0", "label", "name of the class label in the output vector file (default is label)", "label");
+  Optionpk<bool> polygon_opt("l", "line", "create OGRPolygon as geometry instead of points. Only if sample option is also of polygon type. (default is 0: use OGRPoint)", 0);
+  Optionpk<int> band_opt("b", "band", "band index to crop. (Default is -1: use all bands)", -1);
+  Optionpk<short> rule_opt("r", "rule", "rule how to report image information per feature. 0: value at each point (or at centroid of the polygon if line is not set), 1: mean value (written to centroid of polygon if line is not set), 2: proportion classes, 3: custom, 4: minimum of polygon). (Default is 0)", 0);
+  Optionpk<short> verbose_opt("v", "verbose", "verbose (default is 0)", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  image_opt.retrieveOption(argc,argv);
+  sample_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  invalid_opt.retrieveOption(argc,argv);
+  class_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  keepFeatures_opt.retrieveOption(argc,argv);
+  fieldname_opt.retrieveOption(argc,argv);
+  bufferOutput_opt.retrieveOption(argc,argv);
+  geo_opt.retrieveOption(argc,argv);
+  down_opt.retrieveOption(argc,argv);
+  threshold_opt.retrieveOption(argc,argv);
+  min_opt.retrieveOption(argc,argv);
+  boundary_opt.retrieveOption(argc,argv);
+  rbox_opt.retrieveOption(argc,argv);
+  cbox_opt.retrieveOption(argc,argv);
+  disc_opt.retrieveOption(argc,argv);
+  ftype_opt.retrieveOption(argc,argv);
+  ltype_opt.retrieveOption(argc,argv);
+  label_opt.retrieveOption(argc,argv);
+  polygon_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  rule_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  if(help_opt[0]){
+    cout << "usage: pkextract [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  if(verbose_opt[0])
+    std::cout << class_opt << std::endl;
+  Histogram hist;
+  Vector2d<unsigned int> posdata;
+  unsigned long int nsample=0;
+  unsigned long int ntotalvalid=0;
+  unsigned long int ntotalinvalid=0;
+  vector<unsigned long int> nvalid(class_opt.size());
+  vector<unsigned long int> ninvalid(class_opt.size());
+  for(int it=0;it<nvalid.size();++it){
+    nvalid[it]=0;
+    ninvalid[it]=0;
+  }
+  short theDim=boundary_opt[0];
+  if(verbose_opt[0]>1)
+    cout << boundary_opt[0] << endl;
+  ImgReaderGdal imgReader;
+  try{
+    imgReader.open(image_opt[0]);
+  }
+  catch(string errorstring){
+    cout << errorstring << endl;
+    exit(0);
+  }
+  int nband=(band_opt[0]<0)?imgReader.nrOfBand():band_opt.size();
+
+  if(fieldname_opt.size()<nband){
+    string bandString=fieldname_opt[0];
+    fieldname_opt.clear();
+    fieldname_opt.resize(nband);
+    for(int iband=0;iband<nband;++iband){
+      int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+      ostringstream fs;
+      fs << bandString << theBand;
+      fieldname_opt[iband]=fs.str();
+    }
+  }
+
+  if(verbose_opt[0])
+    std::cout << fieldname_opt << std::endl;
+  vector<ImgReaderGdal> maskReader;
+  if(mask_opt[0]!=""){
+    maskReader.resize(mask_opt.size());
+    for(int imask=0;imask<mask_opt.size();++imask){
+      if(verbose_opt[0]>1)
+        cout << "opening mask image file " << mask_opt[imask] << endl;
+      maskReader[imask].open(mask_opt[0]);
+      if(imgReader.isGeoRef())
+        assert(maskReader[imask].isGeoRef());
+    }
+  }
+
+  Vector2d<int> maskBuffer;
+  if(mask_opt[0]!=""){
+    maskBuffer.resize(mask_opt.size());
+    for(int imask=0;imask<maskReader.size();++imask)
+      maskBuffer[imask].resize(maskReader[imask].nrOfCol());
+  }
+  vector<double> oldmaskrow(mask_opt.size());
+  for(int imask=0;imask<mask_opt.size();++imask)
+    oldmaskrow[imask]=-1;
+  
+  if(verbose_opt[0]>1)
+    cout << "Number of bands in input image: " << imgReader.nrOfBand() << endl;
+
+  OGRFieldType fieldType;
+  OGRFieldType labelType;
+  int ogr_typecount=11;//hard coded for now!
+  if(verbose_opt[0]>1)
+    cout << "field and label types can be: ";
+  for(int iType = 0; iType < ogr_typecount; ++iType){
+    if(verbose_opt[0]>1)
+      cout << " " << OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType);
+    if( OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType) != NULL
+        && EQUAL(OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType),
+                 ftype_opt[0].c_str()))
+      fieldType=(OGRFieldType) iType;
+    if( OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType) != NULL
+        && EQUAL(OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType),
+                 ltype_opt[0].c_str()))
+      labelType=(OGRFieldType) iType;
+  }
+  switch( fieldType ){
+  case OFTInteger:
+  case OFTReal:
+  case OFTRealList:
+  case OFTString:
+    if(verbose_opt[0]>1)
+      cout << endl << "field type is: " << OGRFieldDefn::GetFieldTypeName(fieldType) << endl;
+    break;
+  default:
+    cerr << "field type " << OGRFieldDefn::GetFieldTypeName(fieldType) << " not supported" << endl;
+    exit(0);
+    break;
+  }
+  switch( labelType ){
+  case OFTInteger:
+  case OFTReal:
+  case OFTRealList:
+  case OFTString:
+    if(verbose_opt[0]>1)
+      cout << endl << "label type is: " << OGRFieldDefn::GetFieldTypeName(labelType) << endl;
+    break;
+  default:
+    cerr << "label type " << OGRFieldDefn::GetFieldTypeName(labelType) << " not supported" << endl;
+    exit(0);
+    break;
+  }
+  
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+  srandom(time(NULL));
+
+  assert(sample_opt[0]!="");
+  if((sample_opt[0].find(".tif"))!=string::npos){//raster file
+    if(!class_opt[0]){
+      cout << "Warning: no classes selected, if classes must be extracted, set to -1 for all classes using option -c -1" << endl;
+      ImgReaderGdal classReader;
+      ImgWriterOgr ogrWriter;
+      // if(verbose_opt[0]>1){
+      //   cout << "reading position from " << sample_opt[0] << endl;
+      //   cout << "class thresholds: " << endl;
+      //   for(int iclass=0;iclass<class_opt.size();++iclass){
+      //     if(threshold_opt.size()>1)
+      //       cout << class_opt[iclass] << ": " << threshold_opt[iclass] << endl;
+      //     else
+      //       cout << class_opt[iclass] << ": " << threshold_opt[0] << endl;
+      //   }
+      // }
+      classReader.open(sample_opt[0]);
+      // vector<int> classBuffer(classReader.nrOfCol());
+      vector<double> classBuffer(classReader.nrOfCol());
+      Vector2d<double> imgBuffer(nband);//[band][col]
+      vector<double> sample(2+nband);//x,y,band values
+      Vector2d<double> writeBuffer;
+      // vector<int> writeBufferClass;
+      vector<double> writeBufferClass;
+      vector<int> selectedClass;
+      Vector2d<double> selectedBuffer;
+      double oldimgrow=-1;
+      int irow=0;
+      int icol=0;
+      if(verbose_opt[0]>1)
+        cout << "extracting sample from image..." << endl;
+      progress=0;
+      pfnProgress(progress,pszMessage,pProgressArg);
+      for(irow=0;irow<classReader.nrOfRow();++irow){
+        if(irow%down_opt[0])
+          continue;
+        // classReader.readData(classBuffer,GDT_Int32,irow);
+        classReader.readData(classBuffer,GDT_Float64,irow);
+        double x,y;//geo coordinates
+        double iimg,jimg;//image coordinates in img image
+        for(icol=0;icol<classReader.nrOfCol();++icol){
+          if(icol%down_opt[0])
+            continue;
+          // int theClass=0;
+          double theClass=classBuffer[icol];
+          // int processClass=-1;
+          int processClass=0;
+          // if(class_opt[0]<0){//process every class except 0
+          //   if(classBuffer[icol]){
+          //     processClass=0;
+          //     theClass=classBuffer[icol];
+          //   }
+          // }
+          // else{
+          //   for(int iclass=0;iclass<class_opt.size();++iclass){
+          //     if(classBuffer[icol]==class_opt[iclass]){
+          //       processClass=iclass;
+          //       theClass=class_opt[iclass];
+          //     }
+          //   }
+          // }
+          // if(processClass>=0){
+          bool valid=true;
+          if(valid){
+            if(geo_opt[0]){
+              classReader.image2geo(icol,irow,x,y);
+              sample[0]=x;
+              sample[1]=y;
+              if(verbose_opt[0]>1){
+                cout.precision(12);
+                cout << theClass << " " << x << " " << y << endl;
+              }
+              //find col in img
+              imgReader.geo2image(x,y,iimg,jimg);
+              //nearest neighbour
+              jimg=static_cast<int>(jimg);
+              iimg=static_cast<int>(iimg);
+              if(static_cast<int>(iimg)<0||static_cast<int>(iimg)>=imgReader.nrOfCol())
+                continue;
+            }
+            else{
+              iimg=icol;
+              jimg=irow;
+              sample[0]=iimg;
+              sample[1]=jimg;
+            }
+            if(static_cast<int>(jimg)<0||static_cast<int>(jimg)>=imgReader.nrOfRow())
+              continue;
+            if(static_cast<int>(jimg)!=static_cast<int>(oldimgrow)){
+              assert(imgBuffer.size()==nband);
+              for(int iband=0;iband<nband;++iband){
+                int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+                imgReader.readData(imgBuffer[iband],GDT_Float64,static_cast<int>(jimg),theBand);
+                assert(imgBuffer[iband].size()==imgReader.nrOfCol());
+              }
+              oldimgrow=jimg;
+            }
+            // bool valid=true;
+            for(int imask=0;imask<mask_opt.size();++imask){
+              double colMask,rowMask;//image coordinates in mask image
+              if(mask_opt.size()>1){//multiple masks
+                if(geo_opt[0])
+                  maskReader[imask].geo2image(x,y,colMask,rowMask);
+                else{
+                  colMask=icol;
+                  rowMask=irow;
+                }
+                //nearest neighbour
+                rowMask=static_cast<int>(rowMask);
+                colMask=static_cast<int>(colMask);
+                if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[imask].nrOfCol())
+                  continue;
+                if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[imask])){
+                  if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[imask].nrOfRow())
+                    continue;
+                  else{
+                    maskReader[imask].readData(maskBuffer[imask],GDT_Int32,static_cast<int>(rowMask));
+                    oldmaskrow[imask]=rowMask;
+                  }
+                }
+                int ivalue=0;
+                if(mask_opt.size()==invalid_opt.size())//one invalid value for each mask
+                  ivalue=static_cast<int>(invalid_opt[imask]);
+                else//use same invalid value for each mask
+                  ivalue=static_cast<int>(invalid_opt[0]);
+                if(maskBuffer[imask][colMask]==ivalue){
+                  valid=false;
+                  break;
+                }
+              }
+              else if(maskReader.size()){
+                if(geo_opt[0])
+                  maskReader[0].geo2image(x,y,colMask,rowMask);
+                else{
+                  colMask=icol;
+                  rowMask=irow;
+                }
+                //nearest neighbour
+                rowMask=static_cast<int>(rowMask);
+                colMask=static_cast<int>(colMask);
+                if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[0].nrOfCol())
+                  continue;
+                if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[0])){
+                  if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[0].nrOfRow())
+                    continue;
+                  else{
+                    maskReader[0].readData(maskBuffer[0],GDT_Int32,static_cast<int>(rowMask));
+                    oldmaskrow[0]=rowMask;
+                  }
+                }
+                for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
+                  if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                    valid=false;
+                    break;
+                  }
+                }
+              }
+            }
+            if(valid){
+              for(int iband=0;iband<imgBuffer.size();++iband){
+                if(imgBuffer[iband].size()!=imgReader.nrOfCol()){
+                  cout << "Error in band " << iband << ": " << imgBuffer[iband].size() << "!=" << imgReader.nrOfCol() << endl;
+                  assert(imgBuffer[iband].size()==imgReader.nrOfCol());
+                }
+                sample[iband+2]=imgBuffer[iband][static_cast<int>(iimg)];
+              }
+              float theThreshold=(threshold_opt.size()>1)?threshold_opt[processClass]:threshold_opt[0];
+              if(theThreshold>0){//percentual value
+                double p=static_cast<double>(random())/(RAND_MAX);
+                p*=100.0;
+                if(p>theThreshold)
+                  continue;//do not select for now, go to next column
+              }
+              else{//absolute value
+                if(nvalid[processClass]>-theThreshold)
+                  continue;//do not select any more pixels for this class, go to next column to search for other classes
+              }
+              writeBuffer.push_back(sample);
+              writeBufferClass.push_back(theClass);
+              ++ntotalvalid;
+              ++(nvalid[processClass]);
+            }
+            else{
+              ++ntotalinvalid;
+              ++(ninvalid[processClass]);
+            }
+          }//processClass
+        }//icol
+        progress=static_cast<float>(irow+1.0)/classReader.nrOfRow();
+        pfnProgress(progress,pszMessage,pProgressArg);
+      }//irow
+      if(writeBuffer.size()>0){
+        assert(ntotalvalid==writeBuffer.size());
+        if(verbose_opt[0]>0)
+          cout << "creating image sample writer " << output_opt[0] << " with " << writeBuffer.size() << " samples (" << ntotalinvalid << " invalid)" << endl;
+        ogrWriter.open(output_opt[0]);
+        char     **papszOptions=NULL;
+        ostringstream slayer;
+        slayer << "training data";
+        string layername=slayer.str();
+        ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPoint, papszOptions);
+        string fieldname="fid";//number of the point
+        ogrWriter.createField(fieldname,OFTInteger);
+        map<string,double> pointAttributes;
+        ogrWriter.createField(label_opt[0],labelType);
+        for(int iband=0;iband<nband;++iband){
+          int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+          ogrWriter.createField(fieldname_opt[iband],fieldType);
+        }
+        pfnProgress(progress,pszMessage,pProgressArg);
+        cout << "writing sample to " << output_opt[0] << "..." << endl;
+        progress=0;
+        pfnProgress(progress,pszMessage,pProgressArg);
+        for(int isample=0;isample<writeBuffer.size();++isample){
+          if(verbose_opt[0]>1)
+            cout << "writing sample " << isample << endl;
+          pointAttributes[label_opt[0]]=writeBufferClass[isample];
+          for(int iband=0;iband<writeBuffer[0].size()-2;++iband){
+            int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+            // ostringstream fs;
+            // if(nband==1)
+            //   fs << fieldname_opt[0];
+            // else
+            //   fs << fieldname_opt[0] << theBand;
+            // pointAttributes[fs.str()]=writeBuffer[isample][iband+2];
+            pointAttributes[fieldname_opt[iband]]=writeBuffer[isample][iband+2];
+          }
+          if(verbose_opt[0]>1)
+            cout << "all bands written" << endl;
+          ogrWriter.addPoint(writeBuffer[isample][0],writeBuffer[isample][1],pointAttributes,fieldname,isample);
+          progress=static_cast<float>(isample+1.0)/writeBuffer.size();
+          pfnProgress(progress,pszMessage,pProgressArg);
+        }
+        ogrWriter.close();
+      }
+      else{
+        cout << "No data found for any class " << endl;
+      }
+      classReader.close();
+      nsample=writeBuffer.size();
+      if(verbose_opt[0]){
+        cout << "total number of samples written: " << nsample << endl;
+        for(int iclass=0;iclass<class_opt.size();++iclass)
+          cout << "class " << class_opt[iclass] << " has " << nvalid[iclass] << " samples" << endl;
+      }
+    }
+    else{//classification file
+      assert(class_opt[0]);
+      //   if(class_opt[0]){
+      assert(threshold_opt.size()==1||threshold_opt.size()==class_opt.size());
+      ImgReaderGdal classReader;
+      ImgWriterOgr ogrWriter;
+      if(verbose_opt[0]>1){
+        cout << "reading position from " << sample_opt[0] << endl;
+        cout << "class thresholds: " << endl;
+        for(int iclass=0;iclass<class_opt.size();++iclass){
+          if(threshold_opt.size()>1)
+            cout << class_opt[iclass] << ": " << threshold_opt[iclass] << endl;
+          else
+            cout << class_opt[iclass] << ": " << threshold_opt[0] << endl;
+        }
+      }
+      classReader.open(sample_opt[0]);
+      vector<int> classBuffer(classReader.nrOfCol());
+      // vector<double> classBuffer(classReader.nrOfCol());
+      Vector2d<double> imgBuffer(nband);//[band][col]
+      vector<double> sample(2+nband);//x,y,band values
+      Vector2d<double> writeBuffer;
+      vector<int> writeBufferClass;
+      // vector<double> writeBufferClass;
+      vector<int> selectedClass;
+      Vector2d<double> selectedBuffer;
+      double oldimgrow=-1;
+      int irow=0;
+      int icol=0;
+      if(verbose_opt[0]>1)
+        cout << "extracting sample from image..." << endl;
+      progress=0;
+      pfnProgress(progress,pszMessage,pProgressArg);
+      for(irow=0;irow<classReader.nrOfRow();++irow){
+        if(irow%down_opt[0])
+          continue;
+        classReader.readData(classBuffer,GDT_Int32,irow);
+        // classReader.readData(classBuffer,GDT_Float64,irow);
+        double x,y;//geo coordinates
+        double iimg,jimg;//image coordinates in img image
+        for(icol=0;icol<classReader.nrOfCol();++icol){
+          if(icol%down_opt[0])
+            continue;
+          int theClass=0;
+          // double theClass=0;
+          int processClass=-1;
+          if(class_opt[0]<0){//process every class except 0
+            if(classBuffer[icol]){
+              processClass=0;
+              theClass=classBuffer[icol];
+            }
+          }
+          else{
+            for(int iclass=0;iclass<class_opt.size();++iclass){
+              if(classBuffer[icol]==class_opt[iclass]){
+                processClass=iclass;
+                theClass=class_opt[iclass];
+              }
+            }
+          }
+          if(processClass>=0){
+            //         if(classBuffer[icol]==class_opt[0]){
+            if(geo_opt[0]){
+              classReader.image2geo(icol,irow,x,y);
+              sample[0]=x;
+              sample[1]=y;
+              if(verbose_opt[0]>1){
+                cout.precision(12);
+                cout << theClass << " " << x << " " << y << endl;
+              }
+              //find col in img
+              imgReader.geo2image(x,y,iimg,jimg);
+              //nearest neighbour
+              jimg=static_cast<int>(jimg);
+              iimg=static_cast<int>(iimg);
+              if(static_cast<int>(iimg)<0||static_cast<int>(iimg)>=imgReader.nrOfCol())
+                continue;
+            }
+            else{
+              iimg=icol;
+              jimg=irow;
+              sample[0]=iimg;
+              sample[1]=jimg;
+            }
+            if(static_cast<int>(jimg)<0||static_cast<int>(jimg)>=imgReader.nrOfRow())
+              continue;
+            if(static_cast<int>(jimg)!=static_cast<int>(oldimgrow)){
+              assert(imgBuffer.size()==nband);
+              for(int iband=0;iband<nband;++iband){
+                int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+                imgReader.readData(imgBuffer[iband],GDT_Float64,static_cast<int>(jimg),theBand);
+                assert(imgBuffer[iband].size()==imgReader.nrOfCol());
+              }
+              oldimgrow=jimg;
+            }
+            bool valid=true;
+            for(int imask=0;imask<mask_opt.size();++imask){
+              double colMask,rowMask;//image coordinates in mask image
+              if(mask_opt.size()>1){//multiple masks
+                if(geo_opt[0])
+                  maskReader[imask].geo2image(x,y,colMask,rowMask);
+                else{
+                  colMask=icol;
+                  rowMask=irow;
+                }
+                //nearest neighbour
+                rowMask=static_cast<int>(rowMask);
+                colMask=static_cast<int>(colMask);
+                if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[imask].nrOfCol())
+                  continue;
+                if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[imask])){
+                  if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[imask].nrOfRow())
+                    continue;
+                  else{
+                    maskReader[imask].readData(maskBuffer[imask],GDT_Int32,static_cast<int>(rowMask));
+                    oldmaskrow[imask]=rowMask;
+                  }
+                }
+                int ivalue=0;
+                if(mask_opt.size()==invalid_opt.size())//one invalid value for each mask
+                  ivalue=static_cast<int>(invalid_opt[imask]);
+                else//use same invalid value for each mask
+                  ivalue=static_cast<int>(invalid_opt[0]);
+                if(maskBuffer[imask][colMask]==ivalue){
+                  valid=false;
+                  break;
+                }
+              }
+              else if(maskReader.size()){
+                if(geo_opt[0])
+                  maskReader[0].geo2image(x,y,colMask,rowMask);
+                else{
+                  colMask=icol;
+                  rowMask=irow;
+                }
+                //nearest neighbour
+                rowMask=static_cast<int>(rowMask);
+                colMask=static_cast<int>(colMask);
+                if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[0].nrOfCol())
+                  continue;
+                if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[0])){
+                  if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[0].nrOfRow())
+                    continue;
+                  else{
+                    maskReader[0].readData(maskBuffer[0],GDT_Int32,static_cast<int>(rowMask));
+                    oldmaskrow[0]=rowMask;
+                  }
+                }
+                for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
+                  if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                    valid=false;
+                    break;
+                  }
+                }
+              }
+            }
+            if(valid){
+              for(int iband=0;iband<imgBuffer.size();++iband){
+                if(imgBuffer[iband].size()!=imgReader.nrOfCol()){
+                  cout << "Error in band " << iband << ": " << imgBuffer[iband].size() << "!=" << imgReader.nrOfCol() << endl;
+                  assert(imgBuffer[iband].size()==imgReader.nrOfCol());
+                }
+                sample[iband+2]=imgBuffer[iband][static_cast<int>(iimg)];
+              }
+              float theThreshold=(threshold_opt.size()>1)?threshold_opt[processClass]:threshold_opt[0];
+              if(theThreshold>0){//percentual value
+                double p=static_cast<double>(random())/(RAND_MAX);
+                p*=100.0;
+                if(p>theThreshold)
+                  continue;//do not select for now, go to next column
+              }
+              else{//absolute value
+                if(nvalid[processClass]>-theThreshold)
+                  continue;//do not select any more pixels for this class, go to next column to search for other classes
+              }
+              writeBuffer.push_back(sample);
+              //             writeBufferClass.push_back(class_opt[processClass]);
+              writeBufferClass.push_back(theClass);
+              ++ntotalvalid;
+              ++(nvalid[processClass]);
+            }
+            else{
+              ++ntotalinvalid;
+              ++(ninvalid[processClass]);
+            }
+          }//processClass
+        }//icol
+        progress=static_cast<float>(irow+1.0)/classReader.nrOfRow();
+        pfnProgress(progress,pszMessage,pProgressArg);
+      }//irow
+      if(writeBuffer.size()>0){
+        assert(ntotalvalid==writeBuffer.size());
+        if(verbose_opt[0]>0)
+          cout << "creating image sample writer " << output_opt[0] << " with " << writeBuffer.size() << " samples (" << ntotalinvalid << " invalid)" << endl;
+        ogrWriter.open(output_opt[0]);
+        char     **papszOptions=NULL;
+        ostringstream slayer;
+        slayer << "training data";
+        string layername=slayer.str();
+        ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPoint, papszOptions);
+        string fieldname="fid";//number of the point
+        ogrWriter.createField(fieldname,OFTInteger);
+        map<string,double> pointAttributes;
+        //         ogrWriter.createField(label_opt[0],OFTInteger);
+        ogrWriter.createField(label_opt[0],labelType);
+        for(int iband=0;iband<nband;++iband){
+          int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+          // ostringstream fs;
+          // if(nband==1)
+          //   fs << fieldname_opt[0];
+          // else
+          //   fs << fieldname_opt[0] << theBand;
+          // ogrWriter.createField(fs.str(),fieldType);
+          ogrWriter.createField(fieldname_opt[iband],fieldType);
+        }
+        pfnProgress(progress,pszMessage,pProgressArg);
+        cout << "writing sample to " << output_opt[0] << "..." << endl;
+        progress=0;
+        pfnProgress(progress,pszMessage,pProgressArg);
+        for(int isample=0;isample<writeBuffer.size();++isample){
+          pointAttributes[label_opt[0]]=writeBufferClass[isample];
+          for(int iband=0;iband<writeBuffer[0].size()-2;++iband){
+            int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+            // ostringstream fs;
+            // if(nband==1)
+            //   fs << fieldname_opt[0];
+            // else
+            //   fs << fieldname_opt[0] << theBand;
+            // pointAttributes[fs.str()]=writeBuffer[isample][iband+2];
+            pointAttributes[fieldname_opt[iband]]=writeBuffer[isample][iband+2];
+          }
+          ogrWriter.addPoint(writeBuffer[isample][0],writeBuffer[isample][1],pointAttributes,fieldname,isample);
+          progress=static_cast<float>(isample+1.0)/writeBuffer.size();
+          pfnProgress(progress,pszMessage,pProgressArg);
+        }
+        ogrWriter.close();
+      }
+      else{
+        cout << "No data found for any class " << endl;
+      }
+      classReader.close();
+      nsample=writeBuffer.size();
+      if(verbose_opt[0]){
+        cout << "total number of samples written: " << nsample << endl;
+        for(int iclass=0;iclass<class_opt.size();++iclass)
+          cout << "class " << class_opt[iclass] << " has " << nvalid[iclass] << " samples" << endl;
+      }
+    }
+  }
+  else{//vector file
+      if(verbose_opt[0]>1)
+        cout << "reading position from shape file " << sample_opt[0] << endl;
+      ImgReaderOgr sampleReader;
+      try{
+        sampleReader.open(sample_opt[0]);
+      }
+      catch(string errorString){
+        cout << errorString << endl;
+        exit(1);
+      }
+      if(verbose_opt[0]>1)
+        cout << "creating image sample writer " << output_opt[0] << endl;
+      ImgWriterOgr ogrWriter;
+      ogrWriter.open(output_opt[0]);
+      char     **papszOptions=NULL;
+      ostringstream slayer;
+      slayer << "training data";
+      string layername=slayer.str();
+      if(polygon_opt[0]){
+        if(verbose_opt[0])
+          cout << "create polygons" << endl;
+        ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPolygon, papszOptions);
+      }
+      else{
+        if(verbose_opt[0])
+          cout << "create points" << endl;
+        ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPoint, papszOptions);
+      }
+      ogrWriter.copyFields(sampleReader);
+      vector<string> fieldnames;
+      sampleReader.getFields(fieldnames);
+      assert(fieldnames.size()==ogrWriter.getFieldCount());
+      map<string,double> pointAttributes;
+      switch(rule_opt[0]){
+      case(2):{//proportion for each class
+        for(int iclass=0;iclass<class_opt.size();++iclass){
+          ostringstream cs;
+          cs << class_opt[iclass];
+          ogrWriter.createField(cs.str(),fieldType);
+        }
+        if(keepFeatures_opt[0])
+          ogrWriter.createField("origId",OFTInteger);//the fieldId of the original feature
+        break;
+      }
+      case(3):
+      case(4):
+        ogrWriter.createField(label_opt[0],fieldType);
+        break;
+      case(0):
+      case(1):
+      default:{
+        if(keepFeatures_opt[0])
+          ogrWriter.createField("origId",OFTInteger);//the fieldId of the original feature
+        for(int windowJ=-theDim/2;windowJ<(theDim+1)/2;++windowJ){
+          for(int windowI=-theDim/2;windowI<(theDim+1)/2;++windowI){
+            if(disc_opt[0]&&(windowI*windowI+windowJ*windowJ>(theDim/2)*(theDim/2)))
+              continue;
+            for(int iband=0;iband<nband;++iband){
+              int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+              ostringstream fs;
+              if(theDim>1)
+                fs << fieldname_opt[iband] << "_" << windowJ << "_" << windowI;
+              else
+                fs << fieldname_opt[iband];
+              if(verbose_opt[0]>1)
+                cout << "creating field " << fs.str() << endl;
+
+              ogrWriter.createField(fs.str(),fieldType);
+            }
+          }
+        }
+        break;
+      }
+      }
+      OGRLayer  *readLayer;
+      readLayer = sampleReader.getDataSource()->GetLayer(0);
+      OGRLayer *writeLayer;
+      writeLayer=ogrWriter.getDataSource()->GetLayer(0);
+      readLayer->ResetReading();
+      OGRFeature *readFeature;
+      int isample=0;
+      int ifeature=0;
+
+      ImgWriterOgr boxWriter;
+      if(rbox_opt[0]>0||cbox_opt[0]>0){
+        if(verbose_opt[0]>1)
+          cout << "opening box writer " << bufferOutput_opt[0] << endl;
+        boxWriter.open(bufferOutput_opt[0]);
+        string layername="buffer";
+        boxWriter.createLayer(layername, imgReader.getProjection(), wkbPolygon);
+        string fieldname="fid";//number of the point
+        if(verbose_opt[0]>1)
+          cout << "creating field " << fieldname << endl;
+        //       ogrWriter.createField(fieldname,OFTInteger);
+        boxWriter.createField(fieldname,OFTInteger);
+      }
+      while( (readFeature = readLayer->GetNextFeature()) != NULL ){
+        if(verbose_opt[0]>0)
+          cout << "reading feature " << readFeature->GetFID() << endl;
+        if(threshold_opt[0]>0){//percentual value
+          double p=static_cast<double>(random())/(RAND_MAX);
+          p*=100.0;
+          if(p>threshold_opt[0])
+            continue;//do not select for now, go to next feature
+        }
+        else{//absolute value
+          if(ntotalvalid>-threshold_opt[0]){
+            continue;//do not select any more pixels, go to next column feature
+          }
+        }
+        if(verbose_opt[0]>0)
+          cout << "processing feature " << readFeature->GetFID() << endl;
+        //get x and y from readFeature
+        double x,y;
+        OGRGeometry *poGeometry;
+        poGeometry = readFeature->GetGeometryRef();
+        assert(poGeometry!=NULL);
+        try{
+          if(wkbFlatten(poGeometry->getGeometryType()) == wkbPoint ){
+            assert(class_opt.size()==1);//class_opt not implemented for point yet
+            OGRPoint *poPoint = (OGRPoint *) poGeometry;
+            x=poPoint->getX();
+            y=poPoint->getY();
+            bool valid=true;
+            for(int imask=0;imask<mask_opt.size();++imask){
+              double colMask,rowMask;//image coordinates in mask image
+              if(mask_opt.size()>1){//multiple masks
+                maskReader[imask].geo2image(x,y,colMask,rowMask);
+                //nearest neighbour
+                rowMask=static_cast<int>(rowMask);
+                colMask=static_cast<int>(colMask);
+                if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[imask].nrOfCol())
+                  continue;
+                if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[imask])){
+                  if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[imask].nrOfRow())
+                    continue;
+                  else{
+                    maskReader[imask].readData(maskBuffer[imask],GDT_Int32,static_cast<int>(rowMask));
+                    oldmaskrow[imask]=rowMask;
+                    assert(maskBuffer.size()==maskReader[imask].nrOfBand());
+                  }
+                }
+                //               char ivalue=0;
+                int ivalue=0;
+                if(mask_opt.size()==invalid_opt.size())//one invalid value for each mask
+                  ivalue=static_cast<int>(invalid_opt[imask]);
+                else//use same invalid value for each mask
+                  ivalue=static_cast<int>(invalid_opt[0]);
+                if(maskBuffer[imask][colMask]==ivalue){
+                  valid=false;
+                  break;
+                }
+              }
+              else if(maskReader.size()){
+                maskReader[0].geo2image(x,y,colMask,rowMask);
+                //nearest neighbour
+                rowMask=static_cast<int>(rowMask);
+                colMask=static_cast<int>(colMask);
+                if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[0].nrOfCol()){
+                  continue;
+                  // cerr << colMask << " out of mask col range!" << endl;
+                  // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                  // assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[0].nrOfCol());
+                }
+              
+                if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[0])){
+                  if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[0].nrOfRow()){
+                    continue;
+                    // cerr << rowMask << " out of mask row range!" << endl;
+                    // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                    // assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
+                  }
+                  else{
+                    maskReader[0].readData(maskBuffer[0],GDT_Int32,static_cast<int>(rowMask));
+                    oldmaskrow[0]=rowMask;
+                  }
+                }
+                for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
+                  if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                    valid=false;
+                    break;
+                  }
+                }
+              }
+            }
+            if(!valid)
+              continue;
+
+            double value;
+            double i_centre,j_centre;
+            if(geo_opt[0])
+              imgReader.geo2image(x,y,i_centre,j_centre);
+            else{
+              i_centre=x;
+              j_centre=y;
+            }
+            //nearest neighbour
+            j_centre=static_cast<int>(j_centre);
+            i_centre=static_cast<int>(i_centre);
+            //check if j_centre is out of bounds
+            if(static_cast<int>(j_centre)<0||static_cast<int>(j_centre)>=imgReader.nrOfRow())
+              continue;
+            //check if i_centre is out of bounds
+            if(static_cast<int>(i_centre)<0||static_cast<int>(i_centre)>=imgReader.nrOfCol())
+              continue;
+
+            if(rbox_opt[0]){
+              vector< vector<OGRPoint*> > points;
+              points.resize(rbox_opt.size());
+              if(verbose_opt[0]>1)
+                cout << "creating rectangular box for sample " << isample << ": ";
+              for(int ibox=0;ibox<rbox_opt.size();++ibox){
+                int npoint=4;
+                if(verbose_opt[0]>1)
+                  cout << ibox << " ";
+                points[ibox].resize(npoint+1);
+                vector<OGRPoint> pbPoint(npoint+1);
+                pbPoint[0].setX(x-0.5*rbox_opt[ibox]);
+                pbPoint[0].setY(y+0.5*rbox_opt[ibox]);
+                points[ibox][0]=&(pbPoint[0]);//start point UL
+                points[ibox][4]=&(pbPoint[0]);//end point
+                pbPoint[1].setX(x+0.5*rbox_opt[ibox]);
+                pbPoint[1].setY(y+0.5*rbox_opt[ibox]);
+                points[ibox][1]=&(pbPoint[1]);//UR
+                pbPoint[2].setX(x+0.5*rbox_opt[ibox]);
+                pbPoint[2].setY(y-0.5*rbox_opt[ibox]);
+                points[ibox][2]=&(pbPoint[2]);//LR
+                pbPoint[3].setX(x-0.5*rbox_opt[ibox]);
+                pbPoint[3].setY(y-0.5*rbox_opt[ibox]);
+                points[ibox][3]=&(pbPoint[3]);//LL
+                string fieldname="fid";//number of the point
+                boxWriter.addRing(points[ibox],fieldname,isample);
+                // boxWriter.addLineString(points[ibox],fieldname,isample);
+              }
+              if(verbose_opt[0]>1)
+                cout << endl;
+            }
+            if(cbox_opt[0]>0){
+              vector< vector<OGRPoint*> > points;
+              points.resize(cbox_opt.size());
+              if(verbose_opt[0]>1)
+                cout << "creating circular box ";
+              for(int ibox=0;ibox<cbox_opt.size();++ibox){
+                int npoint=50;
+                if(verbose_opt[0]>1)
+                  cout << ibox << " ";
+                points[ibox].resize(npoint+1);
+                vector<OGRPoint> pbPoint(npoint+1);
+                double radius=cbox_opt[ibox]/2.0;
+                double alpha=0;
+                for(int ipoint=0;ipoint<npoint;++ipoint){
+                  alpha=ipoint*2.0*PI/static_cast<double>(npoint);
+                  pbPoint[ipoint].setX(x+radius*cos(alpha));
+                  pbPoint[ipoint].setY(y+radius*sin(alpha));
+                  points[ibox][ipoint]=&(pbPoint[ipoint]);
+                }
+                alpha=0;
+                pbPoint[npoint].setX(x+radius*cos(alpha));
+                pbPoint[npoint].setY(y+radius*sin(alpha));
+                points[ibox][npoint]=&(pbPoint[npoint]);
+                string fieldname="fid";//number of the point
+                boxWriter.addRing(points[ibox],fieldname,isample);
+                // boxWriter.addLineString(points[ibox],fieldname,isample);
+              }
+              if(verbose_opt[0]>1)
+                cout << endl;
+            }
+      
+            OGRFeature *writeFeature;
+            writeFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
+            if(verbose_opt[0]>1)
+              cout << "copying fields from points " << sample_opt[0] << endl;
+            if(writeFeature->SetFrom(readFeature)!= OGRERR_NONE)
+              cerr << "writing feature failed" << endl;
+
+            if(verbose_opt[0]>1)
+              cout << "write feature has " << writeFeature->GetFieldCount() << " fields" << endl;
+
+            vector<double> windowBuffer;
+            for(int windowJ=-theDim/2;windowJ<(theDim+1)/2;++windowJ){
+              for(int windowI=-theDim/2;windowI<(theDim+1)/2;++windowI){
+                if(disc_opt[0]&&(windowI*windowI+windowJ*windowJ>(theDim/2)*(theDim/2)))
+                  continue;
+                int j=j_centre+windowJ;
+                //check if j is out of bounds
+                if(static_cast<int>(j)<0||static_cast<int>(j)>=imgReader.nrOfRow())
+                  continue;
+                int i=i_centre+windowI;
+                //check if i is out of bounds
+                if(static_cast<int>(i)<0||static_cast<int>(i)>=imgReader.nrOfCol())
+                  continue;
+                if(verbose_opt[0]>1)
+                  cout << "reading image value at " << i << "," << j;
+                for(int iband=0;iband<nband;++iband){
+                  int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+                  imgReader.readData(value,GDT_Float64,i,j,theBand);
+                  if(verbose_opt[0]>1)
+                    cout << ": " << value << endl;
+                  ostringstream fs;
+                  if(theDim>1)
+                    fs << fieldname_opt[iband] << "_" << windowJ << "_" << windowI;
+                  else
+                    fs << fieldname_opt[iband];
+                  if(verbose_opt[0]>1)
+                    cout << "set field " << fs.str() << " to " << value << endl;
+                  switch( fieldType ){
+                  case OFTInteger:
+                    writeFeature->SetField(fs.str().c_str(),static_cast<int>(value));
+                    break;
+                  case OFTString:
+                    {
+                      ostringstream os;
+                      os << value;
+                      writeFeature->SetField(fs.str().c_str(),os.str().c_str());
+                      break;
+                    }
+                  case OFTReal:
+                    writeFeature->SetField(fs.str().c_str(),value);
+                    break;
+                  case OFTRealList:{
+                    int fieldIndex=writeFeature->GetFieldIndex(fs.str().c_str());
+                    int nCount;
+                    const double *theList;
+                    theList=writeFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                    vector<double> vectorList(nCount+1);
+                    for(int index=0;index<nCount;++index)
+                      vectorList[nCount]=value;
+                    writeFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                    break;
+                  }
+                  default://not supported
+                    assert(0);
+                    break;
+                  }
+                }
+              }
+            }
+            if(keepFeatures_opt[0])
+              writeFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
+            if(verbose_opt[0]>1)
+              cout << "creating point feature" << endl;
+            if(writeLayer->CreateFeature( writeFeature ) != OGRERR_NONE ){
+              string errorString="Failed to create feature in shapefile";
+              throw(errorString);
+            }
+            OGRFeature::DestroyFeature( writeFeature );
+            ++isample;
+            ++ntotalvalid;
+	    if(verbose_opt[0])
+	      std::cout << "ntotalvalid: " << ntotalvalid << std::endl;
+          }//if wkbPoint
+          else if(wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon){
+            
+            OGRPolygon readPolygon = *((OGRPolygon *) poGeometry);
+            OGRPolygon writePolygon;
+            OGRLinearRing writeRing;
+            OGRPoint writeCentroidPoint;
+            OGRFeature *writePolygonFeature;
+            OGRFeature *writeCentroidFeature;
+
+            readPolygon.closeRings();
+
+            if(verbose_opt[0]>1)
+              cout << "get centroid point from polygon" << endl;
+            readPolygon.Centroid(&writeCentroidPoint);
+
+            double ulx,uly,lrx,lry;
+            double uli,ulj,lri,lrj;
+            if(polygon_opt[0]&&rule_opt[0]==0){
+              ulx=writeCentroidPoint.getX();
+              uly=writeCentroidPoint.getY();
+              lrx=ulx;
+              lry=uly;
+            }
+            else{
+              //get envelope
+              if(verbose_opt[0])
+                cout << "reading envelope for polygon " << ifeature << endl;
+              OGREnvelope* psEnvelope=new OGREnvelope();
+              readPolygon.getEnvelope(psEnvelope);
+              ulx=psEnvelope->MinX;
+              uly=psEnvelope->MaxY;
+              lrx=psEnvelope->MaxX;
+              lry=psEnvelope->MinY;
+              delete psEnvelope;
+            }
+            if(geo_opt[0]){
+              imgReader.geo2image(ulx,uly,uli,ulj);
+              imgReader.geo2image(lrx,lry,lri,lrj);
+            }
+            else{
+              uli=ulx;
+              ulj=uly;
+              lri=lrx;
+              lrj=lry;
+            }
+            //nearest neighbour
+            ulj=static_cast<int>(ulj);
+            uli=static_cast<int>(uli);
+            lrj=static_cast<int>(lrj);
+            lri=static_cast<int>(lri);
+            //iterate through all pixels
+            if(verbose_opt[0]>1)
+              cout << "bounding box for polygon feature " << ifeature << ": " << uli << " " << ulj << " " << lri << " " << lrj << endl;
+
+            if(uli<0||lri>=imgReader.nrOfCol()||ulj<0||ulj>=imgReader.nrOfRow())
+               continue;
+
+            int nPointPolygon=0;
+            if(polygon_opt[0]){
+              writePolygonFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
+            }
+            else if(rule_opt[0]==1)
+              writeCentroidFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
+            //previously here
+            vector<double> polyValues;
+            switch(rule_opt[0]){
+            case(0):
+            case(1):
+            default:
+              polyValues.resize(nband);
+            break;
+            case(2):
+            case(3):
+            case(4):
+              polyValues.resize(class_opt.size());
+            break;
+            }
+            for(int index=0;index<polyValues.size();++index)
+              polyValues[index]=0;
+            OGRPoint thePoint;
+            for(int j=ulj;j<=lrj;++j){
+              for(int i=uli;i<=lri;++i){
+                //check if point is on surface
+                double x=0;
+                double y=0;
+                imgReader.image2geo(i,j,x,y);
+                thePoint.setX(x);
+                thePoint.setY(y);
+                // //test
+                // writeRing.addPoint(&thePoint);
+                // if(thePoint.Within(&readPolygon)){
+                if(readPolygon.Contains(&thePoint)){
+                  bool valid=true;
+                  for(int imask=0;imask<mask_opt.size();++imask){
+                    double colMask,rowMask;//image coordinates in mask image
+                    if(mask_opt.size()>1){//multiple masks
+                      maskReader[imask].geo2image(x,y,colMask,rowMask);
+                      //nearest neighbour
+                      rowMask=static_cast<int>(rowMask);
+                      colMask=static_cast<int>(colMask);
+                      if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[imask].nrOfCol())
+                        continue;
+                      // {
+                      //   cerr << colMask << " out of mask col range!" << endl;
+                      //   cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                      //   assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[imask].nrOfCol());
+                      // }
+              
+                      if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[imask])){
+                        if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[imask].nrOfRow())
+                          continue;
+                        // {
+                        //   cerr << rowMask << " out of mask row range!" << endl;
+                        //   cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                        //   assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
+                        // }
+                        else{
+                          maskReader[imask].readData(maskBuffer[imask],GDT_Int32,static_cast<int>(rowMask));
+                          oldmaskrow[imask]=rowMask;
+                          assert(maskBuffer.size()==maskReader[imask].nrOfBand());
+                        }
+                      }
+                      //               char ivalue=0;
+                      int ivalue=0;
+                      if(mask_opt.size()==invalid_opt.size())//one invalid value for each mask
+                        ivalue=static_cast<int>(invalid_opt[imask]);
+                      else//use same invalid value for each mask
+                        ivalue=static_cast<int>(invalid_opt[0]);
+                      if(maskBuffer[imask][colMask]==ivalue){
+                        valid=false;
+                        break;
+                      }
+                    }
+                    else if(maskReader.size()){
+                      maskReader[0].geo2image(x,y,colMask,rowMask);
+                      //nearest neighbour
+                      rowMask=static_cast<int>(rowMask);
+                      colMask=static_cast<int>(colMask);
+                      if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[0].nrOfCol())
+                        continue;
+                      // {
+                      //   cerr << colMask << " out of mask col range!" << endl;
+                      //   cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                      //   assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[0].nrOfCol());
+                      // }
+              
+                      if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[0])){
+                        if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[0].nrOfRow())
+                          continue;
+                        // {
+                        //   cerr << rowMask << " out of mask row range!" << endl;
+                        //   cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                        //   assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
+                        // }
+                        else{
+                          maskReader[0].readData(maskBuffer[0],GDT_Int32,static_cast<int>(rowMask));
+                          oldmaskrow[0]=rowMask;
+                        }
+                      }
+                      for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
+                        if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                          valid=false;
+                          break;
+                        }
+                      }
+                    }
+                  }
+                  if(!valid)
+                    continue;
+                  //check if within raster image
+                  if(i<0||i>=imgReader.nrOfCol())
+                    continue;
+                  if(j<0||j>=imgReader.nrOfRow())
+                    continue;
+                  writeRing.addPoint(&thePoint);
+                  if(verbose_opt[0]>1)
+                    cout << "point is on surface:" << thePoint.getX() << "," << thePoint.getY() << endl;
+                  ++nPointPolygon;
+                  OGRFeature *writePointFeature;
+                  if(!polygon_opt[0]){
+                    //create feature
+                    if(rule_opt[0]!=1){//do not create in case of mean value (only create point at centroid
+                      writePointFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
+                      if(verbose_opt[0]>1)
+                        cout << "copying fields from polygons " << sample_opt[0] << endl;
+                      if(writePointFeature->SetFrom(readFeature)!= OGRERR_NONE)
+                        cerr << "writing feature failed" << endl;
+                      writePointFeature->SetGeometry(&thePoint);
+                      OGRGeometry *updateGeometry;
+                      updateGeometry = writePointFeature->GetGeometryRef();
+                      OGRPoint *poPoint = (OGRPoint *) updateGeometry;
+                      if(verbose_opt[0]>1)
+                        cout << "write feature has " << writePointFeature->GetFieldCount() << " fields" << endl;
+                    }
+                  }
+                  if(verbose_opt[0]>1)
+                    cout << "reading image value within polygon at position " << i << "," << j;
+                  for(int iband=0;iband<nband;++iband){
+                    int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+                    double value=0;
+                    imgReader.readData(value,GDT_Float64,i,j,theBand);
+                    if(verbose_opt[0]>1)
+                      cout << ": " << value << endl;
+                    if(polygon_opt[0]||rule_opt[0]==1){
+                      int iclass=0;
+                      switch(rule_opt[0]){
+                      case(0)://in centroid if polygon_opt==true or all values as points if polygon_opt!=true
+                      default:
+                        polyValues[iband]=value;
+                        break;
+                      case(1)://mean as polygon if polygon_opt==true or as point in centroid if polygon_opt!=true
+                        polyValues[iband]+=value;
+                      break;
+                      case(2):
+                      case(3):
+                      case(4):
+                        for(iclass=0;iclass<class_opt.size();++iclass){
+                          if(value==class_opt[iclass]){
+                            assert(polyValues.size()>iclass);
+                            polyValues[iclass]+=1;//value
+                            break;
+                          }
+                        }
+                      break;
+                      }
+                    }
+                    else{
+                      // ostringstream fs;
+                      // if(imgReader.nrOfBand()==1)
+                      //   fs << fieldname_opt[0];
+                      // else
+                      //   fs << fieldname_opt[0] << theBand;
+                      if(verbose_opt[0]>1)
+                        cout << "set field " << fieldname_opt[iband] << " to " << value << endl;
+                      switch( fieldType ){
+                      case OFTInteger:
+                        writePointFeature->SetField(fieldname_opt[iband].c_str(),static_cast<int>(value));
+                        break;
+                      case OFTString:
+                        {
+                          ostringstream os;
+                          os << value;
+                          writePointFeature->SetField(fieldname_opt[iband].c_str(),os.str().c_str());
+                          break;
+                        }
+                      case OFTReal:
+                        writePointFeature->SetField(fieldname_opt[iband].c_str(),value);
+                        break;
+                      case OFTRealList:{
+                        int fieldIndex=writePointFeature->GetFieldIndex(fieldname_opt[iband].c_str());
+                        int nCount;
+                        const double *theList;
+                        theList=writePointFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                        vector<double> vectorList(nCount+1);
+                        for(int index=0;index<nCount;++index)
+                          vectorList[nCount]=value;
+                        writePointFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                        break;
+                      }
+                      default://not supported
+                        assert(0);
+                        break;
+                      }
+                    }
+                  }
+                  if(!polygon_opt[0]){
+                    // if(keepFeatures_opt[0])
+                    //   writePointFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
+                    if(rule_opt[0]!=1){//do not create in case of mean value (only at centroid)
+                      if(keepFeatures_opt[0])
+                        writePointFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
+                      //write feature
+                      if(verbose_opt[0]>1)
+                        cout << "creating point feature" << endl;
+                      if(writeLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
+                        string errorString="Failed to create feature in shapefile";
+                        throw(errorString);
+                      }
+                      //destroy feature
+                      OGRFeature::DestroyFeature( writePointFeature );
+		      ++ntotalvalid;
+		      if(verbose_opt[0])
+			std::cout << "ntotalvalid(2): " << ntotalvalid << std::endl;
+		    }
+		  }
+                  ++isample;
+		}
+              }
+	    }
+            // //test
+            // cout << "before write polygon" << endl;
+            if(polygon_opt[0]||rule_opt[0]==1){
+              //add ring to polygon
+              if(polygon_opt[0]){
+                writePolygon.addRing(&writeRing);
+                writePolygon.closeRings();
+                //write geometry of writePolygon
+                writePolygonFeature->SetGeometry(&writePolygon);
+                if(writePolygonFeature->SetFrom(readFeature)!= OGRERR_NONE)
+                  cerr << "writing feature failed" << endl;
+                if(verbose_opt[0]>1)
+                  cout << "copying new fields write polygon " << sample_opt[0] << endl;
+                if(verbose_opt[0]>1)
+                  cout << "write feature has " << writePolygonFeature->GetFieldCount() << " fields" << endl;
+                //write polygon feature
+              }
+              else{//write mean value of polygon to centroid point (rule_opt[0]==1)
+                //create feature
+                if(verbose_opt[0]>1)
+                  cout << "copying fields from polygons " << sample_opt[0] << endl;
+                if(writeCentroidFeature->SetFrom(readFeature)!= OGRERR_NONE)
+                  cerr << "writing feature failed" << endl;
+                writeCentroidFeature->SetGeometry(&writeCentroidPoint);
+                OGRGeometry *updateGeometry;
+                updateGeometry = writeCentroidFeature->GetGeometryRef();
+                assert(wkbFlatten(updateGeometry->getGeometryType()) == wkbPoint );
+                if(verbose_opt[0]>1)
+                  cout << "write feature has " << writeCentroidFeature->GetFieldCount() << " fields" << endl;
+              }
+              switch(rule_opt[0]){
+              case(0)://value at each point (or at centroid of polygon if line is not set
+              default:{
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                for(int index=0;index<polyValues.size();++index){
+                  double theValue=polyValues[index];
+                  // ostringstream fs;
+                  if(verbose_opt[0])
+                    cout << "number of points in polygon: " << nPointPolygon << endl;
+                  int theBand=(band_opt[0]<0)?index:band_opt[index];
+                  // if(nband==1)
+                  //   fs << fieldname_opt[0];
+                  // else
+                  //   fs << fieldname_opt[0] << theBand;
+
+                  if(verbose_opt[0]>1)
+                    cout << "set field " << fieldname_opt[index] << " to " << theValue << endl;
+                  switch( fieldType ){
+                  case OFTInteger:
+                    if(polygon_opt[0])
+                      writePolygonFeature->SetField(fieldname_opt[index].c_str(),static_cast<int>(theValue));
+                    else
+                      writeCentroidFeature->SetField(fieldname_opt[index].c_str(),static_cast<int>(theValue));
+                    break;
+                  case OFTString:
+                    {
+                      ostringstream os;
+                      os << theValue;
+                      if(polygon_opt[0])
+                        writePolygonFeature->SetField(fieldname_opt[index].c_str(),os.str().c_str());
+                      else
+                        writeCentroidFeature->SetField(fieldname_opt[index].c_str(),os.str().c_str());
+                      break;
+                    }
+                  case OFTReal:
+                      if(polygon_opt[0])
+                        writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
+                      else
+                        writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
+                      break;
+                  case OFTRealList:{
+                    int fieldIndex;
+                    int nCount;
+                    const double *theList;
+                    vector<double> vectorList;
+                    if(polygon_opt[0]){
+                      fieldIndex=writePolygonFeature->GetFieldIndex(fieldname_opt[index].c_str());
+                      theList=writePolygonFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                      vectorList.resize(nCount+1);
+                      for(int index=0;index<nCount;++index)
+                        vectorList[index]=theList[index];
+                      vectorList[nCount]=theValue;
+                      writePolygonFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                    }
+                    else{
+                      fieldIndex=writeCentroidFeature->GetFieldIndex(fieldname_opt[index].c_str());
+                      theList=writeCentroidFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                      vectorList.resize(nCount+1);
+                      for(int index=0;index<nCount;++index)
+                        vectorList[index]=theList[index];
+                      vectorList[nCount]=theValue;
+                      writeCentroidFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                    }
+                    break;
+                  }
+                  default://not supported
+                    cout << "field type not supported yet..." << endl;
+                    break;
+                  }
+                }
+                break;
+              }
+              case(1):{//mean value (written to centroid of polygon if line is not set
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                for(int index=0;index<polyValues.size();++index){
+                  double theValue=polyValues[index];
+                  // ostringstream fs;
+                  theValue/=nPointPolygon;
+                  int theBand=(band_opt[0]<0)?index:band_opt[index];
+                  // if(nband==1)
+                  //   fs << fieldname_opt[0];
+                  // else
+                  //   fs << fieldname_opt[0] << theBand;
+                  if(verbose_opt[0]>1)
+                    cout << "set field " << fieldname_opt[index] << " to " << theValue << endl;
+                  switch( fieldType ){
+                  case OFTInteger:
+                    if(polygon_opt[0])
+                      writePolygonFeature->SetField(fieldname_opt[index].c_str(),static_cast<int>(theValue));
+                    else
+                      writeCentroidFeature->SetField(fieldname_opt[index].c_str(),static_cast<int>(theValue));
+                    break;
+                  case OFTString:
+                    {
+                      ostringstream os;
+                      os << theValue;
+                      if(polygon_opt[0])
+                        writePolygonFeature->SetField(fieldname_opt[index].c_str(),os.str().c_str());
+                      else
+                        writeCentroidFeature->SetField(fieldname_opt[index].c_str(),os.str().c_str());
+                      break;
+                    }
+                  case OFTReal:
+                    if(polygon_opt[0])
+                      writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
+                    else
+                      writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
+                    break;
+                  case OFTRealList:{
+                    int fieldIndex;
+                    int nCount;
+                    const double *theList;
+                    vector<double> vectorList;
+                    if(polygon_opt[0]){
+                      fieldIndex=writePolygonFeature->GetFieldIndex(fieldname_opt[index].c_str());
+                      theList=writePolygonFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                      vectorList.resize(nCount+1);
+                      for(int index=0;index<nCount;++index)
+                        vectorList[index]=theList[index];
+                      vectorList[nCount]=theValue;
+                      writePolygonFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                    }
+                    else{
+                      fieldIndex=writeCentroidFeature->GetFieldIndex(fieldname_opt[index].c_str());
+                      theList=writeCentroidFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                      vectorList.resize(nCount+1);
+                      for(int index=0;index<nCount;++index)
+                        vectorList[index]=theList[index];
+                      vectorList[nCount]=theValue;
+                      writeCentroidFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                    }
+                    break;
+                  }
+                  default://not supported
+                    cout << "field type not supported yet..." << endl;
+                    break;
+                  }
+                }
+                break;
+              }
+              case(2):{//proportion classes
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                hist.normalize_pct(polyValues);
+                // hist.sum(polyValues);
+                for(int index=0;index<polyValues.size();++index){
+                  double theValue=polyValues[index];
+                  ostringstream fs;
+                  fs << class_opt[index];
+                  if(polygon_opt[0])
+                    writePolygonFeature->SetField(fs.str().c_str(),static_cast<int>(theValue));
+                  else
+                    writeCentroidFeature->SetField(fs.str().c_str(),static_cast<int>(theValue));
+                }
+                break;
+              }
+              case(3):{//custom
+                assert(polygon_opt[0]);//not implemented for points
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                hist.normalize_pct(polyValues);
+                assert(polyValues.size()==2);//11:broadleaved, 12:coniferous
+                if(polyValues[0]>=75)//broadleaved
+                  writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(11));
+                else if(polyValues[1]>=75)//coniferous
+                  writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(12));
+                else if(polyValues[0]>25&&polyValues[1]>25)//mixed
+                  writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(13));
+                else{
+                  if(verbose_opt[0]){
+                    cout << "No valid value in polyValues..." << endl;
+                    for(int index=0;index<polyValues.size();++index){
+                      double theValue=polyValues[index];
+                      cout << theValue << " ";
+                    }
+                    cout << endl;
+                  }
+                  writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(20));
+                }
+                break;
+              }
+              case(4):{//minimum of polygon
+                assert(polygon_opt[0]);//not implemented for points
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                //search for min class
+                //todo: change to minClass=hist.max(class_opt) once Optionpk is implemented...
+                int minClass=class_opt[class_opt.size()-1];//!hard coded for now, maximum class is last entry in class_opt
+                for(int iclass=0;iclass<class_opt.size();++iclass){
+                  if(polyValues[iclass]>0){
+                    if(verbose_opt[0]>1)
+                      cout << class_opt[iclass] << ": " << polyValues[iclass] << endl;
+                    if(class_opt[iclass]<minClass)
+                      minClass=class_opt[iclass];
+                  }
+                }
+                if(verbose_opt[0]>0)
+                  cout << "minClass: " << minClass << endl;
+                writePolygonFeature->SetField(label_opt[0].c_str(),minClass);
+                break;
+              }
+              }
+              if(polygon_opt[0]){
+                if(keepFeatures_opt[0])
+                  writePolygonFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
+                if(verbose_opt[0]>1)
+                  cout << "creating polygon feature" << endl;
+                if(writeLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
+                  string errorString="Failed to create polygon feature in shapefile";
+                  throw(errorString);
+                }
+                OGRFeature::DestroyFeature( writePolygonFeature );
+		++ntotalvalid;
+		if(verbose_opt[0])
+		  std::cout << "ntotalvalid(1): " << ntotalvalid << std::endl;
+              }
+              else{
+                if(keepFeatures_opt[0])
+                  writeCentroidFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
+                if(verbose_opt[0]>1)
+                  cout << "creating point feature in centroid" << endl;
+                if(writeLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
+                  string errorString="Failed to create point feature in shapefile";
+                  throw(errorString);
+                }
+                OGRFeature::DestroyFeature( writeCentroidFeature );
+		++ntotalvalid;
+		if(verbose_opt[0])
+		  std::cout << "ntotalvalid: " << ntotalvalid << std::endl;
+              }
+            }
+          }
+          else if(wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon){//todo: try to use virtual OGRGeometry instead of OGRMultiPolygon and OGRPolygon
+            OGRMultiPolygon readPolygon = *((OGRMultiPolygon *) poGeometry);
+            OGRPolygon writePolygon;
+            OGRLinearRing writeRing;
+            OGRPoint writeCentroidPoint;
+            OGRFeature *writePolygonFeature;
+            OGRFeature *writeCentroidFeature;
+
+            readPolygon.closeRings();
+
+            if(verbose_opt[0]>1)
+              cout << "get centroid point from polygon" << endl;
+            readPolygon.Centroid(&writeCentroidPoint);
+
+            double ulx,uly,lrx,lry;
+            double uli,ulj,lri,lrj;
+            if(polygon_opt[0]&&rule_opt[0]==0){
+              ulx=writeCentroidPoint.getX();
+              uly=writeCentroidPoint.getY();
+              lrx=ulx;
+              lry=uly;
+            }
+            else{
+              //get envelope
+              if(verbose_opt[0])
+                cout << "reading envelope for polygon " << ifeature << endl;
+              OGREnvelope* psEnvelope=new OGREnvelope();
+              readPolygon.getEnvelope(psEnvelope);
+              ulx=psEnvelope->MinX;
+              uly=psEnvelope->MaxY;
+              lrx=psEnvelope->MaxX;
+              lry=psEnvelope->MinY;
+              delete psEnvelope;
+            }
+            if(geo_opt[0]){
+              imgReader.geo2image(ulx,uly,uli,ulj);
+              imgReader.geo2image(lrx,lry,lri,lrj);
+            }
+            else{
+              uli=ulx;
+              ulj=uly;
+              lri=lrx;
+              lrj=lry;
+            }
+            //nearest neighbour
+            ulj=static_cast<int>(ulj);
+            uli=static_cast<int>(uli);
+            lrj=static_cast<int>(lrj);
+            lri=static_cast<int>(lri);
+            //iterate through all pixels
+            if(verbose_opt[0]>1)
+              cout << "bounding box for feature " << ifeature << ": " << uli << " " << ulj << " " << lri << " " << lrj << endl;
+
+            if(uli<0||lri>=imgReader.nrOfCol()||ulj<0||ulj>=imgReader.nrOfRow())
+               continue;
+
+            int nPointPolygon=0;
+            if(polygon_opt[0]){
+              writePolygonFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
+            }
+            else if(rule_opt[0]==1)
+              writeCentroidFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
+            //previously here
+            vector<double> polyValues;
+            switch(rule_opt[0]){
+            case(0):
+            case(1):
+            default:
+              polyValues.resize(nband);
+            break;
+            case(2):
+            case(3):
+            case(4):
+              polyValues.resize(class_opt.size());
+            break;
+            }
+            for(int index=0;index<polyValues.size();++index)
+              polyValues[index]=0;
+            OGRPoint thePoint;
+            for(int j=ulj;j<=lrj;++j){
+              for(int i=uli;i<=lri;++i){
+                //check if point is on surface
+                double x=0;
+                double y=0;
+                imgReader.image2geo(i,j,x,y);
+                thePoint.setX(x);
+                thePoint.setY(y);
+                // //test
+                // writeRing.addPoint(&thePoint);
+                // if(thePoint.Within(&readPolygon)){
+                if(readPolygon.Contains(&thePoint)){
+                  bool valid=true;
+                  for(int imask=0;imask<mask_opt.size();++imask){
+                    double colMask,rowMask;//image coordinates in mask image
+                    if(mask_opt.size()>1){//multiple masks
+                      maskReader[imask].geo2image(x,y,colMask,rowMask);
+                      //nearest neighbour
+                      rowMask=static_cast<int>(rowMask);
+                      colMask=static_cast<int>(colMask);
+                      if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[imask].nrOfCol())
+                        continue;
+                      // {
+                      //   cerr << colMask << " out of mask col range!" << endl;
+                      //   cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                      //   assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[imask].nrOfCol());
+                      // }
+              
+                      if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[imask])){
+                        if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[imask].nrOfRow())
+                          continue;
+                        // {
+                        //   cerr << rowMask << " out of mask row range!" << endl;
+                        //   cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                        //   assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
+                        // }
+                        else{
+                          maskReader[imask].readData(maskBuffer[imask],GDT_Int32,static_cast<int>(rowMask));
+                          oldmaskrow[imask]=rowMask;
+                          assert(maskBuffer.size()==maskReader[imask].nrOfBand());
+                        }
+                      }
+                      //               char ivalue=0;
+                      int ivalue=0;
+                      if(mask_opt.size()==invalid_opt.size())//one invalid value for each mask
+                        ivalue=static_cast<int>(invalid_opt[imask]);
+                      else//use same invalid value for each mask
+                        ivalue=static_cast<int>(invalid_opt[0]);
+                      if(maskBuffer[imask][colMask]==ivalue){
+                        valid=false;
+                        break;
+                      }
+                    }
+                    else if(maskReader.size()){
+                      maskReader[0].geo2image(x,y,colMask,rowMask);
+                      //nearest neighbour
+                      rowMask=static_cast<int>(rowMask);
+                      colMask=static_cast<int>(colMask);
+                      if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[0].nrOfCol())
+                        continue;
+                      // {
+                      //   cerr << colMask << " out of mask col range!" << endl;
+                      //   cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                      //   assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[0].nrOfCol());
+                      // }
+              
+                      if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[0])){
+                        if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[0].nrOfRow())
+                          continue;
+                        // {
+                        //   cerr << rowMask << " out of mask row range!" << endl;
+                        //   cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+                        //   assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
+                        // }
+                        else{
+                          maskReader[0].readData(maskBuffer[0],GDT_Int32,static_cast<int>(rowMask));
+                          oldmaskrow[0]=rowMask;
+                        }
+                      }
+                      for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
+                        if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                          valid=false;
+                          break;
+                        }
+                      }
+                    }
+                  }
+                  if(!valid)
+                    continue;
+                  //check if within raster image
+                  if(i<0||i>=imgReader.nrOfCol())
+                    continue;
+                  if(j<0||j>=imgReader.nrOfRow())
+                    continue;
+                  writeRing.addPoint(&thePoint);
+                  if(verbose_opt[0]>1)
+                    cout << "point is on surface:" << thePoint.getX() << "," << thePoint.getY() << endl;
+                  ++nPointPolygon;
+                  OGRFeature *writePointFeature;
+                  if(!polygon_opt[0]){
+                    //create feature
+                    if(rule_opt[0]!=1){//do not create in case of mean value (only create point at centroid
+                      writePointFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
+                      if(verbose_opt[0]>1)
+                        cout << "copying fields from polygons " << sample_opt[0] << endl;
+                      if(writePointFeature->SetFrom(readFeature)!= OGRERR_NONE)
+                        cerr << "writing feature failed" << endl;
+                      writePointFeature->SetGeometry(&thePoint);
+                      OGRGeometry *updateGeometry;
+                      updateGeometry = writePointFeature->GetGeometryRef();
+                      OGRPoint *poPoint = (OGRPoint *) updateGeometry;
+                      if(verbose_opt[0]>1)
+                        cout << "write feature has " << writePointFeature->GetFieldCount() << " fields" << endl;
+                    }
+                  }
+                  if(verbose_opt[0]>1)
+                    cout << "reading image value withinin polygon at position " << i << "," << j;
+                  for(int iband=0;iband<nband;++iband){
+                    int theBand=(band_opt[0]<0)?iband:band_opt[iband];
+                    double value=0;
+                    imgReader.readData(value,GDT_Float64,i,j,theBand);
+                    if(verbose_opt[0]>1)
+                      cout << ": " << value << endl;
+                    if(polygon_opt[0]||rule_opt[0]==1){
+                      int iclass=0;
+                      switch(rule_opt[0]){
+                      case(0)://in centroid if polygon_opt==true or all values as points if polygon_opt!=true
+                      default:
+                        polyValues[iband]=value;
+                        break;
+                      case(1)://mean as polygon if polygon_opt==true or as point in centroid if polygon_opt!=true
+                        polyValues[iband]+=value;
+                      break;
+                      case(2):
+                      case(3):
+                      case(4):
+                        for(iclass=0;iclass<class_opt.size();++iclass){
+                          if(value==class_opt[iclass]){
+                            assert(polyValues.size()>iclass);
+                            polyValues[iclass]+=1;//value
+                            break;
+                          }
+                        }
+                      break;
+                      }
+                    }
+                    else{
+                      ostringstream fs;
+                      // if(imgReader.nrOfBand()==1)
+                      //   fs << fieldname_opt[0];
+                      // else
+                      //   fs << fieldname_opt[0] << theBand;
+                      if(verbose_opt[0]>1)
+                        cout << "set field " << fieldname_opt[iband] << " to " << value << endl;
+                      switch( fieldType ){
+                      case OFTInteger:
+                        writePointFeature->SetField(fieldname_opt[iband].c_str(),static_cast<int>(value));
+                        break;
+                      case OFTString:
+                        {
+                          ostringstream os;
+                          os << value;
+                          writePointFeature->SetField(fieldname_opt[iband].c_str(),os.str().c_str());
+                          break;
+                        }
+                      case OFTReal:
+                        writePointFeature->SetField(fieldname_opt[iband].c_str(),value);
+                        break;
+                      case OFTRealList:{
+                        int fieldIndex=writePointFeature->GetFieldIndex(fieldname_opt[iband].c_str());
+                        int nCount;
+                        const double *theList;
+                        theList=writePointFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                        vector<double> vectorList(nCount+1);
+                        for(int index=0;index<nCount;++index)
+                          vectorList[nCount]=value;
+                        writePointFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                        break;
+                      }
+                      default://not supported
+                        assert(0);
+                        break;
+                      }
+                    }
+                  }
+                  if(!polygon_opt[0]){
+                    if(keepFeatures_opt[0])
+                      writePointFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
+                    if(rule_opt[0]!=1){//do not create in case of mean value (only at centroid)
+                      //write feature
+                      if(verbose_opt[0]>1)
+                        cout << "creating point feature" << endl;
+                      if(writeLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
+                        string errorString="Failed to create feature in shapefile";
+                        throw(errorString);
+                      }
+                      //destroy feature
+                      OGRFeature::DestroyFeature( writePointFeature );
+                    }
+                  }
+                  ++isample;
+                  ++ntotalvalid;
+		  if(verbose_opt[0])
+		    std::cout << "ntotalvalid: " << ntotalvalid << std::endl;
+                }
+              }
+            }
+            // //test
+            // cout << "before write polygon" << endl;
+            if(polygon_opt[0]||rule_opt[0]==1){
+              //add ring to polygon
+              if(polygon_opt[0]){
+                writePolygon.addRing(&writeRing);
+                writePolygon.closeRings();
+                //write geometry of writePolygon
+                writePolygonFeature->SetGeometry(&writePolygon);
+                if(writePolygonFeature->SetFrom(readFeature)!= OGRERR_NONE)
+                  cerr << "writing feature failed" << endl;
+                if(verbose_opt[0]>1)
+                  cout << "copying new fields write polygon " << sample_opt[0] << endl;
+                if(verbose_opt[0]>1)
+                  cout << "write feature has " << writePolygonFeature->GetFieldCount() << " fields" << endl;
+                //write polygon feature
+              }
+              else{//write mean value of polygon to centroid point (rule_opt[0]==1)
+                //create feature
+                if(verbose_opt[0]>1)
+                  cout << "copying fields from polygons " << sample_opt[0] << endl;
+                if(writeCentroidFeature->SetFrom(readFeature)!= OGRERR_NONE)
+                  cerr << "writing feature failed" << endl;
+                writeCentroidFeature->SetGeometry(&writeCentroidPoint);
+                OGRGeometry *updateGeometry;
+                updateGeometry = writeCentroidFeature->GetGeometryRef();
+                assert(wkbFlatten(updateGeometry->getGeometryType()) == wkbPoint );
+                if(verbose_opt[0]>1)
+                  cout << "write feature has " << writeCentroidFeature->GetFieldCount() << " fields" << endl;
+              }
+              switch(rule_opt[0]){
+              case(0)://value at each point (or at centroid of polygon if line is not set
+              default:{
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                for(int index=0;index<polyValues.size();++index){
+                  double theValue=polyValues[index];
+                  ostringstream fs;
+                  if(verbose_opt[0])
+                    cout << "number of points in polygon: " << nPointPolygon << endl;
+                  int theBand=(band_opt[0]<0)?index:band_opt[index];
+                  // if(nband==1)
+                  //   fs << fieldname_opt[0];
+                  // else
+                  //   fs << fieldname_opt[0] << theBand;
+                  if(verbose_opt[0]>1)
+                    cout << "set field " << fieldname_opt[index] << " to " << theValue << endl;
+                  switch( fieldType ){
+                  case OFTInteger:
+                    if(polygon_opt[0])
+                      writePolygonFeature->SetField(fieldname_opt[index].c_str(),static_cast<int>(theValue));
+                    else
+                      writeCentroidFeature->SetField(fieldname_opt[index].c_str(),static_cast<int>(theValue));
+                    break;
+                  case OFTString:
+                    {
+                      ostringstream os;
+                      os << theValue;
+                      if(polygon_opt[0])
+                        writePolygonFeature->SetField(fieldname_opt[index].c_str(),os.str().c_str());
+                      else
+                        writeCentroidFeature->SetField(fieldname_opt[index].c_str(),os.str().c_str());
+                      break;
+                    }
+                  case OFTReal:
+                      if(polygon_opt[0])
+                        writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
+                      else
+                        writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
+                    break;
+                  case OFTRealList:{
+                    int fieldIndex;
+                    int nCount;
+                    const double *theList;
+                    vector<double> vectorList;
+                    if(polygon_opt[0]){
+                      fieldIndex=writePolygonFeature->GetFieldIndex(fieldname_opt[index].c_str());
+                      theList=writePolygonFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                      vectorList.resize(nCount+1);
+                      for(int index=0;index<nCount;++index)
+                        vectorList[index]=theList[index];
+                      vectorList[nCount]=theValue;
+                      writePolygonFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                    }
+                    else{
+                      fieldIndex=writeCentroidFeature->GetFieldIndex(fieldname_opt[index].c_str());
+                      theList=writeCentroidFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                      vectorList.resize(nCount+1);
+                      for(int index=0;index<nCount;++index)
+                        vectorList[index]=theList[index];
+                      vectorList[nCount]=theValue;
+                      writeCentroidFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                    }
+                    break;
+                  }//case OFTRealList
+                  }//switch(fieldType)
+                }//for index
+                break;
+              }//case 0 and default
+              case(1):{//mean value (written to centroid of polygon if line is not set
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                for(int index=0;index<polyValues.size();++index){
+                  double theValue=polyValues[index];
+                  ostringstream fs;
+                  theValue/=nPointPolygon;
+                  int theBand=(band_opt[0]<0)?index:band_opt[index];
+                  // if(nband==1)
+                  //   fs << fieldname_opt[0];
+                  // else
+                  //   fs << fieldname_opt[0] << theBand;
+                  if(verbose_opt[0]>1)
+                    cout << "set field " << fieldname_opt[index] << " to " << theValue << endl;
+                  switch( fieldType ){
+                  case OFTInteger:
+                    if(polygon_opt[0])
+                      writePolygonFeature->SetField(fieldname_opt[index].c_str(),static_cast<int>(theValue));
+                    else
+                      writeCentroidFeature->SetField(fieldname_opt[index].c_str(),static_cast<int>(theValue));
+                    break;
+                  case OFTString:
+                    {
+                      ostringstream os;
+                      os << theValue;
+                      if(polygon_opt[0])
+                        writePolygonFeature->SetField(fieldname_opt[index].c_str(),os.str().c_str());
+                      else
+                        writeCentroidFeature->SetField(fieldname_opt[index].c_str(),os.str().c_str());
+                      break;
+                    }
+                  case OFTReal:
+                    if(polygon_opt[0])
+                      writePolygonFeature->SetField(fieldname_opt[index].c_str(),theValue);
+                    else
+                      writeCentroidFeature->SetField(fieldname_opt[index].c_str(),theValue);
+                    break;
+                  case OFTRealList:{
+                    int fieldIndex;
+                    int nCount;
+                    const double *theList;
+                    vector<double> vectorList;
+                    if(polygon_opt[0]){
+                      fieldIndex=writePolygonFeature->GetFieldIndex(fieldname_opt[index].c_str());
+                      theList=writePolygonFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                      vectorList.resize(nCount+1);
+                      for(int index=0;index<nCount;++index)
+                        vectorList[index]=theList[index];
+                      vectorList[nCount]=theValue;
+                      writePolygonFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                    }
+                    else{
+                      fieldIndex=writeCentroidFeature->GetFieldIndex(fieldname_opt[index].c_str());
+                      theList=writeCentroidFeature->GetFieldAsDoubleList(fieldIndex,&nCount);
+                      vectorList.resize(nCount+1);
+                      for(int index=0;index<nCount;++index)
+                        vectorList[index]=theList[index];
+                      vectorList[nCount]=theValue;
+                      writeCentroidFeature->SetField(fieldIndex,vectorList.size(),&(vectorList[0]));
+                    }
+                    break;
+                  }
+                  }
+                }
+                break;
+              }
+              case(2):{//proportion classes
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                hist.normalize_pct(polyValues);
+                // hist.sum(polyValues);
+                for(int index=0;index<polyValues.size();++index){
+                  double theValue=polyValues[index];
+                  ostringstream fs;
+                  fs << class_opt[index];
+                  if(polygon_opt[0])
+                    writePolygonFeature->SetField(fs.str().c_str(),static_cast<int>(theValue));
+                  else
+                    writeCentroidFeature->SetField(fs.str().c_str(),static_cast<int>(theValue));
+                }
+                break;
+              }
+              case(3):{//custom
+                assert(polygon_opt[0]);//not implemented for points
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                hist.normalize_pct(polyValues);
+                assert(polyValues.size()==2);//11:broadleaved, 12:coniferous
+                if(polyValues[0]>=75)//broadleaved
+                  writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(11));
+                else if(polyValues[1]>=75)//coniferous
+                  writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(12));
+                else if(polyValues[0]>25&&polyValues[1]>25)//mixed
+                  writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(13));
+                else{
+                  if(verbose_opt[0]){
+                    cout << "No valid value in polyValues..." << endl;
+                    for(int index=0;index<polyValues.size();++index){
+                      double theValue=polyValues[index];
+                      cout << theValue << " ";
+                    }
+                    cout << endl;
+                  }
+                  writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(20));
+                }
+                break;
+              }
+              case(4):{//minimum of polygon
+                assert(polygon_opt[0]);//not implemented for points
+                if(verbose_opt[0])
+                  cout << "number of points in polygon: " << nPointPolygon << endl;
+                //search for min class
+                //todo: change to minClass=hist.max(class_opt) once Optionpk is implemented...
+                int minClass=class_opt[class_opt.size()-1];//!hard coded for now, maximum class is last entry in class_opt
+                for(int iclass=0;iclass<class_opt.size();++iclass){
+                  if(polyValues[iclass]>0){
+                    if(verbose_opt[0]>1)
+                      cout << class_opt[iclass] << ": " << polyValues[iclass] << endl;
+                    if(class_opt[iclass]<minClass)
+                      minClass=class_opt[iclass];
+                  }
+                }
+                if(verbose_opt[0]>0)
+                  cout << "minClass: " << minClass << endl;
+                writePolygonFeature->SetField(label_opt[0].c_str(),minClass);
+                break;
+              }
+              }
+              if(polygon_opt[0]){
+                if(keepFeatures_opt[0])
+                  writePolygonFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
+                if(verbose_opt[0]>1)
+                  cout << "creating polygon feature" << endl;
+                if(writeLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
+                  string errorString="Failed to create polygon feature in shapefile";
+                  throw(errorString);
+                }
+                OGRFeature::DestroyFeature( writePolygonFeature );
+		++ntotalvalid;
+		if(verbose_opt[0])
+		  std::cout << "ntotalvalid: " << ntotalvalid << std::endl;
+              }
+              else{
+                if(keepFeatures_opt[0])
+                  writeCentroidFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
+                if(verbose_opt[0]>1)
+                  cout << "creating point feature in centroid" << endl;
+                if(writeLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
+                  string errorString="Failed to create point feature in shapefile";
+                  throw(errorString);
+                }
+                OGRFeature::DestroyFeature( writeCentroidFeature );
+		++ntotalvalid;
+		if(verbose_opt[0])
+		  std::cout << "ntotalvalid: " << ntotalvalid << std::endl;
+              }
+            }
+          }
+          else{
+            string test;
+            test=poGeometry->getGeometryName();
+            ostringstream oss;
+            oss << "geometry " << test << " not supported";
+            throw(oss.str());
+          }
+          ++ifeature;
+        }
+        catch(string e){
+          cout << e << endl;
+          continue;
+        }
+      }//end of getNextFeature
+      if(rbox_opt[0]>0||cbox_opt[0]>0)
+        boxWriter.close();
+      ogrWriter.close();
+    }
+  imgReader.close();
+}
+
+  
diff --git a/src/apps/pkfillnodata.cc b/src/apps/pkfillnodata.cc
new file mode 100644
index 0000000..5a629db
--- /dev/null
+++ b/src/apps/pkfillnodata.cc
@@ -0,0 +1,152 @@
+/**********************************************************************
+pkfillnodata.cc: program to fill holes in raster image
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "cpl_string.h"
+#include "gdal_priv.h"
+#include "gdal.h"
+extern "C" {
+#include "gdal_alg.h"
+}
+#include "base/Optionpk.h"
+
+using namespace std;
+int main(int argc,char **argv) {
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<string> input_opt("i", "input", "Input image file (WARNING: will be overwritten with output!", "");
+  Optionpk<int> band_opt("b", "band", "band(s) to process (Default is -1: process all bands)", -1);
+  Optionpk<string> mask_opt("m", "mask", "Mask band indicating pixels to be interpolated (zero valued) ", "");
+  Optionpk<string> output_opt("o", "output", "Output image file", "");
+  Optionpk<double> distance_opt("d", "distance", "Maximum number of pixels to search in all directions to find values to interpolate from (default is 3", 3);
+  Optionpk<int> iteration_opt("it", "iteration", "Number of 3x3 smoothing filter passes to run (default 0)", 0);
+  Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+
+  input_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  distance_opt.retrieveOption(argc,argv);
+  iteration_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << "usage: pkfillnodata -i inputimage -o outputimage -m maskimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  GDALAllRegister();
+  GDALDataset *gds_input;
+  if(verbose_opt[0])
+    cout << "opening input file " << input_opt[0] << endl;
+  gds_input = (GDALDataset *) GDALOpen(input_opt[0].c_str(), GA_ReadOnly);
+  if(gds_input == NULL){
+    string errorString="FileOpenError";
+    throw(errorString);
+  }
+
+  GDALDataset *gds_mask;
+  if(verbose_opt[0])
+    cout << "opening mask file " << mask_opt[0] << endl;
+  gds_mask = (GDALDataset *) GDALOpen(mask_opt[0].c_str(), GA_ReadOnly );
+  if(gds_mask == NULL){
+    string errorString="FileOpenError";
+    throw(errorString);
+  }
+  GDALRasterBand *maskBand;
+  if(verbose_opt[0])
+    cout << "get mask raster band" << endl;
+  maskBand=gds_mask->GetRasterBand(1);
+  
+
+  GDALDriver *poDriver;
+  poDriver = GetGDALDriverManager()->GetDriverByName(gds_input->GetDriver()->GetDescription());
+  if( poDriver == NULL ){
+    string errorString="FileOpenError";
+    throw(errorString);
+  }
+  if(verbose_opt[0])
+    cout << "copying input file to " << output_opt[0] << endl;
+  poDriver->CopyFiles(output_opt[0].c_str(),input_opt[0].c_str());
+  GDALDataset *gds_out;
+  gds_out=(GDALDataset *) GDALOpen(output_opt[0].c_str(), GA_Update);
+
+  if(band_opt[0]<0){
+    band_opt.clear();
+    for(int iband=0;iband<gds_input->GetRasterCount();++iband)
+      band_opt.push_back(iband);
+  }
+  GDALRasterBand *targetBand;
+  for(unsigned short iband=0;iband<band_opt.size();++iband){
+    targetBand=gds_out->GetRasterBand(band_opt[iband]+1);
+    if(verbose_opt[0])
+      cout << "copying input file to " << output_opt[0] << endl;
+    double dfComplete=0.0;
+    const char* pszMessage;
+    void* pProgressArg=NULL;
+    GDALProgressFunc pfnProgress=GDALTermProgress;
+    pfnProgress(dfComplete,pszMessage,pProgressArg);
+    if(GDALFillNodata(targetBand,maskBand,distance_opt[0],0,iteration_opt[0],NULL,pfnProgress,pProgressArg)!=CE_None){
+      cerr << CPLGetLastErrorMsg() << endl;
+      exit(1);
+    }
+    else{
+      dfComplete=1.0;
+      pfnProgress(dfComplete,pszMessage,pProgressArg);
+    }
+
+    //   gds_out=poDriver->CreateCopy(output_opt[0].c_str(),gds_input, FALSE,NULL,NULL,NULL);
+    //   char **papszParmList=NULL;
+    //   gds_out=poDriver->Create(output_opt[0].c_str(),targetBand->GetXSize(),targetBand->GetYSize(),1,targetBand->GetRasterDataType(),papszParmList);
+    //   char **papszMetadata;
+    //   papszMetadata = poDriver->GetMetadata();
+    //   assert( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ));
+    //   ostringstream compressList;
+    //   gds_out->SetMetadataItem("INTERLEAVE",gds_input->GetMetadataItem( "INTERLEAVE", "IMAGE_STRUCTURE"),"IMAGE_STRUCTURE");
+    //   gds_out->SetMetadataItem("COMPRESSION",gds_input->GetMetadataItem( "COMPRESSION", "IMAGE_STRUCTURE"),"IMAGE_STRUCTURE");
+    //   if(gds_input->GetProjectionRef()!=NULL){
+    //     gds_out->SetProjection(gds_input->GetProjectionRef());
+    //     double adfGeoTransform[6];
+    //     gds_input->GetGeoTransform(adfGeoTransform);
+    //     gds_out->SetGeoTransform(adfGeoTransform);
+    //   }
+  }
+  GDALClose(gds_input);
+  GDALClose(gds_mask);
+  GDALClose(gds_out);
+  GDALDumpOpenDatasets(stderr);
+  GDALDestroyDriverManager();
+}
+
diff --git a/src/apps/pkfilter.cc b/src/apps/pkfilter.cc
new file mode 100644
index 0000000..a9e55a4
--- /dev/null
+++ b/src/apps/pkfilter.cc
@@ -0,0 +1,320 @@
+/**********************************************************************
+pkfilter.cc: program to filter raster images (e.g., median, min/max, morphological filtering)
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <assert.h>
+#include <iostream>
+#include <string>
+#include <fstream>
+#include <math.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include "base/Optionpk.h"
+#include "base/Vector2d.h"
+#include "algorithms/Filter2d.h"
+#include "algorithms/Filter.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+
+/*------------------
+  Main procedure
+  ----------------*/
+int main(int argc,char **argv) {
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","",false);
+  Optionpk<std::string> input_opt("i","input","input image file","");
+  Optionpk<std::string> output_opt("o", "output", "Output image file", "");
+  Optionpk<bool> disc_opt("c", "circular", "circular disc kernel for dilation and erosion (default is false)", false);
+  Optionpk<double> angle_opt("a", "angle", "angle used for directional filtering in dilation. Default is less than -180 (no directional effect)", -190);
+  Optionpk<int> function_opt("f", "filter", "filter function (0: median, 1: variance, 2: min, 3: max, 4: sum, 5: mean, 6: minmax, 7: dilation, 8: erosion, 9: closing, 10: opening, 11: spatially homogeneous, 12: SobelX edge detection in X, 13: SobelY edge detection in Y, 14: SobelXY (not supported), 15: smooth, 16: density, 17: majority voting (only for classes), 18: forest aggregation (mixed), 19: smooth no data (mask) values), 20: threshold local filtering", 0);
+  Optionpk<int> dimX_opt("dx", "dx", "filter kernel size in x, must be odd (example: 3). Default is 0", 0);
+  Optionpk<int> dimY_opt("dy", "dy", "filter kernel size in y, must be odd (example: 3). Default is 0. Set dy=0 if 1-D filter must be used in band domain", 0);
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<short> class_opt("class", "class", "class value(s) to use for density, erosion, dilation, openening and closing, thresholding (default is 1)", 1);
+  Optionpk<double> threshold_opt("t", "threshold", "threshold value(s) to use for threshold filter (one for each class)", 0);
+  Optionpk<short> mask_opt("\0", "mask", "mask value(s) ", -1);
+  Optionpk<std::string> tap_opt("tap", "tap", "text file conttaining taps used for filtering (from ul to lr). Default is empty: do not use taps. Use dimX and dimY to specify tap dimensions in x and y", "");
+  Optionpk<std::string> colorTable_opt("\0", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<short> down_opt("d", "down", "down sampling factor. Default is 1: no downsample)", 1);
+  Optionpk<short> verbose_opt("v", "verbose", "verbose (default is 0)", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  input_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+  disc_opt.retrieveOption(argc,argv);
+  angle_opt.retrieveOption(argc,argv);
+  function_opt.retrieveOption(argc,argv);
+  dimX_opt.retrieveOption(argc,argv);
+  dimY_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  class_opt.retrieveOption(argc,argv);
+  threshold_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  tap_opt.retrieveOption(argc,argv);
+  down_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  if(help_opt[0]){
+    cout << "usage: pkfilter -i inputimage -o outputimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  ImgReaderGdal input;
+  ImgWriterGdal output;
+  input.open(input_opt[0]);
+  // output.open(output_opt[0],input);
+
+  output.open(output_opt[0],(input.nrOfCol()+down_opt[0]-1)/down_opt[0],(input.nrOfRow()+down_opt[0]-1)/down_opt[0],input.nrOfBand(),input.getDataType(),input.getImageType(),option_opt);
+  if(input.isGeoRef()){
+    output.setProjection(input.getProjection());
+    double ulx,uly,deltaX,deltaY,rot1,rot2;
+    input.getGeoTransform(ulx,uly,deltaX,deltaY,rot1,rot2);
+    output.setGeoTransform(ulx,uly,deltaX*down_opt[0],deltaY*down_opt[0],rot1,rot2);
+  }
+  if(input.getColorTable()!=NULL)
+    output.setColorTable(input.getColorTable());
+
+  // if(input.isGeoRef()){
+  //   output.setProjection(input.getProjection());
+  //   output.copyGeoTransform(input);
+  // }
+  
+  Filter2d::Filter2d filter2d;
+  Filter filter1d;
+  if(verbose_opt[0])
+    std::cout<< "class values: ";
+  for(int iclass=0;iclass<class_opt.size();++iclass){
+    if(dimY_opt[0]>0)
+      filter2d.pushClass(class_opt[iclass]);
+    else
+      filter1d.pushClass(class_opt[iclass]);
+    if(verbose_opt[0])
+      std::cout<< class_opt[iclass] << " ";
+  }
+  if(verbose_opt[0])
+    std::cout<< std::endl;
+  if(verbose_opt[0])
+    std::cout<< "mask values: ";
+  for(int imask=0;imask<mask_opt.size();++imask){
+    if(verbose_opt[0])
+      std::cout<< mask_opt[imask] << " ";
+    filter2d.pushMask(mask_opt[imask]);
+  }
+  if(verbose_opt[0])
+    std::cout<< std::endl;
+  if(tap_opt[0]!=""){
+    ifstream tapfile(tap_opt[0].c_str());
+    assert(tapfile);
+    Vector2d<double> taps(dimY_opt[0],dimX_opt[0]);
+
+    for(int j=0;j<dimY_opt[0];++j){
+      for(int i=0;i<dimX_opt[0];++i){
+        tapfile >> taps[j][i];
+      }
+    }
+    if(verbose_opt[0]){
+      for(int j=0;j<dimY_opt[0];++j){
+        for(int i=0;i<dimX_opt[0];++i){
+          std::cout<< taps[j][i] << " ";
+        }
+        std::cout<< std::endl;
+      }
+    }
+    filter2d.setTaps(taps);    
+    filter2d.filter(input,output);
+    tapfile.close();
+  }
+  else{
+    if(colorTable_opt[0]!="")
+      output.setColorTable(colorTable_opt[0]);
+    switch(function_opt[0]){
+    case(Filter2d::MEDIAN):
+      filter2d.doit(input,output,Filter2d::MEDIAN,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::VAR):
+      filter2d.doit(input,output,Filter2d::VAR,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::MIN):
+      filter2d.doit(input,output,Filter2d::MIN,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::MAX):
+      filter2d.doit(input,output,Filter2d::MAX,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::MINMAX):
+      filter2d.doit(input,output,Filter2d::MINMAX,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::SUM):
+      filter2d.doit(input,output,Filter2d::SUM,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::MEAN):
+      filter2d.doit(input,output,Filter2d::MEAN,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::MAJORITY):
+      filter2d.doit(input,output,Filter2d::MAJORITY,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::THRESHOLD):
+      filter2d.setThresholds(threshold_opt);
+      filter2d.setClasses(class_opt);
+      filter2d.doit(input,output,Filter2d::THRESHOLD,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::MIXED):
+      filter2d.doit(input,output,Filter2d::MIXED,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    case(Filter2d::DILATE):
+      if(dimY_opt[0]>0)
+        filter2d.morphology(input,output,Filter2d::DILATE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+      else{
+        if(verbose_opt[0])
+          std::cout<< "1-D filtering: dilate" << std::endl;
+        filter1d.morphology(input,output,Filter::DILATE,dimX_opt[0]);
+      }
+      break;
+    case(Filter2d::ERODE):
+      if(dimY_opt[0]>0)
+        filter2d.morphology(input,output,Filter2d::ERODE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+      else{
+        if(verbose_opt[0])
+          std::cout<< "1-D filtering: dilate" << std::endl;
+        filter1d.morphology(input,output,Filter::ERODE,dimX_opt[0]);
+      }
+      break;
+    case(Filter2d::CLOSE):{//closing
+      ostringstream tmps;
+      tmps << "/tmp/dilation_" << getpid() << ".tif";
+      ImgWriterGdal tmpout;
+      tmpout.open(tmps.str(),input);
+      try{
+        if(dimY_opt[0]>0)
+          filter2d.morphology(input,tmpout,Filter2d::DILATE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+        else
+          filter1d.morphology(input,tmpout,Filter::DILATE,dimX_opt[0]);
+      }
+      catch(std::string errorString){
+	std::cout<< errorString;
+	exit(1);
+      }
+      tmpout.close();
+      ImgReaderGdal tmpin;
+      tmpin.open(tmps.str());
+      if(dimY_opt[0]>0)
+        filter2d.morphology(tmpin,output,Filter2d::ERODE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+      else
+        filter1d.morphology(tmpin,output,Filter::ERODE,dimX_opt[0]);
+      tmpin.close();
+      if(remove(tmps.str().c_str( )) !=0){
+        cerr << "could not remove " << tmps.str() << std::endl;
+      }
+      break;
+    }
+    case(Filter2d::OPEN):{//opening
+      ostringstream tmps;
+      tmps << "/tmp/erosion_" << getpid() << ".tif";
+      ImgWriterGdal tmpout;
+      tmpout.open(tmps.str(),input);
+      if(dimY_opt[0]>0)
+        filter2d.morphology(input,tmpout,Filter2d::ERODE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+      else
+        filter1d.morphology(input,tmpout,Filter::ERODE,dimX_opt[0]);
+      tmpout.close();
+      ImgReaderGdal tmpin;
+      tmpin.open(tmps.str());
+      if(dimY_opt[0]>0)
+        filter2d.morphology(tmpin,output,Filter2d::DILATE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+      else
+        filter1d.morphology(tmpin,output,Filter::DILATE,dimX_opt[0]);
+      tmpin.close();
+      if(remove(tmps.str().c_str( )) !=0){
+        cerr << "could not remove " << tmps.str() << std::endl;
+      }
+      break;
+    }
+    case(Filter2d::HOMOG):{//spatially homogeneous
+      filter2d.doit(input,output,Filter2d::HOMOG,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      // filter2d.homogeneousSpatial(input,output,dimX_opt[0],disc_opt[0]);
+      break;
+    }
+    case(Filter2d::SOBELX):{//Sobel edge detection in X
+      Vector2d<double> theTaps(3,3);
+      theTaps[0][0]=-1.0;
+      theTaps[0][1]=0.0;
+      theTaps[0][2]=1.0;
+      theTaps[1][0]=-2.0;
+      theTaps[1][1]=0.0;
+      theTaps[1][2]=2.0;
+      theTaps[2][0]=-1.0;
+      theTaps[2][1]=0.0;
+      theTaps[2][2]=1.0;
+      filter2d.setTaps(theTaps);
+      filter2d.filter(input,output,true);
+      break;
+    }
+    case(Filter2d::SOBELY):{//Sobel edge detection in Y
+      Vector2d<double> theTaps(3,3);
+      theTaps[0][0]=1.0;
+      theTaps[0][1]=2.0;
+      theTaps[0][2]=1.0;
+      theTaps[1][0]=0.0;
+      theTaps[1][1]=0.0;
+      theTaps[1][2]=0.0;
+      theTaps[2][0]=-1.0;
+      theTaps[2][1]=-2.0;
+      theTaps[2][2]=-1.0;
+      filter2d.setTaps(theTaps);
+      filter2d.filter(input,output,true);
+      break;
+    }
+    case(Filter2d::SMOOTH):{//Smoothing filter
+      filter2d.smooth(input,output,dimX_opt[0],dimY_opt[0]);
+      break;
+    }
+    case(Filter2d::SMOOTHNODATA):{//Smoothing filter
+      filter2d.smoothNoData(input,output,dimX_opt[0],dimY_opt[0]);
+      break;
+    }
+    case(Filter2d::DENSITY):{//estimation of forest density
+      filter2d.doit(input,output,Filter2d::DENSITY,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+      break;
+    }
+    default:
+      cerr << "filter function " << function_opt[0] << " not supported" << std::endl;
+      return 1;
+    }
+  }
+  input.close();
+  output.close();
+  return 0;
+}
diff --git a/src/apps/pkgetmask.cc b/src/apps/pkgetmask.cc
new file mode 100644
index 0000000..3b6c221
--- /dev/null
+++ b/src/apps/pkgetmask.cc
@@ -0,0 +1,184 @@
+/**********************************************************************
+pkgetmask.cc: program to create mask image based on values in input raster image
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <assert.h>
+#include <vector>
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "base/Optionpk.h"
+
+using namespace std;
+int main(int argc,char **argv) {
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","",false);
+  Optionpk<string>  input_opt("i", "input", "Input image file", "");
+  Optionpk<short>  band_opt("b", "band", "band(s) used for mask (default is 0)", 0);
+  Optionpk<double> min_opt("m", "min", "Values smaller than min threshold(s) are masked as invalid. Use one threshold for each band (default 0)", 0);
+  Optionpk<double> max_opt("M", "max", "Values greater than max threshold(s) are masked as invalid. Use one threshold for each band (default 0)", 0);
+  Optionpk<string>  operator_opt("p", "operator", "Operator: [AND,OR]. Default is OR)", "OR");
+  Optionpk<unsigned short> valid_opt("t", "tvalue", "value(s) for valid pixels: between min and max (default 1)", 1);
+  Optionpk<unsigned short> invalid_opt("f", "fvalue", "value(s) for invalid pixels: not between min and max (default 0)", 0);
+  Optionpk<string> output_opt("o", "output", "Output mask file", "");
+  Optionpk<string>  otype_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "Byte");
+  Optionpk<string>  oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  input_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  min_opt.retrieveOption(argc,argv);
+  max_opt.retrieveOption(argc,argv);
+  operator_opt.retrieveOption(argc,argv);
+  valid_opt.retrieveOption(argc,argv);
+  invalid_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  otype_opt.retrieveOption(argc,argv);
+  oformat_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << "usage: pkgetmask -i inputimage -o outputimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  GDALDataType theType=GDT_Unknown;
+  if(verbose_opt[0])
+    cout << "possible output data types: ";
+  for(int iType = 0; iType < GDT_TypeCount; ++iType){
+    if(verbose_opt[0])
+      cout << " " << GDALGetDataTypeName((GDALDataType)iType);
+    if( GDALGetDataTypeName((GDALDataType)iType) != NULL
+        && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
+                 otype_opt[0].c_str()))
+      theType=(GDALDataType) iType;
+  }
+  if(verbose_opt[0]){
+    cout << endl;
+    if(theType==GDT_Unknown)
+      cout << "Unknown output pixel type: " << otype_opt[0] << endl;
+    else
+      cout << "Output pixel type:  " << GDALGetDataTypeName(theType) << endl;
+  }
+
+  ImgReaderGdal imgReader(input_opt[0]);
+  assert(band_opt.size()>=0);
+  assert(band_opt.size()<=imgReader.nrOfBand());
+
+  while(band_opt.size()>min_opt.size())
+    min_opt.push_back(min_opt[0]);
+  while(band_opt.size()>max_opt.size())
+    max_opt.push_back(max_opt[0]);
+  while(min_opt.size()>valid_opt.size())
+    valid_opt.push_back(valid_opt[0]);
+  assert(min_opt.size()==max_opt.size());
+  if(verbose_opt[0]){
+    cout << "min,max values: ";
+    for(int imin=0;imin<min_opt.size();++imin){
+      cout << min_opt[imin] << "," << max_opt[imin];
+      if(imin<min_opt.size()-1)
+	cout << " ";
+      else
+	cout << endl;
+    }
+  }
+  
+  vector< vector<float> > lineBuffer(band_opt.size());
+  for(int iband=0;iband<band_opt.size();++iband)
+    lineBuffer.resize(imgReader.nrOfCol());
+  ImgWriterGdal imgWriter;
+  //if output type not set, get type from input image
+  if(theType==GDT_Unknown){
+    theType=imgReader.getDataType();
+    if(verbose_opt[0])
+      cout << "Using data type from input image: " << GDALGetDataTypeName(theType) << endl;
+  }
+  string imageType=imgReader.getImageType();
+  if(oformat_opt[0]!="")//default
+    imageType=oformat_opt[0];
+  imgWriter.open(output_opt[0],imgReader.nrOfCol(),imgReader.nrOfRow(),1,theType,imageType,option_opt);
+  if(colorTable_opt[0]!=""){
+    if(colorTable_opt[0]!="none")
+      imgWriter.setColorTable(colorTable_opt[0]);
+  }
+  else if (imgReader.getColorTable()!=NULL)//copy colorTable from input image
+    imgWriter.setColorTable(imgReader.getColorTable());
+  if(imgReader.isGeoRef()){
+    imgWriter.setProjection(imgReader.getProjection());
+    double ulx,uly,lrx,lry;
+    imgReader.getBoundingBox(ulx,uly,lrx,lry);
+    imgWriter.setGeoTransform(ulx,uly,imgReader.getDeltaX(),imgReader.getDeltaY(),0,0);
+  }
+  vector<char> writeBuffer(imgWriter.nrOfCol());
+  for(int irow=0;irow<imgReader.nrOfRow();++irow){
+    for(int iband=0;iband<band_opt.size();++iband)
+      imgReader.readData(lineBuffer[iband],GDT_Float32,irow,band_opt[iband]);
+    for(int icol=0;icol<imgReader.nrOfCol();++icol){
+      bool valid=(operator_opt[0]=="OR")?false:true;
+      unsigned short validValue=valid_opt[0];
+      for(int ivalid=0;ivalid<min_opt.size();++ivalid){
+        bool validBand=false;
+      // for(int iband=0;iband<band_opt.size();++iband){
+        unsigned short theBand=(band_opt.size()==min_opt.size())? ivalid:0;
+        if(lineBuffer[theBand][icol]>=min_opt[ivalid]&&lineBuffer[theBand][icol]<=max_opt[ivalid]){
+          validValue=valid_opt[ivalid];
+          validBand=true;
+        }
+        valid=(operator_opt[0]=="OR")?valid||validBand : valid&&validBand;
+      }
+      if(valid)
+	writeBuffer[icol]=validValue;
+      else
+	writeBuffer[icol]=invalid_opt[0];
+    }
+    imgWriter.writeData(writeBuffer,GDT_Byte,irow);
+    progress=(1.0+irow)/imgWriter.nrOfRow();
+    pfnProgress(progress,pszMessage,pProgressArg);
+  }
+
+  imgReader.close();
+  imgWriter.close();
+}
diff --git a/src/apps/pkinfo.cc b/src/apps/pkinfo.cc
new file mode 100644
index 0000000..bd0aafc
--- /dev/null
+++ b/src/apps/pkinfo.cc
@@ -0,0 +1,424 @@
+/**********************************************************************
+pkinfo.cc: program to retrieve information from raster images
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <sstream>
+#include <list>
+#include "base/Optionpk.h"
+#include "algorithms/Egcs.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgReaderOgr.h"
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<std::string> input_opt("i","input","input image file","");
+  Optionpk<bool>  bbox_opt("bb", "bbox", "show bounding box ", false);
+  Optionpk<bool>  bbox_te_opt("te", "te", "show bounding box in GDAL format: xmin ymin xmax ymax ", false);
+  Optionpk<bool>  centre_opt("c", "centre", "Image centre in projected X,Y coordinates ", false);
+  Optionpk<bool>  colorTable_opt("ct", "colourtable", "show colour table ", false);
+  Optionpk<bool>  samples_opt("s", "samples", "Number of samples in image ", false);
+  Optionpk<bool>  lines_opt("l", "lines", "Number of lines in image ", false);
+  Optionpk<bool>  nband_opt("nb", "nband", "Show number of bands in image", false);
+  Optionpk<short>  band_opt("b", "band", "Band specific information", 0);
+  // Optionpk<bool>  magic_opt("\0", "magic", "Show magic pixel in image ", false);
+  Optionpk<bool>  dx_opt("dx", "dx", "get resolution in x (in m)", false);
+  Optionpk<bool>  dy_opt("dy", "dy", "get resolution in y (in m)", false);
+  Optionpk<bool>  minmax_opt("mm", "minmax", "Show min and max value of the image ", false);
+  Optionpk<bool>  stat_opt("stat", "stat", "Show statistics (min,max, mean and stdDev of the image ", false);
+  Optionpk<double>  min_opt("m", "min", "Show min value of the image (or set minimum for histogram)", 0);
+  Optionpk<double>  max_opt("M", "max", "Show max value of the image (or set maximum for histogram)", 0);
+  Optionpk<bool>  relative_opt("\0", "rel", "Calculate relative histogram in percentage", false);
+  Optionpk<bool>  projection_opt("p", "projection", "Show projection of the image ", false);
+  Optionpk<bool>  geo_opt("geo", "geo", "get geotransform:  ", false);
+  Optionpk<bool>  interleave_opt("il", "interleave", "Show interleave ", false);
+  Optionpk<bool>  filename_opt("f", "filename", "Image filename ", false);
+  Optionpk<bool>  cover_opt("\0", "cover", "Image covers bounding box (or x and y pos) if printed to std out ", false);
+  Optionpk<double>  x_opt("x", "xpos", "x pos", -1);
+  Optionpk<double>  y_opt("y", "ypos", "y pos", -1);
+  Optionpk<bool>  read_opt("r", "read", "read row y (in projected coordinates if geo option is set, otherwise in image coordinates, 0 based)", 0);
+  Optionpk<bool>  refpixel_opt("ref", "ref", "get reference pixel (lower left corner of centre of gravity pixel)", false);
+  Optionpk<bool>  driver_opt("of", "oformat", "get driver description ", false);
+  Optionpk<std::string>  extent_opt("e", "extent", "get boundary from extent from polygons in vector file", "");
+  Optionpk<double>  ulx_opt("ulx", "ulx", "Upper left x value bounding box (0)", 0.0);
+  Optionpk<double>  uly_opt("uly", "uly", "Upper left y value bounding box (0)", 0.0);
+  Optionpk<double>  lrx_opt("lrx", "lrx", "Lower right x value bounding box (0)", 0.0);
+  Optionpk<double>  lry_opt("lry", "lry", "Lower right y value bounding box (0)", 0.0);
+  Optionpk<bool>  hist_opt("\0", "hist", "Calculate histogram. Use --rel for a relative histogram output. ", false);
+  Optionpk<short>  nbin_opt("\0", "nbin", "Number of bins used in histogram. Use 0 for all input values as integers", 0);
+  Optionpk<bool>  type_opt("ot", "otype", "Return data type", false);
+  Optionpk<bool>  description_opt("\0", "description", "Return image description", false);
+  Optionpk<bool>  metadata_opt("\0", "meta", "Show meta data ", false);
+  Optionpk<double> maskValue_opt("\0", "mask", "mask value(s) for no data to calculate reference pixel in image (Default is 0)",0);
+  
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]){
+    std::cout << version_opt.getHelp() << std::endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+
+  input_opt.retrieveOption(argc,argv);
+  bbox_opt.retrieveOption(argc,argv);
+  bbox_te_opt.retrieveOption(argc,argv);
+  centre_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  samples_opt.retrieveOption(argc,argv);
+  lines_opt.retrieveOption(argc,argv);
+  nband_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  // magic_opt.retrieveOption(argc,argv);
+  dx_opt.retrieveOption(argc,argv);
+  dy_opt.retrieveOption(argc,argv);
+  minmax_opt.retrieveOption(argc,argv);
+  stat_opt.retrieveOption(argc,argv);
+  min_opt.retrieveOption(argc,argv);
+  max_opt.retrieveOption(argc,argv);
+  relative_opt.retrieveOption(argc,argv);
+  projection_opt.retrieveOption(argc,argv);
+  geo_opt.retrieveOption(argc,argv);
+  interleave_opt.retrieveOption(argc,argv);
+  filename_opt.retrieveOption(argc,argv);
+  cover_opt.retrieveOption(argc,argv);
+  x_opt.retrieveOption(argc,argv);
+  y_opt.retrieveOption(argc,argv);
+  read_opt.retrieveOption(argc,argv);
+  refpixel_opt.retrieveOption(argc,argv);
+  driver_opt.retrieveOption(argc,argv);
+  extent_opt.retrieveOption(argc,argv);
+  ulx_opt.retrieveOption(argc,argv);
+  uly_opt.retrieveOption(argc,argv);
+  lrx_opt.retrieveOption(argc,argv);
+  lry_opt.retrieveOption(argc,argv);
+  hist_opt.retrieveOption(argc,argv);
+  nbin_opt.retrieveOption(argc,argv);
+  type_opt.retrieveOption(argc,argv);
+  description_opt.retrieveOption(argc,argv);
+  metadata_opt.retrieveOption(argc,argv);
+  maskValue_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    std::cout << "usage: pkinfo -i imagefile [OPTIONS]" << std::endl;
+    exit(0);
+  }
+
+  //for union
+  double maxLRX=0;
+  double maxULY=0;
+  double minULX=0;
+  double minLRY=0;
+
+  //for intersect
+  double minLRX=0;
+  double minULY=0;
+  double maxULX=0;
+  double maxLRY=0;
+  
+  ImgReaderGdal imgReader;
+  for(int ifile=0;ifile<input_opt.size();++ifile){
+    imgReader.open(input_opt[ifile]);
+    if(filename_opt[0])
+      std::cout << " --input " << input_opt[ifile] << " ";
+    if(centre_opt[0]){
+      double theX, theY;
+      imgReader.getCentrePos(theX,theY);
+      std::cout << setprecision(12) << " -x " << theX << " -y " << theY << " ";
+    }
+    if(refpixel_opt[0]){
+      assert(band_opt[0]<imgReader.nrOfBand());
+      Egcs egcs;
+      for(int inodata=0;inodata<maskValue_opt.size();++inodata)
+        imgReader.pushNoDataValue(maskValue_opt[inodata],band_opt[0]);
+      double refX,refY;
+      //get centre of reference (centre of gravity) pixel in image
+      imgReader.getRefPix(refX,refY,band_opt[0]);
+      cout << setprecision(12) << "-rx " << refX << " -ry " << refY << endl;
+      egcs.setLevel(egcs.res2level(imgReader.getDeltaX()));
+      // unsigned short theLevel=egcs.getLevel(imgReader.getDeltaX());
+      // egcs.setLevel(theLevel);
+      //cout << "cell code at level " << egcs.getLevel() << " (resolution is " << egcs.getResolution() << "): " << egcs.geo2cell(refX,refY) << endl;
+    }
+    if(bbox_opt[0]||bbox_te_opt[0]){
+      double theULX, theULY, theLRX, theLRY;
+      imgReader.getBoundingBox(theULX,theULY,theLRX,theLRY);
+      if(bbox_te_opt[0])
+        std::cout << setprecision(12) << "-te " << theULX << " " << theLRY << " " << theLRX << " " << theULY;
+      else
+        std::cout << setprecision(12) << "--ulx=" << theULX << " --uly=" << theULY << " --lrx=" << theLRX << " --lry=" << theLRY << " ";
+      if(!ifile){
+	maxLRX=theLRX;
+	maxULY=theULY;
+	minULX=theULX;
+	minLRY=theLRY;
+
+	minLRX=theLRX;
+	minULY=theULY;
+	maxULX=theULX;
+	maxLRY=theLRY;
+      }
+      else{
+	maxLRX=(theLRX>maxLRX)?theLRX:maxLRX;
+	maxULY=(theULY>maxULY)?theULY:maxULY;
+	minULX=(theULX<minULX)?theULX:minULX;
+	minLRY=(theLRY<minLRY)?theLRY:minLRY;
+
+	minLRX=(theLRX<minLRX)?theLRX:minLRX;
+	minULY=(theULY<minULY)?theULY:minULY;
+	maxULX=(theULX>maxULX)?theULX:maxULX;
+	maxLRY=(theLRY>maxLRY)?theLRY:maxLRY;
+      }
+    }
+    if(dx_opt[0])
+      std::cout << "--dx " << imgReader.getDeltaX() << " ";
+    if(dy_opt[0])
+      std::cout << "--dy " << imgReader.getDeltaY() << " ";
+    if(cover_opt[0]){
+      //get bounding box from extentReader if defined
+      ImgReaderOgr extentReader;
+      if(extent_opt[0]!=""){
+        extentReader.open(extent_opt[0]);
+        if(!(extentReader.getExtent(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))){
+          cerr << "Error: could not get extent from " << extent_opt[0] << std::endl;
+          exit(1);
+        }
+        // std::cout << "--ulx=" << ulx_opt[0] << " --uly=" << uly_opt[0] << " --lrx=" << lrx_opt[0] << " --lry=" << lry_opt[0] << std::endl;
+      }
+      double theULX, theULY, theLRX, theLRY;
+      imgReader.getBoundingBox(theULX,theULY,theLRX,theLRY);
+      if((ulx_opt[0]||uly_opt[0]||lrx_opt[0]||lry_opt[0])&&(imgReader.covers(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0])))
+	std::cout << " -i " << input_opt[ifile] << " ";
+      else if(imgReader.covers(x_opt[0],y_opt[0]))
+	std::cout << " -i " << input_opt[ifile] << " ";
+
+    }
+    else if(ulx_opt[0]||uly_opt[0]||lrx_opt[0]||lry_opt[0]){
+      double ulx,uly,lrx,lry;
+      imgReader.getBoundingBox(ulx,uly,lrx,lry);
+      if(ulx_opt[0])
+        std::cout << " --ulx=" << fixed << ulx << " ";
+      if(uly_opt[0])
+        std::cout << " --uly=" << fixed << uly << " ";
+      if(lrx_opt[0])
+        std::cout << " --lrx=" << fixed << lrx << " ";
+      if(lry_opt[0])
+        std::cout << " --lry=" << fixed << lry << " ";
+    }
+    if(colorTable_opt[0]){
+      GDALColorTable* colorTable=imgReader.getColorTable();
+      for(int index=0;index<colorTable->GetColorEntryCount();++index){
+        GDALColorEntry sEntry=*(colorTable->GetColorEntry(index));
+        std::cout << index << " " << sEntry.c1 << " " << sEntry.c2 << " " << sEntry.c3 << " " << sEntry.c4 << std::endl;
+      }
+    }
+    if(samples_opt[0])
+      std::cout << "--samples " << imgReader.nrOfCol() << " ";
+    if(lines_opt[0])
+      std::cout << "--rows " << imgReader.nrOfRow() << " ";
+    if(nband_opt[0])
+      std::cout << "--nband " << imgReader.nrOfBand() << " ";
+    // if(magic_opt[0]){
+    //   double magic_x, magic_y;
+    //   imgReader.getMagicPixel(magic_x,magic_y);
+    //   std::cout << "--magic_x " << magic_x << " --magic_y " << magic_y << " ";
+    // }
+    double minValue=0;
+    double maxValue=0;
+    double meanValue=0;
+    double stdDev=0;
+    if(stat_opt[0]){
+      assert(band_opt[0]<imgReader.nrOfBand());
+      GDALProgressFunc pfnProgress;
+      void* pProgressData;
+      GDALRasterBand* rasterBand;
+      rasterBand=imgReader.getRasterBand(band_opt[0]);
+      rasterBand->ComputeStatistics(0,&minValue,&maxValue,&meanValue,&stdDev,pfnProgress,pProgressData);
+      std::cout << "--min " << minValue << " --max " << maxValue << " --mean " << meanValue << " --stdDev " << stdDev << " ";
+    }
+
+    if(minmax_opt[0]){
+      assert(band_opt[0]<imgReader.nrOfBand());
+      imgReader.getMinMax(minValue,maxValue,band_opt[0]);
+      std::cout << "--min " << minValue << " --max " << maxValue << " ";
+    }
+    if(hist_opt[0]){
+      assert(band_opt[0]<imgReader.nrOfBand());
+      if(min_opt[0]==max_opt[0])
+        imgReader.getMinMax(minValue,maxValue,band_opt[0]);
+      else{
+        minValue=min_opt[0];
+        maxValue=max_opt[0];
+      }
+      int nbin=nbin_opt[0];
+      if(nbin_opt[0]==0)
+	nbin=maxValue-minValue+1;
+      assert(nbin>0);
+      std::vector<unsigned long int> output(nbin);
+      unsigned long int nsample=0;
+      unsigned long int ninvalid=0;
+      std::vector<double> lineBuffer(imgReader.nrOfCol());
+      for(int i=0;i<nbin;output[i++]=0);
+      for(int irow=0;irow<imgReader.nrOfRow();++irow){
+	imgReader.readData(lineBuffer,GDT_Float64,irow,band_opt[0]);
+	for(int icol=0;icol<imgReader.nrOfCol();++icol){
+	  if(lineBuffer[icol]>maxValue)
+            ++ninvalid;
+          else if(lineBuffer[icol]<minValue)
+            ++ninvalid;
+	  else if(lineBuffer[icol]==maxValue)
+	    ++output[nbin-1];
+	  else if(static_cast<double>(lineBuffer[icol]-minValue)/(maxValue-minValue)*nbin>=nbin)
+	    ++output[nbin-1];
+	  else
+	    ++output[static_cast<int>(static_cast<double>(lineBuffer[icol]-minValue)/(maxValue-minValue)*nbin)];
+	}
+      }
+      nsample=imgReader.nrOfCol()*imgReader.nrOfRow()-ninvalid;
+      std::cout.precision(10);
+      for(int bin=0;bin<nbin;++bin){
+	nsample+=output[bin];
+        if(output[bin]>0){
+          std::cout << (maxValue-minValue)*bin/(nbin-1)+minValue << " ";
+          if(relative_opt[0])
+            std::cout << 100.0*static_cast<double>(output[bin])/static_cast<double>(nsample) << std::endl;
+          else
+            std::cout << static_cast<double>(output[bin])  << std::endl;
+        }
+      }
+    }
+    else{
+      int minCol,minRow;
+      if(min_opt[0]){
+        assert(band_opt[0]<imgReader.nrOfBand());
+        std::cout << "--min " << imgReader.getMin(minCol, minRow,band_opt[0]);
+      }
+      if(max_opt[0]){
+        assert(band_opt[0]<imgReader.nrOfBand());
+        assert(band_opt[0]<imgReader.nrOfBand());
+        std::cout << "--max " << imgReader.getMax(minCol, minRow,band_opt[0]);
+      }
+    }
+    if(projection_opt[0]){
+      if(imgReader.isGeoRef())
+        std::cout << "--projection " << imgReader.getProjection() << " ";
+      else
+        std::cout << " --projection none" << " ";
+    }
+    if(geo_opt[0]&&!read_opt[0]){
+      double ulx,uly,deltaX,deltaY,rot1,rot2;
+      imgReader.getGeoTransform(ulx,uly,deltaX,deltaY,rot1,rot2);
+      std::cout << " --geo " << setprecision(12) << ulx << " " << uly << " " << deltaX << " " << deltaY << " " << rot1 << " " << rot2 << " ";
+    }
+    if(interleave_opt[0]){
+      std::cout << " --interleave " << imgReader.getInterleave() << " ";
+    }
+    if(type_opt[0]){
+      std::cout << "--otype " << GDALGetDataTypeName(imgReader.getDataType(band_opt[0])) << " ";
+      // std::cout << " -ot " << GDALGetDataTypeName(imgReader.getDataType(band_opt[0])) << " (" << static_cast<short>(imgReader.getDataType(band_opt[0])) << ")" << std::endl;
+    }
+    if(description_opt[0]){
+      // try{
+      // 	std::cout << "image description: " << imgReader.getImageDescription() << std::endl;
+      // }
+      // catch(...){
+      // 	std::cout << "catched" << std::endl;
+      // }
+      list<std::string> metaData;
+      imgReader.getMetadata(metaData);
+      list<std::string>::const_iterator lit=metaData.begin();
+      std::cout << " --description ";
+      while(lit!=metaData.end())
+      	std::cout << *(lit++) << " ";
+    }
+    if(metadata_opt[0]){
+      std::cout << "Metadata: " << std::endl;
+      list<std::string> lmeta;
+      imgReader.getMetadata(lmeta);
+      list<std::string>::const_iterator lit=lmeta.begin();
+      while(lit!=lmeta.end()){
+        std::cout << *lit << std::endl;
+        ++lit;
+      }
+//       char** cmetadata=imgReader.getMetadata();
+//       while(*cmetadata!=NULL){
+//         std::cout << *(cmetadata) << std::endl;
+//         ++cmetadata;
+//       }
+    }
+    if(read_opt[0]){
+      int nband=band_opt.size();
+      if(band_opt[0]<0)
+        nband=imgReader.nrOfBand();
+      std::cout.precision(12);
+      for(int iband=0;iband<nband;++iband){
+        unsigned short theBand=(band_opt[0]<0)? iband : band_opt[iband];
+        std::vector<float> rowBuffer;//buffer will be resized in readdata
+        for(int iy=0;iy<y_opt.size();++iy){
+	  double theRow=y_opt[iy];
+          for(int ix=0;ix<x_opt.size();++ix){
+	    double theCol=x_opt[iy];
+	    if(geo_opt[0])
+	      imgReader.geo2image(x_opt[ix],y_opt[iy],theCol,theRow);
+            assert(theRow>=0);
+            assert(theRow<imgReader.nrOfRow());
+            imgReader.readData(rowBuffer,GDT_Float32, static_cast<int>(theRow), theBand);
+            if(x_opt[ix]>=0){
+              assert(theCol<rowBuffer.size());
+              std::cout << rowBuffer[static_cast<int>(theCol)] << " ";
+            }
+            else{
+              for(int i=0;i<rowBuffer.size();++i)
+                std::cout << rowBuffer[i] << " ";
+            }
+          }
+          std::cout << std::endl;
+        }
+      }
+    }
+    if(driver_opt[0])
+      std::cout << " --oformat " << imgReader.getDriverDescription() << " ";
+    imgReader.close();
+  }
+  if((bbox_opt[0]||bbox_te_opt[0])&&input_opt.size()>1){
+    if(bbox_te_opt[0])
+      std::cout << setprecision(12) << "-te " << minULX << " " << minLRY << " " << maxLRX << " " << maxULY;
+    else
+      std::cout << "union bounding box: " << setprecision(12) << "--ulx=" << minULX << " --uly=" << maxULY << " --lrx=" << maxLRX << " --lry=" << minLRY << std::endl;
+    if(maxULX<minLRX&&minULY>maxLRY){
+      if(bbox_te_opt[0])
+        std::cout << "intersect bounding box: " << setprecision(12) << "-te " << maxULX << " " << maxLRY << " " << minLRX << " --lry=" << minULY << std::endl;
+      else
+        std::cout << "intersect bounding box: " << setprecision(12) << "--ulx=" << maxULX << " --uly=" << minULY << " --lrx=" << minLRX << " --lry=" << maxLRY << std::endl;
+    }
+    else
+      std::cout << "no intersect" << std::endl;
+  }
+  //    std::cout << "bounding box mosaic (ULX ULY LRX LRY): " << minULX << " " << maxULY << " " << maxLRX << " " << minLRY << std::endl;
+  if(!read_opt[0])
+    std::cout << std::endl;
+}
diff --git a/src/apps/pklas2img.cc b/src/apps/pklas2img.cc
new file mode 100644
index 0000000..63f2ccd
--- /dev/null
+++ b/src/apps/pklas2img.cc
@@ -0,0 +1,516 @@
+/**********************************************************************
+pklas2img.cc: program to create (e.g., DEM) raster image from las files
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <iostream>
+#include "Optionpk.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "imageclasses/ImgReaderOgr.h"
+#include "fileclasses/FileReaderLas.h"
+#include "algorithms/Histogram.h"
+#include "algorithms/Filter2d.h"
+
+using namespace std;
+
+int main(int argc,char **argv) {
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<string> input_opt("i", "input", "Input las file", "");
+  // Optionpk<string> mask_opt("m", "mask", "mask image file", "");
+  // Optionpk<short> invalid_opt("t", "invalid", "Mask value(s) where image is invalid. Use multiple values for a single mask. Default value is 0", 0);
+  Optionpk<short> flag_opt("f", "flag", "Flag value(s) to put in image if not valid. Use as many flags as invalid options (Default is 0)", 0);
+  Optionpk<string> attribute_opt("n", "name", "names of the attribute to select: [intensity|return|nreturn|z]", "z");
+  Optionpk<bool> disc_opt("circ", "circular", "circular disc kernel for dilation and erosion (default is false)", false);
+  Optionpk<double> maxSlope_opt("s", "maxSlope", "Maximum slope used for morphological filtering (default is 0)", 0.0);
+  Optionpk<double> hThreshold_opt("ht", "maxHeight", "initial and maximum height threshold for progressive morphological filtering (e.g., -ht 0.2 -ht 2.5)", 0.2);
+  Optionpk<short> maxIter_opt("\0", "maxIter", "Maximum number of iterations in post filter (default is 100)", 100.0);
+  Optionpk<short> nbin_opt("nb", "nbin", "Number of percentile bins for calculating profile (=number of output bands) (default is 10)", 10.0);
+  Optionpk<unsigned short> returns_opt("r", "returns", "number(s) of returns to include (use -r -1 for last return only). Default is 0 (include all returns)", 0);
+  Optionpk<string> composite_opt("c", "composite", "composite for multiple points in cell (min, max, median, mean, sum, first, last, profile). Default is last (overwrite cells with latest point", "last");
+  Optionpk<string> filter_opt("fir", "filter", "filter las points (single,multiple,all). Default is all", "all");
+  Optionpk<string> postFilter_opt("pf", "pfilter", "filter las points (etew_min,promorph (progressive morphological filter),bunting (adapted promorph),open,close,none) . Default is none", "none");
+  Optionpk<short> dimx_opt("\0", "dimX", "Dimension X of postFilter (default is 3)", 3);
+  Optionpk<short> dimy_opt("\0", "dimY", "Dimension Y of postFilter (default is 3)", 3);
+  Optionpk<string> output_opt("o", "output", "Output image file", "");
+  Optionpk<string> projection_opt("p", "projection", "projection in EPSG code, e.g., EPSG:3035 (Default is no projection)", "");
+  Optionpk<double> ulx_opt("\0", "ulx", "Upper left x value bounding box (in geocoordinates if georef is true). Default is 0: read from input file", 0.0);
+  Optionpk<double> uly_opt("\0", "uly", "Upper left y value bounding box (in geocoordinates if georef is true). Default is 0: read from input file", 0.0);
+  Optionpk<double> lrx_opt("\0", "lrx", "Lower right x value bounding box (in geocoordinates if georef is true). Default is 0: read from input file", 0.0);
+  Optionpk<double> lry_opt("\0", "lry", "Lower right y value bounding box (in geocoordinates if georef is true). Default is 0: read from input file", 0.0);
+  Optionpk<string> otype_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "Byte");
+  Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "GTiff");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<double> dx_opt("dx", "dx", "Output resolution in x (in meter) (default is 0.0: keep original resolution)", 0.0);
+  Optionpk<double> dy_opt("dy", "dy", "Output resolution in y (in meter) (default is 0.0: keep original resolution)", 0.0);
+  Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<short> verbose_opt("v", "verbose", "verbose (default is 0)", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+
+  input_opt.retrieveOption(argc,argv);
+  // mask_opt.retrieveOption(argc,argv);
+  // invalid_opt.retrieveOption(argc,argv);
+  flag_opt.retrieveOption(argc,argv);
+  attribute_opt.retrieveOption(argc,argv);
+  disc_opt.retrieveOption(argc,argv);
+  maxSlope_opt.retrieveOption(argc,argv);
+  hThreshold_opt.retrieveOption(argc,argv);
+  maxIter_opt.retrieveOption(argc,argv);
+  nbin_opt.retrieveOption(argc,argv);
+  returns_opt.retrieveOption(argc,argv);
+  composite_opt.retrieveOption(argc,argv);
+  filter_opt.retrieveOption(argc,argv);
+  postFilter_opt.retrieveOption(argc,argv);
+  dimx_opt.retrieveOption(argc,argv);
+  dimy_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  projection_opt.retrieveOption(argc,argv);
+  ulx_opt.retrieveOption(argc,argv);
+  uly_opt.retrieveOption(argc,argv);
+  lrx_opt.retrieveOption(argc,argv);
+  lry_opt.retrieveOption(argc,argv);
+  otype_opt.retrieveOption(argc,argv);
+  oformat_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  dx_opt.retrieveOption(argc,argv);
+  dy_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+
+
+  GDALAllRegister();
+
+  double dfComplete=0.0;
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+
+  Vector2d<vector<float> > inputData;//row,col,point
+   
+  ImgReaderGdal maskReader;
+  ImgWriterGdal outputWriter;
+  GDALDataType theType=GDT_Unknown;
+  if(verbose_opt[0])
+    cout << "possible output data types: ";
+  for(int iType = 0; iType < GDT_TypeCount; ++iType){
+    if(verbose_opt[0])
+      cout << " " << GDALGetDataTypeName((GDALDataType)iType);
+    if( GDALGetDataTypeName((GDALDataType)iType) != NULL
+        && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
+                 otype_opt[0].c_str()))
+      theType=(GDALDataType) iType;
+  }
+  if(verbose_opt[0]){
+    if(theType==GDT_Unknown)
+      cout << "Unknown output pixel type: " << otype_opt[0] << endl;
+    else
+      cout << "Output pixel type:  " << GDALGetDataTypeName(theType) << endl;
+  }
+
+  double maxLRX=0;
+  double maxULY=0;
+  double minULX=0;
+  double minLRY=0;
+
+  unsigned long int totalPoints=0;
+  unsigned long int nPoints=0;
+  unsigned long int ipoint=0;
+  for(int iinput=0;iinput<input_opt.size();++iinput){
+    assert(input_opt[iinput].find(".las")!=string::npos);
+    FileReaderLas lasReader;
+    try{
+      lasReader.open(input_opt[iinput]);
+    }
+    catch(string errorString){
+      cout << errorString << endl;
+      exit(1);
+    }
+    nPoints=lasReader.getPointCount();
+    totalPoints+=nPoints;
+
+    if(ulx_opt[0]>=lrx_opt[0]||uly_opt[0]<=lry_opt[0]){
+      double ulx,uly,lrx,lry;
+      lasReader.getExtent(ulx,uly,lrx,lry);
+      lrx+=dx_opt[0];//pixel coordinates are referenced to upper left corner (las coordinates are centres)
+      lry-=dy_opt[0];//pixel coordinates are referenced to upper left corner (las coordinates are centres)
+      if(ulx>=lrx){
+        ulx=ulx-dx_opt[0]/2.0;
+        lrx=ulx+dx_opt[0]/2.0;
+      }
+      if(uly<=lry){
+        uly=lry+dy_opt[0]/2.0;
+        lry=lry-dy_opt[0]/2.0;
+      }
+      if(maxLRX>minULX){
+        maxLRX=(lrx>maxLRX)?lrx:maxLRX;
+        maxULY=(uly>maxULY)?uly:maxULY;
+        minULX=(ulx<minULX)?ulx:minULX;
+        minLRY=(lry<minLRY)?lry:minLRY;
+      }
+      else{//initialize
+        maxLRX=lrx;
+        maxULY=uly;
+        minULX=ulx;
+        minLRY=lry;
+      }        
+    }
+    else{
+      maxLRX=lrx_opt[0];
+      maxULY=uly_opt[0];
+      minULX=ulx_opt[0];
+      minLRY=lry_opt[0];
+    }
+    lasReader.close();
+  }
+  if(verbose_opt[0]){
+    std::cout << setprecision(12) << "--ulx=" << minULX << " --uly=" << maxULY << " --lrx=" << maxLRX << " --lry=" << minLRY << std::endl;
+    std::cout << "total number of points before filtering: " << totalPoints << std::endl;
+    std::cout << "filter set to " << filter_opt[0] << std::endl;
+    std::cout << "postFilter set to " << postFilter_opt[0] << std::endl;
+  }
+  int ncol=ceil(maxLRX-minULX)/dx_opt[0];//number of columns in outputGrid
+  int nrow=ceil(maxULY-minLRY)/dy_opt[0];//number of rows in outputGrid
+  //todo: multiple bands
+  int nband=(composite_opt[0]=="profile")? nbin_opt[0] : 1;
+  if(output_opt[0]==""){
+    cerr << "Error: no output file defined" << endl;
+    exit(1);
+  }
+  if(verbose_opt[0])
+    cout << "opening output file " << output_opt[0] << endl;
+  outputWriter.open(output_opt[0],ncol,nrow,nband,theType,oformat_opt[0],option_opt);
+  //set projection
+  outputWriter.setGeoTransform(minULX,maxULY,dx_opt[0],dy_opt[0],0,0);
+  if(projection_opt[0]!=""){
+    string projectionString=outputWriter.setProjectionProj4(projection_opt[0]);
+    if(verbose_opt[0])
+      cout << "projection: " << projectionString << endl;
+  }
+  if(!outputWriter.isGeoRef())
+    cout << "Warning: output image " << output_opt[0] << " is not georeferenced!" << endl;
+  if(colorTable_opt[0]!="")
+    outputWriter.setColorTable(colorTable_opt[0]);
+
+  inputData.clear();
+  inputData.resize(nrow,ncol);
+  std::cout << "Reading " << input_opt.size() << " las files" << std::endl;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  for(int iinput=0;iinput<input_opt.size();++iinput){
+    FileReaderLas lasReader;
+    try{
+      lasReader.open(input_opt[iinput]);
+    }
+    catch(string errorString){
+      cout << errorString << endl;
+      exit(1);
+    }
+    //set bounding filter
+    // lasReader.addBoundsFilter(minULX,maxULY,maxLRX,minLRY);
+    //set returns filter
+    if(returns_opt[0])
+      lasReader.addReturnsFilter(returns_opt);
+    lasReader.setFilters();
+
+    if(attribute_opt[0]!="z"){
+      vector<boost::uint16_t> returnsVector;
+      vector<string>::iterator ait=attribute_opt.begin();
+      while(ait!=attribute_opt.end()){
+        if(*ait=="intensity"){
+          if(verbose_opt[0])
+            std::cout << "writing intensity" << std::endl;
+          ++ait;
+        }
+        else if(*ait=="return"){
+          if(verbose_opt[0])
+            std::cout << "writing return number" << std::endl;
+          ++ait;
+        }
+        else if(*ait=="nreturn"){
+          if(verbose_opt[0])
+            std::cout << "writing number of returns" << std::endl;
+          ++ait;
+        }
+        else
+          attribute_opt.erase(ait);
+      }
+    }
+    liblas::Point thePoint;
+    while(lasReader.readNextPoint(thePoint)){
+      progress=static_cast<float>(ipoint)/totalPoints;
+      pfnProgress(progress,pszMessage,pProgressArg);
+      if(verbose_opt[0]>1)
+        cout << "reading point " << ipoint << endl;
+      if(thePoint.GetX()<minULX||thePoint.GetX()>=maxLRX||thePoint.GetY()>=maxULY||thePoint.GetY()<minLRY)
+        continue;
+      if((filter_opt[0]=="single")&&(thePoint.GetNumberOfReturns()!=1))
+        continue;
+      if((filter_opt[0]=="multiple")&&(thePoint.GetNumberOfReturns()<2))
+        continue;
+      double dcol,drow;
+      outputWriter.geo2image(thePoint.GetX(),thePoint.GetY(),dcol,drow);
+      int icol=static_cast<int>(dcol);
+      int irow=static_cast<int>(drow);
+      assert(irow>=0);
+      assert(irow<nrow);
+      assert(icol>=0);
+      assert(icol<ncol);
+      if(attribute_opt[0]=="z")
+        inputData[irow][icol].push_back(thePoint.GetZ());
+      else if(attribute_opt[0]=="intensity")
+        inputData[irow][icol].push_back(thePoint.GetIntensity());
+      else if(attribute_opt[0]=="return")
+        inputData[irow][icol].push_back(thePoint.GetReturnNumber());
+      else if(attribute_opt[0]=="nreturn")
+        inputData[irow][icol].push_back(thePoint.GetNumberOfReturns());
+      else{
+        std::string errorString="attribute not supported";
+        throw(errorString);
+      }
+      ++ipoint;
+    }
+    if(verbose_opt[0])
+      std::cout << "number of points: " << ipoint << std::endl;
+    lasReader.close();
+  }
+  progress=1;
+  pfnProgress(progress,pszMessage,pProgressArg);
+
+  std::cout << "processing LiDAR points" << std::endl;
+  progress=0;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  Histogram hist;
+  //fill in inputData in outputData
+  Vector2d<float> outputData(nrow,ncol);
+  if(composite_opt[0]=="profile"){
+    assert(postFilter_opt[0]=="none");
+    // for(int iband=0;iband<nband;++iband)
+      // outputProfile[iband].resize(nrow,ncol);
+  }
+  for(int irow=0;irow<nrow;++irow){
+    Vector2d<float> outputProfile(nband,ncol);
+    for(int icol=0;icol<ncol;++icol){
+      std::vector<float> profile;
+      if(!inputData[irow][icol].size())
+        outputData[irow][icol]=(static_cast<float>((flag_opt[0])));
+      else{
+        Histogram hist;
+        if(composite_opt[0]=="min")
+          outputData[irow][icol]=hist.min(inputData[irow][icol]);
+        else if(composite_opt[0]=="max")
+          outputData[irow][icol]=hist.max(inputData[irow][icol]);
+        else if(composite_opt[0]=="median")
+          outputData[irow][icol]=hist.median(inputData[irow][icol]);
+        else if(composite_opt[0]=="mean")
+          outputData[irow][icol]=hist.mean(inputData[irow][icol]);
+        else if(composite_opt[0]=="sum")
+          outputData[irow][icol]=hist.sum(inputData[irow][icol]);
+        else if(composite_opt[0]=="first")
+          outputData[irow][icol]=inputData[irow][icol][0];
+        else if(composite_opt[0]=="last")
+          outputData[irow][icol]=inputData[irow][icol].back();
+        else if(composite_opt[0]=="profile"){
+          if(inputData[irow][icol].size()<2){
+            for(int iband=0;iband<nband;++iband)
+              outputProfile[iband][icol]=static_cast<float>(flag_opt[0]);
+            continue;
+          }
+          float min=0;
+          float max=0;
+          hist.minmax(inputData[irow][icol],inputData[irow][icol].begin(),inputData[irow][icol].end(),min,max);
+          if(verbose_opt[0])
+            std::cout << "min,max: " << min << "," << max << std::endl;
+          if(max>min){
+            hist.percentiles(inputData[irow][icol],inputData[irow][icol].begin(),inputData[irow][icol].end(),profile,nband,min,max);
+            assert(profile.size()==nband);
+            for(int iband=0;iband<nband;++iband)
+              outputProfile[iband][icol]=profile[iband];
+          }
+          else{
+            for(int iband=0;iband<nband;++iband)
+              outputProfile[iband][icol]=max;
+          }
+        }
+        else{
+          std::cout << "Error: composite_opt " << composite_opt[0] << " not supported" << std::endl;
+          exit(2);
+        }
+      }
+    }
+    if(composite_opt[0]=="profile"){
+      for(int iband=0;iband<nband;++iband){
+        // assert(outputProfile[iband].size()==outputWriter.nrOfRow());
+        assert(outputProfile[iband].size()==outputWriter.nrOfCol());
+        try{
+          outputWriter.writeData(outputProfile[iband],theType,irow,iband);
+        }
+        catch(std::string errorString){
+          cout << errorString << endl;
+          exit(1);
+        }
+      }
+    }
+    progress=static_cast<float>(irow)/outputWriter.nrOfRow();
+    pfnProgress(progress,pszMessage,pProgressArg);
+  }
+  progress=1;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  inputData.clear();//clean up memory
+  //apply post filter
+  std::cout << "Applying post processing filter: " << postFilter_opt[0] << std::endl;
+  if(postFilter_opt[0]=="etew_min"){
+    if(composite_opt[0]!="min")
+      std::cout << "Warning: composite option is not set to min!" << std::endl;
+    //Elevation Threshold with Expand Window (ETEW) Filter (p.73 frmo Airborne LIDAR Data Processing and Analysis Tools ALDPAT 1.0)
+    //first iteration is performed assuming only minima are selected using options -fir all -c min
+    unsigned long int nchange=1;
+    //increase cells and thresholds until no points from the previous iteration are discarded.
+    int dimx=dimx_opt[0];
+    int dimy=dimy_opt[0];
+    Filter2d::Filter2d morphFilter;
+    morphFilter.setNoValue(0);
+    Vector2d<float> currentOutput=outputData;
+    int iteration=1;
+    while(nchange&&iteration<maxIter_opt[0]){
+      double hThreshold=maxSlope_opt[0]*dimx;
+      Vector2d<float> newOutput;
+      nchange=morphFilter.morphology(currentOutput,newOutput,Filter2d::ERODE,dimx,dimy,disc_opt[0],hThreshold);
+      currentOutput=newOutput;
+      dimx+=2;//change from theory: originally double cellCize
+      dimy+=2;//change from theory: originally double cellCize
+      std::cout << "iteration " << iteration << ": " << nchange << " pixels changed" << std::endl;
+      ++iteration;
+    }
+    outputData=currentOutput;
+  }    
+  else if(postFilter_opt[0]=="promorph"||postFilter_opt[0]=="bunting"){
+    if(composite_opt[0]!="min")
+      std::cout << "Warning: composite option is not set to min!" << std::endl;
+    assert(hThreshold_opt.size()>1);
+    //Progressive morphological filter tgrs2003_zhang vol41 pp 872-882
+    //first iteration is performed assuming only minima are selected using options -fir all -c min
+    //increase cells and thresholds until no points from the previous iteration are discarded.
+    int dimx=dimx_opt[0];
+    int dimy=dimy_opt[0];
+    Filter2d::Filter2d theFilter;
+    theFilter.setNoValue(0);
+    Vector2d<float> currentOutput=outputData;
+    double hThreshold=hThreshold_opt[0];
+    int iteration=1;
+    while(iteration<maxIter_opt[0]){
+      std::cout << "iteration " << iteration << " with window size " << dimx << " and dh_max: " << hThreshold << std::endl;
+      Vector2d<float> newOutput;
+      try{
+        theFilter.morphology(outputData,currentOutput,Filter2d::ERODE,dimx,dimy,disc_opt[0],maxSlope_opt[0]);
+        theFilter.morphology(currentOutput,outputData,Filter2d::DILATE,dimx,dimy,disc_opt[0],maxSlope_opt[0]);
+      //   if(postFilter_opt[0]=="bunting"){//todo: implement doit in Filter2d on Vector2d
+      //     theFilter.doit(outputData,currentOutput,Filter2d::MEDIAN,dimx,dimy,1,disc_opt[0]);
+      // filter2d.doit(input,output,Filter2d::MEDIAN,dimX_opt[0],dimY_opt[0],down_opt[0],disc_opt[0]);
+
+      //     outputData=currentOutput;
+      //   }
+      }
+      catch(std::string errorString){
+        cout << errorString << endl;
+        exit(1);
+      }
+      int newdimx=2*(dimx-1)+1;
+      int newdimy=2*(dimy-1)+1;//from PE&RS vol 71 pp313-324
+      hThreshold=hThreshold_opt[0]+maxSlope_opt[0]*(newdimx-dimx)*dx_opt[0];
+      dimx=newdimx;
+      dimy=newdimy;
+      if(hThreshold>hThreshold_opt[1])
+        hThreshold=hThreshold_opt[1];
+      ++iteration;
+    }
+    outputData=currentOutput;
+  }    
+  else if(postFilter_opt[0]=="open"){
+    if(composite_opt[0]!="min")
+      std::cout << "Warning: composite option is not set to min!" << std::endl;
+    Filter2d::Filter2d morphFilter;
+    morphFilter.setNoValue(0);
+    Vector2d<float> filterInput=outputData;
+    try{
+      morphFilter.morphology(outputData,filterInput,Filter2d::ERODE,dimx_opt[0],dimy_opt[0],disc_opt[0],maxSlope_opt[0]);
+      morphFilter.morphology(filterInput,outputData,Filter2d::DILATE,dimx_opt[0],dimy_opt[0],disc_opt[0],maxSlope_opt[0]);
+    }
+    catch(std::string errorString){
+      cout << errorString << endl;
+      exit(1);
+    }
+  }
+  else if(postFilter_opt[0]=="close"){
+    if(composite_opt[0]!="max")
+      std::cout << "Warning: composite option is not set to max!" << std::endl;
+    Filter2d::Filter2d morphFilter;
+    morphFilter.setNoValue(0);
+    Vector2d<float> filterInput=outputData;
+    try{
+      morphFilter.morphology(outputData,filterInput,Filter2d::DILATE,dimx_opt[0],dimy_opt[0],disc_opt[0],maxSlope_opt[0]);
+      morphFilter.morphology(filterInput,outputData,Filter2d::ERODE,dimx_opt[0],dimy_opt[0],disc_opt[0],maxSlope_opt[0]);
+    }
+    catch(std::string errorString){
+      cout << errorString << endl;
+      exit(1);
+    }
+  }
+  if(composite_opt[0]!="profile"){
+    //write output file
+    std::cout << "writing output raster file" << std::endl;
+    progress=0;
+    pfnProgress(progress,pszMessage,pProgressArg);
+    for(int irow=0;irow<nrow;++irow){
+      try{
+        assert(outputData.size()==outputWriter.nrOfRow());
+        assert(outputData[0].size()==outputWriter.nrOfCol());
+        outputWriter.writeData(outputData[irow],theType,irow,0);
+      }
+      catch(std::string errorString){
+        cout << errorString << endl;
+        exit(1);
+      }
+      progress=static_cast<float>(irow)/outputWriter.nrOfRow();
+      pfnProgress(progress,pszMessage,pProgressArg);
+    }
+  }
+  if(verbose_opt[0])
+    std::cout << "closing lasReader" << std::endl;
+  outputWriter.close();
+}
diff --git a/src/apps/pkmosaic.cc b/src/apps/pkmosaic.cc
new file mode 100644
index 0000000..63517a4
--- /dev/null
+++ b/src/apps/pkmosaic.cc
@@ -0,0 +1,899 @@
+/**********************************************************************
+pkmosaic.cc: program to create mosaic geo-referenced images
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <algorithm>
+#include <vector>
+#include <iostream>
+#include <string>
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "imageclasses/ImgReaderOgr.h"
+#include "base/Vector2d.h"
+#include "base/Optionpk.h"
+#include "algorithms/Histogram.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","introduce -uli -ulj to crop based on image coordinates",false);
+  Optionpk<string>  input_opt("i", "input", "Input image file(s). If input contains multiple images, a multi-band output is created", "");
+  Optionpk<string>  output_opt("o", "output", "Output image file", "");
+  Optionpk<string>  projection_opt("p", "projection", "projection in EPSG format (leave blank to copy from input file, use EPSG:3035 to use European projection and to force to European grid", "");
+  Optionpk<string>  extent_opt("e", "extent", "get boundary from extent from polygons in vector file", "");
+  Optionpk<double>  ulx_opt("ulx", "ulx", "Upper left x value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double>  uly_opt("uly", "uly", "Upper left y value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double>  lrx_opt("lrx", "lrx", "Lower right x value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double>  lry_opt("lry", "lry", "Lower right y value bounding box (in geocoordinates if georef is true)", 0.0);
+  Optionpk<double>  dx_opt("dx", "dx", "Output resolution in x (in meter) (0.0: keep original resolution)", 0.0);
+  Optionpk<double>  dy_opt("dy", "dy", "Output resolution in y (in meter) (0.0: keep original resolution)", 0.0);
+  Optionpk<int>  band_opt("b", "band", "band index to crop (-1: crop all bands)", -1);
+  Optionpk<string>  otype_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "");
+  Optionpk<string>  oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "");
+  Optionpk<string>  colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<short>  flag_opt("f", "flag", "Flag value to put in image if out of bounds.", 0);
+  Optionpk<unsigned short>  resample_opt("r", "resample", "Resampling method (0: nearest neighbour, 1: bi-linear interpolation).", 0);
+  Optionpk<string>  description_opt("\0", "description", "Set image description", "");
+  Optionpk<int> mrule_opt("m", "mrule", "Mosaic rule for mosaic (0: overwrite, 1: max ndvi, 2: max Band, 3: min Band, 4: valid Band, 5: mean value, 6: max voting (only for byte images), 7: median, 8: (weighted) sum (default: 0)", 0);
+  Optionpk<int> ruleBand_opt("\0", "rband", "band index used for the rule (for ndvi, use --ruleBand=redBand --ruleBand=nirBand (default 0)", 0);
+  Optionpk<int> validBand_opt("\0", "validBand", "valid band index(es)", 0);
+  Optionpk<double> invalid_opt("t", "invalid", "invalid value for valid band", 0);
+  Optionpk<double> minValue_opt("min", "min", "flag values smaller or equal to this value as invalid. Default is -99999999", -99999999);
+  Optionpk<double> maxValue_opt("max", "max", "flag values larger or equal to this value as invalid. Default is 99999999", 99999999);
+  Optionpk<bool> file_opt("\0", "file", "write number of observations for each pixels as additional layer in mosaic (default is false)", false);
+  Optionpk<short> weight_opt("w", "weight", "Weights (type: short) for the mosaic, use one weight for each input file in same order as input files are provided). Default is 1 (equal weights).", 1);
+  Optionpk<short> class_opt("c", "class", "classes for multi-band output image: each band represents the number of observations for one specific class. Default is 0 (no multi-band output image).", 0);
+  Optionpk<bool>  verbose_opt("v", "verbose", "verbose", false);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  
+  input_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  projection_opt.retrieveOption(argc,argv);
+  extent_opt.retrieveOption(argc,argv);
+  ulx_opt.retrieveOption(argc,argv);
+  uly_opt.retrieveOption(argc,argv);
+  lrx_opt.retrieveOption(argc,argv);
+  lry_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  otype_opt.retrieveOption(argc,argv);
+  oformat_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  dx_opt.retrieveOption(argc,argv);
+  dy_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  flag_opt.retrieveOption(argc,argv);
+  resample_opt.retrieveOption(argc,argv);
+  description_opt.retrieveOption(argc,argv);
+  mrule_opt.retrieveOption(argc,argv);
+  ruleBand_opt.retrieveOption(argc,argv);
+  validBand_opt.retrieveOption(argc,argv);
+  invalid_opt.retrieveOption(argc,argv);
+  minValue_opt.retrieveOption(argc,argv);
+  maxValue_opt.retrieveOption(argc,argv);
+  file_opt.retrieveOption(argc,argv);
+  weight_opt.retrieveOption(argc,argv);
+  class_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << "usage: pkmosaic -i inputimage -o outputimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  while(invalid_opt.size()<validBand_opt.size())
+    invalid_opt.push_back(invalid_opt[0]);
+  RESAMPLE theResample;
+  switch(resample_opt[0]){
+  case(BILINEAR):
+    theResample=BILINEAR;
+    if(verbose_opt[0])
+      cout << "resampling: bilinear interpolation" << endl;
+    break;
+  default:
+    theResample=NEAR;
+    if(verbose_opt[0])
+      cout << "resampling: nearest neighbour" << endl;
+    break;
+  }
+  
+  int nband=0;
+  int nwriteBand=0;
+  int writeBand=0;
+  vector<short> bands;
+  
+  //get bounding box
+  double maxLRX=0;
+  double maxULY=0;
+  double minULX=0;
+  double minLRY=0;
+  double magic_x=1,magic_y=1;//magic pixel for GDAL map info
+
+  GDALDataType theType=GDT_Unknown;
+  if(verbose_opt[0])
+    cout << "possible output data types: ";
+  for(int iType = 0; iType < GDT_TypeCount; ++iType){
+    if(verbose_opt[0])
+      cout << " " << GDALGetDataTypeName((GDALDataType)iType);
+    if( GDALGetDataTypeName((GDALDataType)iType) != NULL
+        && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
+                 otype_opt[0].c_str()))
+      theType=(GDALDataType) iType;
+  }
+  if(verbose_opt[0]){
+    cout << endl;
+    if(theType==GDT_Unknown)
+      cout << "Unknown output pixel type: " << otype_opt[0] << endl;
+    else
+      cout << "Output pixel type:  " << GDALGetDataTypeName(theType) << endl;
+  }
+
+  double dx=dx_opt[0];
+  double dy=dy_opt[0];
+  //get bounding box from extentReader if defined
+  ImgReaderOgr extentReader;
+  if(extent_opt[0]!=""){
+    extentReader.open(extent_opt[0]);
+    if(!(extentReader.getExtent(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))){
+       cerr << "Error: could not get extent from " << extent_opt[0] << endl;
+       exit(1);
+      }
+    else if(verbose_opt[0])
+      cout << "--ulx=" << ulx_opt[0] << " --uly=" << uly_opt[0] << " --lrx=" << lrx_opt[0] << " --lry=" << lry_opt[0] << endl;
+  }
+
+  ImgReaderGdal imgReader;
+  // GDALDataType dataType;
+  // string driverDescription;
+  string theProjection="";
+  GDALColorTable* theColorTable=NULL;
+  // string interleave;
+  // string compression;
+  string theCompression;
+  string theInterleave;
+  string imageType;
+  bool init=false;
+  for(int ifile=0;ifile<input_opt.size();++ifile){
+    try{
+      imgReader.open(input_opt[ifile]);
+    }
+    catch(string errorstring){
+      cerr << errorstring << " " << input_opt[ifile] << endl;
+    }
+    if(colorTable_opt[0]=="")
+      if(imgReader.getColorTable())
+        theColorTable=(imgReader.getColorTable()->Clone());
+    if(projection_opt[0]=="")
+      theProjection=imgReader.getProjection();
+
+    if((ulx_opt[0]||uly_opt[0]||lrx_opt[0]||lry_opt[0])&&(!imgReader.covers(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))){
+      if(verbose_opt[0])
+	cout << input_opt[ifile] << " not within bounding box, skipping..." << endl;
+      imgReader.close();
+      continue;
+    }
+    double theULX, theULY, theLRX, theLRY;
+    imgReader.getBoundingBox(theULX,theULY,theLRX,theLRY);
+    if(verbose_opt[0])
+      cout << "Bounding Box (ULX ULY LRX LRY): " << fixed << setprecision(6) << theULX << " " << theULY << " " << theLRX << " " << theLRY << endl;
+    if(!init){
+      if(verbose_opt[0]){
+        switch(mrule_opt[0]){
+        default:
+        case(0):
+          cout << "Mosaic rule: overwrite" << endl;
+          break;
+        case(1):
+          cout << "Mosaic rule: max ndvi" << endl;
+          break;
+        case(2):
+          cout << "Mosaic rule: max band" << endl;
+          break;
+        case(3):
+          cout << "Mosaic rule: min band" << endl;
+          break;
+        case(4):
+          cout << "Mosaic rule: valid band" << endl;
+          break;
+        case(5):
+          cout << "Mosaic rule: mean value" << endl;
+          break;
+        case(6):
+          cout << "Mosaic rule: max voting (only for byte images)" << endl;
+          break;
+        case(7):
+          cout << "Mosaic rule: median" << endl;
+          break;
+        case(8):
+          cout << "Mosaic rule: sum" << endl;
+          break;
+        }
+      }
+//       nband=mrule_opt[0]!=6? imgReader.nrOfBand(): 2;//max voting: [winner class][number of votes]
+      // nband=imgReader.nrOfBand();
+      if(band_opt[0]>=0){
+	nband=band_opt.size();
+        bands.resize(band_opt.size());
+        for(int iband=0;iband<band_opt.size();++iband){
+          bands[iband]=band_opt[iband];
+          assert(bands[iband]<imgReader.nrOfBand());
+        }
+      }
+      else{
+	nband=imgReader.nrOfBand();
+        bands.resize(nband);
+        for(int iband=0;iband<nband;++iband)
+          bands[iband]=iband;
+      }
+      assert(validBand_opt.size()==minValue_opt.size());
+      assert(validBand_opt.size()==maxValue_opt.size());
+      for(int iband=0;iband<validBand_opt.size();++iband){
+        assert(validBand_opt[iband]>=0&&validBand_opt[iband]<nband);
+        if(verbose_opt[0]){
+          cout << "band " << validBand_opt[iband] << " is valid in ] " << minValue_opt[iband] << " , " << maxValue_opt[iband] << " [" << endl;
+        }
+      }
+      //if output type not set, get type from input image
+      if(theType==GDT_Unknown){
+        theType=imgReader.getDataType();
+        if(verbose_opt[0])
+          cout << "Using data type from input image: " << GDALGetDataTypeName(theType) << endl;
+      }
+
+      if(oformat_opt[0]!="")//default
+        imageType=oformat_opt[0];
+      else
+        imageType=imgReader.getImageType();
+
+      // dataType=imgReader.getDataType(0);
+      if(verbose_opt[0]){
+        cout << "type of data for " << input_opt[ifile] << ": " << theType << endl;
+        cout << "nband: " << nband << endl;
+      }
+      
+      maxLRX=theLRX;
+      maxULY=theULY;
+      minULX=theULX;
+      minLRY=theLRY;
+      if(!dx||!dy){
+        dx=imgReader.getDeltaX();
+        dy=imgReader.getDeltaY();
+      }
+      // imgReader.getMagicPixel(magic_x,magic_y);
+      init=true;
+    }
+    else{
+      //convert bounding box to magic coordinates
+      //check uniformity magic pixel
+      // double test_x,test_y;
+      // imgReader.getMagicPixel(test_x,test_y);
+      // if(verbose_opt[0]){
+      //   cout << "magic_x, magic_y: " << magic_x << ", " << magic_y << endl;
+      // }
+      // assert(magic_x==test_x);
+      // assert(magic_y==test_y);
+      maxLRX=(theLRX>maxLRX)?theLRX:maxLRX;
+      maxULY=(theULY>maxULY)?theULY:maxULY;
+      minULX=(theULX<minULX)?theULX:minULX;
+      minLRY=(theLRY<minLRY)?theLRY:minLRY;
+    }
+    imgReader.close();
+  }
+  if(verbose_opt[0])
+    cout << "bounding box input images (ULX ULY LRX LRY): " << fixed << setprecision(6) << minULX << " " << maxULY << " " << maxLRX << " " << minLRY << endl;
+  if(ulx_opt[0]||uly_opt[0]||lrx_opt[0]||lry_opt[0]){
+    maxLRX=lrx_opt[0];
+    maxULY=uly_opt[0];
+    minULX=ulx_opt[0];
+    minLRY=lry_opt[0];
+  }
+  
+  if(projection_opt[0].find("ETRS-LAEA")!=string::npos||projection_opt[0].find("EPSG:3035")!=string::npos||projection_opt[0].find("epsg:3035")!=string::npos){
+    //force to LAEA grid
+    minULX=floor(minULX);
+    minULX-=static_cast<int>(minULX)%(static_cast<int>(dx));
+    maxULY=ceil(maxULY);
+    if(static_cast<int>(maxULY)%static_cast<int>(dy))
+      maxULY+=dy;
+    maxULY-=static_cast<int>(maxULY)%(static_cast<int>(dy));
+    maxLRX=ceil(maxLRX);
+    if(static_cast<int>(maxLRX)%static_cast<int>(dx))
+      maxLRX+=dx;
+    maxLRX-=static_cast<int>(maxLRX)%(static_cast<int>(dx));
+    minLRY=floor(minLRY);
+    minLRY-=static_cast<int>(minLRY)%(static_cast<int>(dy));
+  }
+
+  if(verbose_opt[0])
+    cout << "bounding box mosaic image (ULX ULY LRX LRY): " << fixed << setprecision(6) << minULX << " " << maxULY << " " << maxLRX << " " << minLRY << endl;
+  //initialize image
+  if(verbose_opt[0])
+    cout << "initializing mosaic image..." << endl;
+//   double dcol=(maxLRX-minULX+dx-1)/dx;
+//   double drow=(maxULY-minLRY+dy-1)/dy;
+//   int ncol=static_cast<int>(dcol);
+//   int nrow=static_cast<int>(drow);
+
+  int ncol=ceil((maxLRX-minULX)/dx);
+  int nrow=ceil((maxULY-minLRY)/dy);
+
+  if(verbose_opt[0])
+    cout << "mosaic image dim (nrow x ncol): " << nrow << " x " << ncol << endl;
+  ImgWriterGdal imgWriter;
+  while(weight_opt.size()<input_opt.size())
+    weight_opt.push_back(weight_opt[0]);
+  if(verbose_opt[0]){
+    std::cout << weight_opt << std::endl;
+  }
+  if(mrule_opt[0]==6){
+    nwriteBand=(file_opt[0])? class_opt.size()+1:class_opt.size();
+  }
+  else
+    nwriteBand=(file_opt[0])? bands.size()+1:bands.size();
+  if(verbose_opt[0])
+    cout << "open output image " << output_opt[0] << " with " << nwriteBand << " bands" << endl << flush;
+  try{
+    imgWriter.open(output_opt[0],ncol,nrow,nwriteBand,theType,imageType,option_opt);
+  }
+  catch(string error){
+    cout << error << endl;
+  }
+  if(description_opt[0]!="")
+    imgWriter.setImageDescription(description_opt[0]);
+  imgWriter.setGeoTransform(minULX,maxULY,dx,dy,0,0);
+  if(projection_opt[0]!=""){
+    if(verbose_opt[0])
+      cout << "projection: " << projection_opt[0] << endl;
+    imgWriter.setProjectionProj4(projection_opt[0]);
+  }
+  else if(theProjection!=""){
+    if(verbose_opt[0])
+      cout << "projection: " << theProjection << endl;
+    imgWriter.setProjection(theProjection);
+  }
+    
+  if(colorTable_opt[0]!=""){
+    assert(imgWriter.getDataType()==GDT_Byte);
+    imgWriter.setColorTable(colorTable_opt[0]);
+  }
+  else if(theColorTable)
+    imgWriter.setColorTable(theColorTable);
+
+  //create mosaic image
+  if(verbose_opt[0])
+     cout << "creating mosaic image" << endl;
+  Vector2d<double> writeBuffer(nband,imgWriter.nrOfCol());
+  vector<short> fileBuffer(ncol);//holds the number of used files
+  Vector2d<short> maxBuffer;//buffer used for maximum voting
+  Vector2d<double> readBuffer(nband);
+  Histogram hist;
+  if(mrule_opt[0]==1)//ndvi
+    assert(ruleBand_opt.size()==2);
+  if(mrule_opt[0]==6){//max voting
+    maxBuffer.resize(imgWriter.nrOfCol(),256);//use only byte images for max voting
+    for(int iclass=0;iclass<class_opt.size();++iclass)
+      assert(class_opt[iclass]<maxBuffer.size());
+  }
+  int jb=0;
+  double readRow=0;
+  double readCol=0;
+  double lowerCol=0;
+  double upperCol=0;
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  for(int irow=0;irow<imgWriter.nrOfRow();++irow){
+    Vector2d< vector<double> > storeBuffer;
+    vector<bool> writeValid(ncol);
+
+    if(mrule_opt[0]==5||mrule_opt[0]==7||mrule_opt[0]==8)//mean, median or (weighted) sum value
+      storeBuffer.resize(nband,ncol);
+    for(int icol=0;icol<imgWriter.nrOfCol();++icol){
+      writeValid[icol]=false;
+      fileBuffer[icol]=0;
+      if(mrule_opt[0]==6){//max voting
+        for(int iclass=0;iclass<256;++iclass)
+          maxBuffer[icol][iclass]=0;
+      }
+      else{
+        for(int iband=0;iband<nband;++iband)
+          writeBuffer[iband][icol]=flag_opt[0];
+      }
+    }
+    for(int ifile=0;ifile<input_opt.size();++ifile){
+      try{
+        imgReader.open(input_opt[ifile]);
+      }
+      catch(string error){
+        cout << error << endl;
+      }
+      // assert(imgReader.getDataType()==theType);
+      assert(imgReader.nrOfBand()>=nband);
+      if(!imgReader.covers(minULX,maxULY,maxLRX,minLRY)){
+        imgReader.close();
+        continue;
+      }
+      double uli,ulj,lri,lrj;
+      imgReader.geo2image(minULX+(magic_x-1.0)*imgReader.getDeltaX(),maxULY-(magic_y-1.0)*imgReader.getDeltaY(),uli,ulj);
+      imgReader.geo2image(maxLRX+(magic_x-2.0)*imgReader.getDeltaX(),minLRY-(magic_y-2.0)*imgReader.getDeltaY(),lri,lrj);
+      uli=floor(uli);
+      ulj=floor(ulj);
+      lri=floor(lri);
+      lrj=floor(lrj);
+        
+      double startCol=uli;
+      double endCol=lri;
+      if(uli<0)
+        startCol=0;
+      else if(uli>=imgReader.nrOfCol())
+        startCol=imgReader.nrOfCol()-1;
+      if(lri<0)
+        endCol=0;
+      else if(lri>=imgReader.nrOfCol())
+        endCol=imgReader.nrOfCol()-1;
+      int readncol=endCol-startCol+1;
+
+      //convert irow to geo
+      double x=0;
+      double y=0;
+      imgWriter.image2geo(0,irow,x,y);
+      //lookup corresponding row for irow in this file
+      imgReader.geo2image(x,y,readCol,readRow);
+      if(readRow<0||readRow>=imgReader.nrOfRow()){
+        imgReader.close();
+        continue;
+      }
+      // for(int iband=0;iband<imgReader.nrOfBand();++iband){
+      for(int iband=0;iband<nband;++iband){
+	int readBand=(band_opt[0]<0)?iband:band_opt[iband];
+        readBuffer[iband].resize(readncol);
+	try{
+          imgReader.readData(readBuffer[iband],GDT_Float64,startCol,endCol,readRow,readBand,theResample);
+	}
+	catch(string error){
+	  cerr << "error reading image " << input_opt[ifile] << ": " << endl;
+	  throw;
+	}
+      }
+        
+      for(int ib=0;ib<ncol;++ib){
+        assert(imgWriter.image2geo(ib,irow,x,y));
+        //lookup corresponding row for irow in this file
+        imgReader.geo2image(x,y,readCol,readRow);
+        if(readCol<0||readCol>=imgReader.nrOfCol())
+          continue;
+        double val_current=0;
+        double val_new=0;
+        bool readValid=true;
+        switch(resample_opt[0]){
+        case(BILINEAR):
+          lowerCol=readCol-0.5;
+          lowerCol=static_cast<int>(lowerCol);
+          upperCol=readCol+0.5;
+          upperCol=static_cast<int>(upperCol);
+          if(lowerCol<0)
+            lowerCol=0;
+          if(upperCol>=imgReader.nrOfCol())
+            upperCol=imgReader.nrOfCol()-1;
+          for(int vband=0;vband<validBand_opt.size();++vband){
+            val_new=(readCol-0.5-lowerCol)*readBuffer[validBand_opt[vband]][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[validBand_opt[vband]][lowerCol-startCol];
+            if(val_new<=minValue_opt[vband]||val_new>=maxValue_opt[vband]||val_new==invalid_opt[vband]){
+              readValid=false;
+              break;
+            }
+          }
+          break;
+        default:
+          readCol=static_cast<int>(readCol);
+          for(int vband=0;vband<validBand_opt.size();++vband){
+            val_new=readBuffer[validBand_opt[vband]][readCol-startCol];
+            if(val_new<=minValue_opt[vband]||val_new>=maxValue_opt[vband]||val_new==invalid_opt[vband]){
+              readValid=false;
+              break;
+            }
+          }
+          break;
+        }
+	if(readValid){
+          if(writeValid[ib]){
+            int iband=0;
+	    switch(mrule_opt[0]){
+	    case(1):{//max ndvi
+              double red_current=writeBuffer[ruleBand_opt[0]][ib];
+              double nir_current=writeBuffer[ruleBand_opt[1]][ib];
+	      double ndvi_current=0;
+              if(red_current+nir_current>0&&red_current>=0&&nir_current>=0)
+                ndvi_current=(nir_current-red_current)/(nir_current+red_current);
+	      double ndvi_new=0;
+              double red_new=0;
+              double nir_new=0;
+              switch(resample_opt[0]){
+              case(BILINEAR):
+                lowerCol=readCol-0.5;
+                lowerCol=static_cast<int>(lowerCol);
+                upperCol=readCol+0.5;
+                upperCol=static_cast<int>(upperCol);
+                if(lowerCol<0)
+                  lowerCol=0;
+                if(upperCol>=imgReader.nrOfCol())
+                  upperCol=imgReader.nrOfCol()-1;
+                red_new=(readCol-0.5-lowerCol)*readBuffer[ruleBand_opt[0]][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[ruleBand_opt[0]][lowerCol-startCol];
+                nir_new=(readCol-0.5-lowerCol)*readBuffer[ruleBand_opt[1]][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[ruleBand_opt[1]][lowerCol-startCol];
+                if(red_new+nir_new>0&&red_new>=0&&nir_new>=0)
+                  ndvi_new=(nir_new-red_new)/(nir_new+red_new);
+                if(ndvi_new>=ndvi_current){
+                  for(iband=0;iband<nband;++iband){
+                    val_new=(readCol-0.5-lowerCol)*readBuffer[iband][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[iband][lowerCol-startCol];
+                    writeBuffer[iband][ib]=val_new;
+                  }
+                  // fileBuffer[ib]=ifile;
+                  ++fileBuffer[ib];
+                }
+                break;
+              default:
+                readCol=static_cast<int>(readCol);
+                red_new=readBuffer[ruleBand_opt[0]][readCol-startCol];
+                nir_new=readBuffer[ruleBand_opt[1]][readCol-startCol];
+                if(red_new+nir_new>0&&red_new>=0&&nir_new>=0)
+                  ndvi_new=(nir_new-red_new)/(nir_new+red_new);
+                if(ndvi_new>=ndvi_current){
+                  for(iband=0;iband<nband;++iband){
+                    val_new=readBuffer[iband][readCol-startCol];
+                    writeBuffer[iband][ib]=val_new;
+                  }
+                  ++fileBuffer[ib];
+                  // fileBuffer[ib]=ifile;
+                }
+                break;
+              }
+	      break;
+            }
+	    case(2):
+            case(3):
+            case(4)://max,min,valid band
+              val_current=writeBuffer[ruleBand_opt[0]][ib];
+              switch(resample_opt[0]){
+              case(BILINEAR):
+                lowerCol=readCol-0.5;
+                lowerCol=static_cast<int>(lowerCol);
+                upperCol=readCol+0.5;
+                upperCol=static_cast<int>(upperCol);
+                if(lowerCol<0)
+                  lowerCol=0;
+                if(upperCol>=imgReader.nrOfCol())
+                  upperCol=imgReader.nrOfCol()-1;
+                val_new=(readCol-0.5-lowerCol)*readBuffer[ruleBand_opt[0]][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[ruleBand_opt[0]][lowerCol-startCol];
+                val_new*=weight_opt[ifile];
+                if((mrule_opt[0]==2&&val_new>val_current)||(mrule_opt[0]==3&&val_new<val_current)||(mrule_opt[0]==4)){//&&val_new>minValue_opt[0]&&val_new<maxValue_opt[0])){
+                  for(iband=0;iband<nband;++iband){
+                    val_new=(readCol-0.5-lowerCol)*readBuffer[iband][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[iband][lowerCol-startCol];
+                    val_new*=weight_opt[ifile];
+                    writeBuffer[iband][ib]=val_new;
+                  }
+                  // fileBuffer[ib]=ifile;
+                  ++fileBuffer[ib];
+                }
+                break;
+              default:
+                readCol=static_cast<int>(readCol);
+                val_new=readBuffer[ruleBand_opt[0]][readCol-startCol];
+                val_new*=weight_opt[ifile];
+                if((mrule_opt[0]==2&&val_new>val_current)||(mrule_opt[0]==3&&val_new<val_current)||(mrule_opt[0]==4)){//&&val_new>minValue_opt[0]&&val_new<maxValue_opt[0])){
+                  for(iband=0;iband<nband;++iband){
+                    val_new=readBuffer[iband][readCol-startCol];
+                    val_new*=weight_opt[ifile];
+                    writeBuffer[iband][ib]=val_new;
+                  }
+                  // fileBuffer[ib]=ifile;
+                  ++fileBuffer[ib];
+                }
+                break;
+              }
+	      break;
+            case(6)://max voting (only for Byte images)
+              switch(resample_opt[0]){
+              case(BILINEAR):
+                lowerCol=readCol-0.5;
+                lowerCol=static_cast<int>(lowerCol);
+                upperCol=readCol+0.5;
+                upperCol=static_cast<int>(upperCol);
+                if(lowerCol<0)
+                  lowerCol=0;
+                if(upperCol>=imgReader.nrOfCol())
+                  upperCol=imgReader.nrOfCol()-1;
+                for(iband=0;iband<nband;++iband){
+                  val_new=(readCol-0.5-lowerCol)*readBuffer[iband][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[iband][lowerCol-startCol];
+		  maxBuffer[ib][val_new]=maxBuffer[ib][val_new]+weight_opt[ifile];
+                  // ++(maxBuffer[ib][val_new]);
+                }
+                break;
+              default:
+                readCol=static_cast<int>(readCol);
+                for(iband=0;iband<nband;++iband){
+                  val_new=readBuffer[iband][readCol-startCol];
+		  maxBuffer[ib][val_new]=maxBuffer[ib][val_new]+weight_opt[ifile];
+		}
+                break;
+	      }
+              break;
+            case(5)://mean value
+	    case(7)://median value
+	    case(8)://sum value
+              switch(resample_opt[0]){
+              case(BILINEAR):
+                lowerCol=readCol-0.5;
+                lowerCol=static_cast<int>(lowerCol);
+                upperCol=readCol+0.5;
+                upperCol=static_cast<int>(upperCol);
+                if(lowerCol<0)
+                  lowerCol=0;
+                if(upperCol>=imgReader.nrOfCol())
+                  upperCol=imgReader.nrOfCol()-1;
+                for(iband=0;iband<nband;++iband){
+                  val_new=(readCol-0.5-lowerCol)*readBuffer[iband][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[iband][lowerCol-startCol];
+                  val_new*=weight_opt[ifile];
+                  storeBuffer[iband][ib].push_back(val_new);
+                }
+                break;
+              default:
+                readCol=static_cast<int>(readCol);
+                for(iband=0;iband<nband;++iband){
+                  val_new=readBuffer[iband][readCol-startCol];
+                  val_new*=weight_opt[ifile];
+                  storeBuffer[iband][ib].push_back(val_new);
+                  assert(ifile>0);
+                  assert(weight_opt[ifile]>=0);
+                  assert(storeBuffer[iband][ib].back()>=0);
+                }
+                break;
+              }
+              ++fileBuffer[ib];
+	      break;
+	    case(0):
+	    default:
+              switch(resample_opt[0]){
+              case(BILINEAR):
+                lowerCol=readCol-0.5;
+                lowerCol=static_cast<int>(lowerCol);
+                upperCol=readCol+0.5;
+                upperCol=static_cast<int>(upperCol);
+                if(lowerCol<0)
+                  lowerCol=0;
+                if(upperCol>=imgReader.nrOfCol())
+                  upperCol=imgReader.nrOfCol()-1;
+                for(iband=0;iband<nband;++iband){
+                  val_new=(readCol-0.5-lowerCol)*readBuffer[iband][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[iband][lowerCol-startCol];
+                  val_new*=weight_opt[ifile];
+                  writeBuffer[iband][ib]=val_new;
+                }
+                break;
+              default:
+                readCol=static_cast<int>(readCol);
+                for(iband=0;iband<nband;++iband){
+                  val_new=readBuffer[iband][readCol-startCol];
+                  val_new*=weight_opt[ifile];
+                  writeBuffer[iband][ib]=val_new;
+                }
+                break;
+              }
+            // fileBuffer[ib]=ifile;
+            ++fileBuffer[ib];
+            break;
+	    }
+          }
+	  else{
+            writeValid[ib]=true;//readValid was true
+            int iband=0;
+	    switch(mrule_opt[0]){
+            case(5):
+            case(7):
+            case(8):
+              switch(resample_opt[0]){
+              case(BILINEAR):
+                lowerCol=readCol-0.5;
+                lowerCol=static_cast<int>(lowerCol);
+                upperCol=readCol+0.5;
+                upperCol=static_cast<int>(upperCol);
+                if(lowerCol<0)
+                  lowerCol=0;
+                if(upperCol>=imgReader.nrOfCol())
+                  upperCol=imgReader.nrOfCol()-1;
+                for(iband=0;iband<nband;++iband){
+                  val_new=(readCol-0.5-lowerCol)*readBuffer[iband][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[iband][lowerCol-startCol];
+                  val_new*=weight_opt[ifile];
+                  storeBuffer[iband][ib].push_back(val_new);
+                }
+                break;
+              default:
+                readCol=static_cast<int>(readCol);
+                for(iband=0;iband<nband;++iband){
+                  val_new=readBuffer[iband][readCol-startCol];
+                  val_new*=weight_opt[ifile];
+                  storeBuffer[iband][ib].push_back(val_new);
+                }
+                break;
+              }
+              ++fileBuffer[ib];
+              break;
+            case(6):
+              switch(resample_opt[0]){
+              case(BILINEAR):
+                lowerCol=readCol-0.5;
+                lowerCol=static_cast<int>(lowerCol);
+                upperCol=readCol+0.5;
+                upperCol=static_cast<int>(upperCol);
+                if(lowerCol<0)
+                  lowerCol=0;
+                if(upperCol>=imgReader.nrOfCol())
+                  upperCol=imgReader.nrOfCol()-1;
+                for(iband=0;iband<nband;++iband){
+                  val_new=(readCol-0.5-lowerCol)*readBuffer[iband][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[iband][lowerCol-startCol];
+		  maxBuffer[ib][val_new]=maxBuffer[ib][val_new]+weight_opt[ifile];
+                  // ++(maxBuffer[ib][val_new]);
+		}
+                break;
+              default:
+                readCol=static_cast<int>(readCol);
+                for(iband=0;iband<nband;++iband){
+		  val_new=readBuffer[iband][readCol-startCol];
+		  maxBuffer[ib][val_new]=maxBuffer[ib][val_new]+weight_opt[ifile];
+		}
+                  // ++(maxBuffer[ib][val_new]);
+                break;
+              }
+              break;
+            default:
+              switch(resample_opt[0]){
+              case(BILINEAR):
+                lowerCol=readCol-0.5;
+                lowerCol=static_cast<int>(lowerCol);
+                upperCol=readCol+0.5;
+                upperCol=static_cast<int>(upperCol);
+                if(lowerCol<0)
+                  lowerCol=0;
+                if(upperCol>=imgReader.nrOfCol())
+                  upperCol=imgReader.nrOfCol()-1;
+                for(iband=0;iband<nband;++iband){
+                  val_new=(readCol-0.5-lowerCol)*readBuffer[iband][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[iband][lowerCol-startCol];
+                  val_new*=weight_opt[ifile];
+                  writeBuffer[iband][ib]=val_new;
+                }
+                break;
+              default:
+                readCol=static_cast<int>(readCol);
+                for(iband=0;iband<nband;++iband){
+                  val_new=readBuffer[iband][readCol-startCol];
+                  val_new*=weight_opt[ifile];
+                  writeBuffer[iband][ib]=val_new;
+                }
+                break;
+              }
+              // fileBuffer[ib]=ifile;
+              ++fileBuffer[ib];
+              break;
+            }
+          }
+        }
+      }
+      imgReader.close();
+    }
+    if(mrule_opt[0]==6){
+      vector<short> classBuffer(imgWriter.nrOfCol());
+      if(class_opt.size()>1){
+        for(int iclass=0;iclass<class_opt.size();++iclass){
+          for(int icol=0;icol<imgWriter.nrOfCol();++icol)
+            classBuffer[icol]=maxBuffer[icol][class_opt[iclass]];
+          try{
+            imgWriter.writeData(classBuffer,GDT_Int16,irow,iclass);
+          }
+          catch(string error){
+            cerr << "error writing image file " << output_opt[0] << ": " << error << endl;
+            throw;
+          }
+        }
+      }
+      else{
+        for(int icol=0;icol<imgWriter.nrOfCol();++icol){
+          vector<short>::iterator maxit=maxBuffer[icol].begin();
+          maxit=hist.max(maxBuffer[icol],maxBuffer[icol].begin(),maxBuffer[icol].end());
+          writeBuffer[0][icol]=distance(maxBuffer[icol].begin(),maxit);
+          fileBuffer[icol]=*(maxit);
+        }
+        try{
+          imgWriter.writeData(writeBuffer[0],GDT_Float64,irow,0);
+          if(file_opt[0])
+            imgWriter.writeData(fileBuffer,GDT_Int16,irow,1);
+        }
+        catch(string error){
+          cerr << "error writing image file " << output_opt[0] << ": " << error << endl;
+          throw;
+        }
+      }
+    }
+    else{
+      for(int iband=0;iband<bands.size();++iband){
+        // assert(writeBuffer[bands[iband]].size()==imgWriter.nrOfCol());
+        assert(writeBuffer[iband].size()==imgWriter.nrOfCol());
+        for(int icol=0;icol<imgWriter.nrOfCol();++icol){
+          switch(mrule_opt[0]){
+          case(5):
+            assert(storeBuffer[bands[iband]][icol].size()==fileBuffer[icol]);
+            if(storeBuffer[bands[iband]][icol].size())
+              writeBuffer[iband][icol]=hist.mean(storeBuffer[bands[iband]][icol]);
+            break;
+          case(7):
+            assert(storeBuffer[bands[iband]][icol].size()==fileBuffer[icol]);
+            if(storeBuffer[bands[iband]][icol].size())
+              writeBuffer[iband][icol]=hist.median(storeBuffer[bands[iband]][icol]);
+            break;
+          case(8)://sum
+            assert(storeBuffer[bands[iband]][icol].size()==fileBuffer[icol]);
+            if(storeBuffer[bands[iband]][icol].size())
+              writeBuffer[iband][icol]=hist.sum(storeBuffer[bands[iband]][icol]);
+            break;
+          default:
+            break;
+          }
+        }
+        try{
+          imgWriter.writeData(writeBuffer[iband],GDT_Float64,irow,iband);
+        }
+        catch(string error){
+          cerr << "error writing image file " << output_opt[0] << ": " << error << endl;
+          throw;
+        }
+      }
+      if(file_opt[0]){
+        try{
+          imgWriter.writeData(fileBuffer,GDT_Int16,irow,bands.size());
+        }
+        catch(string error){
+          cerr << "error writing image file " << output_opt[0] << ": " << error << endl;
+          throw;
+        }
+      }
+    }
+    progress=static_cast<float>(irow+1.0)/imgWriter.nrOfRow();
+    pfnProgress(progress,pszMessage,pProgressArg);
+  }
+  imgWriter.close();
+}
+  
diff --git a/src/apps/pkndvi.cc b/src/apps/pkndvi.cc
new file mode 100644
index 0000000..7dc0fb5
--- /dev/null
+++ b/src/apps/pkndvi.cc
@@ -0,0 +1,278 @@
+/**********************************************************************
+pkndvi.cc: program to calculate vegetation index image
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************/
+#include <assert.h>
+#include <vector>
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "base/Optionpk.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+  //command line options
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<string> input_opt("i","input","input image file","");
+  Optionpk<string> output_opt("o","output","output image file containing ndvi","");
+  Optionpk<short> band_opt("b", "band", "Bands to be used for vegetation index (see rule option)", 0);
+  Optionpk<string> rule_opt("r", "rule", "Rule for index. [ndvi (b1-b0)/(b1+b0)|gvmi (b0+0.1)-(b1+0.02))/((b0+0.1)+(b1+0.02)))|vari (b1-b2)/(b1+b2-b0)|diff (b1-b0)|scale. Default is 0 (ndvi)", "ndvi");
+  Optionpk<double> invalid_opt("t", "invalid", "Mask value where image is invalid. Default value is 0", 0);
+  Optionpk<int> flag_opt("f", "flag", "Flag value to put in image if not valid (0)", 0);
+  Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<string> description_opt("d", "description", "Set image description", "");
+  Optionpk<double> minmax_opt("m", "minmax", "minimum and maximum values for ndvi (limit all values smaller/larger to min/max (default 0)", 0);
+  Optionpk<double> eps_opt("e", "eps", "epsilon, contraint division by zero (default is 0)", 0);
+  Optionpk<double> scale_opt("s", "scale", "scale[0] is used for input, scale[1] is used for output: DN=scale[1]*ndvi+offset[1] (default is -s 1 -s 1)", 1);
+  Optionpk<double> offset_opt("\0", "offset", "offset[0] is used for input, offset[1] is used for output (see also scale option (default is --offset 0 --offset 0)", 0);
+  Optionpk<string> otype_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "Byte");
+  Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "GTiff");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<short> verbose_opt("v", "verbose", "verbose (default 0)", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  input_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  rule_opt.retrieveOption(argc,argv);
+  invalid_opt.retrieveOption(argc,argv);
+  flag_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  description_opt.retrieveOption(argc,argv);
+  minmax_opt.retrieveOption(argc,argv);
+  eps_opt.retrieveOption(argc,argv);
+  scale_opt.retrieveOption(argc,argv);
+  offset_opt.retrieveOption(argc,argv);
+  otype_opt.retrieveOption(argc,argv);
+  oformat_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  if(help_opt[0]){
+    cout << "usage: pkndvi -i inputimage -o outputimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  if(scale_opt.size()<2){
+    if(input_opt.size()<2)
+      scale_opt.push_back(1);
+    else
+      scale_opt.push_back(scale_opt[0]);
+  }
+  if(verbose_opt[0])
+    std::cout << scale_opt;
+  if(offset_opt.size()<2){
+    if(input_opt.size()<2)
+      offset_opt.push_back(0);
+    else
+      offset_opt.push_back(offset_opt[0]);
+  }
+  if(verbose_opt[0])
+    std::cout << offset_opt;
+  int reqBand=0;
+  if(rule_opt[0]=="scale")
+    reqBand=1;
+  else if(rule_opt[0]=="vari")
+    reqBand=3;
+  else
+    reqBand=2;
+  while(band_opt.size()<reqBand)
+    band_opt.push_back(band_opt[0]);
+  if(verbose_opt[0])
+    std::cout << band_opt;
+
+  //todo: a bit stupid to duplicate input reader, but it works
+  while(input_opt.size()<reqBand)
+    input_opt.push_back(input_opt[0]);
+  if(verbose_opt[0])
+    std::cout << input_opt;
+
+  vector<ImgReaderGdal> inputReader(reqBand);
+  for(int ifile=0;ifile<reqBand;++ifile){
+    inputReader[ifile].open(input_opt[ifile]);
+    assert(inputReader[ifile].nrOfBand()>band_opt[ifile]);
+  }
+
+  if(verbose_opt[0]){
+    cout << "opening output image file " << output_opt[0] << endl;
+    cout << "data type: " << otype_opt[0] << endl;
+  }
+  //create output image with user defined data type 
+  GDALDataType theType=GDT_Unknown;
+  if(verbose_opt[0])
+    cout << "possible output data types: ";
+  for(int iType = 0; iType < GDT_TypeCount; ++iType){
+    if(verbose_opt[0])
+      cout << " " << GDALGetDataTypeName((GDALDataType)iType);
+    if( GDALGetDataTypeName((GDALDataType)iType) != NULL
+	&& EQUAL(GDALGetDataTypeName((GDALDataType)iType),
+		 otype_opt[0].c_str()))
+      theType=(GDALDataType) iType;
+  }
+  if(theType==GDT_Unknown)
+    theType=inputReader[0].getDataType();
+  if(verbose_opt[0])
+    cout << endl << "Output pixel type:  " << GDALGetDataTypeName(theType) << endl;
+
+  ImgWriterGdal outputWriter;
+  if(verbose_opt[0])
+    cout << "opening output image file " << output_opt[0] << endl;
+  outputWriter.open(output_opt[0],inputReader[0].nrOfCol(),inputReader[0].nrOfRow(),1,theType,oformat_opt[0],option_opt);
+
+  if(description_opt[0]!="")
+      outputWriter.setImageDescription(description_opt[0]);
+  //if input image is georeferenced, copy projection info to output image
+  if(inputReader[0].isGeoRef()){
+    outputWriter.setProjection(inputReader[0].getProjection());
+    double ulx,uly,lrx,lry;
+    inputReader[0].getBoundingBox(ulx,uly,lrx,lry);
+    outputWriter.copyGeoTransform(inputReader[0]);
+  }
+  if(colorTable_opt[0]!=""){
+    if(colorTable_opt[0]!="none")
+      outputWriter.setColorTable(colorTable_opt[0]);
+  }
+  else if (inputReader[0].getColorTable()!=NULL)//copy colorTable from first input image
+    outputWriter.setColorTable(inputReader[0].getColorTable());
+  
+  Vector2d<double> lineInput(reqBand,inputReader[0].nrOfCol());
+  vector<double> lineOutput(outputWriter.nrOfCol());
+
+  int irow=0;
+  int icol=0;
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  float progress=0;
+  pfnProgress(progress,pszMessage,pProgressArg);
+  for(irow=0;irow<inputReader[0].nrOfRow();++irow){
+    //read line in lineInput buffer
+    try{
+      if(rule_opt[0]=="scale")
+        inputReader[0].readData(lineInput[0],GDT_Float64,irow,band_opt[0]);
+      else if(rule_opt[0]=="vari"){
+        inputReader[0].readData(lineInput[0],GDT_Float64,irow,band_opt[0]);
+        inputReader[1].readData(lineInput[1],GDT_Float64,irow,band_opt[1]);
+        inputReader[2].readData(lineInput[2],GDT_Float64,irow,band_opt[2]);
+      }
+      else{
+        inputReader[0].readData(lineInput[0],GDT_Float64,irow,band_opt[0]);
+        inputReader[1].readData(lineInput[1],GDT_Float64,irow,band_opt[1]);
+      }
+    }
+    catch(string errorstring){
+      cerr << errorstring << endl;
+      exit(1);
+    }
+    assert(invalid_opt.size()==flag_opt.size());
+    for(icol=0;icol<inputReader[0].nrOfCol();++icol){
+      double ndvi=minmax_opt[0];
+      double flagValue=flag_opt[0];
+      bool valid=true;
+      for(int iflag=0;valid&&iflag<invalid_opt.size();++iflag){
+        for(int iband=0;iband<lineInput.size();++iband){
+          if(lineInput[iband][icol]==invalid_opt[iflag]){
+            flagValue=flag_opt[iflag];
+            valid=false;
+            break;
+          }
+        }
+      }
+      double denom;
+      double nom;
+      if(valid){
+        if(rule_opt[0]=="ndvi"){
+          denom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
+          nom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]+(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
+        }
+        else if(rule_opt[0]=="gvmi"){
+          denom=((lineInput[0][icol]-offset_opt[0])/scale_opt[0]+0.1)-((lineInput[1][icol]-offset_opt[0])/scale_opt[0]+0.02);
+          nom=((lineInput[0][icol]-offset_opt[0])/scale_opt[0]+0.1)+((lineInput[1][icol]-offset_opt[0])/scale_opt[0]+0.02);
+        }
+        else if(rule_opt[0]=="vari"){
+          denom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-(lineInput[2][icol]-offset_opt[0])/scale_opt[0];
+          nom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]+(lineInput[2][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
+        }
+        else if(rule_opt[0]=="diff"){
+          denom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
+          nom=1.0;
+        }
+        else if(rule_opt[0]=="scale"){
+          denom=(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
+          nom=1.0;
+        }
+        else{
+          std::cout << "Error: rule " << rule_opt[0] << " not supported" << std::endl;
+          exit(1);
+        }
+        if(nom>eps_opt[0]||nom<-eps_opt[0])
+        ndvi=denom/nom;
+        if(ndvi<minmax_opt[0])
+          ndvi=minmax_opt[0];
+        else if(minmax_opt.size()>1){
+          if(ndvi>minmax_opt[1])
+            ndvi=minmax_opt[1];
+        }
+        switch(theType){
+        case(GDT_Byte):
+        case(GDT_Int16):
+        case(GDT_UInt16):
+        case(GDT_UInt32):
+        case(GDT_Int32):
+          lineOutput[icol]=static_cast<int>(0.5+ndvi*scale_opt[1]+offset_opt[1]);
+          break;
+        default:
+          lineOutput[icol]=ndvi*scale_opt[1]+offset_opt[1];
+        break;
+        }
+      }
+      else
+        lineOutput[icol]=flagValue;
+    }
+    //write buffer lineOutput to output file
+    try{
+      outputWriter.writeData(lineOutput,GDT_Float64,irow);
+    }
+    catch(string errorstring){
+      cerr << errorstring << endl;
+      exit(1);
+    }
+    //progress bar
+    progress=static_cast<float>(irow+1.0)/outputWriter.nrOfRow();
+    pfnProgress(progress,pszMessage,pProgressArg);
+  }
+  for(int ifile=0;ifile<inputReader.size();++ifile)
+    inputReader[ifile].close();
+  outputWriter.close();
+}
diff --git a/src/apps/pkpolygonize.cc b/src/apps/pkpolygonize.cc
new file mode 100644
index 0000000..036f05a
--- /dev/null
+++ b/src/apps/pkpolygonize.cc
@@ -0,0 +1,115 @@
+/**********************************************************************
+pkpolygonize.cc: program to make vector file from raster image
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "cpl_string.h"
+#include "gdal_priv.h"
+#include "gdal.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "imageclasses/ImgWriterOgr.h"
+#include "base/Optionpk.h"
+#include "ogrsf_frmts.h"
+extern "C" {
+#include "gdal_alg.h"
+#include "ogr_api.h"
+}
+
+using namespace std;
+
+int main(int argc,char **argv) {
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<string> input_opt("i", "input", "Input image file (WARNING: will be overwritten with output!", "");
+  Optionpk<string> mask_opt("m", "mask", "All pixels in the mask band with a value other than zero will be considered suitable for collection as polygons. Use input file as mask to remove background polygon! ", "");
+  Optionpk<string> output_opt("o", "output", "Output vector file", "");
+  Optionpk<int> band_opt("b", "band", "the band to be used from input file (default is 0)", 0);
+  Optionpk<string> fname_opt("n", "name", "the field name of the output layer (default is DN)", "DN");
+  Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+
+  input_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  fname_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  GDALAllRegister();
+
+  double dfComplete=0.0;
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  pfnProgress(dfComplete,pszMessage,pProgressArg);
+  
+
+  ImgReaderGdal maskReader;
+  GDALRasterBand *maskBand=NULL;
+  if(mask_opt[0]!=""){
+    if(verbose_opt[0])
+      cout << "opening mask file " << mask_opt[0] << endl;
+    maskReader.open(mask_opt[0]);
+    maskBand = maskReader.getRasterBand(0);
+  }
+
+  ImgReaderGdal inputReader(input_opt[0]);
+  GDALRasterBand  *inputBand;
+  inputBand=inputReader.getRasterBand(0);
+
+  ImgWriterOgr ogrWriter(output_opt[0]);
+  OGRLayer* theLayer=ogrWriter.createLayer(output_opt[0].substr(output_opt[0].rfind('/')+1), inputReader.getProjectionRef());
+  if(verbose_opt[0])
+    cout << "projection: " << inputReader.getProjection() << endl;
+  ogrWriter.createField(fname_opt[0],OFTInteger);
+
+  OGRLayerH hOutLayer=(OGRLayerH)ogrWriter.getLayer();
+  if(verbose_opt[0])
+    cout << "GDALPolygonize started..." << endl;
+
+  int index=theLayer->GetLayerDefn()->GetFieldIndex(fname_opt[0].c_str());
+  if(GDALPolygonize((GDALRasterBandH)inputBand, (GDALRasterBandH)maskBand, hOutLayer,index,NULL,pfnProgress,pProgressArg)!=CE_None)
+    cerr << CPLGetLastErrorMsg() << endl;
+  else{
+    dfComplete=1.0;
+    pfnProgress(dfComplete,pszMessage,pProgressArg);
+  }
+  cout << "number of features: " << OGR_L_GetFeatureCount(hOutLayer,TRUE) << endl;
+  
+  inputReader.close();
+  if(mask_opt[0]!="")
+    maskReader.close();
+  ogrWriter.close();
+}
+
diff --git a/src/apps/pkreclass.cc b/src/apps/pkreclass.cc
new file mode 100644
index 0000000..9d7f569
--- /dev/null
+++ b/src/apps/pkreclass.cc
@@ -0,0 +1,368 @@
+/**********************************************************************
+pkreclass.cc: program to replace pixel values in raster image
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <assert.h>
+#include <map>
+#include "base/Optionpk.h"
+#include "imageclasses/ImgReaderOgr.h"
+#include "imageclasses/ImgWriterOgr.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+  //command line options
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","",false);
+  Optionpk<string>  input_opt("i", "input", "Input image", "");
+  Optionpk<string>  mask_opt("m", "mask", "Mask image(s)", "");
+  Optionpk<string> output_opt("o", "output", "Output mask file", "");
+  Optionpk<unsigned short> invalid_opt("t", "invalid", "Mask value(s) where image is invalid. Use one value for each mask, or multiple values for a single mask. Default value is 1", 1);
+  Optionpk<int> flag_opt("f", "flag", "Flag value to put in image if not valid (0)", 0);
+  Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<unsigned short>  band_opt("b", "band", "band index to replace (other bands are copied to output)", 0);
+  Optionpk<string> type_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "");
+  Optionpk<string> code_opt("\0", "code", "Recode text file (2 colums: from to)", "");
+  Optionpk<string> class_opt("c", "class", "list of classes to reclass (in combination with reclass option)", "");
+  Optionpk<string> reclass_opt("r", "reclass", "list of recoded class(es) (in combination with class option)", "");
+  Optionpk<string> label_opt("l", "label", "Label name of the shape file to be replaced (default: label)", "label");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
+  Optionpk<string> description_opt("d", "description", "Set image description", "");
+  Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  input_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  invalid_opt.retrieveOption(argc,argv);
+  flag_opt.retrieveOption(argc,argv);
+  code_opt.retrieveOption(argc,argv);
+  class_opt.retrieveOption(argc,argv);
+  reclass_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  type_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  label_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  description_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << "usage: pkreclass -i inputimage -o outputimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  // vector<short> bandVector;
+  // for(int iband=0;iband<band_opt.size();++iband)
+  //   bandVector.push_back(band_opt[iband]);
+  map<string,string> codemapString;//map with codes: codemapString[theKey(from)]=theValue(to)
+  map<double,double> codemap;//map with codes: codemap[theKey(from)]=theValue(to)
+  if(code_opt[0]!=""){
+    if(verbose_opt[0])
+      cout << "opening code text file " << code_opt[0] << endl;
+    ifstream codefile;
+    codefile.open(code_opt[0].c_str());
+    string theKey;
+    string theValue;
+    while(codefile>>theKey){
+      codefile >> theValue;
+      codemapString[theKey]=theValue;
+      codemap[string2type<double>(theKey)]=string2type<double>(theValue);
+    }
+    codefile.close();
+  }
+  else{//use combination of class_opt and reclass_opt
+    assert(class_opt.size()==reclass_opt.size());
+    for(int iclass=0;iclass<class_opt.size();++iclass){
+      codemapString[class_opt[iclass]]=reclass_opt[iclass];
+      codemap[string2type<double>(class_opt[iclass])]=string2type<double>(reclass_opt[iclass]);
+    }
+  }
+  assert(codemapString.size());
+  assert(codemap.size());
+  //if verbose true, print the codes to screen
+  if(verbose_opt[0]){
+    map<string,string>::iterator mit;
+    cout << codemapString.size() << " codes used: " << endl;
+    for(mit=codemapString.begin();mit!=codemapString.end();++mit)
+      cout << (*mit).first << " " << (*mit).second << endl;
+  }
+  if(input_opt[0].find(".shp")!=string::npos){//shape file
+    if(verbose_opt[0])
+      cout << "opening " << input_opt[0] << " for reading " << endl;
+    ImgReaderOgr ogrReader(input_opt[0]);
+    if(verbose_opt[0])
+      cout << "opening " << output_opt[0] << " for writing " << endl;
+    ImgWriterOgr ogrWriter(output_opt[0],ogrReader);
+    if(verbose_opt[0])
+      cout << "copied layer from " << input_opt[0] << endl << flush;
+    OGRFeatureDefn *poFDefn = ogrWriter.getLayer()->GetLayerDefn();
+    //start reading features from the layer
+    if(verbose_opt[0])
+      cout << "reset reading" << endl;
+    ogrReader.getLayer()->ResetReading();
+    unsigned long int ifeature=0;
+    if(verbose_opt[0])
+      cout << "going through features" << endl << flush;
+    while(true){
+//     while( (poFeature = ogrWriter.getLayer()->GetNextFeature()) != NULL ){
+      OGRFeature *poFeature;
+      poFeature=ogrReader.getLayer()->GetNextFeature();
+      if(poFeature== NULL)
+        break;
+      OGRFeatureDefn *poFDefn = ogrWriter.getLayer()->GetLayerDefn();
+      string featurename;
+      for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+        OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+        string fieldname=poFieldDefn->GetNameRef();
+        if(fieldname==label_opt[0]){
+          string fromClass=poFeature->GetFieldAsString(iField);
+          string toClass=fromClass;
+          if(codemapString.find(fromClass)!=codemapString.end())
+            toClass=codemapString[fromClass];
+          poFeature->SetField(iField,toClass.c_str());
+          if(verbose_opt[0])
+            cout << "feature " << ifeature << ": " << fromClass << "->" << poFeature->GetFieldAsInteger(iField) << endl << flush;
+//             cout << "feature " << ifeature << ": " << fromClass << "->" << toClass << endl << flush;
+        }
+      }
+      //do not forget to actually write feature to file!!!
+      ogrWriter.createFeature(poFeature);
+      OGRFeature::DestroyFeature( poFeature );
+      ++ifeature;
+    }
+    if(verbose_opt[0])
+       cout << "replaced " << ifeature << " features" << endl;
+    ogrReader.close();
+    ogrWriter.close();
+  }
+  else{//image file
+    ImgReaderGdal inputReader;
+    vector<ImgReaderGdal> maskReader(mask_opt.size()); 
+    ImgWriterGdal outputWriter;
+    if(verbose_opt[0])
+      cout << "opening input image file " << input_opt[0] << endl;
+    inputReader.open(input_opt[0]);
+    for(int imask=0;imask<mask_opt.size();++imask){
+      if(mask_opt[imask]!=""){
+        if(verbose_opt[0])
+          cout << "opening mask image file " << mask_opt[imask] << endl;
+        maskReader[imask].open(mask_opt[imask]);
+      }
+    }
+    if(verbose_opt[0]){
+      cout << "opening output image file " << output_opt[0] << endl;
+      cout << "data type: " << type_opt[0] << endl;
+    }
+    //create output image with user defined data type 
+    GDALDataType theType=GDT_Unknown;
+    if(verbose_opt[0])
+      cout << "possible output data types: ";
+    for(int iType = 0; iType < GDT_TypeCount; ++iType){
+      if(verbose_opt[0])
+        cout << " " << GDALGetDataTypeName((GDALDataType)iType);
+      if( GDALGetDataTypeName((GDALDataType)iType) != NULL
+          && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
+                   type_opt[0].c_str()))
+        theType=(GDALDataType) iType;
+    }
+    if(theType==GDT_Unknown)
+      theType=inputReader.getDataType();
+    if(verbose_opt[0])
+      cout << endl << "Output pixel type:  " << GDALGetDataTypeName(theType) << endl;
+    outputWriter.open(output_opt[0],inputReader.nrOfCol(),inputReader.nrOfRow(),inputReader.nrOfBand(),theType,inputReader.getImageType(),option_opt);
+    if(description_opt[0]!="")
+      outputWriter.setImageDescription(description_opt[0]);
+
+    if(colorTable_opt[0]!=""){
+      if(colorTable_opt[0]!="none")
+        outputWriter.setColorTable(colorTable_opt[0]);
+    }
+    else if (inputReader.getColorTable()!=NULL)//copy colorTable from input image
+      outputWriter.setColorTable(inputReader.getColorTable());
+    
+    //if input image is georeferenced, copy projection info to output image
+    if(inputReader.isGeoRef()){
+      for(int imask=0;imask<mask_opt.size();++imask)
+        if(mask_opt[imask]!="")
+          assert(maskReader[imask].isGeoRef());
+      outputWriter.setProjection(inputReader.getProjection());
+    }
+    else{
+      for(int imask=0;imask<mask_opt.size();++imask){
+        if(mask_opt[imask]!=""){
+          assert(maskReader[imask].nrOfCol()==inputReader.nrOfCol());
+          assert(maskReader[imask].nrOfRow()==inputReader.nrOfRow());
+        }
+      }
+    }
+    double ulx,uly,lrx,lry;
+    inputReader.getBoundingBox(ulx,uly,lrx,lry);
+    outputWriter.copyGeoTransform(inputReader);
+    assert(flag_opt.size()==invalid_opt.size());
+    if(verbose_opt[0]&&mask_opt[0]!=""){
+      for(int iv=0;iv<invalid_opt.size();++iv)
+        cout << invalid_opt[iv] << "->" << flag_opt[iv] << endl;
+    }
+
+    assert(outputWriter.nrOfCol()==inputReader.nrOfCol());
+    // Vector2d<int> lineInput(inputReader.nrOfBand(),inputReader.nrOfCol());
+    Vector2d<double> lineInput(inputReader.nrOfBand(),inputReader.nrOfCol());
+    Vector2d<short> lineMask(mask_opt.size());
+    for(int imask=0;imask<mask_opt.size();++imask)
+      if(mask_opt[imask]!="")
+        lineMask[imask].resize(maskReader[imask].nrOfCol());
+    Vector2d<double> lineOutput(outputWriter.nrOfBand(),outputWriter.nrOfCol());
+    int irow=0;
+    int icol=0;
+    const char* pszMessage;
+    void* pProgressArg=NULL;
+    GDALProgressFunc pfnProgress=GDALTermProgress;
+    double progress=0;
+    pfnProgress(progress,pszMessage,pProgressArg);
+    double oldRowMask=-1;
+    for(irow=0;irow<inputReader.nrOfRow();++irow){
+      //read line in lineInput buffer
+      for(int iband=0;iband<inputReader.nrOfBand();++iband){
+        try{
+          // inputReader.readData(lineInput[iband],GDT_Int32,irow,iband);
+          inputReader.readData(lineInput[iband],GDT_Float64,irow,iband);
+        }
+        catch(string errorstring){
+          cerr << errorstring << endl;
+          exit(1);
+        }
+      }
+      double x,y;//geo coordinates
+      double colMask,rowMask;//image coordinates in mask image
+      for(icol=0;icol<inputReader.nrOfCol();++icol){
+        bool masked=false;
+        if(mask_opt.size()>1){//multiple masks
+          for(int imask=0;imask<mask_opt.size();++imask){
+            if(mask_opt[imask]=="")
+              continue;
+            if(maskReader[imask].isGeoRef()){
+              inputReader.image2geo(icol,irow,x,y);
+              maskReader[imask].geo2image(x,y,colMask,rowMask);
+            }
+            else{
+              colMask=icol;
+              rowMask=irow;
+            }
+            if(static_cast<int>(rowMask)!=static_cast<int>(oldRowMask)){
+              assert(rowMask>=0&&rowMask<maskReader[imask].nrOfRow());
+              try{
+                maskReader[imask].readData(lineMask[imask],GDT_Int16,static_cast<int>(rowMask));
+              }
+              catch(string errorstring){
+                cerr << errorstring << endl;
+                exit(1);
+              }
+              oldRowMask=rowMask;
+            }
+            short ivalue=0;
+            if(mask_opt.size()==invalid_opt.size())//one invalid value for each mask
+              ivalue=invalid_opt[imask];
+            else//use same invalid value for each mask
+              ivalue=invalid_opt[0];
+            if(lineMask[imask][colMask]==ivalue){
+              for(int iband=0;iband<inputReader.nrOfBand();++iband)
+                lineInput[iband][icol]=flag_opt[imask];
+              masked=true;
+              break;
+            }
+          }
+        }
+        else if(mask_opt[0]!=""){//potentially more invalid values for single mask
+          if(maskReader[0].isGeoRef()){
+            inputReader.image2geo(icol,irow,x,y);
+            maskReader[0].geo2image(x,y,colMask,rowMask);
+          }
+          else{
+            colMask=icol;
+            rowMask=irow;
+          }
+          if(static_cast<int>(rowMask)!=static_cast<int>(oldRowMask)){
+            assert(rowMask>=0&&rowMask<maskReader[0].nrOfRow());
+            try{
+              maskReader[0].readData(lineMask[0],GDT_Int16,static_cast<int>(rowMask));
+            }
+            catch(string errorstring){
+              cerr << errorstring << endl;
+              exit(1);
+            }
+            oldRowMask=rowMask;
+          }
+          for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
+            assert(invalid_opt.size()==flag_opt.size());
+            if(lineMask[0][colMask]==invalid_opt[ivalue]){
+              for(int iband=0;iband<inputReader.nrOfBand();++iband)
+                lineInput[iband][icol]=flag_opt[ivalue];
+              masked=true;
+              break;
+            }
+          }
+        }
+        for(int iband=0;iband<lineOutput.size();++iband){
+          lineOutput[iband][icol]=lineInput[iband][icol];
+          if(find(band_opt.begin(),band_opt.end(),iband)!=band_opt.end()){
+            if(!masked && codemap.find(lineInput[iband][icol])!=codemap.end()){
+              double toValue=codemap[lineInput[iband][icol]];
+	      lineOutput[iband][icol]=toValue;
+	    }
+	  }
+        }
+      }
+      //write buffer lineOutput to output file
+      try{
+        for(int iband=0;iband<outputWriter.nrOfBand();++iband)
+          outputWriter.writeData(lineOutput[iband],GDT_Float64,irow,iband);
+      }
+      catch(string errorstring){
+        cerr << errorstring << endl;
+        exit(1);
+      }
+      //progress bar
+      progress=static_cast<float>((irow+1.0)/outputWriter.nrOfRow());
+      pfnProgress(progress,pszMessage,pProgressArg);
+    }
+    inputReader.close();
+    outputWriter.close();
+  }
+}
diff --git a/src/apps/pksetmask.cc b/src/apps/pksetmask.cc
new file mode 100644
index 0000000..39b573c
--- /dev/null
+++ b/src/apps/pksetmask.cc
@@ -0,0 +1,338 @@
+/**********************************************************************
+pksetmask.cc: program to apply mask image (set invalid values) to raster image
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <assert.h>
+
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "base/Optionpk.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+  //command line options
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","",false);
+  Optionpk<string>  input_opt("i", "input", "Input image", "");
+  Optionpk<string>  mask_opt("m", "mask", "Mask image(s)", "");
+  Optionpk<string> output_opt("o", "output", "Output mask file", "");
+  Optionpk<string>  otype_opt("ot", "otype", "Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image", "");
+  Optionpk<string>  oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "");
+  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "");
+  Optionpk<unsigned short> invalid_opt("t", "invalid", "Mask value(s) where image is invalid. Use one value for each mask, or multiple values for a single mask. Default value is 1", 1);
+  Optionpk<char> operator_opt("p", "operator", "Operator: < = > !. Use operator for each invalid option (default is =)", '=');
+  Optionpk<int> flag_opt("f", "flag", "Flag value to put in image if not valid (0)", 0);
+  Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    cout << "todo: " << todo_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  input_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  otype_opt.retrieveOption(argc,argv);
+  oformat_opt.retrieveOption(argc,argv);
+  option_opt.retrieveOption(argc,argv);
+  invalid_opt.retrieveOption(argc,argv);
+  operator_opt.retrieveOption(argc,argv);
+  flag_opt.retrieveOption(argc,argv);
+  colorTable_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(help_opt[0]){
+    cout << "usage: pksetmask -i inputimage -o outputimage -m maskimage [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  if(verbose_opt[0])
+     cout << "number of mask images: " << mask_opt.size() << endl;
+  vector<ImgReaderGdal> maskReader(mask_opt.size()); 
+  for(int imask=0;imask<mask_opt.size();++imask){
+    assert(mask_opt[imask]!="");
+    if(verbose_opt[0])
+      cout << "opening mask image file " << mask_opt[imask] << endl;
+    maskReader[imask].open(mask_opt[imask]);
+  }
+  if(verbose_opt[0])
+    cout << "opening input image file " << input_opt[0] << endl;
+  ImgReaderGdal inputReader;
+  inputReader.open(input_opt[0]);
+  string imageType=inputReader.getImageType();
+  if(oformat_opt[0]!="")//default
+    imageType=oformat_opt[0];
+  GDALDataType theType=GDT_Unknown;
+  if(verbose_opt[0]){
+    std::cout << "Image type: " << imageType << std::endl;
+    std::cout << "possible output data types: ";
+  }
+  for(int iType = 0; iType < GDT_TypeCount; ++iType){
+    if(verbose_opt[0])
+      cout << " " << GDALGetDataTypeName((GDALDataType)iType);
+    if( GDALGetDataTypeName((GDALDataType)iType) != NULL
+        && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
+                 otype_opt[0].c_str()))
+      theType=(GDALDataType) iType;
+  }
+  if(theType==GDT_Unknown)
+    theType=inputReader.getDataType();
+
+  if(verbose_opt[0]){
+    std::cout << std::endl << "Output data type:  " << GDALGetDataTypeName(theType) << std::endl;
+    std::cout << "opening output image for writing: " << output_opt[0] << std::endl;
+  }
+  ImgWriterGdal outputWriter;
+  try{
+    outputWriter.open(output_opt[0],inputReader.nrOfCol(),inputReader.nrOfRow(),inputReader.nrOfBand(),theType,imageType,option_opt);
+    outputWriter.setProjection(inputReader.getProjection());
+    outputWriter.copyGeoTransform(inputReader);
+  }
+  catch(string errorstring){
+    cout << errorstring << endl;
+    exit(1);
+  }
+  // if(verbose_opt[0])
+  //   cout << "opening output image file " << output_opt[0] << endl;
+  // outputWriter.open(output_opt[0],inputReader);
+  if(colorTable_opt[0]!=""){
+    if(colorTable_opt[0]!="none")
+      outputWriter.setColorTable(colorTable_opt[0]);
+  }
+  else if (inputReader.getColorTable()!=NULL)//copy colorTable from input image
+    outputWriter.setColorTable(inputReader.getColorTable());
+  if(inputReader.isGeoRef()){
+    for(int imask=0;imask<mask_opt.size();++imask)
+      assert(maskReader[imask].isGeoRef());
+  }
+  else{
+    for(int imask=0;imask<mask_opt.size();++imask){
+      assert(maskReader[imask].nrOfCol()==inputReader.nrOfCol());
+      assert(maskReader[imask].nrOfRow()==inputReader.nrOfRow());
+    }
+  }
+  assert(flag_opt.size()==invalid_opt.size());
+  assert(operator_opt.size()==invalid_opt.size()||operator_opt.size()==1);
+  if(verbose_opt[0]){
+    cout << " mask files selected: " << mask_opt.size() << endl;
+    for(int iv=0;iv<invalid_opt.size();++iv){
+      char op=(operator_opt.size()==invalid_opt.size())?operator_opt[iv]:operator_opt[0];
+      cout << op << " " << invalid_opt[iv] << "->" << flag_opt[iv] << endl;
+    }
+  }
+  
+  Vector2d<double> lineInput(inputReader.nrOfBand(),inputReader.nrOfCol());
+  Vector2d<double> lineOutput(outputWriter.nrOfBand(),outputWriter.nrOfCol());
+  assert(lineOutput.size()==lineInput.size());
+  assert(inputReader.nrOfCol()==outputWriter.nrOfCol());
+  // Vector2d<int> lineMask(mask_opt.size());
+  Vector2d<double> lineMask(mask_opt.size());
+  for(int imask=0;imask<mask_opt.size();++imask){
+    if(verbose_opt[0])
+      cout << "mask " << imask << " has " << maskReader[imask].nrOfCol() << " columns and " << maskReader[imask].nrOfRow() << " rows" << endl;
+    lineMask[imask].resize(maskReader[imask].nrOfCol());
+  }
+  int irow=0;
+  int icol=0;
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  float progress=0;
+  if(!verbose_opt[0])
+    pfnProgress(progress,pszMessage,pProgressArg);
+  // double oldRowMask=-1;
+  vector<double> oldRowMask(mask_opt.size());
+  for(int imask=0;imask<mask_opt.size();++imask)
+    oldRowMask[imask]=-1;
+  for(irow=0;irow<inputReader.nrOfRow();++irow){
+    //read line in lineInput buffer
+    for(int iband=0;iband<inputReader.nrOfBand();++iband){
+      try{
+        inputReader.readData(lineInput[iband],GDT_Float64,irow,iband);
+      }
+      catch(string errorstring){
+        cerr << errorstring << endl;
+        exit(1);
+      }
+    }
+    double x,y;//geo coordinates
+    double colMask,rowMask;//image coordinates in mask image
+    for(icol=0;icol<inputReader.nrOfCol();++icol){
+      if(mask_opt.size()>1){//multiple masks
+        for(int imask=0;imask<mask_opt.size();++imask){
+          if(maskReader[imask].isGeoRef()){
+            inputReader.image2geo(icol,irow,x,y);
+            maskReader[imask].geo2image(x,y,colMask,rowMask);
+            colMask=static_cast<int>(colMask);
+            rowMask=static_cast<int>(rowMask);
+          }
+          else{
+            colMask=icol;
+            rowMask=irow;
+          }
+          bool masked=false;
+          if(rowMask>=0&&rowMask<maskReader[imask].nrOfRow()&&colMask>=0&&colMask<maskReader[imask].nrOfCol()){
+	    if(static_cast<int>(rowMask)!=static_cast<int>(oldRowMask[imask])){
+	      assert(rowMask>=0&&rowMask<maskReader[imask].nrOfRow());
+	      try{
+		// maskReader[imask].readData(lineMask[imask],GDT_Int32,static_cast<int>(rowMask));
+		maskReader[imask].readData(lineMask[imask],GDT_Float64,static_cast<int>(rowMask));
+	      }
+	      catch(string errorstring){
+		cerr << errorstring << endl;
+		exit(1);
+	      }
+	      oldRowMask[imask]=rowMask;
+	    }
+	  }
+          else
+            continue;//no coverage in this mask
+	  int ivalue=0;
+	  if(mask_opt.size()==invalid_opt.size())//one invalid value for each mask
+	    ivalue=invalid_opt[imask];
+	  else//use same invalid value for each mask
+	    ivalue=invalid_opt[0];
+	  char op=(operator_opt.size()==mask_opt.size())?operator_opt[imask]:operator_opt[0];
+	  switch(op){
+	  case('='):
+	  default:
+	    if(lineMask[imask][colMask]==ivalue)
+	      masked=true;
+	  break;
+	  case('<'):
+	    if(lineMask[imask][colMask]<ivalue)
+	      masked=true;
+	    break;
+	  case('>'):
+	    if(lineMask[imask][colMask]>ivalue)
+	      masked=true;
+	    break;
+	  case('!'):
+	    if(lineMask[imask][colMask]!=ivalue)
+	      masked=true;
+	    break;
+	  }
+	  if(masked){
+            if(verbose_opt[0]>1)
+              cout << "image masked at (col=" << icol << ",row=" << irow <<") with mask " << mask_opt[imask] << " and value " << ivalue << endl;
+	    for(int iband=0;iband<inputReader.nrOfBand();++iband){
+              if(mask_opt.size()==flag_opt.size())//one flag value for each mask
+                lineInput[iband][icol]=flag_opt[imask];
+              else                
+                lineInput[iband][icol]=flag_opt[0];
+            }
+            masked=false;
+	    break;
+	  }
+        }
+      }
+      else{//potentially more invalid values for single mask
+        if(maskReader[0].isGeoRef()){
+          inputReader.image2geo(icol,irow,x,y);
+          maskReader[0].geo2image(x,y,colMask,rowMask);
+          colMask=static_cast<int>(colMask);
+          rowMask=static_cast<int>(rowMask);
+        }
+        else{
+          colMask=icol;
+          rowMask=irow;
+        }
+        bool masked=false;
+        if(rowMask>=0&&rowMask<maskReader[0].nrOfRow()&&colMask>=0&&colMask<maskReader[0].nrOfCol()){
+          if(static_cast<int>(rowMask)!=static_cast<int>(oldRowMask[0])){
+            assert(rowMask>=0&&rowMask<maskReader[0].nrOfRow());
+            try{
+              // maskReader[0].readData(lineMask[0],GDT_Int32,static_cast<int>(rowMask));
+              maskReader[0].readData(lineMask[0],GDT_Float64,static_cast<int>(rowMask));
+	    }
+            catch(string errorstring){
+              cerr << errorstring << endl;
+              exit(1);
+	    }
+            oldRowMask[0]=rowMask;
+	  }
+          for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
+            assert(invalid_opt.size()==flag_opt.size());
+            char op=(operator_opt.size()==invalid_opt.size())?operator_opt[ivalue]:operator_opt[0];
+            switch(op){
+            case('='):
+            default:
+              if(lineMask[0][colMask]==invalid_opt[ivalue])
+                masked=true;
+              break;
+            case('<'):
+              if(lineMask[0][colMask]<invalid_opt[ivalue])
+                masked=true;
+              break;
+            case('>'):
+              if(lineMask[0][colMask]>invalid_opt[ivalue])
+                masked=true;
+              break;
+            case('!'):
+              if(lineMask[0][colMask]!=invalid_opt[ivalue])
+                masked=true;
+              break;
+            }
+            if(masked){
+              for(int iband=0;iband<inputReader.nrOfBand();++iband)
+                lineInput[iband][icol]=flag_opt[ivalue];
+              masked=false;
+              break;
+            }
+          }
+	}
+      }
+      for(int iband=0;iband<lineOutput.size();++iband)
+        lineOutput[iband][icol]=lineInput[iband][icol];
+    }
+    //write buffer lineOutput to output file
+    for(int iband=0;iband<outputWriter.nrOfBand();++iband){
+      try{
+        outputWriter.writeData(lineOutput[iband],GDT_Float64,irow,iband);
+      }
+      catch(string errorstring){
+        cerr << errorstring << endl;
+        exit(1);
+      }
+    }
+    //progress bar
+    progress=static_cast<float>(irow+1.0)/outputWriter.nrOfRow();
+    pfnProgress(progress,pszMessage,pProgressArg);
+  }
+  inputReader.close();
+  for(int imask=0;imask<mask_opt.size();++imask)
+    maskReader[imask].close();
+  outputWriter.close();
+}
diff --git a/src/apps/pksieve.cc b/src/apps/pksieve.cc
new file mode 100644
index 0000000..e49f1c6
--- /dev/null
+++ b/src/apps/pksieve.cc
@@ -0,0 +1,116 @@
+/**********************************************************************
+pksieve.cc: program to sieve filter raster image
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "cpl_string.h"
+#include "gdal_priv.h"
+#include "gdal.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+#include "imageclasses/ImgWriterOgr.h"
+#include "base/Optionpk.h"
+#include "ogrsf_frmts.h"
+extern "C" {
+#include "gdal_alg.h"
+#include "ogr_api.h"
+}
+
+using namespace std;
+
+int main(int argc,char **argv) {
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<string> input_opt("i", "input", "Input image file", "");
+  Optionpk<string> mask_opt("m", "mask", "Mask band indicating pixels to be interpolated (zero valued) ", "");
+  Optionpk<string> output_opt("o", "output", "Output image file", "");
+  Optionpk<int> band_opt("b", "band", "the band to be used from input file (default is 0)", 0);
+  Optionpk<int> connect_opt("c", "connect", "the connectedness: 4 directions or 8 directions (default: 8))", 8);
+  Optionpk<int> size_opt("s", "size", "raster polygons with sizes smaller than this will be merged into their largest neighbour (default: 0 no sieve filter is performed)", 0);
+  Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+
+  input_opt.retrieveOption(argc,argv);
+  input_opt.retrieveOption(argc,argv);
+  mask_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  band_opt.retrieveOption(argc,argv);
+  connect_opt.retrieveOption(argc,argv);
+  size_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  GDALAllRegister();
+
+  double dfComplete=0.0;
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  pfnProgress(dfComplete,pszMessage,pProgressArg);
+  
+  ImgReaderGdal maskReader;
+  GDALRasterBand *maskBand=NULL;
+  if(mask_opt[0]!=""){
+    if(verbose_opt[0])
+      cout << "opening mask file " << mask_opt[0] << endl;
+    maskReader.open(mask_opt[0]);
+    maskBand = maskReader.getRasterBand(0);
+  }
+
+  ImgReaderGdal inputReader(input_opt[0]);
+  GDALRasterBand  *inputBand;
+  inputBand=inputReader.getRasterBand(band_opt[0]);
+
+  ImgWriterGdal outputWriter;
+  GDALRasterBand *outputBand=NULL;
+  if(output_opt[0]!=""){
+    if(verbose_opt[0])
+      cout << "opening output file " << output_opt[0] << endl;
+    outputWriter.open(output_opt[0],inputReader);
+    outputBand = outputWriter.getRasterBand(0);
+    //sieve filter to remove small raster elements (overwrite input band)
+    if(size_opt[0]){
+      if(GDALSieveFilter((GDALRasterBandH)inputBand, (GDALRasterBandH)maskBand, (GDALRasterBandH)outputBand, size_opt[0], connect_opt[0],NULL,pfnProgress,pProgressArg)!=CE_None)
+        cerr << CPLGetLastErrorMsg() << endl;
+      else{
+        dfComplete=1.0;
+        pfnProgress(dfComplete,pszMessage,pProgressArg);
+      }
+    }
+  }
+  inputReader.close();
+  if(mask_opt[0]!="")
+    maskReader.close();
+  if(output_opt[0]!="")
+    outputWriter.close();
+}
+
diff --git a/src/apps/pkstat.cc b/src/apps/pkstat.cc
new file mode 100644
index 0000000..5a9977a
--- /dev/null
+++ b/src/apps/pkstat.cc
@@ -0,0 +1,255 @@
+/**********************************************************************
+pkstat.cc: program to calculate basic statistics from raster image
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <math.h>
+#include "base/Optionpk.h"
+#include "algorithms/Histogram.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> todo_opt("\0","todo","",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<string> input_opt("i","input","name of the input text file","");
+  Optionpk<char> fs_opt("fs","fs","field separator. Default is space",' ');
+  Optionpk<bool> output_opt("o","output","output the selected columns (default is false)",false);
+  Optionpk<short> col_opt("c", "column", "column nr, starting from 0 (default is 1)", 1);
+  Optionpk<int> range_opt("r", "range", "rows to start/end reading. Use -r 1 -r 10 to read first 10 rows where first row is header. Default is 0 (no header and read all rows)", 0);
+  Optionpk<int> end_opt("end", "end", "row to end reading. Default is 0 (read until end)", 0);
+  Optionpk<bool> num_opt("n","num","sample size",false);
+  Optionpk<bool> mean_opt("m","mean","calculate mean value",false);
+  Optionpk<bool> median_opt("med","median","calculate median",false);
+  Optionpk<bool> var_opt("var","var","calculate variance",false);
+  Optionpk<bool> stdev_opt("\0","stdev","calculate standard deviation",false);
+  Optionpk<bool> sum_opt("s","sum","calculate sum of column",false);
+  Optionpk<bool> minmax_opt("mm","minmax","calculate minimum and maximum value",false);
+  Optionpk<double> min_opt("min","min","calculate minimum value",0);
+  Optionpk<double> max_opt("max","max","calculate maximum value",0);
+  Optionpk<bool> histogram_opt("hist","hist","calculate histogram",false);
+  Optionpk<short> nbin_opt("bin","bin","number of bins to calculate histogram",10);
+  Optionpk<bool> relative_opt("rel","relative","use percentiles for histogram to calculate histogram",true);
+  Optionpk<bool> correlation_opt("cor","correlation","calculate Pearson produc-moment correlation coefficient between two columns (defined by -c <col1> -c <col2>",false);
+  Optionpk<bool> rmse_opt("e","rmse","calculate root mean square error between two columns (defined by -c <col1> -c <col2>",false);
+  Optionpk<bool> reg_opt("reg","regression","calculate linear regression error between two columns (defined by -c <col1> -c <col2>",false);
+  Optionpk<short> verbose_opt("v", "verbose", "verbose (default is 0)", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+  input_opt.retrieveOption(argc,argv);
+  fs_opt.retrieveOption(argc,argv);
+  output_opt.retrieveOption(argc,argv);
+  col_opt.retrieveOption(argc,argv);
+  range_opt.retrieveOption(argc,argv);
+  num_opt.retrieveOption(argc,argv);
+  mean_opt.retrieveOption(argc,argv);
+  median_opt.retrieveOption(argc,argv);
+  var_opt.retrieveOption(argc,argv);
+  stdev_opt.retrieveOption(argc,argv);
+  sum_opt.retrieveOption(argc,argv);
+  minmax_opt.retrieveOption(argc,argv);
+  min_opt.retrieveOption(argc,argv);
+  max_opt.retrieveOption(argc,argv);
+  histogram_opt.retrieveOption(argc,argv);
+  nbin_opt.retrieveOption(argc,argv);
+  relative_opt.retrieveOption(argc,argv);
+  correlation_opt.retrieveOption(argc,argv);
+  rmse_opt.retrieveOption(argc,argv);
+  reg_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]){
+    cout << version_opt.getHelp() << endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+
+  if(help_opt[0]){
+    cout << "usage: pkstat -i asciifile [OPTIONS]" << endl;
+    exit(0);
+  }
+
+  vector< vector<double> > dataVector(col_opt.size());
+  vector< vector<int> > histVector(col_opt.size());
+  ifstream dataFile;
+  if(verbose_opt[0])
+    cout << "opening file " << input_opt[0] << endl;
+  dataFile.open(input_opt[0].c_str());
+
+  int nrow=0;
+  bool withinRange=true;
+  
+  if(fs_opt[0]>' '&&fs_opt[0]<='~'){//field separator is a regular character (minimum ASCII code is space, maximum ASCII code is tilde)
+  // if(input_opt[0].find(".csv")!=string::npos){
+    if(verbose_opt[0])
+      cout << "reading csv file " << input_opt[0] << endl;
+    string csvRecord;
+    while(getline(dataFile,csvRecord)){//read a line
+      withinRange=true;
+      if(nrow<range_opt[0])
+        withinRange=false;
+      if(range_opt.size()>1)
+        if(nrow>range_opt[1])
+          withinRange=false;
+      if(withinRange){
+        istringstream csvstream(csvRecord);
+        string item;
+        int ncol=0;
+        while(getline(csvstream,item,fs_opt[0])){//read a column
+          if(verbose_opt[0])
+            cout << item << " ";
+          for(int icol=0;icol<col_opt.size();++icol){
+            if(ncol==col_opt[icol]){
+              double value=atof(item.c_str());
+              if(value>=min_opt[0]&&value<=max_opt[0])
+                dataVector[icol].push_back(value);
+            }
+          }
+          ++ncol;
+        }
+        if(verbose_opt[0])
+          cout << endl;
+        assert(ncol>=col_opt[0]);
+      }
+      ++nrow;
+    }
+    assert(dataVector.size());
+  }
+  else{//space or tab delimited fields
+    string spaceRecord;
+    while(!getline(dataFile, spaceRecord).eof()){
+      withinRange=true;
+      if(nrow<range_opt[0])
+        withinRange=false;
+      if(range_opt.size()>1)
+        if(nrow>range_opt[1])
+          withinRange=false;
+      if(withinRange){
+        if(verbose_opt[0]>1)
+          cout << spaceRecord << endl;
+        istringstream lineStream(spaceRecord);
+        string item;
+        int ncol=0;
+        while(lineStream >> item){
+          if(verbose_opt[0]>1)
+            cout << item << " ";
+          istringstream itemStream(item);
+          double value;
+          itemStream >> value;
+          for(int icol=0;icol<col_opt.size();++icol){
+            if(ncol==col_opt[icol]){
+              if(value>=min_opt[0]&&value<=max_opt[0])
+                dataVector[icol].push_back(value);
+            }
+          }
+          ++ncol;
+        }
+        if(verbose_opt[0]>1)
+          cout << endl;
+        if(verbose_opt[0])
+          cout << "number of columns: " << ncol << endl;
+        assert(ncol>=col_opt[0]);
+      }
+      ++nrow;
+    }
+  }
+  dataFile.close();
+  double minValue=min_opt[0];
+  double maxValue=max_opt[0];
+  Histogram hist;
+  for(int icol=0;icol<col_opt.size();++icol){
+    if(num_opt[0])
+      cout << "sample size column " << col_opt[icol] << ": " << dataVector[icol].size() << endl;
+    if(mean_opt[0])
+      cout << "mean value column " << col_opt[icol] << ": " << hist.mean(dataVector[icol]) << endl;
+    if(var_opt[0])
+      cout << "variance value column " << col_opt[icol] << ": " << hist.var(dataVector[icol]) << endl;
+    if(stdev_opt[0])
+      cout << "standard deviation column " << col_opt[icol] << ": " << sqrt(hist.var(dataVector[icol])) << endl;
+    if(sum_opt[0]){
+      cout << setprecision(2);
+      cout << fixed << "sum column " << col_opt[icol] << ": " << (hist.sum(dataVector[icol])) << endl;
+    }
+    if(median_opt[0])
+      cout << "median value column " << col_opt[icol] << ": " << hist.median(dataVector[icol]) << endl;
+    if(minmax_opt[0]){
+      cout << "min value  column " << col_opt[icol] << ": " << hist.min(dataVector[icol]) << endl;
+      cout << "max value column " << col_opt[icol] << ": " << hist.max(dataVector[icol]) << endl;
+    }
+    if(histogram_opt[0]){
+      if(verbose_opt[0])
+        std::cout << "calculating histogram for col " << icol << std::endl;
+      hist.distribution(dataVector[icol],dataVector[icol].begin(),dataVector[icol].end(),histVector[icol],nbin_opt[0],minValue,maxValue);
+      if(verbose_opt[0])
+        std::cout << "min and max values: " << minValue << ", " << maxValue << std::endl;
+    }
+  }
+  if(correlation_opt[0]){
+    assert(dataVector.size()==2);
+    cout << "correlation between columns " << col_opt[0] << " and " << col_opt[1] << ": " << hist.correlation(dataVector[0],dataVector[1]) << endl;
+  }
+  if(rmse_opt[0]){
+    assert(dataVector.size()==2);
+    cout << "root mean square error between columns " << col_opt[0] << " and " << col_opt[1] << ": " << hist.rmse(dataVector[0],dataVector[1]) << endl;
+  }
+  if(reg_opt[0]){
+    assert(dataVector.size()==2);
+    double c0=0;
+    double c1=0;
+    double r2=hist.linear_regression(dataVector[0],dataVector[1],c0,c1);
+    cout << "linear regression between columns: " << col_opt[0] << " and " << col_opt[1] << ": " << c0 << "+" << c1 << " * x " << " with R^2 (square correlation coefficient): " << r2 << endl;
+  }
+  if(histogram_opt[0]){
+    for(int irow=0;irow<histVector.begin()->size();++irow){
+      std::cout << (maxValue-minValue)*irow/(nbin_opt[0]-1)+minValue << " ";
+      for(int icol=0;icol<col_opt.size();++icol){
+        if(relative_opt[0])
+          std::cout << 100.0*static_cast<double>(histVector[icol][irow])/static_cast<double>(dataVector[icol].size());
+        else
+          std::cout << histVector[icol][irow];
+        if(icol<col_opt.size()-1)
+          cout << " ";
+      }
+      cout << endl;
+    }
+  }
+  if(output_opt[0]){
+    for(int irow=0;irow<dataVector.begin()->size();++irow){
+      for(int icol=0;icol<col_opt.size();++icol){
+        cout << dataVector[icol][irow];
+        if(icol<col_opt.size()-1)
+          cout << " ";
+      }
+      cout << endl;
+    }
+  }
+}      
diff --git a/src/apps/pkstatogr.cc b/src/apps/pkstatogr.cc
new file mode 100644
index 0000000..30e3efc
--- /dev/null
+++ b/src/apps/pkstatogr.cc
@@ -0,0 +1,118 @@
+/**********************************************************************
+pkstatogr.cc: program to calculate basic statistics from vector file
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <math.h>
+#include <string>
+#include <fstream>
+#include <assert.h>
+#include "base/Optionpk.h"
+#include "imageclasses/ImgReaderOgr.h"
+#include "algorithms/Histogram.h"
+
+int main(int argc, char *argv[])
+{
+  Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+   This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+   This is free software, and you are welcome to redistribute it\n\
+   under certain conditions; use option --license for details.",false);
+  Optionpk<bool> license_opt("lic","license","show license information",false);
+  Optionpk<bool> help_opt("h","help","shows this help info",false);
+  Optionpk<bool> todo_opt("\0","todo","",false);
+  Optionpk<string> input_opt("i", "input", "Input shape file", "");
+  Optionpk<string> field_opt("f", "fields", "fields on which to calculate statistics", "");
+  Optionpk<short> nbin_opt("n", "nbin", "number of bins", 0);
+  Optionpk<bool> min_opt("m","min","calculate minimum value",false);
+  Optionpk<bool> max_opt("M","max","calculate maximum value",false);
+  Optionpk<bool> mean_opt("mean","mean","calculate mean value",false);
+  Optionpk<bool> stdev_opt("stdev","stdev","calculate standard deviation",false);
+  Optionpk<short> verbose_opt("v", "verbose", "verbose (Default: 0)", 0);
+
+  version_opt.retrieveOption(argc,argv);
+  license_opt.retrieveOption(argc,argv);
+  help_opt.retrieveOption(argc,argv);
+  todo_opt.retrieveOption(argc,argv);
+
+  input_opt.retrieveOption(argc,argv);
+  field_opt.retrieveOption(argc,argv);
+  nbin_opt.retrieveOption(argc,argv);
+  min_opt.retrieveOption(argc,argv);
+  max_opt.retrieveOption(argc,argv);
+  mean_opt.retrieveOption(argc,argv);
+  stdev_opt.retrieveOption(argc,argv);
+  verbose_opt.retrieveOption(argc,argv);
+
+  if(version_opt[0]||todo_opt[0]){
+    std::cout << version_opt.getHelp() << std::endl;
+    std::cout << "todo: " << todo_opt.getHelp() << std::endl;
+    exit(0);
+  }
+  if(license_opt[0]){
+    cout << Optionpk<bool>::getGPLv3License() << endl;
+    exit(0);
+  }
+  if(help_opt[0]){
+    std::cout << "usage: pkstatogr -i inputimage -n nbin -f field [-f field]" << std::endl;
+    exit(0);
+  }
+
+  ImgReaderOgr imgReader;
+  try{
+    imgReader.open(input_opt[0]);
+  }
+  catch(string errorstring){
+    cerr << errorstring << endl;
+  }
+
+  ImgReaderOgr inputReader(input_opt[0]);
+  vector<double> theData;
+  Histogram hist;
+  //todo: implement ALL
+
+  for(int ifield=0;ifield<field_opt.size();++ifield){
+    if(verbose_opt[0])
+      cout << "field: " << ifield << endl;
+    theData.clear();
+    inputReader.readData(theData,OFTReal,field_opt[ifield],0,verbose_opt[0]);
+    vector<int> binData;
+    double minimum=0;
+    double maximum=0;
+    int nbin=(nbin_opt[0]>1)? nbin_opt[0] : 2;
+    hist.distribution(theData,theData.begin(),theData.end(),binData,nbin,minimum,maximum);
+    double theMean=0;
+    double theVar=0;
+    hist.meanVar(theData,theMean,theVar);
+    std::cout << " -f " << field_opt[ifield];
+    if(mean_opt[0])
+      std::cout << " --mean " << theMean;
+    if(stdev_opt[0])
+      std::cout << " --stdev " << sqrt(theVar);
+    if(min_opt[0])
+      cout << " -m " << minimum;
+    if(max_opt[0])
+      cout << " -M " << maximum;
+    std::cout << std::endl;
+    if(nbin_opt[0]>1){
+      std::cout << std::endl;
+      for(int bin=0;bin<nbin;++bin)
+        cout << (maximum-minimum)*bin/(nbin-1)+minimum << " " << static_cast<double>(binData[bin])/theData.size() << endl;
+    }
+  }
+  imgReader.close();
+}
+
diff --git a/src/base/Makefile.am b/src/base/Makefile.am
new file mode 100644
index 0000000..370b15b
--- /dev/null
+++ b/src/base/Makefile.am
@@ -0,0 +1,26 @@
+# additional include pathes necessary to compile the C++ library
+AM_CXXFLAGS = -I$(top_srcdir)/src @AM_CXXFLAGS@
+
+###############################################################################
+# THE LIBRARIES TO BUILD
+###############################################################################
+
+# the library names to build (note we are building static libs only)
+noinst_LIBRARIES = libbase.a
+
+# where to install the headers on the system
+libbase_adir = $(includedir)/base
+
+# the list of header files that belong to the library (to be installed later)
+libbase_a_HEADERS = PointData.h
+
+# the sources to add to the library and to add to the source distribution
+libbase_a_SOURCES = $(libbase_a_HEADERS) PointData.cc
+###############################################################################
+
+###############################################################################
+# HEADERS USED FOR BUILDING BUT NOT TO BE INSTALLED
+###############################################################################
+
+noinst_HEADERS = Optionpk.h PosValue.h Vector2d.h PointData.h
+###############################################################################
diff --git a/src/base/Makefile.in b/src/base/Makefile.in
new file mode 100644
index 0000000..3a01970
--- /dev/null
+++ b/src/base/Makefile.in
@@ -0,0 +1,515 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+subdir = src/base
+DIST_COMMON = $(libbase_a_HEADERS) $(noinst_HEADERS) \
+	$(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_gdal.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LIBRARIES = $(noinst_LIBRARIES)
+AR = ar
+ARFLAGS = cru
+libbase_a_AR = $(AR) $(ARFLAGS)
+libbase_a_LIBADD =
+am__objects_1 =
+am_libbase_a_OBJECTS = $(am__objects_1) PointData.$(OBJEXT)
+libbase_a_OBJECTS = $(am_libbase_a_OBJECTS)
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+	-o $@
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(libbase_a_SOURCES)
+DIST_SOURCES = $(libbase_a_SOURCES)
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(libbase_adir)"
+HEADERS = $(libbase_a_HEADERS) $(noinst_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+
+# additional include pathes necessary to compile the C++ library
+AM_CXXFLAGS = -I$(top_srcdir)/src @AM_CXXFLAGS@
+AM_LDFLAGS = @AM_LDFLAGS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FANN_CFLAGS = @FANN_CFLAGS@
+FANN_LIBS = @FANN_LIBS@
+FILECLASSES_OPT = @FILECLASSES_OPT@
+GDAL_CFLAGS = @GDAL_CFLAGS@
+GDAL_CONFIG = @GDAL_CONFIG@
+GDAL_DEP_LDFLAGS = @GDAL_DEP_LDFLAGS@
+GDAL_LDFLAGS = @GDAL_LDFLAGS@
+GDAL_OGR_ENABLED = @GDAL_OGR_ENABLED@
+GDAL_VERSION = @GDAL_VERSION@
+GREP = @GREP@
+GSL_CFLAGS = @GSL_CFLAGS@
+GSL_LIBS = @GSL_LIBS@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+
+###############################################################################
+# THE LIBRARIES TO BUILD
+###############################################################################
+
+# the library names to build (note we are building static libs only)
+noinst_LIBRARIES = libbase.a
+
+# where to install the headers on the system
+libbase_adir = $(includedir)/base
+
+# the list of header files that belong to the library (to be installed later)
+libbase_a_HEADERS = PointData.h
+
+# the sources to add to the library and to add to the source distribution
+libbase_a_SOURCES = $(libbase_a_HEADERS) PointData.cc
+###############################################################################
+
+###############################################################################
+# HEADERS USED FOR BUILDING BUT NOT TO BE INSTALLED
+###############################################################################
+noinst_HEADERS = Optionpk.h PosValue.h Vector2d.h PointData.h
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cc .o .obj
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/base/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign src/base/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLIBRARIES:
+	-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
+libbase.a: $(libbase_a_OBJECTS) $(libbase_a_DEPENDENCIES) 
+	-rm -f libbase.a
+	$(libbase_a_AR) libbase.a $(libbase_a_OBJECTS) $(libbase_a_LIBADD)
+	$(RANLIB) libbase.a
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/PointData.Po at am__quote@
+
+.cc.o:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+install-libbase_aHEADERS: $(libbase_a_HEADERS)
+	@$(NORMAL_INSTALL)
+	test -z "$(libbase_adir)" || $(MKDIR_P) "$(DESTDIR)$(libbase_adir)"
+	@list='$(libbase_a_HEADERS)'; test -n "$(libbase_adir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libbase_adir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(libbase_adir)" || exit $$?; \
+	done
+
+uninstall-libbase_aHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(libbase_a_HEADERS)'; test -n "$(libbase_adir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(libbase_adir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(libbase_adir)" && rm -f $$files
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LIBRARIES) $(HEADERS)
+installdirs:
+	for dir in "$(DESTDIR)$(libbase_adir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-libbase_aHEADERS
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-libbase_aHEADERS
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+	clean-noinstLIBRARIES ctags distclean distclean-compile \
+	distclean-generic distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-libbase_aHEADERS install-man \
+	install-pdf install-pdf-am install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am uninstall-libbase_aHEADERS
+
+###############################################################################
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/base/Optionpk.h b/src/base/Optionpk.h
new file mode 100644
index 0000000..48922f9
--- /dev/null
+++ b/src/base/Optionpk.h
@@ -0,0 +1,267 @@
+/**********************************************************************
+Optionpk.h: class to handle command line options (inherits from stl vector class)
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _OPTIONPK_H_
+#define _OPTIONPK_H_
+
+#include <vector>
+#include <string>
+#include <cstdlib>
+#include <assert.h>
+#include <stdexcept>
+#include <iostream>
+#include <iomanip>
+#include <sstream>
+#include "ogr_feature.h"
+
+using namespace std;
+
+class BadConversion : public runtime_error {
+ public:
+ BadConversion(string const& s)
+   : runtime_error(s)
+    { }
+};
+
+template<typename T> inline T string2type(string const& s,bool failIfLeftoverChars){
+  istringstream i(s);
+  char c;
+  T x;
+  if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+     throw BadConversion(s);
+  return x;
+}
+
+template<typename T> inline T string2type(string const& s){
+  istringstream i(s);
+  T x;
+  if (!(i >> x) )
+     throw BadConversion(s);
+  return x;
+}
+
+//specialization for string
+template<> inline string string2type(string const& s){
+  return s;
+}
+
+//specialization for OGRFieldType
+template<> inline OGRFieldType string2type(string const& s){
+  OGRFieldType ftype;
+  int ogr_typecount=11;//hard coded for now!
+  for(int iType = 0; iType < ogr_typecount; ++iType){
+    if( OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType) != NULL
+        && EQUAL(OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType),s.c_str()))
+      ftype=(OGRFieldType) iType;
+  }
+  return ftype;
+}
+
+template<typename T> inline string type2string(T const& value){
+  ostringstream oss;
+  oss << value;
+  return oss.str();
+}
+
+//specialization for bool
+template<> inline string type2string(bool const& value){
+  if(value)
+    return("true");
+  else
+    return("false");
+}
+
+//specialization for string
+template<> inline string type2string(string const& value){
+  if(value.empty())
+    return("<empty string>");
+  else
+    return(value);
+}
+
+//specialization for float
+template<> inline string type2string(float const& value){
+  ostringstream oss;
+  // oss.precision(1);
+  // oss.setf(ios::fixed);
+  oss << value;
+  return oss.str();
+}
+
+//specialization for double
+template<> inline string type2string(double const& value){
+  ostringstream oss;
+  // oss.precision(1);
+  //  oss.setf(ios::fixed);
+  oss << value;
+  return oss.str();
+}
+
+template<class T> class Optionpk : public vector <T>
+{
+public:
+  Optionpk();
+  Optionpk(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue);
+  ~Optionpk();
+  void setAll(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue);
+  void setHelp(const string& helpInfo){m_help=helpInfo;};
+  string usage() const;
+  static string getGPLv3License(){
+    return static_cast<string>("\n\
+    This program is free software: you can redistribute it and/or modify\n\
+    it under the terms of the GNU General Public License as published by\n\
+    the Free Software Foundation, either version 3 of the License, or\n\
+    (at your option) any later version.\n\
+    \n\
+    This program is distributed in the hope that it will be useful,\n\
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
+    GNU General Public License for more details.\n\
+                                          \n\
+    You should have received a copy of the GNU General Public License\n\
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n");};
+  string getHelp() const {return m_help;};
+  void setDefault(const T& defaultValue);
+  string getDefaultValue() const {return m_defaultValue;};
+  void setShortName(const string& shortName);
+  void setLongName(const string& longName);
+  string getShortName() const {return m_shortName;};
+  string getLongName() const {return m_longName;};
+  bool hasArgument() const {return m_hasArgument;};
+  void hasArgument(bool flag){m_hasArgument=flag;};
+  bool hasShortOption() const {return m_shortName.compare("\0");};
+  bool hasLongOption() const {return m_longName.compare("\0");};
+  int retrieveOption(int argc, char ** argv);
+  template<class T1> friend ostream& operator<<(ostream & os, const Optionpk<T1>& theOption);
+private:
+  string m_shortName;
+  string m_longName;
+  string m_help;
+  bool m_hasArgument;
+  T m_defaultValue;
+};
+
+template<class T1> ostream& operator<<(ostream& os, const Optionpk<T1>& theOption)
+{
+  os << theOption.getLongName() << ": ";
+  for(int index=0;index<theOption.size();++index)
+    os << type2string<T1>(theOption[index]) << " ";
+  os << std::endl;
+  return os;
+}
+
+template<class T> Optionpk<T>::Optionpk() 
+{
+}
+
+template<class T> Optionpk<T>::Optionpk(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue)
+{
+  setAll(shortName,longName,helpInfo,defaultValue);
+}
+
+template<class T> string Optionpk<T>::usage() const
+{
+  ostringstream helpss;
+  string shortOption=m_shortName;
+  string longOption=m_longName;
+  shortOption.insert(0,"-");
+  longOption.insert(0,"--");
+  if(hasShortOption())
+    helpss << "   " << setiosflags(ios::left) << setw(4) << shortOption;
+  else 
+    helpss << "   " << setiosflags(ios::left) << setw(4) << " ";
+  if(hasLongOption())
+    helpss << "   " << setiosflags(ios::left) << setw(20) << longOption;
+  else
+    helpss << "   " << setiosflags(ios::left) << setw(20) << " ";
+  helpss << "   " << m_help;
+  // helpss << std::resetiosflags << " (default: " << type2string<T>(m_defaultValue) << ")";
+  helpss << " (default: " << type2string<T>(m_defaultValue) << ")";
+  return helpss.str();
+}
+
+template<class T> void Optionpk<T>::setAll(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue)
+{
+  m_shortName=shortName;
+  m_longName=longName;
+  m_hasArgument=true;
+  m_help=helpInfo;
+  m_defaultValue=defaultValue;
+}
+template<> void Optionpk<bool>::setAll(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue);
+
+template<> Optionpk<bool>::Optionpk(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue)
+{
+  setAll(shortName,longName,helpInfo,defaultValue);
+}
+
+template<> void Optionpk<bool>::setAll(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue)
+{
+  m_shortName=shortName;
+  m_longName=longName;
+  m_hasArgument=false;
+  m_help=helpInfo;
+  m_defaultValue=defaultValue;
+}
+
+template<class T> Optionpk<T>::~Optionpk() 
+{
+}
+
+template<class T> int Optionpk<T>::retrieveOption(int argc, char **argv){ 
+  for(int i = 1; i < argc; ++i ){
+    string helpStringShort="-h";
+    string helpStringLong="--help";
+    string currentArgument;
+    string currentOption=argv[i];
+    string shortOption=m_shortName;
+    string longOption=m_longName;
+    shortOption.insert(0,"-");
+    longOption.insert(0,"--");
+    // size_t foundEqual=currentOption.rfind("=");
+    size_t foundEqual=currentOption.rfind("=");
+    if(foundEqual!=string::npos){
+      currentArgument=currentOption.substr(foundEqual+1);
+      currentOption=currentOption.substr(0,foundEqual);
+    }
+    if(!(helpStringShort.compare(currentOption))||!(helpStringLong.compare(currentOption)))
+      cout << usage() << endl;
+    if(hasShortOption()&&!(shortOption.compare(currentOption))){//for -option
+      if(foundEqual!=string::npos)
+        this->push_back(string2type<T>(currentArgument));
+      else if(m_hasArgument && i < argc-1)
+        this->push_back(string2type<T>(argv[++i]));
+      else
+        this->push_back(string2type<T>("1"));
+    }
+    else if(hasLongOption()&&!(longOption.compare(currentOption))){//for --option
+      if(foundEqual!=string::npos)
+        this->push_back(string2type<T>(currentArgument));
+      else if(m_hasArgument && i < argc-1)
+        this->push_back(string2type<T>(argv[++i]));
+      else
+        this->push_back(string2type<T>("1"));
+    }
+  }
+  if(!(this->size()))//only set default value if no options were given
+    this->push_back(m_defaultValue);
+  return(this->size());
+}
+
+#endif
diff --git a/src/base/PointData.cc b/src/base/PointData.cc
new file mode 100644
index 0000000..79e2166
--- /dev/null
+++ b/src/base/PointData.cc
@@ -0,0 +1,28 @@
+#include "PointData.h"
+
+PointData::PointData(){
+}
+
+PointData::~PointData(){
+}
+
+double PointData::correctReflectance(const State &state){
+  double ecosfi=state.e*m_cosfi;
+  double optical_depth=(m_cosza*m_cosza>m_epsilon*m_epsilon) ? exp(-m_tau/m_cosza) : 0;
+  double hotspot=(ecosfi<1) ? (state.k+(1-state.k)*(1-state.e*m_cosza)/(1-ecosfi)) : 1;
+  double radial=(1+state.a*m_r);
+  double correctedReflectance;
+  correctedReflectance=(m_reflectance-state.haze)/m_cosza/optical_depth/m_deltaT/hotspot/radial;
+  return correctedReflectance;
+  // return (m_reflectance-state.haze)/((m_cosza*exp(-m_tau/m_cosza)*m_deltaT*(state.k+(1-state.k)*(1-state.e*m_cosza)/(1-ecosfi))*(1+state.a*m_r)));
+}
+
+double PointData::modelReflectance(const State &state){
+  double ecosfi=state.e*m_cosfi;
+  double optical_depth=exp(-m_tau/m_cosza);
+  double hotspot=state.k+(1-state.k)*(1-state.e*m_cosza)/(1-ecosfi);
+  double radial=(1+state.a*m_r);
+  return m_reflectance*m_cosza*optical_depth*m_deltaT*hotspot*radial+state.haze;
+  // return (m_reflectance-state.haze)/((m_cosza*exp(-m_tau/m_cosza)*m_deltaT*(state.k+(1-state.k)*(1-state.e*m_cosza)/(1-ecosfi))*(1+state.a*m_r)));
+}
+
diff --git a/src/base/PointData.h b/src/base/PointData.h
new file mode 100644
index 0000000..08c5a1a
--- /dev/null
+++ b/src/base/PointData.h
@@ -0,0 +1,51 @@
+#ifndef _POINTDATA_
+#define _POINTDATA_
+#include <assert.h>
+#include <math.h>
+#include <vector>
+
+struct State{
+  double k;
+  double e;
+  double a;
+  double haze;
+};
+
+class PointData{
+ public: 
+  PointData();//constructor
+  ~PointData();//destructor
+  void setCosFi(double fi){
+    if(fi>180)
+      fi-=360;
+    else if(fi<-180)
+      fi+=360;
+    m_cosfi=cos(deg2rad(fi));
+  };
+  void setCosSZA(double sza){
+    assert(sza>=0);
+    m_cosza=cos(deg2rad(sza));
+  };
+  double getReflectance() const{return m_reflectance;};
+  void setReflectance(double reflectance) {m_reflectance=reflectance;};
+  double getImage() const{return m_image;}; 
+  void setImage(int image) {m_image=image;}; 
+  void setR(double r){m_r=r;};
+  double getR() const{return m_r;};
+  double correctReflectance(const State &state);
+  double modelReflectance(const State &state);
+  static double m_deltaT;
+  static double m_tau;
+  static double m_epsilon;
+  static double m_flag;
+  static double m_residual;
+ private:
+  double deg2rad(double angle) const{return acos(-1)*angle/180.0;};
+  double m_reflectance;
+  double m_cosza;
+  double m_cosfi;
+  double m_r;
+  int m_image;
+};
+
+#endif //_POINTDATA_
diff --git a/src/base/PosValue.h b/src/base/PosValue.h
new file mode 100644
index 0000000..8ae957f
--- /dev/null
+++ b/src/base/PosValue.h
@@ -0,0 +1,47 @@
+/**********************************************************************
+PosValue.h: class to work with structs containing a position and a value
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _POSVALUE_H_
+#define _POSVALUE_H_
+
+using namespace std;
+
+struct PosValue{
+  int position;
+  double value;
+};
+class Compare_PosValue{
+public:
+  int operator() (const PosValue& pv1, const PosValue& pv2) const{
+    return pv1.value>pv2.value;//for decreasing order
+  }
+};
+class Decrease_PosValue{
+public:
+  int operator() (const PosValue& pv1, const PosValue& pv2) const{
+    return pv1.value>pv2.value;//for decreasing order
+  }
+};
+class Increase_PosValue{
+public:
+  int operator() (const PosValue& pv1, const PosValue& pv2) const{
+    return pv1.value<pv2.value;//for increasing order
+  }
+};
+#endif /* _POSVALUE_H_ */
diff --git a/src/base/Vector2d.h b/src/base/Vector2d.h
new file mode 100644
index 0000000..7ff85b2
--- /dev/null
+++ b/src/base/Vector2d.h
@@ -0,0 +1,294 @@
+/**********************************************************************
+Vector2d.h: 2-dimensional vector class (inherits from stl vector class)
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _VECTOR2D_H_
+#define _VECTOR2D_H_
+
+#include <vector>
+#include <list>
+#include <algorithm>
+#include <numeric>
+#include <gsl/gsl_matrix.h>
+#include "PosValue.h"
+#include "algorithms/Histogram.h"
+
+using namespace std;
+template<class T> class Vector2d: public vector<vector <T> >
+{
+public:
+  Vector2d();
+  Vector2d(const Vector2d<T>& v1);//copy constructor
+  ~Vector2d();
+  Vector2d(int nrow);
+  Vector2d(int nrow, int ncol);
+  Vector2d(int nrow, int ncol, const T& value);
+  Vector2d(const gsl_matrix* gsl_m);
+  void resize(int nrow)
+  {
+    vector< vector<T> >::resize(nrow);
+  };
+  void resize(int nrow, int ncol);
+  int nRows() const {return this->size();};
+  int nCols() const {if(this->size()) return this->begin()->size(); else return 0;};
+  void selectCol(int col, vector<T> &output) const;
+  void selectCol(int col, T* output) const;
+  vector<T> selectCol(int col);
+  void selectCols(const list<int> &cols, Vector2d<T> &output) const;
+  void selectCols(const list<int> &cols);
+  void sort(Vector2d<T>& output);  
+  void scale(const vector<double> &scaleVector, const vector<double> &offsetVector, Vector2d<T>& scaledOutput);
+  void scale(const T lbound, const T ubound, vector<double> &scaleVector, vector<double> &offsetVector, Vector2d<T>& scaledOutput);
+  Vector2d<T> operator=(const Vector2d<T>& v1);
+//   ostream& operator<<(ostream& os, const Vector2d<T>& v);
+//   template<class T> ostream& operator<<(ostream& os, const Vector2d<T>& v);
+  Vector2d<T> sum(const Vector2d<T>& v1, const Vector2d<T>& v2) const;
+  T max(int& x, int& y, double maxValue) const;
+
+  T sum() const;
+};
+  
+template<class T> Vector2d<T>::Vector2d() 
+  : vector< vector<T> >()
+{
+}
+
+template<class T> Vector2d<T>::~Vector2d() 
+{
+}
+
+//copy constructor
+template<class T> Vector2d<T>::Vector2d(const Vector2d<T>& v1){
+  this->resize(v1.size());
+  for(int irow=0;irow<v1.size();++irow)
+    this->at(irow)=v1[irow];
+}
+
+template<class T> Vector2d<T> Vector2d<T>::operator=(const Vector2d<T>& v1){
+  //check for assignment to self (of the form v=v)
+  if(this==&v1)
+     return *this;
+  else{
+    this->resize(v1.size());
+    for(int irow=0;irow<v1.size();++irow)
+      this->at(irow)=v1[irow];
+    return *this;
+  }
+}
+
+template<class T> Vector2d<T>::Vector2d(int nrow) 
+  : vector< vector<T> >(nrow)
+{
+}
+
+template<class T> Vector2d<T>::Vector2d(int nrow, int ncol) 
+//   : vector< vector<T> >(nrow)
+{
+  this->resize(nrow);
+  for(int irow=0;irow<nrow;++irow){
+    (this->operator[](irow)).resize(ncol);
+//     (*this)[irow].resize(ncol);
+  }
+}
+
+template<class T> Vector2d<T>::Vector2d(int nrow, int ncol, const T& value) 
+{
+  this->resize(nrow);
+  for(int irow=0;irow<nrow;++irow){
+    (this->operator[](irow)).resize(ncol);
+    for(int icol=0;icol<ncol;++icol)
+      (this->operator[](irow))[icol]=value;
+  }
+}
+
+template<class T> Vector2d<T>::Vector2d(const gsl_matrix* gsl_m)
+{
+  this->resize(gsl_m->size1);
+  for(int irow=0;irow<this->size();++irow){
+    (this->operator[](irow)).resize(gsl_m->size2);
+    for(int icol=0;icol<this->operator[](irow).size();++icol)
+      (this->operator[](irow))[icol]=gsl_matrix_get(gsl_m,irow,icol);
+  }
+}
+
+
+template<class T> void Vector2d<T>::resize(int nrow, int ncol)
+{
+    this->vector< vector<T> >::resize(nrow);
+    for(int irow=0;irow<nrow;++irow){
+      (this->operator[](irow)).resize(ncol);
+    }
+}
+
+template<class T> void Vector2d<T>::selectCols(const list<int> &cols, Vector2d<T> &output) const
+{
+  output.resize(this->size());
+  list<int>::const_iterator it;
+  for(int irow=0;irow<this->size();++irow){
+    output[irow].resize(cols.size());
+    it=cols.begin();
+    for(int icol=0;icol<cols.size();++icol)
+      output[irow][icol]=(*this)[irow][*(it++)];
+  }
+}
+
+template<class T> void Vector2d<T>::selectCol(int col, vector<T> &output) const
+{
+  assert(col>=0);
+  assert(col<(*this)[0].size());
+  output.resize(this->size());
+  for(int irow=0;irow<this->size();++irow){
+    output[irow]=(*this)[irow][col];
+  }
+}
+
+template<class T> vector<T> Vector2d<T>::selectCol(int col)
+{
+  assert(col>=0);
+  assert(col<(*this)[0].size());
+  vector<T> output(this->size());
+  for(int irow=0;irow<this->size();++irow)
+    output[irow]=(*this)[irow][col];
+  return(output);
+}
+
+template<class T> void Vector2d<T>::selectCol(int col, T* output) const
+{
+  assert(col>=0);
+  assert(col<(*this)[0].size());
+  for(int irow=0;irow<this->size();++irow){
+    output[irow]=(*this)[irow][col];
+  }
+}
+
+template<class T> void Vector2d<T>::selectCols(const list<int> &cols)
+{
+  for(int irow=0;irow<this->size();++irow)
+    for(int icol=((*this)[irow]).size()-1;icol>=0;--icol)
+      if(find(cols.begin(),cols.end(),icol)==cols.end())
+	(*this)[irow].erase(((*this)[irow]).begin()+icol);
+}
+
+// template<class T> ostream& operator<<(ostream& os, const Vector2d<T>& v)
+// {
+//   for(int irow=0;irow<v.size();++irow){
+//     for(int icol=0;icol<v[irow].size();++icol){
+//       os << v[irow][icol] << "\t";
+//     }
+//     os << endl;
+//   }
+//   return os;
+// }
+
+template<class T> void Vector2d<T>::sort(Vector2d<T>& output)
+{
+  //sort according to first sample (ex. wavelength)
+  int nsample=this->size();//including first sample (ex. wavelength)
+  int nband=(*this)[0].size();  
+  vector<PosValue> sortW(nband);
+  for(int ilevel=0;ilevel<nband;++ilevel){
+    PosValue pv;
+    pv.position=ilevel;
+    pv.value=(*this)[0][ilevel];
+    sortW[ilevel]=pv;
+  }
+  std::sort(sortW.begin(),sortW.end(),Increase_PosValue());
+  output.resize(nsample);  
+  for(int isample=0;isample<nsample;++isample){
+    output[isample].resize(nband);
+    for(int iband=0;iband<nband;++iband)
+      output[isample][iband]=(*this)[isample][sortW[iband].position];
+  }
+}
+
+template<class T> void Vector2d<T>::scale(const vector<double> &scaleVector,const vector<double> &offsetVector, Vector2d<T>& scaledOutput)
+{
+  int nsample=this->size();//including first sample (ex. wavelength)
+  int nband=(*this)[0].size();
+  assert(scaleVector.size()==nband);
+  assert(offsetVector.size()==nband);
+  vector<T> pixel(nband);
+  scaledOutput.resize(nsample,nband);
+  for(int isample=0;isample<nsample;++isample)
+    for(int iband=0;iband<nband;++iband)
+      scaledOutput[isample][iband]=((*this)[isample][iband])*scaleVector[iband]+offsetVector[iband];
+}
+
+template<class T> void Vector2d<T>::scale(const T lbound, const T ubound, vector<double> &scaleVector, vector<double> &offsetVector, Vector2d<T>& scaledOutput)
+{
+  //scale to lbound and ubound
+  int nsample=this->size();//including first sample (ex. wavelength)
+  int nband=(*this)[0].size();
+  scaleVector.resize(nband);
+  offsetVector.resize(nband);
+  vector<T> pixel(nsample);
+  T theMin;
+  T theMax;
+  Histogram hist;
+  scaledOutput.resize(nsample,nband);
+  for(int iband=0;iband<nband;++iband){
+    pixel=selectCol(iband);
+    hist.minmax(pixel, pixel.begin(), pixel.end(), theMin, theMax);
+    scaleVector[iband]=static_cast<double>(ubound-lbound)/(theMax-theMin);
+    offsetVector[iband]=static_cast<double>(-theMin*scaleVector[iband])-lbound;
+    for(int isample=0;isample<pixel.size();++isample)
+      scaledOutput[isample][iband]=((*this)[isample][iband])*scaleVector[iband]+offsetVector[iband];
+  }
+}
+
+template<class T> Vector2d<T> Vector2d<T>::sum(const Vector2d<T>& v1, const Vector2d<T>& v2) const{
+  Vector2d<T> vsum(v1.size());
+  assert(v1.size()==v2.size());
+  for(int irow=0;irow<v1.size();++irow){
+    assert(v1[irow].size()==v2[irow].size());
+    vsum[irow].resize(v1[irow].size());
+    for(int icol=0;icol<v1.size();++icol)
+      vsum[irow][icol]=v1[irow][icol]+v2[irow][icol];
+  }
+  return vsum;
+}
+
+template<class T> T Vector2d<T>::sum() const{
+  double theSum=0;
+  for(int irow=0;irow<this->size();++irow){
+    for(int icol=0;icol<this->operator[](irow).size();++icol)
+      theSum+=(this->operator[](irow))[icol];
+  }
+  return theSum;
+}
+
+template<class T> T Vector2d<T>::max(int& x, int& y, double maxValue) const{
+  //todo: what if this->operator[](0)[0] >=maxValue?
+  // double theMax=(this->operator[](0))[0];
+  double theMax=0;
+  for(int irow=0;irow<this->size();++irow){
+    for(int icol=0;icol<(this->operator[](irow)).size();++icol){
+      double currentValue=(this->operator[](irow))[icol];
+      if(currentValue<maxValue&&currentValue>theMax){
+        assert(theMax<maxValue);
+        y=irow;
+        x=icol;
+        theMax=currentValue;
+      }
+    }
+  }
+  assert(theMax<maxValue);
+  return theMax;
+}
+
+#endif /* _VECTOR2D_H_ */
diff --git a/src/fileclasses/FileReaderLas.cc b/src/fileclasses/FileReaderLas.cc
new file mode 100644
index 0000000..25f1d42
--- /dev/null
+++ b/src/fileclasses/FileReaderLas.cc
@@ -0,0 +1,140 @@
+/**********************************************************************
+FileReaderLas.cc: class to read LAS files using liblas API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <string>
+#include <iostream>
+#include <fstream>
+#include "FileReaderLas.h"
+//---------------------------------------------------------------------------
+FileReaderLas::FileReaderLas(void)
+{
+  m_reader=NULL;
+  m_ifstream=NULL;
+}
+
+FileReaderLas::FileReaderLas(const std::string& filename)
+{
+  open(filename);
+}
+
+FileReaderLas::~FileReaderLas(void)
+{
+  delete m_ifstream;
+  delete m_reader;
+}
+
+//---------------------------------------------------------------------------
+
+void FileReaderLas::open(const std::string& filename)
+{
+  m_filename = filename;
+  setCodec(filename);
+}
+
+//---------------------------------------------------------------------------
+void FileReaderLas::close(void)
+{
+  m_ifstream->close();
+  m_ifstream=NULL;
+  m_reader=NULL;
+}
+
+//---------------------------------------------------------------------------
+void FileReaderLas::setCodec(const std::string& filename){
+  m_ifstream = new(std::ifstream);
+  m_ifstream->open(m_filename.c_str(),std::ios::in|std::ios::binary);
+  m_reader = new liblas::Reader(*m_ifstream);
+  //Note: It is possible to use the basic liblas::Reader constructor that takes in a std::istream, but it will not be able to account for the fact that the file might be compressed. Using the ReaderFactory will take care of all of this for you.
+  // liblas::ReaderFactory rfactory;
+  // m_reader=&rfactory.CreateWithStream(ifs);
+}
+
+liblas::Header const& FileReaderLas::getHeader() const{
+  return(m_reader->GetHeader());
+}
+
+bool FileReaderLas::isCompressed() const{
+  return getHeader().Compressed();
+}
+
+unsigned long int FileReaderLas::getPointCount() const{
+  return getHeader().GetPointRecordsCount();
+}
+
+void FileReaderLas::las2ascii(const std::string& filename, bool verbose) const{
+  std::ofstream fpoints(filename.c_str(),std::ios::out);
+  fpoints << "#";
+  fpoints << "X" << "," << "Y" << "," << "Z" << std::endl;
+  if(verbose)
+    std::cout << "reset reading" << std::endl;
+  m_reader->Reset();
+  if(verbose)
+    std::cout << "going through points" << std::endl;
+  while(m_reader->ReadNextPoint()){
+    liblas::Point const& thePoint=m_reader->GetPoint();
+    double x=thePoint.GetX();
+    double y=thePoint.GetY();
+    double z=thePoint.GetZ();
+    fpoints.precision(12);
+    fpoints << x << "," << y << "," << z << std::endl;
+  }
+  fpoints.close();
+}
+
+void FileReaderLas::getExtent(double& ulx, double& uly, double& lrx, double& lry) const{
+  const liblas::Header& theHeader=getHeader();
+  ulx=theHeader.GetMinX();
+  uly=theHeader.GetMaxY();
+  lrx=theHeader.GetMaxX();
+  lry=theHeader.GetMinY();
+}
+
+double FileReaderLas::getMinZ() const{
+  return(getHeader().GetMinZ());
+}
+
+double FileReaderLas::getMaxZ() const{
+  return(getHeader().GetMaxZ());
+}
+
+//todo: does not work ??
+// void FileReaderLas::addBoundsFilter(double ulx, double uly, double lrx, double lry){
+//   liblas::Bounds<double> bounds = liblas::Bounds<double>(ulx,lry,lrx,uly);
+//   typedef liblas::BoundsFilter filter;
+//   filter* bounds_filter = new filter(bounds);
+//   bounds_filter->SetType(liblas::FilterI::eInclusion);
+//   m_filters.push_back(liblas::FilterPtr(bounds_filter));
+// }
+
+void FileReaderLas::addReturnsFilter(std::vector<unsigned short> const& returns){
+  typedef liblas::ReturnFilter filter;
+  filter* return_filter;
+  std::vector<boost::uint16_t> returns_t;
+  if(returns[0]<0)
+    return_filter=new filter(returns_t,true);
+  else{
+    for(int index=0;index<returns.size();++index){
+      assert(returns[index]>0);
+      returns_t.push_back(returns[index]);
+    }
+    return_filter=new filter(returns_t,false);
+  }
+  m_filters.push_back(liblas::FilterPtr(return_filter));
+}
+
diff --git a/src/fileclasses/FileReaderLas.h b/src/fileclasses/FileReaderLas.h
new file mode 100644
index 0000000..93023dd
--- /dev/null
+++ b/src/fileclasses/FileReaderLas.h
@@ -0,0 +1,60 @@
+/**********************************************************************
+FileReaderLas.h: class to read LAS files using liblas API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _IMGREADERLAS_H_
+#define _IMGREADERLAS_H_
+
+#include <string>
+#include <vector>
+#include "liblas/liblas.hpp"
+
+//--------------------------------------------------------------------------
+class FileReaderLas
+{
+public:
+  FileReaderLas(void);
+  FileReaderLas(const std::string& filename);
+  ~FileReaderLas(void);
+  void open(const std::string& filename);
+  void close(void);
+  liblas::Header const& getHeader() const;
+  bool isCompressed() const;
+  unsigned long int getPointCount() const;
+  void las2ascii(const std::string& filename, bool verbose=false) const;
+  template<typename T> liblas::Bounds<T> getExtent() const {return getHeader().GetExtent();};
+  void getExtent(double& ulx, double& uly, double& lrx, double& lry) const;
+  double getMinZ() const;
+  double getMaxZ() const;
+  void resetReader(){m_reader->Reset();};
+  void setFilter(std::vector<liblas::FilterPtr> const& filters);
+  bool const& readNextPoint(liblas::Point& thePoint){bool returnValue=m_reader->ReadNextPoint();thePoint=m_reader->GetPoint();return(returnValue);};
+  liblas::Point const& readPointAt(std::size_t n){m_reader->ReadPointAt(n);return m_reader->GetPoint();};
+  // void addBoundsFilter(double ulx, double uly, double lrx, double lry);
+  void addReturnsFilter(std::vector<unsigned short> const& returns);
+  void setFilters(const std::vector<liblas::FilterPtr>& filters){m_filters=filters;setFilters();};
+  void setFilters(){m_reader->SetFilters(m_filters);};
+protected:
+  void setCodec(const std::string& filename);
+  std::string m_filename;
+  std::ifstream *m_ifstream;
+  liblas::Reader* m_reader;
+  std::vector<liblas::FilterPtr> m_filters;
+};
+
+#endif // _IMGREADERLAS_H_
diff --git a/src/fileclasses/Makefile.am b/src/fileclasses/Makefile.am
new file mode 100644
index 0000000..104b505
--- /dev/null
+++ b/src/fileclasses/Makefile.am
@@ -0,0 +1,19 @@
+AM_LDFLAGS = $(GDAL_LDFLAGS) @AM_LDFLAGS@
+AM_CXXFLAGS = -I$(top_srcdir)/src $(GDAL_CFLAGS) @AM_CXXFLAGS@
+
+###############################################################################
+# THE LIBRARIES TO BUILD
+###############################################################################
+
+# the library names to build (note we are building static libs only)
+noinst_LIBRARIES = libfileClasses.a
+
+# where to install the headers on the system
+libfileClasses_adir = $(includedir)/fileclasses
+
+# the list of header files that belong to the library (to be installed later)
+libfileClasses_a_HEADERS = FileReaderLas.h
+
+# the sources to add to the library and to add to the source distribution
+libfileClasses_a_SOURCES = $(libfileClasses_a_HEADERS) FileReaderLas.cc
+###############################################################################
diff --git a/src/fileclasses/Makefile.in b/src/fileclasses/Makefile.in
new file mode 100644
index 0000000..b9e234d
--- /dev/null
+++ b/src/fileclasses/Makefile.in
@@ -0,0 +1,507 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+subdir = src/fileclasses
+DIST_COMMON = $(libfileClasses_a_HEADERS) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_gdal.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LIBRARIES = $(noinst_LIBRARIES)
+AR = ar
+ARFLAGS = cru
+libfileClasses_a_AR = $(AR) $(ARFLAGS)
+libfileClasses_a_LIBADD =
+am__objects_1 =
+am_libfileClasses_a_OBJECTS = $(am__objects_1) FileReaderLas.$(OBJEXT)
+libfileClasses_a_OBJECTS = $(am_libfileClasses_a_OBJECTS)
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+	-o $@
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(libfileClasses_a_SOURCES)
+DIST_SOURCES = $(libfileClasses_a_SOURCES)
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(libfileClasses_adir)"
+HEADERS = $(libfileClasses_a_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_CXXFLAGS = -I$(top_srcdir)/src $(GDAL_CFLAGS) @AM_CXXFLAGS@
+AM_LDFLAGS = $(GDAL_LDFLAGS) @AM_LDFLAGS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FANN_CFLAGS = @FANN_CFLAGS@
+FANN_LIBS = @FANN_LIBS@
+FILECLASSES_OPT = @FILECLASSES_OPT@
+GDAL_CFLAGS = @GDAL_CFLAGS@
+GDAL_CONFIG = @GDAL_CONFIG@
+GDAL_DEP_LDFLAGS = @GDAL_DEP_LDFLAGS@
+GDAL_LDFLAGS = @GDAL_LDFLAGS@
+GDAL_OGR_ENABLED = @GDAL_OGR_ENABLED@
+GDAL_VERSION = @GDAL_VERSION@
+GREP = @GREP@
+GSL_CFLAGS = @GSL_CFLAGS@
+GSL_LIBS = @GSL_LIBS@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+
+###############################################################################
+# THE LIBRARIES TO BUILD
+###############################################################################
+
+# the library names to build (note we are building static libs only)
+noinst_LIBRARIES = libfileClasses.a
+
+# where to install the headers on the system
+libfileClasses_adir = $(includedir)/fileclasses
+
+# the list of header files that belong to the library (to be installed later)
+libfileClasses_a_HEADERS = FileReaderLas.h
+
+# the sources to add to the library and to add to the source distribution
+libfileClasses_a_SOURCES = $(libfileClasses_a_HEADERS) FileReaderLas.cc
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cc .o .obj
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/fileclasses/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign src/fileclasses/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLIBRARIES:
+	-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
+libfileClasses.a: $(libfileClasses_a_OBJECTS) $(libfileClasses_a_DEPENDENCIES) 
+	-rm -f libfileClasses.a
+	$(libfileClasses_a_AR) libfileClasses.a $(libfileClasses_a_OBJECTS) $(libfileClasses_a_LIBADD)
+	$(RANLIB) libfileClasses.a
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/FileReaderLas.Po at am__quote@
+
+.cc.o:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+install-libfileClasses_aHEADERS: $(libfileClasses_a_HEADERS)
+	@$(NORMAL_INSTALL)
+	test -z "$(libfileClasses_adir)" || $(MKDIR_P) "$(DESTDIR)$(libfileClasses_adir)"
+	@list='$(libfileClasses_a_HEADERS)'; test -n "$(libfileClasses_adir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libfileClasses_adir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(libfileClasses_adir)" || exit $$?; \
+	done
+
+uninstall-libfileClasses_aHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(libfileClasses_a_HEADERS)'; test -n "$(libfileClasses_adir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(libfileClasses_adir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(libfileClasses_adir)" && rm -f $$files
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LIBRARIES) $(HEADERS)
+installdirs:
+	for dir in "$(DESTDIR)$(libfileClasses_adir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-libfileClasses_aHEADERS
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-libfileClasses_aHEADERS
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+	clean-noinstLIBRARIES ctags distclean distclean-compile \
+	distclean-generic distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-libfileClasses_aHEADERS install-man \
+	install-pdf install-pdf-am install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am uninstall-libfileClasses_aHEADERS
+
+###############################################################################
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/imageclasses/ImgReaderGdal.cc b/src/imageclasses/ImgReaderGdal.cc
new file mode 100644
index 0000000..047d9da
--- /dev/null
+++ b/src/imageclasses/ImgReaderGdal.cc
@@ -0,0 +1,452 @@
+/**********************************************************************
+ImgReaderGdal.cc: class to read raster files using GDAL API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include "ImgReaderGdal.h"
+#include <assert.h>
+#include <sstream>
+#include <iostream>
+
+ImgReaderGdal::ImgReaderGdal(void)
+  : m_gds(NULL), m_isGeoRef(false), m_ncol(0), m_nrow(0), m_nband(0)
+{}
+
+void ImgReaderGdal::open(const string& filename)//, double magicX, double magicY)
+{
+  m_filename = filename;
+  setCodec();//magicX,magicY);
+}
+
+ImgReaderGdal::~ImgReaderGdal(void)
+{
+  // delete m_gds;
+//   GDALDumpOpenDatasets(stderr);
+//   GDALDestroyDriverManager();//could be used by other objects...
+}
+
+//--------------------------------------------------------------------------
+void ImgReaderGdal::close(void)
+{
+  GDALClose(m_gds);
+}
+
+void ImgReaderGdal::setCodec()//double magicX, double magicY)
+{
+  GDALAllRegister();
+  m_gds = (GDALDataset *) GDALOpen(m_filename.c_str(), GA_ReadOnly );
+  if(m_gds == NULL){
+    string errorString="FileOpenError";
+    throw(errorString);
+  }
+  m_ncol= m_gds->GetRasterXSize();
+  m_nrow= m_gds->GetRasterYSize();
+  m_nband= m_gds->GetRasterCount();
+  m_isGeoRef=( static_cast<string>(m_gds->GetProjectionRef())  != "" );
+  // m_magic_x=magicX;
+  // m_magic_y=magicY;
+  if(m_isGeoRef){
+    double adfGeoTransform[6];
+    if( m_gds->GetGeoTransform( adfGeoTransform ) == CE_None )
+    {
+      m_ulx=adfGeoTransform[0];
+      m_uly=adfGeoTransform[3];
+      m_delta_x=adfGeoTransform[1];
+      m_delta_y=-adfGeoTransform[5];
+    }
+  }
+  else{
+    m_ulx=0;
+    m_uly=nrOfRow();
+    m_delta_x=1;
+    m_delta_y=1;
+  }
+}
+
+string ImgReaderGdal::getProjection(void) const 
+{
+  string theProjection=m_gds->GetProjectionRef();
+  // size_t startpos,endpos;
+  // while((startpos=theProjection.find(",AUTHORITY"))!=string::npos){
+  //   endpos=theProjection.find("]",startpos+1,1)+1;
+  //   theProjection.erase(startpos,endpos-startpos);
+  // }
+  return theProjection;
+}
+
+string ImgReaderGdal::getProjectionRef(void) const 
+{
+  string theProjection;
+  if(m_gds->GetProjectionRef())
+    return(m_gds->GetProjectionRef());
+  else
+    return "";
+}
+
+GDALDataType ImgReaderGdal::getDataType(int band) const
+{
+  assert(band<m_nband+1);
+  return (m_gds->GetRasterBand(band+1))->GetRasterDataType();
+}
+
+GDALRasterBand* ImgReaderGdal::getRasterBand(int band)
+{
+  assert(band<m_nband+1);
+  return (m_gds->GetRasterBand(band+1));
+}
+
+GDALColorTable* ImgReaderGdal::getColorTable(int band) const
+{
+  assert(band<m_nband+1);
+  return (m_gds->GetRasterBand(band+1))->GetColorTable();
+}
+
+string ImgReaderGdal::getDriverDescription() const
+{
+  return m_gds->GetDriver()->GetDescription();
+}
+
+void ImgReaderGdal::getGeoTransform(double& ulx, double& uly, double& deltaX, double& deltaY, double& rot1, double& rot2) const
+{
+  double adfGeoTransform[6];// { 444720, 30, 0, 3751320, 0, -30 };
+  m_gds->GetGeoTransform(adfGeoTransform);
+  ulx=adfGeoTransform[0];
+  deltaX=adfGeoTransform[1];
+  rot1=adfGeoTransform[2];
+  uly=adfGeoTransform[3];
+  rot2=adfGeoTransform[4];
+  deltaY=-adfGeoTransform[5];//convention of GDAL!
+}
+
+string ImgReaderGdal::getGeoTransform() const
+{
+  if(!isGeoRef())
+    return("");
+  else{
+    double adfGeoTransform[6];// { 444720, 30, 0, 3751320, 0, -30 };
+    m_gds->GetGeoTransform(adfGeoTransform);
+    double ulx=adfGeoTransform[0];
+    double deltaX=adfGeoTransform[1];
+    double rot1=adfGeoTransform[2];
+    double uly=adfGeoTransform[3];
+    double rot2=adfGeoTransform[4];
+    double deltaY=-adfGeoTransform[5];//convention of GDAL!
+    ostringstream s;
+    s << "[" << ulx << "," << deltaX << "," << rot1 << "," << uly << "," << rot2 << "," << -deltaY << "]";
+    return(s.str());
+  }
+}
+
+char** ImgReaderGdal::getMetadata()
+{
+  if(m_gds->GetMetadata()!=NULL)
+    return(m_gds->GetMetadata());
+  else
+    return (char**)"";
+}
+
+char** ImgReaderGdal::getMetadata() const
+{
+  if(m_gds->GetMetadata()!=NULL)
+    return(m_gds->GetMetadata());
+  else 
+    return (char**)"";
+}
+
+void ImgReaderGdal::getMetadata(list<string>& metadata) const
+{
+  char** cmetadata=m_gds->GetMetadata();
+  while(*cmetadata!=NULL){
+    metadata.push_back(*(cmetadata));
+    ++cmetadata;
+  }
+}
+
+string ImgReaderGdal::getDescription() const
+{
+  if(m_gds->GetDriver()->GetDescription()!=NULL)
+    return m_gds->GetDriver()->GetDescription();
+  else
+    return "";
+}
+
+string ImgReaderGdal::getMetadataItem() const 
+{
+  if(m_gds->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME )!=NULL)
+    return m_gds->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME );
+  else
+    return "";
+}
+string ImgReaderGdal::getImageDescription() const 
+{
+  if(m_gds->GetDriver()->GetMetadataItem("TIFFTAG_IMAGEDESCRIPTION")!=NULL)
+    return m_gds->GetDriver()->GetMetadataItem("TIFFTAG_IMAGEDESCRIPTION");
+  else
+    return "";
+}
+
+string ImgReaderGdal::getInterleave() const
+{
+  if(m_gds->GetMetadataItem( "INTERLEAVE", "IMAGE_STRUCTURE"))
+    return m_gds->GetMetadataItem( "INTERLEAVE", "IMAGE_STRUCTURE");
+  else
+    return("BAND");
+}
+
+string ImgReaderGdal::getCompression() const
+{
+  if(m_gds->GetMetadataItem( "COMPRESSION", "IMAGE_STRUCTURE"))
+    return m_gds->GetMetadataItem( "COMPRESSION", "IMAGE_STRUCTURE");
+  else
+    return("NONE");
+}
+
+bool ImgReaderGdal::getBoundingBox(double& ulx, double& uly, double& lrx, double& lry) const
+{
+  if(m_isGeoRef){
+    //    ulx=m_ulx-(m_magic_x-1.0)*m_delta_x;
+    //    uly=m_uly+(m_magic_y-1.0)*m_delta_y;
+    ulx=m_ulx;
+    uly=m_uly;
+    lrx=ulx+nrOfCol()*m_delta_x;
+    lry=uly-nrOfRow()*m_delta_y;
+    return true;
+  }
+  else{
+    ulx=0;
+    uly=nrOfRow()-1;
+    lrx=nrOfCol()-1;
+    lry=0;
+    return false;
+  }
+}
+
+bool ImgReaderGdal::getCentrePos(double& x, double& y) const
+{
+  if(m_isGeoRef){
+//     x=m_ulx+(nrOfCol()/2.0-(m_magic_x-1.0))*m_delta_x;
+//     y=m_uly-(nrOfRow()/2.0-(m_magic_y-1.0))*m_delta_y;
+    x=m_ulx+(nrOfCol()/2.0)*m_delta_x;
+    y=m_uly-(nrOfRow()/2.0)*m_delta_y;
+    return true;
+  }
+  else{
+    x=nrOfCol()/2.0;
+    y=nrOfRow()/2.0;
+    return false;
+  }
+}
+
+//i and j represent fraction of pixels, return true if image is georeferenced
+bool ImgReaderGdal::geo2image(double x, double y, double& i, double& j) const
+{
+  //double values are returned, caller is responsible for interpolation step
+  if(m_isGeoRef){
+//     double ulx=m_ulx-(m_magic_x-1.0)*m_delta_x;
+//     double uly=m_uly+(m_magic_y-1.0)*m_delta_y;
+    double ulx=m_ulx;
+    double uly=m_uly;
+    i=(x-ulx)/m_delta_x;
+    j=(uly-y)/m_delta_y;
+    return true;
+  }
+  else{
+    i=x;
+    j=nrOfRow()-y;
+    return false;
+  }
+}
+
+//x and y represent centre of pixel, return true if image is georeferenced
+bool ImgReaderGdal::image2geo(double i, double j, double& x, double& y) const
+{
+  if(m_isGeoRef){
+//     x=m_ulx+(1.5-m_magic_x+i)*m_delta_x;
+//     y=m_uly-(1.5-m_magic_y+j)*m_delta_y;
+    x=m_ulx+(0.5+i)*m_delta_x;
+    y=m_uly-(0.5+j)*m_delta_y;
+    return true;
+  }
+  else{
+    x=0.5+i;
+    y=nrOfRow()-(0.5+j);
+    return false;
+  }
+}
+
+bool ImgReaderGdal::covers(double x, double  y) const
+{
+  double theULX, theULY, theLRX, theLRY;
+  getBoundingBox(theULX,theULY,theLRX,theLRY);
+  return((x > theULX)&&
+         (x < theLRX)&&
+         (y < theULY)&&
+         (y >theLRY));
+}
+
+bool ImgReaderGdal::covers(double ulx, double  uly, double lrx, double lry) const
+{
+  double theULX, theULY, theLRX, theLRY;
+  getBoundingBox(theULX,theULY,theLRX,theLRY);
+  return((ulx < theLRX)&&(lrx > theULX)&&(lry < theULY)&&(uly > theLRY));
+}
+
+double ImgReaderGdal::getMin(int& x, int& y, int band) const{
+  double minValue=0;
+  vector<double> lineBuffer(nrOfCol());
+  for(int irow=0;irow<nrOfRow();++irow){
+    readData(lineBuffer,GDT_Float64,irow,band);
+    if(!irow)//initialize
+      minValue=lineBuffer[0];
+    for(int icol=0;icol<nrOfCol();++icol){
+      if(minValue>lineBuffer[icol]){
+        y=irow;
+        x=icol;
+        minValue=lineBuffer[icol];
+      }
+    }
+  }
+  return minValue;
+}
+
+double ImgReaderGdal::getMax(int& x, int& y, int band) const{
+  double maxValue=0;
+  vector<double> lineBuffer(nrOfCol());
+  for(int irow=0;irow<nrOfRow();++irow){
+    readData(lineBuffer,GDT_Float64,irow,band);
+    if(!irow)//initialize
+      maxValue=lineBuffer[0];
+    for(int icol=0;icol<nrOfCol();++icol){
+      if(maxValue<lineBuffer[icol]){
+        y=irow;
+        x=icol;
+        maxValue=lineBuffer[icol];
+      }
+    }
+  }
+  return maxValue;
+}
+
+void ImgReaderGdal::getMinMax(double& minValue, double& maxValue, int band, bool exhaustiveSearch) const
+{
+  GDALRasterBand  *poBand;
+  int             bGotMin, bGotMax;
+  double          adfMinMax[2];
+        
+  poBand = m_gds->GetRasterBand(band+1);
+  adfMinMax[0] = poBand->GetMinimum( &bGotMin );
+  adfMinMax[1] = poBand->GetMaximum( &bGotMax );
+  if( ! (bGotMin && bGotMax) )
+    GDALComputeRasterMinMax((GDALRasterBandH)poBand, FALSE, adfMinMax);
+    // GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
+  minValue=adfMinMax[0];
+  maxValue=adfMinMax[1];
+  if(exhaustiveSearch){//force exhaustive search
+    vector<double> lineBuffer(nrOfCol());
+    for(int irow=0;irow<nrOfRow();++irow){
+      readData(lineBuffer,GDT_Float64,irow,band);
+      for(int icol=0;icol<nrOfCol();++icol){
+	if(minValue>lineBuffer[icol])
+	  minValue=lineBuffer[icol];
+	if(maxValue<lineBuffer[icol])
+	  maxValue=lineBuffer[icol];
+      }
+    }
+  }
+}
+
+void ImgReaderGdal::getRange(vector<short>& range, int band) const
+{
+  vector<short> lineBuffer(nrOfCol());
+  range.clear();
+  for(int irow=0;irow<nrOfRow();++irow){
+    readData(lineBuffer,GDT_Int16,irow,band);
+    for(int icol=0;icol<nrOfCol();++icol){
+      if(find(range.begin(),range.end(),lineBuffer[icol])==range.end())
+        range.push_back(lineBuffer[icol]);
+    }
+  }
+  sort(range.begin(),range.end());
+}
+
+int ImgReaderGdal::getNoDataValues(vector<double>& noDataValues, int band) const
+{
+  if(m_noDataValues.size()){
+    noDataValues=m_noDataValues;
+    return m_noDataValues.size();
+  }
+  else
+    return 0;
+}
+
+int ImgReaderGdal::pushNoDataValue(double noDataValue, int band)
+{
+  if(find(m_noDataValues.begin(),m_noDataValues.end(),noDataValue)==m_noDataValues.end())
+    m_noDataValues.push_back(noDataValue);
+  return(m_noDataValues.size());
+}
+
+// bool ImgReaderGdal::setNoDataValue(double noDataValue,int band)
+// {
+//   GDALRasterBand  *poBand;
+//   poBand = m_gds->GetRasterBand(band+1);
+//   if(poBand->SetNoDataValue(noDataValue)!=CE_None)
+//     return false;
+//   else
+//     return true;
+// }
+
+void ImgReaderGdal::getRefPix(double& refX, double &refY, int band) const
+{
+  vector<double> lineBuffer(nrOfCol());
+  double validCol=0;
+  double validRow=0;
+  int nvalidCol=0;
+  int nvalidRow=0;
+  for(int irow=0;irow<nrOfRow();++irow){
+    readData(lineBuffer,GDT_Float64,irow,band);
+    for(int icol=0;icol<nrOfCol();++icol){
+      bool valid=(find(m_noDataValues.begin(),m_noDataValues.end(),lineBuffer[icol])==m_noDataValues.end());
+      if(valid){
+        validCol+=icol+1;
+        ++nvalidCol;
+        validRow+=irow+1;
+        ++nvalidRow;
+      }
+    }
+  }
+  if(isGeoRef()){
+    //reference coordinate is lower left corner of pixel in centre of gravity
+    //we need geo coordinates for exactly this location: validCol(Row)/nvalidCol(Row)-0.5
+    double cgravi=validCol/nvalidCol-0.5;
+    double cgravj=validRow/nvalidRow-0.5;
+    double refpixeli=floor(cgravi);
+    double refpixelj=ceil(cgravj-1);
+    //but image2geo provides location at centre of pixel (shifted half pixel right down)
+    image2geo(refpixeli,refpixelj,refX,refY);
+    //refX and refY now refer to centre of gravity pixel
+    refX-=0.5*getDeltaX();//shift to left corner
+    refY-=0.5*getDeltaY();//shift to lower left corner
+  }
+  else{
+    refX=floor(validCol/nvalidCol-0.5);//left corner
+    refY=floor(validRow/nvalidRow-0.5);//upper corner
+    //shift to lower left corner of pixel
+    refY+=1;
+      
+  }
+}
diff --git a/src/imageclasses/ImgReaderGdal.h b/src/imageclasses/ImgReaderGdal.h
new file mode 100644
index 0000000..7580b4a
--- /dev/null
+++ b/src/imageclasses/ImgReaderGdal.h
@@ -0,0 +1,247 @@
+/**********************************************************************
+ImgReaderGdal.h: class to read raster files using GDAL API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _IMGREADERGDAL_H_
+#define _IMGREADERGDAL_H_
+
+#include <assert.h>
+#include <fstream>
+#include <string>
+#include <sstream>
+#include "gdal_priv.h"
+#include "base/Vector2d.h"
+
+using namespace std;
+
+enum RESAMPLE { NEAR = 0, BILINEAR = 1, BICUBIC = 2 };
+
+//--------------------------------------------------------------------------
+class ImgReaderGdal
+{
+public:
+  ImgReaderGdal(void);
+  ImgReaderGdal(const string& filename){open(filename);};
+  ~ImgReaderGdal(void);
+  void open(const string& filename);//, double magicX=1, double magicY=1);
+  void close(void);
+  int nrOfCol(void) const { return m_ncol;};
+  int nrOfRow(void) const { return m_nrow;};
+  int nrOfBand(void) const { return m_nband;};
+  bool isGeoRef() const {return m_isGeoRef;};
+  string getProjection(void) const;
+  string getProjectionRef(void) const;
+  string getGeoTransform() const;
+  void getGeoTransform(double& ulx, double& uly, double& deltaX, double& deltaY, double& rot1, double& rot2) const;
+  string getDescription() const;
+  string getMetadataItem() const;
+  string getImageDescription() const;
+  bool getBoundingBox (double& ulx, double& uly, double& lrx, double& lry) const;
+  bool getCentrePos(double& x, double& y) const;
+  double getUlx() const {return (m_isGeoRef)? m_ulx : 0;};
+  double getUly() const {return (m_isGeoRef)? m_uly : nrOfRow()-1;};
+  double getLrx() const {return (m_isGeoRef)? m_ulx+nrOfCol()*m_delta_x : nrOfCol()-1;};
+  double getLry() const {return (m_isGeoRef)? m_uly-nrOfRow()*m_delta_y : 0;};
+  // bool getMagicPixel(double& magicX, double& magicY) const {magicX=m_magic_x;magicY=m_magic_y;};
+  int getNoDataValues(vector<double>& noDataValues, int band=0) const;
+  int pushNoDataValue(double noDataValue,int band=0);
+  bool covers(double x, double y) const;
+  bool covers(double ulx, double  uly, double lrx, double lry) const;
+  bool geo2image(double x, double y, double& i, double& j) const;
+  bool image2geo(double i, double j, double& x, double& y) const;
+  double getDeltaX(void) const {return m_delta_x;};
+  double getDeltaY(void) const {return m_delta_y;};
+  template<typename T> void readData(T& value, const GDALDataType& dataType, int col, int row, int band=0) const;
+  template<typename T> void readData(vector<T>& buffer, const GDALDataType& dataType , int minCol, int maxCol, int row, int band=0) const;
+  template<typename T> void readData(vector<T>& buffer, const GDALDataType& dataType , int minCol, int maxCol, double row, int band=0, RESAMPLE resample=0) const;
+  template<typename T> void readDataBlock(Vector2d<T>& buffer, const GDALDataType& dataType , int minCol, int maxCol, int minRow, int maxRow, int band=0) const;
+  template<typename T> void readDataBlock(vector<T>& buffer, const GDALDataType& dataType , int minCol, int maxCol, int minRow, int maxRow, int band=0) const;
+  template<typename T> void readData(vector<T>& buffer, const GDALDataType& dataType, int row, int band=0) const;
+  template<typename T> void readData(vector<T>& buffer, const GDALDataType& dataType, double row, int band=0, RESAMPLE resample=0) const;
+  void getMinMax(double& minValue, double& maxValue, int band=0, bool exhaustiveSearch=false) const;
+  double getMin(int& col, int& row, int band=0) const;
+  double getMax(int& col, int& row, int band=0) const;
+  void getRefPix(double& refX, double &refY, int band=0) const;
+  void getRange(vector<short>& range, int Band=0) const;
+  GDALDataType getDataType(int band=0) const;
+  GDALRasterBand* getRasterBand(int band=0);
+  GDALColorTable* getColorTable(int band=0) const;
+  string getDriverDescription() const;
+  string getImageType() const{return getDriverDescription();};
+//   string getImageType() const{return "GTiff";};
+  string getInterleave() const;
+  string getCompression() const;
+  GDALDataset* getDataset(){return m_gds;};
+  char** getMetadata();
+  char** getMetadata() const;
+  void getMetadata(list<string>& metadata) const;
+
+protected:
+  void setCodec();//double magicX, double magicY);
+
+  string m_filename;
+  GDALDataset *m_gds;
+  int m_ncol;
+  int m_nrow;
+  int m_nband;
+  double m_ulx;
+  double m_uly;
+  double m_delta_x;
+  double m_delta_y;
+  // double m_magic_x;
+  // double m_magic_y;
+  bool m_isGeoRef;
+  vector<double> m_noDataValues;
+};
+
+//     adfGeoTransform[0] /* top left x */
+//     adfGeoTransform[1] /* w-e pixel resolution */
+//     adfGeoTransform[2] /* rotation, 0 if image is "north up" */
+//     adfGeoTransform[3] /* top left y */
+//     adfGeoTransform[4] /* rotation, 0 if image is "north up" */
+//     adfGeoTransform[5] /* n-s pixel resolution */
+
+template<typename T> void ImgReaderGdal::readData(T& value, const GDALDataType& dataType, int col, int row, int band) const
+{
+  //fetch raster band
+  GDALRasterBand  *poBand;
+  assert(band<nrOfBand()+1);
+  poBand = m_gds->GetRasterBand(band+1);//GDAL uses 1 based index
+  assert(col<nrOfCol());
+  assert(col>=0);
+  assert(row<nrOfRow());
+  assert(row>=0);
+  poBand->RasterIO(GF_Read,col,row,1,1,&value,1,1,dataType,0,0);
+}
+
+template<typename T> void ImgReaderGdal::readData(vector<T>& buffer, const GDALDataType& dataType, int minCol, int maxCol, int row, int band) const
+{
+  //fetch raster band
+  GDALRasterBand  *poBand;
+  assert(band<nrOfBand()+1);
+  poBand = m_gds->GetRasterBand(band+1);//GDAL uses 1 based index
+  assert(minCol<nrOfCol());
+  assert(minCol>=0);
+  assert(maxCol<nrOfCol());
+  assert(minCol<=maxCol);
+  assert(row<nrOfRow());
+  assert(row>=0);
+  if(buffer.size()!=maxCol-minCol+1)
+    buffer.resize(maxCol-minCol+1);
+  poBand->RasterIO(GF_Read,minCol,row,buffer.size(),1,&(buffer[0]),buffer.size(),1,dataType,0,0);
+}
+
+template<typename T> void ImgReaderGdal::readData(vector<T>& buffer, const GDALDataType& dataType , int minCol, int maxCol, double row, int band, RESAMPLE resample) const
+{
+  vector<T> readBuffer_upper;
+  vector<T> readBuffer_lower;
+  if(buffer.size()!=maxCol-minCol+1)
+    buffer.resize(maxCol-minCol+1);
+  double upperRow=row-0.5;
+  upperRow=static_cast<int>(upperRow);
+  double lowerRow=row+0.5;
+  lowerRow=static_cast<int>(lowerRow);
+  switch(resample){
+  case(BILINEAR):
+    if(lowerRow>=nrOfRow())
+      lowerRow=nrOfRow()-1;
+    if(upperRow<0)
+      upperRow=0;
+    readData(readBuffer_upper,GDT_Float64,minCol,maxCol,static_cast<int>(upperRow),band);
+    readData(readBuffer_lower,GDT_Float64,minCol,maxCol,static_cast<int>(lowerRow),band);
+    //do interpolation in y
+    for(int icol=0;icol<maxCol-minCol+1;++icol){
+      buffer[icol]=(lowerRow-row+0.5)*readBuffer_upper[icol]+(1-lowerRow+row-0.5)*readBuffer_lower[icol];
+    }
+    break;
+  default:
+    readData(buffer,GDT_Float64,minCol,maxCol,static_cast<int>(row),band);
+    break;
+  }
+}
+
+template<typename T> void ImgReaderGdal::readDataBlock(Vector2d<T>& buffer, const GDALDataType& dataType , int minCol, int maxCol, int minRow, int maxRow, int band) const
+{
+  buffer.resize(maxRow-minRow+1);
+  for(int irow=minRow;irow<=maxRow;++irow){
+    buffer[irow-minRow].resize(maxCol-minCol+1);
+    readData(buffer[irow-minRow],dataType,minCol,maxCol,irow,band);
+  }
+}
+  
+template<typename T> void ImgReaderGdal::readDataBlock(vector<T>& buffer, const GDALDataType& dataType , int minCol, int maxCol, int minRow, int maxRow, int band) const
+{
+  //fetch raster band
+  GDALRasterBand  *poBand;
+  assert(band<nrOfBand()+1);
+  poBand = m_gds->GetRasterBand(band+1);//GDAL uses 1 based index
+  assert(minCol<nrOfCol());
+  assert(minCol>=0);
+  assert(maxCol<nrOfCol());
+  assert(minCol<=maxCol);
+  assert(minRow<nrOfRow());
+  assert(minRow>=0);
+  assert(maxRow<nrOfRow());
+  assert(minRow<=maxRow);
+  if(buffer.size()!=(maxRow-minRow+1)*(maxCol-minCol+1))
+    buffer.resize((maxRow-minRow+1)*(maxCol-minCol+1));
+  poBand->RasterIO(GF_Read,minCol,minRow,maxCol-minCol+1,maxRow-minRow+1,&(buffer[0]),(maxCol-minCol+1),(maxRow-minRow+1),dataType,0,0);
+}
+
+// template<typename T> void ImgReaderGdal::readDataBlock(vector<T>& buffer, const GDALDataType& dataType , int minCol, int maxCol, int minRow, int maxRow, int band) const
+// {
+//   assert(band<nrOfBand()+1);
+//   assert(minCol<nrOfCol());
+//   assert(minCol>=0);
+//   assert(maxCol<nrOfCol());
+//   assert(minCol<=maxCol);
+//   assert(minRow<nrOfRow());
+//   assert(minRow>=0);
+//   assert(maxRow<nrOfRow());
+//   assert(minRow<=maxRow);
+//   if(buffer.size()!=(maxRow-minRow+1)*(maxCol-minCol+1))
+//     buffer.resize((maxRow-minRow+1)*(maxCol-minCol+1));
+//   //fetch raster band
+//   GDALRasterBand  *poBand;
+//   assert(band<nrOfBand()+1);
+//   poBand = m_gds->GetRasterBand(band+1);//GDAL uses 1 based index
+//   for(int irow=0;irow<maxRow-minRow+1;++irow)
+//     poBand->RasterIO(GF_Read,minCol,minRow+irow,maxCol-minCol+1,1,&(buffer[irow*(maxCol-minCol+1)]),maxCol-minCol+1,1,dataType,0,0);
+// }
+  
+template<typename T> void ImgReaderGdal::readData(vector<T>& buffer, const GDALDataType& dataType, int row, int band) const
+{
+  readData(buffer,dataType,0,nrOfCol()-1,row,band);
+}
+
+template<typename T> void ImgReaderGdal::readData(vector<T>& buffer, const GDALDataType& dataType, double row, int band, RESAMPLE resample) const
+{
+  readData(buffer,dataType,0,nrOfCol()-1,row,band,resample);
+}
+
+
+#endif // _IMGREADERGDAL_H_
+
+//       //fetch raster band
+//   GDALRasterBand  *poBand;
+//   assert(band<nrOfBand()+1);
+//   poBand = m_gds->GetRasterBand(band+1);//GDAL uses 1 based index
+//   buffer.resize(maxCol-minCol+1);
+//   assert(minCol<nrOfCol());
+//   assert(row<nrOfRow());
+//   poBand->RasterIO(GF_Read,minCol,row,buffer.size(),1,&(buffer[0]),buffer.size(),1,GDT_Int16,0,0);
diff --git a/src/imageclasses/ImgReaderOgr.cc b/src/imageclasses/ImgReaderOgr.cc
new file mode 100644
index 0000000..bf09509
--- /dev/null
+++ b/src/imageclasses/ImgReaderOgr.cc
@@ -0,0 +1,230 @@
+/**********************************************************************
+ImgReaderOgr.cc: class to read vector files using OGR API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <iostream>
+#include <fstream>
+#include "ImgReaderOgr.h"
+#include "ImgWriterOgr.h"
+#include "cpl_string.h"
+//---------------------------------------------------------------------------
+ImgReaderOgr::ImgReaderOgr(void)
+{}
+
+ImgReaderOgr::ImgReaderOgr(const string& filename)
+{
+  open(filename);
+}
+
+ImgReaderOgr::~ImgReaderOgr(void)
+{
+}
+
+//---------------------------------------------------------------------------
+
+void ImgReaderOgr::open(const string& filename)
+{
+  m_filename = filename;
+  setCodec();
+}
+
+//---------------------------------------------------------------------------
+void ImgReaderOgr::close(void)
+{
+  OGRDataSource::DestroyDataSource(m_datasource);
+}
+
+//---------------------------------------------------------------------------
+void ImgReaderOgr::setCodec(void){
+  //register the drivers
+  OGRRegisterAll();
+  //open the input OGR datasource. Datasources can be files, RDBMSes, directories full of files, or even remote web services depending on the driver being used. However, the datasource name is always a single string.
+  m_datasource = OGRSFDriverRegistrar::Open(m_filename.c_str(), FALSE);//FAlSE: do not update
+  if( m_datasource == NULL ){
+    string errorString="Open failed";
+    throw(errorString);
+  }
+}
+
+bool ImgReaderOgr::getExtent(double& ulx, double& uly, double& lrx, double& lry, int layer)
+{
+  OGREnvelope oExt;
+  if(getLayer(layer)->GetExtent(&oExt,TRUE)==OGRERR_NONE){
+    ulx=oExt.MinX;
+    uly=oExt.MaxY;
+    lrx=oExt.MaxX;
+    lry=oExt.MinY;
+    return true;
+  }
+  else
+    return false;
+}
+
+unsigned long int ImgReaderOgr::getFeatureCount(int layer) const
+{
+  return(m_datasource->GetLayer(layer)->GetFeatureCount());
+}
+
+int ImgReaderOgr::getFieldCount(int layer) const
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if((poLayer = m_datasource->GetLayer(layer))==NULL){
+    string errorstring="Could not get layer";
+    throw(errorstring);
+  }
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  return(poFDefn->GetFieldCount());
+}
+
+int ImgReaderOgr::getFields(vector<string>& fields, int layer) const
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if((poLayer = m_datasource->GetLayer(layer))==NULL){
+    string errorstring="Could not get layer";
+    throw(errorstring);
+  }
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  fields.clear();
+  fields.resize(poFDefn->GetFieldCount());
+  for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+    OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+    fields[iField]=poFieldDefn->GetNameRef();
+  }
+  return(fields.size());
+}
+
+int ImgReaderOgr::getFields(vector<OGRFieldDefn*>& fields, int layer) const
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if((poLayer = m_datasource->GetLayer(layer))==NULL){
+    string errorstring="Could not get layer";
+    throw(errorstring);
+  }
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  fields.clear();
+  fields.resize(poFDefn->GetFieldCount());
+  for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+    OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+    fields[iField]=poFDefn->GetFieldDefn(iField);
+  }
+  assert(fields.size()==getFieldCount());
+  return(fields.size());
+}
+
+string ImgReaderOgr::getProjection(int layer) const
+{
+  if(m_datasource->GetLayer(layer)->GetSpatialRef()){
+    char* ppszResult;
+    m_datasource->GetLayer(layer)->GetSpatialRef()->exportToWkt(&ppszResult);
+    return(ppszResult);
+  }
+  else
+    return "";
+}
+
+OGRwkbGeometryType ImgReaderOgr::getGeometryType(int layer) const
+{
+  return m_datasource->GetLayer(layer)->GetLayerDefn()->GetGeomType();
+}
+
+ostream& operator<<(ostream& theOstream, ImgReaderOgr& theImageReader){
+  //An OGRDataSource can potentially have many layers associated with it. The number of layers available can be queried with OGRDataSource::GetLayerCount() and individual layers fetched by index using OGRDataSource::GetLayer(). However, we wil just fetch the layer by name.
+  //todo: try to open and catch if failure...
+  // ofstream fpoints(filename.c_str(),ios::out);
+  OGRLayer  *poLayer;
+  poLayer = theImageReader.getDataSource()->GetLayer(0);
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+
+  poLayer->ResetReading();
+
+  theOstream << "#";
+  int iField=0;
+  theOstream << "X" << " " << "Y" << " ";
+  // theOstream << poFDefn->GetFieldDefn(iField)->GetNameRef() << " ";
+  for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+      OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+      string fieldname=poFieldDefn->GetNameRef();
+      theOstream << fieldname << " ";
+  }
+  theOstream << std::endl;
+
+  poLayer->ResetReading();
+  
+  //start reading features from the layer
+  OGRFeature *poFeature;
+  unsigned long int ifeature=0;
+  while( (poFeature = poLayer->GetNextFeature()) != NULL ){
+    OGRGeometry *poGeometry;
+    poGeometry = poFeature->GetGeometryRef();
+    // if(verbose){
+    //   if(!poGeometry)
+    //     cerr << "no geometry defined" << endl << flush;
+    //   else if(wkbFlatten(poGeometry->getGeometryType()) != wkbPoint)
+    //     cerr << "poGeometry type: " << wkbFlatten(poGeometry->getGeometryType()) << endl << flush;
+    // }
+    assert(poGeometry != NULL 
+           && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+    OGRPoint *poPoint = (OGRPoint *) poGeometry;
+    double x=poPoint->getX();
+    double y=poPoint->getY();
+    vector<string> vfields(poFDefn->GetFieldCount());
+    string featurename;
+    vector<string>::iterator fit=vfields.begin();
+    for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+      // OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+      // string fieldname=poFieldDefn->GetNameRef();
+      // if(fieldname==pointname)
+      //   featurename=poFeature->GetFieldAsString(iField);
+      // else
+      *(fit++)=poFeature->GetFieldAsString(iField);
+    }
+//     theOstream << ifeature << " " << featurename << " " << x << " " << y;
+    theOstream.precision(12);
+    // theOstream << featurename << " " << x << " " << y;
+    theOstream << x << " " << y;
+    for(fit=vfields.begin();fit!=vfields.end();++fit)
+      theOstream << " " << *fit;
+    theOstream << endl;
+    ++ifeature;
+  }
+  // theOstream.close();
+  return(theOstream);
+}
+
+// OGRLayer * ImgReaderOgr::executeSql(const string& output, const string& sqlStatement, OGRGeometry* spatialFilter)
+// {
+//   OGRLayer *poResultSet;
+//   poResultSet = m_datasource->ExecuteSQL(sqlStatement.c_str(), spatialFilter,NULL );
+
+//   if( poResultSet != NULL ){
+//     ImgWriterOgr imgWriter;
+//     imgWriter.open(output);
+//     imgWriter.copyLayer(poResultSet,output);
+//     m_datasource->ReleaseResultSet( poResultSet );
+//     imgWriter.close();
+//   }
+// }
diff --git a/src/imageclasses/ImgReaderOgr.h b/src/imageclasses/ImgReaderOgr.h
new file mode 100644
index 0000000..5863420
--- /dev/null
+++ b/src/imageclasses/ImgReaderOgr.h
@@ -0,0 +1,718 @@
+/**********************************************************************
+ImgReaderOgr.h: class to read vector files using OGR API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _IMGREADEROGR_H_
+#define _IMGREADEROGR_H_
+
+#include <assert.h>
+#include <fstream>
+#include <string>
+#include <sstream>
+#include <map>
+#include <vector>
+#include <iostream>
+#include "ogrsf_frmts.h"
+#include "base/Vector2d.h"
+#include "ImgReaderGdal.h"
+
+using namespace std;
+
+//--------------------------------------------------------------------------
+class ImgReaderOgr
+{
+public:
+  ImgReaderOgr(void);
+  ImgReaderOgr(const string& filename);
+  ~ImgReaderOgr(void);
+  void open(const string& filename);
+  void close(void);
+  //   int readData(Vector2d<double>& data, const OGRFieldType& fieldType, vector<string>& fields, int layer=0, bool pos=false);//default layer 0 and no pos information in data
+  template <typename T> int readXY(vector<T>& xVector, vector<T>& yVector, int layer=0, bool verbose=false);
+  template <typename T> int readY(vector<T>& yVector, int layer=0, bool verbose=false);
+  template <typename T> int readData(vector<T>& data, const OGRFieldType& fieldType, vector<string>& fields, OGRFeature *poFeature, int layer=0, bool pos=false, bool verbose=false);
+  template <typename T> int readData(vector<T>& data, const OGRFieldType& fieldType, const string& theField, int layer=0, bool verbose=false);
+  template <typename T> int readData(Vector2d<T>& data, const OGRFieldType& fieldType, vector<string>& fields, int layer=0, bool pos=false, bool verbose=false);//default layer 0 and no pos information in data
+  template <typename T> int readData(map<int,Vector2d<T> >& data, const OGRFieldType& fieldType, vector<string>& fields, const string& label, int layer=0, bool pos=false, bool verbose=false);//default layer 0 and no pos information in data
+  void shape2ascii(ostream& theOstream, const string& pointname, int layer=0, bool verbose=false);
+  unsigned long int getFeatureCount(int layer=0) const;
+  int getFieldCount(int layer=0) const;
+  OGRLayer* getLayer(int layer=0){return m_datasource->GetLayer(layer);};
+  string getProjection(int layer=0) const;
+  OGRwkbGeometryType getGeometryType(int layer=0) const;
+  string getLayerName(int layer=0){return m_datasource->GetLayer(layer)->GetLayerDefn()->GetName();};
+  //  int getLayer(int layer=0) const;
+  int getFields(vector<string>& fields, int layer=0) const;
+  int getFields(vector<OGRFieldDefn*>& fields, int layer=0) const;
+  OGRDataSource* getDataSource(void) {return m_datasource;};
+  OGRSFDriver* getDriver(void) const {return m_datasource->GetDriver();};
+//   OGRLayer *executeSql(const string& output,const string& sqlStatement, OGRGeometry* spatialFilter=NULL);
+  template<typename T> int readSql(Vector2d<T>& data, const OGRFieldType& fieldType, vector<string>& fields, const string& sqlStatement, OGRGeometry* spatialFilter=NULL, int layer=0, bool pos=false, bool verbose=false);
+  template<typename T> int readSql(map<int,Vector2d<T> >& data, const OGRFieldType& fieldType, vector<string>& fields, const string& label, const string& sqlStatement, OGRGeometry* spatialFilter, int layer=0, bool pos=false, bool verbose=false);
+  bool getExtent(double& ulx, double& uly, double& lrx, double& lry, int layer=0);
+
+  friend ostream& operator<<(ostream& theOstream, ImgReaderOgr& theImageReader);
+  
+protected:
+  void setCodec(void);
+
+  string m_filename;
+  OGRDataSource *m_datasource;
+};
+
+//read data from all features in a map, organized by classes
+template <typename T> int ImgReaderOgr::readData(map<int,Vector2d<T> >& data, const OGRFieldType& fieldType, vector<string>& fields, const string& label, int layer, bool pos, bool verbose)
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if(verbose)
+    cout << "number of layers: " << m_datasource->GetLayerCount() << endl;
+  poLayer = m_datasource->GetLayer(layer);
+  if(poLayer!=NULL){
+    OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+    if(fields.empty()){
+      fields.resize(poFDefn->GetFieldCount());
+      if(verbose)
+        cout << "resized fields to " << fields.size() << endl;
+    }
+    //start reading features from the layer
+    OGRFeature *poFeature;
+    if(verbose)
+      cout << "reset reading" << endl;
+    poLayer->ResetReading();
+    unsigned long int ifeature=0;
+    int posOffset=(pos)?2:0;
+    if(verbose)
+      cout << "going through features" << endl << flush;
+    int theClass=0;
+    while( (poFeature = poLayer->GetNextFeature()) != NULL ){
+      vector<T> theFeature;//(fields.size()+posOffset);//x,y+selectedfields
+      if(verbose)
+        cout << "reading feature " << ifeature << endl << flush;
+      OGRGeometry *poGeometry;
+      poGeometry = poFeature->GetGeometryRef();
+      if(verbose){
+        if(poGeometry == NULL)
+          cerr << "no geometry defined" << endl << flush;
+        else if(wkbFlatten(poGeometry->getGeometryType()) != wkbPoint)
+          cerr << "Warning: poGeometry type: " << wkbFlatten(poGeometry->getGeometryType()) << endl << flush;
+      }
+      assert(poGeometry != NULL );
+             // && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+      OGRPoint *poPoint;
+      if(pos){
+        poPoint = (OGRPoint *) poGeometry;
+        if(wkbFlatten(poGeometry->getGeometryType()) == wkbPoint){
+        theFeature.push_back(poPoint->getX());
+        theFeature.push_back(poPoint->getY());
+        }
+        else if(wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon){
+          OGRPolygon * poPolygon = (OGRPolygon *) poGeometry;
+          poPolygon->Centroid(poPoint);
+          theFeature.push_back(poPoint->getX());
+          theFeature.push_back(poPoint->getY());
+        }        
+        else{
+          string errorstring="Error: Centroid for non polygon geometry not supported until OGR 1.8.0, change ImgReaderOgr if version >= 1.8.0 is installed...";
+            throw(errorstring);
+          // poGeometry->Centroid(poPoint);
+          // theFeature.push_back(poPoint->getX());
+          // theFeature.push_back(poPoint->getY());
+        }       
+      }
+      OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+      string featurename;
+      for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+        OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+        string fieldname=poFieldDefn->GetNameRef();
+        if(fieldname==label)
+          theClass=poFeature->GetFieldAsInteger(iField);
+        else{
+          switch(fieldType){
+          case(OFTReal):
+            if(fields.size()<poFDefn->GetFieldCount()){
+              if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+                theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+            }
+            else{
+              fields[iField]=fieldname;
+              theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+            }
+            break;
+          case(OFTInteger):
+            if(fields.size()<poFDefn->GetFieldCount()){
+              if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+                theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+            }
+            else{
+              fields[iField]=fieldname;
+              theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+            }
+            break;
+          default:
+            {
+              string errorstring="field type not supported in ImgReaderOgr::ReadData";
+              throw(errorstring);
+            }
+            break;
+          }
+        }
+      }
+      data[theClass].push_back(theFeature);
+      ++ifeature;
+      ++ifeature;
+    }
+    if(verbose)
+      cout << "number of features read: " << ifeature << endl << flush;
+    typename map<int,Vector2d<T> >::const_iterator mit=data.begin();
+    int nband=0;
+    if(verbose)
+      cout << "read classes: " << flush;
+    while(mit!=data.end()){
+      if(verbose)
+        cout << mit->first << " " << flush;
+      if(!nband)
+        nband=fields.size();
+      if(pos)
+        assert((mit->second)[0].size()==nband+2);
+      else
+        assert((mit->second)[0].size()==nband);
+      ++mit;
+    }
+    if(verbose)
+      cout << endl << flush;
+    return(nband);
+  }
+  else{
+    ostringstream ess;
+    ess << "no layer in " << m_filename;
+    throw(ess.str());
+  }
+}
+
+//read x positions
+template <typename T> int ImgReaderOgr::readXY(vector<T>& xVector, vector<T>& yVector, int layer, bool verbose){
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if(verbose)
+    cout << "number of layers: " << m_datasource->GetLayerCount() << endl;
+  poLayer = m_datasource->GetLayer(layer);
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  //start reading features from the layer
+  OGRFeature *poFeature;
+  if(verbose)
+    cout << "reset reading" << endl;
+  poLayer->ResetReading();
+  unsigned long int ifeature=0;
+  if(verbose)
+    cout << "going through features" << endl << flush;
+  while( (poFeature = poLayer->GetNextFeature()) != NULL ){
+    if(verbose)
+      cout << "reading feature " << ifeature << endl << flush;
+    OGRGeometry *poGeometry;
+    poGeometry = poFeature->GetGeometryRef();
+    if(verbose){
+      if(poGeometry == NULL)
+        cerr << "no geometry defined" << endl << flush;
+      else// if(wkbFlatten(poGeometry->getGeometryType()) != wkbPoint)
+        cout << "poGeometry type: " << wkbFlatten(poGeometry->getGeometryType()) << endl;
+    }
+    // assert(poGeometry != NULL 
+    //        && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+    OGRPoint *poPoint = (OGRPoint *) poGeometry;
+    xVector.push_back(poPoint->getX());
+    yVector.push_back(poPoint->getY());
+    ++ifeature;
+  }
+  assert(xVector.size()==yVector.size());
+  if(xVector.size()){
+    return xVector.size();
+  }
+  else{
+    ostringstream ess;
+    ess << "no layer in " << m_filename;
+    throw(ess.str());
+  }
+}
+
+//read data from a single feature
+template <typename T> int ImgReaderOgr::readData(vector<T>& data, const OGRFieldType& fieldType, vector<string>& fields, OGRFeature *poFeature, int layer, bool pos, bool verbose)
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if(verbose)
+    cout << "number of layers: " << m_datasource->GetLayerCount() << endl;
+  poLayer = m_datasource->GetLayer(layer);
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  if(fields.empty()){
+    fields.resize(poFDefn->GetFieldCount());
+    if(verbose)
+      cout << "resized fields to " << fields.size() << endl;
+  }
+  OGRGeometry *poGeometry;
+  poGeometry = poFeature->GetGeometryRef();
+  if(verbose){
+    if(poGeometry == NULL)
+      cerr << "no geometry defined" << endl << flush;
+    else if(wkbFlatten(poGeometry->getGeometryType()) != wkbPoint)
+      cerr << "poGeometry type: " << wkbFlatten(poGeometry->getGeometryType()) << endl << flush;
+  }
+  assert(poGeometry != NULL 
+         && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+  OGRPoint *poPoint = (OGRPoint *) poGeometry;
+  if(pos){
+    data.push_back(poPoint->getX());
+    data.push_back(poPoint->getY());
+  }
+  string featurename;
+  for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+    OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+    string fieldname=poFieldDefn->GetNameRef();
+    switch(fieldType){
+    case(OFTReal):
+      if(fields.size()<poFDefn->GetFieldCount()){
+        if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+          data.push_back(poFeature->GetFieldAsDouble(iField));
+      }
+      else{
+        fields[iField]=fieldname;
+        data.push_back(poFeature->GetFieldAsDouble(iField));
+      }
+      break;
+    case(OFTInteger):
+      if(fields.size()<poFDefn->GetFieldCount()){
+        if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+          data.push_back(poFeature->GetFieldAsDouble(iField));
+      }
+      else{
+        fields[iField]=fieldname;
+        data.push_back(poFeature->GetFieldAsDouble(iField));
+      }
+      break;
+    default:
+      {
+        string errorstring="field type not supported in ImgReaderOgr::ReadData";
+        throw(errorstring);
+      }
+      break;
+    }
+  }
+  //   assert(data.size()==ifeature);
+  if(data.size()){
+    if(pos)
+      assert(data.size()==fields.size()+2);
+    else
+      assert(data.size()==fields.size());
+    return fields.size();
+  }
+  else{
+    ostringstream ess;
+    ess << "no layer in " << m_filename;
+    throw(ess.str());
+  }
+}
+
+//read one field from all features
+template <typename T> int ImgReaderOgr::readData(vector<T>& data, const OGRFieldType& fieldType, const string& theField, int layer, bool verbose)
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if(verbose)
+    cout << "number of layers: " << m_datasource->GetLayerCount() << endl;
+  poLayer = m_datasource->GetLayer(layer);
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  int nfield=(theField!="")? poFDefn->GetFieldCount() : 1;
+  if(theField==""){
+    //read first field available 
+    if(verbose)
+      cout << "read first field from total of " << nfield << endl;
+  }
+
+  //start reading features from the layer
+  OGRFeature *poFeature;
+  if(verbose)
+    cout << "reset reading" << endl;
+  poLayer->ResetReading();
+  unsigned long int ifeature=0;
+  if(verbose)
+    cout << "going through features" << endl << flush;
+  while( (poFeature = poLayer->GetNextFeature()) != NULL ){
+    // vector<T> theFeature;//(fields.size()+posOffset);//x,y+selectedfields
+    T theFeature;
+    if(verbose)
+      cout << "reading feature " << ifeature << endl << flush;
+    OGRGeometry *poGeometry;
+    poGeometry = poFeature->GetGeometryRef();
+    if(verbose){
+      if(poGeometry == NULL)
+        cerr << "no geometry defined" << endl << flush;
+      else// if(wkbFlatten(poGeometry->getGeometryType()) != wkbPoint)
+        cout << "poGeometry type: " << wkbFlatten(poGeometry->getGeometryType()) << endl;
+    }
+    // assert(poGeometry != NULL 
+    //        && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+    OGRPoint *poPoint = (OGRPoint *) poGeometry;
+
+    for(int iField=0;iField<nfield;++iField){
+      OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+      string fieldname=poFieldDefn->GetNameRef();
+      if(fieldname!=theField)
+        continue;
+      switch(fieldType){
+      case(OFTInteger):
+      case(OFTReal):
+        theFeature=poFeature->GetFieldAsDouble(iField);
+      break;
+      default:
+        {
+          string errorstring="field type not supported in ImgReaderOgr::ReadData";
+          throw(errorstring);
+        }
+        break;
+      }
+    }
+    data.push_back(theFeature);
+    if(verbose)
+      cout << "feature is: " << theFeature << endl;
+    ++ifeature;
+  }
+  if(data.size()){
+    return data.size();
+  }
+  else{
+    ostringstream ess;
+    ess << "no layer in " << m_filename;
+    throw(ess.str());
+  }
+}
+
+//read data from all features  
+template <typename T> int ImgReaderOgr::readData(Vector2d<T>& data, const OGRFieldType& fieldType, vector<string>& fields, int layer, bool pos, bool verbose)
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if(verbose)
+    cout << "number of layers: " << m_datasource->GetLayerCount() << endl;
+  poLayer = m_datasource->GetLayer(layer);
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  if(fields.empty()){
+    fields.resize(poFDefn->GetFieldCount());
+    if(verbose)
+      cout << "resized fields to " << fields.size() << endl;
+  }
+  //start reading features from the layer
+  OGRFeature *poFeature;
+  if(verbose)
+    cout << "reset reading" << endl;
+  poLayer->ResetReading();
+  unsigned long int ifeature=0;
+  int posOffset=(pos)?2:0;
+  if(verbose)
+    cout << "going through features" << endl << flush;
+  while( (poFeature = poLayer->GetNextFeature()) != NULL ){
+    vector<T> theFeature;//(fields.size()+posOffset);//x,y+selectedfields
+    if(verbose)
+      cout << "reading feature " << ifeature << endl << flush;
+    OGRGeometry *poGeometry;
+    poGeometry = poFeature->GetGeometryRef();
+    if(verbose){
+      if(poGeometry == NULL)
+        cerr << "no geometry defined" << endl << flush;
+      else if(wkbFlatten(poGeometry->getGeometryType()) != wkbPoint)
+        cerr << "poGeometry type: " << wkbFlatten(poGeometry->getGeometryType()) << endl << flush;
+    }
+    assert(poGeometry != NULL 
+           && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+    OGRPoint *poPoint = (OGRPoint *) poGeometry;
+    if(pos){
+      theFeature.push_back(poPoint->getX());
+      theFeature.push_back(poPoint->getY());
+    }
+    OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+    string featurename;
+    for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+      OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+      string fieldname=poFieldDefn->GetNameRef();
+      switch(fieldType){
+      case(OFTReal):
+        if(fields.size()<poFDefn->GetFieldCount()){
+          if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+            theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+        }
+        else{
+          fields[iField]=fieldname;
+          theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+        }
+        break;
+      case(OFTInteger):
+        if(fields.size()<poFDefn->GetFieldCount()){
+          if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+            theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+        }
+        else{
+          fields[iField]=fieldname;
+          theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+        }
+        break;
+      default:
+        {
+          string errorstring="field type not supported in ImgReaderOgr::ReadData";
+          throw(errorstring);
+        }
+        break;
+      }
+    }
+    data.push_back(theFeature);
+    ++ifeature;
+  }
+//   assert(data.size()==ifeature);
+  if(data.size()){
+    if(pos)
+      assert(data[0].size()==fields.size()+2);
+    else
+      assert(data[0].size()==fields.size());
+    return fields.size();
+  }
+  else{
+    ostringstream ess;
+    ess << "no layer in " << m_filename;
+    throw(ess.str());
+  }
+}
+
+template<typename T> int ImgReaderOgr::readSql(map<int, Vector2d<T> >& data, const OGRFieldType& fieldType, vector<string>& fields, const string& label, const string& sqlStatement, OGRGeometry* spatialFilter, int layer, bool pos, bool verbose)
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer *poLayer;
+  poLayer = m_datasource->ExecuteSQL(sqlStatement.c_str(), spatialFilter,NULL );
+  if(poLayer!=NULL){
+    OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+    if(fields.empty()){
+      fields.resize(poFDefn->GetFieldCount());
+      if(verbose)
+        cout << "resized fields to " << fields.size() << endl;
+    }
+    //start reading features from the layer
+    OGRFeature *poFeature;
+    if(verbose)
+      cout << "reset reading" << endl;
+    poLayer->ResetReading();
+    unsigned long int ifeature=0;
+    int posOffset=(pos)?2:0;
+    if(verbose)
+      cout << "going through features" << endl << flush;
+    int theClass=0;
+    while( (poFeature = poLayer->GetNextFeature()) != NULL ){
+      vector<T> theFeature;//(fields.size()+posOffset);//x,y+selectedfields
+      if(verbose)
+        cout << "reading feature " << ifeature << endl << flush;
+      OGRGeometry *poGeometry;
+      poGeometry = poFeature->GetGeometryRef();
+      if(verbose){
+        if(poGeometry == NULL)
+          cerr << "no geometry defined" << endl << flush;
+        else if(wkbFlatten(poGeometry->getGeometryType()) != wkbPoint)
+          cerr << "poGeometry type: " << wkbFlatten(poGeometry->getGeometryType()) << endl << flush;
+      }
+      assert(poGeometry != NULL 
+             && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+      OGRPoint *poPoint = (OGRPoint *) poGeometry;
+      if(pos){
+        theFeature.push_back(poPoint->getX());
+        theFeature.push_back(poPoint->getY());
+      }
+      OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+      string featurename;
+      for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+        OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+        string fieldname=poFieldDefn->GetNameRef();
+        if(fieldname==label)
+          theClass=poFeature->GetFieldAsInteger(iField);
+        else{
+          switch(fieldType){
+          case(OFTReal):
+            if(fields.size()<poFDefn->GetFieldCount()){
+              if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+                theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+            }
+            else{
+              fields[iField]=fieldname;
+              theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+            }
+            break;
+          case(OFTInteger):
+            if(fields.size()<poFDefn->GetFieldCount()){
+              if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+                theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+            }
+            else{
+              fields[iField]=fieldname;
+              theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+            }
+            break;
+          default:
+            {
+              string errorstring="field type not supported in ImgReaderOgr::ReadData";
+              throw(errorstring);
+            }
+            break;
+          }
+        }
+      }
+      data[theClass].push_back(theFeature);
+      ++ifeature;
+    }
+    if(verbose)
+      cout << "number of features read: " << ifeature << endl << flush;
+    typename map<int,Vector2d<T> >::const_iterator mit=data.begin();
+    int nband=0;
+    if(verbose)
+      cout << "read classes: " << flush;
+    while(mit!=data.end()){
+      if(verbose)
+        cout << mit->first << " " << flush;
+      if(!nband)
+        nband=fields.size();
+      if(pos)
+        assert((mit->second)[0].size()==nband+2);
+      else
+        assert((mit->second)[0].size()==nband);
+      ++mit;
+    }
+    if(verbose)
+      cout << endl << flush;
+    return(nband);
+  }
+  else{
+    ostringstream ess;
+    ess << "no layer in " << m_filename;
+    throw(ess.str());
+  }
+}
+
+template<typename T> int ImgReaderOgr::readSql(Vector2d<T>& data, const OGRFieldType& fieldType, vector<string>& fields, const string& sqlStatement, OGRGeometry* spatialFilter, int layer, bool pos, bool verbose)
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer *poLayer;
+  poLayer = m_datasource->ExecuteSQL(sqlStatement.c_str(), spatialFilter,NULL );
+  if(poLayer!=NULL){
+    OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+    if(fields.empty()){
+      fields.resize(poFDefn->GetFieldCount());
+      if(verbose)
+        cout << "resized fields to " << fields.size() << endl;
+    }
+    //start reading features from the layer
+    OGRFeature *poFeature;
+    if(verbose)
+      cout << "reset reading" << endl;
+    poLayer->ResetReading();
+    unsigned long int ifeature=0;
+    int posOffset=(pos)?2:0;
+    if(verbose)
+      cout << "going through features" << endl << flush;
+    while( (poFeature = poLayer->GetNextFeature()) != NULL ){
+      vector<T> theFeature;//(fields.size()+posOffset);//x,y+selectedfields
+      if(verbose)
+        cout << "reading feature " << ifeature << endl << flush;
+      OGRGeometry *poGeometry;
+      poGeometry = poFeature->GetGeometryRef();
+      if(verbose){
+        if(poGeometry == NULL)
+          cerr << "no geometry defined" << endl << flush;
+        else if(wkbFlatten(poGeometry->getGeometryType()) != wkbPoint)
+          cerr << "poGeometry type: " << wkbFlatten(poGeometry->getGeometryType()) << endl << flush;
+      }
+      assert(poGeometry != NULL 
+             && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+      OGRPoint *poPoint = (OGRPoint *) poGeometry;
+      if(pos){
+        theFeature.push_back(poPoint->getX());
+        theFeature.push_back(poPoint->getY());
+      }
+      OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+      string featurename;
+      for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+        OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+        string fieldname=poFieldDefn->GetNameRef();
+        switch(fieldType){
+        case(OFTReal):
+          if(fields.size()<poFDefn->GetFieldCount()){
+            if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+              theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+          }
+          else{
+            fields[iField]=fieldname;
+            theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+          }
+          break;
+        case(OFTInteger):
+          if(fields.size()<poFDefn->GetFieldCount()){
+            if(find(fields.begin(),fields.end(),fieldname)!=fields.end())
+              theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+          }
+          else{
+            fields[iField]=fieldname;
+            theFeature.push_back(poFeature->GetFieldAsDouble(iField));
+          }
+          break;
+        default:
+          {
+            string errorstring="field type not supported in ImgReaderOgr::ReadData";
+            throw(errorstring);
+          }
+          break;
+        }
+      }
+      data.push_back(theFeature);
+      ++ifeature;
+    }
+    m_datasource->ReleaseResultSet( poLayer );
+    //   assert(data.size()==ifeature);
+    if(data.size()){
+      if(pos)
+        assert(data[0].size()==fields.size()+2);
+      else
+        assert(data[0].size()==fields.size());
+      return fields.size();
+    }
+    else
+      return(0);
+  }
+  else{
+    ostringstream ess;
+    ess << "no layer in " << m_filename;
+    throw(ess.str());
+  }
+}
+
+#endif // _IMGREADEROGR_H_
diff --git a/src/imageclasses/ImgWriterGdal.cc b/src/imageclasses/ImgWriterGdal.cc
new file mode 100644
index 0000000..bbbdacf
--- /dev/null
+++ b/src/imageclasses/ImgWriterGdal.cc
@@ -0,0 +1,546 @@
+/**********************************************************************
+ImgWriterGdal.cc: class to write raster files using GDAL API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <iostream>
+#include <iomanip>
+#include <time.h>
+#include "ogr_spatialref.h"
+#include "ImgWriterGdal.h"
+//---------------------------------------------------------------------------
+ImgWriterGdal::ImgWriterGdal(void)
+  : m_gds(NULL), m_isGeoRef(false), m_ncol(0), m_nrow(0), m_nband(0)
+{}
+
+// ImgWriterGdal::ImgWriterGdal(void)
+//   : m_gds(NULL), m_magic_x(1), m_magic_y(1), m_isGeoRef(false), m_ncol(0), m_nrow(0), m_nband(0), m_interleave("BAND"), m_compression("LZW")
+// {}
+
+ImgWriterGdal::~ImgWriterGdal(void)
+{
+  // delete m_gds;
+//   GDALDumpOpenDatasets(stderr);
+//   GDALDestroyDriverManager();//could still be be used by other objects
+}
+
+//---------------------------------------------------------------------------
+void ImgWriterGdal::open(const string& filename, const ImgReaderGdal& imgSrc, const vector<string>& options)
+{
+  m_isGeoRef=imgSrc.isGeoRef();
+  m_filename=filename;
+  m_ncol=imgSrc.nrOfCol();
+  m_nrow=imgSrc.nrOfRow();
+  m_nband=imgSrc.nrOfBand();
+  m_type=imgSrc.getDataType();
+  m_options=options;
+  // m_interleave=imgSrc.getInterleave();
+  // m_compression=imgSrc.getCompression();
+  // imgSrc.getMagicPixel(m_magic_x,m_magic_y);
+  setCodec(imgSrc);
+}
+
+// void ImgWriterGdal::open(const string& filename, int ncol, int nrow, int nband, const GDALDataType& dataType, const string& imageType, const string& interleave, const string& compression, int magicX, int magicY)
+// {
+//   m_isGeoRef=false;
+//   m_filename = filename;
+//   m_ncol = ncol;
+//   m_nrow = nrow;
+//   m_nband = nband;
+//   m_type=dataType;
+//   m_interleave = interleave;
+//   m_compression=compression;
+//   m_magic_x=magicX;
+//   m_magic_y=magicY;
+//   setCodec(imageType);
+// }
+
+void ImgWriterGdal::open(const string& filename, int ncol, int nrow, int nband, const GDALDataType& dataType, const string& imageType, const vector<string>& options)
+{
+  m_isGeoRef=false;
+  m_filename = filename;
+  m_ncol = ncol;
+  m_nrow = nrow;
+  m_nband = nband;
+  m_type=dataType;
+  // m_interleave = interleave;
+  // m_compression=compression;
+  m_options=options;
+  // m_magic_x=magicX;
+  // m_magic_y=magicY;
+  setCodec(imageType);
+}
+
+//---------------------------------------------------------------------------
+void ImgWriterGdal::close(void)
+{
+  GDALClose(m_gds);
+  char **papszOptions=NULL;
+  for(vector<string>::const_iterator optionIt=m_options.begin();optionIt!=m_options.end();++optionIt)
+    papszOptions=CSLAddString(papszOptions,optionIt->c_str());
+  CSLDestroy(papszOptions);
+}
+
+//---------------------------------------------------------------------------
+void ImgWriterGdal::setCodec(const ImgReaderGdal& imgSrc){
+  GDALAllRegister();
+  GDALDriver *poDriver;
+  poDriver = GetGDALDriverManager()->GetDriverByName(imgSrc.getDriverDescription().c_str());
+  if( poDriver == NULL ){
+    string errorString="FileOpenError";
+    throw(errorString);
+  }
+  char **papszMetadata;
+  papszMetadata = poDriver->GetMetadata();
+  assert( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ));
+  char **papszOptions=NULL;
+  for(vector<string>::const_iterator optionIt=m_options.begin();optionIt!=m_options.end();++optionIt)
+    papszOptions=CSLAddString(papszOptions,optionIt->c_str());
+  // char **papszOptions=NULL;
+  // ostringstream compressList;
+  // compressList << "COMPRESS=" << m_compression;
+  // papszOptions = CSLAddString(papszOptions,(compressList.str()).c_str());
+  // ostringstream interleaveList;
+  // interleaveList << "INTERLEAVE=" << m_interleave;
+  // papszOptions = CSLAddString(papszOptions,(interleaveList.str()).c_str());
+  m_gds=poDriver->Create(m_filename.c_str(),m_ncol,m_nrow,m_nband,m_type,papszOptions);
+  if(imgSrc.isGeoRef()){
+    setProjection(imgSrc.getProjection());
+    double ulx,uly,deltaX,deltaY,rot1,rot2;
+    imgSrc.getGeoTransform(ulx,uly,deltaX,deltaY,rot1,rot2);
+    setGeoTransform(ulx,uly,deltaX,deltaY,rot1,rot2);
+  }
+  m_gds->SetMetadata(imgSrc.getMetadata() ); 
+  m_gds->SetMetadataItem( "TIFFTAG_DOCUMENTNAME", m_filename.c_str());
+  m_gds->SetMetadataItem( "TIFFTAG_SOFTWARE", "pktools v2.0 by Pieter Kempeneers");
+  time_t rawtime;
+  time ( &rawtime );
+
+  time_t tim=time(NULL);
+  tm *now=localtime(&tim);
+  ostringstream datestream;
+  //date string must be 20 characters long...
+  datestream << now->tm_year+1900;
+  if(now->tm_mon+1<10)
+    datestream << ":0" << now->tm_mon+1;
+  else
+    datestream << ":" << now->tm_mon+1;
+  if(now->tm_mday<10)
+    datestream << ":0" << now->tm_mday;
+  else
+    datestream << ":" << now->tm_mday;
+  if(now->tm_hour<10)
+    datestream << " 0" << now->tm_hour;
+  else
+    datestream << " " << now->tm_hour;
+  if(now->tm_min<10)
+    datestream << ":0" << now->tm_min;
+  else
+    datestream << ":" << now->tm_min;
+  if(now->tm_sec<10)
+    datestream << ":0" << now->tm_sec;
+  else
+    datestream << ":" << now->tm_sec;
+  m_gds->SetMetadataItem( "TIFFTAG_DATETIME", datestream.str().c_str());
+//   list<string> lmeta;
+//   imgReader.getMetadata(lmeta);
+//   list<string>::const_iterator lit=lmeta.begin();
+//   while(lit!=lmeta.end()){
+//     cout << *lit << endl;
+//     ++lit;
+//   }
+  // m_gds->SetMetadataItem( "INTERLEAVE", m_interleave.c_str(), "IMAGE_STRUCTURE" );
+  // m_gds->SetMetadataItem( "COMPRESS", m_compression.c_str(), "IMAGE_STRUCTURE" );
+  if(imgSrc.getColorTable()!=NULL)
+    setColorTable(imgSrc.getColorTable());
+}
+
+void ImgWriterGdal::setCodec(const string& imageType)
+{
+  GDALAllRegister();
+  GDALDriver *poDriver;
+  poDriver = GetGDALDriverManager()->GetDriverByName(imageType.c_str());
+  if( poDriver == NULL ){
+    ostringstream s;
+    s << "FileOpenError (" << imageType << ")";
+    throw(s.str());
+  }
+  char **papszMetadata;
+  papszMetadata = poDriver->GetMetadata();
+  assert( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ));
+  char **papszOptions=NULL;
+  for(vector<string>::const_iterator optionIt=m_options.begin();optionIt!=m_options.end();++optionIt)
+    papszOptions=CSLAddString(papszOptions,optionIt->c_str());
+  // ostringstream compressList;
+  // compressList << "COMPRESS=" << m_compression;
+  // papszOptions = CSLAddString(papszOptions,(compressList.str()).c_str());
+  // ostringstream interleaveList;
+  // interleaveList << "INTERLEAVE=" << m_interleave;
+  // papszOptions = CSLAddString(papszOptions,(interleaveList.str()).c_str());
+  m_gds=poDriver->Create(m_filename.c_str(),m_ncol,m_nrow,m_nband,m_type,papszOptions);
+
+  // m_gds->SetMetadataItem( "INTERLEAVE", m_interleave.c_str(), "IMAGE_STRUCTURE" );
+  // m_gds->SetMetadataItem( "COMPRESSION", m_compression.c_str(), "IMAGE_STRUCTURE" );
+  m_gds->SetMetadataItem( "TIFFTAG_DOCUMENTNAME", m_filename.c_str());
+  m_gds->SetMetadataItem( "TIFFTAG_SOFTWARE", "pktools v2.0 by Pieter Kempeneers");
+  time_t rawtime;
+  time ( &rawtime );
+
+  time_t tim=time(NULL);
+  tm *now=localtime(&tim);
+  ostringstream datestream;
+  //date string must be 20 characters long...
+  datestream << now->tm_year+1900;
+  if(now->tm_mon+1<10)
+    datestream << ":0" << now->tm_mon+1;
+  else
+    datestream << ":" << now->tm_mon+1;
+  if(now->tm_mday<10)
+    datestream << ":0" << now->tm_mday;
+  else
+    datestream << ":" << now->tm_mday;
+  if(now->tm_hour<10)
+    datestream << " 0" << now->tm_hour;
+  else
+    datestream << " " << now->tm_hour;
+  if(now->tm_min<10)
+    datestream << ":0" << now->tm_min;
+  else
+    datestream << ":" << now->tm_min;
+  if(now->tm_sec<10)
+    datestream << ":0" << now->tm_sec;
+  else
+    datestream << ":" << now->tm_sec;
+  m_gds->SetMetadataItem( "TIFFTAG_DATETIME", datestream.str().c_str());
+//   m_gds->SetMetadataItem( "TIFFTAG_DATETIME", ctime(&rawtime));
+}
+
+void ImgWriterGdal::setMetadata(char** metadata)
+{
+  assert(m_gds);
+  m_gds->SetMetadata(metadata); 
+}
+
+string ImgWriterGdal::getProjection(void) const 
+{
+  assert(m_gds);
+  string theProjection=m_gds->GetProjectionRef();
+  //due to error in Gdal? AUTHORITY fields do not seem to work!
+  // size_t startpos,endpos;
+  // while((startpos=theProjection.find(",AUTHORITY"))!=string::npos){
+  //   endpos=theProjection.find("]",startpos+1,1)+1;
+  //   theProjection.erase(startpos,endpos-startpos);
+  // }
+  return theProjection;
+}
+
+//---------------------------------------------------------------------------
+void ImgWriterGdal::setGeoTransform(double ulx, double uly, double deltaX, double deltaY, double rot1, double rot2)
+{
+  m_isGeoRef=true;
+  m_ulx=ulx;
+  m_uly=uly;
+  m_delta_x=deltaX;
+  m_delta_y=deltaY;
+  double adfGeoTransform[6];// { 444720, 30, 0, 3751320, 0, -30 };
+  adfGeoTransform[0]=ulx;
+  adfGeoTransform[1]=deltaX;
+  adfGeoTransform[2]=rot1;
+  adfGeoTransform[3]=uly;
+  adfGeoTransform[4]=rot2;
+  adfGeoTransform[5]=-deltaY;//convention of GDAL!
+  if(m_gds)
+    m_gds->SetGeoTransform(adfGeoTransform);
+}
+
+void ImgWriterGdal::copyGeoTransform(const ImgReaderGdal& imgSrc)
+{
+  setProjection(imgSrc.getProjection());
+  double ulx,uly,deltaX,deltaY,rot1,rot2;
+  imgSrc.getGeoTransform(ulx,uly,deltaX,deltaY,rot1,rot2);
+  setGeoTransform(ulx,uly,deltaX,deltaY,rot1,rot2);
+}
+
+string ImgWriterGdal::setProjectionProj4(const string& projection)
+{
+  if(!m_isGeoRef)
+    m_isGeoRef=true;
+
+    OGRSpatialReferenceH hSRS;  
+    char *pszResult = NULL;  
+  
+    CPLErrorReset();  
+      
+    hSRS = OSRNewSpatialReference( NULL );  
+    if( OSRSetFromUserInput( hSRS, projection.c_str() ) == OGRERR_NONE )  
+        OSRExportToWkt( hSRS, &pszResult );  
+    else  
+    {  
+        // CPLError( CE_Failure, CPLE_AppDefined,  
+        //           "Translating source or target SRS failed:\n%s",  
+        //           projection.c_str() );  
+        ostringstream s;
+        s << "Error in set projection " << projection;
+        throw(s.str());
+        // exit( 1 );
+    }  
+    // m_gds->SetProjection(pszResult);
+
+    //due to error in Gdal? AUTHORITY fields do not seem to work!
+    string theProjection=pszResult;
+    // size_t startpos,endpos;
+    // while((startpos=theProjection.find(",AUTHORITY"))!=string::npos){
+    //   endpos=theProjection.find("]",startpos+1,1)+1;
+    //   theProjection.erase(startpos,endpos-startpos);
+    // }
+    assert(m_gds);
+    m_gds->SetProjection(theProjection.c_str());
+    OSRDestroySpatialReference( hSRS );  
+  
+    // return pszResult;  
+    return theProjection;  
+
+//   OGRSpatialReference oSRS;
+//   char *pszSRS_WKT = NULL;
+//   oSRS.importFromProj4(projection.c_str());
+// //   oSRS.SetLAEA(52,10,4321000,3210000);//redundant but according to JRC standard
+//   oSRS.exportToWkt(&pszSRS_WKT);
+//   m_gds->SetProjection(pszSRS_WKT);
+//   CPLFree(pszSRS_WKT);
+}
+
+void ImgWriterGdal::setProjection(const string& projection)
+{
+  if(!m_isGeoRef)
+    m_isGeoRef=true;
+  OGRSpatialReference oSRS;
+  char *pszSRS_WKT = NULL;
+  assert(m_gds);
+  m_gds->SetProjection(projection.c_str());
+  CPLFree(pszSRS_WKT);
+}
+
+//default projection: ETSR-LAEA
+string ImgWriterGdal::setProjection(void)
+{
+  string theProjection;
+  OGRSpatialReference oSRS;
+  char *pszSRS_WKT = NULL;
+  //// oSRS.importFromEPSG(3035);
+  oSRS.SetGeogCS("ETRS89","European_Terrestrial_Reference_System_1989","GRS 1980",6378137,298.2572221010042,"Greenwich",0,"degree",0.0174532925199433);
+  // cout << setprecision(16) << "major axis: " << oSRS.GetSemiMajor(NULL) << endl;//notice that major axis can be set to a different value than the default to the well known standard corresponding to the name (European_Terrestrial_Reference_System_1989), but that new value, while recognized by GetSemiMajor, will not be written in the geotiff tag!
+  oSRS.SetProjCS( "ETRS89 / ETRS-LAEA" );
+  oSRS.SetLAEA(52,10,4321000,3210000);
+  oSRS.exportToWkt( &pszSRS_WKT );
+  theProjection=pszSRS_WKT;
+  CPLFree( pszSRS_WKT );
+  assert(m_gds);
+  m_gds->SetProjection(theProjection.c_str());
+  return(theProjection);
+}
+
+bool ImgWriterGdal::getBoundingBox(double& ulx, double& uly, double& lrx, double& lry) const
+{
+  if(m_isGeoRef){
+//     ulx=m_ulx-(m_magic_x-1.0)*m_delta_x;
+//     uly=m_uly+(m_magic_y-1.0)*m_delta_y;
+//     lrx=ulx+(nrOfCol()+1.0-m_magic_x)*m_delta_x;
+//     lry=uly-(nrOfRow()+1.0-m_magic_y)*m_delta_y;
+    ulx=m_ulx;
+    uly=m_uly;
+    lrx=ulx+nrOfCol()*m_delta_x;
+    lry=uly-nrOfRow()*m_delta_y;
+    return true;
+  }
+  else{
+    ulx=0;
+    uly=nrOfRow()-1;
+    lrx=nrOfCol()-1;
+    lry=0;
+    return false;
+  }
+}
+
+bool ImgWriterGdal::getCentrePos(double& x, double& y) const
+{
+  if(m_isGeoRef){
+//     x=m_ulx+(nrOfCol()/2.0-(m_magic_x-1.0))*m_delta_x;
+//     y=m_uly-(nrOfRow()/2.0+(m_magic_y-1.0))*m_delta_y;
+    x=m_ulx+nrOfCol()/2.0*m_delta_x;
+    y=m_uly-nrOfRow()/2.0*m_delta_y;
+    return true;
+  }
+  else
+    return false;
+}
+
+bool ImgWriterGdal::geo2image(double x, double y, double& i, double& j) const
+{
+  //double values are returned, caller is responsible for interpolation step
+  if(m_isGeoRef){
+//     double ulx=m_ulx-(m_magic_x-1.0)*m_delta_x;
+//     double uly=m_uly+(m_magic_y-1.0)*m_delta_y;
+    double ulx=m_ulx;
+    double uly=m_uly;
+    i=(x-ulx)/m_delta_x;
+    j=(uly-y)/m_delta_y;
+    return true;
+  }
+  else{
+    i=x;
+    j=nrOfRow()-y;
+    return false;
+  }
+}
+
+//centre of pixel is always returned (regardless of magic pixel reference)!
+bool ImgWriterGdal::image2geo(double i, double j, double& x, double& y) const
+{
+  if(m_isGeoRef){
+//     x=m_ulx+(1.5-m_magic_x+i)*m_delta_x;
+//     y=m_uly-(1.5-m_magic_y+j)*m_delta_y;
+    x=m_ulx+(0.5+i)*m_delta_x;
+    y=m_uly-(0.5+j)*m_delta_y;
+    return true;
+  }
+  else
+    return false;
+}
+
+bool ImgWriterGdal::covers(double x, double  y) const
+{
+  double theULX, theULY, theLRX, theLRY;
+  getBoundingBox(theULX,theULY,theLRX,theLRY);
+  return((x > theULX)&&
+	 (x < theLRX)&&
+	 (y < theULY)&&
+	 (y >theLRY));
+}
+
+bool ImgWriterGdal::covers(double ulx, double  uly, double lrx, double lry) const
+{
+  double theULX, theULY, theLRX, theLRY;
+  getBoundingBox(theULX,theULY,theLRX,theLRY);
+  return((ulx < theLRX)&&(lrx > theULX)&&(lry < theULY)&&(uly > theLRY));
+}
+
+string ImgWriterGdal::getGeoTransform() const
+{
+  double adfGeoTransform[6];// { 444720, 30, 0, 3751320, 0, -30 };
+  double ulx;
+  double deltaX;
+  double rot1;
+  double uly;
+  double rot2;
+  double deltaY;
+  if(m_gds){
+    m_gds->GetGeoTransform(adfGeoTransform);
+    ulx=adfGeoTransform[0];
+    deltaX=adfGeoTransform[1];
+    rot1=adfGeoTransform[2];
+    uly=adfGeoTransform[3];
+    rot2=adfGeoTransform[4];
+    deltaY=-adfGeoTransform[5];//convention of GDAL!
+  }
+  else{//virtual writer
+    ulx=m_ulx;
+    uly=m_uly;
+    deltaX=m_delta_x;
+    deltaY=m_delta_y;
+    rot1=0;
+    rot2=0;
+  }
+  ostringstream s;
+  s << "[" << ulx << "," << deltaX << "," << rot1 << "," << uly << "," << rot2 << "," << -deltaY << "]";
+  return(s.str());
+}
+
+void ImgWriterGdal::getGeoTransform(double& ulx, double& uly, double& deltaX, double& deltaY, double& rot1, double& rot2) const
+{
+  if(m_gds){
+    double adfGeoTransform[6];// { 444720, 30, 0, 3751320, 0, -30 };
+    m_gds->GetGeoTransform(adfGeoTransform);
+    ulx=adfGeoTransform[0];
+    deltaX=adfGeoTransform[1];
+    rot1=adfGeoTransform[2];
+    uly=adfGeoTransform[3];
+    rot2=adfGeoTransform[4];
+    deltaY=-adfGeoTransform[5];//convention of GDAL!
+  }
+  else{//virtual writer
+    ulx=m_ulx;
+    uly=m_uly;
+    deltaX=m_delta_x;
+    deltaY=m_delta_y;
+    rot1=0;
+    rot2=0;
+  }
+}
+
+GDALDataType ImgWriterGdal::getDataType(int band) const
+{
+  assert(band<m_nband+1);
+  return (m_gds->GetRasterBand(band+1))->GetRasterDataType();
+}
+
+GDALRasterBand* ImgWriterGdal::getRasterBand(int band)
+{
+  assert(band<m_nband+1);
+  return (m_gds->GetRasterBand(band+1));
+}
+
+//filename is ascii file containing 5 columns: index R G B ALFA (0:transparent, 255:solid)
+void ImgWriterGdal::setColorTable(const string& filename, int band)
+{
+  //todo: fool proof table in file (no checking currently done...)
+  ifstream ftable(filename.c_str(),ios::in);
+  string line;
+//   poCT=new GDALColorTable();
+  GDALColorTable colorTable;
+  short nline=0;
+  while(getline(ftable,line)){
+    ++nline;
+    istringstream ist(line);
+    GDALColorEntry sEntry;
+    short id;
+    ist >> id >> sEntry.c1 >> sEntry.c2 >> sEntry.c3 >> sEntry.c4;
+//     poCT->SetColorEntry(id,&sEntry);
+    colorTable.SetColorEntry(id,&sEntry);
+  }
+  // assert(nline==colorTable.GetColorEntryCount());
+//   (m_gds->GetRasterBand(band+1))->SetColorTable(poCT);
+  (m_gds->GetRasterBand(band+1))->SetColorTable(&colorTable);
+}
+
+void ImgWriterGdal::setColorTable(GDALColorTable* colorTable, int band)
+{
+  (m_gds->GetRasterBand(band+1))->SetColorTable(colorTable);
+}
+
+//write an entire image from memory to file
+bool ImgWriterGdal::writeData(void* pdata, const GDALDataType& dataType, int band) const{
+  //fetch raster band
+  GDALRasterBand  *poBand;
+  if(band>=nrOfBand()+1){
+    ostringstream s;
+    s << "band (" << band << ") exceeds nrOfBand (" << nrOfBand() << ")";
+    throw(s.str());
+  }
+  poBand = m_gds->GetRasterBand(band+1);//GDAL uses 1 based index
+  poBand->RasterIO(GF_Write,0,0,nrOfCol(),nrOfRow(),pdata,nrOfCol(),nrOfRow(),dataType,0,0);
+  return true;
+}  
diff --git a/src/imageclasses/ImgWriterGdal.h b/src/imageclasses/ImgWriterGdal.h
new file mode 100644
index 0000000..59f70c9
--- /dev/null
+++ b/src/imageclasses/ImgWriterGdal.h
@@ -0,0 +1,211 @@
+/**********************************************************************
+ImgWriterGdal.h: class to write raster files using GDAL API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _IMGWRITERGDAL_H_
+#define _IMGWRITERGDAL_H_
+
+#include <assert.h>
+#include <fstream>
+#include <string>
+#include <sstream>
+#include "gdal_priv.h"
+#include "ImgReaderGdal.h"
+
+
+using namespace std;
+
+//--------------------------------------------------------------------------
+class ImgWriterGdal
+{
+public:
+  ImgWriterGdal(void);
+  ~ImgWriterGdal(void);
+  void open(const string& filename);
+  void open(const string& filename, const ImgReaderGdal& imgSrc, const vector<string>& options=vector<string>());
+  // void open(const string& filename, int ncol, int nrow, int nband, const GDALDataType& dataType, const string& imageType="GTiff", const string& interleave="BAND", const string& compression="LZW", int magicX=1, int magicY=1);
+  void open(const string& filename, int ncol, int nrow, int nband, const GDALDataType& dataType, const string& imageType, const vector<string>& options=vector<string>());
+  void close(void);
+  int nrOfCol(void) const { return m_ncol;};
+  int nrOfRow(void) const { return m_nrow;};
+  int nrOfBand(void) const { return m_nband;};
+  void setGeoTransform(double ulx, double uly, double deltaX, double deltaY, double rot1=0, double rot2=0);
+  void copyGeoTransform(const ImgReaderGdal& imgSrc);
+  string setProjection(void);//set (and return) default projection ETSR-LAEA
+  void setProjection(const string& projection);
+  string setProjectionProj4(const string& projection);
+  void setImageDescription(const string& imageDescription){m_gds->SetMetadataItem( "TIFFTAG_IMAGEDESCRIPTION",imageDescription.c_str());};
+  string getProjection(void) const;
+  string getGeoTransform() const;
+  void getGeoTransform(double& ulx, double& uly, double& deltaX, double& deltaY, double& rot1, double& rot2) const;
+  bool getBoundingBox(double& ulx, double& uly, double& lrx, double& lry) const;
+  bool getCentrePos(double& x, double& y) const;
+  bool covers(double x, double y) const;
+  bool covers(double ulx, double  uly, double lrx, double lry) const;
+  bool geo2image(double x, double y, double& i, double& j) const;
+  bool image2geo(double i, double j, double& x, double& y) const;
+  bool isGeoRef() const {return m_isGeoRef;};
+  // void getMagicPixel(double& x, double& y) const {x=m_magic_x;y=m_magic_y;};
+  double getDeltaX(void) const {return m_delta_x;};
+  double getDeltaY(void) const{return m_delta_y;};
+  template<typename T> bool writeData(T& value, const GDALDataType& dataType, int col, int row, int band=0) const;
+  template<typename T> bool writeData(vector<T>& buffer, const GDALDataType& dataType , int minCol, int maxCol, int row, int band=0) const;
+  template<typename T> bool writeData(vector<T>& buffer, const GDALDataType& dataType, int row, int band=0) const;
+  bool writeData(void* pdata, const GDALDataType& dataType, int band=0) const;
+  // string getInterleave(){return m_interleave;};
+  // string getCompression(){return m_compression;};
+  GDALDataType getDataType(int band=0) const;
+  GDALRasterBand* getRasterBand(int band);
+  void setColorTable(const string& filename, int band=0);
+  void setColorTable(GDALColorTable* colorTable, int band=0);
+  void setMetadata(char** metadata);
+
+protected:
+  void setCodec(const string& imageType);
+  void setCodec(const ImgReaderGdal& ImgSrc);
+
+  string m_filename;
+  GDALDataset *m_gds;
+  int m_ncol;
+  int m_nrow;
+  int m_nband;
+  GDALDataType m_type;
+  double m_ulx;
+  double m_uly;
+  double m_delta_x;
+  double m_delta_y;
+  // double m_magic_x;
+  // double m_magic_y;
+  bool m_isGeoRef;
+  // string m_interleave;
+  // string m_compression;
+  vector<string> m_options;
+};
+
+template<typename T> bool ImgWriterGdal::writeData(T& value, const GDALDataType& dataType, int col, int row, int band) const
+{
+  //fetch raster band
+  GDALRasterBand  *poBand;
+  if(band>=nrOfBand()+1){
+    ostringstream s;
+    s << "band (" << band << ") exceeds nrOfBand (" << nrOfBand() << ")";
+    throw(s.str());
+  }
+  poBand = m_gds->GetRasterBand(band+1);//GDAL uses 1 based index
+  if(col>=nrOfCol()){
+    ostringstream s;
+    s << "col (" << col << ") exceeds nrOfCol (" << nrOfCol() << ")";
+    throw(s.str());
+  }
+  if(col<0){
+    ostringstream s;
+    s << "col (" << col << ") is negative";
+    throw(s.str());
+  }
+  if(row>=nrOfRow()){
+    ostringstream s;
+    s << "row (" << row << ") exceeds nrOfRow (" << nrOfRow() << ")";
+    throw(s.str());
+  }
+  if(row<0){
+    ostringstream s;
+    s << "row (" << row << ") is negative";
+    throw(s.str());
+  }
+  poBand->RasterIO(GF_Write,col,row,1,1,&value,1,1,dataType,0,0);
+}
+
+template<typename T> bool ImgWriterGdal::writeData(vector<T>& buffer, const GDALDataType& dataType, int minCol, int maxCol, int row, int band) const
+{
+  //fetch raster band
+  GDALRasterBand  *poBand;
+  if(band>=nrOfBand()+1){
+    ostringstream s;
+    s << "band (" << band << ") exceeds nrOfBand (" << nrOfBand() << ")";
+    throw(s.str());
+  }
+  poBand = m_gds->GetRasterBand(band+1);//GDAL uses 1 based index
+  if(buffer.size()!=maxCol-minCol+1){
+    string errorstring="invalid buffer size";
+    throw(errorstring);
+  }
+  if(minCol>=nrOfCol()){
+    ostringstream s;
+    s << "minCol (" << minCol << ") exceeds nrOfCol (" << nrOfCol() << ")";
+    throw(s.str());
+  }
+  if(minCol<0){
+    ostringstream s;
+    s << "mincol (" << minCol << ") is negative";
+    throw(s.str());
+  }
+  if(maxCol>=nrOfCol()){
+    ostringstream s;
+    s << "maxCol (" << maxCol << ") exceeds nrOfCol (" << nrOfCol() << ")";
+    throw(s.str());
+  }
+  if(maxCol<minCol){
+    ostringstream s;
+    s << "maxCol (" << maxCol << ") is less than minCol (" << minCol << ")";
+    throw(s.str());
+  }
+
+  if(row>=nrOfRow()){
+    ostringstream s;
+    s << "row (" << row << ") exceeds nrOfRow (" << nrOfRow() << ")";
+    throw(s.str());
+  }
+  if(row<0){
+    ostringstream s;
+    s << "row (" << row << ") is negative";
+    throw(s.str());
+  }
+  poBand->RasterIO(GF_Write,minCol,row,buffer.size(),1,&(buffer[0]),buffer.size(),1,dataType,0,0);
+}
+
+template<typename T> bool ImgWriterGdal::writeData(vector<T>& buffer, const GDALDataType& dataType, int row, int band) const
+{
+  //fetch raster band
+  GDALRasterBand  *poBand;
+  if(band>=nrOfBand()+1){
+    ostringstream s;
+    s << "band (" << band << ") exceeds nrOfBand (" << nrOfBand() << ")";
+    throw(s.str());
+  }
+  poBand = m_gds->GetRasterBand(band+1);//GDAL uses 1 based index
+  if(buffer.size()!=nrOfCol()){
+    string errorstring="invalid buffer size";
+    throw(errorstring);
+  }
+  if(row>=nrOfRow()){
+    ostringstream s;
+    s << "row (" << row << ") exceeds nrOfRow (" << nrOfRow() << ")";
+    throw(s.str());
+  }
+  poBand->RasterIO(GF_Write,0,row,buffer.size(),1,&(buffer[0]),buffer.size(),1,dataType,0,0);
+}
+
+#endif // _IMGWRITERGDAL_H_
+
+
+//     adfGeoTransform[0] /* top left x */
+//     adfGeoTransform[1] /* w-e pixel resolution */
+//     adfGeoTransform[2] /* rotation, 0 if image is "north up" */
+//     adfGeoTransform[3] /* top left y */
+//     adfGeoTransform[4] /* rotation, 0 if image is "north up" */
+//     adfGeoTransform[5] /* n-s pixel resolution */
diff --git a/src/imageclasses/ImgWriterOgr.cc b/src/imageclasses/ImgWriterOgr.cc
new file mode 100644
index 0000000..3cda0a2
--- /dev/null
+++ b/src/imageclasses/ImgWriterOgr.cc
@@ -0,0 +1,540 @@
+/**********************************************************************
+ImgWriterOgr.cc: class to write vector files using OGR API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include "ImgReaderOgr.h"
+#include "ImgWriterOgr.h"
+#include "ImgReaderGdal.h"
+#include "cpl_string.h"
+//---------------------------------------------------------------------------
+ImgWriterOgr::ImgWriterOgr(void)
+{}
+
+ImgWriterOgr::~ImgWriterOgr(void)
+{
+}
+
+ImgWriterOgr::ImgWriterOgr(const string& filename)
+{
+  open(filename);
+}
+
+ImgWriterOgr::ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr)
+{
+  m_filename=filename;
+  setCodec(imgReaderOgr.getDriver());
+  createLayer(filename,imgReaderOgr.getProjection(),imgReaderOgr.getGeometryType(),NULL);
+  copyFields(imgReaderOgr);
+}
+
+ImgWriterOgr::ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr, bool copyData)
+{
+  CPLErrorReset();
+  m_filename=filename;
+  setCodec(imgReaderOgr.getDriver());
+  createLayer(filename,imgReaderOgr.getProjection(),imgReaderOgr.getGeometryType(),NULL);
+  copyFields(imgReaderOgr);
+  if(copyData){
+    OGRFeature *poFeature;
+    while( (poFeature = imgReaderOgr.getLayer()->GetNextFeature()) != NULL ){
+      poFeature = imgReaderOgr.getLayer()->GetNextFeature();
+      if( poFeature == NULL )
+        break;
+      OGRFeature *poDstFeature = NULL;
+
+      poDstFeature=createFeature();
+//       poDstFeature = OGRFeature::CreateFeature(m_datasource->GetLayer(m_datasource->GetLayerCount()-1)->GetLayerDefn());
+      if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE ){
+	const char* fmt;
+	string errorString="Unable to translate feature %d from layer %s.\n";
+	fmt=errorString.c_str();
+        CPLError( CE_Failure, CPLE_AppDefined,
+                  fmt,
+                  poFeature->GetFID(), getLayerName().c_str() );
+        // CPLError( CE_Failure, CPLE_AppDefined,
+        //           "Unable to translate feature %d from layer %s.\n",
+        //           poFeature->GetFID(), getLayerName().c_str() );
+            
+        OGRFeature::DestroyFeature( poFeature );
+        OGRFeature::DestroyFeature( poDstFeature );
+      }
+      poDstFeature->SetFID( poFeature->GetFID() );
+      OGRFeature::DestroyFeature( poFeature );
+
+      CPLErrorReset();
+      if(createFeature( poDstFeature ) != OGRERR_NONE){
+	const char* fmt;
+	string errorString="Unable to translate feature %d from layer %s.\n";
+	fmt=errorString.c_str();
+        CPLError( CE_Failure, CPLE_AppDefined,
+		  fmt,
+                  poFeature->GetFID(), getLayerName().c_str() );
+        OGRFeature::DestroyFeature( poDstFeature );
+      }
+      OGRFeature::DestroyFeature( poDstFeature );
+    }
+  }
+}
+
+//---------------------------------------------------------------------------
+
+void ImgWriterOgr::open(const string& filename, const string& imageType)
+{
+  m_filename = filename;
+  setCodec(imageType);
+}
+
+//---------------------------------------------------------------------------
+void ImgWriterOgr::close(void)
+{
+  OGRDataSource::DestroyDataSource(m_datasource);
+}
+
+//---------------------------------------------------------------------------
+void ImgWriterOgr::setCodec(const string& imageType){
+  //register the drivers
+  OGRRegisterAll();
+  //fetch the shape file driver
+  OGRSFDriver *poDriver;
+  poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(imageType.c_str());
+  if( poDriver == NULL ){
+    string errorString="FileOpenError";
+    throw(errorString);
+  }
+  //create the data source
+  m_datasource=poDriver->CreateDataSource(m_filename.c_str(),NULL);
+  if(m_datasource==NULL){
+    string errorString="Creation of output file failed";
+    throw(errorString);
+  }
+}
+
+void ImgWriterOgr::setCodec(OGRSFDriver *poDriver){
+  OGRRegisterAll();
+  if( poDriver == NULL ){
+    string errorString="FileOpenError";
+    throw(errorString);
+  }
+  //create the data source
+  m_datasource=poDriver->CreateDataSource(m_filename.c_str(),NULL);
+  if(m_datasource==NULL){
+    string errorString="Creation of output file failed";
+    throw(errorString);
+  }
+}
+
+// OGRLayer* ImgWriterOgr::copyLayer(OGRLayer* poSrcLayer, const string& layername, char** papszOptions)
+// {
+//   return(m_datasource->CopyLayer(poSrcLayer, layername.c_str(),papszOptions));
+// }
+
+OGRLayer* ImgWriterOgr::createLayer(const string& layername, const string& theProjection, const OGRwkbGeometryType& eGType, char** papszOptions)
+{
+  if( !m_datasource->TestCapability( ODsCCreateLayer ) ){
+    string errorString="Test capability to create layer failed";
+    throw(errorString);
+  }
+  //papszOptions = CSLSetNameValue( papszOptions, "DIM", "1" );
+  //if points: use wkbPoint
+  //if no constraints on the types geometry to be written: use wkbUnknown 
+  OGRLayer* poLayer;
+  if(theProjection!=""){
+    if(theProjection.find("EPSPG:")!=string::npos){
+      int epsg_code=atoi(theProjection.substr(theProjection.find_first_not_of("EPSG:")).c_str());
+      OGRSpatialReference oSRS;
+      oSRS.importFromEPSG(epsg_code);
+      poLayer=m_datasource->CreateLayer( layername.c_str(), &oSRS, eGType,papszOptions );
+    }
+    else{
+      OGRSpatialReference oSRS(theProjection.c_str());
+      poLayer=m_datasource->CreateLayer( layername.c_str(), &oSRS, eGType,papszOptions );
+    }
+  }
+  else
+    poLayer=m_datasource->CreateLayer( layername.c_str(), NULL, eGType,papszOptions );
+  //check if destroy is needed?!
+  CSLDestroy( papszOptions );
+  if( poLayer == NULL ){
+    string errorstring="Layer creation failed";
+    throw(errorstring);
+  }
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  return poLayer;
+}
+
+void ImgWriterOgr::createField(const string& fieldname, const OGRFieldType& fieldType, int theLayer)
+{
+  OGRFieldDefn oField( fieldname.c_str(), fieldType );
+  if(fieldType==OFTString)
+    oField.SetWidth(32);
+  if(theLayer<0)
+    theLayer=m_datasource->GetLayerCount()-1;//get back layer
+  if(m_datasource->GetLayer(theLayer)->CreateField( &oField ) != OGRERR_NONE ){
+      ostringstream es;
+      es << "Creating field " << fieldname << " failed";
+      string errorString=es.str();
+      throw(errorString);
+  }
+}
+
+int ImgWriterOgr::getFields(vector<string>& fields, int layer) const
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if((poLayer = m_datasource->GetLayer(layer))==NULL){
+    string errorstring="Could not get layer";
+    throw(errorstring);
+  }
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  fields.clear();
+  fields.resize(poFDefn->GetFieldCount());
+  for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+    OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+    fields[iField]=poFieldDefn->GetNameRef();
+  }
+  return(fields.size());
+}
+
+int ImgWriterOgr::getFields(vector<OGRFieldDefn*>& fields, int layer) const
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if((poLayer = m_datasource->GetLayer(layer))==NULL){
+    string errorstring="Could not get layer";
+    throw(errorstring);
+  }
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  fields.clear();
+  fields.resize(poFDefn->GetFieldCount());
+  for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
+    OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+    fields[iField]=poFDefn->GetFieldDefn(iField);
+  }
+  assert(fields.size()==getFieldCount());
+  return(fields.size());
+}
+
+void ImgWriterOgr::copyFields(const ImgReaderOgr& imgReaderOgr, int theLayer){
+  if(theLayer<0)
+    theLayer=m_datasource->GetLayerCount()-1;//get back layer
+  //get fields from imgReaderOgr
+  vector<OGRFieldDefn*> fields;
+  
+  imgReaderOgr.getFields(fields);
+//   OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  for(int iField=0;iField<fields.size();++iField){
+    if(m_datasource->GetLayer(theLayer)->CreateField(fields[iField]) != OGRERR_NONE ){
+      ostringstream es;
+      es << "Creating field " << fields[iField]->GetNameRef() << " failed";
+      string errorString=es.str();
+      throw(errorString);
+    }
+  }
+}
+
+void ImgWriterOgr::addPoint(double x, double y, const map<string,double>& pointAttributes, string fieldName, const string& theId){
+  OGRFeature *poFeature;
+  poFeature=createFeature();
+  OGRPoint pt;
+  poFeature->SetField( fieldName.c_str(), theId.c_str());
+  for(map<string,double>::const_iterator mit=pointAttributes.begin();mit!=pointAttributes.end();++mit){
+    poFeature->SetField((mit->first).c_str(), mit->second);
+  }
+  pt.setX(x);
+  pt.setY(y);
+  poFeature->SetGeometry( &pt );
+  if(createFeature(poFeature)!=OGRERR_NONE){
+    string errorString="Failed to create feature in shapefile";
+    throw(errorString);
+  }
+  OGRFeature::DestroyFeature( poFeature );
+}
+
+void ImgWriterOgr::addPoint(double x, double y, const map<string,double>& pointAttributes, string fieldName, int theId){
+  OGRFeature *poFeature;
+  poFeature = createFeature();
+  OGRPoint pt;
+  if(pointAttributes.size()+1!=poFeature->GetFieldCount()){
+    ostringstream ess;
+    ess << "Failed to add feature: " << pointAttributes.size() << " !=" << poFeature->GetFieldCount() << endl;
+    throw(ess.str());
+  }
+  assert(pointAttributes.size()+1==poFeature->GetFieldCount());
+  poFeature->SetField( fieldName.c_str(), theId);
+  int fid=0;
+  for(map<string,double>::const_iterator mit=pointAttributes.begin();mit!=pointAttributes.end();++mit){
+    poFeature->SetField((mit->first).c_str(),mit->second);
+  }
+  pt.setX(x);
+  pt.setY(y);
+  poFeature->SetGeometry( &pt );
+  if(createFeature(poFeature)!=OGRERR_NONE){
+    string errorString="Failed to create feature in shapefile";
+    throw(errorString);
+  }
+  OGRFeature::DestroyFeature( poFeature );
+}
+
+//add a line string (polygon), caller is responsible to close the line (end point=start point)
+void ImgWriterOgr::addLineString(vector<OGRPoint*>& points, const string& fieldName, int theId){
+  OGRFeature *poFeature;
+  poFeature = createFeature();
+  poFeature->SetStyleString("PEN(c:#FF0000,w:5px)");//see also http://www.gdal.org/ogr/ogr_feature_style.html
+  poFeature->SetField( fieldName.c_str(), theId);
+  OGRLineString theLineString;
+  theLineString.setNumPoints(points.size());
+  for(int ip=0;ip<points.size();++ip)
+    theLineString.setPoint(ip,points[ip]);
+  if(poFeature->SetGeometry( &theLineString )!=OGRERR_NONE){
+    string errorString="Failed to set line OGRLineString as feature geometry";
+    throw(errorString);
+  }
+  if(createFeature(poFeature)!=OGRERR_NONE){
+    string errorString="Failed to create feature in shapefile";
+    throw(errorString);
+  }
+  OGRFeature::DestroyFeature( poFeature );
+}
+
+//add a ring (polygon), caller is responsible to close the line (end point=start point)?
+void ImgWriterOgr::addRing(vector<OGRPoint*>& points, const string& fieldName, int theId){
+  OGRFeature *poFeature;
+  poFeature = createFeature();
+  poFeature->SetStyleString("PEN(c:#FF0000,w:5px)");//see also http://www.gdal.org/ogr/ogr_feature_style.html
+  poFeature->SetField( fieldName.c_str(), theId);
+  // OGRLineString theLineString;
+  // theLineString.setNumPoints(points.size());
+  OGRPolygon thePolygon;
+  OGRLinearRing theRing;
+  for(int ip=0;ip<points.size();++ip)
+    theRing.addPoint(points[ip]);
+  //  theRing.addPoint(points[0]);//close the ring
+  theRing.closeRings();//redundent with previous line?
+  thePolygon.addRing(&theRing);
+  // SetSpatialFilter(&thePolygon)
+  poFeature->SetGeometry( &thePolygon );
+  if(createFeature(poFeature)!=OGRERR_NONE){
+    string errorString="Failed to create feature in shapefile";
+    throw(errorString);
+    OGRFeature::DestroyFeature( poFeature );
+  }
+  if(poFeature->SetGeometry( &thePolygon )!=OGRERR_NONE){
+    string errorString="Failed to set polygon as feature geometry";
+    throw(errorString);
+  }
+  OGRFeature::DestroyFeature( poFeature );
+}
+
+//add a line string (polygon), caller is responsible to close the line (end point=start point)
+void ImgWriterOgr::addLineString(vector<OGRPoint*>& points, const string& fieldName, const string& theId){
+  OGRFeature *poFeature;
+  poFeature = createFeature();
+  poFeature->SetField( fieldName.c_str(), theId.c_str());
+  OGRLineString theLineString;
+  theLineString.setNumPoints(points.size());
+  for(int ip=0;ip<points.size();++ip)
+    theLineString.setPoint(ip,points[ip]);
+  if(poFeature->SetGeometry( &theLineString )!=OGRERR_NONE){
+    string errorString="Failed to set line OGRLineString as feature geometry";
+    throw(errorString);
+  }
+  if(createFeature(poFeature)!=OGRERR_NONE){
+    string errorString="Failed to create feature in shapefile";
+    throw(errorString);
+  }
+  OGRFeature::DestroyFeature( poFeature );
+}
+
+OGRFeature* ImgWriterOgr::createFeature(){
+  return(OGRFeature::CreateFeature(m_datasource->GetLayer(m_datasource->GetLayerCount()-1)->GetLayerDefn()));
+}
+
+OGRErr ImgWriterOgr::createFeature(OGRFeature *theFeature){
+  return m_datasource->GetLayer(m_datasource->GetLayerCount()-1)->CreateFeature(theFeature);
+}
+
+int ImgWriterOgr::getFieldCount(int layer) const
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if((poLayer = m_datasource->GetLayer(layer))==NULL){
+    string errorstring="Could not get layer";
+    throw(errorstring);
+  }
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  return(poFDefn->GetFieldCount());
+}
+
+int ImgWriterOgr::getFeatureCount() const
+{
+  return(getLayer()->GetFeatureCount());
+}
+
+int ImgWriterOgr::ascii2shape(const string& filename, const string &layername, const vector<string>& fieldName, const vector<OGRFieldType>& fieldType, short colX, short colY, const string& theProjection, const OGRwkbGeometryType& eGType)
+{
+  char     **papszOptions=NULL;
+  createLayer(layername, theProjection, eGType, papszOptions);
+  //create attribute fields that should appear on the layer. Fields must be added to the layer before any features are written. To create a field we initialize an OGRField object with the information about the field. In the case of Shapefiles, the field width and precision is significant in the creation of the output .dbf file, so we set it specifically, though generally the defaults are OK
+  int ncol=fieldName.size();
+  assert(fieldName.size()==fieldType.size());
+  assert(colX>=0);
+  assert(colY>=0);
+  assert(colX<ncol+2);
+  assert(colY<ncol+2);
+  for(int ifield=0;ifield<ncol;++ifield)
+    createField(fieldName[ifield],fieldType[ifield]);
+  //create a local OGRFeature, set attributes and attach geometry before trying to write it to the layer. It is imperative that this feature be instantiated from the OGRFeatureDefn associated with the layer it will be written to.
+  //todo: try to open and catch if failure...
+  ifstream fpoints(filename.c_str(),ios::in);
+  string line;
+  OGRPolygon thePolygon;
+  OGRLinearRing theRing;
+  OGRPoint firstPoint;
+  OGRFeature *polyFeature;
+  if(eGType!=wkbPoint)
+    polyFeature=createFeature();
+  while(getline(fpoints,line)){
+    OGRFeature *pointFeature;
+    if(eGType==wkbPoint)
+      pointFeature=createFeature();
+    OGRPoint thePoint;
+    bool skip=false;
+    istringstream ist(line);
+    string value;
+    int colId=0;
+    int fieldId=0;
+    while(ist >> value){
+      if(colId==colX)
+	thePoint.setX(atof(value.c_str()));
+      else if(colId==colY)
+	thePoint.setY(atof(value.c_str()));
+      else{
+        switch(fieldType[fieldId]){
+        case(OFTReal):
+	  if(eGType==wkbPoint)
+	    pointFeature->SetField(fieldId,atof(value.c_str()));
+	  else if(firstPoint.IsEmpty())
+	    polyFeature->SetField(fieldId,atof(value.c_str()));
+          break;
+        case(OFTInteger):
+	  if(eGType==wkbPoint)
+	    pointFeature->SetField(fieldId,atoi(value.c_str()));
+	  else if(firstPoint.IsEmpty())
+	    polyFeature->SetField(fieldId,atof(value.c_str()));
+          break;
+        case(OFTString):
+	  if(eGType==wkbPoint)
+	    pointFeature->SetField(fieldId,value.c_str());
+	  else if(firstPoint.IsEmpty())
+	    polyFeature->SetField(fieldId,atof(value.c_str()));
+          break;
+        default:
+          break;
+        }
+        ++fieldId;
+      }
+      ++colId;
+    }
+    if(colId!=fieldId+2){
+      ostringstream ess;
+      ess << "Error: colId = " << colId << " is different from fieldId+2 = " << fieldId;
+      throw(ess.str());
+    }
+    if(eGType==wkbPoint){
+      pointFeature->SetGeometry( &thePoint );
+      if(createFeature(pointFeature)!=OGRERR_NONE){
+	string errorString="Failed to create feature in shapefile";
+	throw(errorString);
+	OGRFeature::DestroyFeature( pointFeature );
+      }
+    }
+    else{
+      if(firstPoint.IsEmpty()){
+	firstPoint=thePoint;
+      }
+      theRing.addPoint(&thePoint);
+    }
+  }
+  if(eGType!=wkbPoint){
+    theRing.addPoint(&firstPoint);//close the ring
+    thePolygon.addRing(&theRing);
+    // SetSpatialFilter(&thePolygon)
+    polyFeature->SetGeometry( &thePolygon );
+    if(createFeature(polyFeature)!=OGRERR_NONE){
+      string errorString="Failed to create feature in shapefile";
+      throw(errorString);
+      OGRFeature::DestroyFeature( polyFeature );
+    }
+  }
+  return getFeatureCount();
+}
+
+int ImgWriterOgr::addData(const ImgReaderGdal& imgReader, int theLayer, bool verbose)
+{
+  OGRLayer  *poLayer;
+  if(theLayer<0)
+    theLayer=m_datasource->GetLayerCount()-1;//get back layer
+  assert(m_datasource->GetLayerCount()>theLayer);
+  if(verbose)
+    cout << "number of layers: " << m_datasource->GetLayerCount() << endl;
+  if(verbose)
+    cout << "get layer " << theLayer << endl;
+  poLayer = m_datasource->GetLayer(theLayer);
+  //start reading features from the layer
+  OGRFeature *poFeature;
+  if(verbose)
+    cout << "reset reading" << endl;
+  poLayer->ResetReading();
+  for(int iband=0;iband<imgReader.nrOfBand();++iband){
+    ostringstream fs;
+    fs << "band" << iband;
+    createField(fs.str(),OFTReal);
+  }
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  int nfield=poFDefn->GetFieldCount();
+  if(verbose)
+    cout << "new number of fields: " << nfield << endl;
+  while( (poFeature = poLayer->GetNextFeature()) != NULL ){
+    OGRGeometry *poGeometry;
+    poGeometry = poFeature->GetGeometryRef();
+    assert(poGeometry != NULL 
+           && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+    OGRPoint *poPoint = (OGRPoint *) poGeometry;
+    double x=poPoint->getX();
+    double y=poPoint->getY();
+    for(int iband=0;iband<imgReader.nrOfBand();++iband){
+      double imgData;
+      imgReader.readData(imgData,GDT_Float64,x,y,iband);
+      //todo: put imgdata in field
+      ostringstream fs;
+      fs << "band" << iband;
+      poFeature->SetField(fs.str().c_str(),imgData);
+    }
+  }
+  return(nfield);
+}
+
diff --git a/src/imageclasses/ImgWriterOgr.h b/src/imageclasses/ImgWriterOgr.h
new file mode 100644
index 0000000..5005111
--- /dev/null
+++ b/src/imageclasses/ImgWriterOgr.h
@@ -0,0 +1,80 @@
+/**********************************************************************
+ImgWriterOgr.h: class to write vector files using OGR API library
+Copyright (C) 2008-2012 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools 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.
+
+pktools 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 pktools.  If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#ifndef _IMGWRITEROGR_H_
+#define _IMGWRITEROGR_H_
+
+#include <assert.h>
+#include <fstream>
+#include <string>
+#include <sstream>
+#include <map>
+#include <vector>
+#include "ogrsf_frmts.h"
+#include "ImgReaderGdal.h"
+#include "ImgWriterGdal.h"
+#include "ImgReaderOgr.h"
+
+using namespace std;
+
+//--------------------------------------------------------------------------
+class ImgWriterOgr
+{
+public:
+  ImgWriterOgr(void);
+  ImgWriterOgr(const string& filename);
+  ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr);
+  ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr, bool copyData);
+  ~ImgWriterOgr(void);
+  void open(const string& filename, const string& imageType="ESRI Shapefile");
+  void close(void);
+  int ascii2shape(const string& filename, const string &layername, const vector<string>& fieldName, const vector<OGRFieldType>& fieldType, short colX=1, short colY=2, const string& theProjection="", const OGRwkbGeometryType& eGType=wkbPoint);
+  OGRLayer* createLayer(const string& layername="New layer", const string& theProjection="", const OGRwkbGeometryType& eGType=wkbUnknown, char** papszOptions=NULL);
+  OGRLayer* copyLayer(OGRLayer* poSrcLayer, const string& layername, char** papszOptions=NULL);
+  void createField(const string& fieldname, const OGRFieldType& fieldType, int theLayer=-1);//default: get back layer
+  OGRLayer* getLayer(int layer=0) const {return m_datasource->GetLayer(layer);};
+  string getLayerName(int layer=0){return m_datasource->GetLayer(layer)->GetLayerDefn()->GetName();};
+  int getFields(vector<string>& fields, int layer=0) const;
+  int getFields(vector<OGRFieldDefn*>& fields, int layer=0) const;
+  void copyFields(const ImgReaderOgr& imgReaderOgr, int theLayer=-1);//default: get back layer
+  void addLineString(vector<OGRPoint*>& points, const string& fieldName, const string& theId);
+  void addRing(vector<OGRPoint*>& points, const string& fieldName, int theId);
+  void addLineString(vector<OGRPoint*>& points, const string& fieldName, int theId);
+  void addPoint(double x, double y, const map<string,double>& pointAttributes, string fieldName, const string& theId);
+  void addPoint(double x, double y, const map<string,double>& pointAttributes, string fieldName, int theId);
+  int addData(const ImgReaderGdal& imgReader, int layer=-1, bool verbose=false);
+  OGRFeature* createFeature();
+  OGRErr createFeature(OGRFeature* theFeature);
+  int getFieldCount(int layer=0) const;
+  int getFeatureCount() const;
+  OGRDataSource* getDataSource(void) {return m_datasource;};
+  OGRSFDriver* getDriver(void) const {return m_datasource->GetDriver();};
+
+protected:
+  void setCodec(const string& imageType);
+  void setCodec(OGRSFDriver *poDriver);
+  
+//   OGRLayer* getLayer(int layer=-1);
+    
+  string m_filename;
+  OGRDataSource *m_datasource;
+//   vector<OGRLayer*> m_layers;
+};
+
+#endif // _IMGWRITEROGR_H_
diff --git a/src/imageclasses/Makefile.am b/src/imageclasses/Makefile.am
new file mode 100644
index 0000000..227059f
--- /dev/null
+++ b/src/imageclasses/Makefile.am
@@ -0,0 +1,19 @@
+AM_LDFLAGS = $(GDAL_LDFLAGS) @AM_LDFLAGS@
+AM_CXXFLAGS = -I$(top_srcdir)/src $(GDAL_CFLAGS) @AM_CXXFLAGS@
+
+###############################################################################
+# THE LIBRARIES TO BUILD
+###############################################################################
+
+# the library names to build (note we are building static libs only)
+noinst_LIBRARIES = libimageClasses.a
+
+# where to install the headers on the system
+libimageClasses_adir = $(includedir)/imageclasses
+
+# the list of header files that belong to the library (to be installed later)
+libimageClasses_a_HEADERS = ImgReaderGdal.h  ImgReaderOgr.h  ImgWriterGdal.h  ImgWriterOgr.h
+
+# the sources to add to the library and to add to the source distribution
+libimageClasses_a_SOURCES = $(libimageClasses_a_HEADERS) ImgReaderGdal.cc  ImgReaderOgr.cc  ImgWriterGdal.cc  ImgWriterOgr.cc
+###############################################################################
diff --git a/src/imageclasses/Makefile.in b/src/imageclasses/Makefile.in
new file mode 100644
index 0000000..372539a
--- /dev/null
+++ b/src/imageclasses/Makefile.in
@@ -0,0 +1,512 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+subdir = src/imageclasses
+DIST_COMMON = $(libimageClasses_a_HEADERS) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_gdal.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LIBRARIES = $(noinst_LIBRARIES)
+AR = ar
+ARFLAGS = cru
+libimageClasses_a_AR = $(AR) $(ARFLAGS)
+libimageClasses_a_LIBADD =
+am__objects_1 =
+am_libimageClasses_a_OBJECTS = $(am__objects_1) \
+	ImgReaderGdal.$(OBJEXT) ImgReaderOgr.$(OBJEXT) \
+	ImgWriterGdal.$(OBJEXT) ImgWriterOgr.$(OBJEXT)
+libimageClasses_a_OBJECTS = $(am_libimageClasses_a_OBJECTS)
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+	-o $@
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(libimageClasses_a_SOURCES)
+DIST_SOURCES = $(libimageClasses_a_SOURCES)
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(libimageClasses_adir)"
+HEADERS = $(libimageClasses_a_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_CXXFLAGS = -I$(top_srcdir)/src $(GDAL_CFLAGS) @AM_CXXFLAGS@
+AM_LDFLAGS = $(GDAL_LDFLAGS) @AM_LDFLAGS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FANN_CFLAGS = @FANN_CFLAGS@
+FANN_LIBS = @FANN_LIBS@
+FILECLASSES_OPT = @FILECLASSES_OPT@
+GDAL_CFLAGS = @GDAL_CFLAGS@
+GDAL_CONFIG = @GDAL_CONFIG@
+GDAL_DEP_LDFLAGS = @GDAL_DEP_LDFLAGS@
+GDAL_LDFLAGS = @GDAL_LDFLAGS@
+GDAL_OGR_ENABLED = @GDAL_OGR_ENABLED@
+GDAL_VERSION = @GDAL_VERSION@
+GREP = @GREP@
+GSL_CFLAGS = @GSL_CFLAGS@
+GSL_LIBS = @GSL_LIBS@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+
+###############################################################################
+# THE LIBRARIES TO BUILD
+###############################################################################
+
+# the library names to build (note we are building static libs only)
+noinst_LIBRARIES = libimageClasses.a
+
+# where to install the headers on the system
+libimageClasses_adir = $(includedir)/imageclasses
+
+# the list of header files that belong to the library (to be installed later)
+libimageClasses_a_HEADERS = ImgReaderGdal.h  ImgReaderOgr.h  ImgWriterGdal.h  ImgWriterOgr.h
+
+# the sources to add to the library and to add to the source distribution
+libimageClasses_a_SOURCES = $(libimageClasses_a_HEADERS) ImgReaderGdal.cc  ImgReaderOgr.cc  ImgWriterGdal.cc  ImgWriterOgr.cc
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cc .o .obj
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/imageclasses/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign src/imageclasses/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLIBRARIES:
+	-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
+libimageClasses.a: $(libimageClasses_a_OBJECTS) $(libimageClasses_a_DEPENDENCIES) 
+	-rm -f libimageClasses.a
+	$(libimageClasses_a_AR) libimageClasses.a $(libimageClasses_a_OBJECTS) $(libimageClasses_a_LIBADD)
+	$(RANLIB) libimageClasses.a
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ImgReaderGdal.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ImgReaderOgr.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ImgWriterGdal.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ImgWriterOgr.Po at am__quote@
+
+.cc.o:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+install-libimageClasses_aHEADERS: $(libimageClasses_a_HEADERS)
+	@$(NORMAL_INSTALL)
+	test -z "$(libimageClasses_adir)" || $(MKDIR_P) "$(DESTDIR)$(libimageClasses_adir)"
+	@list='$(libimageClasses_a_HEADERS)'; test -n "$(libimageClasses_adir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libimageClasses_adir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(libimageClasses_adir)" || exit $$?; \
+	done
+
+uninstall-libimageClasses_aHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(libimageClasses_a_HEADERS)'; test -n "$(libimageClasses_adir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(libimageClasses_adir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(libimageClasses_adir)" && rm -f $$files
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LIBRARIES) $(HEADERS)
+installdirs:
+	for dir in "$(DESTDIR)$(libimageClasses_adir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-libimageClasses_aHEADERS
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-libimageClasses_aHEADERS
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+	clean-noinstLIBRARIES ctags distclean distclean-compile \
+	distclean-generic distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-libimageClasses_aHEADERS install-man \
+	install-pdf install-pdf-am install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am uninstall-libimageClasses_aHEADERS
+
+###############################################################################
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pktools.git



More information about the Pkg-grass-devel mailing list