IF块语法

时间:2013-07-22 19:14:34

标签: if-statement fortran

我正在尝试比较一个月的数组,以检查每个数字是奇数月甚至是月份,以便我可以将文件标记为月份// date // year.txt并上传与另一个匹配日期的行将文件放入相应的.txt文件中。

我的输出应该是90个.txt文件,每个文件都包含与APM_FORMATTED.txt中特定日期匹配的行。

PROGRAM APM_TEST
IMPLICIT NONE

INTEGER :: READSTATUS, YEAR_MIN, MONTH_MIN, DAY_MIN, YEAR_MAX, MONTH_MAX, DAY_MAX, I, IND, IND1, D, D1, D2 
CHARACTER(13) :: DATE_INPUT
CHARACTER(2) :: FILE_DAY, FILE_MONTH, FILE_YEAR, CURRENT_DAY, CURRENT_MONTH
CHARACTER(632) :: ROW1
INTEGER, DIMENSION(1,6) :: M
INTEGER, DIMENSION(1,6) :: N
INTEGER, DIMENSION(1,3) :: MON


WRITE(*,'(" ENTER DATE RANGE OF FILE (E.G. 010413-010713):")', ADVANCE = "NO")
        READINT : DO
            READ (*,*,IOSTAT=READSTATUS) DATE_INPUT
            IF (READSTATUS==0) THEN
            EXIT READINT
            ELSE
            WRITE(*,'(/"READ ERROR. PLEASE RE-INPUT:")')
            ENDIF
        ENDDO READINT

        READ(DATE_INPUT(5:6), '(I2)') YEAR_MIN 
        READ(DATE_INPUT(3:4), '(I2)') MONTH_MIN
        READ(DATE_INPUT(1:2), '(I2)') DAY_MIN
        READ(DATE_INPUT(12:13), '(I2)') YEAR_MAX
        READ(DATE_INPUT(10:11), '(I2)') MONTH_MAX
        READ(DATE_INPUT(8:9), '(I2)') DAY_MAX




        IND=1
        IND1=1
        M=(/1,3,5,7,9,11/)
        N=(/4,6,8,10,12/)

36      DO MON=MONTH_MIN, MONTH_MAX
            IF (ANY(M.EQ.MON(IND))) THEN

                DO D=DAY_MIN,31
                    FILE_DAY=DATE_INPUT(1:2)
                    FILE_MONTH=DATE_INPUT(3:4)
                    FILE_YEAR=DATE_INPUT(5:6)
                    OPEN(UNIT=201, FILE="APM_FORMATTED.TXT")
                    OPEN(IND1, FILE=(FILE_MONTH//FILE_DAY//FILE_YEAR//".TXT"), ACTION="WRITE", STATUS="NEW") 
45                  DO I=1,200000
                        READ(201,'(A632)') ROW1
                        IF (ROW1(1:3).EQ.'APM') THEN
                        READ(ROW1(41:42), '(I2)') CURRENT_DAY
                        READ(ROW1(43:44), '(I2)') CURRENT_MONTH

                            IF (CURRENT_MONTH.EQ.MON .AND. CURRENT_DAY.EQ.D) THEN 
                            WRITE(IND1,*) ROW1
                            ELSE
                            GOTO 45
                            ENDIF

                        ELSE 
                        ENDIF
                    ENDDO
                    IND1=IND1+1
                    CLOSE(IND1)
                    CLOSE(201)
                ENDDO

            ELSEIF (ANY(N.EQ.MON)) THEN

                DO D1=DAY_MIN,30
                    FILE_DAY=DATE_INPUT(1:2)
                    FILE_MONTH=DATE_INPUT(3:4)
                    FILE_YEAR=DATE_INPUT(5:6)
                    OPEN(UNIT=201, FILE="APM_FORMATTED.TXT")
                    OPEN(IND1, FILE=(FILE_MONTH//FILE_DAY//FILE_YEAR//".TXT"), ACTION="WRITE", STATUS="NEW") 
73                  DO I=1,200000
                        READ(201,'(A632)') ROW1
                        IF (ROW1(1:3).EQ.'APM') THEN
                        READ(ROW1(41:42), '(I2)') CURRENT_DAY
                        READ(ROW1(43:44), '(I2)') CURRENT_MONTH

                            IF (CURRENT_MONTH.EQ.MON .AND. CURRENT_DAY.EQ.D1) THEN 
                            WRITE(IND1,*) ROW1
                            ELSE
                            GOTO 73
                            ENDIF

                        ELSE
                        ENDIF
                    ENDDO
                    IND1=IND1+1
                    CLOSE(IND1)
                    CLOSE(201)
                ENDDO

            ELSEIF (ANY(M.EQ.4)) THEN 

                DO D2=DAY_MIN,28
                    FILE_DAY=DATE_INPUT(1:2)
                    FILE_MONTH=DATE_INPUT(3:4)
                    FILE_YEAR=DATE_INPUT(5:6)
                    OPEN(UNIT=201, FILE="APM_FORMATTED.TXT")
                    OPEN(IND1, FILE=(FILE_MONTH//FILE_DAY//FILE_YEAR//".TXT"), ACTION="WRITE", STATUS="NEW") 
101                 DO I=1,200000
                        READ(201,'(A632)') ROW1
                        IF (ROW1(1:3).EQ.'APM') THEN
                        READ(ROW1(41:42), '(I2)') CURRENT_DAY
                        READ(ROW1(43:44), '(I2)') CURRENT_MONTH

                            IF (CURRENT_MONTH.EQ.MON .AND. CURRENT_DAY.EQ.D2) THEN
                            WRITE(IND1,*) ROW1
                            ELSE
                            GOTO 101
                            ENDIF

                        ELSE
                        ENDIF

                    ENDDO
                    IND1=IND1+1
                    CLOSE(IND1)
                    CLOSE(201)
                ENDDO
            ELSE 
            GOTO 36
            ENDIF
            IND=IND+1
            DAY_MIN=1

    ENDDO

END PROGRAM APM_TEST

Errors:
error FOR2614: assignment between arrays of differing rank
error FOR2614: assignment between arrays of differing rank
error FOR2799: DO control variable MON is not scalar
error FOR2979: expected 2 subscripts but found 1 for array MON
error FOR3041: operands to relational operator .EQ. are of incompatible data type
error FOR3041: operands to relational operator .EQ. are of incompatible data type
error FOR3048: illegal data type to binary logical operator .AND. 
error FOR3156: array shapes differ in dimension 2 (extent 6 and 3)
error FOR3041: operands to relational operator .EQ. are of incompatible data type
error FOR3041: operands to relational operator .EQ. are of incompatible data type
error FOR3048: illegal data type to binary logical operator .AND. 
error FOR3041: operands to relational operator .EQ. are of incompatible data type
error FOR3041: operands to relational operator .EQ. are of incompatible data type
error FOR3048: illegal data type to binary logical operator .AND. 

1 个答案:

答案 0 :(得分:2)

第38行和第45行有语法错误(很可能也是其他行)。查看您最喜欢的书籍或在线教程,了解正确的IF块和语句语法。 Fortran中的基本IF - 块语法采用以下形式:

IF(scalar-logical-expr)THEN
  ...
ELSEIF(scalar-logical-expr)THEN
  ...
ELSE
  ...
ENDIF