File: gdalmdiminfo_bin.cpp

package info (click to toggle)
gdal 3.12.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 92,292 kB
  • sloc: cpp: 1,223,498; ansic: 206,434; python: 26,278; java: 6,001; xml: 4,769; sh: 3,855; cs: 2,513; yacc: 1,306; makefile: 214
file content (94 lines) | stat: -rw-r--r-- 2,733 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/******************************************************************************
 *
 * Project:  GDAL Utilities
 * Purpose:  Command line application to list info about a multidimensional
 *raster Author:   Even Rouault,<even.rouault at spatialys.com>
 *
 * ****************************************************************************
 * Copyright (c) 2019, Even Rouault <even.rouault at spatialys.com>
 *
 * SPDX-License-Identifier: MIT
 ****************************************************************************/

#include "gdal_version.h"
#include "gdal.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "commonutils.h"
#include "gdal_utils_priv.h"

/**
 * @brief Makes sure the GDAL library is properly cleaned up before exiting.
 * @param nCode exit code
 * @todo Move to API
 */
static void GDALExit(const int nCode)
{
    GDALDestroy();
    exit(nCode);
}

/************************************************************************/
/*                               Usage()                                */
/************************************************************************/

static void Usage()

{
    fprintf(stderr, "%s\n", GDALMultiDimInfoAppGetParserUsage().c_str());
    GDALExit(1);
}

/************************************************************************/
/*                                main()                                */
/************************************************************************/

MAIN_START(argc, argv)

{
    EarlySetConfigOptions(argc, argv);

    GDALAllRegister();

    argc = GDALGeneralCmdLineProcessor(argc, &argv, 0);
    if (argc < 1)
        GDALExit(-argc);

    argv = CSLAddString(argv, "-stdout");

    GDALMultiDimInfoOptionsForBinary sOptionsForBinary;

    std::unique_ptr<GDALMultiDimInfoOptions,
                    decltype(&GDALMultiDimInfoOptionsFree)>
        psOptions{GDALMultiDimInfoOptionsNew(argv + 1, &sOptionsForBinary),
                  GDALMultiDimInfoOptionsFree};

    CSLDestroy(argv);

    if (!psOptions)
        Usage();

    GDALDatasetH hDataset =
        GDALOpenEx(sOptionsForBinary.osFilename.c_str(),
                   GDAL_OF_MULTIDIM_RASTER | GDAL_OF_VERBOSE_ERROR,
                   sOptionsForBinary.aosAllowInputDrivers.List(),
                   sOptionsForBinary.aosOpenOptions.List(), nullptr);
    if (!hDataset)
    {
        fprintf(stderr, "gdalmdiminfo failed - unable to open '%s'.\n",
                sOptionsForBinary.osFilename.c_str());
        GDALExit(1);
    }

    char *pszGDALInfoOutput = GDALMultiDimInfo(hDataset, psOptions.get());
    int nRet = pszGDALInfoOutput != nullptr ? 0 : 1;
    CPLFree(pszGDALInfoOutput);

    GDALClose(hDataset);

    GDALDestroy();

    return nRet;
}

MAIN_END