You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.4 KiB

2 months ago
  1. <!doctype html>
  2. <title>CodeMirror: Fortran mode</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../../doc/docs.css">
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="fortran.js"></script>
  8. <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  9. <div id=nav>
  10. <a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
  11. <ul>
  12. <li><a href="../../index.html">Home</a>
  13. <li><a href="../../doc/manual.html">Manual</a>
  14. <li><a href="https://github.com/codemirror/codemirror5">Code</a>
  15. </ul>
  16. <ul>
  17. <li><a href="../index.html">Language modes</a>
  18. <li><a class=active href="#">Fortran</a>
  19. </ul>
  20. </div>
  21. <article>
  22. <h2>Fortran mode</h2>
  23. <div><textarea id="code" name="code">
  24. ! Example Fortran code
  25. program average
  26. ! Read in some numbers and take the average
  27. ! As written, if there are no data points, an average of zero is returned
  28. ! While this may not be desired behavior, it keeps this example simple
  29. implicit none
  30. real, dimension(:), allocatable :: points
  31. integer :: number_of_points
  32. real :: average_points=0., positive_average=0., negative_average=0.
  33. write (*,*) "Input number of points to average:"
  34. read (*,*) number_of_points
  35. allocate (points(number_of_points))
  36. write (*,*) "Enter the points to average:"
  37. read (*,*) points
  38. ! Take the average by summing points and dividing by number_of_points
  39. if (number_of_points > 0) average_points = sum(points) / number_of_points
  40. ! Now form average over positive and negative points only
  41. if (count(points > 0.) > 0) then
  42. positive_average = sum(points, points > 0.) / count(points > 0.)
  43. end if
  44. if (count(points < 0.) > 0) then
  45. negative_average = sum(points, points < 0.) / count(points < 0.)
  46. end if
  47. deallocate (points)
  48. ! Print result to terminal
  49. write (*,'(a,g12.4)') 'Average = ', average_points
  50. write (*,'(a,g12.4)') 'Average of positive points = ', positive_average
  51. write (*,'(a,g12.4)') 'Average of negative points = ', negative_average
  52. end program average
  53. </textarea></div>
  54. <script>
  55. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  56. lineNumbers: true,
  57. mode: "text/x-fortran"
  58. });
  59. </script>
  60. <p><strong>MIME types defined:</strong> <code>text/x-fortran</code>.</p>
  61. </article>