PROCESSING PROGRAMS FOR 2-DIMENSIONAL CRYSTALS:
            -----------------------------------------------

1. LATREF:
----------

This program refines the lattice distances and angles for a computed 2-D
Fourier transform of a 2-D periodic array.
Positions of lattice points are measured as accurately as possible from
printed output of the transform; the program then calculates the average
lattice parameters in 3 cycles.
In the first cycle, the parameters are calculated from the average of all
the input points.
In the second cycle, those input points which are more than 3 transform
away from the calculated lattice point are rejected before calculating a
predicted lattice.
In the third cycle, only those input points within 0.7 transform steps of
latest predicted lattice are used in the calculation.
The final output includes the two reciprocal lattice spacings a* and b*,
also the angle between the transform X-axis and the a*-axis and the angle
between the a* and b* axes.

      	Data cards on unit 1:

      		ISHAPE, IPIXEL, RMAX  (*)
            		if ISHAPE < 3 :
      		      		RAD (*)
            		if ISHAPE = 3 :
      		      		XSIDE, YSIDE  (*)
      		      		ILIST, IHMAX, IHMIN, IKMAX, IKMIN  (*)
      		      		IH(J), IK(J), XD(J), YD(J)       (*)
      		ISHAPE hole shape defined in TRMASK i.e. :
      		       if = 1 hard edge circular holes
      		       if = 2 soft edge circular gaussian weighted to EXP(-2) at edge
      		       if = 3 hard edge rectangular holes
      		IPIXEL pixel size in TONE display of transform in 1/100 inch
      		RMAX cutoff radius (mm.) in transform for spots generated
      		RAD  radius for circular holes in mm.
      		XSIDE, YSIDE  half edge lengths for rectangular holes in mm.
      		ILIST  if ne 0 lattice points are listed and sent to file 
      			for TRMASK input
      		IHMAX, IHMIN, IKMAX, IKMIN specify the h and k limits for the 
      			calculated lattice.
      		IH(J), IK(J) are the (h,k) indices for a particular lattice 
      			point.
      		XD(J), YD(J) are estimated X & Y coordinated in mm. from F(0,0)
      			on TONE display
      			the lattice point on the printed transform output.
      	
      		Output refined lattice positions in TRMASK format on (OUT)



2. NNBOX :       Older program from 1980 - (JMS)
----------
    This program extracts data from selected areas of the Fourier transform
on disc by FFTRANS.
N x N arrays of amplitudes (on a linear scale) and phases are printed out
around selected lattice points, so that the lattice parameters can be
checked.
Intensities are integrated within a 3 x 3 array around the lattice point
and corrected for background intensity, which is estimated from the
average intensity around the perimeter of the N x N array.
An interpolated phase is calculated for the lattice point, from the
computed values of the 4 nearest transform points, by bilinear interpolation.
If required, the extracted amplitudes (square roots of background-corrected
intensities) and phases are written on to a disc area, ready for use by
programs performing subsequent steps in the analysis.

      Data Cards:


      TITLE                           (20A4)

      IPIXEL, ICOORD, NOH, NOK, NHOR,NVERT  (*)

      RINNER, ROUTER, XORIG, YORIG  (*)

      (if ICOORD < 0) :

      AX, AY, BX, BY  (*)

      (if ICOORD > 0) :

      IH(I), IK(I), X(I), Y(I)  (*)
      	 (up to 100 of these)
      
               -----------------------------------

      TITLE identifies the run.

      IPIXEL pixel size from TONE output

      ICOORD  = - 2 reciprocal lattice generated from 1,0 & 0,1 positions
                    in grid units (e.g. from TRNOUT output)
              = - 1 reciprocal lattice generated from 1,0 & 0,1 positions
                    in mm. (e.g. from TONE output)
              =   1 individual spot centres to be read in in mm.
              =   2 individual spot centres to be read in in grid units.

      NOH, NOK maximum number of orders of spots in h & k directions.

      NHOR, NVERT box size in mm. or grid units (see ICOORD) in horizontal
                  & vertical directions i.e X & Y respectively. Up to 21
                  in each direction.

      RINNER, ROUTER in mm or grid units set annulus in transform s.t. centre
                     of spots must fall inside to be included. Only used if
                     ICOORD < 0.

      XORIG, YORIG X & Y phase origin shifts to be added to those read in on
                   header of transform.

      AX, AY, BX, BY coordinates in mm or grid units of 1,0 & 0,1 spots resp.

      IH(I), IK(I) indices of individual spot

      X, Y  coordinates of individual spot in mm. or grid units (see ICOORD).




3. EMTILT:    Runs on-line with prompts
---------
  CALCULATE TILT ANGLES FROM TILTED AND UNTILTED RECIPROCAL CELL DEIMENSIONS.
        CONVENTION FOR MEASURING TILT AXIS TO ASTAR IS THAT THE ANGLE IS
        FROM TILTAXIS TO ASTAR IN THE DIRECTION GIVEN BY ASTAR TO BSTAR
        BEING POSITIVE.
           ***** TILT ANGLE PROGRAM - PETER SHAW 3.5.81
      		 UNTILTED ASTAR,BSTAR,GAMMASTAR ....?
      		 TILTED ASTAR,BSTAR,GAMMASTAR .....?


4.  TWOFILE:         last update 1-Jan-1992
-----------
     Program to perform simple additions or multiplications on 2 images of
      same dimensions and type (i.e. both must be real or both complex).

     Data   ICOMB
            WT1 , WT2   (Only needed if ICOMB=0)
            IORIGIN,ORIGXA,ORIGYA,ORIGXB,ORIGYB  (Only needed for complex)

       ICOMB=-1 Divide two image densities pointwise real or complex.
       ICOMB=0  Linear combination (Addition) with weights WT1, WT2
       ICOMB=1  Multiply two image densities pointwise, real or complex.
       ICOMB=2  Multiply first image point by complex conjugate of second
                 image point (only useful in complex image(Transform)).

       WT1,WT2  Weights for addition,   Result = (A*WT1 + B*WT2)

       IORIGIN   If 0, do not apply any extra origin shift (to complex images)
                If 1, apply origin shift ORIGXA,ORIGYA to image A(Stream IN1)
                If 2, apply origin shift ORIGXB,ORIGYB to image B(Stream IN2)
                If 3, apply origin shifts to images A and B

        First image on stream 1 (IN1)
        Second image on stream 2 (IN2)
        Added or Multiplied image output on stream 3 (OUT)


5.  MASKTRAN:         last update 12-Nov-1991
------------
  Program for masking a Fourier transform                                   *
     Input transform in standard format on stream 1 (IN)                    *
     Output masked transform in standard format on stream 2 (OUT)           *
     Control file contains parameters for generation of list of holes in    *
         mask on stream 5, normal input stream (MASK)                       *
                                                                            *
     Mask file in free format                                               *
                                                                            *
  -  first record  ISHAPE, IAMPLIMIT                                        *
     ISHAPE=1 Hard edge circular holes                                      *
          2 Soft edge circular holes (Gaussian weighted to EXP(-2) at edge) *
          3 Hard edge rectangular holes                                     *
     IAMPLIMIT  if T then spots allowed through mask are limited in their   *
                     maximum amplitude (they are reduced to 2x average)     *
                if F then no amplitude reduction is applied                 *
                                                                            *
  -  second record RAD       (ISHAPE = 1 or 2) radius (circular holes)      *
                DELX,DELY (ISHAPE = 3)  half edge lengths(rectangular holes)*
                                                                            *
  -  third record AX,AY,BX,BY,IHMIN,IHMAX,IKMIN,IKMAX,RMAX,ITYPE            *
       AX    etc, lattice parameters from refined NNBOX output in grid units*
       IHMIN etc, set min/max limits on H,K for lattice generator           *
       RMAX  Cutoff radius in transform for lattice generator in grid units *
       ITYPE if = 0, then generate all spots                                *
             if = 1, then include only spots of given index (see below)     *
                                                                            *
     Followed by record for each required spot to be allowed through mask   *
         IH,IK                                                              *
                                                                            *
     Derived from TRMASK(Version 1.04)22-SEP-82 (RAC)                       *
                                                                            *

6.  AUTOCORRL:
-------------
	This program was adapted from FFTRANS to include                *
	1.  Forward transform from image size NX,NY                     *
	2.  Squaring of transform and placing in larger area            *
	3.  Back transform to produce autocorrelation size NX3,NY3      *
                                                                        *
	Version	2.00	1.1.92	RH	Convert for Alliant, date only  *
	Version	2.01	3.1.92	RH	Debug and tidy-up               *
                                                                        *
                                                                        *
	 The real-space origin is at (1,1) and		                *
	the origin of reciprocal space is at (1,NY/2+1).		*
	The FT of an image NX,NY is NX/2+1,NY complex value.		*
									*
	  All transforms are done using Lynn ten Eyck's subroutines.	*
	These allow arbitrary-sized images having a LARGEST PRIME	*
	factor of 19!!.							*
									*
									*
									*
	Only input parameter determines change in size between input    *
	and output image boxes.                                         *
									*
	Logical I/O assignments are:					*
									*
	IN			input image      			*
	OUT			output autocorrelation			*
									*
									*



7.  QUADSERCHA:
--------------

       VX2.0   RH       1.1.92  convert to UNIX for Alliant

  ORIGINAL CROSS-CORRELATION SEARCHING PROGRAM 15.8.84
  SEARCHES A CROSS-CORRELATION MAP CALCULATED
  SEPARATELY BY THE FFT METHOD BUT GIVES OUTPUT CONSISTING
  OF A LIST OF CROSS-CORRELATION PEAKS AND POSITIONS.

  MODIFIED JUN 1987 TO HANDLE RECTANGULAR IMAGES.   JMB.
  MODIFIED FROM PROFSERCH DEC 1986.   JMB.

  NOW PREDICTS DIFFERENCE BETWEEN LATTICE POSITION AND SEARCH POSITION
  FROM LOCAL AREA NEAR POINT, OF DIMENSIONS +/- NRANGE IN A AND B.
  ON FIRST PASS ONLY THE AREA ALREADY PASSED IN THE SEARCH PROCEDURE
  CONTAINS USEABLE INFORMATION; 
  IN OPTIONAL SECOND PASS THE AREA AHEAD
  OF THE CURRENT POINT CONTAINS USEABLE INFORMATION STORED FROM PASS 1.

  THIS PROGRAM PRODUCES :-
        1. The file 'PROFDATA'; it contains the data for use in CCUNBENDA.
           First the information previously transferrd in file 'PIXPARMS';
           Then the list of best correlation peak positions and the
           heights of their correlation peaks.   
        2. A plot of the lattice positions searched in which; 1) error 
           vectors are shown X10; 2) peak heights are shown as grey levels.
	 3. The file 'ERRORS'; this contains a list of the differences
	    between actual positions of peaks and lattice positions. It
	    can be used in a second pass through this program if some
	    patches gave bad correlation peaks first time through and look
	    as if they could be improved with hindsight

-------CORRELATION PEAKS ARE SEARCHED FOR AROUND THEIR
-------EXPECTED POSITION BASED ON INPUT LATTICE PARAMETERS

 ON ALLIANT  --- as below
 fortran -g -uniproc -o quadsercha.exe quadsercha.for -limlib -lccp4 -lplot82

   FILE STRUCTURE IS
     INPUT:

     CARDS ON UNIT 5 : 
	1	IPASS,NRANGE		! controls search learning algorithm.
	2	FILENAME 		! name of cross-correlation file
	3	ISIZEX,ISIZEY		! SIZE OF TRANSFORM
	4	ASTR1,ASTR2,BSTR1,BSTR2	! Lattice vectors
	5	MINA,MAXA,MINB,MAXB	! NUMBER UNIT CELLS TO SEARCH
	6	KDC,KDR			! RADIUS OF CORR SEARCH
	7	IC,IR			! POSN OF SEARCH START (0,0 IS ORIGIN)
	8	IPRNT			! YES/NO FOR DETAILED PRINTOUT
	9	RADLIMP,RADLIMQ,RADANGP	! ELLIPTICAL CUTOFF.

	  IPASS	-0 no error input or output, simple search only.
		-1 writes error file with peak positions for use in later pass.
		-2 reads error file for use in better initial peak predict.
	  NRANGE- range of previous peaks used in prediction of next peak posn.
	  ISIZEX- size of transform in x-pixels (eg. 3000,3000)
	  ISIZEY-                  and y-pixels
	  ASTR1 - reciprocal space lattice vectors.
	  ASTR2 -	""
	  BSTR1 -	""
	  BSTR2 -	""
	  MINA  - number of unit cells to search for in each direction from
	  MAXA  - search origin IC,IR  e.g.(-120,120,-120,120)
	  MINB  -   ""
	  MAXB  -   ""
	  KDC   - search over +/- this number of pixels on each side of the
	  KDR   - predicted centre of each correlation peak.
	  IC    - position of search origin for the first correlation peak
	  IR    - relative to corner of image at 0,0 -  e.g.(1500,1500)
	  IPRNT - more (Y) or less (N) printout
	  RADLIMP- radius for profile fit in profile units in one direction
	  RADLIMQ- same in orthogonal direction -- (20x smaller than pixels)
	  RADANGP- angle relative to x-axis of RADLIMP (elliptical)
     INPUT FILES :
	  ERRORS      - (Created if IPASS=1); Read if IPASS=2; Contains
                     - list of XERROR,YERROR,PEAK found when IPASS=1
                     - not written or read if IPASS=0
         PROFILE     - Profile used for matching against correlation peaks.
                     - This has been previously obtained from procedure
                     - AUTOCORRL
     OUTPUT FILES:
         PROFDATA    - File contains;
                     - Parameters to be transferred between programs,
                     - including data read in here, maximum value of 
                     - peak height, raw list of correlation peak positions
                     - and heights produced by this program and to be used
                     - by CCUNBENDA
	  ERRORS      - Produced when IPASS=1; File contains list of
			 XERROR(IA,IB),YERROR(IA,IB),PEAK(IA,IB)




8.  CCUNBENDC:
-------------
		Original pre-history versions called CCUNBEND and CCUNBENDA. 

	VX 3.5	RH     15.6.90 

  CONTROL DATA :-
	CARD 1 : FILE NAME OF INPUT IMAGE FILE.(ONLY HEADER READ IF IOUT=0).
	CARD 2 : ITYPE,IOUT,IMAXCOR,ISTEP.
	CARD 3 : IKNOTX,IKNOTY,EPS,FACTOR,TLTAXIS
	CARD 4 : PLOT TITLE FOR DISTORTION CORRECTION DISPLAY.
      and if IOUT = 1,
	CARD 5 : FULL FILE NAME FOR OUTPUT OF CORRECTED IMAGE.
	CARD 6 : TITLE TO BE ADDED TO CORRECTED IMAGE TITLE RECORD.

   INPUT FILES:
         CCORDATA      - FILE OF PARAMETERS CONTAINING DETAILS OF
                          THE CCORSERCH RUN AND 
                       - RAW LIST OF CORRELATION PEAK POSITION AND HEIGHTS
                          PRODUCED BY CCORSERCH.
         PIX(NAME)     - ORIGINAL DENSITOMETER RAW IMAGE FILE.

   OUTPUT FILE:
         PIXOUT(NAME1) - THE UNBENT IMAGE FILE, FULLY CORRECTED FOR
                          THE SMOOTHED DISTORTION CORRECTIONS.
   OPTIONS ARE:
                         INTERPOLATION OF IMAGE DISTORTION TO PRODUCE
         ITYPE = 0 ----- USES CORRELATION PEAKS EXACTLY WITHOUT SMOOTHING.
               = 1 ----- SAME USING BICUBIC SPLINE FITTING (NAGLIB).

         IOUT  = 0 ----- NO OUTPUT, DIAGNOSTICS ONLY.
               = 1 ----- CORRECTED IMAGE OUTPUT USING THE SMOOTHED PARAMETERS
                          AS ABOVE.
         ISTEP --------- SIZE OF GRID ON WHICH THE INTERPOLATED VECTORS ARE
                          CALCULATED.
         IMAXCOR ------- SIZE OF THE MAXIMUM ALLOWED CORRECTION, TO ENABLE THE
                          SIZE OF EACH STRIP READ INTO CORE TO BE CALCULATED -
                          (ISTEP + 2*IMAXCOR).
                          CORRECTIONS LARGER THAN IMAXCOR ARE REDUCED.
			   A FURTHER LIMIT THAT IMAXCOR IS NOT GREATER THAN 
			   ISTEP WAS INTRODUCED IN Nov-88 TO KEEP THE PROGRAM
			   SIMPLE. BIGGER VALUES WILL NEED A MAJOR REWRITE.
         IKNOTX -------- NUMBER OF KNOTS TO BE DISTRIBUTED ACROSS IMAGE IN
                          BICUBIC SPLINE MODE OF SMOOTHING --  IKNOTX DESCRIBES
                          DISTORTIONS PARALLEL TO THE TILTAXIS.
         IKNOTY -------- NUMBER OF KNOTS -- IKNOTY DESCRIBES DISTORTIONS
                          PERPENDICULAR TO THE TILTAXIS -- THIS WILL NEED TO
                          BE SEVERAL TIMES HIGHER IF THE IMAGE IS OF A HIGHLY
                          TILTED SPECIMEN.
         EPS ----------- THRESHOLD FOR DETERMINATION OF RANK OF BICUBIC
                          SPLINE FITTING MATRIX. TRY 0.00001 --- OTHERWISE
                          SEE WRITE-UP FOR NAGLIB E02DAF SUBROUTINE.
         THRESH -------- THRESHOLD OF CROSS-CORRELATION PEAK HEIGHT,
                          CALCULATED AS;
                    DENMAX (READ FROM CCORDATA) * FACTOR (READ FROM UNIT 5),
                        , BELOW WHICH THE PEAK IS NOT USED.
         TLTAXIS ------- DIRECTION OF TILTAXIS RELATIVE TO NORMAL X-Y AXES OF
                          IMAGE.


9.  MMBOX:       last update   vx2.00  9-Jan-1992
---------        More sophisticated version of NNBOX


10. MMLATREF:    last update  24-Dec-1986
------------     refines lattice using transform of untilted mage


11. TTBOX:  last update vx2.01 6-Oct-1992  extra column on output     
---------   prints out amplitudes & phases in N * N boxes from a 
            Fourier transform, fully corrected for contrast transfer function
              in tilted image.


     DATACARDS ----------------------------------------------

  1.	FILIN -- full name of input file (.FFT)

  2.	ISER,TITLE (I10,17A4)

  3.	GENGRID   (A)

  4.	GENPTS    (A)

  4a.  LISTPTS   (A)
  4b.  PLOTPTS   (A)

  5.	ISIZEX,ISIZEY,DSTEP,XMAG,CS,KVOLT   (*)

  6.	DFMID1,DFMID2,ANGAST,TLTAXIS,TLTANGL   (*)

  7.	IOUT,NUMSPOT, NOH, NOK, NHOR, NVERT  (*)

  8.	FILOUT only if IOUT.NE.0 -- full name of output file, formatted data.

  9	RESMIN, RESMAX,  XORIG, YORIG, SEGMNT  (*)

  10.	if GENGRID or GENPTS :		AX, AY, BX, BY    (*)

  11.	if GENPTS 		        : IH(I), IK(I)              (*)
	if .not.GENGRID and .not.GENPTS : IH(I), IK(I), X(I), Y(I)  (*)


     ISER        serial number for run to be printed & output on IOUT.
     TITLE       title to be printed & output on unit IOUT.
     GENGRID     if YES generate grid from lattice points (1,0) & (0,1).
     GENPTS      if YES individual spots requested & generated from grid
		  if NO all spots within RESMIN to RESMAX generated.
     LISTPTS     if YES list spots whose amps and phases will be output.
     PLOTPTS     if YES plot spots with IQ<8 using symbol size propnl to 8-IQ
     ISIZEX,Y	  size of image in x and y, checked against file-header.
     DSTEP	  densitometer stepsize in microns.
     XMAG	  magnification of micrograph.
     CS	          spherical aberration coefficient in mm.
     KVOLT	  microscope voltage in KV, used to calculate wavelength. 
     DFMID1	  defocus in one direction (underfocus +ve) 
     DFMID2	  defocus at 90-degs to above
     ANGAST	  direction for DFMID1 in degrees relative to x,y in transform.
     TLTAXIS	  direction of tiltaxis in degrees relative to x,y in transform,
		    should be between -90 and +90 degrees.
     TLTANGL	  magnitude of tiltangle.
			(+ve for less underfocus at start of scan(y=0)).
			if tiltaxis is precisely parallel to y, then TLTANGL
			should be positive for less underfocus at x=0.
     IOUT         output unit number for serial number and title, followed by
    		   IH,IK,A,P,IQ terminated with IH=100.
     NUMSPOT      number of spots to be printed.
     NOH, NOK     number of orders of spots in H & K directions to be generated.
     NHOR, NVERT  box size in grid units in horizontal & vertical directions,
                  i.e. X & Y resp. ( up to 20 grid units in each
                  direction).
     RESMIN, RESMAX inner & outer resolution limits in Angstroms within which
			 spots(centre of box) must fall.
     XORIG, YORIG X & Y phase origin shifts to be added to those
                  added to those read in on the transform.
     SEGMNT       segment of reciprocal space within which spots
                  must fall to be include in this run. +/- 90
                  includes all spots, +45 is half data near tiltaxis
                  -45 is half perpendicular to tilt axis.
     AX,AY,BX,BY  coordinates in grid units of 1,0 & 0,1 spots
                  respectively.
     IH, IK       indices of individual spots required.
     X, Y         coordinates of individual spots required.


12. TTMASK:       last update 3-Jan-1992   vx2.00
----------
  Program for masking a Fourier transform, with simultaneous correction for *
     tilted contrast transfer function.                                     *
      									    *
     Output is written on top of input, so keep a copy if you think it will *
     need to be done more than once using different parameters.             *
									    *
     Input and output masked transform is on stream 1 (INOUT)               *
                                                                            *
     Data cards for control data file in free format                        *
                                                                            *
  1.	ISIZEX,ISIZEY,DSTEP,XMAG,CS,KVOLT              (*)                  *
                                                                            *
  2.	DFMID1,DFMID2,ANGAST,TLTAXIS,TLTANGL   (*)                          *
                                                                            *
  3.   ISHAPE=1 Hard edge circular holes      (*)                           *
          2 Soft edge circular holes (Gaussian weighted to EXP(-2) at edge) *
                                                                            *
  4.    RADMIN,RADMAX (ISHAPE = 1 or 2) radius (circular holes)   (*)       *
   	  MIN VALUE ON TILT AXIS; MAX VALUE AT 1200 rlu FROM TILT AXIS      *
         ISHAPE = 1 (Hard edged), = 2 (Gaussian fall off to exp(-2) at edge)*
                                                                            *
  5.  AX,AY,BX,BY,IHMIN,IHMAX,IKMIN,IKMAX,RMAX,ITYPE,NUMSPOT  (*)           *
       AX    etc,lattice parameters from refined NNBOX output in grid units *
       IHMIN etc, set min/max limits on H,K for lattice generator           *
       RMAX  Cutoff radius in transform for lattice generator in grid units *
       ITYPE if = 0, then generate all spots                                *
             if = 1, then include only spots of given index (see below)     *
                                                                            *
  6. Followed by record for each required spot to be allowed through mask   *
         IH,IK      (*)                                                     *
                                                                            *
     ISIZEX,Y	  size of image in x and y, checked against file-header.
     DSTEP	  densitometer stepsize in microns.
     XMAG	  magnification of micrograph.
     CS	          spherical aberration coefficient in mm.
     KVOLT	  microscope voltage in KV, used to calculate wavelength. 
     DFMID1	  defocus in one direction (underfocus +ve) 
     DFMID2	  defocus at 90-degs to above
     ANGAST	  direction for DFMID1 in degrees relative to x,y in transform.
     TLTAXIS	  direction of tiltaxis in degrees relative to x,y in transform,
		    should be between -90 and +90 degrees.
     TLTANGL	  magnitude of tiltangle.
			(+ve for less underfocus at start of scan(y=0)).
			if tiltaxis is precisely parallel to y, then TLTANGL
			should be positive for less underfocus at x=0.
                                                                            *

13. TTREFINE:  refines defocus, astigmatism, tiltaxis and tiltangle in images
------------	     of thin tilted crystals.
	  VERY IMPORTANT NOTE : The quality of image data required for success
	     in this type of least squares refinement is high, particularly
	     if more than one parameter is to be refined. BE VERY CAREFUL.

	Version 1.14    14 Jun 1989     RH      IQ=9 added.

 DATACARDS :

  1.    IMODE,NCYC,FSHIFT,LIST,LCF,MAXIM,LISTS,ISHIFT,IREF        (*)

  2.	FILIN -- full name of input file (.FFT)

  3.	ISIZEX,ISIZEY,DSTEP,XMAG,CS,KVOLT           (*)

  4.	NUMSPOT, NOH, NOK, NHOR, NVERT              (*)

  5.	RESMIN, RESMAX                              (*)

  6.	AX, AY, BX, BY                              (*)

  7.    ISPGRP,ORIGH,ORIGK,REVHK,ROT180,SGNXCH      (*)

  8.	DFMID1,DFMID2,ANGAST,TLTAXIS,TLTANGL   (*)  These are parameters which
						        can be refined.
  9.    FC=F SIGFC=SIGF PHCAL=PHS FOM=FOM ##    Program uses SIGFC as test for
						the presence of F and FOM as
						test for presence of phase. This
						data is input on stream LCF11.


     IMODE        if = 1 Defocus refined
		     = 2 Defocus and astigmatism refined.
		     = 3 Tiltaxis refined.
		     = 4 Tiltangle refined.
		     = 5 All five parameters refined.
     NCYC	  Maximum number of cycles of refinement.
     FSHIFT       Fractional shifts to be applied at each cycle.
     LIST         if T, list spots whose amps and phases will be used,
                       and list their resulting details.
     LCF          if T, reads in ref amplitudes from LCF(or non-LCF) file.
		  if F, uses dummy amplitudes, in which case the various
                       R-factors and residuals do not mean a lot.
     MAXIM        IF T, the program simply maximises the corrected diffraction
                        spot intensities.
                  if F, the program minimises the rms R-factor against LCF amps.
     LISTS        IF T, write output to data set 10 for use in statistics 
	                program
     ISHIFT       IF T, adds 1/3(ax + bx); 1/3(ay +by) to lattice points for use
                        in control calculations. If F does nothing.
     IREF	  if = 0 Set IREF=0. Read formatted data h,k,a,p; not LCF file
                     = 1 Use LCF file ---- only needed if LCf.eq.T

     ISIZEX	  size of image, used to check against image file-header.
     ISIZEY
     DSTEP	  densitometer stepsize in microns.
     XMAG	  magnification of micrograph.
     CS	          spherical aberration coefficient in mm.
     KVOLT	  microscope voltage in KV, used to calculate wavelength. 
     NUMSPOT      number of spots to be printed out at each cycle.
     NOH, NOK     number of orders of spots in H & K directions to be generated.
     NHOR, NVERT  box size in grid units in horizontal & vertical directions,
                  i.e. X & Y resp. ( up to 20 grid units in each
                  direction).
     RESMIN, RESMAX inner & outer resolution limits in Angstroms within which
			 spots(centre of box) must fall.
     AX,AY,BX,BY  coordinates in grid units of 1,0 & 0,1 spots
                         respectively.
     DFMID1	  defocus in one direction (underfocus +ve) 
     DFMID2	  defocus at 90-degs to above
     ANGAST	  direction for DFMID1 in degrees relative to x,y in transform.
     TLTAXIS	  direction of tiltaxis in degrees relative to x,y in transform,
		        should be between -90 and +90 degrees.
     TLTANGL	  magnitude of tiltangle.
			(+ve for less underfocus at start of scan(y=0))
			   (or if TLTAXIS is parallel to y, at x=0)
     ISPGRP	  two-dimensional space group number (1 - 17)
     ORIGH,ORIGK  phase origin shifts for (1,0) and (0,1) reflection to bring
		  phases to the precise crystallographic origin (from ORIGMERG).
     REVHK	  reverses H and K before comparing to reference data.
     ROT180	  rotates by 180 degs about c-axis. (needed in p3)
     SGNXCH	  rotates by 180 degs about a-axis. (needed in p121)

  The function which this program minimises (when LCF=.TRUE. and MAXIM=.FALSE.)
    is :-

    L = Sum of [1/sigma**2]*[Aobs-Aed*]**2

					where Aed is the scaled (sf+tf)
					   electron diffraction data.
					and Aobs is the result of con-
					   volution of the F.T. of the
					   image with the F.T. of the
					   function of ctf with position.
					See Henderson et al, Utramic.(1986).

14. TTBOXREF:  Refines lattice parameters in tilted image transforms,
------------       The data cards are similar to TTBOX and TTREFINE.

15. CTFREFINE:  Program to refine the ctf of a 2-dimensional crystal by altering
-------------      the defocus and astigmatism.

	Version 1.06	1.3.91		RH  bigger lcf curve storage NMAXC
      	    Rectangular images possible; ISIZEX given in data; Y components
      	    of lattice parameters must be scaled by ISIZEX/ISIZEY before input.
  INPUT :-
         PARAMETERS DESCRIBING IMAGE   (AS IN CTFPLOT,CTFAPPLY,ORIGTILT)
   CARD 0 : LIST LISTW QMAX ---
                        IF LIST=.TRUE. (T) GIVES EXTENSIVE OUTPUT OF NUMBERS
                        IF LISTW=.TRUE. GIVES INFORMATION FOR 'WILSON' PLOT
                                       AS FOR LIST=.TRUE. BUT FOR Q <= QMAX
   CARD 1 : AX AY BX BY ISIZEX DSTEP XMAG
   CARD 2 : DFMID1 DFMID2 ANGAST CS KV
   CARD 3 : TITLE FOR PLOT OF FINAL BEST FIT.
   CARD 4 : ORIGH ORIGK TAXA TANGL REVHK ROT180 SGNXCH
   CARD 5 : RESMIN RESMAX     RESOLUTION LIMITS TO BE USED IN ANGSTROMS.
               PARAMETERS DESCRIBING REFERENCE DATA
   CARD 6 : ISPGRP,IREF,NCYC
			(IREF=-1 if no reference data available)
                        (IREF=0 FOR PROJECTION DATA)
      			(IREF=1 FOR 3D LCF FILE DATA)
                         NCYC IS MAX NUMBER OF CYCLES OF CTF REFINEMENT.
   CARD 7 : FC=F SIGFC=SIGF PHCAL=PHS FOM=FOM ## (IF IREF=1 LCF CONTROL)
				PROGRAM USES SIGFC AS TEST FOR PRESENCE OF F
				AND FOM AS TEST FOR PRESENCE OF MEASURED PHASE.

         AX,AY   - LATTICE PARAMETERS (FROM NNBOX) OF (1,0) AND (0,1)
         BX,BY   -                                     IN GRID UNITS.
         ISIZEX  - SIZE OF DENSITOMETERED ARRAY IN X DIRECTION (E.G. 2048)
         DSTEP   - DENSITOMETER STEPSIZE IN MICRONS
         XMAG    - PRECISE MAGNIFICATION NORMALLY WORKED OUT FROM LATTICE
                    PARAMETERS AND KNOWN CELL DIMENSIONS.
         DFMID1  - DEFOCUS LEVEL (UNDERFOCUS +VE). IF DFMID2=DFMID1, IMAGE
         DFMID2  -  IS NON-ASTIGMATIC. OTHERWISE AMOUNT OF DEFOCUS IN TWO
                    ORTHOGONAL DIRECTIONS, DFMID! BEING DEFOCUS IN DIRECTION
                    ANGAST (DEGS) RELATIVE TO X AND Y OF THE FOURIER TRANSFORM
         CS      - SPHERICAL ABERRATION IN MM.
         KV      - E.M. ACCELERATING VOLTAGE

  DATASTREAMS
   'INIMAGE'   - INPUT OF IMAGE DATA           	 H K AMP PHS IQ RMSBK
   'INREF'     - INPUT OF REFERENCE PROJECTION DATA	 H K FOBS(I) PHASE
			( IF FOBS BUT NO PHASE, SET PHASE = -999.0 )
   'HKLIN'     - INPUT OF REFERENCE 3D LCF DATA

  PARAMETERS TO BE CALCULATED
        (A)...PHASE AGREEMENT OVERALL, IF REFERENCE PHASE DATA EXISTS.
        (B)...CORRELATION COEFF BETWEEN IMAGE AND REFERENCE AMPLITUDES.

  THE FUNCTION MINIMISED WILL BE :-
         L =  Sum of [(1/SIGMA**2) * (FIM**2-FREF**2*CTF**2)**2]
  THIS IS THE SAME AS MAXIMISING      (1/SIGMA**2) * FIM**2 * FREF**2 * CTF**2

		where SIGMA = standard deviation of FIM**2

16. CTFAPPLY:
------------
  CTFAPPLY : derived from CTFPLOT giving automatic application of C.T.F. to
             phases input from MMBOX and output ready for ORIGTILT.
  PROGRAM PLOTS SPOTS FROM MMBOX IN RECIPROCAL SPACE AND C.T.F. PLOT OF IMAGE.

	V1.03	13.6.90		RH	Minor change to FORMAT statement 105.
	V1.04	6.10.92		RH	Extended o/p format h,k,A,P,IQ,BCK,CTF

  INPUT PARAMETERS
      CARD 1    AX AY BX BY ISIZE DSTEP XMAG
      CARD 2    DFMID1 DFMID2 ANGAST CS KV
      CARD 3    ISER TITLE

         AX,AY   - LATTICE PARAMETERS (FROM NNBOX) OF (1,0) AND (0,1)
         BX,BY   -                                     IN GRID UNITS.
         ISIZE   - SIZE OF DENSITOMETERED ARRAY (E.G. 2048)
         DSTEP   - DENSITOMETER STEPSIZE IN MICRONS
         XMAG    - PRECISE MAGNIFICATION NORMALLY WORKED OUT FROM LATTICE
                    PARAMETERS AND KNOWN CELL DIMENSIONS.
         DFMID1  - DEFOCUS LEVEL (UNDERFOCUS +VE). IF DFMID2=DFMID1, IMAGE
         DFMID2  -  IS NON-ASTIGMATIC. OTHERWISE AMOUNT OF DEFOCUS IN TWO
                    ORTHOGONAL DIRECTIONS, DFMID1 BEING DEFOCUS IN DIRECTION
                    ANGAST (DEGS) RELATIVE TO X AND Y OF THE FOURIER TRANSFORM
         CS      - SPHERICAL ABERRATION IN MM.
         KV      - E.M. ACCELERATING VOLTAGE
         ISER    - SERIAL NUMBER AT HEAD OF OUTPUT FILE.
         TITLE   - TITLE FOR OUTPUT FILE.

   INPUT  DATASTREAM  'IN'
   OUTPUT DATASTREAM  'OUT'




17. ORIGTILTB :   
-------------
   THREE-DIMENSIONAL IMAGE COMBINING PROGRAM FOR ALL SEVENTEEN TWO-SIDED PLANE 
        GROUPS -------- ORIGIN, BEAMTILT AND CRYSTAL TILT REFINEMENT.

      VERSION VX3.02  RH  4.3.91 
      NOTE: TILT REFINEMENT (CRYSTAL AND BEAM) HAS BEEN TESTED ONLY IN
					P3		30.12.84
					P22121		  8.8.88

      ORIGINAL PROGRAM WRITTEN BY S.D.FULLER, 10-MAY-1980.
      THIS VERSION --
                     PRODUCES PLOTTER O/P ON FILE PLOT.PLT(SUBROUTINE GRAPH)
                     PRODUCES A MERGED LIST OF H,K,ZSTAR,AMPL,PHASE,FILMNO,
                        DESCRIPTIVE CODE(+/-IQ) ON UNIT 3.
                     THE MERGED LIST CAN THEN BE READ IN AND USED FOR
                        CYCLICAL ORIGIN REFINEMENT.
                     REFINES CRYSTAL TILTAXIS AN TILTANGLE.
                     REFINES BEAMTILT (MANIFESTED AS A RESOLUTION-DEPENDENT
                        SHIFT OF THE PHASE ORIGIN).

###############################################################################

               CARD INPUT ON UNIT 5

   1  ISPGRP,NPROG,NTILT,NBEAM,ILIST,ALNG,BLNG,WIDTH,ANG,IPLOT,MINRFL   (*)

   2  IRUN,LHMIN,LHMAX,IQMAX,IBOXPHS,NREFOUT,NSHFTIN                    (*)

   IF NPROG.EQ.0
       THE FIRST SET OF REFLECTIONS MUST BE FOR AN UNTILTED
       IMAGE AND ONLY THE UNIQUE REFLECTIONS SHOULD BE PROVIDED
       THIS OPTION IS MEANT FOR MERGING RAW DATA -- AS IN ORIGINAL
       ORIGMERG.
   IF NPROG.EQ.1
       THE FIRST SET OF DATA READ IN WILL BE FROM O/P OF A PREVIOUS
       RUN OF ORIGMERG (UNIT 3 O/P). SUBSEQUENT FILMS WILL BE COMPARED
       ONLY WITH THIS FIRST SET AND NO OUTPUT WILL BE POSSIBLE.
       THIS OPTION IS MEANT FOR ORIGIN REFINEMENT OF AN ALREADY 
       MERGED SET OF DATA.

                3  IFILM,TITLE                           (I10,10A4)

                3A Filename -- e.g. SS1:[RH15]P4151.APH           (A)

                4  ISER                                           (*)

                5  IH,IK,A,P                                      (*)

                6  IH=900  --- THIS ENDS THE SET OF REFLECTIONS

   IF NPROG.EQ.2    (NO INPUT OF ABOVE CARDS 3,4,5, or 6)
       THE REFERENCE DATA IS A THREE-DIMENSIONAL LCF DATA FILE.
       THIS OPTION IS MEANT FOR STRUCTURES THAT HAVE BEEN WELL
       WORKED OVER ALREADY -- E.G. PURPLE MEMBRANE.
          Input is on file with name HKLIN for LCF file.

   BUT          3  FC=.... PHCAL=.... FOM=....  ##          (LCF CONTROL)
  
       PROCEEDS ACCORDING TO NPROG.EQ.1, BUT REFINEMENT IS DONE AGAINST
       AMPLITUDE AND PHASE CURVE-FITTED DATA. THE PHASE ORIGIN IS REFINED
       AS WELL AS (if NTILT=T) THE TILTANGLE AND TILTAXIS. THIS REFINEMENT
       OF ORIGIN AND TILT IS CARRIED OUT SEPARATELY UNTIL THERE IS
       NO FURTHER CHANGE IN THE PARAMETERS.

   7  IFILM,TITLE                                   (I10,10A4)

   7A Filename -- e.g. SS1:[RH15]P4151.APH           (A)

   7B NWGT                                                        (*)

   8  TAXA,TANGL,IORIGT                                           (*)

   9  ORIGH,ORIGK,STEP,WIN,SGNXCH,SCALE,ROT180,REVHK,CTFREV       (*)

   9a CS,KV,TILTH,TILTK                                            (*)

   9b DRESMAX, DRESMIN (BLANK CARD GIVES 100.0,3.5)                 (*)

  10  ISER                                                        (*)

  11  IH,IK,A,P,IQ                                                (*)

  12  IH=900  --- THIS ENDS THE SET OF REFLECTIONS.

            ANY NUMBER OF FURTHER IMAGES SPECIFIED BY CARDS 10-12 CAN
            BE INCLUDED AT THIS STAGE.

  13  IFILM<0  --- THIS ENDS DATA INPUT

  14 TITLE --- TITLE FOR PLOT OUTPUT IF REQUESTED.		(20A4)
   	
###############################################################################


                 ISPGRP - NUMBER OF SPACE GROUP AS BELOW
		 NPROG  - DETERMINES TYPE OF RUN
		          IF =0, NORMAL SEQUENTIAL MERGING (OLD ORIGMERG).
		          IF =1, READS IN PREVIOUSLY MERGED DATA O/P ON UNIT 3.
                         IF =2, READS IN REFERENCE DATA FROM LCF FILE.
		 NTILT  -  IF (F) NO CRYSTAL TILTANGLE OR TILTAXIS REFINEMENT.
		           IF (T) CRYSTAL TILTANGLE AND TILTAXIS ARE REFINED.
                 NBEAM  -  IF (F) NO BEAMTILT REFINEMENT.
                          IF (T) BEAMTILT IS REFINED -- IN MILLIRADIANS.
                 ILIST  - IF =1 PROGRAM LISTS EACH REFLECTION OTHERWISE
                           ONLY THE PLOT OF RESIDUALS AND THE FINAL
                           COMBINED LIST OF REFLECTIONS IS GENERATED
                 ALNG   -  A AXIS IN ANGSTROMS for untilted crystal.
                 BLNG   -  B AXIS IN ANGSTROMS        "        "   .
                 WIDTH  -  THICKNESS OF UNIT CELL IN ANGSTROMS
                 ANG    -  ANGLE BETWEEN A AND B - ONLY FOR P1 OR P2
                 IPLOT  -  IF NOT 0, PLOT FINAL AMPLITUDE & PHASE CURVES
                            ON CALCOMP PLOTTER
                 MINRFL -  MINIMUM NUMBER OF POINTS REQUIRED FOR A CURVE
                            TO BE PLOTTED
                 IRUN   - RUN NUMBER, USED AS AN IDENTIFIER ON UNIT 3 O/P
                 LHMIN  - MINIMUM H INDEX TO BE PLOTTED
                 LHMAX  - MAXIMUM H INDEX TO BE PLOTTED
                              (PROGRAM STOPS AFTER LAST PLOT)
                 IQMAX  - REFLECTION NOT USED FOR ORIGIN OR TILTANGLE
                           REFINEMENT IF IQ>IQMAX
                 IBOXPHS- SIZE OF PHASE ORIGIN SEARCH, (DEFAULT = 121)
                 NREFOUT-  IF (F) NO OUTPUT OF REFERENCE PROJECTION DATA.
                           IF (T) FILE IS CREATED WITH REFERENCE PROJECTION
                                 DATA AT SAME ANGLE AS INPUT DATA.
                 NSHFTIN-  IF (F) NO OUTPUT OF ORIGIN SHIFTED INPUT DATA
                           IF (T) FILE IS CREATED FROM SHIFTED INPUT DATA
                 IFILM  - INTEGER FILM IDENTIFIER
                 TITLE  - DESCRIPTION OF FILM
                 NIN    - UNIT NUMBER OF INPUT DATA STREAM * NOT USED NOW
                 FILIN  - NAME OF FILE CONTAINING H,K,A,P,IQ DATA
                 NWGT   - IF (T) THEN READ EXTRA FLMWGT DATA FOR EACH REFLECTION
                         IF (F) THEN NO EXTRA WEIGHT DATA.
                 ISER   - SERIAL NUMBER OF FILM ON UNIT NIN, MUST=IFILM.
                 IH     - H INDEX OF REFLECTION
                 IK     - K INDEX OF REFLECTION
                 P      - PHASE OF REFLECION
                 A      - AMPLITUDE OF REFLECTION
                 IQ     - QUALITY OF REFLECTION
                 TAXA   - ANGLE MEASURED FROM THE TILT AXIS TO THE A-AXIS,
                          MEASURED IN DIRECTION OF A TO B BEING POSITIVE.
                 TANGL  - TILT ANGLE IN DEGREES
                 IORIGT - IF IORIGT=1, ORIGIN REFINEMENT IS DONE WITH
                              WGT = 1.0 FOR EACH NEW SPOT.
                 ORIGH  - INITIAL PHASE SHIFT FOR 1,0 -- IN DEGREES
                 ORIGK  - INITIAL PHASE SHIFT FRO 0,1 --  "    "
                 STEP   - STEP SIZE IN DEGREES FOR ORIGIN REFINEMENT
                          STEP = 0 ==> NO REFINEMENT
                 WIN    - ZSTAR RANGE WITHIN WHICH SPOTS ARE COMPARED
                          FOR SCALING AND ORIGIN REFINEMENT
                 SCALE  - MULTIPLIED BY AMPLITUDES BEFORE COMBINATION
                         IF EQUAL TO 0 SCALING IS AUTOMATIC
                 SGNXCH - IF NOT EQUAL TO 0, FLIP AROUND A AXIS, USEFUL IN P121
                 ROT180 - IF NOT=0, ROTATE 180 DEG ABOUT Z-AXIS, USEFUL IN P1,P3
                 REVHK  - IF NOT = 0, H AND K ARE INTERCHANGED ON INPUT.
                          THIS IS A COSMETIC FEATURE TO FACILITATE INDEXING
                          DIFFICULT HIGHLY TILTED FILMS. NOTE THAT ALL OTHER
                          PARAMETERS, SUCH AS TAXA,TANGL MUST REMAIN CORRECT
                          W.R.T. THE ORIGINAL DIRECTIONS FOR H AND K.
		  CTFREV - IF NOT = 0, 
			  REVERSES SIGN OF STRUCTURE FACTOR BY ADDING 180 DEGS
			  TO THE PHASE. USEFUL FOR LOW DOSE IMAGES WHERE THERE
			  IS UNCERTAINTY ABOUT WHETHER IMAGE IS OVER-FOCUSSED
			  OR UNDER-FOCUSSED.
                 CS     - SPHERICAL ABERRATION COEFFICIENT - USED TO GET
                            BEAMTILT ON RIGHT ABSOLUTE SCALE OF MILIRADIANS.
                 KV     - MICROSCOPE VOLTAGE - USED TO CALCULATE WAVELENGTH.
                 TILTH  - BEAMTILT IN DIRECTION OF ASTAR.
                 TILTK  - BEAMTILT IN DIRECTION OF BSTAR.

###############################################################################

    OUTPUT IS MADE VIA
         UNIT   6 - LINEPRINTER
         UNIT   3 - MERGED DATA POINTS(H,K,ZSTAR,AMPL,PHASE,FILMNO,IQ CODE --
                     CAN BE USED BY ORIGREFN FOR FURTHER CYLES OF REFINEMENT.
         PLOT.PLT - PLOT FILE FOR PLOT OUTPUT.
         UNIT   2 - If requested, origin shifted H,K,0,AMP,PHASE of projection.
         UNIT   4 - If requested, H,K,0,REFAMP,REFPHASE for refdata projection.

    INPUT IS MADE VIA
         UNIT   5 - CONTROL DATA
         UNIT 10  - NEW IMAGES TO BE MERGED, OR PREVIOUSLY MERGED DATASET
         LCF11    - LCF FILE OF AMPLITUDES AND PHASES. (for NPROG.EQ.2)



C     NUMBER   SPACEGROUP    ASYMMETRIC UNIT        REAL   IMAGINARY
C
C          1          P1         H>=0
C
C          2         P21         H,Z>=0              Z=0
C
C          3         P12         H,K>=0              K=0
C
C          4        P121         H,K>=0              K=0
C
C          5         C12         H,K>=0              K=0
C
C          6        P222         H,K,Z>=0            H=0
C                                                    K=0
C                                                    Z=0
C
C          7       P2221         H,K,Z>=0          (0,2N,Z)  (0,2N+1,Z)
C                                                    (H,K,0)
C                                                    (H,0,Z)
C
C          8      P22121         H,K,Z>=0            (H,K,0)
C                                                   (2N,0,Z)  (2N+1,0,Z)
C                                                   (0,2N,Z)  (0,2N+1,Z)
C
C          9        C222         H,K,Z>=0            (H,K,0)
C                                                    (H,0,Z)
C                                                    (0,K,Z)
C
C         10          P4         H,K,Z>=0            (H,K,0)
C
C         11        P422         H,K,Z>=0            (H,K,0)
C                                K>=H                (H,0,Z)
C                                                    (0,K,Z)
C                                                    (H,H,Z)
C
C         12       P4212         H,K,Z>=0            (H,K,0)
C                                K>=H                (H,H,Z)
C                                                   (2N,0,Z)   (2N+1,0,Z)
C                                                   (0,2N,Z)   (0,2N+1,Z)
C
C         13          P3         H,K>=0
C
C         14        P312         H,K>=0              (H,H,Z)
C                                K>=H
C
C         15        P321         H,K>=0              (H,0,Z)
C                                 K>H                (0,K,Z)
C
C         16          P6       H,K,Z>=0             (H,K,0)
C
C         17        P622         H,K,Z>=0            (H,K,0)
C                                K>=H                (H,H,Z)
C

18.LLFILT:
---------

Program to do sinc-function fitting to experimental lattice line
data to produce smooth curves and equally spaced interpolated values.
Graphical output of results on line printer and formatted file
of structure factors on disc. Present version cannot impose any
space group symmetry on the lattice lines.  Input from ORIGMERG.
Uses the LINFIL package for solving the linear interpolation
equations.

Input ORIGMERG data on stream 1  (IN)
Output structure factors on stream 2 (OUT)

DATA CARDS:

   1.   TITLE (10A4)
   2.   THICK,FILT,CUTOFF,IGRPH,FSCA,ZMIN,ZMAX (*)
   3.   ACELL,BCELL,GAMMA (*)


     TITLE is header for plots
     THICK is virtual specimen thickness in angstroms used to set
            spacing of sinc functions
     FILT  is filter level for least squares in LINFIL. Generally
            a value of 0.01 will do but depends on noise level.
     CUTOFF  is Fourier cut-off for fitted structure factors in
            reciprocal Angstroms.
     IGRPH = 0  no graphical output
             1  graphs of layer line data plotted.  Data points as (x),
                fitted points as (o).
     FSCA  = 0. gives auto scaling of graphs
         .NE.0. gives constant scaling of graphs with FMAX=FSCA
     ZMIN, ZMAX  min max zstar along lattice lines - used for drawing
            box for graphs.  In reciprocal Angstroms.
     ACELL, BCELL, GAMMA    2-D cell dimensions (angstroms, degrees) in
            plane - used for calculating Fourier cutoff


19. LATLINE:
-----------
	  This is a program to do fitting of curves to either		*
	Intensity or F,Phi data for individual layer lines.		*
	Individual weights are used for F's and phases (or I's)		*
	Normally a trial set of A,B for each lattice line are		*
	input (optionally this can be calculated internally).		*
	This trial set is then refined to minimize the weighted		*
	least-squares error between F's and Phases.			*
									*
	Version  1.23		24.12.82 	DAA	VAX		*
        Version  1.24           07.12.88        JMB
      				Option IWP=-2: sigphi input in degrees  *
                                Guessed phase is weighted               *
                                AK adjusted by factor nfobs/nphases     *
                                Symbols on phase plot show input sigphi *
	Version  1.25		15.3.91  RH   remove determinant test   *
									*
									*
	Input parameters (unit 5):					*
									*
	TITLE		80 Character title for this data set		*
									*
	IPG		Plane group number (1-17)			*
									*
	IPAT		0 for F & Phase     1 for Intensity data	*
									*
	AK,IWF,IWP	AK = relative weights for phases with		*
			respect to the F's				*
			IWF,IWP are flags to use individual weights	*
			for F's and Phases in input file:		*
			-1 : use individual sigmas   (1/sigma**2)	*
			 0 : set all weights = 1.0			*
			 1 : use individual weights			*
                 IWP=  -2 : use individual sigmas; (wt=1/sigma**2);    *
                          : phase and sigma both input in degrees   	*
	ALAT,ZMIN,ZMAX,DELPLT						*
			ALAT = lattice size in angstroms		*
			ZMIN = minimum z* value expected for data set	*
			ZMAX = maximum z* value expected for data set	*
			DELPLT = z* interval for plotting		*
			if DELPLT = 0.0, then no plotting		*
									*
	DELPRO,RMIN,RMAX,RCUT,PFACT					*
			DELPRO = real-space  or patterson-space		*
			sampling interval for profile function		*
			(in angstroms)					*
			RMIN,RMAX lower,upper boundaries for 		*
			profile function (angstroms)			*
			in general RMIN = -RMAX				*
			note, overall boundary width must be 2x		*
			as wide for Intensities compared to F,Phase	*
			RCUT = distance from either boundary to		*
			point where tapering of profile is to start	*
			(in angstroms) see also PFACT			*
			PFACT controls mode of tapering, starting	*
			RCUT inside of RMIN/RMAX and going towards	*
			RMIN/RMAX. 					*
			PFACT <= 0  then use linear drop off to zero	*
			at RMIN/RMAX					*
			PFACT > 0  then use gaussian roll-off where	*
			PFACT = value of gaussian at RMIN/RMAX		*
			(a value of .1 is reasonable)			*
									*
	IGUESS,BINSIZ							*
			IGUESS = 0 to refine input set of lattice data	*
			       = 1 to generate a new set		*
			BINSIZ = delta z* for binning observations	*
			This is only used to generate the initial	*
			guess, which is then refined against the	*
			actual obsered data points.			*
			(a value of .005 to .002 is reasonable)		*
									*
	NCYCLS,MPRINT   Number of refinement cycles to perform.		*
			If  <0  then output initial guess.		*
			If  =0  then minimizer goes till end		*
			     else (25-50 is quite reasonable)		*
	                If MPRINT >0, print var/covar matrix            *
	                          =0  do not                            *
									*
									*
									*
	Data formats (all are free-format):				*
									*
	Observed data  [logical unit = OBS] :				*
	H, K, Zstar, Fobs, Phiobs, Weight on Fobs, Weight on Phiobs	*
									*
	If no Fobs for this Zstar you must set Fobs=-999.		*
	If no Phiobs for this Zstar you must set Phiobs=-999.		*
									*
	For Intensity data:						*
	Fobs    actually = Iobs						*
	Phiobs  should be 0						*
									*
	It is assumed that the H,K are in the correct asymmetric	*
	unit for the symmetry operators to be valid.			*
	The data can be un-sorted on Zstar.				*
									*
									*
	Initial guess for the lattice data  [logical unit = GUESS] :	*
	H, K, Zstar, AMP, PHASE						*
									*
	H,K must correspond to the H,K that is on the observed		*
	data file. Data must be sorted in order of increasing Zstar	*
	and MUST be in equal intervals of Zstar. The actual sampling	*
	interval is not critical, as long as it is the same or finer	*
	than the critical sampling interval of 1./(RMAX - RMIN)		*
	If the plane group has an inversion-center along Zstar		*
	then only Zstar >= 0 are allowed; the first value must		*
	correspond to Zstar=0.						*
									*
									*
	Output data  [logical unit = OBS] :				*
									*
	H, K, Zstar, Fcalc, Phicalc, SigmaF, SigmaPhi, Figmerit		*
		the figure of merit = cos(Sigmaphi)			*
									*
	Plots are generated on   [logical unit = PLOT] 			*
									*


20. THREEFOLD:              last update 1-Jul-1985
-------------
   REFINEMENT OF PHASE ORIGIN AND BEAM TILT IN PURPLE MEMBRANE PROJECTION
   IMAGES.
     MORE SOPHISTICATED UPDATE 12.11.84, NOW CONTAINS OPTIONS TO CARRY OUT :-
   (A) PHASE ORIGIN SEARCH, ENABLES BEST PHASE ORIGIN TO BE FOUND REGARDLESS
	OF HOW FAR FROM IT THE INITIAL ESTIMATE IS.
   (B) PHASE ORIGIN REFINEMENT. THIS CARRIES OUT LEAST SQUARES REFINEMENT
	TO MINIMISE PHASE RESIDUAL, ONCE THE PHASE ORIGIN MINIMUM IS NEAR.
	THE STARTING POINT CAN BE EITHER THE INPUT ORIGIN OR THE VALUES 
	DETERMINED IN (A).
   (C) PHASE ORIGIN AND BEAM TILT REFINEMENT. FOUR PARAMETERS ARE REFINED 
	HERE TO COMPENSATE FOR ALL IMAGE PARAMETERS. BEAM TILT CAUSES THE
	APPARENT THREEFOLD ORIGIN TO MOVE ALONG A LINE WHEN SPOTS OF
	DIFFERENT RESOLUTION ARE CONSIDERED. THE STARTING POINT FOR PHASE
	ORIGIN IS THE OUTPUT FROM (A) OR (B), OR THE INPUT VALUES. THE 
	STARTING POINT FOR THE BEAM TILT IS EITHER (0,0) OR THE INPUT VALUES.
 
                                  ##############

   CARD INPUT

   ON UNIT 'IN'
	   ANY NUMBER OF SPOTS WITH ANY INDEX (PRECEDED BY TITLE LINE)
          H, K, AMPLITUDE, PHASE

   ON UNIT 5
   1.  SEARCH,REFINE,TILT,NYC	3*(LOGICAL*1), I5 (* FORMAT)
		IF TRUE(T) THEN APPRORIATE OPERATION IS PERFORMED.
		THE SEQUENCE OF OPERATIONS IS PERFORMED IN THE ORDER SHOWN.

   2.  ORIGH,ORIGK,TILTH,TILTK
	  STARTING ORIGIN PHASE SHIFT AND STARTING BEAM TILT.

   3.  STEP,ISIZE
       PHASE-SHIFT STEP AND SIZE OF SEARCH AREA FOR PHASE ORIGIN GRID SEARCH.
       IF GRID IS 121 X 121,A STEPSIZE OF 3 DEGREES WILL COVER WHOLE CELL.

   4.  CELL,RIN,ROUT,CS,KV
	  CELL DIMENSION AND RESOLUTION RANGE IN ANGTROMS, SPHERICAL ABERRATION
	  AND MICROSCOPE OPERATING VOLTAGE (USED TO CALC WAVELENGTH).

   5.  ILIST,ROT180,IQMAX
	  ILIST=1 GIVES MORE DETAILED OUTPUT
	  ROT180=1 ENABLES SAME CONVENTION AS OTHER PROGRAMS TO BE USED FOR
	    P3 INDEXING CONVENTION.

                              #############

   12.10.84  PERFORMS SORTING OF THE INPUT SPOTS SO THAT ANY FILE OF SPOTDATA
             CAN BE USED FOR THE REFINEMENT.
		INDEX IS EITHER H>0 AND K>=0 OR RELATED TO THIS BY
		     THE THREEFOLD ROTATION.
		SPOTS HAVE THEIR INDEX CHANGED ON INPUT SO THAT THEY CONFORM
		TO THE ABOVE CONVENTION.
   16.6.85   R-FACTOR MINIMISATION (NOT LEAST SQUARES) OF THE RECIPROCAL
               SPACE DISTANCE ERROR
		L = SUM OF 2 * SIN(ABS(PHASEDIFF/2))


21. AVRGPHASES:              last update 21-Sep-1987
--------------
      PROGRAM TO OBTAIN WEIGHTED AVERAGE PHASES FROM MERGED LIST
      		INPUT IS OUTPUT FROM ORIGMERG
            	OUTPUT TO INCLUDE EXPERIMENTAL RESIDUAL AND MERGED FOM