File: graceL1b2Vector.cpp

package info (click to toggle)
groops 0%2Bgit20250907%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 11,140 kB
  • sloc: cpp: 135,607; fortran: 1,603; makefile: 20
file content (91 lines) | stat: -rw-r--r-- 2,647 bytes parent folder | download | duplicates (2)
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
/***********************************************/
/**
* @file graceL1b2Vector.cpp
*
* @brief Read GRACE L1B data.
*
* @author Torsten Mayer-Guerr
* @date 2005-01-19
*
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
This program reads vector orientation data (positions of instruments in the satellite frame) from the GRACE SDS format
(VGB1B, VGN1B, VGO1B, VKB1B, or VCM1B).
The \configFile{outputfileVector}{matrix} is a $(3n\times1)$ matrix containing $(x,y,z)$ for each record.
The GRACE SDS format is described in "GRACE Level 1B Data Product User Handbook JPL D-22027"
given at \url{http://podaac.jpl.nasa.gov/grace/documentation.html}.
)";

/***********************************************/

#include "programs/program.h"
#include "files/fileMatrix.h"
#include "fileGrace.h"

/***** CLASS ***********************************/

/** @brief Read GRACE L1B data.
* @ingroup programsConversionGroup */
class GraceL1b2Vector
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(GraceL1b2Vector, SINGLEPROCESS, "read GRACE L1B data (VGB1B, VGN1B, VGO1B, VKB1B, or VCM1B)", Conversion, Grace, Matrix)

/***********************************************/

void GraceL1b2Vector::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
  try
  {
    FileName fileNameOut, fileNameIn;

    readConfig(config, "outputfileVector", fileNameOut, Config::MUSTSET,  "", "");
    readConfig(config, "inputfile",        fileNameIn,  Config::MUSTSET,  "", "VGB1B, VGN1B, VGO1B, VKB1B, or VCM1B");
    if(isCreateSchema(config)) return;

    // =============================================

    logStatus<<"read file <"<<fileNameIn<<">"<<Log::endl;
    UInt numberOfRecords;
    FileInGrace file(fileNameIn, numberOfRecords);

    Vector vec(3*numberOfRecords);

    for(UInt i=0; i<numberOfRecords; i++)
    {
      Int32    seconds;
      Char     GRACE_id;
      Double   mag, x, y, z;
      Byte     qualflg;

      file>>seconds>>GRACE_id>>mag>>x>>y>>z>>FileInGrace::flag(qualflg);

      const Time time = mjd2time(51544.5) + seconds2time(seconds);
      logInfo<<time.dateTimeStr()<<", flag = "<<Int(qualflg)<<Log::endl;
      vec(3*i+0) = mag*x;
      vec(3*i+1) = mag*y;
      vec(3*i+2) = mag*z;
    }

    // =============================================

    if(!fileNameOut.empty())
    {
      logInfo<<"write data to <"<<fileNameOut<<">"<<Log::endl;
      writeFileMatrix(fileNameOut, vec);
    }
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/