Hello Fortran Experts:
I am writing with another request for assistance/direction. I have two arrays.
One is an array of n random numbers (converted to integer). The other is an
array of elevation, latitude and longitude values. I would like to use the
integer values in the random array as record identifiers for the z, x, y array
to select those records and put them into a different array while maintaining
the z, x, y array with those records removed. I have been reading about arrays
but I am new to programming and do not know how to approach this problem. I am
using ELF90 (Essential Lahey Fortran 90).
Any suggestions would be greatly appreciated.
I have pasted the existing code below. This code only includes the reading in
of the elevation file and creation of the random array, as I am at a loss as to
how to proceed with the above step.
[Is there example code available that might serve as a guideline? I couldn't
find anything related in Numerical Recipes in Fortran or Fortran 90].
Thank you, in advance, for any suggestions and for your time.
Sincerely,
Suzanne Wechsler
--------------------------------------------------------------------------- ----
! This program is intended to do the following:
!
! (1) read in an elevation file with x, y, z coordinates; (DONE)
! (2) count the number of records in the file; (DONE)
! (3) generate random numbers to use to match subscripts of the input records;
(DONE)
! (4) select the records from the input file based on the subscripts and place
! them in their own array (as validation points); (NEED HELP) and
! (5) maintain the array that the elements were extracted from. (NEED HELP)
!
! Input: Spot Elevation File
! Output: Array of randomly selected elevations
! Spot elevation file minus the extracted elevations
!
! The following is an example of the file format for the input file:
! -------------------------------------------------
! Elev. X-Coordinate Y-Cooridinate
! -------------------------------------------------
! 1580 404292.375 4747337
! 1600 404372.4375 4747337
! 1300 401050.6875 4747327
! 1320 401500.9063 4747327
! 1300 403091.75 4747327
! 1540 404192.3438 4747327
! 1560 404222.3438 4747327
! 780 407273.9375 4747327
!
--------------------------------------------------------------------------
--------
program rn
implicit none
INTEGER :: nrandom, i, j, norig
REAL, allocatable :: random(:)
REAL, allocatable :: subr(:)
INTEGER, allocatable :: subi(:)
REAL, DIMENSION(10000,3) :: xyzorig ! 3D array - 10000 rows, 3 columns
! REAL, DIMENSION(10000,3) :: validpt - This would be the records selected from
xyzorig
! REAL, DIMENSION(10000,3) :: newxyz - This would be the xyzorig without the
validpt data
CHARACTER (LEN=12) :: origxyz
!
--------------------------------------------------------------------------
--------
! nrandom = number of random values to extract from the spot elevation
file
! norig = number of records in the original spot elevation file
! subscript() = list of random numbers
! origxyz = original spot elevation file
! xyzorig() = array of original spot elevation file
!
--------------------------------------------------------------------------
--------
write (*,'(1x,a)', advance='no')"Enter the number of random numbers to
generate: "
READ (*,*) nrandom
write (*,'(1x,a)', advance='no')"Enter the spot elevation file: "
READ (*,'(a)') origxyz
!write (*,'(1x,a)', advance='no')"Enter the name for the validation point file:
"
!READ (*,'(a)') validxyz
open (1, FILE=origxyz, STATUS='old')
!
--------------------------------------------------------------------------
-----------------
! Read in spot elevation file and count number of records in file
!
--------------------------------------------------------------------------
-----------------
norig=0
do i=1, 10000
READ(1,*,END=30) (xyzorig(i,j), j=1,3)
norig=norig+1
end do
30 do i=1, norig
WRITE(*,*) (xyzorig(i,j), j=1,3)
end do
write (*,*)"The number of records in the input file is: ", norig
!
--------------------------------------------------------------------------
-----------------
! Generates 10,000 random numbers in a range of 0 to 1
!
--------------------------------------------------------------------------
-----------------
ALLOCATE (random(nrandom))
ALLOCATE (subr(nrandom)) ! arrays allocated size of nrandom
ALLOCATE (subi(nrandom))
if (nrandom > norig) THEN
WRITE (*,*) "The number of random numbers requested exceeds values in input
file."
GO TO 250
end if
write (*,*) "Selecting random numbers........"
call random_seed() ! initializes the random number generator
do i=1, nrandom
call random_number(random)
END do
!
--------------------------------------------------------------------------
-----------------
! Convert random numbers from 0-1 range to range consistent with input file
!
--------------------------------------------------------------------------
-----------------
subr=random*norig
subi=INT(subr)+1
WRITE (*,*) "The records to be randomly removed are:", subi(1:nrandom) !writes
"nrandom" random numbers as integers
!
--------------------------------------------------------------------------
-----------------
! Select records from input file based on random subscripts in subi()
!
--------------------------------------------------------------------------
-----------------
This is what I don't know how to do.........
!
--------------------------------------------------------------------------
-----------------
! Remove elevations of subscripts corresponding to subi from original array
into new array
!
--------------------------------------------------------------------------
-----------------
!
--------------------------------------------------------------------------
-----------------
! Save array with records removed
!
--------------------------------------------------------------------------
-----------------
GO TO 250
250 STOP "Program Completed"
end program rn