def step8():
 print "Apply gains to the data -"
 print "apply to bandpass calibrator - "+BPname
 applycal(vis=datain+'_'+str(bw)+'.ms',field=str(BP),spw=allspw,
        gaintable=['delays.cal','bandpass.bcal','intphase.gcal','flux.cal'],
        gainfield=[str(BP),str(BP),str(BP),str(BP)])
 print "apply to complex gain calibrator -"+CGname
 applycal(vis=datain+'_'+str(bw)+'.ms',field=str(CG1),spw=allspw,
        gaintable=['delays.cal','bandpass.bcal','intphase.gcal','flux.cal'],
        gainfield=[str(BP),str(BP),str(CG1),str(CG1)])
 applycal(vis=datain+'_'+str(bw)+'.ms',field=str(CG2),spw=allspw,
        gaintable=['delays.cal','bandpass.bcal','intphase.gcal','flux.cal'],
        gainfield=[str(BP),str(BP),str(CG2),str(CG2)])
 applycal(vis=datain+'_'+str(bw)+'.ms',field=str(CG3),spw=allspw,
        gaintable=['delays.cal','bandpass.bcal','intphase.gcal','flux.cal'],
        gainfield=[str(BP),str(BP),str(CG3),str(CG3)])
 print "apply to flux-density calibrator -"+FLname
 applycal(vis=datain+'_'+str(bw)+'.ms',field=str(FL),spw=allspw,
        gaintable=['delays.cal','bandpass.bcal','intphase.gcal','flux.cal'],
        gainfield=[str(BP),str(BP),str(FL),str(FL)])
 print "apply to targets -"+T1name+" & "+T2name
 applycal(vis=datain+'_'+str(bw)+'.ms',field=str(T1)+','+str(T2),spw=allspw,
        gaintable=['delays.cal','bandpass.bcal','scanphase.gcal','flux.cal'],
        gainfield=[str(BP),str(BP),[str(CG2),str(CG3)],[str(CG2),str(CG3)]])
 print "Done with applying gains to the data!"