      subroutine subq(maxgen,ipopsize,nin,nout,plistin,plistout)
      implicit real*8(a-h,o-z)
      dimension plistin(nin),plistout(nout)
      data fitmax/ 0 /
      data igen/ 0 /
      data iflag/ 0 /
      save
      if(iflag.eq.0)then
         open(unit=19,file='outfort19')
         print*,'maxgen=',maxgen
         print*,'ipopsize=',ipopsize
         print*,'nin=',nin
         print*,'nout=',nout
         print*,'plistin=',(plistin(i), i=1,nin*10)
         ipopsz=ipopsize
         istat=1
         print*,'p_subq'
         iflag = 1
      endif
! --- Initialization for Printing
        write(19,*)' GEN   I    FITNESS   VAL-FUNC       X          Y'
        fitmax=0.0
        xmax=0.0
        ymax=0.0
        igenmax=0
        iflag = 1
! ---------------------------------------- !
       ipop=0
       j=1
       do i=1,ipopsize*nin,nin
         x=plistin(i)
         y=plistin(i+1)
         y=y/1e16
         ipop=ipop+1
!        f=x**4+4.1*x**3+x**2-5.2*x+20.0
!        f=x**4+4.1*x**3+x**2-5.2*x+20.0+abs(y)**(1.0/6.0)
         f=x**4+4.1*x**3+x**2-5.2*x+20.0+y**4+4.1*y**3+y**2-5.2*y+20.0
         fitness=1.0/f
         write(19,900) igen,ipop,fitness,f,x,y
         if(fitness.gt.fitmax) then
           fitmax=fitness
           xmax=x
           ymax=y
           igenmax=igen
         endif
         if(ipop.eq.ipopsize) then
           igen=igen+1
         endif
         plistout(j)=fitness
         plistout(j+1)=-999.0d0
         j=j+nout
       enddo

       write(19,*)
       fmin=1.0/fitmax
       write(19,910) fitmax,xmax,ymax,fmin,igenmax
       if(igen .eq. maxgen)then 
         write(19,901) ipopsize,ipop,igen
         close(19)
       endif
       return 
901    format(1x,'ipopsize=',i4,4x,'ipop=',i2,3x,'igen=',i2,
     c       //,1x,60('-'),//,1x,'ga run has finished')
910    format(1x,'fitmax=',e16.9,2x,
     c          'xmax=',e16.9,2x,
     c          'ymax=',e16.9,2x,
     c          'fmin=',e16.9,2x,
     c          'igenmax=',i3,/)

900    format(1X,i3,2x,i3,2x,4(F9.5,2X))
       end
