parameter ibuf string=name snointer !snointer==0 : mark coordinates, auto mask, interactive mask ! 1 : mark coordinates, auto mask, but not interactive mask ! 2 : mark coordinates, interactive mask only (?) ! 3 : auto mask only, no display string file '{name}%i1' ibuf if snointer==3 goto maskit2 end_if ! Display unmask clip $ibuf min=lowbad max=highbad maskonly daosky $ibuf mask !mn $ibuf pix=9 silent tv $ibuf l=max[15.,5+2.*sky] z=-5 ! Do this mark just to get the initial markstar text out of the way mark new exit ! Mark reference stars err goto gettemp ! If we have a file already, we are done. Recentroid in case pos file was rough get coo=pos/{file} sr=0 sc=0 mark auto exit save coo=pos/{file} sr=0 sc=0 goto maskit ! Otherwise try out the last marked positions gettemp: err goto markit get coo=pos/last sr=0 sc=0 open incoo pos/last.coo read incoo read incoo read incoo read incoo r0=@incoo.3 c0=@incoo.2 close incoo box 1 n=20 cr=r0 cc=c0 tvbox box=1 color=2 printf 'If the displayed positions are OK, hit E in display to use them' printf 'If the positions are OK, but offset, hit the 1 key on the star' printf ' corresponding to the green box, then E to exit' printf 'To start with a new set of stars, hit Q in the display window,' printf ' then E to exit' r1=0 c1=0 mark auto if r1>0 get coo=pos/last sr=0 sc=0 clear vec mark auto dr=r1-r0 dc=c1-c0 printf 'If the displayed positions are OK, hit E in display to use them' printf 'To start with a new set of stars, hit Q in the display window,' printf ' then E to exit' end_if err goto markit save coo=pos/{file} sr=0 sc=0 goto maskit markit: clear vec printf 'Hit several stars using C in display window, E to exit' mark new save coo=pos/{file} sr=0 sc=0 maskit: save coo=pos/last sr=0 sc=0 maskit2: ! Get old mask if it exists. If it doesn't put a unmasked image in buffer 102 create 102 nr=nr[ibuf] sr=sr[ibuf] nc=nc[ibuf] sc=sc[ibuf] const=1 unmask err goto instmask get mask=msk/{file} masktoim 102 nr=nr[ibuf] sr=sr[ibuf] nc=nc[ibuf] sc=sc[ibuf] ! Add mask for instrument instmask: ! If wfpc, then add mask from data quality file if wfpc==1 ! printf '{name}' >./tmp.dat ! $'rm' tmp.out ! $awk '\{print substr($1,2,8), substr($1,10,1)\}' tmp.dat >./tmp.out ! open tmp ./tmp.out ! string rname {tmp} ! rchip=@tmp.2 ! close tmp ! rd 201 archive/u{rname}_c1f nim=rchip rd 201 archive/{name}_c1f nim=ibuf ! dont mask warm pixels (flag bit 512 or 1024) and 201 c=4095-512-1024 ! mask out all others clip 201 max=0.5 maskonly ! Now select out saturated pixels (mask=8) and set them to a large number in ! data file, set all other bad pixels to a small number to make sure they ! arent counted as saturated pixels (and get circular masks around them ! as a result) maskval=8 copy 202 201 and 202 c=maskval ! 202 will have saturated pixels only set to 32767 ! 203 will have mask of unsaturated pixels div 202 202 copy 203 202 sub 203 c=1 mul 203 c=-1 mul 202 c=32767 mul $ibuf 203 add $ibuf 202 maxbad=30000 else_if acs==1 call acsread 201 {name} ibuf 3 and 201 c=32767-64-4096-8192-2-16-32 clip 201 max=0.5 maskonly ! Now select out saturated pixels (mask=2048) and set them to a large number in ! data file, set all other bad pixels to a small number to make sure they ! arent counted as saturated pixels (and get circular masks around them ! as a result) maskval=2048 copy 202 201 and 202 c=maskval div 202 202 copy 203 202 sub 203 c=1 mul 203 c=-1 mul 202 c=65535 mul $ibuf 203 add $ibuf 202 maxbad=65530 else err continue get mask=/usr/tmp/blank end_if if snointer==2 mul $ibuf 102 tv $ibuf l=max[15.,5+2.*sky] z=-5 goto nextbox end_if err continue ! Mask around saturated stars with circular mask clip $ibuf maskonly max=maxbad rad=ps ! Mask other bad pixels as single pixels clip $ibuf maskonly min=lowbad masktoim 101 nr=nr[ibuf] sr=sr[ibuf] nc=nc[ibuf] sc=sc[ibuf] ! Add old mask into current mask mul 101 102 clip 102 min=0.5 maskonly ! Multiply by mask mul $ibuf 101 ! Display if snointer<3 tv $ibuf l=max[15.,5+2.*sky] z=-5 end_if if snointer==1|snointer==3 goto moveon end_if nextbox: printf 'Mark rectangular regions (in display window) to mask (E to quit)' aedit $ibuf mask int printf 'Mark circular regions (in display window) to mask (E to quit)' aedit $ibuf circ mask int printf 'Mark polygon regions (in display window) to mask (E to quit)' err goto moveon mpoly: markpoly 1 clip $ibuf poly=1 max=-1e10 maskonly goto mpoly moveon: ! Multiply by mask masktoim 101 nr=nr[ibuf] sr=sr[ibuf] nc=nc[ibuf] sc=sc[ibuf] mul $ibuf 101 ! Set masked pixels to bad value copy 102 101 sub 102 c=1 mul 102 c=-1 mul 102 c=lowbad-100 add $ibuf 102 ! Display if snointer~=3 tv $ibuf l=max[15.,5+2.*sky] z=-5 end_if ! Save mask $mkdir msk save mask=msk/{file} printf 'Add to mask if desired and save in ./{file}' end