c rainpal.for
c
c creates a pds pallette for color density slice images
c
c Jeff Phillips 8 Aug 91
      dimension n(6)
      character*50 ifile
      print *,'Enter output file name: '
      read(5,100) ifile
  100 format(a)
      open(10,file=ifile,form='formatted',status='unknown')
      print *,'Enter zero level'
      read(5,*) n(3)
      print *,'Enter data range (eg. 1 240)'
      read(5,*) n(1),n(6)
      n(2)=n(1)+(n(3)-n(1))/2
      do 20 i=4,5
      n(i)=n(3)+float((i-3)*(n(6)-n(3)))/3.
   20 continue
      print *,n
c
      jm=0
      write(10,*) jm,jm,jm,jm
      do 40 j=1,255
      if (j.lt.n(1)) then
           ir=0
           ig=0
           ib=0
      else if(j.lt.n(2)) then
           ir=0
           ig=127+float(j-n(1))/float(n(2)-n(1))*127
           ib=ig
      else if (j.lt.n(3)) then
           ir=float(j-n(2))/float(n(3)-n(2))*127
           ig=255
           ib=255
      else if (j.lt.n(4)) then
           ir=float(j-n(3))/float(n(4)-n(3))*255
           ig=255
           ib=0
      else if (j.lt.n(5)) then
           ir=255
           ig=127+float(n(5)-j)/float(n(5)-n(4))*127
           ib=0
      else if (j.lt.n(6)) then
           ir=127+float(n(6)-j)/float(n(6)-n(5))*127
           ig=127
           ib=0
      else
           ir=255
           ig=255
           ib=255
      endif
      write(10,*) j,ir,ig,ib
   40 continue
      stop
      end
