      SUBROUTINE GENWRT(Q,TQ,NQ,HELJD)    
C     
C     ROUTINE TO WRITE DATA FORMATTED AS HJDS AND INTENSITIES     
C     
      DIMENSION Q(*)
      CHARACTER FNAME*25,FORMAT*80  
      DOUBLE PRECISION HELJD(*),TIME,TQ(*)
      ISEC=0 
      READ 20,FNAME     
      IF(FNAME.NE.'FORMAT')THEN     
C       FORMAT='(F15.6,F15.7)'
        FORMAT='(F18.7,15X,E15.6)'  
        GO TO 25  
      END IF
      READ 20,FORMAT    
      DO J=1,80
        IF(FORMAT(J:J).EQ.'#')THEN
C         WRITE THE DATA OUT IN SECONDS, NOT DAYS
          ISEC=1
          FORMAT(J:79)=FORMAT(J+1:80)
        END IF
      END DO
      PRINT *,'           WRITE FORMAT IS ',FORMAT    
      READ 20,FNAME     
   20 FORMAT(A)   
   25 CLOSE(11)   
      OPEN(11,FILE=FNAME,STATUS='UNKNOWN')     
      DO 50 J=1,NQ
        TIME=HELJD(1)+TQ(J)/86400.0D0     
        IF(ISEC.EQ.1)WRITE(11,FORMAT)TQ(J),Q(J)     
        IF(ISEC.EQ.0)WRITE(11,FORMAT)TIME,Q(J)   
   50 CONTINUE    
      REWIND 11   
      CLOSE(11)   
      PRINT 100,NQ,FNAME,HELJD(1)   
  100 FORMAT(12X,I5,' POINTS WRITTEN TO FILE ',A12,' STARTING AT HJD ', 
     *       F12.5)     
      RETURN
      END   
