Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. PROGRAM Exercise
  2. C
  3. C PARAMETERS
  4. C
  5. INTEGER UNUM
  6. PARAMETER (UNUM=15)
  7. C
  8. C LOCAL VARIABLES
  9. C
  10. REAL LINES
  11.  
  12. C
  13. C FUNCTION DECLARATIONS
  14. C
  15. REAL NUMLIN
  16. C
  17. C COMMON VARIABLES
  18. C
  19.  
  20. C
  21. C DATA STATEMENTS
  22. C
  23.  
  24.  
  25. C MAIN PROGRAM MODULE
  26. C
  27.  
  28. OPEN(UNIT=UNUM, FILE = 'line.txt', STATUS='OLD')
  29. LINES=NUNMLIN(UNUM)
  30.  
  31. C
  32. C Rewinding to the top of the file because the pointer is at the end
  33. C of the file
  34. C
  35.  
  36. REWIND(UNUM)
  37. CLOSE(UNUM)
  38.  
  39. CALL PROCES(UNUM,LINES)
  40.  
  41. STOP
  42. END PROGRAM
  43.  
  44. CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
  45. C SUBROUTINE PROCES
  46. C
  47. C dynamically allocates space
  48. C
  49.  
  50. SUBROUTINE PROCES(U,L)
  51.  
  52. CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
  53. C FUNCTIONS
  54. C
  55. C NUMLIN - counts the number of lines, uses the fact that the file
  56. C is already open and passes this information to the next subroutine
  57. C
  58. REAL FUNCTION NUMLIN(S)
  59. REAL NUMLIN
  60. REAL S
  61.  
  62. CHARACTER*256 LINE
  63. 100 READ(S,*,END=200) LINE
  64. NUMLIN=NUMLIN+1
  65. GOTO 100
  66. 200 CONTINUE
  67.  
  68. RETURN
  69. END
  70.  
  71. 100 READ(S,*,END=200) LINE
  72. 1
  73.  
  74. 200 CONTINUE
  75. 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement