Advertisement
Chepurnyx

Untitled

Mar 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. subroutine Input
  2. common /data/ xmin, xmax, xi, ymin, ymax, yi
  3. open(1,file='C:\laba2\input.txt',status='old',err=1)
  4. read(1,*,err=2,end=3) xmin, xmax, xi, ymin, ymax, yi
  5. goto 4
  6. 1 print *, 'Error, can not open file'
  7. pause
  8. goto 5
  9. 2 print *, 'Error, can not read file'
  10. pause
  11. goto 5
  12. 3 print *, 'Error, end of the file'
  13. pause
  14. goto 5
  15. 6 print *, 'Error, incorrect data'
  16. pause
  17. goto 5
  18. 4 if (xmin.gt.xmax
  19. * .or. ymin.gt.ymax .or. ymin.lt.0 .or. ymax.lt.0 .or. yi.lt.0
  20. * .or. (xi.eq.0 .and. xmin.ne.xmax)
  21. * .or. (xi.eq.0 .and. xmin.ne.xmax)) then
  22. goto 6
  23. endif
  24. 5 close(1,status='keep')
  25. end
  26. ******************************************************************
  27. subroutine Size
  28. common/data/xmin,xmax,xi,ymin,ymax,yi
  29. common/tabl/n,m
  30. n=0
  31. m=0
  32. if (xmin.eq.xmax) then
  33. n=2
  34. else
  35. tmin=xmin
  36. do while (tmin .lt. xmax)
  37. tmin=tmin+xi
  38. n=n+1
  39. enddo
  40. !a=(xmax-xmin)/xi
  41. !n=a
  42. !if (n.lt.a) n=n+1
  43. n=n+2
  44. endif
  45. if (xmin.eq.ymax) then
  46. m=2
  47. else
  48. tmin=ymin
  49. do while (tmin .lt. ymax)
  50. tmin=tmin+yi
  51. m=m+1
  52. enddo
  53. !b=(ymax-ymin)/yi
  54. !m=b
  55. !if (m.lt.b)m=m+1
  56. m=m+2
  57. endif
  58. print *,n,m
  59. end
  60. *******************************************************************
  61. subroutine Table
  62. common/data/xmin,xmax,xi,ymin,ymax,yi
  63. common/tabl/n,m
  64. pi=3.14159265
  65. eps=0.0000003
  66. call size
  67. open(2,file='C:\laba2\output.txt',status='old',err=8)
  68. !open(2,file='C:\laba2\test1.txt',status='old',err=8)
  69. goto 9
  70. 8 print *, 'Error, can not open file'
  71. *---------------------------------------------*
  72. 9 write (2,40) 'x\y'
  73. ty=ymin-yi
  74. do i=2,m-1,1
  75. ty=ty+yi
  76. write (2,20) ty
  77. enddo
  78. if (ty+yi .ge. ymax) write (2,30) ymax
  79. do i=1,m-1,1
  80. write (2,90)
  81. enddo
  82. write (2,110)
  83. *---------------------------------------------*
  84. tx=xmin-xi
  85. do j=2,n,1
  86. tx=tx+xi
  87. do while (tx .ge. 360)
  88. tx=tx-360
  89. enddo
  90. write (2,50) tx
  91. ty=ymin-yi
  92. do i=2,m-1,1
  93. ty=ty+yi
  94. do while (ty .ge. 360)
  95. ty=ty-360
  96. enddo
  97. sin1=sin((tx+ty)*pi/180)
  98. if (tx-ty .lt. 0) then
  99. sin2=-sin((-(tx-ty))*pi/180)
  100. else
  101. sin2=sin((tx-ty)*pi/180)
  102. endif
  103. cos1=cos(tx*pi/180)
  104. if (abs(sin1+sin2) .lt. eps) then
  105. write (2,60) 'error'
  106. else
  107. if (tx.eq.90 .or. tx.eq.270) then
  108. res=0
  109. else
  110. res=2*cos1/(sin1+sin2)
  111. endif
  112. write (2,20) res
  113. endif
  114. enddo
  115. ty=ymax
  116. do while (ty .ge. 360)
  117. ty=ty-360
  118. enddo
  119. sin1=sin((tx+ty)*pi/180)
  120. if (tx-ty .lt. 0) then
  121. sin2=-sin((-(tx-ty))*pi/180)
  122. else
  123. sin2=sin((tx-ty)*pi/180)
  124. endif
  125. cos1=cos(tx*pi/180)
  126. if (abs(sin1+sin2) .lt. eps) then
  127. write (2,70) 'error'
  128. else
  129. if (tx.eq.90 .or. tx.eq.270) then
  130. res=0
  131. else
  132. res=2*cos1/(sin1+sin2)
  133. endif
  134. write (2,30) res
  135. endif
  136. do i=1,m-1,1
  137. write (2,90)
  138. enddo
  139. write (2,110)
  140. enddo
  141. 20 format (E11.4, ' | ' \)
  142. 30 format (E11.4, ' | ')!
  143. 50 format (E11.4, ' || ' \)
  144. 40 format (A11, ' || ' \)
  145. 60 format (A11, ' | ' \)
  146. 70 format (A11, ' | ')
  147. 80 format (A11)!
  148. 90 format ('--------------', \)
  149. !100 format ('-------------', \)
  150. 110 format ('--------------')!
  151. close(2)
  152. end
  153. ****************************************************************
  154. program main
  155. common /data/ xmin, xmax, xi, ymin, ymax, yi
  156. call Input
  157. call Table
  158. pause
  159. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement