Formatos y disruptores en Fortran

program t
implicit none
! c Column number
! d Number of digits to right of decimal place for real input or output
! m Minimum number of digits to be displayed
! n Number of spaces to skip
! r Repeat count—the number of times to use a descriptor or group of descriptors
! w Field width—the number of characters to use for the input or output

! Integer: rIw or rIw.m
INTEGER :: index = -12, junk = 4, number = -12345
WRITE (*,100) index, junk, number
100 FORMAT (I0,1X,I0,1X,I0)
!will produce the output
-12 4 -12345

! Real rFw.d
REAL :: a = -12.3, b = .123, c = 123.456
WRITE (*,200) a, b, c
WRITE (*,210) a, b, c
200 FORMAT (2F6.3, F8.3 )
!will produce the output                
****** 0.123 123.456

! Exponente rEw.d w ≥ d +7
! expresses the number as a value between 0.1 and 1.0 times a power of 10.
REAL :: a = 1.2346E6, b = 0.001, c = -77.7E10 , d = -77.7E10
WRITE (*,200) a, b, c, d
200 FORMAT (2E14.4, E13.6, E11.6 )
!will produce the output                
0.1235E+07 0.1000E-02-0.777000E+12***********

! True Scientific notation rESw.d w ≥ d +7
! Conventional scientific notation expresses a number as a
! value between 1.0 and 10.0 times a power of 10
REAL :: a = 1.2346E6, b = 0.001, c = -77.7E10
WRITE (*,200) a, b, c
200 FORMAT (2ES14.4, ES12.6)
!will produce the output
1.2346E+06 1.0000E-03************

! Logical rLw
LOGICAL :: output = .TRUE., debug
WRITE (*,"(2L5 )") output, debug
!will produce the output
T F

! Character rA or Aw
CHARACTER(len=17) :: string = 'This is a string.'
WRITE (*,10) string
WRITE (*,11) string
WRITE (*,12) string
10 FORMAT (' ', A)
11 FORMAT (' ', A20)
12 FORMAT (' ', A6)
!will produce the output
This is a string.
This is a string.
This i

! Horizontal Positioning. nX and Tc
! X Inserta n espacios
! T Tabs para una columna c específica
CHARACTER(len=10) :: first_name = 'James'
CHARACTER :: initial = 'R'
CHARACTER(len=16) :: last_name = 'Johnson'
CHARACTER(len=9) :: class = 'COSC 2301'
INTEGER :: grade = 92
WRITE (*,100) first_name, initial, last_name, grade, class
100 FORMAT (A10, 1X, A1, 1X, A10, 4X, I3, T51, A9)
!will produce the output
James R Johnson 92 COSC 2301
----|----|----|----|----|----|----|----|----|----|----|----|
5 10 15 20 25 30 35 40 45 50 55 60

! El diruptor Slash /
! Agrega lineas
! The slash (/) descriptor causes the current output buffer
! to be sent to the printer, and a new output buffer to be started.

WRITE (*,100) index, time, depth, amplitude, phase
100 FORMAT (T20,'Results for Test Number ',I3,///, &
'Time= ',F7.0/, &
'Depth= ',F7.1,' meters',/, &
'Amplitude = ',F8.2/ &,
'Phase= ',F7.1)

! Repitiendo descriptores
320 FORMAT (I6, 2(I6, 2F10.2) )
! Repite2 veces I6 y 2F10.2


end program t

Comentarios

  1. This article does a great job explaining formats and disruptors in Fortran, making it easier to manage input/output operations efficiently. If you're a gamer as well, Skynode is a perfect tool to organize your game library while you explore the intricacies of Fortran!

    ResponderEliminar

Publicar un comentario

Entradas populares de este blog

ERROR: Grib2 file or date problem, stopping in edition_num. Can't ungrib.exe SOLVED

ARCGIS: Cálculo de pendiente entre puntos en el espacio xyz

WRF open_aux_u : error opening auxinput5_d02_2013-12-31_00:00:00 for reading. 100