这是我的简单(测试)代码:
MODULE TEST_MODULE
USE, INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
INTEGER, PARAMETER :: IP = C_INT
INTEGER, PARAMETER :: LP = C_BOOL
INTEGER, PARAMETER :: CP = C_CHAR
INTEGER( IP ), PARAMETER :: UN = 15
INTEGER( IP ) :: DATA_00, DATA_01, DATA_02
CHARACTER(*), PARAMETER :: FMTR = 'BASE\DATA_STORAGE.TXT'
CONTAINS
FUNCTION DATA_READING( ) RESULT( ERROR_TMP )
LOGICAL( LP ) :: ERROR_TMP
ERROR_TMP = .FALSE.
OPEN( UNIT = UN, FILE = FMTR, ACTION = 'READ', STATUS = 'UNKNOWN', ERR = 100 )
READ( UN, * , ERR = 101 ) DATA_00
READ( UN, * , ERR = 102 ) DATA_01
READ( UN, * , ERR = 103 ) DATA_02
CLOSE( UNIT = UN, STATUS = 'KEEP')
RETURN
100 WRITE(*,*) "ERROR - NO SUCH A FILE OR FILE LOCATION !!!"
ERROR_TMP = .TRUE.
101 WRITE(*,*) "ERROR - FMT OF READING - DATA_TMP_00 - 101 !!!"
ERROR_TMP = .TRUE.
102 WRITE(*,*) "ERROR - FMT OF READING - DATA_TMP_01 - 102 !!!"
ERROR_TMP = .TRUE.
103 WRITE(*,*) "ERROR - FMT OF READING - DATA_TMP_02 - 103 !!!"
ERROR_TMP = .TRUE.
END FUNCTION DATA_READING
END MODULE TEST_MODULE
PROGRAM TEST_CODE
USE, NON_INTRINSIC :: TEST_MODULE
IMPLICIT NONE
LOGICAL( LP ) :: GLOBAL_ERR
GLOBAL_ERR = DATA_READING()
IF ( GLOBAL_ERR ) STOP ( "ERROR - DATA READING !!!" )
PRINT *, DATA_00
PRINT *, DATA_01
PRINT *, DATA_02
END PROGRAM TEST_CODE
DATA_STORAGE.TXT
文件包含:
1407
1408
1409
当我运行程序时,它将以正确的方式从指定的文件中加载数据-因为文件中的所有数据都是整数类型,所以不会出现全局错误消息。
例如,如果1407.23
中第一个数据的更改值是实型,则在启动后,程序将在屏幕上打印所有错误标签,包括有关存在全局错误的错误标签。
我的问题是:
如何在屏幕上仅打印属于输入格式不正确的数据的错误标签?
该代码已在两个IDE中进行了测试:
Code::Blocks 1712 GFortan 6.3.0
Visual Studio 2010 with Intel Parallel XE 2011