! @(#)tfocus.prg 12.1.1.1 (ES0-DMD) 09/16/97 11:26:49 !=========================================================================== ! Copyright (C) 1995 European Southern Observatory (ESO) ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation; either version 2 of ! the License, or (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public ! License along with this program; if not, write to the Free ! Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, ! MA 02139, USA. ! ! Corresponding concerning ESO-MIDAS should be addressed as follows: ! Internet e-mail: midas@eso.org ! Postal address: European Southern Observatory ! Data Management Division ! Karl-Schwarzschild-Strasse 2 ! D 85748 Garching bei Muenchen ! GERMANY !=========================================================================== ! ! @(#)tfocus.prg 12.1.1.1 (ESO-ASD) 09/16/97 11:26:49 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++ !.IDENT tfocus.prg !.PURPOSE Sequence focus in the displayed image !.USE @c tfocus !.AUTHOR Cristian Levin !.VERSION 1.0 01/06/92 Creation !.VERSION 2.0 12/08/94 plotting enhanced (CL) !.VERSION 2.1 10/01/95 implementation of parameters file (CL) !.VERSION 2.2 14/09/95 add CREATE/GRAPHICS + remove CLEAR/CHAN OVER ! K.Banse !.VERSION 3.0 11/12/98 adapted for the WFI !.VERSION 3.1 12/09/99 Calls Focus database, & cleaned. (J.Brewer) !.KEYWORDS ! ------------------------------------------------------ ! ! PARAMETERS: ! P1: Start focus value (no default) ! P2: Step size (no default) ! P3: Number of exposures (no default) ! def/par p1 ? N " Enter initial focus value: " def/par p2 ? N " Enter focus step size (e.g. 40): " def/par p3 ? N " Enter number of exposures (e.g. 9): " def/par p4 Y C " Calculate positions automatically?: " ! ! These shift values should be properly set ! define/local xshift/i/1/1 0 define/local yshift/i/1/1 -50 define/local focx/d/1/1 0.0 define/local focy/d/1/1 0.0 define/local seex/d/1/1 0.0 define/local seey/d/1/1 0.0 define/local focus/d/1/1 0.0 define/local aux/d/1/1 0.0 define/local fox/d/1/1 0.0 define/local sign/d/1/1 0.0 define/local n/i/1/1 0 ! ! setup the graphics window ! create/graph set/graphics default set/graphics pmode=1 ! ! Message to user... wri/out wri/out " >>> Mark TOP image first! <<<" wri/out set/midas output=no ! ! Below for auto detection... ! if "{p4}" .eq. "Y" then create/table tfocus 15 {p3} null create/column tfocus :xstart create/column tfocus :xend create/column tfocus :ystart create/column tfocus :yend ! ! getting the coordinates of the first position in the sequence... ! set/midas output=yes cent/gauss cursor if outputi(1) .eq. 0 then write/out write/out Invalid number of coordinates. return endif ! ! Create table with the expected positions of the star in the focus ! sequence as calculated from the first position ! do n = 1 {p3} 1 tfocus,:xstart,@{n} = 'outputr(1)' + ({n}-1)*{xshift} tfocus,:ystart,@{n} = 'outputr(2)' + ({n}-1)*{yshift} tfocus,:xend,@{n} = 'outputr(3)' + ({n}-1)*{xshift} tfocus,:yend,@{n} = 'outputr(4)' + ({n}-1)*{yshift} enddo ! ! Measure the star at all positions ! center/gauss {idimemc},tfocus tfocus else ! ! Measure the positions individually ! create/table tfocus 15 0 null set/midas output=yes write/out write/out "Click on the star images in the sequence one by one" write/out center/gaus cursor tfocus endif ! ! Switch off MIDAS screen output... ! set/midas output=no ! ! fit-x computation ! compute/table tfocus :step = SEQ - 1 compute/table tfocus :xfwhm = :xfwhm * 0.239 name/column tfocus :xfwhm "arcsec" regression/polynomial tfocus :xfwhm :step 2 save/regression tfocus test comp/regression tfocus :fitx = test(:step) focx = {p1} + {p2}*({outputd(2)}/(-2.*{outputd(3)})) seex = -{outputd(2)}*{outputd(2)}/(4.0*{outputd(3)})+{outputd(1)} ! ! fit-y computation ! compute/table tfocus :yfwhm = :yfwhm * 0.239 name/column tfocus :yfwhm "arcsec" regression/polynomial tfocus :yfwhm :step 2 save/regression tfocus test comp/regression tfocus :fity = test(:step) focy = {p1} + {p2}*({outputd(2)}/(-2.*{outputd(3)})) seey = -{outputd(2)}*{outputd(2)}/(4.0*{outputd(3)})+{outputd(1)} ! ! compute the scaling for plots... ! compute/table tfocus :maxim = MAX(:xfwhm,:yfwhm) sort/table tfocus :maxim(-) define/local maxim/r/1/1 {tfocus,:maxim,1} maxim = {maxim} + 0.2 ! let's give a margin value compute/table tfocus :minim = MIN(:xfwhm,:yfwhm) sort/table tfocus :minim define/local minim/r/1/1 {tfocus,:minim,1} minim = {minim} - 0.2 ! let's give a margin value set/graphics yaxis={minim},{maxim} ! ! plot (x,y)-value versus (x,y)-sigma ! sort/table tfocus :step set/graphics stype=6 colour=1 ! cross(x), black plot/table tfocus :step :xfwhm set/graphics stype=5 colour=4 ! cross(+), blue overplot/table tfocus :step :yfwhm ! ! plot of the fit ! set/graphics stype=0 ltype=1 ! no symbol, solid line set/graphics colour=1 ! black overplot/table tfocus :step :fitx set/graphics colour=4 ! blue overplot/table tfocus :step :fity ! ! focus computation ! aux = {focx} * {focy} aux = M$ABS({aux}) fox = M$ABS({focx}) sign = {focx}/{fox} focus = {sign} * M$SQRT({aux}) ! ! Enable the screen output... ! set/midas output=yes write/out write/out set/format ,f12.0 !for double keywords write/out " X: BLACK Y: BLUE" write/out write/out "FOCUS: X = {focx} " "Y = {focy} " "MEAN = {focus}" write/out set/format ,f12.2 !for double keywords write/out " seeing-X = {seex} seeing-Y = {seey}" set/graphics default ! ! All of below added by J.Brewer (12 Sept. 99) for the focus database... ! ! ! Get the image name... ! define/local ioff/i/1/2 0,0 ioff = ididev(6)*ididev(15)+1 !offset into keyword IDIMEMC ioff(2) = ioff(1)+19 !define/local cmc/c/1/20 {idimemc({ioff}:{ioff(2)})} define/local cmc/c/1/8 {idimemc({ioff}:{ioff(2)})} ! ! Call shell script to write info to focus database. ! write/out define/local good/c/1/1 y inquire/key good/C/1/1 "Is this a good fit to the data? (y/n) [{good}] " if good .EQ. "n" .AND. good .EQ. "N" then write/out "OK, we won't add this to our focus database..." goto STOP endif write/out "Adding measurement to WFI focus database..." set/format ,f12.0 $/home/drs/bin/Add2FocDB {cmc} {focx} {focy} ! The End... ! STOP: