[PDF] Formating To make columns line up in Fortran you must use format





Previous PDF Next PDF



Basic I/O Concepts – FORTRAN 90 Chapter 5 of Textbook

This handout is designed to give you the basics of formatting input and output in your FORTRAN programs. A thorough reading of Chapter 5 in the text may be 



FORTRAN 90: Formatted Input/Output

Formatted Output. • Two output statements in FORTRAN. – PRINT and WRITE. • PRINT format-descriptor output-list. • What is a format descriptor?



Fortran 90 Basics

required in this course to write safe programs. ?Fortran 90 is not completely format-free! ... ?A Fortran 90 constant may be an integer real



Guide 138 - An introduction to programming in Fortran 90

programming and Fortran 90 to write straightforward programs. fred.f90. 2) Compile the code into an intermediate format called an object file.



Introduction to using the netCDF data format with Fortran 90 I

Jul 20 2010 Writing netCDF files to use with GMT requires using the COARDS. (“Cooperative Ocean/Atmosphere Research Data Service”) data convention. The ...



Programming bridging course Fortran 90/95

Standard formatting (list-directed I/O) read/write(*



Fortran Reference Guide

Fortran Arrays describes special characteristics of arrays in Fortran 90/95. Input and Output



Simple File Input & Output 1 The OPEN statement

Fortran 90 has a wealth of commands for I/O and in this course we will only We will look briefly at two types of files formatted and unformatted files.



Formating To make columns line up in Fortran you must use format

Each bottom row element is the average of the values above it. Print the resulting matrix with the print matrix subroutine of the previous example. c11.3 Write 



Input/output in Fortran

Input/output in Fortran Formats. • Fine control of input/output. • Direct use in print statement: ... 90 91 92 93 94 95 96 97 98 99.

LECTURE 11: Formating

To make columns line up in Fortran, you must useformat statements.

Instead of

print *, ... write # format( *** ) where#is anarbitrary number(usually with 3 digits) used as aname for the format and***areformat instructions. Just as in Scialb, the format instructions depends on the type of variables that we are dealing with and the space that we want to use for the printing: a ch aracterstrings of unspecified length. a12 r eserves12 s pacesfor ch aracters(letters, numerals) i for integers i5 re serves5 spa cesan integ er f7.2 reserves 7 s paces(including spaces for '.' an dany '-') for a real (floating point) number with two decimal places. 4f7.2 reserves 4 consecutive fields of type f7.2. 4x pr ints4 space sas does ' '. beg insa new line Items areright-justiedin their elds (blanks added on the left).For instance, when printing in thef7.2real format: '-999.44' lls its 7 space eld, '1.00'lls only the rightmost 4 of the 7 spacesFor example print *,x,ylets Fortran format the print. print '(20f6.2)',x,yprints both real numbersxandyin a eld of 6 spaces (including . and -) and 2 decimal places. The 20 species that this format may to be used to printas many as 20 real num- bers. But here, we have only two variables x, y and hence we use only

2 of the possible 20 elds.The remaining 18 used elds are ignored.

If we write

print *,x print *,y then the rst statement printsx, advances to the next line and printsy. To print both on the same line,replaceprint *,xwith write(*,advance='no'),x. Here are four ways to print x in the 'f7.2' real format. print '(f7.2)',x

101 format(f7.2)

!101 is the na mefor the format print 101,x !prints the value o fx by using the format 101 write(*,101),x !prints the value of x by us ingthe form at 101
write(*,101,advance='no'),x doesnt advance to the next line after printing. 1 c11.1Mo difythe 5 red statemen tsto mak ethe title prin ton one line. Change this to get spaces betweenHw 1 Hw 2... You should get

Hw 1 Hw 2 ... Exam Grade

notH1H2 ... notHw1 Hw2 .... Once you get the program working,delete n=3and uncomment the read *,nline to enable user input. program printtitle print *,'Enter # of homework assignments' n=3 ! afterthe pr ogramworks, delete this and read *, n !uncomment this to accept input. do i=1,n print 100 ,'Hw',i !keep the ,'Hw',i enddo

100 format(a

1 ,i 1 print '(a6,a6)','Exam','Grade' endprogram

We can call a subroutine to execute a printing.

e11.1 The follo wingsubroutine prin tsa m atrixbwithnrows andm columns. The programprintmatrixtestexecutes this subroutines to print a matrixawith 2 rows and 2 columns. subroutine printmatrix(b,n,m) integer::n,m real::b(n,m) !n = # rows, m = # columns do i=1,n; print '(20f6.2)',b(i,1:m); enddo endsubroutine !2 decimal reals printed in fields of 6 spaces program printmatrixtest real::a(2,2) a(1,:)=[10.25,200.] a(2,:)=[3.,4.5] call printmatrix(a,2,2) endprogram c11.2 W ritea programwhich reads in a 33 matrixaand then extends ato a 44 matrix with an added column on the right and added row on the bottom. In each row, the value in the last column is 10 times the rows rst element plus the sum of the next two elements. Each bottom row element is the average of the values above it. Print the resulting matrix with theprintmatrixsubroutine of the previous example. c11.3 W ritea p rogramcalculatewhich extends annmmatrixato a larger (n+1)(m+1) matrix. Get from the user the number of rowsn and the number of columnsm. Allocate space for an (n+1)(m+1) ma- trixa. The user then entersnrows, one at a time, each withmcolumns. These are the rstnrows andmcolumns ofa. Your program calculates the lastm+1column whose entries are the sum of them-1rst columns scores plus 3 times themcolumn. Then, your program calculates each n+1row entry which is the average (mean) of thenscores above it. Fi- nally use theprintmatrixsubroutine to print the matrix. But modify the subroutine so the printed rows start withstudent 1, student 2, ...averages. For instance, if the user enters the 44 matrix

4 4 4.2 8

4 2 2.11 3

1 0 0.5 0

3.5 3 3 2

the output should look like 2 student 1 4 4 4.2 8 36.2 student 2 4 2 2.11 3 17.11 student 3 1 0 0.5 0 1.5 student 4 3.5 3 3 2 15.5 averages 3.12 2.25 2.45 3.25 17.58 c11.4 Let a= [a1;a2;:::;an] be a vector of lengthnand letmbe the average value of the entriesa1; a2;:::; an. The standard deviation ofa is given by r(a1m)2+ (a2m)2++ (anm)2n Write a functionstddev(a,n)which, given a vectoraofnreal num- bers, returns the standard deviation ofa. Write a program to test your function. c11.5 W ritea function grade2(x,m,s)which, given an real scorex, a mean valuemand a standard deviationsreturns the character •A if x is 2 std. dev. above the mean, •F if x is 2 std. dev. below the mean, •B if x is 1 std. dev. above the mean, •D if x is 1 std. dev. below the mean, •C otherwise. Write a programtestgradewhich appliesgradeto three inputsx,m andsentered by the userc11.6Assume that there are nstudents in a class and each of them has receivedmscores along the semester, corresponding tom1 homeworks and 1 exam. Write a program which extends thenmmatrix of scores toato a larger (n+1)(m+1) matrix. Get from the user the number of students (n) and the number of scores per students (m). Allocate space for an (n+1)(m+1) matrixa. The user then enters the scores of the students (m-1homework scores and 1 exam score). These are the rstnrows and mcolumns ofa. The program calculates the last (m+1) column (the students grade scores) which are the sum of them-1homework scores plus 3 times the exam score. Your program calculates each bottom-row (n+1 row) entry which is the average (mean) of the n scores above it. The user then enters the names of the students, which are listed in a vectornamesof lengthn+1of characters strings. Assign'averages' toname(n+1).Using thestddevfunction fromc11.5 , nd the standard deviation of the grade scores (m+1 column). Modifyprintmatrixto a subroutine which prints rst the initial head- ing

Hw 1 Hw 2 ... Exam Grade

to the screen and then prints for each student, the students name (use the built-in functiontrimto trim o trailing blanks in students' names ), homework scores, exam score, nal grade score, and, at the end of each line, prints the letter grade calculated by thegrade2function from c11.5 . (Useadvance='no'with thewritefunction to keep the letter grade on the same line). The last line will be the averages row, with no letter grade at the end.The columns must line up vertically.

If the user enters the matrix of scores

3

4 4 4.2 8

4 2 2.11 3

1 0 1.5 0

3.5 3 3 2;

and the list of students [jackson,johnson,nugimoto,weng] the output should look like hw 1 hw 2 hw 3 Exam Grade jackson 4.00 4.00 4.20 8.00 36.20 B johnson 4.00 2.00 2.11 3.00 17.11 C nugimoto 1.00 0.00 1.50 0.00 2.50 B weng 3.50 3.00 3.00 2.00 15.50 C averages 3.12 2.25 2.70 3.25 17.83LABWORK SESSION, Monday, May 4th, 2015.

Send the problems in one email to

gautier@math.ha waii.edu with the subject line

190 l11(10)

.Don't attach les! In linear algebra, anmmatrixAis said to be aboolean matrixif all its entries are equal to 0 or 1. For instance,

B=1 0 1

0 1 1 andC=2

40 1 0 0

0 1 1 0

0 0 1 03

5 are boolean matrices. Moreover, a boolean matrix with constant row sums is called adesign matrix. For instance, the matrixBabove is a design matrix (its row sums are constant equal to 2) but the matrixCis not (the sum of its rst row is 1 but the sum of its second row is 2).Write a functionisboolean(a,n,m)which, given two integersnandmand a nmmatrixaof integers, returns.TRUE.ifais a boolean matrix and .FALSE.otherwise. Write a functionisdesign(a,n,m)which, given two integersnandmand anmmatrixaof integers, returns.TRUE.ifa is a design matrix and.FALSE.otherwise. Then, write a program which •asks for and reads a numbern, •asks for and reads a numberm, •allocates space for anmmatrixa, •asks for and reads thenrows ofa, one at a time, •use a subroutineprintmat(a,n,m)to print the matrix according to the following format: for each row of the matrixa, the subrou- tine prints the entries of the row (those entries may be considered as integers with 3 spaces saved) then prints the character string 'sum of the row:'and nally prints the row sum (which may be considered as an integer with 3 spaces saved), 4 •uses the functionisbooleanto print'This matrix is a boolean matrix'ifais a boolean matrix and'This matrix is not a boolean matrix'otherwise, •uses the functionisdesignto print'This matrix is a design matrix'ifais a design matrix and'This matrix is not a design matrix'otherwise. For instance, if the user enters the matrix C above, the output should look like

0 1 0 0 sum of the row: 1

0 1 1 0 sum of the row: 2

0 0 1 0 sum of the row: 1

This matrix is a boolean matrix

This matrix is not a design matrix

5 6quotesdbs_dbs21.pdfusesText_27
[PDF] fortran 90/95 pdf

[PDF] fortran 95 compiler

[PDF] fortran 95 continuation line

[PDF] fortran 95 do loop

[PDF] fortran 95 download

[PDF] fortran 95 manual

[PDF] fortran 95 tutorial

[PDF] fortran 95 write

[PDF] fortran 95/2003 explained

[PDF] fortran command

[PDF] fortran exercises

[PDF] fortran grammar

[PDF] fortran manual

[PDF] fortran parameter

[PDF] fortran syntax cheat sheet