-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfratio_slave.cpp
96 lines (85 loc) · 3.53 KB
/
fratio_slave.cpp
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
#include "data.h"
#include "cmd_slave.h"
#include <fstream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <sagecal.h>
#include "utils.h"
#include "utils_dn.h"
using namespace std;
using namespace Data;
int fratio_slave(dlg_app_info *app) {
/*-----------------------------------------------input------------------------------------------------------------*/
Data::IOData iodata;
Data::LBeam beam;
Data::MPIData mpiData;
int sources_precessed = get_last_iter(app->uid);
openblas_set_num_threads(1);
load_iodata_dn(&(app->inputs[0]), &iodata);
load_share_mpidata(Data::shareDir, &mpiData);
cout << "[fratio_slave]========, iodata.N/M/Mt/Nms:" << iodata.N << "/" << iodata.M << "/" << iodata.Mt << "/" << iodata.Nms
<< ", iodata.freq0:" << iodata.freq0/ 1e6<< "Mhz,msname:" << iodata.msname << "," << endl;
if (Data::doBeam) {
load_share_beam(Data::shareDir,iodata.msname, &beam);
}
/*----------------------------------------------------------------------------------------------------------------*/
Block<int> sort(1);
sort[0] = MS::TIME; /* note: only sort over TIME for ms iterator to work */
vector < MSIter * > msitr;
vector < MeasurementSet * > msvector;
MeasurementSet *ms = new MeasurementSet(iodata.msname, Table::Update);
MSIter *mi = new MSIter(*ms, sort, iodata.deltat * (double) iodata.tilesz);
msitr.push_back(mi);
msvector.push_back(ms);
for (int cm = 0; cm < iodata.Nms; cm++) {
msitr[cm]->origin();
}
if(sources_precessed!=0) {
if (!Data::doBeam) {
Data::loadData(msitr[0]->table(), iodata, &iodata.fratio);
} else {
Data::loadData(msitr[0]->table(), iodata, beam, &iodata.fratio);
}
Data::writeData(msitr[0]->table(), iodata);
/* advance to next data chunk */
for (int cm = 0; cm < iodata.Nms; cm++) {
for(int it=0;it<sources_precessed;it++)
(*msitr[cm])++;
}
} else {
if (!Data::doBeam) {
Data::loadData(msitr[0]->table(), iodata, &iodata.fratio);
} else {
Data::loadData(msitr[0]->table(), iodata, beam, &iodata.fratio);
}
}
/*----------------------------------------------------------------------------------------------------------------*/
/* downweight factor for regularization, depending on amount of data flagged,
0.0 means all data are flagged */
iodata.fratio = 1.0 - iodata.fratio;
if (Data::verbose) {
cout << iodata.msname << ": downweight ratio (" << iodata.fratio << ") based on flags." << endl;
}
/*----------------------------------------share output------------------------------------------------------------*/
dump_share_iodata(Data::shareDir,iodata.msname,&iodata);
if (Data::doBeam) {
dump_share_beam(Data::shareDir,iodata.msname,&iodata,&beam);
}
/*-------------------------------------output---------------------------------------------------------------------*/
dump_iodata_dn(&(app->outputs[0]), &iodata);
dump_mpidata_dn(&(app->outputs[0]), &mpiData);
/*------------------------------------free ----------------------------------------------------------------------*/
for (int cm = 0; cm < iodata.Nms; cm++) {
delete msitr[cm];
delete msvector[cm];
}
if (!doBeam) {
Data::freeData(iodata);
} else {
Data::freeData(iodata, beam);
}
delete[] mpiData.freqs;
cout << "[fratio_slave]========, Done." << endl;
return 0;
}