Tonto | ||
---|---|---|
<< Previous | Next >> |
This chapter gives you some examples of simple TONTO programs that you can study, compile, or extend.
All the programs are distributed with TONTO in the foofiles directory, in files named run_XXXX.foo, where XXXX is the name of the module mainly being used.
To compile these programs just type make run_XXXX.x in the tonto directory; an executable run_XXXX.x will then be produced.
To run the program, just tupe run_XXXX.x.
Except for the TEXTFILE example, all results are deposited in the "stdout" file.
One of the most often used modules is TEXTFILE, which is concerned with reading and writing ASCII textfiles. The following example illustrates the basic use of this module, which used repeatedly in the following examples.
You will need to edit a file "in" to get this program to work. This is described in the program body, and the results are written to your terminal screen.
program run_textfile use TYPES ! Always use the TYPES module use SYSTEM ! Always use the SYSTEM module use STR use TEXTFILE #include "macros" implicit none TEXTFILE* :: in STR :: junk,name REALMAT(2,2) :: m tonto.initialize ! Always initialise "tonto" before anything stdout.create_stdout ! Always create "stdout" before you use it stdout.flush ! If you do not open "stdout" it goes to the terminal stdout.flush stdout.text('Hello! Welcome to TONTO!') stdout.flush stdout.flush stdout.text('This message goes to the stdout -- unless I explicitly "open" the "stdout" file.') stdout.flush stdout.text('Now edit a file "in" and put your name in it, and also a matrix of four numbers.') stdout.flush stdout.text('Type ^Z now to suspend this program. When you are done editing the file, recommence') stdout.text('the program by typing "fg" <return> and then "c" <return> to continue on.') ! Pause a while by reading a junk string from "stdin". We can't do more than this ! because fortran doesn't handle a stream very well yet. stdin.create_stdin ! Always create "stdin" before using it stdin.read(junk) ! Always open "stdin" except in this case where you want to "pause" ! Open the file "in" and read the info stdout.flush stdout.text('Explicitly opening the file "in" now ...') stdout.flush stdout.flush in.create("in") in.open(for="read") in.read(name) in.read(m) in.close stdout.flush stdout.text('Hello ' // name.trim// '!') stdout.flush stdout.text('If you see this message that means you succesfully edited the file "in"!') stdout.flush stdout.flush stdout.text('Here is the matrix you entered:') stdout.flush stdout.put(m) stdout.flush stdout.text('Here is the same matrix printed witha different number of decimal places:') stdout.flush stdout.set_real_precision(3) stdout.set_real_width(8) stdout.put(m) stdout.flush stdout.text('Here is the first column:') stdout.flush stdout.put(m(:,1),"column") stdout.flush stdout.text('Here is the second column:') stdout.flush stdout.put(m(:,2),"column") stdout.flush stdout.text('Good luck with thye rest of TONTO ...') stdout.flush end |
Hello! Welcome to TONTO! This message goes to the stdout -- unless I explicitly "open" the "stdout" file. Now edit a file "in" and put your name in it, and also a matrix of four numbers. Type ^Z now to suspend this program. When you are done editing the file, recommence the program by typing "fg" <return> and then "c" <return> to continue on. c Explicitly opening the file "in" now ... Hello dylan! If you see this message that means you succesfully edited the file "in"! Here is the matrix you entered: 1 2 1 1.000000000 2.000000000 2 3.000000000 4.000000000 Here is the same matrix printed witha different number of decimal places: 1 2 1 1.000 2.000 2 3.000 4.000 Here is the first column: 1 1.000 2 3.000 Here is the second column: 1 2.000 2 4.000 Good luck with thye rest of TONTO ... |