README provides accompanying documentation 
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
	Version	  Date	 **	** indicates compulsory control card change

	V2.00	21.12.98 **	Original program, Niko Grigorieff
	V2.01	28.12.98	input parameter file created when IFLAG < 0
		30.12.98	bug : set BUFF=C3DF, BUFS=C3DS on 3D map input
		  2.1.99 **	subr GETSYMMAT added with all point groups
		  8.1.99	RBIN,RBINS normalised; PFREE,PNOISE all resoln
	V2.02	  9.1.99	O/P formats changed 7011+7012(6707), 7014(7013)
		 12.1.99	subtract 1.0 from SSNR, write out sqrt thereof
		 20.1.99	store then output best parameters for mode IFLAG=4
		 24.1.99	if no good particles, message - abnormal termination
	V2.03	 24.1.99	subr LIMITSYMM added to restrict search angles
		 24.1.99 **	added multiple film number input on card 8 (MORE)
		 31.1.99	further restriction to asymmetric unit (THETAMAX)
		 31.1.99	quadrant search changed to IQUAD,IQUADMAX in PSEARCH
		  5.2.99	write out history of improved orientations (temporary)
		  5.2.99	comment out the above history (search for BESTPHI)
	V2.04	  6.2.99 **	add two extra input parameters (DANG, ITMAX) on card 2
		  8.2.99	correction to asymmetric unit search (psi<=>phi)
		  9.2.99	DANG allowed to be 360 degrees
		 11.2.99	resolution limit printout format change -> F11.3
		 11.2.99	do not set phase residual to PI but leave as best value
		 11.2.99	double precision PFREE
		 13.2.99	put date before time in NDOC1 output
	V2.05	 14.2.99	IANG dimension increased to 80000, plus online check
		 15.2.99	increase dimension of RBIN arrays to avoid checkbounds
		 16.2.99	double precision REAL*8 STD,VTD,TTD, also subr PINSERT
		 16.2.99	STD,VTD,UTD,STDD calculated from number of non-zero pixels
		 16.2.99	STD,VTD,UTD,STDD denominator multiplied by IREDUN
		 16.2.99	PDIFF phase calculation done if complex number non-zero
		 19.2.99	trim 1 pixel off APPLYSYM resolution to avoid edge artefact
		 21.2.99	move NSET and ILAST reset statements to earlier position
	V2.06	 24.2.99	MBUF dimension debugged to NPB*NN1*NN1, used in CTFREFINE
		 27.2.99	delete FDEF section to find IFIRSTF on each film (830,831)
		 12.3.99	calculate overall average phase residual versus reference
        V2.07    13.6.99        add statistics versus reference as function of resolution  
		  4.7.99	add resolution in Angstroms to output of statistical tables
		  5.7.99	remove silly magnification restraint RFT=RFT+(10*DMAG)**2  
		  6.7.99	add spacegroup 1 & Angstrom cell axes to 3D map O/P header 
		  6.7.99	add -NX/2,-NY/2,-NZ/2 startpoints to MRC map header
		  6.7.99	remove the divide by AMAGP in calculation of RMAX1,RMAX2 
        V2.08    10.7.99 **	add FMAG magnification refinement for images on same film
		 11.7.99	leave spacegroup 1, but number symm bytes 0 in O/P header
		 13.7.99	FMAG and FDEF can work together one film at a time
        V2.09    25.7.99        RREC,RMAX1,RMAX2 input now specified in Angstroms
		 25.7.99 **	input parameter DSTEP added (densitometer step size)
		 25.7.99 **	space group 1, nsym 80 added to MRC O/P 3D map header
	V3.00	 27.7.99 **	absolute magnification + DSTEP to calculate pixel size
		 27.7.99	change AMAGL to RELMAG to clarify meaning
		 28.7.99	output date and time to parameter file at end of run 
		 29.7.99	3D input map pixel size checked against PSIZE
		  2.8.99	RI (Particle radius too large!!!) test moved 
		  3.8.99	add VX to carry version number throughout
	V3.01	 23.8.99	debug absolute magnification output
		 15.4.99	IFLAG=IABS(IFLAG) moved outside input loop (lost from 2.01)
		 15.4.99	FINPAT=FINPAT1(NSET) when NSET>1 (lost from 2.01)
		 15.9.99	reinstitution of two earlier lost debugs
		 13.1.00	debug format statement 6702
		 25.2.00	matching images angle written in degrees
		  5.3.00	ITMAX value written out for all searches
	V3.02	 14.3.00 **	FHIST added, to output history of orientation improvement
	V3.03	 31.3.00	set outer edge of resolution shell to zero before output
		 13.4.00	simplify 6702 write and format statements
	V3.04	 29.6.00	for matching image output, set spacegroup = 0.
	V3.05	  1.2.01	write out param file when FMAG.eq.T
	V4.00	 28.5.01 **	addition of TARGET, MASK and matching projection filename
		 28.5.01	remove all reference to FSCC - Marin's nonsense
		 29.5.01	remove image subtraction via PINSERT for IFLAG=1 refinement
		  7.6.01	xpar -> xparmap in write statement in subr CALCFX
	V4.01	 11.6.01	introduce THETATRP inside subr CTFAPPLY
	V4.02	  7.8.01	correct MAXR1,MAXR2 by multiplying by AMAGP
		  9.8.01	RIHP,RI2P,etc inside subr CTFAPPLY divided by AMAGP
		  9.8.01	No map or datafile outputs if RELMAG is < -100.0
		 12.8.01	CALCFX format statement -> F9.4
	V4.03	 12.8.01	refine magn/ctf using unweighted phase residual PRES_UNW
	V4.04	 15.8.01	replace function PDIFF with souped-up version
	V4.05	 19.8.01	IRADA=1 to speed up PSEARCH, PREFINE calls to AINTERPO3D
		 19.8.01	magref/ctfref with CTFAPPLY_PHASE_ONLY, not PRES_UNW
		 19.8.01	add resolution statistics for particle refinement
		 19.8.01	Replace sinc function with look-up table (speed)
	V4.06	 27.8.01 **	add subr BEAUTIFY to symmetrize and mask final map
		 27.8.01	add FASTIG, FBEAUT to allow choices of options
		 27.8.01	add RBFACT: apply B-factor to orientation param refinement
	V5.00	 27.8.01 	HALFP=0 in APPLSYMC, centre moved +0.5 pixel in BEAUTIFY
		  2.9.01 	add IF(NPAR.NE.0) before VA04 call in PREFINE
	V5.01	  3.9.01	THETAMAX1=90.0 must be set when ASYM not T or I
                  3.9.01	BUG: UTD changed to STDD in VAFUNC common block
                  3.9.01	not reading weight file on input since not used anymore
                  3.9.01	FMATCH=T: now writing out ICMPxICMP reduced matching
                                         projection and original particle for easy comparison
                  3.9.01        FMATCH=T: including some particles parameters in matching
                                         projection images (subroutine STAMP)
                  3.9.01        reduce shifts in angles to [-180.0,180.0]
                  3.9.01        remove resetting of input parameters when IFLAG>=3
                  3.9.01        debug IFLAG=3,4 option: now also storing BESTAMAG,
                               BESTDFMID1, BESTDFMID2, BESTANGAST, do not reset old values
                  3.9.01        add output of phase residual change in additional column of
                               parameter file
                  3.9.01        debug subroutine IOPEN: set cell(1-3) when file exists
        V5.02   16.11.01	All the SUBROUTINES and FUNCTIONS are now in separate files
			        Removed the /FILEIO/ and the /SINLUT/ common blocks
		19.11.01	added "EXTERNAL MATMUL" in applysymc.f, applysymr.f, beautify.f
				and checksym.f
				removed unused variables "SAMP", "FINFO" and "FINPIC" in frealign_v5_02.for	
		 4.12.01       CALL FLUSH() was added to force the writing to /tmp/beta.par_${1}_${2}
        V5.03   10.12.2001     Made subroutines to read card1, card2, card3, card4 and card5

	V5.04	 7.01.2002     Made subroutines for cards 6 to 18, card18a, SHIFT, SHIFTVOL, 
			       MASKING, SEARCHANG, DELSCRATCH, STORESHIFT, RESSTAT, OPMAPS, 
			       OPRESSTATHALF and  OPRESSTATMAPS.

	V5.05    28.01.2002    Made subroutines SHIFT2D,BACKUP,A3D3,MATCH and MAIN
			       Do not pass the variables SBUF in OPMAPS and DPH in SEARCHANG
			       DO not pass INLINE in card1, N2, NSTAC and RTEMP in card8and9 ,
				ABSMAGP and LINE in card10, FOUTPAR and FOUTSH in card11and12,
				ID,IS and NUTD in card13and14.	
	V5.06    7.02.2002     REMOVE COMMON block /PRXPAR/XPAR,NPAR
                               REMOVE COMMON block /VAFUNC/NSAM,MAXR1,MAXR2,IRADA,OUTD,OUTQ,C3DF,C3DS,
                                                           U3DF,U3DS,STDD,BUFF,BUFS,MASK
                               REMOVE COMMON block /CTFAPP/PBUF,PBUQ,SHX,SHY,CSN,WLN,WGH1,WGH2,
                                                           THETATR,CTFF,CTFS,AMAGP,RIH,HALFWC,RI2,
                      					   RI3,RI4,IVFLAG,DATD,DATQ,PHI,THETA,PSI,
                      					   RMAX1N,RMAX2N,ILST,IBUF,B3DV,MBUF,XSTD,QBUC,QBUQ,
                      					   NCALCFX_CTF,RBFACT,DELTADF
                               REMOVE COMMON block /SINLUT/SINCLUT
      			       Common parameters in different subroutines that could possibly change are defined 
			       in Frealign only.
			       USE IMPLICIT NONE in all subroutines except ran2,fourn,rlft3 and va04.	
			       COMBINE subroutines SHIFT2D and SHIFT, the new subroutine is called SHIFT. 	
		               Replace code in CTFAPPLY and CTFAPPLY_PHASE_ONLY by calling SHIFT
                                 (SHIFT is called twice in each).
			       SHIFT also corrects for CTF in certain cases.
        V6.00    9.03.2002     Now using FFTPACK Fourier transform routines -> all even-numbered particle
                               possible
                               Removed small bug in main loop (main.f) which forced DFMID1=DFMID2 on
                               output in parameter file (discovered by Alexander Fotin, Harvard Med. School)
        V6.01   27.03.2002     Faster interpolation during refinement by using padded reference
                               volume (padded array size set by NNBIG). IPAD automatically set to 1
                               (if no padding), 2 or 4, depending on available array space.
        V6.02   16.03.2002     Corrected a minor bug affecting reading/writing of SPIDER files
                               (subroutine iopen), and particle numbers for free phase residual
                               (subroutine card10)
        V6.03   29.06.2002     New checks:
                               1) Warning if particle numbers in parameter file not consecutive
                               2) Warning if more particles in stack than in parameter file
                               3) Stop if fewer particles in stack than in parameter file
                               4) Stop if MIN/MAX of a particle equal (blank image)
                               5) Stop if MIN of particle >= 0 or MAX of particle =< 0 (particle
                                  not normalized)
        V6.04    1.07.2002     Bug in cards8and9: if several data set read in, file name for matching
                               projections only solicited once -> corrected
                               Bug in cards8and9: RMAX1/RMAX2 not converted to reciprocal values for
                               2nd, 3rd data sets -> corrected
                               Bug in lmain: when opening 2nd, 3rd ... data set, next particle read
                               from stack caused read error as file location not reset to beginning
                               of new stack -> corrected
                               Bug in lmain: in mode 0, MAXR1/MAXR2/RBFACT not set until first
                               pfree calculated -> corrected
        V6.05   13.07.2002     Changed matching projections format: dimensions now given by 3*RI;
                               useful if original particle size NSAM much larger than particle
                               (necessary to include high resolution fringes). Also: no shifts
                               are applied to matching projection, particle is now shifted into
                               centre. Changes in subroutines cards8and9, lmain, match; new subroutine
                               window.
                               Also changed high resolution limit (RMAX2) in cards8and9: now allows
                               resolution up to 3.0 A.
                               Also changed setting for interpolation radius IRADA in frealign:
                               setting now depends on comparison of particle radius RI with
                               dimension of refereence volume, IPAD*NSAM.
                               Also, now there is no calculation of 3D data if RELMAG = -100
                               or smaller as there will be no 3D output either - only refinement.
                               -> changes in frealign, lmain and a3d3
        V6.06   18/07/2002     CTF refinement done on individual particles when resolution of
                               refinement higher than 10A (flag CI in lmain): changed subroutines
                               lmain, ctfrefine, frealign.
                               If mask radius RI+HALFW/2.0 exceeds window dimensions, warning is
                               issued instead of STOP -> changes in cards13and14
                               Bug: need to set PBUQ=0, SPEQ=0 after RLFT3 since subsequent shift
                               operation would be incompatible if PBUQ, SPEQ nonzero (this is a
                               consequence of using a specialized real FFT -> changes in lmain
                               Changed output of matching projections: now only PRES and DPRES
                               included in output -> changes in match
                               RLIM now set to PSIZE/RREC-2.0/NSAM (in cards8and9) to avoid
                               array overruns in other parts of the program
                               Changed function pres to be minimized: now using a correlation
                               coefficient (pres actually returns acos(cc)) instead of phase
                               residual -> changes in pres and other parts of the program
                               calling pres, changes mainly due to additional array RBUF
                               Output of resolution table changed: instead of PFREE the
                               table now gives the correlation coefficient CC in resolution
                               zones, as well as an expected correlation EXP. C calculated
                               from the variance ratio of the entire particle image and the
                               background measured at the edge of each image (new subroutine
                               variance). A third column gives an estimate of the standard
                               deviation, SIG C, between measured CC and EXP. C, a fourth
                               column gives the value of the complementary error function,
                               giving the probability of the observed difference between measured
                               CC and EXP. C given SIG C. -> changes in opresstathalf, frealign
                               and lmain.
                               Changed mask order (1st and 3rd position) to agree with order
                               of parameters in parameter file
                               Bug in ccp: IX, IY need to be set to zero so that they are
                               also initilized when mask=x x x 0 0 -> changes in ccp
                               Added feature to include fixed percentage of particles: if
                               thresh is set between 0 and 1 then it indicates percentage
                               -> changes in lmain, card10, new subroutine pinc
                               Bug in lmain: if no of particles larger than 46341 then
                               product ILIST(K)*ILIST(K-1) overflows INTEGER number
                               -> now convert to REAL before multiplication
                               Increased NLMAX to 100000
                               Bug in card10: if angles have values less than -180.0 they
                               are out of range for calcfx -> now resetting angles to be
                               between -180.0 and 180.0
        V6.07   12/09/2002     Experimental
        V6.08   14/08/2003     New target function in pres.f: Sum(CC**3) is maximized
        V6.09   22/12/2003     Fixed refinement of magnification/CTF: now uses old phase
                               residual
        V6.10   20/02/2004     Introduced correction of 3D volume (subroutine correct3d)
                               Now use only linear boxftv in pinsert (previously used boxftv**2)
                               Fixed usage of mask array in psearch
        V6.11   13/04/2004     Introduced Winer filter constant W=1.0/REAL(NSAM) in cc3 and cc3m
                               Check in variance that RI is not larger than window dimension
                               Bug removed in shiftvol

  Remember also to change the version number in DATA  VX statement (main program only)
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
  Description of function of variables used in program
    Arrays at heart of the program concept
	A3D,D3D	- accumulates 3D transform
	B3D	- 3D mask initially, then accumulates 3D transform, then workspace in symmav
	C3D	- 3D map I/O
		[extensions above V=volume(real), F=transform(complex), S=section(complex)]
		[extensions immediately below are V=volume(real), S=section(real)]
	S3D,V3D	- accumulates 3D sum of CTF**2
	T3D	- accumulates 3D sum of CTF**2, then workspace in applying symmetry
	U3D	- 3D weights I/O
	ASUM	- sum of absolute amplitudes, weighted by sinc box function
	VSUM	- sum of squares of amplitudes weighted by sinc box function
	PSUM	- sum of phase differences at each reciprocal space pixel
	KSUM	- total number of terms in 3D transform accumulation
    Filenames
	FINPIC	- not used
	FINFO	- search angles file, not implemented
	SFILE	- scratch file for backup of long jobs
	FINPAT	- particle image stack used for each dataset
	FINPAT1	- particle image stack on input
	FINPAT2	- matching projections stack
	FINPAR	- I/P parameter file
	FOUTPAR	- O/P parameter file
	FOUTSH	- O/P parameter shifts file
	F3D	- 3D map file for input and/or output
	FWEIGH	- 3D weights file (entries set to 1.0 if not available)
	FQF	- O/P 3D Q-factor file
	FAMP	- O/P 3D standard deviation of amplitude
	FPHA	- O/P 3D standard deviation of phase
	FPOI	- O/P of 3D pointspread function
    Variables
	CFORM	- single byte format identifier S,I,M
	NSANG	- number of search angles for PSEARCH
	LUNARA	- Spider I/O file variable
	IBUF	- for defocus & magnification refinement, number of particles in buffer
	NILMAX	- maximum no. particles in dimension statements, ILAST should be smaller
	NPB	- maximum number of images for defocus/magnification refinement
	IVFLAG	- flag indicating that the next group of images for defocus or
			magnification refinement is being processed, IVFLAG=1 for
			defocus and IVFLAG=2 for magnification, otherwise IVFLAG=0
	IPFR	- flag to mark particles used for free phase residual (1) or normal (0)
	XPAR,XPARMAP	- parameters for refinement by VA04 Powell minimiser
			for particles, 5 (or 6) are used - PHI,THETA,PSI,DSHX,DSHY,(MAG)
			for defocus, 3 parameters are used - DFMID1,DFMID2,ANGAST
			for magnification, 1 parameter is used  - AMAGP
	NDOC1		- output parameter file
	NDOC2		- output file giving shifts in each parameter
	AMAGP, AMAG	- particle magnification used internally - numbers are near 1.0 
			  and refer to extra magnification to be applied to image pixels 
			  relative to 3D map pixels
			  images recorded at lower magnification causes AMAG > 1.0
			  AMAG is the same as AMAGP in subr CALCFX
			- Note that the real space radii used in masking, e.g. RI, 
			  are divided by AMAG before being used to mask particle 
			  images whereas reciprocal space radius limits, e.g. MAXR1, 
			  are multipied by AMAG before being applied to particle 
			  transforms.
	RELMAG		- to adjust relative magnification of each dataset 
	ABSMAGP, ABSMAGPIN, ABSMAGS - absolute particle magnification input and summation
	NSET	- number of the dataset read in defined by cards 6 to 12, starts at 1.
	NSETST	- number of dataset on which first image IFIRST occurs, can be 1 or above.
	NNSET	- number of images in each dataset
	TARGET	- target phase residual below whcih search or refinement terminates
	THRESH	- phase residual threshold above which particles are not included in map
	MASK	- mask [psi, theta, phi, deltaX, deltaY] to select which of the 
		  5 parameters defining particle orientation and position are to be 
		  refined, [1 1 1 1 1] for all five.
	THETATR	- the diffraction angle of the first pixel in the transform of a particle
		  image, sampled at a pixel size of PSIZE
	STD,VTD	- sum of CTF**2 in PINSERT, then set to 0.1*mean value of CTF**2
		  essentially a small Wiener actor - could be increased
	FALL	- if T then all files O/P, if F (when RELMAG=-100) stops before symmetry.
	RBFAC, RBFACT	- absolute B-factor, and scaled coefficient for PRES damping

