PROGRAM vecgen ! ! This program randomly generates an N-length vector and writes it to ! a file, with N on the first line, and the rest of the array on ! following line(s). ! IMPLICIT NONE INTEGER N DOUBLE PRECISION, ALLOCATABLE :: V(:) PRINT *, 'Enter N (> 0)' READ *, N IF (N .lt. 1) THEN PRINT*, 'N must be greater than 0, but you used:', N STOP END IF ALLOCATE(V(N)) ! allocate array CALL RANDOM_NUMBER(V) ! randomly generate array ! ! Write array to file, and quit ! OPEN(unit=10, file='vector.dat', status='replace', action='write') WRITE(10, *) N WRITE(10, *) V CLOSE(10) DEALLOCATE(V) PRINT *, 'Results written to file ''vector.dat''' END PROGRAM vecgen