C This goal of program is to use a subroutine which can be used to C display a 1D array of real numbers. The subroutine takes C arguments which give the stating address of the array, the number C of elements in the array, and the number of elements which should C be displayed per line of output. The subroutine also shows on the C right side of the line the range of indices of the elements being C shown on that particular line. C C John Schneider C CptS 203, HW 8, Problem 2. C-------------------------------------------------------------------------- program disp implicit none real a(200) integer i, nelem, perlin character filnam*50 C..... C Read the elements of the array from the specified file. We C are allowed to assume no more than 200 elements will be entered. C..... print *, 'Enter the file name:' read '(a)',filnam open(12,file=filnam,status='old') i=1 10 read(12,*,end=20) a(i) i=i+1 goto 10 20 continue nelem=i-1 C..... C Report the number of elements read and prompt user for number of C elements to be shown per line. C..... print *, 'Number of elements ',nelem,'.' print *, 'Enter number of elements per line:' read *, perlin call showit(a,nelem,perlin) stop end C..... C Subroutine to display one-dimensional array "a" with "perlin" C values per line of output. The array has nelem elements. C..... subroutine showit(a,nelem,perlin) implicit none real a(*) integer nelem, perlin, i, j, low, high C..... C Write all the "fully populate" lines of output. If perlin is one, C handle that as an exception to make output a bit neater. C..... do 10 i=1,nelem/perlin if (perlin .ne. 1) then low = (i-1)*perlin + 1 high = low + perlin - 1 print *,low,' --',high,': ',(a((i-1)*perlin+j),j=1,perlin) else print *,i,': ',a(i) endif 10 continue C..... C Check if the number of elements is not a multiple of perlin (could C also check this be comparing mod(nelem,perlin) to zero). If not, C there are any left-over elements that we still have to display. C..... if (nelem .ne. perlin*(nelem/perlin)) then C........Find the indices for the elements still left to be displayed. low = perlin*(nelem/perlin) + 1 high = nelem C........ C Handle things differently depending on if there are one element or C more than elements to be displayed. C........ if (high .ne. low) then print *,low,' --',high,': ',(a(j),j=low,high) else print *,low,': ',(a(j),j=low,high) endif endif return end