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-04-29 17:29:47 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             :  * Permission is hereby granted, free of charge, to any person obtaining a
      12             :  * copy of this software and associated documentation files (the "Software"),
      13             :  * to deal in the Software without restriction, including without limitation
      14             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15             :  * and/or sell copies of the Software, and to permit persons to whom the
      16             :  * Software is furnished to do so, subject to the following conditions:
      17             :  *
      18             :  * The above copyright notice and this permission notice shall be included
      19             :  * in all copies or substantial portions of the Software.
      20             :  *
      21             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27             :  * DEALINGS IN THE SOFTWARE.
      28             :  ****************************************************************************/
      29             : 
      30             : #include "gribdrivercore.h"
      31             : 
      32             : /************************************************************************/
      33             : /*                     GRIBDriverIdentify()                             */
      34             : /************************************************************************/
      35             : 
      36       52007 : int GRIBDriverIdentify(GDALOpenInfo *poOpenInfo)
      37             : 
      38             : {
      39       52007 :     if (poOpenInfo->nHeaderBytes < 8)
      40       47017 :         return FALSE;
      41             : 
      42        4990 :     const char *pasHeader = reinterpret_cast<char *>(poOpenInfo->pabyHeader);
      43             :     // Does a part of what ReadSECT0(), but in a thread-safe way.
      44     4814940 :     for (int i = 0; i < poOpenInfo->nHeaderBytes - 3; i++)
      45             :     {
      46     4810440 :         if (STARTS_WITH_CI(pasHeader + i, "GRIB")
      47             : #ifdef ENABLE_TDLP
      48             :             || STARTS_WITH_CI(pasHeader + i, "TDLP")
      49             : #endif
      50             :         )
      51         481 :             return TRUE;
      52             :     }
      53             : 
      54        4509 :     return FALSE;
      55             : }
      56             : 
      57             : /************************************************************************/
      58             : /*                     GRIBDriverSetCommonMetadata()                    */
      59             : /************************************************************************/
      60             : 
      61        1217 : void GRIBDriverSetCommonMetadata(GDALDriver *poDriver)
      62             : {
      63        1217 :     poDriver->SetDescription(DRIVER_NAME);
      64        1217 :     poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
      65        1217 :     poDriver->SetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER, "YES");
      66        1217 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME,
      67        1217 :                               "GRIdded Binary (.grb, .grb2)");
      68        1217 :     poDriver->SetMetadataItem(GDAL_DMD_OPENOPTIONLIST,
      69             :                               "<OpenOptionList>"
      70             :                               "    <Option name='USE_IDX' type='boolean' "
      71             :                               "description='Load metadata from "
      72             :                               "wgrib2 index file if available' default='YES'/>"
      73        1217 :                               "</OpenOptionList>");
      74        1217 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/grib.html");
      75        1217 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "grb grb2 grib2");
      76        1217 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
      77             : 
      78        1217 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES,
      79             :                               "Byte UInt16 Int16 UInt32 Int32 Float32 "
      80        1217 :                               "Float64");
      81             : 
      82        1217 :     poDriver->pfnIdentify = GRIBDriverIdentify;
      83        1217 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
      84        1217 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES");
      85        1217 : }
      86             : 
      87             : /************************************************************************/
      88             : /*                    DeclareDeferredGRIBPlugin()                       */
      89             : /************************************************************************/
      90             : 
      91             : #ifdef PLUGIN_FILENAME
      92             : void DeclareDeferredGRIBPlugin()
      93             : {
      94             :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
      95             :     {
      96             :         return;
      97             :     }
      98             :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
      99             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     100             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     101             :                               PLUGIN_INSTALLATION_MESSAGE);
     102             : #endif
     103             :     GRIBDriverSetCommonMetadata(poDriver);
     104             :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     105             : }
     106             : #endif

Generated by: LCOV version 1.14