-
Notifications
You must be signed in to change notification settings - Fork 0
/
gencity.f90
72 lines (45 loc) · 1.92 KB
/
gencity.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
program gencity
implicit none
integer, parameter :: idp = selected_real_kind(15,307)
integer :: i
character(len=12) :: path_to_file = './cities.dat'
integer, parameter :: icity_count = 50 !! Anzahl Städte
real(idp), parameter :: rrange = 1d001 !! Bereich der Koordinaten
!! x,y in [0,rrange]
real(idp) :: rrandom_number !! Zufallszahl
real(idp), allocatable :: rcoordinates(:,:) !! Koordinaten
!! Initialisieren des zufälligen Seeds
call init_random_seed()
!! Erzeugen der Zufallskoordinaten
allocate(rcoordinates(2,icity_count))
open(unit=100, file=path_to_file, action='write')
write(100,'(A2,I3,A8)')'# ', icity_count, ' Städte'
write(100,'(A2,A5,2A25)')'# ', 'Stadt', 'x-Koordinate', 'y-Koordinate'
do i = 1, icity_count
!! x-Koordinate
! call random_number(rrandom_number)
! rcoordinates(1,i) = ceiling(rrandom_number * rrange)
!! y-Koordinate
! call random_number(rrandom_number)
! rcoordinates(2,i) = ceiling(rrandom_number * rrange)
!write(100,'(I6,2ES25.15)')i, real(50,idp)*(real(1,idp)+cos(real(2*3.14,idp)/real(icity_count,idp)*real(i-1,idp))), real(50,idp)*(real(1,idp)+sin(real(2*3.14,idp)/real(icity_count,idp)*real(i-1,idp)))
enddo
! write(100,'(A2,I3,A8)')'# ', icity_count, ' Städte'
! write(100,'(A2,A5,2A25)')'# ', 'Stadt', 'x-Koordinate', 'y-Koordinate'
! do i = 1, icity_count, 1
! write(100,'(I6,2ES25.15)')i, rcoordinates(1,i), rcoordinates(2,i)
! enddo
close(100)
deallocate(rcoordinates)
contains
subroutine init_random_seed()
integer :: i, n, clock
integer, dimension(:), allocatable :: seed
call random_seed(size = n)
allocate(seed(n))
call system_clock(count=clock)
seed = clock + 37 * (/ (i - 1, i = 1, n) /)
call random_seed(put = seed)
deallocate(seed)
end subroutine
end program