# this works for 8 spectral window frequency switched data # some rows may get the same flags set multiple times here, but thats okay # it was easier to be lazy and do that that to work out when it had # already set and when it still needed to be set. # it should be harmless to run this multiple times - the same rows will # simply be re-flagged each time. include 'table.g'; flagIt := function(myMSname) { print 'opening MS:',myMSname; mainTab := table(myMSname,readonly=F); mt := mainTab.getcol('TIME'); md := mainTab.getcol('DATA_DESC_ID'); print 'finding previously flagged data ...'; flaggedTab := mainTab.query('ANY(FLAG)'); print flaggedTab.nrows(),'flagged rows found'; for (i in 1:flaggedTab.nrows()) { thisTime := flaggedTab.getcell('TIME',i); thisDD := flaggedTab.getcell('DATA_DESC_ID',i); # also flag the freq. switched DD_ID corresponding to thisDD if (thisDD == 0) otherDD := 1; if (thisDD == 1) otherDD := 0; if (thisDD == 2) otherDD := 3; if (thisDD == 3) otherDD := 2; if (thisDD == 4) otherDD := 5; if (thisDD == 5) otherDD := 4; if (thisDD == 6) otherDD := 7; if (thisDD == 7) otherDD := 6; rowsToFlag := ind(mt)[mt==thisTime & (md==thisDD | md==otherDD)]; if (is_fail(rowsToFlag)) return rowsToFlag; print 'flagging DD_ID pairs', thisDD, otherDD, 'at rows', rowsToFlag,'in scan', flaggedTab.getcell('SCAN_NUMBER',i), 'at',flaggedTab.getcell('TIME',i); flag := mainTab.getcell('FLAG',rowsToFlag[1]); if (is_fail(flag)) return flag; if (len(rowsToFlag) > 1) { for (j in 2:len(rowsToFlag)) { flag := flag | mainTab.getcell('FLAG',rowsToFlag[j]); if (is_fail(flag)) return flag; } } for (row in rowsToFlag) { ok := mainTab.putcell('FLAG',row,flag); if (is_fail(ok)) return ok; } } mainTab.done(); flaggedTab.done(); }