The print statement is used to send output to the standard output unit ( usually your monitor, or sometimes your printer ) of your computer system.
The concept of the PRINT statement is a pretty basic thing for most people to understand. You need only remember a few details of the details of its use. For starters take a look at the following print statement.
print *, 'The velocity on impact is', v1
The first thing that you should notice right away is the '*' that follows the initial print statement. This star tells the computer to output the data that follows in a format compatible with the type of items contained in the following comma delimmited list.
The next thing that you should look at is the data list that is slated to be output. It contains a combination of a character string and a variable ( v1 ). A comma like the one that separates the character string and the variable v1 is always used to separate two different output list items. Next, the entire character string in the above print statement except for the single quotes will be printed. In FORTRAN 77 you had to use single quotes to encapsulate any character string marked for output, but in FORTRAN 90 it is equally valid to use double quotes. If you have a need to output a character string that contains either a single quote or double quote, you'll can place two quotes in a row as in the following example so the computer knows that the quotes are not being used to mark the end of the character string.
Print *, 'The car''s speed is', cspeed, 'mph'
Alternately, knowing that you want single quotes in your output, you can bound the entire string with double quotes, removing confusion (Fortran 90 only).
Print *, "The car's speed is", cspeed, "mph"
Although the "*" (list directed) format is good for many situations, it is sometimes necessary to use a specific output format for full control of output appearance. This can be accomplished using the format statement. To reference a format statement a statement label should be inserted in place of the '*' in the print statement. The following example should clarify this point.
Print 1000, x,y,z 1000 format (1x,3(f5.2))
Remember that PRINT always routes your output to the standard output unit for your system. Now, the standard output unit for most systems is your computer's monitor. Although, you should be aware that there are still a few systems that use the printer as its standard output device. If you need to write your output to a file, or put it into a character variable, use the write statement.
Before I close the book on the print statement I want to point out one more thing concerning the print statement. In the format statement for the above print statement you'll notice that I used the X edit descriptor to skip one space before I begin to actually output my results. The reason why I do this is to make sure that the output of my results don't get messed up by the printer control variables. Printer control variables date to the dawn of FORTRAN. They really aren't necessary anymore, but like a few other outdated constructs in FORTRAN we can't seem to get rid of them. The story behind the control variables was that the first character in a line from PRINT or WRITE statements was interpreted by the printer as a special command. It told the printer how many lines to scroll down before it began printing. There were four primary characters that were used to do this, two of which were zero and one. Zero told the printer to double space things and one told it scroll to the top of the next page. So, if the very first thing you output is a number that begins with zero or one you run the risk of invoking the old printer control variables. This problem is normally encountered when routing the output to some printers. Therefore, it is a good idea to skip a space before you begin printing using a format statement to control the layout of your output.
trig.f and sums.f
Written by Jason Wehr : firstname.lastname@example.org and Maintained by John Mahaffy : email@example.com