      program datasca
c
c From a Scalepack "data.sca" output file with, in general, two
c reflections per record:
c    h, k, l, Fsq(+), sigmaFsq(+), Fsq(-), sigmaFsq(-)
c To a file with separate records:  
c   +h,+k,+l, Fsq(+), sigmaFsq(+)
c   -h,-k,-l, Fsq(-), sigmaFsq(-)
c
      character file*40,record*80,c(7)*1,d(14)*1
      data d /'0','1','2','3','4','5','6','7','8','9','.',' ','+','-'/
      write (6,'(/1x,''Enter input file name.'')')
      read (5,'(a)') file
      open (1,file=file,status='old')
      write (6,'(/1x,''Enter output file name.'')')
      read (5,'(a)') file
      open (2,file=file,status='new')
      n=0
      np=0
      nn=0
 1    read (1,'(a)',end=9) record
c
c Check for leading blanks or signs in the (3i4, 4f8) fields for
c h, k, l, Fsq(+), sigmaFsq(+), Fsq(-), sigmaFsq(-).
c
      read (record,'(3(a1,3x),4(a1,7x))') (c(i),i=1,7)
      do i=1,7
        do j=12,14
          if (c(i).eq.d(j)) go to 10
        end do
        go to 1
 10     continue
      end do
c
c Check for numeric values.
c
      read (record,'(3(3x,a1),4(7x,a1))') (c(i),i=1,7)
c
c Integer h, k, l indices.
c
      do i=1,3
        do j=1,10
          if (c(i).eq.d(j)) go to 21
        end do
        go to 1
 21     continue
      end do
c
c Real, integer, or blank Fsq and sigma(Fsq) values,
c
      do i=4,7
        do j=1,12
          if (c(i).eq.d(j)) go to 22
        end do
        go to 1
 22     continue
      end do
c
c Read and copy reflection records. 
c
      read (record,'(3i4,4f8)',err=1) ih,ik,il,fsqp,sigp,fsqn,sign
      n=n+1
c
c Only positive sigma(Fsq) values are valid.
c
      if (sigp.gt.0) then
        write (2,2000) +ih,+ik,+il,fsqp,sigp
        np=np+1
      end if
      if (sign.gt.0) then
        write (2,2000) -ih,-ik,-il,fsqn,sign
        nn=nn+1
      end if
 2000 format (3i5,2e15.7)
      go to 1
 9    write (6,'(/1x,
     &''n  = '',i6,'' "data.sca" reflection records''/1x,
     &''np = '',i6,'' +h,+k,+l reflections''/1x,
     &''nn = '',i6,'' -h,-k,-l reflections'')') n,np,nn
      stop
      end

