LCOV - code coverage report
Current view: top level - frmts/envisat - adsrange.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 0 43 0.0 %
Date: 2024-11-21 22:18:42 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  APP ENVISAT Support
       4             :  * Purpose:  Detect range of ADS records matching the MDS records.
       5             :  * Author:   Martin Paces, martin.paces@eox.at
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2013, EOX IT Services, GmbH
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  *****************************************************************************/
      12             : 
      13             : #include "adsrange.hpp"
      14             : #include "timedelta.hpp"
      15             : 
      16             : #include "cpl_string.h"
      17             : 
      18             : CPL_C_START
      19             : #include "EnvisatFile.h"
      20             : #include "records.h"
      21             : CPL_C_END
      22             : 
      23             : #include <cmath>
      24             : 
      25             : /* -------------------------------------------------------------------- */
      26             : /*
      27             :  * data-set descriptor (private helper class)
      28             :  */
      29             : 
      30             : class DataSet
      31             : {
      32             :   public:
      33             :     EnvisatFile &envfile;
      34             :     int index;
      35             :     int nrec;
      36             : 
      37           0 :     DataSet(EnvisatFile &envfileIn, int indexIn)
      38           0 :         : envfile(envfileIn), index(indexIn), nrec(0)
      39             :     {
      40           0 :         EnvisatFile_GetDatasetInfo(&envfileIn, indexIn, nullptr, nullptr,
      41             :                                    nullptr, nullptr, nullptr, &nrec, nullptr);
      42           0 :     }
      43             : 
      44           0 :     TimeDelta getMJD(int ridx)
      45             :     {
      46           0 :         if (ridx < 0)
      47           0 :             ridx += nrec;
      48             : 
      49             :         GUInt32 mjd[3];
      50           0 :         EnvisatFile_ReadDatasetRecordChunk(&envfile, index, ridx, mjd, 0, 12);
      51             : 
      52             : #define INT32(x) ((GInt32)CPL_MSBWORD32(x))
      53             : 
      54           0 :         return TimeDelta(INT32(mjd[0]), INT32(mjd[1]), INT32(mjd[2]));
      55             : 
      56             : #undef INT32
      57             :     }
      58             : 
      59             :   private:
      60             :     CPL_DISALLOW_COPY_ASSIGN(DataSet)
      61             : };
      62             : 
      63             : /* -------------------------------------------------------------------- */
      64             : /*
      65             :  * constructor of the ADSRangeLastAfter object
      66             :  *
      67             :  */
      68             : 
      69           0 : ADSRangeLastAfter::ADSRangeLastAfter(EnvisatFile &envfile, int ads_idx,
      70             :                                      int mds_idx,
      71           0 :                                      const TimeDelta &line_interval)
      72             : {
      73             :     /* abs.time tolerance */
      74           0 :     TimeDelta atol = line_interval * 0.5;
      75             : 
      76             :     /* MDS and ADS descriptor classes */
      77           0 :     DataSet mds(envfile, mds_idx);
      78           0 :     DataSet ads(envfile, ads_idx);
      79             : 
      80             :     /* read the times of the first and last measurements */
      81           0 :     mjd_m_first = mds.getMJD(0); /* MDJ time of the first MDS record */
      82           0 :     mjd_m_last = mds.getMJD(-1); /* MDJ time of the last MDS record */
      83             : 
      84             :     /* look-up the first applicable ADSR */
      85             : 
      86           0 :     int idx = 0;
      87             :     TimeDelta t_mds =
      88           0 :         mjd_m_first + atol;          /*time of the first MDSR + tolerance */
      89           0 :     TimeDelta t_ads = ads.getMJD(0); /*time of the first ADSR */
      90           0 :     TimeDelta t_ads_prev = t_ads;    /* holds previous ADSR */
      91             : 
      92           0 :     if (t_ads < t_mds)
      93             :     {
      94           0 :         for (idx = 1; idx < ads.nrec; ++idx)
      95             :         {
      96           0 :             t_ads = ads.getMJD(idx);
      97             : 
      98           0 :             if (t_ads >= t_mds)
      99           0 :                 break;
     100             : 
     101           0 :             t_ads_prev = t_ads;
     102             :         }
     103             :     }
     104             : 
     105             :     /* store the first applicable ASDR */
     106           0 :     idx_first = idx - 1;    /* sets -1 if no match */
     107           0 :     mjd_first = t_ads_prev; /* set time of the first rec. if no match */
     108             : 
     109             :     /* look-up the last applicable ADSR */
     110             : 
     111           0 :     idx = ads.nrec - 2;
     112           0 :     t_mds = mjd_m_last - atol; /* time of the last MDSR - tolerance */
     113           0 :     t_ads = ads.getMJD(-1);    /* time of the first ADSR */
     114           0 :     t_ads_prev = t_ads;        /* holds previous ADSR */
     115             : 
     116           0 :     if (t_ads > t_mds)
     117             :     {
     118           0 :         for (idx = ads.nrec - 2; idx >= 0; --idx)
     119             :         {
     120           0 :             t_ads = ads.getMJD(idx);
     121             : 
     122           0 :             if (t_ads <= t_mds)
     123           0 :                 break;
     124             : 
     125           0 :             t_ads_prev = t_ads;
     126             :         }
     127             :     }
     128             : 
     129             :     /* store the last applicable ASDR */
     130           0 :     idx_last = idx + 1;    /* sets ads.nrec if no match */
     131           0 :     mjd_last = t_ads_prev; /* set time of the last rec. if no match */
     132             : 
     133             :     /* valuate the line offsets */
     134           0 :     off_first = (int)floor(0.5 + (mjd_m_first - mjd_first) / line_interval);
     135           0 :     off_last = (int)floor(0.5 + (mjd_last - mjd_m_last) / line_interval);
     136           0 : }

Generated by: LCOV version 1.14