Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function f(x, y)
- common /const/ pi
- f = abs(cos(x*pi/180)/sin(y*pi/180))
- end
- program main
- common /const/ pi
- common /values/ x1, x2, y1, y2, hx, hy
- pi = 3.1415927
- call input
- call output
- write (*,*) 'OK'
- pause
- end
- subroutine input
- character*20 msg
- common /const/ pi
- common /values/ x1, x2, y1, y2, hx, hy
- open(1, file = 'input.txt')
- read(1,*) x1, x2, hx
- read(1,*) y1, y2, hy
- if (((x2-x1).GT.0.AND.hx.LT.0).OR.((x2-x1).LT.0.AND.hx.GT.0)) then
- msg = 'bad input data for x'
- call exeption(msg)
- end if
- if (((y2-y1).GT.0.AND.hy.LT.0).OR.((y2-y1).LT.0.AND.hy.GT.0)) then
- msg = 'bad input data for y'
- call exeption(msg)
- end if
- end
- subroutine output
- logical bm, bn
- common /const/ pi
- common /values/ x1, x2, y1, y2, hx, hy
- 100 format (E10.4, ' ' \)
- 101 format (A11, ' ' \)
- 102 format (E11.4, ' ' \)
- 103 format (A10, ' ' \)
- 104 format (A10)
- open(2, file = 'output.txt')
- a = abs((x2-x1)/hx)
- b = abs((y2-y1)/hy)
- m = a + 1
- n = b + 1
- bm = (a - int(a)).NE.0
- bn = (b - int(b)).NE.0
- if (bm) m = m + 1
- if (bn) n = n + 1
- write(2, 101) 'y\x'
- do x = x1,x2,hx
- write(2, 100) x
- end do
- if (bm) write(2, 100) x2
- write(2, 104)
- write(2, 104)
- do y = y1,y2,hy
- write(2, 102) y
- do x = x1,x2,hx
- if (sin(y*pi/180).NE.sin(0.0)) then
- write(2, 100) f(x, y)
- else
- write(2, 103) '+inf'
- end if
- end do
- if (bm) write(2, 100) f(x2, y)
- write (2, 104)
- end do
- if (bn) then
- write(2, 102) y*180/pi
- do x = x1,x2,hx
- if (sin(y*pi/180).NE.sin(0.0)) then
- write(2, 100) f(x, y2)
- else
- write(2, 103) '+inf'
- end if
- end do
- if (bm) write(2, 100) f(x2, y2)
- write (2, 104)
- end if
- close(2)
- end
- subroutine exeption(message)
- character*20 message
- print *, message
- pause
- stop
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement