File: votab.cpp

package info (click to toggle)
munipack 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 33,104 kB
  • sloc: cpp: 29,677; sh: 4,909; f90: 2,872; makefile: 278; python: 140; xml: 72; awk: 12
file content (187 lines) | stat: -rw-r--r-- 4,173 bytes parent folder | download | duplicates (4)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*

  VOTable convertor

  Copyright © 2010 - 2013, 2017-8 F.Hroch (hroch@physics.muni.cz)

  This file is part of Munipack.

  Munipack is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Munipack is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Munipack.  If not, see <http://www.gnu.org/licenses/>.


  Reference:

  http://www.ivoa.net/Documents/VOTable/20091130/REC-VOTable-1.2.html

*/

#include "votable.h"
#include <wx/wx.h>
#include <wx/app.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
#include <cstdio>

using namespace std;

class VOTab: public wxAppConsole
{
public:
  bool OnInit();
  int OnRun();
private:
  wxString vooper();
};

IMPLEMENT_APP_CONSOLE(VOTab)

bool VOTab::OnInit()
{
  wxLog::DisableTimestamp();
  return true;
}

int VOTab::OnRun()
{
  wxString msg = vooper();

  // Looks strangle? See: cone.cpp.
  if( msg == "" )
    fprintf(stderr,"STOP 0\n");
  else
    fprintf(stderr,"STOP '%s'\n",static_cast<const char *>(msg.c_str()));
  return msg != "";
}


wxString VOTab::vooper()
{
  wxString output, type, file;
  wxString pt, mk, ak, dk;
  double pa, pd, ps, ml;
  long pw = -1, ph = -1;

  // limit logging
  wxLog::SetLogLevel(wxLOG_Message);
  wxLog::SetVerbose(); // important to activate previous setup

  wxFFileInputStream pstream(stdin);
  wxTextInputStream input(pstream);

  while(pstream.IsOk() && ! pstream.Eof()) {

    wxString line = input.ReadLine();

    if( line.StartsWith("VERBOSE") ) {
      if( GetBool(line) )
	wxLog::SetLogLevel(wxLOG_Debug);
      else
	wxLog::SetLogLevel(wxLOG_Message);
      wxLog::SetVerbose(); // important to activate previous setup
    }

    if( line.StartsWith("TYPE") )
      type = GetString(line);

    if( line.StartsWith("FILE") )
      file = GetString(line);

    if( line.StartsWith("PROJ TYPE") )
      pt = GetString(line);

    if( line.StartsWith("PROJ ALPHA") )
      pa = GetDouble(line);

    if( line.StartsWith("PROJ DELTA") )
      pd = GetDouble(line);

    if( line.StartsWith("PROJ SCALE") )
      ps = GetDouble(line);

    if( line.StartsWith("PROJ WIDTH") )
      pw = GetLong(line);

    if( line.StartsWith("PROJ HEIGHT") )
      ph = GetLong(line);

    if( line.StartsWith("MAG LIMIT") )
      ml = GetDouble(line);

    if( line.StartsWith("COL_RA") )
      ak = GetString(line);

    if( line.StartsWith("COL_DEC") )
      dk = GetString(line);

    if( line.StartsWith("COL_MAG") )
      mk = GetString(line);

    if( line.StartsWith("OUTPUT") )
      output = GetString(line);

  }


  if( type == "FITS" && ! output.IsEmpty() ) {
    FITStable vt(file);
    return vt.Save(output,true) ? "" : "FITS save failed.";
  }

  wxFFile ffile;
  if( output.IsEmpty() )
    ffile.Attach(stdout);
  else
    ffile.Open(output.c_str(),"w");

  if( ! ffile.IsOpened() )
    return "Failed to create or open `"+output+"'.";

  wxFFileOutputStream ostream(ffile);
  if( ! ostream.IsOk() )
    return "Failed to initialise an output stream.";

  if( type.IsEmpty() || type == "XML" ) {
    VOTable vt(file);
    return vt.Save(ostream) ? "" : "XML save failed.";
  }

  else if( type == "CSV" ) {
    CSVtable vt(file);
    return vt.Save(ostream) ? "" : "CSV save failed.";
  }

  else if( type == "TXT" ) {
    TXTable vt(file);
    return vt.Save(ostream) ? "" : "Text save failed.";
  }
  else if( type == "SVG" ) {
    SVGcanvas vt(file);

    vt.SetProjection(pt);
    vt.SetProjectionCenter(pa,pd);
    vt.SetScale(ps);
    vt.SetMaglim(ml);
    vt.SetMagkey(mk);
    vt.SetAlphakey(ak);
    vt.SetDeltakey(dk);
    if( pw > 0 && ph > 0 )
      vt.SetCanvasSize(pw,ph);

    return vt.Save(ostream) ? "" : "SVG save failed.";
  }
  else
    return "Type `"+type+"' unrecognized.";

  return "Votable failed.";
}