Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Page 638 suggested changes to code

JohnNichols
Valued Contributor III
356 Views
program Cosines
    implicit none
    INTEGER, PARAMETER :: dp = selected_real_kind(15, 307)
    integer,parameter :: k15 = selected_int_kind(15)
    INTEGER(kind=k15) k

    real(kind = dp) :: a, b,c
    !Write to the screen (preconnected unit 6).
    WRITE(6, '('' This is unit 6'')')
    ! Use the OPEN statement to connect unit 6
    ! to an external file named 'COSINES'.
    OPEN (UNIT = 6, FILE = 'COSINES', STATUS = 'UNKNOWN')
    DO k = 1, 63, 1
        c = real (k)
        a = c/10.0
        b = COS (a)
        ! Write to the file 'COSINES'.
        WRITE (6, 100) a, b
        WRITE (*, 100)k, a, b
100     FORMAT (I4, '   ',F3.1,'   ', F5.2)
    END DO
    ! Close it.
    CLOSE (6)
    ! Reconnect unit 6 to the screen, by writing to it.
    ! Reconnect unit 6 to the screen, by writing to it.
    WRITE(6,' ('' Cosines completed'')')
    END cosines

The original code needs a little help.

3 Replies
Barbara_P_Intel
Moderator
292 Views

Thank you, again, @JohnNichols. I filed a feature request, DOC-10967, to modernize the Fortran example.

BTW... did you run this? I made some tweaks with the FORMAT statements.

PROGRAM Cosines
    implicit none
    INTEGER, PARAMETER :: dp = selected_real_kind(15, 307)
    integer,parameter :: k15 = selected_int_kind(15)
    INTEGER(kind=k15) k
    real(kind = dp) :: a, b,c

    !Write to the screen (preconnected unit 6).
    WRITE(6, '('' This is unit 6'')')
    ! Use the OPEN statement to connect unit 6
    ! to an external file named 'COSINES'.
    OPEN (UNIT = 6, FILE = 'COSINES', STATUS = 'UNKNOWN')
    DO k = 1, 63, 1
        c = real (k)
        a = c / 10.0
        b = COS(a)
        ! Write to the file 'COSINES'.
        WRITE (6, 100) a, b
        WRITE (*, 101)k, a, b
100     FORMAT (F3.1, '   ', F5.2)
101     FORMAT (I4, '   ', F3.1,'   ', F5.2)
    END DO
    ! Close it.
    CLOSE (6)
    ! Reconnect unit 6 to the screen, by writing to it.
    WRITE(6,' ('' Cosines completed'')')
END PROGRAM Cosines

 

0 Kudos
JohnNichols
Valued Contributor III
236 Views

@Barbara_P_Intel 

1. I have a standard Fortran Program called Console 3 set up in Visual Studio 2022.  

2. I copy the code into this program which is a shell from one of your standard formats

3. I run it till there are no errors. 

4. I upload it to this site straight from Console 3.  

5. I throw it away. 

 

But you are correct, the code I copied across was missing the last program, my mistake, IaMS. 

0 Kudos
Barbara_P_Intel
Moderator
140 Views

The new Cosines example that you submitted is now published in the Fortran Developer Guide 2023.1.

Read all about it!



0 Kudos
Reply