-
Notifications
You must be signed in to change notification settings - Fork 8
/
2dhistogram.f90
72 lines (63 loc) · 1.76 KB
/
2dhistogram.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 twodhis
implicit none
real :: x, y, xmin, xmax, ymin, ymax
real :: xbinsize, ybinsize, xcenter, ycenter
real, dimension(:,:), allocatable :: Prob
integer :: n, i, j, numstate, inputstatus, xbinnum, ybinnum
open (unit=10, file="hist.in")
open (unit=20, file="hist.out")
numstate=0
do n=1, 1
read(10, *) x, y
xmin=x
xmax=x
ymin=y
ymax=y
end do
rewind(10)
do
read (10, *, IOSTAT=inputstatus) x, y
if (inputstatus < 0) EXIT
numstate=numstate+1
xmin=min(xmin, x)
xmax=max(xmax, x)
ymin=min(ymin, y)
ymax=max(ymax, y)
end do
print *, "number of lines=", numstate
print *, "x minimum=", xmin
print *, "x maximum=", xmax
print *, "y minimum=", ymin
print *, "y maximum=", ymax
rewind(10)
xbinsize=0.1
ybinsize=0.1
xbinnum=(xmax-xmin)/xbinsize+1
ybinnum=(ymax-ymin)/ybinsize+1
print *, "number of bins in x dimension:", xbinnum
print *, "number of bins in y dimension:", ybinnum
allocate(prob(xbinnum, ybinnum))
rewind(10)
do i=1, xbinnum
do j=1, ybinnum
Prob(i,j)=0.0
end do
end do
do n=1, numstate
read(10, *) x, y
i=(x-xmin)/xbinsize+1
j=(y-ymin)/ybinsize+1
Prob(i,j)=Prob(i,j)+1.0
end do
do i=1, xbinnum
do j=1, ybinnum
xcenter=xmin+i*xbinsize-0.5d0*xbinsize
ycenter=ymin+j*ybinsize-0.5d0*ybinsize
Prob(i,j)=Prob(i,j)/numstate
write(20, *) xcenter, ycenter, Prob(i,j)
end do
end do
deallocate(prob)
close(10)
close(20)
end