0

I have a file txt with 8 lines.

            <ShapeResults>
                <Integrals YYYYY />
                <Simplexes Rows="888" Cols="3">0,1,2;3,2663</Simplexes>
                <Integrals YYYYY />
                <Integrals NNNNN />
              <Group ShapeType="Optum.Shapes.Face" XXXX, YYY, ShapeID="2".....>---> 10000 characters
                <Simplexes Rows="888" Cols="3">0,1,2;3,2663</Simplexes>
                <Integrals YYYYY />
              </Group2>
              </Group>

I will change a line (e.g. line 4) and I will have the same format in the rest of the file. Line 6 has 10,000 characters more or less and I do not how to copy and write in my file. I have tried creating a new file and copy all in that file, but It has a restriction of FORMAT (A999). I only copy 999 characters. See my code.

    INTEGER                 :: RV_NUMBER, NRV, FN1, FN2, I
    CHARACTER               :: LINE*999, NAME*15, GEOS*50
    REAL*8                  :: X(1)
    character   :: totalstring*500 , formato*10, TAMANHOstring*3
    character   :: Gstring*50,Cstring*50,Fstring*50,FBstring*50,Estring*50
   
    FN1 = 1
    FN2 = 2

    OPEN(UNIT=FN1,FILE=TRIM(GEOS),POSITION="REWIND",STATUS="OLD")
    OPEN(UNIT=FN2,FILE="transito.txt",POSITION="REWIND",STATUS="UNKNOWN")

    DO WHILE (.NOT. EOF(FN1))
        READ(FN1,200) LINE
        WRITE(FN2,200) LINE
    END DO
    
    CLOSE(FN2)
    OPEN(UNIT=FN2,FILE="transito.txt",POSITION="REWIND",STATUS="OLD")
    
    REWIND(FN2)
    REWIND(FN1)
   
    DO I=1,3
        READ(FN2,200) LINE
        WRITE(tamanhostring,'(I3)') LEN_TRIM(LINE)
        formato = '(A' // adjustl(tamanhostring) // ')'
        WRITE(FN1,trim(formato)) TRIM(LINE)
    END DO

    write(Cstring,'(F7.4)') X(1)
    
    totalstring = '       <c>'
    totalstring = trim(totalstring)//trim(Cstring)//'</c>'
    
    READ(FN2,200) LINE
    write(FN1,*) trim(totalstring) 
 
        DO WHILE (.NOT. EOF(FN2))
        READ(FN2,200) LINE
        WRITE(tamanhostring,'(I3)') LEN_TRIM(LINE)
        formato = '(A' // adjustl(tamanhostring) // ')'
        WRITE(FN1,trim(formato)) TRIM(LINE)
    END DO

    CLOSE(FN1)
    CLOSE(FN2)
    
10  FORMAT(A24,G17.11,A5,ES21.15,A4)
20  FORMAT(A11,A2,F20.5)
200 FORMAT(A999)

I want to change only a line 4, and I want to have as the same format the rest of the file. The problem is in line 6 which has 10,000 characters more or less and I do not how to copy and write in my file.

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
  • Seeing as `line` is only length 999, how would you store 10000 characters in it? – francescalus Jul 28 '23 at 14:25
  • Dear @francescalus, If I put a FORMAT(A1000) or FORMAT(A10000), It produce an error. I have tested and I have found that FORMAT(A999) is a maximum value of characters – A. T. Siacara Jul 28 '23 at 14:38
  • 2
    You don't want `A1000` if `line` is only length 999. Try simply with `format(A)` and increase the length of `line`. – francescalus Jul 28 '23 at 14:44
  • Welcome, I suggest taking the [tour] around this site and reading [ask]. The string variable indeed has to be long enoigh to fit the complete string that should be stored in it. – Vladimir F Героям слава Jul 28 '23 at 14:49
  • Dear @francescalus, how can I increase the length of `line`? `LINE*999` to `LINE*10000`? – A. T. Siacara Jul 28 '23 at 14:49
  • Dear @VladimirFГероямслава, my problem is that, how can I increase the size? – A. T. Siacara Jul 28 '23 at 14:56
  • Yes, `character line*10000` declares `line` to be of length 10000. But then, so does [`character(len=10000) line`](https://stackoverflow.com/a/66532444/3157076). – francescalus Jul 28 '23 at 15:12
  • Dear @francescalus, it copy all in the new file, but it generate an error to copy to the original file. The error is in the large line. The problem is write from the new file to the original file. Do you know how to solve? – A. T. Siacara Jul 28 '23 at 17:32
  • Before I look terribly hard at this, you'll need to explain what all that fiddling with `tamanhostring` and `formato` is designed to do. Really `write(fn1,'(a)') trim(line)` would seem to be what you are after. – francescalus Jul 28 '23 at 17:40

0 Answers0