1 | #include <tables/Tables/Table.h>
|
---|
2 | #include <tables/Tables/ScaColDesc.h>
|
---|
3 | #include <tables/Tables/ArrColDesc.h>
|
---|
4 | #include <tables/Tables/ArrayColumn.h>
|
---|
5 |
|
---|
6 | #include "STUpgrade.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | using namespace casa;
|
---|
10 |
|
---|
11 | namespace asap {
|
---|
12 |
|
---|
13 | std::string STUpgrade::upgrade(const std::string& name) {
|
---|
14 | std::string inname = name;
|
---|
15 | Table origtab(name);
|
---|
16 | uInt version = origtab.keywordSet().asuInt("VERSION");
|
---|
17 | if (version == version_) {
|
---|
18 | return name;
|
---|
19 | }
|
---|
20 | if (version == 2) {
|
---|
21 | inname = two2three(inname);
|
---|
22 | version = 3;
|
---|
23 | }
|
---|
24 | if (version == 3) {
|
---|
25 | return three2four(inname);
|
---|
26 | }
|
---|
27 | throw(AipsError("Unsupported version of ASAP file."));
|
---|
28 | }
|
---|
29 |
|
---|
30 | std::string STUpgrade::two2three(const std::string& name) {
|
---|
31 |
|
---|
32 | std::string fname = name+".asap3";
|
---|
33 | Table origtab(name);
|
---|
34 | origtab.deepCopy(fname, Table::New);
|
---|
35 | Table tab(fname, Table::Update);
|
---|
36 | tab.removeColumn("PARANGLE");
|
---|
37 | Table tfocus = tab.rwKeywordSet().asTable("FOCUS");
|
---|
38 | ScalarColumnDesc<Float> pa("PARANGLE");
|
---|
39 | pa.setDefault(Float(0.0));
|
---|
40 | tfocus.addColumn(pa);
|
---|
41 | //tfocus.rwKeywordSet().define("PARALLACTIFY", False)
|
---|
42 | Int verid = tab.rwKeywordSet().fieldNumber("VERSION");
|
---|
43 | tab.rwKeywordSet().define(verid, uInt(3));
|
---|
44 | tab.tableInfo().setType("Scantable");
|
---|
45 | return fname;
|
---|
46 | }
|
---|
47 |
|
---|
48 | std::string STUpgrade::three2four(const std::string& name) {
|
---|
49 | std::string fname = name;
|
---|
50 | Table origtab(name);
|
---|
51 | Vector<String> cnames(3);
|
---|
52 | cnames[0] = "RESTFREQUENCY";
|
---|
53 | cnames[1] = "NAME";
|
---|
54 | cnames[2] = "FORMATTEDNAME";
|
---|
55 | Table origmoltab = origtab.rwKeywordSet().asTable("MOLECULES");
|
---|
56 | const ColumnDesc &desc = (origmoltab.tableDesc().columnDescSet())[cnames[0]];
|
---|
57 | Bool isScalar = desc.isScalar() ;
|
---|
58 | if ( isScalar ) {
|
---|
59 | fname += ".asap4";
|
---|
60 | origtab.deepCopy(fname, Table::New);
|
---|
61 | Table tab(fname, Table::Update);
|
---|
62 | Table moltable = tab.rwKeywordSet().asTable("MOLECULES");
|
---|
63 | ROScalarColumn<Double> rfcol(moltable, cnames[0]);
|
---|
64 | ROScalarColumn<String> nmecol(moltable, cnames[1]);
|
---|
65 | ROScalarColumn<String> fmtnmecol(moltable, cnames[2]);
|
---|
66 | Vector<Double> rf = rfcol.getColumn();
|
---|
67 | Vector<String> nme = nmecol.getColumn();
|
---|
68 | Vector<String> fmtnme = fmtnmecol.getColumn();
|
---|
69 | Array<Double> arf = rf.addDegenerate(1);
|
---|
70 | Array<String> anme = nme.addDegenerate(1);
|
---|
71 | Array<String> afmtnme = fmtnme.addDegenerate(1);
|
---|
72 | moltable.removeColumn(cnames);
|
---|
73 | moltable.addColumn(ArrayColumnDesc<Double>(cnames[0]));
|
---|
74 | moltable.addColumn(ArrayColumnDesc<String>(cnames[1]));
|
---|
75 | moltable.addColumn(ArrayColumnDesc<String>(cnames[2]));
|
---|
76 | ArrayColumn<Double> arfcol(moltable, cnames[0]);
|
---|
77 | ArrayColumn<String> anmecol(moltable, cnames[1]);
|
---|
78 | ArrayColumn<String> afmtnmecol(moltable, cnames[2] );
|
---|
79 | arfcol.putColumn(arf);
|
---|
80 | anmecol.putColumn(anme);
|
---|
81 | afmtnmecol.putColumn(afmtnme);
|
---|
82 | Int verid = tab.rwKeywordSet().fieldNumber("VERSION");
|
---|
83 | tab.rwKeywordSet().define(verid, uInt(4));
|
---|
84 | }
|
---|
85 | else {
|
---|
86 | Int verid = origtab.rwKeywordSet().fieldNumber("VERSION");
|
---|
87 | origtab.rwKeywordSet().define(verid, uInt(4));
|
---|
88 | }
|
---|
89 | return fname;
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|