        SUBROUTINE OUTPUT

**********************************************************************
*                                                                    *
*       This subroutine writes the data for density and potential    *
*       for the initial calculation and every tenth iteration of     *
*       the do while (t.le.tmax) loop.                               *
*       The format for the files is Tecplot (www.tecplot.com).       *
*                                                                    *
*       Version 0.4 - Last Modified 5/05/04                          *
*                                                                    *
**********************************************************************

        INCLUDE "fpvar.inc"

        CHARACTER OUTFILE*9, ALPHA*10
        REAL AVERN(MOZ), DELTAN(MOZ,MOX)

********************************************************************
*                                                                  *
*       String Operation to number each file used                  *
*                                                                  *
********************************************************************

        ALPHA='0123456789'
        JJ=JJ+1
        II=1
        IF (JJ.EQ.11) THEN
           JJ=1
           KK=KK+1
           END IF
        OUTFILE(1:3)='out'
        OUTFILE(4:4)=ALPHA(KK:KK)
        OUTFILE(5:5)=ALPHA(JJ:JJ)
        OUTFILE(6:9)='.dat'

*********************************************************************
*                                                                   *
*       Calculates average densities and relative perturbations     *
*                                                                   *
*********************************************************************

        DO 400 I=1,MOZ
 400       AVERN(I)=0.0
        DO 404 I=1,MOZ
           DO 402 J=1,MOX-1
 402          AVERN(I)=AVERN(I)+N(I,J)
           AVERN(I)=AVERN(I)/REAL(MOX-1)
           DO 404 J=1,MOX
 404          DELTAN(I,J)=(N(I,J)-AVERN(I))/AVERN(I)

*********************************************************************
*                                                                   *
*       Writes data to a Tecplot-friendly file (www.tecplot.com).   *
*       Data is printed "x-axis, altitude, density, perturbations,  *
*       potential".                                                 *
*                                                                   *
*********************************************************************

        OPEN(STATUS='UNKNOWN',UNIT=9,FILE=OUTFILE)
        WRITE(9,*) 'TITLE="fp.f ~ t =',T,' s"'
        WRITE(9,*) 'VARIABLES="Latitude","Altitude","Density (m<sup>-3</
     $sup>)","Perturbations","Potential"'
        WRITE(9,*) 'ZONE F=POINT I=',mox,',J=101'
        DO 420, J=1,MOX
           DO 420, I=11,111
              XX=(DX*REAL(J-1)-LX)/1000.
              ZZ=160.0+DZ*REAL(I-1)/1000.
 420          WRITE(9,*)XX,ZZ,N(I,J),DELTAN(I,J),PHI(I,J)
              CLOSE(9) 
        RETURN
        END


