看不懂的错误提示First non-blank character in a character type format ...
一个简单的程序,就是编译不出来,错误提示看不懂PROGRAM capacitor
IMPLICIT NONE
! Data dictionary: declare constants
REAL, PARAMETER :: ELECTRONS_PER_COULOMB = 6.241461E18
! Data dictionary: declare variable types, definitions, & units
REAL :: c ! Capacitance of the capacitor (farads).
REAL :: charge ! Charge on the capacitor (coulombs).
REAL :: electrons ! Number of electrons on the plates of the capacitor
REAL :: energy ! Energy stored in the electric field (joules)
INTEGER :: type ! Type of input data available for the calculation:
!1:C and V
!2:CHARGE and V
REAL :: v ! Voltage on the capacitor (volts).
! Prompt user for the type of input data available.
WRITE (*, 100)
100 FORMAT (' This program calculates information about a ' &
'capacitor.',/, ' Please specify the type of information',&
' available from the following list:',/,&
' 1 -- capacitance and voltage ',/,&
' 2 -- charge and voltage ',//,&
' Select options 1 or 2: ')
! Get response and validate it.
DO
READ (*,*) type
IF ( (type == 1) .OR. (type == 2) ) EXIT
WRITE (*,110) type
110 FORMAT (' Invalid response: ', I6, '.Please enter 1 or 2:')
END DO
! Get additional data based upon the type of calculation.
input: IF ( type == 1 ) THEN
! Get capacitance.
WRITE (*,' Enter capacitance in farads: ')
READ (*,*) c
! Get voltage.
WRITE (*,' Enter voltage in volts: ')
READ (*,*) v
ELSE
! Get charge
WRITE (*,' Enter charge in coulombs: ')
READ (*,*) charge
! Get voltage.
WRITE (*,' Enter voltage in volts: ')
READ (*,*) v
END IF input
! Calculate the unknown quantities.
calculate: IF ( type == 1 ) THEN
charge = c * v ! Charge
ELSE
c = charge / v ! Capacitance
END IF calculate
electrons = charge * ELECTRONS_PER_COULOMB ! Electrons
energy = 0.5 * c * v**2 ! Energy
! Write out answers.
WRITE (*,120) v, c, charge, electrons, energy
120 FORMAT (' For this capacitor: ',/, &
' Voltage = ', F10.2, ' V',/, &
' Capacitance = ', ES10.3, ' F',/, &
' Total charge = ', ES10.3, ' C',/, &
' Number of electrons = ', ES10.3,/, &
' Total energy = ', F10.4, ' joules' )
END PROGRAM capacitor
错误提示:First non-blank character in a character type format specifier must be a left parenthesis. [' Enter capacitance in farads: ']
WRITE (*,' Enter capacitance in farads: ')
改为
WRITE (*,'("Enter capacitance in farads: ")')
其他几处类同 fcode 发表于 2014-8-26 22:05
WRITE (*,' Enter capacitance in farads: ')
改为
WRITE (*,'("Enter capacitance in farads: ")')
谢谢!
是不是写在write里面的必须加括号啊?
我试了单引号加双引号可以,双引号加单引号也可以,如果是相同的引号就不行,这个详细的是怎么规定的啊,有点不清楚 麦田守望者 发表于 2014-8-27 10:32
谢谢!
是不是写在write里面的必须加括号啊?
我试了单引号加双引号可以,双引号加单引号也可以,如果是 ...
试验出来的就是规矩,以后在使用中就有经验了,就按照这个经验来。 珊瑚虫 发表于 2014-8-27 10:40
试验出来的就是规矩,以后在使用中就有经验了,就按照这个经验来。
嗯,实践出真知啊 Fortran 的单引号,双引号是等价的。
但是,如果引号里面还有引号,就会冲突。所以需要单引号和双引号间隔使用。
WRITE (*,'("Enter capacitance in farads: ")')
与
WRITE (*,"('Enter capacitance in farads: ')")
是同一个意思。
vvt 发表于 2014-8-27 12:16
Fortran 的单引号,双引号是等价的。
但是,如果引号里面还有引号,就会冲突。所以需要单引号和双引号间隔 ...
这样的啊,谢谢~
页:
[1]