      SUBROUTINE PHWRIT(Q,TQ,NQ,LIM,SAMTIM,HELJD,NORUN)     
C     
C     ROUTINE TO WRITE DATA IN THE FORM OF PHASE AND FLUX   
C     
      DIMENSION Q(nq),LIM(2,norun),SAMTIM(norun)   
      DOUBLE PRECISION tq(nq),HELJD(norun),TTT 
      CHARACTER FNAME*25,FORMAT*80
C     
C     THERE IS 1 DATA CARD WITH THE FILE NAME   
C     
C     READ THE FILE NAME AND ASSIGN THE FILE    
C     
      FORMAT='(FOR PHASE '',F10.4,'' FLUX IS '',1PE12.5)'
      MINCYC=0
    5 READ 20,FNAME
      IF(FNAME.EQ.'FORMAT'.OR.FNAME.EQ.'format')THEN
        READ 20,FORMAT
        PRINT 6,FORMAT
    6   FORMAT(12X,'WRITING FORMAT IS:'/
     *         12X,A)
        GO TO 5
      END IF
      IF(FNAME.EQ.'CYCLE'.OR.FNAME.EQ.'cycle')THEN
        READ *,MINCYC
        PRINT 8,MINCYC
    8   FORMAT(12X,'SUBTRACTING CYCLE ',I8,'  FROM ALL PHASES')
        GO TO 5
      END IF
      CLOSE(11)   
      OPEN(11,FILE=FNAME,status='unknown')     
      PRINT 10,FNAME     
   10 FORMAT(12X,'WRITING DATA TO FILE ',A)     
   20 FORMAT(A)   
      DO 100 J=1,NQ
        TTT=HELJD(1)+TQ(J)-MINCYC
        WRITE(11,FORMAT)TTT,Q(J)   
  100 CONTINUE    
      REWIND 11   
      CLOSE(11)   
      RETURN
      END   
