call xmdv (xmidispvisi)
	checking
	photometry A
	photometry B
	Fringes:
xmidispvisi::init
	short_fringefile= MIDIname_datime(self.fringefile) (utilities.pro)

;;;;;;;;;;; MASK ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	self.maskobj = obj_new('miamask',...NOEWSPHOT=noewsphot,...

	--------- EWS phot
	oirChopPhotoImages: does chopping of raw frames
	chop_images=oirgetdata(chopimgfile)
	-----------------------------------

	maskdata = self->meanmask(WIDTH=maskwd,show=show_traces,SCI_MODE=sci_mode)
		xmidispvisi::meanmask
		Maskwidth is      1.00000
		chop_image= MIDISkySubImage(self.photfiles[iFile], before=1, after=1)
			MIDISkySubImage (MIA/utilities.pro)
			chop_image= MIDIChopImageC(filename, BEFORE=before, AFTER=after)
			MIDISkySubImage: High_sens
		chop_nod_disp_one_window, chop_image.int1,1.,2,1,mtrace,fx,fxc,photmask1,/silent
		chop_nod_disp_one_window, chop_image.int2,1.,2,1,mtrace,fx,fxc,photmask2,/silent
		(CURVEFIT errors are caused in gaussfit by noise profile)
		Two channels in chop-img, must be Hi-Sense
	Maskname is PHOTOMETRY/Mask_2005-04-18T04:26:26.250+04:27:45.250.fits
	Writing mask PHOTOMETRY/Mask_2005-04-18T04:26:26.250+04:27:45.250.fits
	self.maskfile = check_mask_position(self.fringefile,self.maskfile)
		check_mask_position (midivisi.pro)
		rmsdata = Cached_MeanRMS(fringefile) (utilities.pro)
			Cached_MeanRMS
			Mean+RMS file is
			/usr/local/src/MIA+EWS/c/bin/oirMeanRMS
		maskdata= oirgetdata(maskfile)
		Is the position of the mask satisfactory? (y/n)

	
	Or: self.maskobj->gui

;;;;;;;;;;; PHOTOMETRY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	After the mask has been created, either new EWS photometry is called
	or self->do_photometry:

	self->ews_photometry
		oirChopPhotoImages		; chops images
		oirMakePhotoSpectra		; extracts spectra

	self->do_photometry
	Photometry A...
		xmidispvisi::do_photometry
		Reading chopping data...
		chop_image= MIDISkySubImage(photfile, before=before, after=after)
		spec1 = total(win1 * maskdata.data1, 2) / DIT
		spec2 = total(win2 * maskdata.data2, 2) / DIT
	Photometry B...
		xmidispvisi::do_photometry
		Reading chopping data...
		chop_image= MIDISkySubImage(photfile, before=before, after=after)
		spec1 = total(win1 * maskdata.data1, 2) / DIT
		spec2 = total(win2 * maskdata.data2, 2) / DIT
	sqrt(A*B)...
		chop_image= MIDISkySubImage(photfileB, before=before, after=after)
          	win1 = sqrt(win1 * chop_image.int1 > 0.)
          	win2 = sqrt(win2 * chop_image.int2 > 0.)
		spec1 = total(win1 * maskdata.data1, 2) / DIT
		spec2 = total(win2 * maskdata.data2, 2) / DIT

;;;;;;;;;;; GET DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	data = getCompressSpec(self.fringefile, self.maskfile, $
		getCompressSpec (utilities.pro)
		/usr/local/src/MIA+EWS/c/bin/oir1dCompressData	
		getting data...
	using wavelength calibration for PRISM
	Using code for Undispersed tracking
	integrating over lambda =  7.0...13.0, x = 41...146
 	total opd length per scan:      83.2000 micron
xmidispvisi::visibility
	visibi = self->plot_disp_goodbad(lolams,hilams,PLOT=plot)
	if keyword_set(maskmul) then begin
          	photA1= total( self.specA1[ lolam:hilam ])
          	photA2= total( self.specA2[ lolam:hilam ])
          	photB1= total( self.specB1[ lolam:hilam ])
          	photB2= total( self.specB2[ lolam:hilam ])
          	phot = sqrt(photA1*photB1 > 0.) + sqrt(photA2*photB2 > 0.)
      	endif else begin
          	phot = total( self.specAB[ lolam:hilam ])
      	endelse
      	visibi[2,l] = visibi[2,l] / 2d / phot

Visibility returned by xmdv::visibility
	Calls xmdv::raw_correlflux	
		Co-adds interferograms in wavelength bins
		FFT, square, and integrate within frequency bins
		Then return sqrt of result



******************************************************************************************
Routines in use by MIA+EWS

Photometry:

MIDISkySubImage -> MIDIChopImageC -> midiChopimg.c
				  -> midiChopImage (ews/midi/utilities/fringeUtilities.pro)

	Both routines can drop frames before and after change of chopping phase

	midiChopImage: probably oldest chop routine, implemented in IDL, averages all
	sky and target frames and returns difference + sky in two data fields.

	midiChopimg.c is pretty much the C version of midiChopImage, and also averages
	over all target and sky frames, i.e. does not do pairwise chopping.


oirChopPhotoImages

	Loop over shutter A and B files
	unChopData
	normalizeExposure
	Subtract sky
	binChopData: to create NBIN chopped frames for computing RMS,
		each one will have several chopping cycles averaged
		in it. Assumes cycles start with Sky, then target,
		accumulates pairs (sky,target) in NBIN different bins.
	deSky
oirMakePhotoSpectra

	New C routines starting in version 1.3, used when NOEWS=0


New implementation of oirChopJitterPhotoImages.c:

Frame data: [nx,ny], nx is the fastest varying index, nx=171,ny=41 (PRISM).

profiles1[41][nrows]

Compute and store white light profiles in first call do unChopData
Then compute offsets and bins
Compute NBIN sub-averages in binChopData using offset bins
