- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The new Cosines example that you submitted is now published in the Fortran Developer Guide 2023.1.
Read all about it!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page