      ! disrgbfile - create tiff image from 3 byte files, r, g, b

      character*60 rfile,gfile,bfile,str
      integer*1, allocatable :: rgb(:,:,:)
      integer statb(13),fstat

      if(iargc().lt.4)then
         print *,'Usage: disrgbfile redfile greenfile bluefile length <firstline=0> <nlines>'
         stop
      end if

      call getarg(1,rfile)
      call getarg(2,gfile)
      call getarg(3,bfile)
      call getarg(4,str)
      read(str,*)len
      ifirst=0
      if(iargc().ge.5)then
         call getarg(5,str)
         read(str,*)ifirst
      end if
      open(21,file=rfile,recl=len,access='direct')
      ierr=fstat(21,statb)
      nlines=statb(8)/len
      print *,'Lines in file: ',nlines,len,' pixels'
      close(21)
      nlines=nlines-ifirst
      if(iargc().ge.6)then
         call getarg(6,str)
         read(str,*)nlines
      end if

      allocate (rgb(len,nlines,4))

      open(21,file=rfile,recl=len,access='direct')
      open(22,file=gfile,recl=len,access='direct')
      open(23,file=bfile,recl=len,access='direct')

      krec=0
      do irec=ifirst+1,ifirst+nlines
         krec=krec+1
         read(21,rec=irec)(rgb(k,krec,1),k=1,len)
         read(22,rec=irec)(rgb(k,krec,2),k=1,len)
         read(23,rec=irec)(rgb(k,krec,3),k=1,len)
         do k=1,len
            rgb(k,krec,4)=255
         end do
      end do

      str='disrgb.tif'
      call writetiff(rgb,len,nlines,str)

      end
