Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26758 Discussions

AboutboxQQ and C-Style Escape Sequences

Ted_Lillys
Beginner
240 Views

Hi all

I have an about box in a QuickWin app, compiled for x64 and I'm having some trouble getting some escape sequences to be respected.  The following code generates the following about box.  I've tried single quotes, double quotes, ''C or CHAR(0) to terminate the string with no change in result.  The presence of "Use IFQWIN " has no impact.  Any thoughts?

TIA - Ted

      STRING1 = 'Regular Build\n'
      STRING2 = 'Mixed Aquifer pH used for isotherm selection\n'
      STRING3='Report Surface Water Body Results as Mass Fluxes'
    
  ii = ABOUTBOXQQ('EPAs Composite Model for Leachate '//
     >   'Migration with Transformation Products\n'//
     >   'EPACMTP Version '//getVerStr()//'\n'//
     >   'Build Notes:\n'//
     >   trim(STRING1)//trim(STRING2)//trim(STRING3)//CHAR(0))

4-24-2017 5-38-36 PM.jpg

0 Kudos
1 Solution
IanH
Black Belt
240 Views

Try using CHAR(10) instead of the embedded '\n' sequence, e.g.

STRING1 = "Regular Build" // CHAR(10)

Position 10 in the character set used by Intel Fortran (which is some sort of ascii extension - you could use ACHAR instead of CHAR) is the newline character.

View solution in original post

13 Replies
IanH
Black Belt
241 Views

Try using CHAR(10) instead of the embedded '\n' sequence, e.g.

STRING1 = "Regular Build" // CHAR(10)

Position 10 in the character set used by Intel Fortran (which is some sort of ascii extension - you could use ACHAR instead of CHAR) is the newline character.

View solution in original post

Ted_Lillys
Beginner
240 Views

IanH - Thanks.  That did the trick:

4-24-2017 6-54-34 PM.jpg

Steve_Lionel
Black Belt Retired Employee
240 Views

C-style escape sequences work only in C strings. Try this:

   STRING1 = 'Regular Build\n'
    STRING2 = 'Mixed Aquifer pH used for isotherm selection\n'
    STRING3='Report Surface Water Body Results as Mass Fluxes'
  
ii = ABOUTBOXQQ('EPAs Composite Model for Leachate '//
   >   'Migration with Transformation Products\n'C//
   >   'EPACMTP Version '//getVerStr()//'\n'C//
   >   'Build Notes:\n'C//
   >   trim(STRING1)//trim(STRING2)//trim(STRING3)//CHAR(0))

 

GVautier
New Contributor II
240 Views
       STRING1 = 'Regular Build\n'c
       STRING2 = 'Mixed Aquifer pH used for isotherm selection\n'c

Al strings with escaped characters must be C strings.

How does Fortran manage concatenation of C strings?

In my sens string1//string2 will lead to a char(0) in the middle of the resulting string. Am I wrong?

jimdempseyatthecove
Black Belt
240 Views

>>How does Fortran manage concatenation of C strings?

Likely by writing a function that locates the NULL in the left string (or used entire string in the event of lack of NULL).

It is Fortran, it knows not of C strings (other than for literal constant). You get the null.

character(len=128) :: text
text = "Howdy\n"C

Has a newline and NULL at positions 6 and 7, followed by 121 spaces.

Jim Dempsey

Steve_Lionel
Black Belt Retired Employee
240 Views

jimdempseyatthecove wrote:

>>How does Fortran manage concatenation of C strings?

Likely by writing a function that locates the NULL in the left string (or used entire string in the event of lack of NULL)

Nope - the only recognition of C-string as a concept (and this is an extension, not a standard feature), is in literal constants. Nothing else, including concatenation, knows that such a thing exists. Once you have a variable with an embedded NUL, that is just another byte of data.

Ted_Lillys
Beginner
240 Views

I tried both Steve's and Gilles' suggestions but the result was less satisfying:

4-25-2017 8-48-57 AM.jpg

IanH's suggestion worked:

      STRING1 = 'Regular Build'//CHAR(10)
      STRING2 = 'Mixed Aquifer pH used for isotherm selection'//CHAR(10)
      STRING3='Report Surface Water Body Results as Mass Fluxes'

      ii = ABOUTBOXQQ('EPAs Composite Model for Leachate '//
     >   'Migration with Transformation Products'//CHAR(10)//
     >   'EPACMTP Version '//getVerStr()//CHAR(10)//
     >   'Build Notes:'//CHAR(10)//
     >   trim(STRING1)//trim(STRING2)//trim(STRING3)//CHAR(0))

Result:

4-25-2017 8-57-59 AM.jpg

While testing I noticed something else.  After changing the code and rebuilding for Release x64 I would get a LNK1104 error: cannot open file 'x64\Release\EPACMTPV2_2.exe'.  I checked the Task Manager and the process from the previous test was still active.  I had started the process with "Start without Debugging" and killed the application with Ctrl-C.  After killing the process, the build would complete normally.  Any idea why the process would persists after closing the program?

Steve_Lionel
Black Belt Retired Employee
240 Views

You're right, my suggestion won't work for you for exactly the reason I described in post 7. Sorry about that. The point remains that C escape sequences are recognized only inside C-string literals.

Ted_Lillys
Beginner
240 Views

No worries, Steve. Thanks for the response.  I did have another question that I hid at the end of my last post.  Long story short, when I was testing the Release version of the program, the process seemed to persist after closing the program with Ctrl+C.  Any clues as to why that would happen?

 

Steve_Lionel
Black Belt Retired Employee
240 Views

Compiler version? I recall a problem like this in QuickWin from last year, but thought it was fixed in 17.0.2 (or maybe earlier).

Ted_Lillys
Beginner
240 Views

Parallel Studio XE 2017 Update 2 Composer Edition for Fortran Windows* Integration for Microsoft VS 2015, Version 17.0.0041.14

Steve_Lionel
Black Belt Retired Employee
240 Views

Ok, that's current. Perhaps one of the Intel folks can check on the status of the QuickWin process persistence bug.

jimdempseyatthecove
Black Belt
240 Views
!  strcat.f90 
module string_lib
    contains
    function my_strcat(a, b)
        implicit none
        character(:), allocatable :: my_strcat
        character(LEN=*), intent(in) :: a, b
        integer a_end, b_end
        a_end = INDEX(a,CHAR(0))
        if(a_end == 0) then
            a_end = LEN(a)
        else
            a_end = a_end-1
        endif
        
        b_end = INDEX(b,CHAR(0))
        if(b_end == 0) then
            b_end = LEN(b)
        else
            b_end = b_end-1
        endif
        my_strcat = a(1:a_end)//b(1:b_end)//CHAR(0)
    end function my_strcat
end module string_lib
    
program strcat
    use string_lib
    implicit none
    character(:), allocatable :: fee
    character(:), allocatable :: foo
    character(:), allocatable :: text
    
    fee = "fee"//CHAR(0)//"junk"
    foo = "foo"//CHAR(0)//"junkToo"
    text = my_strcat(fee,foo)
    print *, text, len(text)
end program strcat

Jim Dempsey

Reply