C
C  fortran example program 22
C
C  CWJ SDSU 2/16/2005
C
C  examples of opening and closing files
C



      implicit none

      character*15 filename
      integer ilast

      integer i

      print*,' Give me the name of a file (without extension)'
      read*,filename
      ilast = index(filename,' ')-1
      
      open(unit=7,name=filename(1:ilast)//'.old',status='old',err=101)

      print*,' successfully opened! '
    
      read(7,*)i

      open(unit=8,name=filename(1:ilast)//'.dat',status='unknown')

      open(unit=9,name=filename(1:ilast)//'.new',status = 'new',err=102)
      write(9,99)i,2*i,3*i
   99 format(3i3)
 
      stop      

  101 continue
      print*,' Oops that file does not exist '
      stop

  102 continue
      print*,' Oops that file already exists '

      end
     

