parameter start end noflat gainnorm !unalias rd !unalias wd ! Subroutine procedure to do PICCRS. Calling routine should set the following ! variables: !string title '30 Dor' !string name '30dor' !string filt 'F547M' !string lfilt 'f547m' ! ! File {lfilt}.inp should exist with list of root file names, exposure times ! !variable outtime should be set with the desired output exposure time - ! this time will be loaded into header card EXPTIME !cards GAIN and RN will be loaded with calculated gain and readnoise ! Get the exposure times into variables t%i2.2 open input ./{name}{lfilt}.inp stat n=count[input] do jpic=1,n string var 't%i2.2' jpic read input {var}=@input.2 string var 'b%i2.2' jpic {var}=0 err continue string svar 'sky%i2.2' jpic {var}={svar} end_do close input tottime=0 totrn=0 open input ./{name}{lfilt}.inp do jpic=1,n string fname {input} if noflat==1 string file '{fname}%i1' start else string file 'e{fname}%i1' start end_if rd 1 {file} headonly {pictype} rn=6 tottime=tottime+{?1:exptime} totrn=totrn+({?1:exptime}/rn)^2 end_do close input ! Loop over each chip do ipic=start,end open input ./{name}{lfilt}.inp do jpic=1,n string fname {input} if noflat==1 string file '{fname}%i1' start else string file 'e{fname}%i1' start end_if rd 1 {file} headonly {pictype} if wfpc==1 call wfpcgain 1 ipic end_if gainpic=gain if jpic==1 gainpic0=gainpic end_if end_do close input if ipic==1 string flat 'wfpc2cal/flats/iflat_{filt}_pc%i1' ipic else string flat 'wfpc2cal/flats/iflat_{filt}_wf%i1' ipic end_if if noflat~=1 rd 94 {flat} box 9 nr=1 sr=800 nc=800 sc=1 div 94 94 box=9 end_if if darkmask==1 ! string dark 'wfpc2cal/sdark/sdark_{sdark}_%i1' ipic ! rd 97 {dark} string dark 'wfpc2cal/sdark/{dark1}_%i1' ipic rd 98 {dark} string dark 'wfpc2cal/sdark/{dark2}_%i1' ipic rd 99 {dark} ! sub 98 97 ! sub 99 97 unmask clip 99 min=-0.002 maskonly clip 99 max=0.002 maskonly clip 98 min=-0.002 maskonly clip 98 max=0.002 maskonly save mask=/usr/tmp/darkbad end_if ! Create input file for PICCRS open input ./{name}{lfilt}.inp $'rm' piccrs.inp do jpic=1,n string var 't%i2.2' jpic string bvar 'b%i2.2' jpic string fname {input} if noflat==1 string file '{fname}%i1' ipic else string file 'e{fname}%i1' ipic end_if string zfile '{prefix}{fname}%i1' ipic printf '{file} %2f12.4 {zfile}' {var} {bvar} >>./piccrs.inp end_do close input printf 'Output gain: %f12.4 rn: %f12.4' gainpic0*tottime/outtime | tottime/sqrt[totrn] ! Combine frames piccrs $ipic list=./piccrs.inp gain=gain rn=6 min=lowbad bsat=maxbad {pictype} | sig=95 n=96 f=fval unmask clip $ipic min=-99 maskonly ! Flatten if noflat~=1 mul $ipic 94 end_if ! Normalize to desired exposure time and gain mul $ipic c=outtime if gainnorm>0 mul $ipic c=gainpic0/gainnorm fits $ipic float=crsgain gainnorm end_if ! Set bad pixels back to -100 clip $ipic vmask=-100 ! Set exposure level, time, gain, readnoise fits $ipic float=exptime outtime fits $ipic float=gaineff gainpic0*tottime/outtime fits $ipic float=rneff tottime/sqrt[totrn] ch $ipic '{title}, {lfilt}' string file '{outdir}/{name}{lfilt}%i1' ipic wd $ipic {file} full if dosig==1 ! Sigma image. Take sqrt and set undefined pixels to -1 unmask clip 95 min=-99 maskonly sqrt 95 mul 95 c=outtime clip 95 vmask=-1 ch 95 '{title}, {lfilt}, sigma image' string file '{outdir}/{name}{lfilt}sig%i1' ipic wd 95 {file} end_if if darkmask==1 ch 96 '{title}, {lfilt}, npix image' string file '{outdir}/{name}{lfilt}n%i1' ipic get mask=/usr/tmp/darkbad max 97 98 99 masktoim 99 nr=nr[96] nc=nc[96] sr=sr[96] sc=sc[96] clip 99 min=0.5 vmin=1 max=0.5 vmax=0 mul 97 99 mul 97 c=outtime div 97 $ipic clip 97 max=0.25 vmax=-1 min=0.25 vmin=1. mul 96 97 ! masktoim 99 nr=nr[96] nc=nc[96] sr=sr[96] sc=sc[96] ! clip 99 min=0.1 vmin=-1 ! mul 96 99 dispose 97 98 99 wd 96 {file} end_if unmask end_do if noflat~=1 dispose 94 end_if end