LCOV - code coverage report
Current view: top level - frmts/grib - gribdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 25 25 100.0 %
Date: 2024-11-21 22:18:42 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GRIB Driver
       4             :  * Purpose:  GDALDataset driver for GRIB translator for read support
       5             :  * Author:   Bas Retsios, retsios@itc.nl
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2007, ITC
       9             :  * Copyright (c) 2008-2017, Even Rouault <even dot rouault at spatialys dot com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "gribdrivercore.h"
      15             : 
      16             : /************************************************************************/
      17             : /*                     GRIBDriverIdentify()                             */
      18             : /************************************************************************/
      19             : 
      20       54804 : int GRIBDriverIdentify(GDALOpenInfo *poOpenInfo)
      21             : 
      22             : {
      23       54804 :     if (poOpenInfo->nHeaderBytes < 8)
      24       49596 :         return FALSE;
      25             : 
      26        5208 :     const char *pasHeader = reinterpret_cast<char *>(poOpenInfo->pabyHeader);
      27             :     // Does a part of what ReadSECT0(), but in a thread-safe way.
      28     4996410 :     for (int i = 0; i < poOpenInfo->nHeaderBytes - 3; i++)
      29             :     {
      30     4991700 :         if (STARTS_WITH_CI(pasHeader + i, "GRIB")
      31             : #ifdef ENABLE_TDLP
      32             :             || STARTS_WITH_CI(pasHeader + i, "TDLP")
      33             : #endif
      34             :         )
      35         493 :             return TRUE;
      36             :     }
      37             : 
      38        4715 :     return FALSE;
      39             : }
      40             : 
      41             : /************************************************************************/
      42             : /*                     GRIBDriverSetCommonMetadata()                    */
      43             : /************************************************************************/
      44             : 
      45        1293 : void GRIBDriverSetCommonMetadata(GDALDriver *poDriver)
      46             : {
      47        1293 :     poDriver->SetDescription(DRIVER_NAME);
      48        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
      49        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER, "YES");
      50        1293 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME,
      51        1293 :                               "GRIdded Binary (.grb, .grb2)");
      52        1293 :     poDriver->SetMetadataItem(GDAL_DMD_OPENOPTIONLIST,
      53             :                               "<OpenOptionList>"
      54             :                               "    <Option name='USE_IDX' type='boolean' "
      55             :                               "description='Load metadata from "
      56             :                               "wgrib2 index file if available' default='YES'/>"
      57        1293 :                               "</OpenOptionList>");
      58        1293 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/grib.html");
      59        1293 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "grb grb2 grib2");
      60        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
      61             : 
      62        1293 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES,
      63             :                               "Byte UInt16 Int16 UInt32 Int32 Float32 "
      64        1293 :                               "Float64");
      65             : 
      66        1293 :     poDriver->pfnIdentify = GRIBDriverIdentify;
      67        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
      68        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES");
      69        1293 : }
      70             : 
      71             : /************************************************************************/
      72             : /*                    DeclareDeferredGRIBPlugin()                       */
      73             : /************************************************************************/
      74             : 
      75             : #ifdef PLUGIN_FILENAME
      76             : void DeclareDeferredGRIBPlugin()
      77             : {
      78             :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
      79             :     {
      80             :         return;
      81             :     }
      82             :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
      83             : #ifdef PLUGIN_INSTALLATION_MESSAGE
      84             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
      85             :                               PLUGIN_INSTALLATION_MESSAGE);
      86             : #endif
      87             :     GRIBDriverSetCommonMetadata(poDriver);
      88             :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
      89             : }
      90             : #endif

Generated by: LCOV version 1.14