LCOV - code coverage report
Current view: top level - apps - gdalmdiminfo_bin.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 39 50 78.0 %
Date: 2024-05-03 15:49:35 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL Utilities
       4             :  * Purpose:  Command line application to list info about a multidimensional
       5             :  *raster Author:   Even Rouault,<even.rouault at spatialys.com>
       6             :  *
       7             :  * ****************************************************************************
       8             :  * Copyright (c) 2019, Even Rouault <even.rouault at spatialys.com>
       9             :  *
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #include "gdal_version.h"
      30             : #include "gdal.h"
      31             : #include "cpl_string.h"
      32             : #include "cpl_multiproc.h"
      33             : #include "commonutils.h"
      34             : #include "gdal_utils_priv.h"
      35             : 
      36             : /************************************************************************/
      37             : /*                               Usage()                                */
      38             : /************************************************************************/
      39             : 
      40           0 : static void Usage(bool bIsError, const char *pszErrorMsg = nullptr)
      41             : 
      42             : {
      43           0 :     fprintf(
      44             :         bIsError ? stderr : stdout,
      45             :         "Usage: gdalmdiminfo [--help] [--help-general]\n"
      46             :         "                    [-oo <NAME>=<VALUE>]... [-arrayoption "
      47             :         "<NAME>=<VALUE>]...\n"
      48             :         "                    [-detailed] [-nopretty] [-array <array_name>]\n"
      49             :         "                    [-limit <number>] [-stats] [-if <format>]...\n"
      50             :         "                    <datasetname>\n");
      51             : 
      52           0 :     if (pszErrorMsg != nullptr)
      53           0 :         fprintf(stderr, "\nFAILURE: %s\n", pszErrorMsg);
      54             : 
      55           0 :     exit(bIsError ? 1 : 0);
      56             : }
      57             : 
      58             : /************************************************************************/
      59             : /*                                main()                                */
      60             : /************************************************************************/
      61             : 
      62           4 : MAIN_START(argc, argv)
      63             : 
      64             : {
      65           4 :     EarlySetConfigOptions(argc, argv);
      66             : 
      67           4 :     GDALAllRegister();
      68             : 
      69           4 :     argc = GDALGeneralCmdLineProcessor(argc, &argv, 0);
      70           4 :     if (argc < 1)
      71           0 :         exit(-argc);
      72             : 
      73          15 :     for (int i = 0; argv != nullptr && argv[i] != nullptr; i++)
      74             :     {
      75          12 :         if (EQUAL(argv[i], "--utility_version"))
      76             :         {
      77           1 :             printf("%s was compiled against GDAL %s and is running against "
      78             :                    "GDAL %s\n",
      79             :                    argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME"));
      80           1 :             CSLDestroy(argv);
      81           1 :             return 0;
      82             :         }
      83          11 :         else if (EQUAL(argv[i], "--help"))
      84             :         {
      85           0 :             Usage(false);
      86             :         }
      87             :     }
      88           3 :     argv = CSLAddString(argv, "-stdout");
      89             : 
      90           3 :     GDALMultiDimInfoOptionsForBinary sOptionsForBinary;
      91             : 
      92             :     GDALMultiDimInfoOptions *psOptions =
      93           3 :         GDALMultiDimInfoOptionsNew(argv + 1, &sOptionsForBinary);
      94           3 :     if (psOptions == nullptr)
      95           0 :         Usage(true);
      96             : 
      97           3 :     if (sOptionsForBinary.osFilename.empty())
      98           0 :         Usage(true, "No datasource specified.");
      99             : 
     100             :     GDALDatasetH hDataset =
     101           3 :         GDALOpenEx(sOptionsForBinary.osFilename.c_str(),
     102             :                    GDAL_OF_MULTIDIM_RASTER | GDAL_OF_VERBOSE_ERROR,
     103           3 :                    sOptionsForBinary.aosAllowInputDrivers.List(),
     104           3 :                    sOptionsForBinary.aosOpenOptions.List(), nullptr);
     105           3 :     if (!hDataset)
     106             :     {
     107           1 :         fprintf(stderr, "gdalmdiminfo failed - unable to open '%s'.\n",
     108             :                 sOptionsForBinary.osFilename.c_str());
     109             : 
     110           1 :         GDALMultiDimInfoOptionsFree(psOptions);
     111             : 
     112           1 :         CSLDestroy(argv);
     113             : 
     114           1 :         GDALDumpOpenDatasets(stderr);
     115             : 
     116           1 :         GDALDestroyDriverManager();
     117             : 
     118           1 :         CPLDumpSharedList(nullptr);
     119           1 :         CPLCleanupTLS();
     120           1 :         exit(1);
     121             :     }
     122             : 
     123           2 :     char *pszGDALInfoOutput = GDALMultiDimInfo(hDataset, psOptions);
     124             : 
     125           2 :     if (pszGDALInfoOutput)
     126           0 :         printf("%s", pszGDALInfoOutput);
     127             : 
     128           2 :     CPLFree(pszGDALInfoOutput);
     129             : 
     130           2 :     GDALClose(hDataset);
     131             : 
     132           2 :     GDALMultiDimInfoOptionsFree(psOptions);
     133             : 
     134           2 :     CSLDestroy(argv);
     135             : 
     136           2 :     GDALDumpOpenDatasets(stderr);
     137             : 
     138           2 :     GDALDestroyDriverManager();
     139             : 
     140           2 :     CPLDumpSharedList(nullptr);
     141           2 :     CPLCleanupTLS();
     142             : 
     143           2 :     exit(0);
     144             : }
     145             : 
     146           0 : MAIN_END

Generated by: LCOV version 1.14