02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

I/O and file handling<br />

Syntax of I/O statements<br />

The implied-DO loop is generally used to transmit arrays and array elements, as in the<br />

following:<br />

INTEGER :: b(10)<br />

PRINT *, (b(i), i = 1,10)<br />

If b has been initialized with the values 1 through 10 in order, the PRINT statement will<br />

produce the following output:<br />

1 2 3 4 5 6 7 8 9 10<br />

If an nonsubscripted array name occurs in the list, the entire array is transmitted at each<br />

iteration. For example:<br />

REAL :: x(3)<br />

PRINT *, (x, i=1, 2)<br />

If x has been initialized to be [ 1 2 3 ],theoutputwillbe:<br />

1.0 2.0 3.0 1.0 2.0 3.0<br />

The list can contain expressions that use the index value. For example:<br />

REAL :: x(10) = (/.1, .2, .3, .4, .5, .6, .7, .8, .9, 1 /)<br />

PRINT *, (i*2, x(i*2), i = 1, 5)<br />

print the numbers<br />

2 .2 4 .4 6 .6 8 .8 10 1<br />

Implied-DO loops can also be nested. The form of a nested implied-DO loop in an I/O statement<br />

is:<br />

(((list, index1 = init1, limit1, step1), index2 = init2, limit2,<br />

step2) ... indexN = initN, limitN, stepN)<br />

Nested implied-DO loops follow the same rules as do other nested DO loops. For example, given<br />

the following statements:<br />

REAL :: a(2,2)<br />

a(1,1) = 1<br />

a(2,1) = 2<br />

a(1,2) = 3<br />

a(2,2) = 4<br />

WRITE(6,*)((a(i,j),i=1,2),j=1,2)<br />

the output will be:<br />

1.0 2.0 3.0 4.0<br />

The first, or nested DO loop, is completed once for each execution of the outer loop.<br />

192<br />

Chapter 8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!