;+ ; NAME: batch_rivm_na ; ; DESCRIPTION: ; Runs RIVM in a loop, with settings appropriate for sodium data, to ; reduce all the magnetograms in a day. ; ; CALLING SEQUENCE: ; batch_rivm_na, cdir, wdir ; ; INPUT PARAMETERS: ; cdir = directory that contains the raw calibration files ; wdir directory that contains the raw data files ; ; OPTIONAL INPUT KEYWORDS: ; save_binarr - If set, save traditional IMG0*_unb/_bn binary array file ; nodelete - If set, keep the intermediate files. Default behavior, ; whereas earlier versions would save by default. 2012.04.24 ; delete - Retained for backward compatibility. nodelete keyword ; takes precedence. ; calib - If set, use the CAL and FLAT files that are already ; processed (*inv files). Default processes the CAL ; and FLAT files. ; noscan - If set, do not run quality scan on the data files. ; Default runs IVM_SCAN and IVM_DATA_PATCH to correct bad images. ; AND all the keywords used by RIVM. ; ; RESTRICTIONS: ; The best way to use this procedure is to make a copy of ; it and edit for the details of the call to RIVM. ; ; HISTORY: ; Written 1998 Barry LaBonte, one a long line of attempts. ; Add keyword inheritance, better preprocessing Sept 2, 1999 BJL ; Modify for daily flat processing June 22, 2001 BJL ; KDL: warning, does not work when combined with 'jump' keyword. ; BJL Oct 3, 2002 Replace SPAWN with FILE_DELETE ; ELW 20110610 Sodium, copied from batch_rivm with updates from KD's version ;- PRO batch_rivm_na, cdir, wdir, nodelete=nodelete, calib=calib, $ scat=scat, noscan=noscan, _EXTRA=ex, unblur=unblur, sodium=sodium, $ regparm=regparm, destretchonly=destretchonly, $ save_binarr=save_binarr, verbose=verbose ; Avoid bulky .mycshrc by using Bourne shell for system calls. ELW-20091223 setenv,'SHELL=/bin/sh' sodium=1 ; This version of batch_rivm is sodium-specific ; Keep intermediate files by default keep_int = keyword_set(delete) if (keyword_set(nodelete)) then keep_int=1 ; Get the exact directory names to enable exact comparisons CD, cdir, CURRENT=here CD, wdir, CURRENT=caldir CD, here, CURRENT=datdir ; Calibrate or not? redc = 1 redf = 1 IF( NOT KEYWORD_SET(calib) ) THEN BEGIN CD, caldir dfiles = FINDFILE('ID*') ffiles = FINDFILE('IF*') cfiles = FINDFILE('IC*') print, 'Calling RIVMCAL with the following arguments:' print, ' dfiles=',dfiles print, ' ffiles=',ffiles print, ' cfiles=',cfiles print, ' (dayflat is output)' RIVMCAL, dfiles, ffiles, cfiles, dayflat, scat=scat, _EXTRA=ex, KEEP_INT=keep_int CD, here ENDIF ; Are the cal files here? IF( caldir NE here ) THEN BEGIN ; List the calibration files cfiles = FINDFILE( caldir + '/ICA* ' + caldir + '/IDK* ' + $ caldir + '/IF*' ) ncfiles = N_ELEMENTS(cfiles) ; Link them in locally FOR i=0,ncfiles-1 DO SPAWN, 'ln -s ' + cfiles(i) + ' .' ENDIF ; Now the actual cal files - not the suffixed versions calfiles = FINDFILE( 'ICA*' ) gcal = WHERE( STRPOS( calfiles, 'inv' ) LT 0 AND $ STRPOS( calfiles, 'instr' ) LT 0, ngcal ) IF( ngcal GT 0 ) THEN calfiles = calfiles(gcal) ; List the magnetogram files CD, datdir ; (Not a typo - FIND_FILE is different from FINDFILE) files = FIND_FILE('IMGR*') if (~sodium) then begin ; ELW20110613 - Avoid data patch code for Sodium ns = strpos(files,'_dpa') noneedtoscan = where(ns GE 0) needtoscan = kill_index(indgen(n_elements(files)),noneedtoscan) ; Quality check unless already done IF( NOT KEYWORD_SET(noscan) ) AND needtoscan[0] GE 0 THEN BEGIN for iscan = 0,n_elements(needtoscan)-1 do begin IVM_SCAN, files[needtoscan[iscan]], flags IF( MAX(flags) GE 0 ) THEN BEGIN IVM_DATA_PATCH, files[needtoscan[iscan]], flags ENDIF endfor files = FIND_FILE('IMGR*') ENDIF endif print,files CD, here nfiles = N_ELEMENTS(files) ; Match the Cal files with the data files calmatch = FILE_TIME_MATCH( files, calfiles, /PREVIOUS ) ;uncomment and customize below if appropriate ;restore,'custom_mask.sav' ;restores mask for xbgram7, variable 'mmask' ; for 'mask' keyword below. To use default mask from ivm_mask, set mask=1. ; for no mask (slower, more dangerous) use mask=0 ; see RIVM_V3.pro for details on keywords ; as of RIVM v3.0, following are all options, and 'best' values where needed ; Loop over all the magnetograms found, calling rivm at each one FOR i=0,nfiles-1 DO BEGIN & ; Link the next data file in if needed IF( datdir NE here ) THEN $ SPAWN,'ln -s ' + datdir + '/' + files(i) + ' .' datf = files(i) ; Specify the Cal file for this data file calf = calmatch(i) print, 'Arguments for the call to rivm:' print, ' calf=',calf print, ' datf=',datf print, ' keep_int=',keep_int print, ' redf=',redf print, ' redc=',redc if (keyword_set(dayflat)) then print, ' dayflat=',dayflat if (keyword_set(unblur)) then print, ' unblur=',unblur if (keyword_set(scat)) then print, ' scat=',scat print, ' verbose=', keyword_set(verbose) ? verbose : 0 destretchonly=1 regparm = [256,256,256,256,1] ; optional coalignment parameters if (~ keyword_set(scat)) then begin scat=[0.00221795, -1.65501] print, ' batch_rivm_na: Using default scat = [0.00221795, -1.65501]' endif ; Call RIVM - set some defaults, if not overridden by inheritance gram=rivm(calf,datf,$ ; names of cal, dat file from above ; fitmap, $ ; variable to return for goodness of fit image keep_int = keep_int, $ ; keep intermediate files redf = redf, $ ; flats have been reduced already redc = redc, $ ; calibration matrix has been computed already dayflat = dayflat, $ ; daily flat file for interpolation regparm = regparm, $ ; optional coalignment parameters ; regparm = [bx,by,hx,hy,no_lim],$ ; optional coalignment parameters ; ; defaults: [128,128,nx/2,ny/2,0] scat=scat, $ ; amount (or flag to) remove scattered light. ; set to [1.0e-4,-1.15] for Na data. save_binarr=save_binarr,$ ; Save binary arrays, not just fits gif = 1, $ ; produce a GIF file as output unblur = unblur, $ ; flag to unblur (call ivm_desee) sodium = sodium, $ ; sodium / chromospheric destretchonly=destretchonly, $ ; call ivm_desee only for warp corrections unbias = 1, $ ; remove continuum and residual polarization biases warp = 1, $ ; warp geometry cam. images to data camera. parasitic = 1, $ ; correct for parasitic light spurious = 1, $ ; correct for spurious extinction detrend = 1, $ ; take out limb darkening when needed seeing = 1, $ ; if set, remove worst-seeing images mask = 1, $ ; mask to give xbgram for points to fit, not fit verbose=verbose, $ ; verbosity ; dl = 0.12, $ ; wavelength (A) from line center to determine B, Photosphere ; dl = 0.070 $ ; wavelength (A) from line center to determine B, Chromosphere ; invert can be 'quicklook', 'jls', 'triplet', 'unno-jls', or 'unno' ; invert = 'unno', $ ; default is 'triplet', other option 'quicklook' binstokes = binstokes,$ ;flag (if=1) or amount (integer > 1) to bin before inverting _EXTRA=ex $ ; Finally pass all the inherited keywords ; jump = 'blur', $ ; jump to this point in the program ; d0fil = d0fil, $ ; IDK0yymmdd.hhmmss file, if other than in header ; f0fil = f0fil, $ ; IFA0yymmdd.hhmmss file, if other than in header ; npoints = npoints, $ ; number of spectral points, if other than in header ; nfus = nfus, $ ; number of F-P steps, if other than in header ; shut = 1, $ ; subtract leaky-shutter light (pre-199X data) ; old_data = 1, $ ; pre-199X data ; no_reg = 1, $ ; do not attempt to coalign images ; fourstep = 1, $ ; use (override header) four-step demodulation ; calsmooth = 1, $ ; width of smoothing function for cal matricies ; matched ='mfile',$ ; file with 4x2 coalignment transform matrix ; fitfunct = 'voigt', $ ;use voigt function (can be 'gaussian') ; no_geomreflat=no_geomreflat, $ ; set this to avoid new geom de-fringing. ; /no_bgram, $ ; return header information and do not run xbgram ) ; KEEP THIS (closes rivm) ; Delete the link to the data file if needed IF( datdir NE here ) THEN FILE_DELETE, files(i) ; Delete the last step Geometry file if intermediate files not wanted ; IF( KEYWORD_SET(delete) ) THEN FILE_DELETE, 'IMG1*' ENDFOR RETURN END