procedure btc_gainflip(filename) # scale btc chips to gain=1, and flip as desired string filename {prompt="List of root names of image sets"} string bpmroot="" {prompt="Root name of bad pixel masks to add to header"} string getstats="" {prompt="Root name for iterstat output if desired"} bool gainmult=yes {prompt="Multiply all chips by their gain?"} bool flipns=yes {prompt="Flip chip #4 N-S (up-down)?"} bool flipew=yes {prompt="Flip all chips E-W (left-right)?"} struct *name # filename should list the names of the root image to be worked on begin string root, image, scales, bbpmroot, ggetstats real iteravg, chipscale bbpmroot=bpmroot ggetstats=getstats # -- cycle through image sets name = filename while (fscan (name, root) != EOF) { for (i=1; i<=4; i+=1) { image = root//"_"//i//".imh" # -- multiply image and existing iterstat header keywords by gain if (gainmult) { imgets(image, "gainold", >& "dev$null") if ((imgets.value)=="0") { imgets(image, "gain", >& "dev$null") imar (image,"*",real(imgets.value),image,ver-,noact-) hedit (image,"gainold","(gain)",add+,ve-,sho-,updat+) hedit (image,"gain",1.0,add+,ve-,sho+,updat+) imgets(image, "itermean", >& "dev$null") if ((imgets.value)!="0") { hedit(image,"itermean","(itermean*gainold)",add+,ve-,sho-,updat+) hedit(image,"itermode","(itermode*gainold)",add+,ve-,sho-,updat+) hedit(image,"itersig","(itersig*gainold)",add+,ve-,sho-,updat+) hedit(image,"itermed","(itermed*gainold)",add+,ve-,sho-,updat+) hedit(image,"variance","(variance*gainold*gainold)",ad+,ve-,sho-,updat+) } } else { print (image//" already multiplied by gain!") } } # -- flip chip #4 N-S if (flipns) { if(i==4) { imgets(image, "flipns", >& "dev$null") if ((str(imgets.value)) != "yes") { imgets(image, "flip", >& "dev$null") if ((str(imgets.value)) != "yes") { imcopy (image//"[*,-*]", image, ver-) hedit(image,"flipns","yes",add+,ve-,sho-,updat+) hedit(image,"flip","yes",add+,ve-,sho-,updat+) print (image//" flipped N-S...") } else { print (image//" already flipped N-S!") hedit(image,"flipns","yes",add+,ve-,sho-,updat+) } } else { print (image//" already flipped N-S!") hedit(image,"flip","yes",add+,ve-,sho-,updat+) } } } # -- flip all chips E-W if (flipew) { imgets(image, "flipew", >& "dev$null") if ((str(imgets.value)) != "yes") { imcopy (image//"[-*,*]", image, ver-) hedit (image,"flipew","yes",add+,ver-,show-,update+) print (image//" flipped E-W...") } else { print (image//" already flipped E-W!") } # -- add bad pixel mask names to headers if (bbpmroot!="") { hedit(image,"bpm",bbpmroot//"_"//i//".pl",add+,ver-,sho+,updat+) } } } # -- iterstat if desired if (ggetstats!="") { print (root//" images flipped and gain-multiplied. Running iterstat.") iterstat (root//"_?.imh", >> ggetstats) } } beep end