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