      program mklayer

      parameter(nnlayer=40,nnx=40)
      real data(nnlayer,nnx),datanew(nnlayer,3)
      character idata*254
      character fname(nnx)*10
      character fin*50,fout*50

      write(*,'(a\)')' enter INPUT-FILE : '
      read(*,'(a)')fin
      write(*,'(a\)')' enter NLAYER,NX : '
      read(*,*) nlayer, nx
      write(*,'(a\)')' enter scale factor(x?) : '
      read(*,*)sfac
      write(*,'(a\)')' enter OUTPIT-FILE : '
      read(*,'(a)') fout

      open(4,file=fin)
        read(4,'(a)')idata
        write(*,'(a)')idata
        do 150 i = 1, nlayer
          read(4,*)(data(i,j),j=1,nx+2)
          write(*,'(10f6.1)')(data(i,j),j=1,nx+2)
  150   continue
      close(4)
      icount = 0
      ifirst = 1
      do 180 i = 1, 250
        if(idata(i:i).eq.','.or.idata(i:i).eq.' ')then
          icount = icount+1
          ilast = i-1
          if(icount.ge.3)then
            fname(icount-2) = idata(ifirst:ilast)
            write(*,'(1h ,a)')fname(icount-2)
          end if
          ifirst = i+1
          if(icount.eq.nx+2) goto 190
        end if
  180 continue
  190 continue

      open(7,file=fout)
      do 300 j = 1, nx
        nl = 0
        do 200 i = 1, nlayer
          if(data(i,j+2).ne.0.0)then
            nl = nl+1
            datanew(nl,1)=data(i,1)
            datanew(nl,2)=data(i,2)
c *******************************************
            datanew(nl,3)=data(i,j+2)*sfac
c *******************************************
          end if
  200   continue
          write(7,'(a)')fname(j)
          write(7,'(2i10)')nl,0
          do 250 i = 1, nl
            write(7,'(4f10.1)')(datanew(i,k),k=1,3),datanew(i,2)/15.0
  250     continue
  300 continue
      close(7)

      stop
      end
