0

我正在编写一个代码来获取输入文件并逐行(ROWS)对其进行更改。我使用一些分隔符,如“@”和“#”来分隔行并对每个类别的行进行不同的更改。当我运行代码时,一切都很好,但是当我执行它时,它会生成一个空白的 .txt 文件。这是我的代码。帮我。

程序转换1

    !!DEFINES THE DIFFERENT VARIABLES USED IN CONVERSION1 PROGRAM!!
    INTEGER ::  K, L
    REAL :: A(5)
    CHARACTER :: ROW1

    !!INCLUDES THE BLOCK TO CONTINUE BUILDING ON THE VALUE OF J(LINE NUMBERS)!!
    INCLUDE 'OTHER_CONDITIONS.BLK'


    !!OPENS EXISTING FILE TO BE READ AND THEN PROGRAM WRITES IT TO 2ND MODIFIED FILE!!
    OPEN(UNIT=1, FILE='C:\MSDEV\Projects\UUDF_Conversion\BXK__96B.TXT')
    OPEN(UNIT=2, FILE='C:\MSDEV\Projects\UUDF_Conversion\BXK__96B_MODIFIED.TXT')

    !!TO OBTAIN AN ARRAY OF LINE NUMBERS WHERE A NEW CATEGORY STARTS, SYMBOLIZED BY '@'!!


    L=1
    DO K=1,10000
    READ(1,'(A150)') ROW1
    IF (ROW1(1:1)=='@') THEN
    A(L)= K
    L = L+1
    ENDIF
    ENDDO 
    CONTINUE

    PRINT(*,*) ROW, ROW1

    !!DO LOOP GOES THROUGH EACH AND EVERY LINE OF THE DOCUMENT CHECKING FOR CONDITIONS MET IN ORDER TO MANIPULATE!!
    DO J=1,10000
    READ(1,'(A150)') ROW

            !!AIRPORT DATA!!
            IF ((J==2) .AND. (ROW(73:73).NE. ' ') .AND. (ROW(80:80).EQ.'|')) THEN
                WRITE(2, '(A)') ROW(1:75) // ROW(78:150)
            ELSEIF ((J==5) .AND. (ROW(8:8).NE. ' ') .AND. (ROW(15:15).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:10) // ROW(13:150)
            ELSEIF ((J==6) .AND. (ROW(27:27).NE. ' ') .AND. (ROW(34:34).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:29) // ROW(32:150)
            ELSEIF ((J==7) .AND. (ROW(18:18).NE. ' ') .AND. (ROW(25:25).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:20) // ROW(23:150)

            !!RUNWAY DATA BEFORE THE FIRST '#'!!            
            ELSEIF ((J==(A(1)+1)) .AND. (ROW(17:17).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:12) // ROW(15:150)
            ELSEIF ((J==(A(1)+2)) .AND. (ROW(11:11).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:6) // ROW(9:150)
            ELSEIF ((J==(A(1)+3)) .AND. (ROW(17:17).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:12) // ROW(15:150)
            ELSEIF ((J==(A(1)+4)) .AND. (ROW(25:25).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:20) // ROW(23:150)
            ELSEIF ((J==(A(1)+5)) .AND. (ROW(31:31).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:26) // ROW(29:150)
            ELSEIF ((J.GT.(A(1)+6)) .AND. (ROW(1:1).NE.'@') .OR. (ROW(1:1).NE.'#')) THEN
                    WRITE(2, '(A)') ROW(1:39) // ROW(42:150)
            ELSEIF ((J.GT.A(1)) .AND. (J.LT.A(2)) .AND. (ROW(1:1)=='#')) THEN
                    CALL RUNWAY_DATA

            !!NAVIGATIONAL AID DATA!!       
            ELSEIF ((J==(A(2)+1)) .AND. (ROW(101:101).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:96) // ROW(99:150)
                    WRITE(2, '(A)') ROW(1:26) // ROW(35:150)
                    WRITE(2, '(A)') ROW(1:71) // ROW(74:150)
            ELSEIF ((J==(A(3)-1)) .AND. (J=='#')) THEN
                    WRITE(2, '(A)') '@'

            !!OBSTRUCTION 1!!       
            ELSEIF ((J.GT.A(3)) .AND. (ROW(129:129).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:124) // ROW(127:150)

            !!OBSTRUCTION 2!!       
            ELSEIF ((J.GE.A(4)) .AND. (ROW(108:108).EQ.'|')) THEN
                    WRITE(2, '(A)') ROW(1:103) // ROW(106:150) 

            !!IF ALL ELSE FAILS!!
            ELSE
                WRITE(2, '(A)') ROW
            ENDIF

    END DO
    CONTINUE                    
    END

    !!SUBROUTINE RUNWAY_DATA TO MANIPULATE DATA AFTER THE '@' IN RUNWAY DATA SECTION AFTER A '#'!!
    SUBROUTINE RUNWAY_DATA

    !!REDEFINES EXISTING VARIABLES FROM MAIN PROGRAM!!

    INCLUDE 'OTHER_CONDITIONS.BLK'


    !!USES THE EXISTING LINE NUMBER FROM MAIN PROGRAM TO PROCEED ON AND CHECK LINE BY LINE FOR CONDITIONS MET WITHIN 2 '#'S'!!
    J=J+1
    IF (ROW(17:17).EQ.'|') THEN
       WRITE(2, '(A)') ROW(1:12) // ROW(15:150)
    ENDIF

    J=J+1
    IF (ROW(11:11).EQ.'|') THEN
        WRITE(2, '(A)') ROW(1:6) // ROW(9:150)
    ENDIF

    J=J+1
    IF (ROW(17:17).EQ.'|') THEN
        WRITE(2, '(A)') ROW(1:12) // ROW(15:150)
    ENDIF

    J=J+1
    IF (ROW(25:25).EQ.'|') THEN
        WRITE(2, '(A)') ROW(1:20) // ROW(23:150)
    ENDIF

    J=J+1
    IF (ROW(31:31).EQ.'|') THEN
        WRITE(2, '(A)') ROW(1:26) // ROW(29:150)
    ENDIF

    J=J+1
    IF ((ROW(1:1).NE.'@') .OR.(ROW(1:1).NE.'#')) THEN             
        WRITE(2, '(A)') ROW(1:39) // ROW(42:150)    
    ENDIF

    J=J+1
    IF ((ROW(1:1).EQ.'#') .OR. (ROW(1:1).EQ.'@')) THEN
    STOP
    ENDIF        

    RETURN
    END SUBROUTINE RUNWAY_DATA

阻止程序“OTHER_CONDITIONS.BLK”

    COMMON /INDEX_POSITION/ J
    INTEGER J


    COMMON /LINE/ ROW
    CHARACTER ROW
4

1 回答 1

0

这可能不是问题,但根据输入,您可能会遇到下标错误。我建议进行更改,例如:

implicit none

integer, parmeter :: max_at_cnt
real, dimension (max_at_cnt) :: A

...

L=1
DO K=1,10000
   READ(1,'(A150)') ROW1
   IF (ROW1(1:1)=='@') THEN
      if ( L <= max_at_cnt) then
         A(L)= K
         L = L+1
      else
         write (*, *) "Too many @s in the file!"
      end if
   END IF
END DO 
于 2012-08-07T22:35:34.287 回答