OGS
Raster2ASC.cpp
Go to the documentation of this file.
1
12#include <tclap/CmdLine.h>
13
14#ifdef USE_PETSC
15#include <mpi.h>
16#endif
17
19#include "GeoLib/Raster.h"
20#include "InfoLib/GitInfo.h"
21
22int main(int argc, char* argv[])
23{
24 TCLAP::CmdLine cmd(
25 "Converts ascii raster files (e.g. Surfer *.grd files or *.xyz files) "
26 "into ASC raster files.\n\n"
27 "OpenGeoSys-6 software, version " +
29 ".\n"
30 "Copyright (c) 2012-2024, OpenGeoSys Community "
31 "(http://www.opengeosys.org)",
33
34 TCLAP::ValueArg<std::string> output_arg(
35 "o", "output", "filename for output raster", true, "", "output file");
36 cmd.add(output_arg);
37
38 TCLAP::ValueArg<std::string> input_arg(
39 "i", "input", "filename for input raster", true, "", "input file");
40 cmd.add(input_arg);
41
42 cmd.parse(argc, argv);
43
44#ifdef USE_PETSC
45 MPI_Init(&argc, &argv);
46#endif
47
48 std::unique_ptr<GeoLib::Raster> raster(
49 FileIO::AsciiRasterInterface::readRaster(input_arg.getValue()));
50
51 if (raster == nullptr)
52 {
53 ERR("Couldn't read input raster file.");
54 return EXIT_FAILURE;
55 }
56
57 std::string output_name = output_arg.getValue();
58 if (output_name.substr(output_name.length() - 4, 4) != ".asc")
59 {
60 output_name = output_name.append(".asc");
61 }
62
64#ifdef USE_PETSC
65 MPI_Finalize();
66#endif
67 return EXIT_SUCCESS;
68}
Definition of the AsciiRasterInterface class.
Git information.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
int main(int argc, char *argv[])
Definition of the GeoLib::Raster class.
static void writeRasterAsASC(GeoLib::Raster const &raster, std::string const &file_name)
Writes an Esri asc-file.
static GeoLib::Raster * readRaster(std::string const &fname)
GITINFOLIB_EXPORT const std::string ogs_version