c clog_plot.f c c
c
c     This program was written by Jason Christopher Wehr on 
c     October 10, 1996.  This was written as an example 
c     program for Dr. Mahaffy's Compsci 201 class.  The
c     intent of this program is to take a series of data
c     points and convert their values into logrithmic
c     values so that those values can be plotted on a 
c     logrithmic scale.
c                      
      module group
c
c     This module will contain all the variables that need
c     to be shared between individual program units.
c
      implicit none
      real, allocatable :: values(:),plot(:)
      integer, allocatable :: points(:)
      integer ldata
      logical lvar
c
c     values - This is an array used to store the original
c              values of your data
c
c     plot   - This is an array that will store the power
c              of ten that ten needs to be raised to get 
c              your original value.  It is also what you 
c              would plot on your logarithmic axis.
c
c     points - This is just an array used for storing the 
c              the the point number.
c
c     ldata -  This will be the number of data points to
c              be read
c
c     lvar  -   This is a logical variable used to help
c               loop out of the program in case of some
c               error.
c 
      end module group
c
      program lpoints 
      use group
      implicit none
      integer i,k
      character*20 name
c
c     The character variable name will store the name of the 
c     file in which all of the needed data is located.
c
      open (29,file='points.out',status='unknown')
c     
c     The subroutine input1 will pick up the name of
c     the file in which the data is stored. It will 
c     also read the number of data points.
c 
      call input1(name)
c     
c     This if test is used to kick out of the program in 
c     case there was trouble reading the file in which 
c     the input data is supposed to be stored.
c 
      if (lvar.eqv..false.) then
c
        go to 700
c
      end if 
      allocate (values(1:ldata),plot(1:ldata))
      allocate (points(1:ldata))
      call input2
c     
c     Input2 will store all the needed values into the 
c     arrays points and values
c 
      do k=1,ldata
c
        plot(k)=log10(values(k))
c
      end do
      call output
      print *, 'The Results are in the file points.out.'
 700  stop   
      end     


      subroutine input1(name)
      use group
      implicit none
      integer lfile,jj
      real dummy
      character*20 name
      print *, ' What is the name of the file that contains your data?'
      read (*,'(a)') name
      lfile = len_trim(name)
      open(37,file=name(1:lfile),status='old',iostat=jj,err=3000)
  100 read (37,*,end=102) dummy
        ldata = ldata + 1
        go to 100
  102 continue
c
      rewind (37)
c
      go to 3001
 3000 print *, 'Unable to read ',name(1:lfile),'.'
      print *, 'Error condition is:',jj    
      lvar = .false.
      go to 3002
 3001 lvar = .true.
 3002 return
      end
c
      subroutine input2
      use group
      implicit none
      integer ff,i
      do i=1,ldata
        read (37,*,iostat=ff,err=600) points(i),values(i)
c
      end do 
c
      go to 601
 600  print *, 'Error occured while attempting to read data!'
      print *, 'Error condition number is:',ff
 601  return 
      end  
c
      subroutine output
      use group
      implicit none
      integer k
         write (29,*) "Point Number     Original Value   Log point"
         write (29,*) "___________________________________________"
         write (29,*)
      do k=1,ldata
         write(29,2000) points(k),values(k),plot(k)
      end do
 2000 format (4x,i3,12x,f9.3,8x,f9.7)
      return
      end 
c
c c