C This program opens a set of files that have a common base name, a C dot, and then an integer index. The index starts from one. Each C file contains real values listed one per line. The number of C values is not known a prior. The maximum value for each file is C reported. After reading all the files, the maximum for the set is C reported. It is assumed there are never more than 9,999 files. C C John Schneider C CptS 203, HW 10, problem 2. C-------------------------------------------------------------------------- program maxfnd implicit none real x, maxfil, maxtot character base*40, filnam*50, number*4 integer length, i, eof C.....Get the base name and append a dot to it. print *, 'Enter base name.' read '(a)', base length = index(base,' ') base(length:) = '.' do 20 i=1,9999 C........Convert the current index to a string using an internal file. write(number,'(i4)')i if (i .lt. 10) then filnam = base(1:length) // number(4:4) else if (i .lt. 100) then filnam = base(1:length) // number(3:4) else if (i .lt. 1000) then filnam = base(1:length) // number(2:4) else filnam = base(1:length) // number endif C........ C Open the file. If there is an error, i.e., the file doesn't C exist, jump out of the loop. C........ open(12,file=filnam,status='old',err=30) read(12,*,iostat=eof) x C........Set the maximum for the file equal to the first value read. maxfil = x C........ C Read the rest of the values in the file, resetting the maxfil C if appropriate. C........ 10 if (eof .eq. 0) then if (x .gt. maxfil) maxfil=x read(12,*,iostat=eof) x goto 10 endif C........ C If this is the first file read, initialize the overall maximum C value. Otherwise, compare the max for this file to the overall C max and reset if appropriate. C........ if (i .eq. 1) then maxtot = maxfil else if (maxfil .gt. maxtot) maxtot = maxfil endif print *, 'Max for ',filnam(1:index(filnam,' ')),'= ',maxfil close(12) 20 continue 30 print *, 'Overall maximum: ',maxtot return end