forked from johannesgerer/jburkardt-f
-
Notifications
You must be signed in to change notification settings - Fork 1
/
f90.html
743 lines (685 loc) · 22.4 KB
/
f90.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
<html>
<head>
<title>
F90 - Examples of FORTRAN90 Code
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
F90 <br> Examples of FORTRAN90 Code
</h1>
<hr>
<p>
<b>F90</b>
is a directory of FORTRAN90 programs which
illustrate some of the features of the FORTRAN90 programming language.
</p>
<p>
The new array syntax added to FORTRAN90 is one of the nicest features
for general scientific programming. Other useful features include
a standard random number generator, a standard way to get the time
and CPU time, and some ways to make a chunk of data available
without resorting to common blocks or very long argument lists.
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../c_src/c/c.html">
C</a>,
C programs which
illustrate features of the C language.
</p>
<p>
<a href = "../../cpp_src/cpp/cpp.html">
C++</a>,
C++ programs which
illustrate features of the C++ language.
</p>
<p>
<a href = "../../f77_src/f77/f77.html">
F77</a>,
FORTRAN77 programs which
illustrate features of the FORTRAN77 language.
</p>
<p>
<a href = "../../f_src/f90_intrinsics/f90_intrinsics.html">
F90_INTRINSICS</a>,
FORTRAN90 programs which
illustrate the use of FORTRAN90 intrinsic functions.
</p>
<p>
<a href = "../../f_src/f90_random/f90_random.html">
F90_RANDOM</a>,
FORTRAN90 programs which
illustrate the use of Fortran's random number generator routines.
</p>
<p>
<a href = "../../f_src/g95_intrinsics/g95_intrinsics.html">
G95_INTRINSICS</a>,
FORTRAN90 programs which
illustrate the use of intrinsic functions peculiar
to the G95 FORTRAN compiler.
</p>
<p>
<a href = "../../f_src/gfortran/gfortran.html">
GFORTRAN<a>,
FORTRAN90 programs which
includes examples of the use of the GFORTRAN compiler with
FORTRAN90 code.
</p>
<p>
<a href = "../../f_src/gfortran_intrinsics/gfortran_intrinsics.html">
GFORTRAN_INTRINSICS</a>,
a FORTRAN90 program which
demonstrates the use of some of the intrinsic functions
included with the GFORTRAN compiler.
</p>
<p>
<a href = "../../f_src/makefiles/makefiles.html">
MAKEFILES</a>,
FORTRAN90 programs which
show how to use makefiles with a set of FORTRAN90 files.
</p>
<p>
<a href = "../../m_src/matlab/matlab.html">
MATLAB</a>,
MATLAB programs which
illustrate features of MATLAB.
</p>
<p>
<a href = "../../f_src/mixed/mixed.html">
MIXED</a>,
FORTRAN90 programs which
show how to write a program partly in FORTRAN90
and partly in some other language.
</p>
<p>
<a href = "../../f_src/mpi/mpi.html">
MPI</a>,
FORTRAN90 programs which
show how to set up parallel programs in FORTRAN90.
</p>
<p>
<a href = "../../f_src/real_precision/real_precision.html">
REAL_PRECISION</a>,
FORTRAN90 programs which
investigate the somewhat awkward methods for requesting
a real data type with given precision. This is the preferred
method for requesting double or quadruple precision arithmetic;
</p>
<p>
<a href = "../../f_src/timer/timer.html">
TIMER</a>,
FORTRAN90 programs which
show how to compute elapsed CPU time in FORTRAN90.
</p>
<p>
<a href = "../../f_src/timestamp/timestamp.html">
TIMESTAMP</a>,
a FORTRAN90 library which
shows how to get a timestamp in FORTRAN90.
</p>
<p>
<a href = "../../f_src/xlf_intrinsics/xlf_intrinsics.html">
XLF_INTRINSICS</a>,
FORTRAN90 programs which
includes some examples of the use of intrinsic functions peculiar
to the IBM XLF FORTRAN compiler.
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
Jeanne Adams, Walter Brainerd, Jeanne Martin, Brian Smith,
Jerrold Wagener,<br>
Fortran90 Handbook,<br>
Complete ANSI/ISO Reference,<br>
McGraw Hill, 1992,<br>
ISBN: 0-07-000406-4,<br>
LC: QA76.73.F28.F67.
</li>
<li>
Ian Chivers, Jane Sleightholme,<br>
Introduction to Programming with Fortran,<br>
Springer, 2005,<br>
ISBN: 1846280532,<br>
LC: QA76.73.F29.C48.
</li>
<li>
Miles Ellis, Ivor Philips, Thomas Lahey,<br>
Fortran90 Programming,<br>
Addison-Wesley, 1994,<br>
ISBN: 0-201-54446-6,<br>
LC: QA76.73.F25E435.
</li>
<li>
Michael Metcalf,<br>
Fortran95/2003 Explained,<br>
Oxford, 2004,<br>
ISBN: 0198526938,<br>
LC: QA76.73.F235.M48.
</li>
<li>
Larry Nyhoff, Sanford Leestma,<br>
Introduction to Fortran90 for Engineers and Scientists,<br>
Prentice-Hall, 1996,<br>
ISBN: 0135052157,<br>
LC: QA76.73.F25N925.
</li>
<li>
James Ortega,<br>
An Introduction to FORTRAN90 for Scientific Computing,<br>
Oxford, 1994,<br>
ISBN: 0-19-517213-2,<br>
LC: QA76.73.O75.
</li>
<li>
William Press, Brian Flannery, Saul Teukolsky, William Vetterling,<br>
Numerical Recipes in FORTRAN: The Art of Scientific Computing,<br>
Second Edition,<br>
Cambridge University Press, 1992,<br>
ISBN: 0-521-43064-X,<br>
LC: QA297.N866.
</li>
<li>
GNU,<br>
GFORTRAN Reference Manual,<br>
<a href = "../../pdf/gfortran.pdf">gfortran.pdf</a>.
</li>
<li>
GNU,<br>
G95 Reference Manual,<br>
<a href = "../../pdf/g95_manual.pdf">g95_manual.pdf</a>.
</li>
<li>
IBM Corporation,<br>
XLF Language Reference Manual
</li>
<li>
Intel Corporation,<br>
Intel Fortran Language Reference.
</li>
</ol>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<b>ALLOCATABLE</b> attempts to pass a dummy allocatable array to a
subroutine which allocates, assigns and returns it. This procedure
only became legal some time after the FORTRAN95 standard, and is
now acceptable in the FORTRAN 2003. The compilers I have access to
still don't allow it.
<ul>
<li>
<a href = "allocatable.f90">allocatable.f90</a>, the source code;
</li>
<li>
<a href = "allocatable.sh">allocatable.sh</a>,
commands to compile and run the source code;
</li>
<li>
<a href = "allocatable_output.txt">allocatable_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>BIG_INTS</b> shows how you can use the new KIND qualifier to create,
for example, really big integers.
<ul>
<li>
<a href = "big_ints.f90">big_ints.f90</a>, the source code;
</li>
<li>
<a href = "big_ints.sh">big_ints.sh</a>, commands that
compile and run the source code with the F90 compiler;
</li>
<li>
<a href = "big_ints_output.txt">big_ints_output.txt</a>,
the output file;
</li>
<li>
<a href = "big_ints_g95.sh">big_ints_g95.sh</a>, commands that
compile and run the source code with the G95 compiler;
</li>
<li>
<a href = "big_ints_g95_output.txt">big_ints_g95_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>BINARY_TREE</b> shows how a binary tree can be defined and manipulated,
using the FORTRAN90 "POINTER" type.
<ul>
<li>
<a href = "binary_tree.f90">binary_tree.f90</a>, the source code;
</li>
<li>
<a href = "binary_tree.sh">binary_tree.sh</a>, commands that
compile and run the source code with the F90 compiler;
</li>
<li>
<a href = "binary_tree_output.txt">binary_tree_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>CHAR_ALLOC</b> shows that in FORTRAN90 it is possible to declare
an allocatable array of characters, for which the dimension is not
specified in advance. Note, however, that the "length", that is,
the "LEN" parameter, must be specified explicitly. It is not possible
to make the "LEN" parameter "allocatable" until FORTRAN2003.
<ul>
<li>
<a href = "char_alloc.f90">char_alloc.f90</a>, the source code;
</li>
<li>
<a href = "char_alloc.sh">char_alloc.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "char_alloc_output.txt">char_alloc_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>CONSTANT_TYPE</b> shows that FORTRAN90 constants have a type, and that
if you don't specify it for real values, the default will be
single precision.
<ul>
<li>
<a href = "constant_type.f90">constant_type.f90</a>, the source code;
</li>
<li>
<a href = "constant_type.sh">constant_type.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "constant_type_output.txt">constant_type_output.txt</a>,
the output file;
</li>
<li>
<a href = "constant_type_g95.sh">constant_type_g95.sh</a>,
commands that compile and run the source code with the G95
compiler. Note that the compilation FAILS because G95
does not support the "KIND = 16" argument;
</li>
</ul>
</p>
<p>
<b>DIGITS</b> investigates how many digits you can usefully specify
for data.
<ul>
<li>
<a href = "digits.f90">digits.f90</a>, the source code;
</li>
<li>
<a href = "digits.sh">digits.sh</a>, commands that
compile and run the source code with the F90 compiler;
</li>
<li>
<a href = "digits_output.txt">digits_output.txt</a>,
the output file;
</ul>
</p>
<p>
<b>DIVISION</b> shows that, if you're expecting double precision accuracy,
you need to specify your constants carefully, as double precision
values.
<ul>
<li>
<a href = "division.f90">division.f90</a>, the source code;
</li>
<li>
<a href = "division.sh">division.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "division_output.txt">division_output.txt</a>,
the output file;
</li>
<li>
<a href = "division_g95.sh">division_g95.sh</a>, commands that
compile and run the source code with the G95 compiler;
</li>
<li>
<a href = "division_g95_output.txt">division_g95_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>DOUBLE_COMPLEX</b> shows how you can use the new KIND qualifier to
create and use variables of type "double precision complex".
<ul>
<li>
<a href = "double_complex.f90">double_complex.f90</a>, the source code;
</li>
<li>
<a href = "double_complex.sh">double_complex.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "double_complex_output.txt">double_complex_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>EXPONENT_FORMAT_OVERFLOW</b> shows that (at least some) FORTRAN compilers
<b>cannot properly print real numbers with exponents of magnitude greater than 99</b>.
This becomes an especially serious problem if you write a very large or very
small number out, and then read it back in, only to find that it has suddenly
entirely lost its exponent, and now has magnitude roughly 1!
<ul>
<li>
<a href = "exponent_format_overflow.f90">exponent_format_overflow.f90</a>,
the source code;
</li>
<li>
<a href = "exponent_format_overflow.sh">exponent_format_overflow.sh</a>, commands that
compile and run the source code with the F90 compiler;
</li>
<li>
<a href = "exponent_format_overflow_output.txt">exponent_format_overflow_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>EXPONENTIAL</b> investigates ways of approximating the exponential function.
<ul>
<li>
<a href = "exponential.f90">exponential.f90</a>, the source code;
</li>
<li>
<a href = "exponential.sh">exponential.sh</a>, commands that
compile and run the source code with the F90 compiler;
</li>
<li>
<a href = "exponential_output.txt">exponential_output.txt</a>,
the output file;
</ul>
</p>
<p>
<b>HELLO</b> is just a "Hello, world!" program.
<ul>
<li>
<a href = "hello.f90">hello.f90</a>, the source code;
</li>
<li>
<a href = "hello.sh">hello.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "hello_output.txt">hello_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>LINKED_LIST</b> shows how a linked list can be defined, using the FORTRAN90
"POINTER" type.
<ul>
<li>
<a href = "linked_list.f90">linked_list.f90</a>, the source code;
</li>
<li>
<a href = "linked_list.sh">linked_list.sh</a>, commands that
compile and run the source code with the F90 compiler;
</li>
<li>
<a href = "linked_list_output.txt">linked_list_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>MATRIX_FUNCTION_TEST</b> shows how you may now define a function whose
return value is a matrix.
<ul>
<li>
<a href = "matrix_function_test.f90">matrix_function_test.f90</a>,
the source code;
</li>
<li>
<a href = "matrix_function_test.sh">matrix_function_test.sh</a>,
commands that compile and run the source code;
</li>
<li>
<a href = "matrix_function_test_output.txt">matrix_function_test_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>MAXMIN_TEST</b> shows the use of the very useful MAXVAL and MINVAL
operators for vectors and arrays, and the so-very-fussy and hence
maddeningly useless operators MAXLOC and MINLOC.
<ul>
<li>
<a href = "maxmin_test.f90">maxmin_test.f90</a>,
the source code;
</li>
<li>
<a href = "maxmin_test.sh">maxmin_test.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "maxmin_test_output.txt">maxmin_test_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>MXM</b> multiplies two matrices using the MATMUL intrinsic.
<ul>
<li>
<a href = "mxm.f90">mxm.f90</a>, the source code;
</li>
<li>
<a href = "mxm.sh">mxm.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "mxm_output.txt">mxm_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>RANDOM_PRB</b> demonstrates the random number routines.
<ul>
<li>
<a href = "random_prb.f90">random_prb.f90</a>, the source code;
</li>
<li>
<a href = "random_prb.sh">random_prb.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "random_prb_output.txt">random_prb_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>READ_VARIABLE_RECORDS</b> shows how to read lines of data when
you don't know how many items are on each line. We're assuming
that every item is in "I4" format, but the number of such items
variables from line to line.
<ul>
<li>
<a href = "read_variable_records.f90">read_variable_records.f90</a>,
the source code;
</li>
<li>
<a href = "read_variable_records.sh">read_variable_records.sh</a>,
commands that compile and run the source code;
</li>
<li>
<a href = "read_variable_records.txt">read_variable_records.txt</a>,
the input file to be read.
</li>
<li>
<a href = "read_variable_records_output.txt">read_variable_records_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>RECURSIVE_FUN_TEST</b> shows how you can use recursion in a function
definition.
<ul>
<li>
<a href = "recursive_fun_test.f90">recursive_fun_test.f90</a>,
the source code;
</li>
<li>
<a href = "recursive_fun_test.sh">recursive_fun_test.sh</a>,
commands that compile and run the source code;
</li>
<li>
<a href = "recursive_fun_test_output.txt">recursive_fun_test_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>RECURSIVE_SUB_TEST</b> shows how you can use recursion in a
subroutine definition.
<ul>
<li>
<a href = "recursive_sub_test.f90">recursive_sub_test.f90</a>,
the source code;
</li>
<li>
<a href = "recursive_sub_test.sh">recursive_sub_test.sh</a>,
commands that compile and run the source code;
</li>
<li>
<a href = "recursive_sub_test_output.txt">recursive_sub_test_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>SGE_MOD</b> tries to set up an interesting example of the use of
modules.
In this case, the idea is that a set of linear algebra routines
will share a module that stores the value of a matrix, its LU
factor and determinant, and also knows which of these items
have been computed. This hides a lot of information from the
user, and makes for simple calls.
<ul>
<li>
<a href = "sge_mod.f90">sge_mod.f90</a>, the source code;
</li>
<li>
<a href = "sge_mod_prb.f90">sge_mod_prb.f90</a>,
a sample calling code;
</li>
<li>
<a href = "sge_mod_prb.sh">sge_mod_prb.sh</a>, commands that
compile and run the source code and the calling code;
</li>
<li>
<a href = "sge_mod_prb_output.txt">sge_mod_prb_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>SORT_TEST</b> bubble-sorts a real vector.
<ul>
<li>
<a href = "sort_test.f90">sort_test.f90</a>, the source code;
</li>
<li>
<a href = "sort_test.sh">sort_test.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "sort_test_output.txt">sort_test_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>STAR16</b> looks at the use of the common but nonstandard
way to request quadruple real precision using "REAL*16" declarations.
Most recently, this seems to work with the G95 compiler, but not
with the GFORTRAN compiler.
<ul>
<li>
<a href = "star16.f90">star16.f90</a>, the source code;
</li>
<li>
<a href = "star16.sh">star16.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "star16_output.txt">star16_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>VECTOR_MAX</b> inquires whether a loop with the body "Z(I)=max(X(I),Y(I))"
can be replaced by the vector operation "Z(1:N)=max(X(1:N),Y(1:N))".
<ul>
<li>
<a href = "vector_max.f90">vector_max.f90</a>, the source code;
</li>
<li>
<a href = "vector_max.sh">vector_max.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "vector_max_output.txt">vector_max_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>WHERE_TEST</b> demonstrates the WHERE statement.
<ul>
<li>
<a href = "where_test.f90">where_test.f90</a>, the source code;
</li>
<li>
<a href = "where_test.sh">where_test.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "where_test_output.txt">where_test_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../f_src.html">
the FORTRAN90 source codes</a>.
</p>
<hr>
<i>
Last revised on 02 February 2010.
</i>
<!-- John Burkardt -->
</body>
</html>