2.04                      *******************
                                  * MAPINV WRITE-UP *
                                  *******************
        
        PURPOSE- To calculate three dimensional Fourier coefficients
                 (structure factors) when given an electron density
                 map and control cards.
        
           This program will calculate structure factors by using a 
        multivariate variable radix fast Fourier transform algorithm to invert 
        an electron density map. The program is fully general so that all 
        space groups can be handled.  It is assumed that the input map was 
        prepared by program FSFOUR.  Structure factors may be calculated for
        reflections in the following range:
                       h .ge. -NX/2  and  h .lt. NX/2
                       k .ge. -NY/2  and  k .lt. NY/2
                       l .ge. 0      and  l .lt. NZ/2
        where NX, NY, NZ are the number of grid points along the a, b, and c 
        axes, respectively, in the input map.
        
        
                            INPUT DATA  (UNIT 5)
        
         CARD 1     PAMFIL               (free format)
        
                    PAMFIL = Name of input file containing cell and symmetry
                             parameters.
        
        
         CARD 2     TITLE                (free format)
        
                    TITLE = anything
        
        
         CARD 3     MAPFIL               (free format)
        
                    MAPFIL = Name of input map file.
        
        
         CARD 4     SFOUT                (free format)
        
                    SFOUT = Name of output structure factor file.
               
        
         CARD 5  IPRNT, IPAIR, HMIN, HMAX, KMIN, KMAX, LMAX  (free format)
        
                                  IPRNT = 0 for no printing of structure
                                            factors.
                                        = 1 for printout
        
        
                                  IPAIR = 0 for no pairing of calculated
                                            structure factors with observed
                                            data.
                                        = 1 to combine calculated structure
                                            factors with observed data 
                                            (supplied on auxilliary file) and 
                                            output R factor to the line printer
                                        = 2 same as 1, but a separate file with
                                            the combined data is also written.
                                            
        
                                  HMIN  =
        
                                            limiting values defining range of
                                  HMAX  =
        
                                            indices for which structure factors
                                  KMIN  =
        
                                            will be calculated
                                  KMAX  =
        
                                            (LMIN is always 0)
                                  LMAX  =
        
                            
         CARD 5A   AUXINP         (free format)
        
              ***** This card should be included ONLY if IPAIR > 0 *****
        
         AUXINP = Name of input file containing auxilliary structure
                  factors for scaling.
                   
        
         CARD 5B   AUXOUT         (free format)
        
              ***** This card should be included ONLY if IPAIR = 2 *****
        
         AUXOUT = Name of output file to contain calculated structure
                  factors scaled to (and paired with) the auxilliary
                  structure factors.
        
        
         CARD 6  SC, F000, IMOD, IRHOMN     (free format)
        
        
                             SC  =   scale factor applied to calculated
                                     structure factors (see below).
                                     If 0. defaults to 1.
        
                            F000 =   total number of electrons in the unit 
                                     cell (see below).
        
                            IMOD = 0 for no modification of map prior to
                                     transformation
        
                                 = 1 to modify map prior to transformation  
                                     according to input criterion
        
                                 =-1 same as 1 but the resulting density
                                     is also squared prior to transformation.
        
                          IRHOMN =   modification criterion (applied if   
                                     IMOD .ne.0). If (rho input + IRHOMN) < 0, 
                                     rho will be reset to 0.  If F000 is
                                     supplied, IRHOMN is automatically set to 
                                     correspond to non-negativity of electron 
                                     density.
        
        
                      ********** NOTES ON THE PROGRAM **********
        
           The input map file MAPFIL is assumed to have been generated with 
        program FSFOUR. It is binary, terminated with an end of file, and 
        after a few header records, contains the electron density map 
        represented as records (of integers) along x. y is the slowest varying 
        coordinate.
        
        All calculated structure factors within the index range specified will 
        be output to file SFOUT. Note that this may include redundant 
        (symmetry related) as well as systematically absent reflections, if 
        they they fall within the specified index range.  The output file is 
        binary, with records of H,K,L,FCALC,FCALC,PHI and is terminated by an 
        end of file. H,K and L are INTEGERS whereas FCALC and PHI are REALS. 
        PHI is in degrees. Note that FCALC is duplicated within each record so 
        that the file structure is consistant with the input required by 
        program FSFOUR.
        
        If IPAIR > 0, then in addition to file SFOUT, an input file AUXINP of 
        observed structure factor amplitudes will be paired with the 
        corresponding calculated amplitudes and phases, and the combined data 
        used in one cycle of least squares refinement of a scale factor. The 
        resulting R factor between observed and calculated  amplitudes is then 
        output to the lineprinter. Note that the input reflection data on file 
        AUXINP is restricted to the same range of indices as the calculated 
        data. If input values fall out of bounds they will be ignored. 
        Therefore, if data were collected with L negative, it will have to be 
        transformed by symmetry before it can be used successfully on file 
        AUXINP.
        
        If IPAIR = 2, the results are identical to those obtained with IPAIR = 
        1, except that the combined (and rescaled) data is also output to a 
        separate file AUXOUT. The new file is of the same form as SFOUT, but 
        with records consisting of H,K,L,FOBS,FCALC,PHICALC for only those 
        reflections which were input on file AUXINP.
        
                             ***** SCALING THE DATA *****
        
        It is often desirable to control the scale of the calculated structure 
        factors. If the input electron density map was generated from 
        structure factors which are related to an absolute scale by:
        
        F(input to FSFOUR) = k * F(absolute)
        
        then k should be input for SC to obtain calculated structure factors 
        on an absolute scale. If sc= 0. (or 1.), then the calculated structure 
        factors will be on the same scale as those used to generate the map 
        (unless IMOD = -1, in which case they will be much larger).  Note that 
        this scaling applies only to the output on file SFOUT (and the 
        lineprinter, if IPRNT .ne.0). If IPAIR .eq. 2, then the calculated 
        structure factors on file AUXOUT will always be scaled for best 
        agreement with those supplied on file AUXINP.
        
        
                             ***** MODIFYING THE MAP *****
        
           The following applies only if IMOD .ne. 0. Inclusion of F000 will 
        result in imposing non-negativity of electron density everywhere in 
        the map prior to inversion, provided SC is reasonably well known. If 
        SC is unknown, then F000 and SC on card 3 should be zero and IRHOMN 
        should be input to control the type and degree of modification. 
        Intelligent use of this parameter would then require knowledge of the 
        input map values prior to running the job.  IRHOMN should be equal to 
        F000/V on the same scale as the input map. If IMOD = -1, IRHOMN is 
        first added to each density value, resulting values below zero are set 
        to zero, and each value is then squared prior to Fourier 
        transformation. This is equivalent to imposing non-negativity, 
        followed by one cycle through the tangent formula.  Phases can 
        therefore be tangent formula refined or extended.
        
        
                             ***** FILE REQUIREMENTS *****
        
        MAPFIL     - input map file, binary, as output by program FSFOUR
        
        
        SFOUT      - output file with all calculated structure factors,
                     binary, six word records as described earlier
        
        AUXINP     - auxilliary input structure factor file (required only 
                     if IPAIR .ne. 0), binary, six word records in same form 
                     as SFOUT (only H,K,L and FOBS are used)
                                                              
        AUXOUT     - output auxilliary structure factor file, binary, six
                     word records as described earlier.