problem building formatted strings in code

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

problem building formatted strings in code

Christopher S. Talley
I have a legacy FORTRAN code that I’m attempting to build with GFORTRAN-8.3.0. Several places in the code, FORMAT strings are built from substrings for generating output. One of the FORMAT strings is created incorrectly.

In the code fragment below, the string eps should contain ‘  12(‘
but instead contain ‘  12’


        integer nf,nnnf,nnodes
        character*1 cp1
        character*4 cn,cnnf
        character*6 epf

        cp1 = '('
        nf = 5
        nnodes = 10
        write(cn,'(I4)')nnodes
        nnnf = 8+nf-1
        write(cnnf,'(i4)')nnnf
        epf = cnnf//cp1


Below is a full example that I build with ‘ gfortran -m32 formatted_io.for’:

formatted_io.for
===========================
      program main
       implicit none
       integer nf,nnnf,nnodes
       character*4 cn,cnnf
       character*1 cp1,cp2,ccm,two
       character*9 cci6
       character*11 ce12
       character*300 cf1268,modcf1268
       character*8 epf

        nf = 5
        nnodes = 10
        write(cn,'(I4)')nnodes
        nnnf = 8+nf-1
        write(cnnf,'(i4)')nnnf
        epf = cnnf//cp1

        cp1 = '('
        cp2 = ')'
        ccm = ','
        ce12 = '('' '' E12.6)'
        two = '2'
        cci6 = '('',''i6)'

       print *, nf, nnodes, nnnf
C    This prints correctly
       print *, cnnf//cp1
C    This has missing ‘(‘ at end
       print *, epf

C     Node Mixture and not print add
        cf1268 = cp1//'E12.6'//ccm//epf//cn//ce12//cp2//ccm//
     &  two//ce12//ccm//ccm//ccm//cci6//cp2
C    Incorrect string, missing ‘('
      print *, cf1268

        modcf1268 = cp1//'E12.6'//ccm//epf//cp1//cn//ce12//cp2//ccm//
     &  two//ce12//ccm//ccm//ccm//cci6//cp2
C    Correct string, with extra ‘('
      print *, modcf1268

      end program

===========================


Thanks,

Chris

Reply | Threaded
Open this post in threaded view
|

Re: problem building formatted strings in code

Thomas Koenig-6
Am 10.04.19 um 21:49 schrieb Christopher S. Talley:
>          nf = 5
>          nnodes = 10
>          write(cn,'(I4)')nnodes
>          nnnf = 8+nf-1
>          write(cnnf,'(i4)')nnnf
>          epf = cnnf//cp1
>
>          cp1 = '('

The code is invalid, cp1 is undefined while it is assigned to epf.


Reply | Threaded
Open this post in threaded view
|

Re: problem building formatted strings in code

Christopher S. Talley

Sorry. That’s what I get for juggling multiple project with interruptions. I accidentally pasted the code fragments in the wrong order. That was a side issue that popped up when I was trying to decipher a troublesome format string that was being built in my example. Does the following format string from the legacy code I am working with make sense in ANY FORTRAN dialect? GFORTRAN-8.3.0 complains about multiple commas, but Intel 2019 FORTRAN doesn’t complain.

(E12.6,  12(   (  10(' ' E12.6)),2(' ' E12.6),,,(','i6)  )

Thanks,

Chris


> On Apr 10, 2019, at 3:55 PM, Thomas Koenig <[hidden email]> wrote:
>
> Am 10.04.19 um 21:49 schrieb Christopher S. Talley:
>>         nf = 5
>>         nnodes = 10
>>         write(cn,'(I4)')nnodes
>>         nnnf = 8+nf-1
>>         write(cnnf,'(i4)')nnnf
>>         epf = cnnf//cp1
>>         cp1 = '('
>
> The code is invalid, cp1 is undefined while it is assigned to epf.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: problem building formatted strings in code

Christopher S. Talley
Sorry again. I really need to go home for the day. I meant to past the following format line:

(E12.6,  12(     10(' ' E12.6)),2(' ' E12.6),,,(','i6)  )


On Apr 10, 2019, at 5:49 PM, Chris Talley <[hidden email]<mailto:[hidden email]>> wrote:


Sorry. That’s what I get for juggling multiple project with interruptions. I accidentally pasted the code fragments in the wrong order. That was a side issue that popped up when I was trying to decipher a troublesome format string that was being built in my example. Does the following format string from the legacy code I am working with make sense in ANY FORTRAN dialect? GFORTRAN-8.3.0 complains about multiple commas, but Intel 2019 FORTRAN doesn’t complain.

(E12.6,  12(   (  10(' ' E12.6)),2(' ' E12.6),,,(','i6)  )

Thanks,

Chris


On Apr 10, 2019, at 3:55 PM, Thomas Koenig <[hidden email]<mailto:[hidden email]>> wrote:

Am 10.04.19 um 21:49 schrieb Christopher S. Talley:
       nf = 5
       nnodes = 10
       write(cn,'(I4)')nnodes
       nnnf = 8+nf-1
       write(cnnf,'(i4)')nnnf
       epf = cnnf//cp1
       cp1 = '('

The code is invalid, cp1 is undefined while it is assigned to epf.