index.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  9. <div id=nav>
  10. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></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/codemirror">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>