cleanup
This commit is contained in:
parent
3377641ee3
commit
0411d8c19b
120
CMakeLists.txt
120
CMakeLists.txt
@ -7,6 +7,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
add_compile_options(-Wno-missing-template-arg-list-after-template-kw)
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_search_module(EDITLINE REQUIRED libeditline)
|
||||
|
||||
find_package(GCTL REQUIRED)
|
||||
find_package(GCTL_MESH REQUIRED)
|
||||
find_package(GCTL_OPTIMIZATION REQUIRED)
|
||||
@ -16,14 +22,36 @@ include_directories(${GCTL_MESH_INC_DIR})
|
||||
include_directories(${GCTL_OPTIMIZATION_INC_DIR})
|
||||
include_directories(${GCTL_POTENTIAL_INC_DIR})
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${BIN_DIR})
|
||||
|
||||
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
|
||||
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
|
||||
message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
|
||||
|
||||
if(GCTL_FOUND)
|
||||
message(STATUS "GCTL Version: " ${GCTL_VERSION})
|
||||
endif()
|
||||
|
||||
if(GCTL_MESH_FOUND)
|
||||
message(STATUS "GCTL_MESH Version: " ${GCTL_MESH_VERSION})
|
||||
endif()
|
||||
|
||||
if(GCTL_OPTIMIZATION_FOUND)
|
||||
message(STATUS "GCTL_OPTIMIZATION Version: " ${GCTL_OPTIMIZATION_VERSION})
|
||||
endif()
|
||||
|
||||
if(GCTL_POTENTIAL_FOUND)
|
||||
message(STATUS "GCTL_POTENTIAL Version: " ${GCTL_POTENTIAL_VERSION})
|
||||
endif()
|
||||
|
||||
# 传递安装地址给编译期宏变量
|
||||
option(GCTL_TOOLKITS_INSTALL_PREFIX "Pass install directory." ON)
|
||||
set(DIR_VAR ${CMAKE_INSTALL_PREFIX})
|
||||
|
||||
# 加入一个头文件配置,让cmake对源码进行操作
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/config.h.in"
|
||||
"${PROJECT_SOURCE_DIR}/gctl_toolkits_config.h"
|
||||
)
|
||||
|
||||
macro(add_toolkit name lib1 lib2 lib3 lib4)
|
||||
aux_source_directory(${name} ${name}_src)
|
||||
add_executable(${name} ${${name}_src})
|
||||
@ -49,27 +77,63 @@ macro(add_toolkit name lib1 lib2 lib3 lib4)
|
||||
install(TARGETS ${name} RUNTIME DESTINATION sbin)
|
||||
endmacro()
|
||||
|
||||
add_toolkit(2minfo ON ON OFF OFF)
|
||||
add_toolkit(addnoise ON OFF OFF OFF)
|
||||
add_toolkit(cutprofile ON OFF OFF OFF)
|
||||
add_toolkit(fractopo ON OFF OFF OFF)
|
||||
add_toolkit(gm3d ON OFF OFF OFF)
|
||||
add_toolkit(gmsh2vtk ON OFF OFF OFF)
|
||||
add_toolkit(gmshinfo ON OFF OFF OFF)
|
||||
add_toolkit(grd2xyz ON OFF OFF OFF)
|
||||
add_toolkit(handyman ON OFF OFF OFF)
|
||||
add_toolkit(lbsi ON OFF ON OFF)
|
||||
add_toolkit(lki ON OFF ON OFF)
|
||||
add_toolkit(nc2other ON OFF OFF OFF)
|
||||
add_toolkit(ncget ON OFF OFF OFF)
|
||||
add_toolkit(ncinfo ON OFF OFF OFF)
|
||||
add_toolkit(shc2xyz ON OFF OFF OFF)
|
||||
add_toolkit(slbsi ON OFF ON OFF)
|
||||
add_toolkit(sph2plane ON OFF OFF OFF)
|
||||
add_toolkit(tetgen2gmsh ON OFF OFF OFF)
|
||||
add_toolkit(tetgm ON OFF ON ON)
|
||||
add_toolkit(trackline ON OFF OFF OFF)
|
||||
add_toolkit(triangle2gmsh ON OFF OFF OFF)
|
||||
add_toolkit(txtinfo ON OFF OFF OFF)
|
||||
add_toolkit(xyz2nc ON OFF OFF OFF)
|
||||
add_toolkit(xyz2sph ON OFF OFF OFF)
|
||||
if(GCTL_FOUND)
|
||||
add_toolkit(addnoise ON OFF OFF OFF)
|
||||
add_toolkit(cutprofile ON OFF OFF OFF)
|
||||
add_toolkit(fractopo ON OFF OFF OFF)
|
||||
add_toolkit(gm3d ON OFF OFF OFF)
|
||||
add_toolkit(gmsh2vtk ON OFF OFF OFF)
|
||||
add_toolkit(gmshinfo ON OFF OFF OFF)
|
||||
add_toolkit(grd2xyz ON OFF OFF OFF)
|
||||
add_toolkit(handyman ON OFF OFF OFF)
|
||||
add_toolkit(nc2other ON OFF OFF OFF)
|
||||
add_toolkit(ncget ON OFF OFF OFF)
|
||||
add_toolkit(ncinfo ON OFF OFF OFF)
|
||||
add_toolkit(shc2xyz ON OFF OFF OFF)
|
||||
add_toolkit(sph2plane ON OFF OFF OFF)
|
||||
add_toolkit(tetgen2gmsh ON OFF OFF OFF)
|
||||
add_toolkit(trackline ON OFF OFF OFF)
|
||||
add_toolkit(triangle2gmsh ON OFF OFF OFF)
|
||||
add_toolkit(txtinfo ON OFF OFF OFF)
|
||||
add_toolkit(xyz2nc ON OFF OFF OFF)
|
||||
add_toolkit(xyz2sph ON OFF OFF OFF)
|
||||
endif()
|
||||
|
||||
if(GCTL_FOUND AND GCTL_MESH_FOUND)
|
||||
add_toolkit(2minfo ON ON OFF OFF)
|
||||
endif()
|
||||
|
||||
if(GCTL_FOUND AND GCTL_OPTIMIZATION_FOUND)
|
||||
add_toolkit(slbsi ON OFF ON OFF)
|
||||
add_toolkit(lbsi ON OFF ON OFF)
|
||||
add_toolkit(lki ON OFF ON OFF)
|
||||
add_toolkit(levy_planner ON OFF ON OFF)
|
||||
endif()
|
||||
|
||||
if(GCTL_FOUND AND GCTL_OPTIMIZATION_FOUND AND GCTL_POTENTIAL_FOUND)
|
||||
add_toolkit(tetgm ON OFF ON ON)
|
||||
endif()
|
||||
|
||||
if(EDITLINE_FOUND AND GCTL_FOUND)
|
||||
add_toolkit(dsviewer ON OFF OFF OFF)
|
||||
target_link_libraries(dsviewer PRIVATE ${EDITLINE_LIBRARIES})
|
||||
|
||||
file(GLOB HELP_DOC dsviewer/dsviewer.md)
|
||||
install(FILES ${HELP_DOC} DESTINATION sbin/share)
|
||||
endif()
|
||||
|
||||
if(EDITLINE_FOUND AND GCTL_FOUND AND GCTL_MESH_FOUND)
|
||||
add_toolkit(gridmanager ON ON OFF OFF)
|
||||
target_link_libraries(gridmanager PRIVATE ${EDITLINE_LIBRARIES})
|
||||
|
||||
file(GLOB HELP_DOC gridmanager/readme_gridmanager.md)
|
||||
install(FILES ${HELP_DOC} DESTINATION sbin/share)
|
||||
endif()
|
||||
|
||||
if(EDITLINE_FOUND AND GCTL_FOUND AND GCTL_POTENTIAL_FOUND)
|
||||
add_toolkit(gridmanager-potential ON ON OFF ON)
|
||||
target_link_libraries(gridmanager-potential PRIVATE ${EDITLINE_LIBRARIES})
|
||||
|
||||
file(GLOB HELP_DOC gridmanager-potential/readme_gridmanager_potential.md)
|
||||
install(FILES ${HELP_DOC} DESTINATION sbin/share)
|
||||
endif()
|
522
LICENSE
Normal file
522
LICENSE
Normal file
@ -0,0 +1,522 @@
|
||||
GCTL License
|
||||
--------------
|
||||
|
||||
GCTL is distributed under a dual licensing scheme. 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
|
||||
of the License, or (at your option) any later version. A copy of the GNU
|
||||
Lesser General Public License is reproduced below.
|
||||
|
||||
If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
the GCTL, please consider the option to obtain a commercial license for a
|
||||
fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
to include some description of your company and the realm of its activities.
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
=====================================================================
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser 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 Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "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
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY 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
|
||||
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library 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 library 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random
|
||||
Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
1
config.h.in
Normal file
1
config.h.in
Normal file
@ -0,0 +1 @@
|
||||
#cmakedefine GCTL_TOOLKITS_INSTALL_PREFIX "${DIR_VAR}"
|
26
dsviewer/CMakeLists.backup
Normal file
26
dsviewer/CMakeLists.backup
Normal file
@ -0,0 +1,26 @@
|
||||
set(TOOL_NAME dsviewer)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_search_module(EDITLINE REQUIRED libeditline)
|
||||
include_directories(${EDITLINE_INCLUDE_DIRS})
|
||||
link_directories(${EDITLINE_LIBRARY_DIRS})
|
||||
|
||||
aux_source_directory(. TOOL_SRC)
|
||||
add_executable(${TOOL_NAME} ${TOOL_SRC})
|
||||
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
target_link_libraries(${TOOL_NAME} PRIVATE gctl)
|
||||
target_link_libraries(${TOOL_NAME} PRIVATE ${EDITLINE_LIBRARIES})
|
||||
|
||||
install(TARGETS ${TOOL_NAME} RUNTIME DESTINATION sbin)
|
||||
|
||||
file(GLOB HELP_DOC *.md)
|
||||
install(FILES ${HELP_DOC} DESTINATION sbin/share)
|
614
dsviewer/dsviewer.cpp
Normal file
614
dsviewer/dsviewer.cpp
Normal file
@ -0,0 +1,614 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. 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
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "dsviewer.h"
|
||||
// We use the editline library to handle all inputs
|
||||
#include "editline.h"
|
||||
// install configuration
|
||||
#include "../gctl_toolkits_config.h"
|
||||
|
||||
cmd_pair curr_cmd; // Executing command
|
||||
gctl::dsv_io tc; // Grid object
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Strip whitespace from the start and end of STRING. Return a pointer
|
||||
* into STRING.
|
||||
*/
|
||||
char *stripwhite(char *string)
|
||||
{
|
||||
char *s, *t;
|
||||
|
||||
for (s = string; isspace(*s); s++) ;
|
||||
|
||||
if (*s == 0)
|
||||
return s;
|
||||
|
||||
t = s + strlen(s) - 1;
|
||||
while (t > s && isspace(*t))
|
||||
t--;
|
||||
*++t = '\0';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Generator function for command completion. STATE lets us
|
||||
know whether to start from scratch; without any state
|
||||
(i.e. STATE == 0), then we start at the top of the list. */
|
||||
char *command_generator(const char *text, int state)
|
||||
{
|
||||
static int list_index, len;
|
||||
|
||||
/* If this is a new word to complete, initialize now. This
|
||||
includes saving the length of TEXT for efficiency, and
|
||||
initializing the index variable to 0. */
|
||||
if (!state)
|
||||
{
|
||||
list_index = 0;
|
||||
len = strlen(text);
|
||||
}
|
||||
|
||||
/* Return the next name which partially matches from the command list. */
|
||||
while (list_index < CMD_NUM)
|
||||
{
|
||||
if (std::string(text) == commands[list_index].name.substr(0, len))
|
||||
{
|
||||
//const char* name = commands[list_index].name.data();
|
||||
return strdup(commands[list_index].name.data());
|
||||
}
|
||||
else list_index++;
|
||||
}
|
||||
|
||||
/* If no names matched, then return NULL. */
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempt to complete on the contents of TEXT. START and END
|
||||
* bound the region of rl_line_buffer that contains the word to
|
||||
* complete. TEXT is the word to complete. We can use the entire
|
||||
* contents of rl_line_buffer in case we want to do some simple
|
||||
* parsing. Return the array of matches, or NULL if there aren't any.
|
||||
*/
|
||||
char **dsviewer_completion(const char *text, int start, int end)
|
||||
{
|
||||
char **matches = nullptr;
|
||||
|
||||
/* If this word is at the start of the line, then it is a command
|
||||
to complete. Otherwise it is the name of a file in the current
|
||||
directory. */
|
||||
if (start == 0) matches = rl_completion_matches(text, command_generator);
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
void initialize_readline(void)
|
||||
{
|
||||
/* Allow conditional parsing of the ~/.inputrc file. */
|
||||
rl_readline_name = "dsviewer";
|
||||
|
||||
/* Tell the completer that we want a crack first. */
|
||||
rl_attempted_completion_function = dsviewer_completion;
|
||||
}
|
||||
|
||||
} // End C section
|
||||
|
||||
void display_cmds()
|
||||
{
|
||||
std::clog << "Command:\n";
|
||||
for (size_t i = 0; i < CMD_NUM - 1; i++)
|
||||
{
|
||||
std::clog << std::setw(12) << commands[i].name << ":\t" << commands[i].brief << "\n";
|
||||
}
|
||||
|
||||
std::clog << "\nEnter \"<command>?\" to see detailed instructions.\n";
|
||||
|
||||
std::clog << "\nCmdFile:\n";
|
||||
std::clog << "Each line of the input file(s) will be parsed as a command.\nEmpty lines and lines start with '#' will be skipped.\n";
|
||||
|
||||
std::clog << "\nHereDoc:\n";
|
||||
std::clog << "You can use HereDoc to input commands. A simple example is:\n";
|
||||
std::clog << "dsviewer << EOF\n";
|
||||
std::clog << "open file1.csv\n";
|
||||
std::clog << "info\n";
|
||||
std::clog << "EOF\n";
|
||||
return;
|
||||
}
|
||||
|
||||
void display_help(std::string input_cmd)
|
||||
{
|
||||
std::string install_dir = GCTL_TOOLKITS_INSTALL_PREFIX;
|
||||
std::ifstream helpin;
|
||||
open_infile(helpin, install_dir + "/sbin/share/dsviewer", ".md");
|
||||
|
||||
std::string tmp_l, tmp_help;
|
||||
std::vector<std::string> cmds;
|
||||
std::vector<std::string> helps;
|
||||
while (getline(helpin, tmp_l))
|
||||
{
|
||||
if (tmp_l.substr(0, 4) == "####")
|
||||
{
|
||||
cmds.push_back(tmp_l.substr(5));
|
||||
tmp_help = "";
|
||||
while (getline(helpin, tmp_l))
|
||||
{
|
||||
if (tmp_l == "") break;
|
||||
else tmp_help += tmp_l + "\n";
|
||||
}
|
||||
helps.push_back(tmp_help);
|
||||
}
|
||||
}
|
||||
helpin.close();
|
||||
|
||||
std::string cmd_str;
|
||||
for (size_t j = 0; j < cmds.size(); j++)
|
||||
{
|
||||
parse_string_to_value(cmds[j], ' ', true, cmd_str);
|
||||
if (input_cmd == cmd_str)
|
||||
{
|
||||
replace_all(tmp_l, cmds[j], "\\", "");
|
||||
std::cout << GCTL_BOLDGREEN << tmp_l << GCTL_RESET << "\n";
|
||||
std::cout << helps[j] << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void exec_cmd(std::string cmd)
|
||||
{
|
||||
std::string cmd_name;
|
||||
parse_string_to_value(cmd, ' ', true, cmd_name);
|
||||
|
||||
// show instruction if there is a question mark at end of the command
|
||||
if (cmd_name.back() == '?')
|
||||
{
|
||||
cmd_name = cmd_name.substr(0, cmd_name.length() - 1);
|
||||
display_help(cmd_name);
|
||||
return;
|
||||
}
|
||||
|
||||
// set default command to null
|
||||
curr_cmd = commands[CMD_NUM - 1];
|
||||
for (size_t i = 0; i < CMD_NUM - 1; i++)
|
||||
{
|
||||
if (cmd_name == commands[i].name)
|
||||
{
|
||||
curr_cmd = commands[i]; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (curr_cmd.func_p == nullptr) throw gctl::runtime_error("Invalid command: " + cmd_name);
|
||||
|
||||
std::vector<std::string> cmd_units;
|
||||
parse_string_with_quotes(cmd, cmd_units);
|
||||
|
||||
return curr_cmd.func_p(cmd_units);
|
||||
}
|
||||
|
||||
// This function is defined to avoid potential breakdown while running in script mode.
|
||||
void quit(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void info(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
std::smatch ret;
|
||||
std::regex pata("att"), patt("tag"), patc("col"), patr("row"), path("hdr");
|
||||
|
||||
// info [att|tag|hdr|col|row]
|
||||
int info_code = 0;
|
||||
if (cmd_units.size() > 1)
|
||||
{
|
||||
if (regex_search(cmd_units[1], ret, pata)) info_code = AttInfo;
|
||||
if (regex_search(cmd_units[1], ret, patt)) info_code = info_code|TagInfo;
|
||||
if (regex_search(cmd_units[1], ret, patc)) info_code = info_code|ColInfo;
|
||||
if (regex_search(cmd_units[1], ret, patr)) info_code = info_code|RowInfo;
|
||||
if (regex_search(cmd_units[1], ret, path)) info_code = info_code|HeadInfo;
|
||||
tc.info(info_code);
|
||||
}
|
||||
else tc.info(ColInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
void head(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// head [number]
|
||||
int h = 10;
|
||||
if (cmd_units.size() > 1) h = atoi(cmd_units[1].c_str());
|
||||
if (h <= 0) throw std::runtime_error("head: invalid number.");
|
||||
|
||||
_1s_vector cnames = tc.column_names();
|
||||
display_vector(cnames, std::cout, tc.delimeter());
|
||||
|
||||
_1s_array line;
|
||||
for (size_t i = 1; i <= h; i++)
|
||||
{
|
||||
tc.get_row(line, i);
|
||||
line.show(std::cout, tc.delimeter());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void tail(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// tail [number]
|
||||
int h = 10;
|
||||
if (cmd_units.size() > 1) h = atoi(cmd_units[1].c_str());
|
||||
if (h <= 0) throw std::runtime_error("tail: invalid number.");
|
||||
|
||||
_1s_vector cnames = tc.column_names();
|
||||
display_vector(cnames, std::cout, tc.delimeter());
|
||||
|
||||
_1s_array line;
|
||||
for (size_t i = tc.row_number() - h + 1; i <= tc.row_number(); i++)
|
||||
{
|
||||
tc.get_row(line, i);
|
||||
line.show(std::cout, tc.delimeter());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void set_enable(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// enable table|column|row [<name1>,<name2>...]
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("enable: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "table") tc.table_output(Enable);
|
||||
else if (cmd_units[1] == "column")
|
||||
{
|
||||
for (size_t i = 2; i < cmd_units.size(); i++)
|
||||
{
|
||||
tc.column_output(cmd_units[i], Enable);
|
||||
}
|
||||
}
|
||||
else if (cmd_units[1] == "row")
|
||||
{
|
||||
for (size_t i = 2; i < cmd_units.size(); i++)
|
||||
{
|
||||
tc.row_output(cmd_units[i], Enable);
|
||||
}
|
||||
}
|
||||
else throw std::runtime_error("enable: invalid parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
void set_disable(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// disable table|column|row [<name1>,<name2>...]
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("disable: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "table") tc.table_output(Disable);
|
||||
else if (cmd_units[1] == "column")
|
||||
{
|
||||
for (size_t i = 2; i < cmd_units.size(); i++)
|
||||
{
|
||||
tc.column_output(cmd_units[i], Disable);
|
||||
}
|
||||
}
|
||||
else if (cmd_units[1] == "row")
|
||||
{
|
||||
for (size_t i = 2; i < cmd_units.size(); i++)
|
||||
{
|
||||
tc.row_output(cmd_units[i], Disable);
|
||||
}
|
||||
}
|
||||
else throw std::runtime_error("disable: invalid parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
void load_file(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// load <file> [nohead|column|row|both] [head_num] [<delimeter>] [att_sym] [tag_sym]
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("open: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(5, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 5); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
int ht = NoHead;
|
||||
if (copy_str[0] == "nohead") ht = NoHead;
|
||||
else if (copy_str[0] == "column") ht = ColHead;
|
||||
else if (copy_str[0] == "row") ht = RowHead;
|
||||
else if (copy_str[0] == "both") ht = RowHead|ColHead;
|
||||
|
||||
int hnum = 0;
|
||||
if (copy_str[1] != "null") hnum = atoi(copy_str[1].c_str());
|
||||
if (hnum != 0) tc.head_number(hnum);
|
||||
|
||||
if (copy_str[2] != "null") tc.delimeter(copy_str[2][0]);
|
||||
if (copy_str[3] != "null") tc.annotation_symbol(copy_str[3][0]);
|
||||
if (copy_str[4] != "null") tc.tag_symbol(copy_str[4][0]);
|
||||
|
||||
std::string naked_name, exten_name;
|
||||
parse_filename(cmd_units[1], naked_name, exten_name);
|
||||
|
||||
if (exten_name == ".csv") tc.load_csv(naked_name);
|
||||
else tc.load_text(naked_name, exten_name, ht);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_file(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save <file> [<delimeter>] [att_sym] [tag_sym]
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(3, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 3); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
if (copy_str[0] != "null") tc.delimeter(copy_str[0][0]);
|
||||
if (copy_str[1] != "null") tc.annotation_symbol(copy_str[1][0]);
|
||||
if (copy_str[2] != "null") tc.tag_symbol(copy_str[2][0]);
|
||||
|
||||
std::string naked_name, exten_name;
|
||||
parse_filename(cmd_units[1], naked_name, exten_name);
|
||||
|
||||
if (exten_name == ".csv") tc.save_csv(naked_name);
|
||||
else tc.save_text(naked_name, exten_name);
|
||||
return;
|
||||
}
|
||||
|
||||
void statistic(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// stats <column> <column>...
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("stats: insufficient parameters.");
|
||||
|
||||
_1d_array data;
|
||||
for (size_t i = 1; i < cmd_units.size(); i++)
|
||||
{
|
||||
tc.get_column(data, cmd_units[i]);
|
||||
std::clog << "column: " << cmd_units[i]
|
||||
<< " | " << data.min() << "/" << data.mean() << "/" << data.max()
|
||||
<< " | STD: " << data.std() << "\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void set_type(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// type row|col int|float|string <name>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("type: insufficient parameters.");
|
||||
if (cmd_units[1] == "row")
|
||||
{
|
||||
if (cmd_units[2] == "int") tc.row_type(Int, cmd_units[3]);
|
||||
else if (cmd_units[2] == "float") tc.row_type(Float, cmd_units[3]);
|
||||
else if (cmd_units[2] == "string") tc.row_type(String, cmd_units[3]);
|
||||
else throw std::runtime_error("type: invalid parameters.");
|
||||
}
|
||||
else if (cmd_units[1] == "col")
|
||||
{
|
||||
if (cmd_units[2] == "int") tc.column_type(Int, cmd_units[3]);
|
||||
else if (cmd_units[2] == "float") tc.column_type(Float, cmd_units[3]);
|
||||
else if (cmd_units[2] == "string") tc.column_type(String, cmd_units[3]);
|
||||
else throw std::runtime_error("type: invalid parameters.");
|
||||
}
|
||||
else throw std::runtime_error("type: invalid parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
void set_titles(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// title <row|col> <t1>,<t2>,<t3>,... [<id1>,<id2>,<id3>,...]
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("title: insufficient parameters.");
|
||||
if (cmd_units[1] == "row")
|
||||
{
|
||||
std::vector<std::string> row_titles;
|
||||
std::vector<int> row_ids;
|
||||
parse_string_to_vector(cmd_units[2], ',', row_titles);
|
||||
if (cmd_units.size() >= 4)
|
||||
{
|
||||
parse_string_to_vector(cmd_units[3], ',', row_ids);
|
||||
if (row_titles.size() != row_ids.size()) throw std::runtime_error("title: invalid parameters.");
|
||||
tc.row_names(row_titles, row_ids);
|
||||
}
|
||||
else tc.row_names(row_titles);
|
||||
}
|
||||
else if (cmd_units[1] == "col")
|
||||
{
|
||||
std::vector<std::string> col_titles;
|
||||
std::vector<int> col_ids;
|
||||
parse_string_to_vector(cmd_units[2], ',', col_titles);
|
||||
if (cmd_units.size() >= 4)
|
||||
{
|
||||
parse_string_to_vector(cmd_units[3], ',', col_ids);
|
||||
if (col_titles.size()!= col_ids.size()) throw std::runtime_error("title: invalid parameters.");
|
||||
tc.column_names(col_titles, col_ids);
|
||||
}
|
||||
else tc.column_names(col_titles);
|
||||
}
|
||||
else throw std::runtime_error("title: invalid parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
void math_func(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// math <func> <col1>,<col2>,<col3>...
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("math: insufficient parameters.");
|
||||
|
||||
std::vector<std::string> col_names;
|
||||
parse_string_to_vector(cmd_units[2], ',', col_names);
|
||||
|
||||
tc.cal_column(cmd_units[1], col_names, 12);
|
||||
return;
|
||||
}
|
||||
|
||||
void rand_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// random normal|uniform <p1> <p2> [<colname>]
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("random: insufficient parameters.");
|
||||
|
||||
random_type_e rd_type = RdNormal;
|
||||
if (cmd_units[1] == "normal") rd_type = RdNormal;
|
||||
else if (cmd_units[1] == "uniform") rd_type = RdUniform;
|
||||
else throw std::runtime_error("random: invalid parameters.");
|
||||
|
||||
double p1 = atof(cmd_units[2].c_str());
|
||||
double p2 = atof(cmd_units[3].c_str());
|
||||
array<double> rd_data(tc.row_number());
|
||||
rd_data.random_float(p1, p2, rd_type);
|
||||
|
||||
if (cmd_units.size() >= 5) tc.fill_column(rd_data, cmd_units[4], 12);
|
||||
else
|
||||
{
|
||||
std::string col_name = "RdData";
|
||||
tc.add_column(col_name);
|
||||
tc.fill_column(rd_data, col_name, 12);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void filt_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// filter row|col regex|math <expression> <name1>,<name2>,<name3>...
|
||||
if (cmd_units.size() < 5) throw std::runtime_error("filter: insufficient parameters.");
|
||||
std::vector<std::string> tar_names;
|
||||
parse_string_to_vector(cmd_units[4], ',', tar_names);
|
||||
|
||||
table_headtype_e thead;
|
||||
if (cmd_units[1] == "row") thead = RowHead;
|
||||
else if (cmd_units[1] == "col") thead = ColHead;
|
||||
else throw std::runtime_error("filter: invalid parameters.");
|
||||
|
||||
if (cmd_units[2] == "regex") tc.filter(cmd_units[3], tar_names[0], thead);
|
||||
else if (cmd_units[2] == "math") tc.filter(cmd_units[3], tar_names, thead);
|
||||
else throw std::runtime_error("filter: invalid parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
void insert_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// insert row|col [<new-name>] [<insert-name>]
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("insert: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "row")
|
||||
{
|
||||
if (cmd_units.size() == 2) tc.add_row();
|
||||
else if (cmd_units.size() == 3) tc.add_row(cmd_units[2]);
|
||||
else if (cmd_units.size() == 4) tc.add_row(cmd_units[2], cmd_units[3]);
|
||||
}
|
||||
else if (cmd_units[1] == "col")
|
||||
{
|
||||
if (cmd_units.size() == 2) tc.add_column();
|
||||
else if (cmd_units.size() == 3) tc.add_column(cmd_units[2]);
|
||||
else if (cmd_units.size() == 4) tc.add_column(cmd_units[2], cmd_units[3]);
|
||||
}
|
||||
else throw std::runtime_error("insert: invalid parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
void set_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// set row|col \<name\> \<value\>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("set: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "row")
|
||||
{
|
||||
_1s_array row_data(tc.row_number(), cmd_units[3]);
|
||||
tc.fill_row(row_data, cmd_units[2]);
|
||||
}
|
||||
else if (cmd_units[1] == "col")
|
||||
{
|
||||
_1s_array col_data(tc.col_number(), cmd_units[3]);
|
||||
tc.fill_column(col_data, cmd_units[2]);
|
||||
}
|
||||
else throw std::runtime_error("set: invalid parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
void display_table(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// view
|
||||
tc.display();
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc >= 2)
|
||||
{
|
||||
std::string tmp_l;
|
||||
std::ifstream cmdin;
|
||||
|
||||
// Run commands from files. Each line is a command.
|
||||
// You can give more than one file
|
||||
for (size_t i = 1; i < argc; i++) try
|
||||
{
|
||||
open_infile(cmdin, argv[i]);
|
||||
while (getline(cmdin, tmp_l) && tmp_l != "" && tmp_l[0] != '#')
|
||||
{
|
||||
exec_cmd(tmp_l);
|
||||
}
|
||||
cmdin.close();
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, "run dsviewer in the interactive mode for instructions.", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setlocale(LC_CTYPE, "");
|
||||
initialize_readline(); /* Bind our completer. */
|
||||
|
||||
display_logo();
|
||||
std::clog << "dsviewer - read, manipulate and write dsv/csv files.\n";
|
||||
std::clog << "Usage: dsviewer [<cmdfile1> <cmdfile2>...]\n";
|
||||
std::clog << "Enter '?' to see all available commands.\n";
|
||||
|
||||
std::string cmd_str;
|
||||
char *c_line = (char *)NULL;
|
||||
char *c_line_s = (char *)NULL;
|
||||
bool quit = false;
|
||||
|
||||
while (!quit) try
|
||||
{
|
||||
c_line = readline(">> ");
|
||||
if (!c_line) break;
|
||||
|
||||
c_line_s = stripwhite(c_line);
|
||||
cmd_str = c_line_s;
|
||||
|
||||
if (cmd_str == "quit") quit = true;
|
||||
else if (cmd_str == "?") display_cmds();
|
||||
else exec_cmd(cmd_str);
|
||||
|
||||
free(c_line);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, "Enter 'help' for instructions.", 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
86
dsviewer/dsviewer.h
Normal file
86
dsviewer/dsviewer.h
Normal file
@ -0,0 +1,86 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. 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
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#ifndef GCTL_DSVIEWER_H
|
||||
#define GCTL_DSVIEWER_H
|
||||
|
||||
#include <regex>
|
||||
#include "gctl/io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
// Function pointer for commands
|
||||
typedef void (*cmd_func_ptr)(const std::vector<std::string> &cmd_units);
|
||||
|
||||
struct cmd_pair
|
||||
{
|
||||
std::string name;
|
||||
cmd_func_ptr func_p;
|
||||
std::string brief;
|
||||
};
|
||||
|
||||
void quit(const std::vector<std::string> &cmd_units);
|
||||
void info(const std::vector<std::string> &cmd_units);
|
||||
void head(const std::vector<std::string> &cmd_units);
|
||||
void tail(const std::vector<std::string> &cmd_units);
|
||||
void load_file(const std::vector<std::string> &cmd_units);
|
||||
void save_file(const std::vector<std::string> &cmd_units);
|
||||
void statistic(const std::vector<std::string> &cmd_units);
|
||||
void set_enable(const std::vector<std::string> &cmd_units);
|
||||
void set_disable(const std::vector<std::string> &cmd_units);
|
||||
void set_type(const std::vector<std::string> &cmd_units);
|
||||
void set_titles(const std::vector<std::string> &cmd_units);
|
||||
void math_func(const std::vector<std::string> &cmd_units);
|
||||
void rand_data(const std::vector<std::string> &cmd_units);
|
||||
void filt_data(const std::vector<std::string> &cmd_units);
|
||||
void insert_data(const std::vector<std::string> &cmd_units);
|
||||
void set_data(const std::vector<std::string> &cmd_units);
|
||||
void display_table(const std::vector<std::string> &cmd_units);
|
||||
|
||||
#define CMD_NUM 18
|
||||
const cmd_pair commands[CMD_NUM] = {
|
||||
{"quit", quit, "Quit the program."},
|
||||
{"view", display_table, "Display valid cells."},
|
||||
{"info", info, "Show the table information."},
|
||||
{"head", head, "Show head line(s) of the table."},
|
||||
{"tail", tail, "Show tail line(s) of the table."},
|
||||
{"open", load_file, "Open a dsv/csv file."},
|
||||
{"save", save_file, "Save the table to a file."},
|
||||
{"stats", statistic, "Calculate statistics of the selected columns."},
|
||||
{"enable", set_enable, "Enable column/row outputs by name or index."},
|
||||
{"disable", set_disable, "Disable column/row outputs by name or index."},
|
||||
{"insert", insert_data, "Insert a new column/row data."},
|
||||
{"set", set_data, "Set a column/row data."},
|
||||
{"type", set_type, "Set column/row data types."},
|
||||
{"title", set_titles, "Set row and column titles."},
|
||||
{"math", math_func, "Preform mathematic operations of column data."},
|
||||
{"random", rand_data, "Generate random column data."},
|
||||
{"filter", filt_data, "Filter row and column data using regex and mathematic expressions."},
|
||||
{"null", nullptr, "null"}
|
||||
};
|
||||
|
||||
#endif // GCTL_DSVIEWER_H
|
47
dsviewer/dsviewer.md
Normal file
47
dsviewer/dsviewer.md
Normal file
@ -0,0 +1,47 @@
|
||||
#### quit
|
||||
Does what it says.
|
||||
|
||||
#### info [att|tag|hdr|col|row]
|
||||
Show the table information. 'att' shows the annotations, 'tag' shows the tag lines, 'hdr' shows the head lines, 'col' shows the columns' summary, and 'row' shows the rows' summary. Use '|' to separate multiple options.
|
||||
|
||||
#### head
|
||||
Show the first `n` (the default is 10) rows of the table.
|
||||
|
||||
#### tail
|
||||
Show the last `n` (the default is 10) rows of the table.
|
||||
|
||||
#### open \<file\> [nohead|column|row|both] [\<head_num\>] [\<deli-sym\>] [\<att-sym\>] [\<tag-sym\>]
|
||||
Open a dsv/csv file. The default setups are 'nohead', space for delimeter, '#' for annotations, and '!' for tags. If the file name ends with '.csv', the default delimeter is ','.
|
||||
|
||||
#### save \<file\> [\<delimeter\>] [\<att-sym\>] [\<tag-sym\>]
|
||||
Save table to a dsv/csv file. The default setups are space for delimeter, '#' for annotations, and '!' for tags. If the file name ends with '.csv', the default delimeter is ','.
|
||||
|
||||
#### stats \<colname1\> \<colname2\> ...
|
||||
Show statistics of a data column or columns. If the input file has no column names, use inbuilt names `C<id>` to select the columns.
|
||||
|
||||
#### enable table|column|row [\<name1\> \<name2\> ...]
|
||||
Enable table outputs. If the input file has no row or column names, use inbuilt names `R<id>` and `C<id>` to select the rows and columns.
|
||||
|
||||
#### disable table|column|row [\<name1\> \<name2\> ...]
|
||||
Disable table outputs. If the input file has no row or column names, use inbuilt names `R<id>` and `C<id>` to select the rows and columns.
|
||||
|
||||
#### insert row|col [\<new-name\>] [\<insert-name\>]
|
||||
Insert a new row or column. The new row or column will be attached to the end of the table by default. A `new-name` can be provided if the user wants to rename the new row or column. Provide the `insert-name` to insert the new row or column at the specified row or column. The remaining columns or rows will be moved one step right or down accordingly. If the input file has no row or column names, use inbuilt names `R<id>` and `C<id>` to select the rows and columns.
|
||||
|
||||
#### set row|col \<name\> \<value\>
|
||||
Set a row or column's value to the given one. If the input file has no row or column names, use inbuilt names `R<id>` and `C<id>` to select the rows and columns.
|
||||
|
||||
#### type row|col int|float|string \<name\>
|
||||
Set the data type of a row or column. If the input file has no row or column names, use inbuilt names `R<id>` and `C<id>` to select the rows and columns.
|
||||
|
||||
#### title row|col \<t1\>,\<t2\>,\<t3\>,... [\<id1\>,\<id2\>,\<id3\>,...]
|
||||
Set row and column titles. The titles will be assigned sequentially if no index is specified.
|
||||
|
||||
#### math \<func\> \<col1\>,\<col2\>,\<col3\>...
|
||||
Preform mathematic operations of column data. The user needs to write a mathematical expression using the column names as variables. Then provide the column names as the arguments, in which the resultant column's name must be placed at the beginning. For example, to calculate the sum of column `C1` and `C2`, and store the result in column `C3`, the command is: `math C3=C1+C2 C3,C1,C2`.
|
||||
|
||||
#### random normal|uniform \<p1\> \<p2\> [\<colname\>]
|
||||
Generate random data using normal or uniform distribution. The first parameter is the mean or the lower bound, and the second parameter is the standard deviation or the upper bound. If no column name is provided, a new column will be created (titled "RdData").
|
||||
|
||||
#### filter row|col regex|math \<expression\> \<name1\>,\<name2\>,\<name3\>...
|
||||
Filter row and column data using regex and mathematic expressions. The first parameter is the expression, and the following parameters are the column names. For example, to filter rows whose column `C1` is greater than 0, the command is: `filter col math C1>0 C1`. Regex expression can be used to filter rows whose column `C1` contains the string "abc", the command is: `filter col regex abc C1`.
|
11
dsviewer/example.csv
Normal file
11
dsviewer/example.csv
Normal file
@ -0,0 +1,11 @@
|
||||
Name,Age,Gender,Occupation,City,Phone Number,Email,Annual Income,Company,Position
|
||||
John Doe,28,Male,Engineer,New York,123-456-7890,john.doe@example.com,$75000,ABC Tech,Senior Software Engineer
|
||||
Jane Smith,34,Female,Teacher,Los Angeles,234-567-8901,jane.smith@example.com,$55000,XYZ School,Math Teacher
|
||||
Michael Brown,22,Male,Student,Toronto,345-678-9012,michael.brown@example.com,$18000,University of Toronto,Undergraduate Student
|
||||
Emily Davis,45,Female,Doctor,Chicago,456-789-0123,emily.davis@example.com,$180000,Chicago Medical Center,Cardiologist
|
||||
David Wilson,30,Male,Designer,San Francisco,567-890-1234,david.wilson@example.com,$90000,DesignWorks,Senior Graphic Designer
|
||||
Sarah Johnson,29,Female,Marketing Specialist,Seattle,678-901-2345,sarah.johnson@example.com,$85000,MarketingPro,Marketing Manager
|
||||
Robert Lee,36,Male,Software Developer,Boston,789-012-3456,robert.lee@example.com,$120000,SoftDev Solutions,Lead Developer
|
||||
Laura Miller,25,Female,Graphic Designer,Denver,890-123-4567,laura.miller@example.com,$60000,Creative Arts,Junior Designer
|
||||
William Clark,40,Male,Consultant,Atlanta,901-234-5678,william.clark@example.com,$110000,ConsultPro,Business Consultant
|
||||
Olivia Turner,33,Female,Researcher,Phoenix,012-345-6789,olivia.turner@example.com,$70000,ResearchInnovate,Research Scientist
|
|
1
gctl_toolkits_config.h
Normal file
1
gctl_toolkits_config.h
Normal file
@ -0,0 +1 @@
|
||||
#define GCTL_TOOLKITS_INSTALL_PREFIX "/opt/stow/gctl_toolkits"
|
25
gridmanager-potential/CMakeLists.backup
Normal file
25
gridmanager-potential/CMakeLists.backup
Normal file
@ -0,0 +1,25 @@
|
||||
set(TOOL_NAME gridmanager-potential)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_search_module(EDITLINE REQUIRED libeditline)
|
||||
include_directories(${EDITLINE_INCLUDE_DIRS})
|
||||
link_directories(${EDITLINE_LIBRARY_DIRS})
|
||||
|
||||
aux_source_directory(. TOOL_SRC)
|
||||
add_executable(${TOOL_NAME} ${TOOL_SRC})
|
||||
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
target_link_libraries(${TOOL_NAME} PUBLIC ${GCTL_LIB})
|
||||
target_link_libraries(${TOOL_NAME} PUBLIC gctl_potential)
|
||||
target_link_libraries(${TOOL_NAME} PUBLIC ${EDITLINE_LIBRARIES})
|
||||
|
||||
install(TARGETS ${TOOL_NAME} RUNTIME DESTINATION sbin)
|
||||
|
||||
file(GLOB HELP_DOC *.md)
|
||||
install(FILES ${HELP_DOC} DESTINATION sbin/share)
|
881
gridmanager-potential/gridmanager-potential.cpp
Normal file
881
gridmanager-potential/gridmanager-potential.cpp
Normal file
@ -0,0 +1,881 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. 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
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "gridmanager-potential.h"
|
||||
// We use the editline library to handle all inputs
|
||||
#include "editline.h"
|
||||
// install configuration
|
||||
#include "../gctl_toolkits_config.h"
|
||||
|
||||
cmd_pair curr_cmd; // Executing command
|
||||
gctl::gm_regular_grid rg; // Grid object
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Strip whitespace from the start and end of STRING. Return a pointer
|
||||
* into STRING.
|
||||
*/
|
||||
char *stripwhite(char *string)
|
||||
{
|
||||
char *s, *t;
|
||||
|
||||
for (s = string; isspace(*s); s++) ;
|
||||
|
||||
if (*s == 0)
|
||||
return s;
|
||||
|
||||
t = s + strlen(s) - 1;
|
||||
while (t > s && isspace(*t))
|
||||
t--;
|
||||
*++t = '\0';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Generator function for command completion. STATE lets us
|
||||
know whether to start from scratch; without any state
|
||||
(i.e. STATE == 0), then we start at the top of the list. */
|
||||
char *command_generator(const char *text, int state)
|
||||
{
|
||||
static int list_index, len;
|
||||
|
||||
/* If this is a new word to complete, initialize now. This
|
||||
includes saving the length of TEXT for efficiency, and
|
||||
initializing the index variable to 0. */
|
||||
if (!state)
|
||||
{
|
||||
list_index = 0;
|
||||
len = strlen(text);
|
||||
}
|
||||
|
||||
/* Return the next name which partially matches from the command list. */
|
||||
while (list_index < CMD_NUM)
|
||||
{
|
||||
if (std::string(text) == commands[list_index].name.substr(0, len))
|
||||
{
|
||||
//const char* name = commands[list_index].name.data();
|
||||
return strdup(commands[list_index].name.data());
|
||||
}
|
||||
else list_index++;
|
||||
}
|
||||
|
||||
/* If no names matched, then return NULL. */
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempt to complete on the contents of TEXT. START and END
|
||||
* bound the region of rl_line_buffer that contains the word to
|
||||
* complete. TEXT is the word to complete. We can use the entire
|
||||
* contents of rl_line_buffer in case we want to do some simple
|
||||
* parsing. Return the array of matches, or NULL if there aren't any.
|
||||
*/
|
||||
char **gridmanager_completion(const char *text, int start, int end)
|
||||
{
|
||||
char **matches = nullptr;
|
||||
|
||||
/* If this word is at the start of the line, then it is a command
|
||||
to complete. Otherwise it is the name of a file in the current
|
||||
directory. */
|
||||
if (start == 0) matches = rl_completion_matches(text, command_generator);
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
void initialize_readline(void)
|
||||
{
|
||||
/* Allow conditional parsing of the ~/.inputrc file. */
|
||||
rl_readline_name = "gridmanager";
|
||||
|
||||
/* Tell the completer that we want a crack first. */
|
||||
rl_attempted_completion_function = gridmanager_completion;
|
||||
}
|
||||
|
||||
} // End C section
|
||||
|
||||
void display_cmds()
|
||||
{
|
||||
std::clog << "Command:\n";
|
||||
for (size_t i = 0; i < CMD_NUM - 1; i++)
|
||||
{
|
||||
std::clog << std::setw(12) << commands[i].name << ":\t" << commands[i].brief << "\n";
|
||||
}
|
||||
|
||||
std::clog << "\nEnter \"<command>?\" to see detailed instructions.\n\n";
|
||||
std::clog << "Keywords:\n";
|
||||
for (size_t i = 0; i < KEY_NUM; i++)
|
||||
{
|
||||
std::clog << std::setw(12) << keywords[i].name << ":\t" << keywords[i].brief << "\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void display_help(std::string input_cmd)
|
||||
{
|
||||
std::string install_dir = GCTL_TOOLKITS_INSTALL_PREFIX;
|
||||
std::ifstream helpin;
|
||||
open_infile(helpin, install_dir + "/sbin/share/readme_gridmanager_potential", ".md");
|
||||
|
||||
std::string tmp_l, tmp_help;
|
||||
std::vector<std::string> cmds;
|
||||
std::vector<std::string> helps;
|
||||
while (getline(helpin, tmp_l))
|
||||
{
|
||||
if (tmp_l.substr(0, 4) == "####")
|
||||
{
|
||||
cmds.push_back(tmp_l.substr(5));
|
||||
tmp_help = "";
|
||||
while (getline(helpin, tmp_l))
|
||||
{
|
||||
if (tmp_l == "") break;
|
||||
else tmp_help += tmp_l + "\n";
|
||||
}
|
||||
helps.push_back(tmp_help);
|
||||
}
|
||||
}
|
||||
helpin.close();
|
||||
|
||||
std::string cmd_str;
|
||||
for (size_t j = 0; j < cmds.size(); j++)
|
||||
{
|
||||
parse_string_to_value(cmds[j], ' ', true, cmd_str);
|
||||
if (input_cmd == cmd_str)
|
||||
{
|
||||
replace_all(tmp_l, cmds[j], "\\", "");
|
||||
std::cout << tmp_l << "\n";
|
||||
std::cout << helps[j] << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void exec_cmd(std::string cmd)
|
||||
{
|
||||
std::string cmd_name;
|
||||
parse_string_to_value(cmd, ' ', true, cmd_name);
|
||||
|
||||
// show instruction if there is a question mark at end of the command
|
||||
if (cmd_name.back() == '?')
|
||||
{
|
||||
cmd_name = cmd_name.substr(0, cmd_name.length() - 1);
|
||||
display_help(cmd_name);
|
||||
return;
|
||||
}
|
||||
|
||||
// set default command to null
|
||||
curr_cmd = commands[CMD_NUM - 1];
|
||||
for (size_t i = 0; i < CMD_NUM - 1; i++)
|
||||
{
|
||||
if (cmd_name == commands[i].name)
|
||||
{
|
||||
curr_cmd = commands[i]; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (curr_cmd.func_p == nullptr) throw gctl::runtime_error("Invalid command: " + cmd_name);
|
||||
|
||||
std::vector<std::string> cmd_units;
|
||||
parse_string_with_quotes(cmd, cmd_units);
|
||||
|
||||
return curr_cmd.func_p(cmd_units);
|
||||
}
|
||||
|
||||
// This function is defined to avoid potential breakdown while running in script mode.
|
||||
void quit(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void mesh_info(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// info [\<new-grid-name\>] [\<new-info\>]
|
||||
if (cmd_units.size() == 1)
|
||||
{
|
||||
rg.show_info();
|
||||
return;
|
||||
}
|
||||
|
||||
gctl::array<std::string> copy_str(2, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 2); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
if (copy_str[0] != "null") rg.set_meshname(copy_str[0]);
|
||||
if (copy_str[1] != "null") rg.set_meshinfo(copy_str[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef GCTL_MESH_EXPRTK
|
||||
|
||||
inline double expr2double(std::string s)
|
||||
{
|
||||
exprtk::symbol_table<double> sym_tab;
|
||||
exprtk::expression<double> expr;
|
||||
exprtk::parser<double> p;
|
||||
|
||||
sym_tab.add_constants();
|
||||
expr.register_symbol_table(sym_tab);
|
||||
p.compile(s, expr);
|
||||
|
||||
return expr.value();
|
||||
}
|
||||
|
||||
#endif // GCTL_MESH_EXPRTK
|
||||
|
||||
void new_grid(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// new \<new-file\> \<xnum\> \<ynum\> \<xmin\> \<ymin\> \<dx\> \<dy\> [\<info\>]
|
||||
if (cmd_units.size() < 8) throw std::runtime_error("new-grid: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(8, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 8); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
if (rg.initiated()) rg.clear_regular_grid();
|
||||
|
||||
double xmin, ymin, dx, dy;
|
||||
#ifdef GCTL_MESH_EXPRTK
|
||||
|
||||
xmin = expr2double(copy_str[3]);
|
||||
ymin = expr2double(copy_str[4]);
|
||||
dx = expr2double(copy_str[5]);
|
||||
dy = expr2double(copy_str[6]);
|
||||
|
||||
#else
|
||||
|
||||
xmin = atof(copy_str[3].c_str());
|
||||
ymin = atof(copy_str[4].c_str());
|
||||
dx = atof(copy_str[5].c_str());
|
||||
dy = atof(copy_str[6].c_str());
|
||||
|
||||
#endif // GCTL_MESH_EXPRTK
|
||||
|
||||
rg.init(copy_str[0], copy_str[7], atoi(copy_str[1].c_str()),
|
||||
atoi(copy_str[2].c_str()), xmin, ymin, dx, dy);
|
||||
return;
|
||||
}
|
||||
|
||||
void open_grid(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// open binary <file>
|
||||
// open netcdf <file> [<x-name> <y-name>] [<data-name>] [node|cell]
|
||||
// open surfer <file> <new-data-name> [surfer6-text|surfer6-binary|surfer7] [node|cell]
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("open: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "binary") open_binary(cmd_units);
|
||||
else if (cmd_units[1] == "netcdf") open_netcdf(cmd_units);
|
||||
else if (cmd_units[1] == "surfer") open_surfer(cmd_units);
|
||||
else throw std::runtime_error("open: unknown file format.");
|
||||
return;
|
||||
}
|
||||
|
||||
void save_grid(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save binary <file>
|
||||
// save netcdf <file> [<data-name>|node|cell]
|
||||
// save surfer <file> <data-name> [surfer6-text|surfer6-binary|surfer7]
|
||||
// save gmsh <file>
|
||||
// save text <file> <data-name> [<data-name>]...
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "binary") save_binary(cmd_units);
|
||||
else if (cmd_units[1] == "netcdf") save_netcdf(cmd_units);
|
||||
else if (cmd_units[1] == "surfer") save_surfer(cmd_units);
|
||||
else if (cmd_units[1] == "gmsh") save_gmsh(cmd_units);
|
||||
else if (cmd_units[1] == "text") save_text(cmd_units);
|
||||
else throw std::runtime_error("save: unknown file format.");
|
||||
return;
|
||||
}
|
||||
|
||||
void open_binary(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// open binary <file>
|
||||
rg.load_binary(cmd_units[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_binary(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save binary <file>
|
||||
rg.save_binary(cmd_units[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
void open_netcdf(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// open netcdf <file> [<x-name> <y-name>] [<data-name>] [node|cell]
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("open: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(5, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 5); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
mesh_data_type_e d_type = NodeData;
|
||||
if (copy_str[4] == "cell") d_type = ElemData;
|
||||
else if (copy_str[4] == "node") d_type = NodeData;
|
||||
|
||||
if (copy_str[1] == "null") copy_str[1] = "x";
|
||||
if (copy_str[2] == "null") copy_str[2] = "y";
|
||||
if (copy_str[3] == "null") rg.load_netcdf_grid(copy_str[0], d_type, copy_str[1], copy_str[2]);
|
||||
else rg.load_netcdf_grid(copy_str[0], d_type, copy_str[1], copy_str[2], copy_str[3]);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_netcdf(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save netcdf <file> [<data-name>|node|cell]
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(2, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 2); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
if (copy_str[1] == "null") rg.save_netcdf_grid(copy_str[0], NodeData);
|
||||
else if (copy_str[1] == "cell") rg.save_netcdf_grid(copy_str[0], ElemData);
|
||||
else rg.save_netcdf_grid(copy_str[0], copy_str[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_gmsh(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save gmsh <file>
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
rg.save_gmsh(cmd_units[2], NotPacked);
|
||||
return;
|
||||
}
|
||||
|
||||
void open_surfer(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// open surfer <file> [<new-data-name>] [surfer6-text|surfer6-binary|surfer7] [node|cell]
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("open: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 4); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
surfer_file_type_e st = Surfer6Text;
|
||||
if (copy_str[2] == "surfer6-text") st = Surfer6Text;
|
||||
else if (copy_str[2] == "surfer6-binary") st = Surfer6Binary;
|
||||
else if (copy_str[2] == "surfer7") st = Surfer7Grid;
|
||||
|
||||
mesh_data_type_e d_type = NodeData;
|
||||
if (copy_str[3] == "node") d_type = NodeData;
|
||||
else if (copy_str[3] == "cell") d_type = ElemData;
|
||||
|
||||
if (copy_str[1] == "null") rg.load_surfer_grid(copy_str[0], "Untitled", d_type, st);
|
||||
else rg.load_surfer_grid(copy_str[0], copy_str[3], d_type, st);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_surfer(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save surfer <file> <data-name> [surfer6-text|surfer6-binary|surfer7]
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(3, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 3); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
surfer_file_type_e st = Surfer6Text;
|
||||
if (copy_str[2] == "surfer6-text") st = Surfer6Text;
|
||||
else if (copy_str[2] == "surfer6-binary") st = Surfer6Binary;
|
||||
else if (copy_str[2] == "surfer7") st = Surfer7Grid;
|
||||
|
||||
rg.save_surfer_grid(copy_str[0], copy_str[1] ,st);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_text(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save text <file> <data-name>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(cmd_units.size() - 3, "null");
|
||||
for (size_t i = 0; i < cmd_units.size() - 3; i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 3];
|
||||
}
|
||||
|
||||
rg.save_text(cmd_units[2], copy_str);
|
||||
return;
|
||||
}
|
||||
|
||||
void data_cloud(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// data-cloud \<new-data-name\> node|cell \<data-could-file\> \<search-x\> \<search-y\> \<search-deg\>
|
||||
if (cmd_units.size() < 7) throw std::runtime_error("data-cloud: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(7, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 7); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
mesh_data_type_e d_type = NodeData;
|
||||
if (copy_str[1] == "node") d_type = NodeData;
|
||||
else if (copy_str[1] == "cell") d_type = ElemData;
|
||||
else throw std::runtime_error("open-surfer: invalid grid data type.");
|
||||
|
||||
geodsv_io text_in;
|
||||
text_in.load_text(copy_str[2]);
|
||||
|
||||
array<point2dc> posi_arr;
|
||||
_1d_array data_vec;
|
||||
text_in.get_column_point2dc(posi_arr, 0, 1);
|
||||
text_in.get_column(data_vec, 2);
|
||||
|
||||
rg.load_data_cloud(posi_arr, data_vec, atof(copy_str[3].c_str()), atof(copy_str[4].c_str()), atof(copy_str[5].c_str()), copy_str[0], d_type);
|
||||
return;
|
||||
}
|
||||
|
||||
void gradient(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// gradient <data-name> <new-data-name> dx|dy <order>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("gradient: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 4); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
gradient_type_e g_type;
|
||||
if (copy_str[2] == "dx") g_type = Dx;
|
||||
else if (copy_str[2] == "dy") g_type = Dy;
|
||||
else throw std::runtime_error("gradient: invalid gradient type.");
|
||||
|
||||
int order = 1;
|
||||
if (copy_str[3] != "null") order = atoi(copy_str[3].c_str());
|
||||
|
||||
rg.regular_grid::gradient(copy_str[0], copy_str[1], g_type, order);
|
||||
return;
|
||||
}
|
||||
|
||||
void wavelet(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// wavelet \<data-name\> \<wavelet-name\> \<order\> [\<show-summary\>]
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("wavelet: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 4); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
int order = order = atoi(copy_str[2].c_str());
|
||||
|
||||
if (copy_str[3] == "yes") rg.wavelet(copy_str[0], copy_str[1], order, true);
|
||||
else rg.wavelet(copy_str[0], copy_str[1], order, false);
|
||||
return;
|
||||
}
|
||||
|
||||
void sum_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// sum-data \<new-data-name\> \<data-name1\> \<data-name2\>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("sum: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(3, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 3); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
rg.sum(copy_str[0], copy_str[1], copy_str[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
void diff_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// sum-data \<new-data-name\> \<data-name1\> \<data-name2\>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("diff: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(3, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 3); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
rg.diff(copy_str[0], copy_str[1], copy_str[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
void bool_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// bool \<new-data-name\> \<data-name1> \<bool-data\> [reverse]
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("bool: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 4); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
if (copy_str[3] == "reverse") rg.boolean(copy_str[0], copy_str[1], copy_str[2], true);
|
||||
else rg.boolean(copy_str[0], copy_str[1], copy_str[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
void func_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// function \<expression\> \<new-data-name\>
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("function: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(3, "null");
|
||||
for (size_t i = 0; i <= GCTL_MIN(cmd_units.size() - 1, 3); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 1];
|
||||
}
|
||||
|
||||
rg.function(copy_str[0], copy_str[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
void calculator(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// calculator \<expression\> \<var1,data-name1\> \<var2,data-name2\>...
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("calculator: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(cmd_units.size() - 1, "null");
|
||||
for (size_t i = 1; i <= cmd_units.size() - 1; i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
array<std::string> var_list(copy_str.size() - 1), data_list(copy_str.size() - 1);
|
||||
for (size_t i = 0; i < var_list.size(); i++)
|
||||
{
|
||||
parse_string_to_value(copy_str[i + 1], ',', true, var_list[i], data_list[i]);
|
||||
}
|
||||
|
||||
rg.calculator(copy_str[0], var_list, data_list);
|
||||
return;
|
||||
}
|
||||
|
||||
void data_output(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// data-output enable|disable \<data-name1\> \<data-name2\>...
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("data-output: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(cmd_units.size() - 1, "null");
|
||||
for (size_t i = 1; i <= cmd_units.size() - 1; i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
meshdata* data_ptr;
|
||||
if (copy_str[0] == "enable")
|
||||
{
|
||||
for (size_t i = 1; i < copy_str.size(); i++)
|
||||
{
|
||||
data_ptr = rg.get_data_ptr(copy_str[i]);
|
||||
data_ptr->output_ok_ = true;
|
||||
}
|
||||
}
|
||||
else if (copy_str[0] == "disable")
|
||||
{
|
||||
for (size_t i = 1; i < copy_str.size(); i++)
|
||||
{
|
||||
data_ptr = rg.get_data_ptr(copy_str[i]);
|
||||
data_ptr->output_ok_ = false;
|
||||
}
|
||||
}
|
||||
else throw std::runtime_error("data-output: invalid operation type.");
|
||||
return;
|
||||
}
|
||||
|
||||
void data_rename(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// data-rename [\<old-name\>] [\<new-name\>]
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("rename: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(2, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 2); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
meshdata &data = rg.get_data(copy_str[0]);
|
||||
data.name_ = copy_str[1];
|
||||
return;
|
||||
}
|
||||
|
||||
void data_view(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// plot [\<data-name\>]...
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("view: insufficient parameters.");
|
||||
|
||||
for (size_t i = 1; i < cmd_units.size(); i++)
|
||||
{
|
||||
rg.view(cmd_units[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void data_plot(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// plot [\<data-name\>]...
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("plot: insufficient parameters.");
|
||||
|
||||
for (size_t i = 1; i < cmd_units.size(); i++)
|
||||
{
|
||||
rg.plot(cmd_units[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void get_stats(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// statistic \<data-name1\> \<data-name2\>...
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("statistic: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(cmd_units.size() - 1, "null");
|
||||
for (size_t i = 1; i <= cmd_units.size() - 1; i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
meshdata *data_ptr;
|
||||
std::vector<double> stats;
|
||||
for (size_t i = 0; i < copy_str.size(); i++)
|
||||
{
|
||||
data_ptr = rg.get_data_ptr(copy_str[i]);
|
||||
data_ptr->show_info();
|
||||
data_ptr->show_stats();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void get_profile(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// profile \<data-name\> \<out-file\> {\<x\>,\<y\> \<x\>,\<y\> \<num\>}|{\<xy-file\> [\<file-format\>]}
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("profile: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(5, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 5); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
array<point2dc> xys;
|
||||
array<double> p_data;
|
||||
if (access(copy_str[2].c_str(), R_OK))
|
||||
{
|
||||
point2dc st_p, ed_p;
|
||||
gctl::parse_string_to_value(copy_str[2], ',', true, st_p.x, st_p.y);
|
||||
gctl::parse_string_to_value(copy_str[3], ',', true, ed_p.x, ed_p.y);
|
||||
rg.extract_profile(copy_str[0], st_p, ed_p, atoi(copy_str[4].c_str()), xys, p_data);
|
||||
}
|
||||
else // File exist
|
||||
{
|
||||
geodsv_io fio;
|
||||
fio.load_text(copy_str[2]);
|
||||
fio.get_column_point2dc(xys, 0, 1);
|
||||
|
||||
rg.extract_points(copy_str[0], xys, p_data);
|
||||
}
|
||||
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, copy_str[1], ".txt");
|
||||
ofile << "# x y d val\n";
|
||||
for (size_t i = 0; i < xys.size(); i++)
|
||||
{
|
||||
ofile << xys[i].x << " " << xys[i].y << " " << distance(xys[0], xys[i]) << " " << p_data[i] << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
return;
|
||||
}
|
||||
|
||||
void potential_gradient(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// potential-gradient <data-name> <new-data-name> Tzx|Tzy|Tzz <order>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("potential-gradient: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 4); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
gravitational_field_type_e g_type;
|
||||
if (copy_str[2] == "Tzx") g_type = Tzx;
|
||||
else if (copy_str[2] == "Tzy") g_type = Tzy;
|
||||
else if (copy_str[2] == "Tzz") g_type = Tzz;
|
||||
else throw std::runtime_error("potential-gradient: invalid gradient type.");
|
||||
|
||||
int order = 1;
|
||||
if (copy_str[3] != "null") order = atoi(copy_str[3].c_str());
|
||||
|
||||
rg.gm_regular_grid::gradient(copy_str[0], copy_str[1], g_type, order);
|
||||
return;
|
||||
}
|
||||
|
||||
void rtp(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// rtp <data-name> <rtp-name> inclination declination
|
||||
if (cmd_units.size() < 5) throw std::runtime_error("rtp: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 4); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
rg.rtp(copy_str[0], copy_str[1], atof(copy_str[2].c_str()), atof(copy_str[3].c_str()));
|
||||
return;
|
||||
}
|
||||
|
||||
void drtp(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// drtp <data-name> <rtp-name> <inclination-name> <declination-name> [<order>]
|
||||
if (cmd_units.size() < 5) throw std::runtime_error("drtp: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(5, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 5); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
int order = 1;
|
||||
if (copy_str[4] != "null") order = atoi(copy_str[4].c_str());
|
||||
if (order < 1) throw std::runtime_error("drtp: invalid differential order.");
|
||||
|
||||
rg.drtp(copy_str[0], copy_str[1], copy_str[2], copy_str[3], order);
|
||||
return;
|
||||
}
|
||||
|
||||
void continuation(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// continuation <data-name> <out-name> <height>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("continuation: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(3, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 3); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
double height = atof(copy_str[2].c_str());
|
||||
std::cout << height << "\n";
|
||||
|
||||
rg.conti(copy_str[0], copy_str[1], height);
|
||||
return;
|
||||
}
|
||||
|
||||
void trend(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// trend <data-name> <reg-name> <res-name> <wx-size> <wy-size> <x-order> <y-order>
|
||||
if (cmd_units.size() < 8) throw std::runtime_error("trend: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(7, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 7); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
int wx_s = atoi(copy_str[3].c_str());
|
||||
int wy_s = atoi(copy_str[4].c_str());
|
||||
int x_od = atoi(copy_str[5].c_str());
|
||||
int y_od = atoi(copy_str[6].c_str());
|
||||
if (wx_s < 3 || wy_s < 3 || x_od < 1 || y_od < 1) throw std::runtime_error("trend: invalid trending parameters.");
|
||||
|
||||
rg.trend(copy_str[0], copy_str[1], copy_str[2], wx_s, wy_s, x_od, y_od);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc >= 2)
|
||||
{
|
||||
std::string tmp_l;
|
||||
std::ifstream cmdin;
|
||||
|
||||
// Run commands from files. Each line is a command.
|
||||
// You can give more than one file
|
||||
for (size_t i = 1; i < argc; i++) try
|
||||
{
|
||||
open_infile(cmdin, argv[i]);
|
||||
while (getline(cmdin, tmp_l) && tmp_l != "" && tmp_l[0] != '#')
|
||||
{
|
||||
exec_cmd(tmp_l);
|
||||
}
|
||||
cmdin.close();
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, "run gridmanager-potential in the interactive mode for instructions.", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setlocale(LC_CTYPE, "");
|
||||
initialize_readline(); /* Bind our completer. */
|
||||
|
||||
display_logo();
|
||||
std::clog << "gridmanager - conversion, compuatation and manipulation of the grid data.\n";
|
||||
std::clog << "gridmanager-potential - processing grided potential field data.\n";
|
||||
std::clog << "Enter '?' to see all available commands.\n";
|
||||
|
||||
std::string cmd_str;
|
||||
char *c_line = (char *)NULL;
|
||||
char *c_line_s = (char *)NULL;
|
||||
bool quit = false;
|
||||
|
||||
while (!quit) try
|
||||
{
|
||||
c_line = readline(">> ");
|
||||
if (!c_line) break;
|
||||
|
||||
c_line_s = stripwhite(c_line);
|
||||
cmd_str = c_line_s;
|
||||
|
||||
if (cmd_str == "quit") quit = true;
|
||||
else if (cmd_str == "?") display_cmds();
|
||||
else exec_cmd(cmd_str);
|
||||
|
||||
free(c_line);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, "Enter 'help' for instructions.", 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
119
gridmanager-potential/gridmanager-potential.h
Normal file
119
gridmanager-potential/gridmanager-potential.h
Normal file
@ -0,0 +1,119 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. 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
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#ifndef GCTL_GRIDMANAGER_POTENTIAL_H
|
||||
#define GCTL_GRIDMANAGER_POTENTIAL_H
|
||||
|
||||
#include "gctl/potential/gm_regular_grid.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
// Function pointer for commands
|
||||
typedef void (*cmd_func_ptr)(const std::vector<std::string> &cmd_units);
|
||||
|
||||
struct cmd_pair
|
||||
{
|
||||
std::string name;
|
||||
cmd_func_ptr func_p;
|
||||
std::string brief;
|
||||
};
|
||||
|
||||
void quit(const std::vector<std::string> &cmd_units);
|
||||
void mesh_info(const std::vector<std::string> &cmd_units);
|
||||
void new_grid(const std::vector<std::string> &cmd_units);
|
||||
void data_cloud(const std::vector<std::string> &cmd_units);
|
||||
void gradient(const std::vector<std::string> &cmd_units);
|
||||
void wavelet(const std::vector<std::string> &cmd_units);
|
||||
void sum_data(const std::vector<std::string> &cmd_units);
|
||||
void diff_data(const std::vector<std::string> &cmd_units);
|
||||
void bool_data(const std::vector<std::string> &cmd_units);
|
||||
void func_data(const std::vector<std::string> &cmd_units);
|
||||
void calculator(const std::vector<std::string> &cmd_units);
|
||||
void data_output(const std::vector<std::string> &cmd_units);
|
||||
void data_rename(const std::vector<std::string> &cmd_units);
|
||||
void data_view(const std::vector<std::string> &cmd_units);
|
||||
void data_plot(const std::vector<std::string> &cmd_units);
|
||||
void get_stats(const std::vector<std::string> &cmd_units);
|
||||
void get_profile(const std::vector<std::string> &cmd_units);
|
||||
|
||||
void open_grid(const std::vector<std::string> &cmd_units);
|
||||
void save_grid(const std::vector<std::string> &cmd_units);
|
||||
void open_binary(const std::vector<std::string> &cmd_units);
|
||||
void save_binary(const std::vector<std::string> &cmd_units);
|
||||
void open_netcdf(const std::vector<std::string> &cmd_units);
|
||||
void save_netcdf(const std::vector<std::string> &cmd_units);
|
||||
void save_gmsh(const std::vector<std::string> &cmd_units);
|
||||
void open_surfer(const std::vector<std::string> &cmd_units);
|
||||
void save_surfer(const std::vector<std::string> &cmd_units);
|
||||
void save_text(const std::vector<std::string> &cmd_units);
|
||||
|
||||
void potential_gradient(const std::vector<std::string> &cmd_units);
|
||||
void rtp(const std::vector<std::string> &cmd_units);
|
||||
void drtp(const std::vector<std::string> &cmd_units);
|
||||
void continuation(const std::vector<std::string> &cmd_units);
|
||||
void trend(const std::vector<std::string> &cmd_units);
|
||||
|
||||
#define CMD_NUM 25
|
||||
const cmd_pair commands[CMD_NUM] = {
|
||||
{"info", mesh_info, "Show mesh's information."},
|
||||
{"init", new_grid, "Initialize a new grid framework."},
|
||||
{"open", open_grid, "Open a grid file."},
|
||||
{"save", save_grid, "Save grid data to a file."},
|
||||
{"cloud", data_cloud, "Import grid data from data cloud."},
|
||||
{"gradient", gradient, "Calculate directional gradients."},
|
||||
{"wavelet", wavelet, "Decompose grid data using the wavelet algorithm."},
|
||||
{"sum", sum_data, "Calculate the sum of two grid data."},
|
||||
{"diff", diff_data, "Calculate the difference of two grid data."},
|
||||
{"bool", bool_data, "Preform the boolean operation of grid data."},
|
||||
{"function", func_data, "Generate grid data from a mathematic expression."},
|
||||
{"calculator", calculator, "Preform the mathematic operation of grid data."},
|
||||
{"output", data_output, "Set output properites of grid data."},
|
||||
{"rename", data_rename, "Rename a grid data."},
|
||||
{"view", data_view, "Display a grid data using the exprtk library."},
|
||||
{"plot", data_plot, "Plot a grid data using the GMT library."},
|
||||
{"statistic", get_stats, "Show statistics of grid data."},
|
||||
{"profile", get_profile, "Extract profile data of a grid data."},
|
||||
{"gravgradient", potential_gradient, "Calculate gravitational gradients."},
|
||||
{"rtp", rtp, "Preform the Reduce to Pole (RTP) process."},
|
||||
{"drtp", drtp, "Preform the Differential Reduce to Pole (DRTP) process"},
|
||||
{"continuation", continuation, "Preform the upward or downward continuation process."},
|
||||
{"trend", trend, "Preform the separation process for the potential field data."},
|
||||
{"quit", quit, "Quit the program."},
|
||||
{"null", nullptr, "null"}
|
||||
};
|
||||
|
||||
#define KEY_NUM 6
|
||||
const cmd_pair keywords[KEY_NUM] = {
|
||||
{"netcdf", nullptr, "netCDF format."},
|
||||
{"surfer", nullptr, "Surfer format."},
|
||||
{"binary", nullptr, "GCTL native format."},
|
||||
{"gmsh", nullptr, "Gmsh format."},
|
||||
{"node", nullptr, "Node registered data."},
|
||||
{"cell", nullptr, "Cell registered data."}
|
||||
};
|
||||
|
||||
#endif // GCTL_GRIDMANAGER_POTENTIAL_H
|
75
gridmanager-potential/readme_gridmanager_potential.md
Normal file
75
gridmanager-potential/readme_gridmanager_potential.md
Normal file
@ -0,0 +1,75 @@
|
||||
#### quit
|
||||
Does what it says.
|
||||
|
||||
#### info [\<new-grid-name\>] [\<new-info\>]
|
||||
Show and/or edit information of the grid. This option could be used to assign new name and information to the grid. If the input name or information contain spaces, enclose them with quotes.
|
||||
|
||||
#### init \<new-file\> \<xnum\> \<ynum\> \<xmin\> \<ymin\> \<dx\> \<dy\> [\<info\>]
|
||||
(Re)create a new grid. 'xnum' and 'ynum' are point numbers on the x and y directions.
|
||||
'xmin' and 'ymin' are the minimal values of the grid's coordinates. 'dx' and
|
||||
'dy' are the grid spacings. Extra 'info' about the new grid could be added here.
|
||||
Mathematic expresstions could be used to specify the grid ranges.
|
||||
|
||||
#### open binary|netcdf|surfer \<file\>
|
||||
1. `open binary <file>` Open a grid stored in the GCTL native binary format (.2m file).
|
||||
2. `open netcdf <file> [<x-name> <y-name>] [<data-name>] [node|cell]` Open a grid stored in the netCDF format. 'node' (default) or 'cell' indicates whether the input grid data should be node or cell registed. names of the input grid's x-axial and y-axial should be given id they are not 'x' and 'y'. A \<data-name\> could be given to read the specficed data. Otherwise all grid data will be readed.
|
||||
3. `open surfer <file> [<new-data-name>] [surfer6-text|surfer6-binary|surfer7] [node|cell]` Open a grid stored in the Surfer formats. 'node' (default) or 'cell' indicates whether the input grid data should be node or cell registed. 'surfer6-text' (default), 'surfer6-binary' and 'surfer7' are the expected grid format. Since no data name is stored in the Surfer grid, a new data name could be given.
|
||||
|
||||
#### save binary|netcdf|surfer|gmsh \<file\>
|
||||
1. `save binary <file>` Save the grid using the GCTL native binary format (.2m file).
|
||||
2. `save netcdf <file> [<data-name>|node|cell]` Save grid data using the netCDF format. A \<data-name\> could be given to write the specficed data. Use 'node' (default) or 'cell' to write all node or cell registed data, respectively.
|
||||
3. `save surfer <file> <data-name> [surfer6-text|surfer6-binary|surfer7]` Save grid data using the Surfer format. A \<data-name\> must be given to write the specficed data. 'surfer6-text', 'surfer6-binary' and 'surfer7' are the outputing grid format.
|
||||
4. `save gmsh <file>` Save the grid using the Gmsh legacy format. This command will write all data that are allowed for outputing.
|
||||
5. `save text <file>` Save the grid data to text file.
|
||||
|
||||
#### cloud \<new-data-name\> node|cell \<data-could-file\> \<search-x\> \<search-y\> \<search-deg\>
|
||||
Import a randomly distributed data could (namely a xyz data). Note that a grid must exist before the use this command. 'node' or 'cell' indicates whether the input could data should be node or cell registed. \<data-could-file\> is the input data file. \<search-x\>,\<search-y\> and \<search-deg\> defines an oval of which the command is used to interpolate the could data to grid points.
|
||||
|
||||
#### gradient \<data-name\> \<new-data-name\> dx|dy \<order\>
|
||||
Calculate directional gradient(s) of the selected data. The new gradient data will have the same
|
||||
data type of the used data. 'dx' and 'dy' give the calculation directions. higher orders of the gradient could be specified by given them at the end of the command.
|
||||
|
||||
#### wavelet \<data-name\> \<wavelet-name\> \<order\> [\<show-summary\>]
|
||||
Using a wavelet \<wavelet-name\> to decompose the selecte data. Avaiable wavelets include 'bd2'... .The order of decomposition could be set using \<order\>. And set \<show-summary\> to yes to see the summary.
|
||||
|
||||
#### sum \<new-data-name\> \<data-name1\> \<data-name2\>
|
||||
Calculate the sum of the two data. The arguments' format should be clear enough.
|
||||
|
||||
#### diff \<new-data-name\> \<data-name1\> \<data-name2\>
|
||||
Calculate the difference of the two data. The arguments' format should be clear enough.
|
||||
|
||||
#### bool \<new-data-name\> \<data-name1> \<bool-data\> [reverse]
|
||||
Preform the bool operation on the slected data set. Put 'reverse' to for a reversed calculation.
|
||||
|
||||
#### calculator \<expression\> \<var1,data-name1\> \<var2,data-name2\>...
|
||||
Preform mathematic calculation using stored data. \<expression\> is a string that describles the expected calculation. For example, 'c := a + b' represents a summation between two data 'a' and 'b'. And the sum is stored in data 'c'. Note that 'a', 'b' and 'c' are algebraic symbols. So they must be tided to actual data using \<var,data-name\>, in which \<var\> is the algebraic symbol, \<data-name>\ is the data name. Remeber to put the output data name at the first place and if the input expression contain spaces, enclose them with quotes.
|
||||
|
||||
#### function \<expression\> \<new-data-name\>
|
||||
Create a new grid data named \<new-data-name\> from a mathematic expression. Default algebraic symbols 'f', 'x' and 'y' are defined for the resultent data, x-coordinate and y-coordinate, respectively. For example, 'f := x + y' represents a summation of the grid coordinates.
|
||||
|
||||
#### output enable|disable \<data-name1\> \<data-name2\>...
|
||||
Enable or disable output of the given data.
|
||||
|
||||
#### rename [\<old-name\>] [\<new-name\>]
|
||||
Change data name.
|
||||
|
||||
#### statistic \<data-name1\> \<data-name2\>...
|
||||
Show statistics of the selected data.
|
||||
|
||||
#### profile \<data-name\> \<out-file\> {\<x\>,\<y\> \<x\>,\<y\> \<num\>}|\<xy-file\>
|
||||
Extract a profile from the selected data and output to a text file.
|
||||
|
||||
#### gravgradient \<data-name\> \<new-data-name\> Tzx|Tzy|Tzz [\<order\>]
|
||||
Calculate directional gradient(s) of the selected potential field data using the frequency domain method. The new gradient data will have the same data type of the used data. 'Tzx', 'Tzy' and 'Tzz' give the calculation directions. higher orders of the gradient could be specified by given them at the end of the command.
|
||||
|
||||
#### rtp \<data-name\> \<rtp-name\> \<inclination\> \<declination>\
|
||||
Preforms the Reduce to Pole (RTP) process for the total intense magnetic field data.
|
||||
|
||||
#### drtp \<data-name\> \<rtp-name\> \<inclination-name\> \<declination-name\> [\<order\>]
|
||||
Preforms the Differential Reduce to Pole (DRTP) process for the total intense magnetic field data.
|
||||
|
||||
#### continuation \<data-name\> \<out-name\> \<height\>
|
||||
Preforms the upward or downward continuation process for the potential field data.
|
||||
|
||||
#### trend \<data-name\> \<reg-name\> \<res-name\> \<wx-size\> \<wy-size\> \<x-order\> \<y-order\>
|
||||
Preforms the separation process for the potential field data using the polynomial trending method.
|
27
gridmanager/CMakeLists.backup
Normal file
27
gridmanager/CMakeLists.backup
Normal file
@ -0,0 +1,27 @@
|
||||
set(TOOL_NAME gridmanager)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_search_module(EDITLINE REQUIRED libeditline)
|
||||
include_directories(${EDITLINE_INCLUDE_DIRS})
|
||||
link_directories(${EDITLINE_LIBRARY_DIRS})
|
||||
|
||||
aux_source_directory(. TOOL_SRC)
|
||||
add_executable(${TOOL_NAME} ${TOOL_SRC})
|
||||
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
target_link_libraries(${TOOL_NAME} PRIVATE ${GCTL_LIB})
|
||||
target_link_libraries(${TOOL_NAME} PRIVATE ${GCTL_GRAPHIC_LIB})
|
||||
target_link_libraries(${TOOL_NAME} PRIVATE gctl_mesh)
|
||||
target_link_libraries(${TOOL_NAME} PRIVATE ${WaveLib_LIB})
|
||||
target_link_libraries(${TOOL_NAME} PRIVATE ${EDITLINE_LIBRARIES})
|
||||
|
||||
install(TARGETS ${TOOL_NAME} RUNTIME DESTINATION sbin)
|
||||
|
||||
file(GLOB HELP_DOC *.md)
|
||||
install(FILES ${HELP_DOC} DESTINATION sbin/share)
|
776
gridmanager/gridmanager.cpp
Normal file
776
gridmanager/gridmanager.cpp
Normal file
@ -0,0 +1,776 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. 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
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "gridmanager.h"
|
||||
// We use the editline library to handle all inputs
|
||||
#include "editline.h"
|
||||
// install configuration
|
||||
#include "../gctl_toolkits_config.h"
|
||||
|
||||
cmd_pair curr_cmd; // Executing command
|
||||
gctl::regular_grid rg; // Grid object
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Strip whitespace from the start and end of STRING. Return a pointer
|
||||
* into STRING.
|
||||
*/
|
||||
char *stripwhite(char *string)
|
||||
{
|
||||
char *s, *t;
|
||||
|
||||
for (s = string; isspace(*s); s++) ;
|
||||
|
||||
if (*s == 0)
|
||||
return s;
|
||||
|
||||
t = s + strlen(s) - 1;
|
||||
while (t > s && isspace(*t))
|
||||
t--;
|
||||
*++t = '\0';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Generator function for command completion. STATE lets us
|
||||
know whether to start from scratch; without any state
|
||||
(i.e. STATE == 0), then we start at the top of the list. */
|
||||
char *command_generator(const char *text, int state)
|
||||
{
|
||||
static int list_index, len;
|
||||
|
||||
/* If this is a new word to complete, initialize now. This
|
||||
includes saving the length of TEXT for efficiency, and
|
||||
initializing the index variable to 0. */
|
||||
if (!state)
|
||||
{
|
||||
list_index = 0;
|
||||
len = strlen(text);
|
||||
}
|
||||
|
||||
/* Return the next name which partially matches from the command list. */
|
||||
while (list_index < CMD_NUM)
|
||||
{
|
||||
if (std::string(text) == commands[list_index].name.substr(0, len))
|
||||
{
|
||||
//const char* name = commands[list_index].name.data();
|
||||
return strdup(commands[list_index].name.data());
|
||||
}
|
||||
else list_index++;
|
||||
}
|
||||
|
||||
/* If no names matched, then return NULL. */
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempt to complete on the contents of TEXT. START and END
|
||||
* bound the region of rl_line_buffer that contains the word to
|
||||
* complete. TEXT is the word to complete. We can use the entire
|
||||
* contents of rl_line_buffer in case we want to do some simple
|
||||
* parsing. Return the array of matches, or NULL if there aren't any.
|
||||
*/
|
||||
char **gridmanager_completion(const char *text, int start, int end)
|
||||
{
|
||||
char **matches = nullptr;
|
||||
|
||||
/* If this word is at the start of the line, then it is a command
|
||||
to complete. Otherwise it is the name of a file in the current
|
||||
directory. */
|
||||
if (start == 0) matches = rl_completion_matches(text, command_generator);
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
void initialize_readline(void)
|
||||
{
|
||||
/* Allow conditional parsing of the ~/.inputrc file. */
|
||||
rl_readline_name = "gridmanager";
|
||||
|
||||
/* Tell the completer that we want a crack first. */
|
||||
rl_attempted_completion_function = gridmanager_completion;
|
||||
}
|
||||
|
||||
} // End C section
|
||||
|
||||
void display_cmds()
|
||||
{
|
||||
std::clog << "Command:\n";
|
||||
for (size_t i = 0; i < CMD_NUM - 1; i++)
|
||||
{
|
||||
std::clog << std::setw(12) << commands[i].name << ":\t" << commands[i].brief << "\n";
|
||||
}
|
||||
|
||||
std::clog << "\nEnter \"<command>?\" to see detailed instructions.\n\n";
|
||||
std::clog << "Keywords:\n";
|
||||
for (size_t i = 0; i < KEY_NUM; i++)
|
||||
{
|
||||
std::clog << std::setw(12) << keywords[i].name << ":\t" << keywords[i].brief << "\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void display_help(std::string input_cmd)
|
||||
{
|
||||
std::string install_dir = GCTL_TOOLKITS_INSTALL_PREFIX;
|
||||
std::ifstream helpin;
|
||||
open_infile(helpin, install_dir + "/sbin/share/readme_gridmanager", ".md");
|
||||
|
||||
std::string tmp_l, tmp_help;
|
||||
std::vector<std::string> cmds;
|
||||
std::vector<std::string> helps;
|
||||
while (getline(helpin, tmp_l))
|
||||
{
|
||||
if (tmp_l.substr(0, 4) == "####")
|
||||
{
|
||||
cmds.push_back(tmp_l.substr(5));
|
||||
tmp_help = "";
|
||||
while (getline(helpin, tmp_l))
|
||||
{
|
||||
if (tmp_l == "") break;
|
||||
else tmp_help += tmp_l + "\n";
|
||||
}
|
||||
helps.push_back(tmp_help);
|
||||
}
|
||||
}
|
||||
helpin.close();
|
||||
|
||||
std::string cmd_str;
|
||||
for (size_t j = 0; j < cmds.size(); j++)
|
||||
{
|
||||
parse_string_to_value(cmds[j], ' ', true, cmd_str);
|
||||
if (input_cmd == cmd_str)
|
||||
{
|
||||
replace_all(tmp_l, cmds[j], "\\", "");
|
||||
std::cout << GCTL_BOLDGREEN << tmp_l << GCTL_RESET << "\n";
|
||||
std::cout << helps[j] << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void exec_cmd(std::string cmd)
|
||||
{
|
||||
std::string cmd_name;
|
||||
parse_string_to_value(cmd, ' ', true, cmd_name);
|
||||
|
||||
// show instruction if there is a question mark at end of the command
|
||||
if (cmd_name.back() == '?')
|
||||
{
|
||||
cmd_name = cmd_name.substr(0, cmd_name.length() - 1);
|
||||
display_help(cmd_name);
|
||||
return;
|
||||
}
|
||||
|
||||
// set default command to null
|
||||
curr_cmd = commands[CMD_NUM - 1];
|
||||
for (size_t i = 0; i < CMD_NUM - 1; i++)
|
||||
{
|
||||
if (cmd_name == commands[i].name)
|
||||
{
|
||||
curr_cmd = commands[i]; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (curr_cmd.func_p == nullptr) throw gctl::runtime_error("Invalid command: " + cmd_name);
|
||||
|
||||
std::vector<std::string> cmd_units;
|
||||
parse_string_with_quotes(cmd, cmd_units);
|
||||
|
||||
return curr_cmd.func_p(cmd_units);
|
||||
}
|
||||
|
||||
// This function is defined to avoid potential breakdown while running in script mode.
|
||||
void quit(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void mesh_info(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// info [\<new-grid-name\>] [\<new-info\>]
|
||||
if (cmd_units.size() == 1)
|
||||
{
|
||||
rg.show_info();
|
||||
return;
|
||||
}
|
||||
|
||||
gctl::array<std::string> copy_str(2, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 2); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
if (copy_str[0] != "null") rg.set_meshname(copy_str[0]);
|
||||
if (copy_str[1] != "null") rg.set_meshinfo(copy_str[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef GCTL_MESH_EXPRTK
|
||||
|
||||
inline double expr2double(std::string s)
|
||||
{
|
||||
exprtk::symbol_table<double> sym_tab;
|
||||
exprtk::expression<double> expr;
|
||||
exprtk::parser<double> p;
|
||||
|
||||
sym_tab.add_constants();
|
||||
expr.register_symbol_table(sym_tab);
|
||||
p.compile(s, expr);
|
||||
|
||||
return expr.value();
|
||||
}
|
||||
|
||||
#endif // GCTL_MESH_EXPRTK
|
||||
|
||||
void new_grid(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// new \<new-file\> \<xnum\> \<ynum\> \<xmin\> \<ymin\> \<dx\> \<dy\> [\<info\>]
|
||||
if (cmd_units.size() < 8) throw std::runtime_error("new-grid: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(8, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 8); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
if (rg.initiated()) rg.clear_regular_grid();
|
||||
|
||||
double xmin, ymin, dx, dy;
|
||||
#ifdef GCTL_MESH_EXPRTK
|
||||
|
||||
xmin = expr2double(copy_str[3]);
|
||||
ymin = expr2double(copy_str[4]);
|
||||
dx = expr2double(copy_str[5]);
|
||||
dy = expr2double(copy_str[6]);
|
||||
|
||||
#else
|
||||
|
||||
xmin = atof(copy_str[3].c_str());
|
||||
ymin = atof(copy_str[4].c_str());
|
||||
dx = atof(copy_str[5].c_str());
|
||||
dy = atof(copy_str[6].c_str());
|
||||
|
||||
#endif // GCTL_MESH_EXPRTK
|
||||
|
||||
rg.init(copy_str[0], copy_str[7], atoi(copy_str[1].c_str()),
|
||||
atoi(copy_str[2].c_str()), xmin, ymin, dx, dy);
|
||||
return;
|
||||
}
|
||||
|
||||
void open_grid(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// open binary <file>
|
||||
// open netcdf <file> [<x-name> <y-name>] [<data-name>] [node|cell]
|
||||
// open surfer <file> <new-data-name> [surfer6-text|surfer6-binary|surfer7] [node|cell]
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("open: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "binary") open_binary(cmd_units);
|
||||
else if (cmd_units[1] == "netcdf") open_netcdf(cmd_units);
|
||||
else if (cmd_units[1] == "surfer") open_surfer(cmd_units);
|
||||
else throw std::runtime_error("open: unknown file format.");
|
||||
return;
|
||||
}
|
||||
|
||||
void save_grid(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save binary <file>
|
||||
// save netcdf <file> [<data-name>|node|cell]
|
||||
// save surfer <file> <data-name> [surfer6-text|surfer6-binary|surfer7]
|
||||
// save gmsh <file>
|
||||
// save text <file> <data-name> [<data-name>]...
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
if (cmd_units[1] == "binary") save_binary(cmd_units);
|
||||
else if (cmd_units[1] == "netcdf") save_netcdf(cmd_units);
|
||||
else if (cmd_units[1] == "surfer") save_surfer(cmd_units);
|
||||
else if (cmd_units[1] == "gmsh") save_gmsh(cmd_units);
|
||||
else if (cmd_units[1] == "text") save_text(cmd_units);
|
||||
else throw std::runtime_error("save: unknown file format.");
|
||||
return;
|
||||
}
|
||||
|
||||
void open_binary(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// open binary <file>
|
||||
rg.load_binary(cmd_units[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_binary(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save binary <file>
|
||||
rg.save_binary(cmd_units[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
void open_netcdf(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// open netcdf <file> [<x-name> <y-name>] [<data-name>] [node|cell]
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("open: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(5, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 5); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
mesh_data_type_e d_type = NodeData;
|
||||
if (copy_str[4] == "cell") d_type = ElemData;
|
||||
else if (copy_str[4] == "node") d_type = NodeData;
|
||||
|
||||
if (copy_str[1] == "null") copy_str[1] = "x";
|
||||
if (copy_str[2] == "null") copy_str[2] = "y";
|
||||
if (copy_str[3] == "null") rg.load_netcdf_grid(copy_str[0], d_type, copy_str[1], copy_str[2]);
|
||||
else rg.load_netcdf_grid(copy_str[0], d_type, copy_str[1], copy_str[2], copy_str[3]);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_netcdf(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save netcdf <file> [<data-name>|node|cell] [xname] [yname]
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 4); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
std::string xname = "x", yname = "y";
|
||||
if (copy_str[2] != "null") xname = copy_str[2];
|
||||
if (copy_str[3] != "null") yname = copy_str[3];
|
||||
|
||||
if (copy_str[1] == "null") rg.save_netcdf_grid(copy_str[0], NodeData, xname, yname);
|
||||
else if (copy_str[1] == "node") rg.save_netcdf_grid(copy_str[0], NodeData, xname, yname);
|
||||
else if (copy_str[1] == "cell") rg.save_netcdf_grid(copy_str[0], ElemData, xname, yname);
|
||||
else rg.save_netcdf_grid(copy_str[0], copy_str[1], xname, yname);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_gmsh(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save gmsh <file>
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
rg.save_gmsh_withdata(cmd_units[2], OverWrite, NotPacked);
|
||||
return;
|
||||
}
|
||||
|
||||
void open_surfer(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// open surfer <file> [<new-data-name>] [surfer6-text|surfer6-binary|surfer7] [node|cell]
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("open: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 4); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
surfer_file_type_e st = Surfer6Text;
|
||||
if (copy_str[2] == "surfer6-text") st = Surfer6Text;
|
||||
else if (copy_str[2] == "surfer6-binary") st = Surfer6Binary;
|
||||
else if (copy_str[2] == "surfer7") st = Surfer7Grid;
|
||||
|
||||
mesh_data_type_e d_type = NodeData;
|
||||
if (copy_str[3] == "node") d_type = NodeData;
|
||||
else if (copy_str[3] == "cell") d_type = ElemData;
|
||||
|
||||
if (copy_str[1] == "null") rg.load_surfer_grid(copy_str[0], "Untitled", d_type, st);
|
||||
else rg.load_surfer_grid(copy_str[0], copy_str[3], d_type, st);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_surfer(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save surfer <file> <data-name> [surfer6-text|surfer6-binary|surfer7]
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(3, "null");
|
||||
for (size_t i = 0; i < GCTL_MIN(cmd_units.size() - 2, 3); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 2];
|
||||
}
|
||||
|
||||
surfer_file_type_e st = Surfer6Text;
|
||||
if (copy_str[2] == "surfer6-text") st = Surfer6Text;
|
||||
else if (copy_str[2] == "surfer6-binary") st = Surfer6Binary;
|
||||
else if (copy_str[2] == "surfer7") st = Surfer7Grid;
|
||||
|
||||
rg.save_surfer_grid(copy_str[0], copy_str[1] ,st);
|
||||
return;
|
||||
}
|
||||
|
||||
void save_text(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save text <file> <data-name>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(cmd_units.size() - 3, "null");
|
||||
for (size_t i = 0; i < cmd_units.size() - 3; i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 3];
|
||||
}
|
||||
|
||||
rg.save_text(cmd_units[2], copy_str);
|
||||
return;
|
||||
}
|
||||
|
||||
void data_cloud(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// data-cloud \<new-data-name\> node|cell \<data-could-file\> \<search-x\> \<search-y\> \<search-deg\>
|
||||
if (cmd_units.size() < 7) throw std::runtime_error("data-cloud: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(7, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 7); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
mesh_data_type_e d_type = NodeData;
|
||||
if (copy_str[1] == "node") d_type = NodeData;
|
||||
else if (copy_str[1] == "cell") d_type = ElemData;
|
||||
else throw std::runtime_error("open-surfer: invalid grid data type.");
|
||||
|
||||
geodsv_io text_in;
|
||||
text_in.load_text(copy_str[2]);
|
||||
|
||||
array<point2dc> posi_arr;
|
||||
_1d_array data_vec;
|
||||
text_in.get_column_point2dc(posi_arr, 0, 1);
|
||||
text_in.get_column(data_vec, 2);
|
||||
|
||||
rg.load_data_cloud(posi_arr, data_vec, atof(copy_str[3].c_str()), atof(copy_str[4].c_str()), atof(copy_str[5].c_str()), copy_str[0], d_type);
|
||||
return;
|
||||
}
|
||||
|
||||
void gradient(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// gradient <data-name> <new-data-name> dx|dy <order>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("gradient: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 4); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
gradient_type_e g_type;
|
||||
if (copy_str[2] == "dx") g_type = Dx;
|
||||
else if (copy_str[2] == "dy") g_type = Dy;
|
||||
else throw std::runtime_error("gradient: invalid gradient type.");
|
||||
|
||||
int order = 1;
|
||||
if (copy_str[3] != "null") order = atoi(copy_str[3].c_str());
|
||||
|
||||
rg.gradient(copy_str[0], copy_str[1], g_type, order);
|
||||
return;
|
||||
}
|
||||
|
||||
void wavelet(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// wavelet \<data-name\> \<wavelet-name\> \<order\> [\<show-summary\>]
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("wavelet: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 4); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
int order = order = atoi(copy_str[2].c_str());
|
||||
|
||||
if (copy_str[3] == "yes") rg.wavelet(copy_str[0], copy_str[1], order, true);
|
||||
else rg.wavelet(copy_str[0], copy_str[1], order, false);
|
||||
return;
|
||||
}
|
||||
|
||||
void sum_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// sum-data \<new-data\> \<data1\> \<data2\>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("sum: insufficient parameters.");
|
||||
|
||||
rg.sum(cmd_units[1], cmd_units[2], cmd_units[3]);
|
||||
return;
|
||||
}
|
||||
|
||||
void diff_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// diff \<new-data\> \<data1\> \<data2\>
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("diff: insufficient parameters.");
|
||||
|
||||
rg.diff(cmd_units[1], cmd_units[2], cmd_units[3]);
|
||||
return;
|
||||
}
|
||||
|
||||
void bool_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// bool \<new-data-name\> \<data-name1> \<bool-data\> [reverse]
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("bool: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(4, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 4); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
if (copy_str[3] == "reverse") rg.boolean(copy_str[0], copy_str[1], copy_str[2], true);
|
||||
else rg.boolean(copy_str[0], copy_str[1], copy_str[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
void func_data(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// function \<expression\> \<new-data-name\>
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("function: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(3, "null");
|
||||
for (size_t i = 0; i <= GCTL_MIN(cmd_units.size() - 1, 3); i++)
|
||||
{
|
||||
copy_str[i] = cmd_units[i + 1];
|
||||
}
|
||||
|
||||
rg.function(copy_str[0], copy_str[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
void calculator(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// calculator \<expression\> \<var1,data-name1\> \<var2,data-name2\>...
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("calculator: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(cmd_units.size() - 1, "null");
|
||||
for (size_t i = 1; i <= cmd_units.size() - 1; i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
array<std::string> var_list(copy_str.size() - 1), data_list(copy_str.size() - 1);
|
||||
for (size_t i = 0; i < var_list.size(); i++)
|
||||
{
|
||||
parse_string_to_value(copy_str[i + 1], ',', true, var_list[i], data_list[i]);
|
||||
}
|
||||
|
||||
rg.calculator(copy_str[0], var_list, data_list);
|
||||
return;
|
||||
}
|
||||
|
||||
void data_output(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// data-output enable|disable \<data-name1\> \<data-name2\>...
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("data-output: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(cmd_units.size() - 1, "null");
|
||||
for (size_t i = 1; i <= cmd_units.size() - 1; i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
meshdata *data_ptr;
|
||||
if (copy_str[0] == "enable")
|
||||
{
|
||||
for (size_t i = 1; i < copy_str.size(); i++)
|
||||
{
|
||||
data_ptr = rg.get_data_ptr(copy_str[i]);
|
||||
data_ptr->output_ok_ = true;
|
||||
}
|
||||
}
|
||||
else if (copy_str[0] == "disable")
|
||||
{
|
||||
for (size_t i = 1; i < copy_str.size(); i++)
|
||||
{
|
||||
data_ptr = rg.get_data_ptr(copy_str[i]);
|
||||
data_ptr->output_ok_ = false;
|
||||
}
|
||||
}
|
||||
else throw std::runtime_error("data-output: invalid operation type.");
|
||||
return;
|
||||
}
|
||||
|
||||
void data_rename(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// data-rename [\<old-name\>] [\<new-name\>]
|
||||
if (cmd_units.size() < 3) throw std::runtime_error("rename: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(2, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 2); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
meshdata &curr_data = rg.get_data(copy_str[0]);
|
||||
curr_data.name_ = copy_str[1];
|
||||
return;
|
||||
}
|
||||
|
||||
void data_view(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// plot [\<data-name\>]...
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("view: insufficient parameters.");
|
||||
|
||||
for (size_t i = 1; i < cmd_units.size(); i++)
|
||||
{
|
||||
rg.view(cmd_units[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void data_plot(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// plot [\<data-name\>]...
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("plot: insufficient parameters.");
|
||||
|
||||
for (size_t i = 1; i < cmd_units.size(); i++)
|
||||
{
|
||||
rg.plot(cmd_units[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void get_stats(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// statistic \<data-name1\> \<data-name2\>...
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("statistic: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(cmd_units.size() - 1, "null");
|
||||
for (size_t i = 1; i <= cmd_units.size() - 1; i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
meshdata *data_ptr;
|
||||
std::vector<double> stats;
|
||||
for (size_t i = 0; i < copy_str.size(); i++)
|
||||
{
|
||||
data_ptr = rg.get_data_ptr(copy_str[i]);
|
||||
data_ptr->show_info();
|
||||
data_ptr->show_stats();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void get_profile(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// profile \<data-name\> \<out-file\> {\<x\>,\<y\> \<x\>,\<y\> \<num\>}|{\<xy-file\>}
|
||||
if (cmd_units.size() < 4) throw std::runtime_error("profile: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(5, "null");
|
||||
for (size_t i = 1; i <= GCTL_MIN(cmd_units.size() - 1, 5); i++)
|
||||
{
|
||||
copy_str[i - 1] = cmd_units[i];
|
||||
}
|
||||
|
||||
array<point2dc> xys;
|
||||
array<double> p_data;
|
||||
if (access(copy_str[2].c_str(), R_OK))
|
||||
{
|
||||
point2dc st_p, ed_p;
|
||||
gctl::parse_string_to_value(copy_str[2], ',', true, st_p.x, st_p.y);
|
||||
gctl::parse_string_to_value(copy_str[3], ',', true, ed_p.x, ed_p.y);
|
||||
rg.extract_profile(copy_str[0], st_p, ed_p, atoi(copy_str[4].c_str()), xys, p_data);
|
||||
}
|
||||
else // File exist
|
||||
{
|
||||
geodsv_io fio;
|
||||
fio.load_text(copy_str[2]);
|
||||
fio.get_column_point2dc(xys, 0, 1);
|
||||
|
||||
rg.extract_points(copy_str[0], xys, p_data);
|
||||
}
|
||||
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, copy_str[1], ".txt");
|
||||
ofile << "# x y d val\n";
|
||||
for (size_t i = 0; i < xys.size(); i++)
|
||||
{
|
||||
ofile << xys[i].x << " " << xys[i].y << " " << distance(xys[0], xys[i]) << " " << p_data[i] << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc >= 2)
|
||||
{
|
||||
std::string tmp_l;
|
||||
std::ifstream cmdin;
|
||||
|
||||
// Run commands from files. Each line is a command.
|
||||
// You can give more than one file
|
||||
for (size_t i = 1; i < argc; i++) try
|
||||
{
|
||||
open_infile(cmdin, argv[i]);
|
||||
while (getline(cmdin, tmp_l) && tmp_l != "" && tmp_l[0] != '#')
|
||||
{
|
||||
exec_cmd(tmp_l);
|
||||
}
|
||||
cmdin.close();
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, "run gridmanager in the interactive mode for instructions.", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setlocale(LC_CTYPE, "");
|
||||
initialize_readline(); /* Bind our completer. */
|
||||
|
||||
display_logo();
|
||||
std::clog << "gridmanager - conversion, compuatation and manipulation of the grid data.\n";
|
||||
std::clog << "Enter '?' to see all available commands.\n";
|
||||
|
||||
std::string cmd_str;
|
||||
char *c_line = (char *)NULL;
|
||||
char *c_line_s = (char *)NULL;
|
||||
bool quit = false;
|
||||
|
||||
while (!quit) try
|
||||
{
|
||||
c_line = readline(">> ");
|
||||
if (!c_line) break;
|
||||
|
||||
c_line_s = stripwhite(c_line);
|
||||
cmd_str = c_line_s;
|
||||
|
||||
if (cmd_str == "quit") quit = true;
|
||||
else if (cmd_str == "?") display_cmds();
|
||||
else exec_cmd(cmd_str);
|
||||
|
||||
free(c_line);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, "Enter 'help' for instructions.", 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
110
gridmanager/gridmanager.h
Normal file
110
gridmanager/gridmanager.h
Normal file
@ -0,0 +1,110 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. 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
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#ifndef GCTL_MESH_GRIDMANAGER_H
|
||||
#define GCTL_MESH_GRIDMANAGER_H
|
||||
|
||||
#include "gctl/io/term_io.h"
|
||||
#include "gctl/io/dsv_io.h"
|
||||
#include "gctl/mesh/regular_grid.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
// Function pointer for commands
|
||||
typedef void (*cmd_func_ptr)(const std::vector<std::string> &cmd_units);
|
||||
|
||||
struct cmd_pair
|
||||
{
|
||||
std::string name;
|
||||
cmd_func_ptr func_p;
|
||||
std::string brief;
|
||||
};
|
||||
|
||||
void quit(const std::vector<std::string> &cmd_units);
|
||||
void mesh_info(const std::vector<std::string> &cmd_units);
|
||||
void new_grid(const std::vector<std::string> &cmd_units);
|
||||
void data_cloud(const std::vector<std::string> &cmd_units);
|
||||
void gradient(const std::vector<std::string> &cmd_units);
|
||||
void wavelet(const std::vector<std::string> &cmd_units);
|
||||
void sum_data(const std::vector<std::string> &cmd_units);
|
||||
void diff_data(const std::vector<std::string> &cmd_units);
|
||||
void bool_data(const std::vector<std::string> &cmd_units);
|
||||
void func_data(const std::vector<std::string> &cmd_units);
|
||||
void calculator(const std::vector<std::string> &cmd_units);
|
||||
void data_output(const std::vector<std::string> &cmd_units);
|
||||
void data_rename(const std::vector<std::string> &cmd_units);
|
||||
void data_view(const std::vector<std::string> &cmd_units);
|
||||
void data_plot(const std::vector<std::string> &cmd_units);
|
||||
void get_stats(const std::vector<std::string> &cmd_units);
|
||||
void get_profile(const std::vector<std::string> &cmd_units);
|
||||
|
||||
void open_grid(const std::vector<std::string> &cmd_units);
|
||||
void save_grid(const std::vector<std::string> &cmd_units);
|
||||
void open_binary(const std::vector<std::string> &cmd_units);
|
||||
void save_binary(const std::vector<std::string> &cmd_units);
|
||||
void open_netcdf(const std::vector<std::string> &cmd_units);
|
||||
void save_netcdf(const std::vector<std::string> &cmd_units);
|
||||
void save_gmsh(const std::vector<std::string> &cmd_units);
|
||||
void open_surfer(const std::vector<std::string> &cmd_units);
|
||||
void save_surfer(const std::vector<std::string> &cmd_units);
|
||||
void save_text(const std::vector<std::string> &cmd_units);
|
||||
|
||||
#define CMD_NUM 20
|
||||
const cmd_pair commands[CMD_NUM] = {
|
||||
{"info", mesh_info, "Show mesh's information."},
|
||||
{"init", new_grid, "Initialize a new grid framework."},
|
||||
{"open", open_grid, "Open a grid file."},
|
||||
{"save", save_grid, "Save grid data to a file."},
|
||||
{"cloud", data_cloud, "Import grid data from data cloud."},
|
||||
{"gradient", gradient, "Calculate directional gradients."},
|
||||
{"wavelet", wavelet, "Decompose grid data using the wavelet algorithm."},
|
||||
{"sum", sum_data, "Calculate the sum of two grid data."},
|
||||
{"diff", diff_data, "Calculate the difference of two grid data."},
|
||||
{"bool", bool_data, "Preform the boolean operation of grid data."},
|
||||
{"function", func_data, "Generate grid data from a mathematic expression."},
|
||||
{"calculator", calculator, "Preform the mathematic operation of grid data."},
|
||||
{"output", data_output, "Set output properites of grid data."},
|
||||
{"rename", data_rename, "Rename a grid data."},
|
||||
{"view", data_view, "Display a grid data using the exprtk library."},
|
||||
{"plot", data_plot, "Plot a grid data using the GMT library."},
|
||||
{"statistic", get_stats, "Show statistics of grid data."},
|
||||
{"profile", get_profile, "Extract profile data of a grid data."},
|
||||
{"quit", quit, "Quit the program."},
|
||||
{"null", nullptr, "null"}
|
||||
};
|
||||
|
||||
#define KEY_NUM 6
|
||||
const cmd_pair keywords[KEY_NUM] = {
|
||||
{"netcdf", nullptr, "netCDF format."},
|
||||
{"surfer", nullptr, "Surfer format."},
|
||||
{"binary", nullptr, "GCTL native format."},
|
||||
{"gmsh", nullptr, "Gmsh format."},
|
||||
{"node", nullptr, "Node registered data."},
|
||||
{"cell", nullptr, "Cell registered data."}
|
||||
};
|
||||
|
||||
#endif // GCTL_MESH_GRIDMANAGER_H
|
60
gridmanager/readme_gridmanager.md
Normal file
60
gridmanager/readme_gridmanager.md
Normal file
@ -0,0 +1,60 @@
|
||||
#### quit
|
||||
Does what it says.
|
||||
|
||||
#### info [\<new-grid-name\>] [\<new-info\>]
|
||||
Show and/or edit information of the grid. This option could be used to assign new name and information to the grid. If the input name or information contain spaces, enclose them with quotes.
|
||||
|
||||
#### init \<new-file\> \<xnum\> \<ynum\> \<xmin\> \<ymin\> \<dx\> \<dy\> [\<info\>]
|
||||
(Re)create a new grid. 'xnum' and 'ynum' are point numbers on the x and y directions.
|
||||
'xmin' and 'ymin' are the minimal values of the grid's coordinates. 'dx' and
|
||||
'dy' are the grid spacings. Extra 'info' about the new grid could be added here.
|
||||
Mathematic expresstions could be used to specify the grid ranges.
|
||||
|
||||
#### open binary|netcdf|surfer \<file\>
|
||||
1. `open binary <file>` Open a grid stored in the GCTL native binary format (.2m file).
|
||||
2. `open netcdf <file> [<x-name> <y-name>] [<data-name>] [node|cell]` Open a grid stored in the netCDF format. 'node' (default) or 'cell' indicates whether the input grid data should be node or cell registed. names of the input grid's x-axial and y-axial should be given id they are not 'x' and 'y'. A \<data-name\> could be given to read the specficed data. Otherwise all grid data will be readed.
|
||||
3. `open surfer <file> [<new-data-name>] [surfer6-text|surfer6-binary|surfer7] [node|cell]` Open a grid stored in the Surfer formats. 'node' (default) or 'cell' indicates whether the input grid data should be node or cell registed. 'surfer6-text' (default), 'surfer6-binary' and 'surfer7' are the expected grid format. Since no data name is stored in the Surfer grid, a new data name could be given.
|
||||
|
||||
#### save binary|netcdf|surfer|gmsh \<file\>
|
||||
1. `save binary <file>` Save the grid using the GCTL native binary format (.2m file).
|
||||
2. `save netcdf <file> [<data-name>|node|cell] [xname] [yname]` Save grid data using the netCDF format. A \<data-name\> could be given to write the specficed data. Use 'node' (default) or 'cell' to write all node or cell registed data, respectively.
|
||||
3. `save surfer <file> <data-name> [surfer6-text|surfer6-binary|surfer7]` Save grid data using the Surfer format. A \<data-name\> must be given to write the specficed data. 'surfer6-text', 'surfer6-binary' and 'surfer7' are the outputing grid format.
|
||||
4. `save gmsh <file>` Save the grid using the Gmsh legacy format. This command will write all data that are allowed for outputing.
|
||||
5. `save text <file>` Save the grid data to text file.
|
||||
|
||||
#### cloud \<new-data-name\> node|cell \<data-could-file\> \<search-x\> \<search-y\> \<search-deg\>
|
||||
Import a randomly distributed data could (namely a xyz data). Note that a grid must exist before the use this command. 'node' or 'cell' indicates whether the input could data should be node or cell registed. \<data-could-file\> is the input data file. \<search-x\>,\<search-y\> and \<search-deg\> defines an oval of which the command is used to interpolate the could data to grid points.
|
||||
|
||||
#### gradient \<data-name\> \<new-data-name\> dx|dy \<order\>
|
||||
Calculate directional gradient(s) of the selected data. The new gradient data will have the same
|
||||
data type of the used data. 'dx' and 'dy' give the calculation directions. higher orders of the gradient could be specified by given them at the end of the command.
|
||||
|
||||
#### wavelet \<data-name\> \<wavelet-name\> \<order\> [\<show-summary\>]
|
||||
Using a wavelet \<wavelet-name\> to decompose the selecte data. Avaiable wavelets include 'bd2'... .The order of decomposition could be set using \<order\>. And set \<show-summary\> to yes to see the summary.
|
||||
|
||||
#### sum \<new-data\> \<data1\> \<data2\>
|
||||
Calculate the sum of the two data. The arguments' format should be clear enough.
|
||||
|
||||
#### diff \<new-data\> \<data1\> \<data2\>
|
||||
Calculate the difference of the two data. The arguments' format should be clear enough.
|
||||
|
||||
#### bool \<new-data-name\> \<data-name1> \<bool-data\> [reverse]
|
||||
Preform the bool operation on the slected data set. Put 'reverse' to for a reversed calculation.
|
||||
|
||||
#### calculator \<expression\> \<var1,data-name1\> \<var2,data-name2\>...
|
||||
Preform mathematic calculation using stored data. \<expression\> is a string that describles the expected calculation. For example, 'c := a + b' represents a summation between two data 'a' and 'b'. And the sum is stored in data 'c'. Note that 'a', 'b' and 'c' are algebraic symbols. So they must be tided to actual data using \<var,data-name\>, in which \<var\> is the algebraic symbol, \<data-name>\ is the data name. Remeber to put the output data name at the first place and if the input expression contain spaces, enclose them with quotes.
|
||||
|
||||
#### function \<expression\> \<new-data-name\>
|
||||
Create a new grid data named \<new-data-name\> from a mathematic expression. Default algebraic symbols 'f', 'x' and 'y' are defined for the resultent data, x-coordinate and y-coordinate, respectively. For example, 'f := x + y' represents a summation of the grid coordinates.
|
||||
|
||||
#### output enable|disable \<data-name1\> \<data-name2\>...
|
||||
Enable or disable output of the given data.
|
||||
|
||||
#### rename [\<old-name\>] [\<new-name\>]
|
||||
Change data name.
|
||||
|
||||
#### statistic \<data-name1\> \<data-name2\>...
|
||||
Show statistics of the selected data.
|
||||
|
||||
#### profile \<data-name\> \<out-file\> {\<x\>,\<y\> \<x\>,\<y\> \<num\>}|\<xy-file\>
|
||||
Extract a profile from the selected data and output to a text file.
|
16
levy_planner/CMakeLists.backup
Normal file
16
levy_planner/CMakeLists.backup
Normal file
@ -0,0 +1,16 @@
|
||||
set(TOOL_NAME levy_planner)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
aux_source_directory(. TOOL_SRC)
|
||||
add_executable(${TOOL_NAME} ${TOOL_SRC})
|
||||
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(${TOOL_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
target_link_libraries(${TOOL_NAME} PRIVATE ${GCTL_LIB})
|
||||
target_link_libraries(${TOOL_NAME} PRIVATE gctl_optimization)
|
||||
|
||||
install(TARGETS ${TOOL_NAME} RUNTIME DESTINATION sbin)
|
84
levy_planner/levy_planner.cpp
Normal file
84
levy_planner/levy_planner.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. 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
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "gctl/optimization/lgd.h"
|
||||
|
||||
class levy_planner : public gctl::lgd_solver
|
||||
{
|
||||
public:
|
||||
levy_planner(){}
|
||||
virtual ~levy_planner(){}
|
||||
virtual double LGD_Evaluate(const gctl::array<double> &x, gctl::array<double> &g){return 0;}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
gctl::display_logo();
|
||||
|
||||
levy_planner p;
|
||||
gctl::lgd_para my_para = p.default_lgd_para();
|
||||
|
||||
double alpha, beta;
|
||||
std::cout << "Input alpha (> 0) and beta (1.0 ~ 2.0): ";
|
||||
std::cin >> alpha >> beta;
|
||||
|
||||
if (alpha <= 0 || beta <= 1.0 || beta >= 2.0)
|
||||
{
|
||||
std::cout << "Invalid inputs\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
my_para.flight_times = 100000;
|
||||
my_para.beta = beta;
|
||||
p.set_lgd_para(my_para);
|
||||
|
||||
gctl::array<double> dist;
|
||||
p.get_levy_distribution(dist);
|
||||
|
||||
for (size_t i = 0; i < dist.size(); i++)
|
||||
{
|
||||
dist[i] *= alpha;
|
||||
}
|
||||
|
||||
double mean = dist.mean();
|
||||
double std = dist.std();
|
||||
double cnt = 0.0;
|
||||
|
||||
for (size_t i = 0; i < dist.size(); i++)
|
||||
{
|
||||
if (fabs(dist[i] - mean) > 3.0*std) cnt += 1.0;
|
||||
}
|
||||
|
||||
std::cout << "Step Avg. = " << mean << "\n";
|
||||
std::cout << "Step STD = " << std << "\n";
|
||||
std::cout << "Large Ones = " << cnt/1000.0 << "%\n";
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
1
lib/gctl_config.h
Normal file
1
lib/gctl_config.h
Normal file
@ -0,0 +1 @@
|
||||
#define GCTL_TOOLKITS_INSTALL_PREFIX "/opt/stow/gctl_toolkits"
|
Loading…
Reference in New Issue
Block a user