File: instrumentStarCameraMultiply.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 (119 lines) | stat: -rw-r--r-- 3,862 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/***********************************************/
/**
* @file instrumentStarCameraMultiply.cpp
*
* @brief Mutiply instrument data with a factor and add them together.
*
* @author Torsten Mayer-Guerr
* @date 2012-06-24
*
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
This program applies several rotations given by \configFile{inputfileStarCamera}{instrument}.
The resulting rotation is written as \configFile{outputfileStarCamera}{instrument}.
All instrument files must be synchronized (\program{InstrumentSynchronize}).
)";

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

#include "programs/program.h"
#include "files/fileInstrument.h"

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

/** @brief Mutiply instrument data with a factor and add them together.
* @ingroup programsGroup */
class InstrumentStarCameraMultiply
{
public:
  class Data
  {
    public:
    FileName fileName;
    Bool     inverse;
  };

  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(InstrumentStarCameraMultiply, SINGLEPROCESS, "Mutiply instrument data with a factor and add them together", Instrument)

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

template<> Bool readConfig(Config &config, const std::string &name, InstrumentStarCameraMultiply::Data &var, Config::Appearance mustSet, const std::string &defaultValue, const std::string &annotation)
{
  if(!readConfigSequence(config, name, mustSet, defaultValue, annotation))
    return FALSE;
  readConfig(config, "inputfileStarCamera", var.fileName, Config::MUSTSET,  "", "");
  readConfig(config, "inverse",             var.inverse,  Config::DEFAULT,  "0", "");
  endSequence(config);
  return TRUE;
}

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

void InstrumentStarCameraMultiply::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
  try
  {
    FileName outName;
    std::vector<Data> data;

    readConfig(config, "outputfileStarCamera", outName, Config::MUSTSET,  "", "");
    readConfig(config, "instrument",           data,    Config::MUSTSET,  "", "");
    if(isCreateSchema(config)) return;

    std::vector<InstrumentFilePtr> instrumentFile;
    instrumentFile.resize(data.size());
    for(UInt i=0; i<instrumentFile.size(); i++)
      instrumentFile.at(i) = InstrumentFile::newFile(data.at(i).fileName);
    for(UInt i=1; i<instrumentFile.size(); i++)
      InstrumentFile::checkArcCount({*instrumentFile.at(0), *instrumentFile.at(i)});

    // read data
    // ---------
    logStatus<<"read starCamera data"<<Log::endl;
    UInt arcCount = instrumentFile.at(0)->arcCount();
    std::vector<Arc> arcList;

    Single::forEach(arcCount, [&](UInt arcNo)
    {
      StarCameraArc starCamera = instrumentFile.at(0)->readArc(arcNo);
      UInt epochCount = starCamera.size();
      if(data.at(0).inverse)
        for(UInt k=0; k<epochCount; k++)
          starCamera.at(k).rotary = inverse(starCamera.at(k).rotary);

      for(UInt i=1; i<instrumentFile.size(); i++)
      {
        StarCameraArc starCamera2 = instrumentFile.at(i)->readArc(arcNo);
        Arc::checkSynchronized({starCamera, starCamera2});
        for(UInt k=0; k<epochCount; k++)
        {
          if(data.at(i).inverse)
            starCamera.at(k).rotary = starCamera.at(k).rotary * inverse(starCamera2.at(k).rotary);
          else
            starCamera.at(k).rotary = starCamera.at(k).rotary * starCamera2.at(k).rotary;
        }
      }
      arcList.push_back(starCamera);
    });

    // save file
    // ---------
    logStatus<<"write instrument data to file <"<<outName<<">"<<Log::endl;
    InstrumentFile::write(outName, arcList);

    Arc::printStatistics(arcList);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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