dbl_pos_sw_cal := function(msname,scana,scanb,minint=F,maxint=F,plotem=F, ifnum=1) { # which bank bank := "Z"; if (ifnum==1) bank := "A"; if (ifnum==2) bank := "B"; if (ifnum==3) bank := "C"; if (ifnum==4) bank := "D"; # open the measurement set d.open(msname); t := table(msname,readonly=F); # get range of integrations to do ints := d.qscan(scana).ints; if (is_boolean(minint)) minint := 1; if (is_boolean(maxint)) maxint := ints; if (maxint > ints) maxint := ints; # remove flags from the data print "Removing all flags from data..."; d.flag(scana,[minint:maxint],flag=F); print "1..."; d.flag(scanb,[minint:maxint],flag=F); print "2..."; d.flag(scana+1,[minint:maxint],flag=F); print "3..."; d.flag(scanb+1,[minint:maxint],flag=F); print "4..."; for (k in minint:maxint) { # get the data for the target source target_on_cal_off := d.getr(scana,1,int=k,nif=ifnum).data.arr; target_on_cal_on := d.getr(scana,2,int=k,nif=ifnum).data.arr; target_off_cal_off := d.getr(scana+1,1,int=k,nif=ifnum).data.arr; target_off_cal_on := d.getr(scana+1,2,int=k,nif=ifnum).data.arr; # See Arecibo memo by Salter and Ghosh on double position switching # now calculate (on-off) target_onoff_cal_off := (target_on_cal_off-target_off_cal_off); target_onoff_cal_on := (target_on_cal_on -target_off_cal_on ); # get the data for the continuum source continuum_on_cal_off := d.getr(scanb,1,int=k,nif=ifnum).data.arr; continuum_on_cal_on := d.getr(scanb,2,int=k,nif=ifnum).data.arr; continuum_off_cal_off := d.getr(scanb+1,1,int=k,nif=ifnum).data.arr; continuum_off_cal_on := d.getr(scanb+1,2,int=k,nif=ifnum).data.arr; # now calculate (on-off)/off continuum_onoff_cal_off :=(continuum_on_cal_off-continuum_off_cal_off); continuum_onoff_cal_on :=(continuum_on_cal_on -continuum_off_cal_on ); # now ratio of (on-off) for target and continuum sources ratio_cal_off := target_onoff_cal_off / continuum_onoff_cal_off; ratio_cal_on := target_onoff_cal_on / continuum_onoff_cal_on ; # put the data back into the measurement set rows := t.getcol('SCAN_NUMBER'); gbtbank := t.getcol('GBT_BANK'); counta := 0; countb := 0; for (i in 1:len(rows)) { if (gbtbank[i] == bank) { if (rows[i] == scana || rows[i] == scana+1) { # found row counta +:= 1; if (counta == 2*k-1 || counta == 2*k) { ans := t.putcell('CORRECTED_DATA',i,ratio_cal_off); } } if( rows[i] == scanb || rows[i] == scanb+1) { countb +:=1; if (countb == 2*k-1 || countb == 2*k) { ans := t.putcell('CORRECTED_DATA',i,ratio_cal_on); } } } } # plot the data if (plotem) { d.plotc(scana,k,pol=1); # d.plotc(scanb,k); } printf('%d/%d..',k,maxint); } print ' '; # close the measurement set d.close(msname); t.done(); }