For Programmers: Free Programming Magazines  


Home > Archive > Fortran > January 2008 > How to quote the " character in a format statement?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to quote the " character in a format statement?
Mirko.Vukovic@gmail.com

2008-01-30, 7:24 pm

Hi,

This is a follow-up on my previous post, as it relates to generating
valid TecPlot files.

Given a vector of strings, I need to print out a string of the
following form (with the quote characters in it).
"string1" "string2" "string3"

I was trying along the lines of
"4('magic'A5'magic')"
but I could not quite figure out what the magic would be.

My other alternative is to modify the string's by prepending and
appending the quotes.

Any other opinions?

Thank you,

Mirko
e p chandler

2008-01-30, 7:24 pm

On Jan 30, 5:38=A0pm, Mirko.Vuko...@gmail.com wrote:
> Hi,
>
> This is a follow-up on my previous post, as it relates to generating
> valid TecPlot files.
>
> Given a vector of strings, I need to print out a string of the
> following form (with the quote characters in it).
> "string1" "string2" "string3"
>
> I was trying along the lines of
> "4('magic'A5'magic')"
> but I could not quite figure out what the magic would be.
>
> My other alternative is to modify the string's by prepending and
> appending the quotes.
>
> Any other opinions?
>
> Thank you,
>
> Mirko


You have a number of choices. Either the quote marks can go in a
format descriptor, in a separate format statement or in the argument
list. A quote mark may be expressed as the contents of a string
variable, as the result of an intrinsic function, as a string literal
(delimited by apostrophes or by quotes) or even as a Hollerith edit
descriptor in a Format statement.

Here's a sampler:

character*1 q

q=3Dachar(34)

write(*,100)
100 format('"','hello','"')

write(*,200)
200 format(1h",'hello',1h")

write(*,'("""","hello","""")')

write(*,'(a1,"hello",a1)') '"','"'

write(*,'(a1,"hello",a1)') achar(34),achar(34)

write(*,'(a1,"hello",a1)') q,q

end

etc., etc., etc.

-- e-mail: epc8 at juno dot com
-- e

Steven G. Kargl

2008-01-30, 7:24 pm

In article <c706bb0b-6fc4-409f-b487-8519cf2326ac@k39g2000hsf.googlegroups.com>,
Mirko.Vukovic@gmail.com writes:
> Hi,
>
> This is a follow-up on my previous post, as it relates to generating
> valid TecPlot files.
>
> Given a vector of strings, I need to print out a string of the
> following form (with the quote characters in it).
> "string1" "string2" "string3"
>
> I was trying along the lines of
> "4('magic'A5'magic')"
> but I could not quite figure out what the magic would be.
>
> My other alternative is to modify the string's by prepending and
> appending the quotes.
>
> Any other opinions?
>

character(len=5) :: s = 'abcde'
write(*,'(A)') '"' // trim(s) // '"'
write(*,1) trim(s)
1 format('"',A,'"')
end


--
Steve
http://troutmask.apl.washington.edu/~kargl/
Mirko.Vukovic@gmail.com

2008-01-31, 7:27 pm

On Jan 30, 6:10 pm, ka...@troutmask.apl.washington.edu (Steven G.
Kargl) wrote:
> In article <c706bb0b-6fc4-409f-b487-8519cf232...@k39g2000hsf.googlegroups.com>,
> Mirko.Vuko...@gmail.com writes:
>
>
>
>
>
>
>
> character(len=5) :: s = 'abcde'
> write(*,'(A)') '"' // trim(s) // '"'
> write(*,1) trim(s)
> 1 format('"',A,'"')
> end
>
> --
> Stevehttp://troutmask.apl.washington.edu/~kargl/


Thank you to both.

Since the number of repeats is not determined at compile time, I ended
up building up the format string in a loop:

character(len=500)::sFormatVar
....
sFormatVar="('Variables= "
add_var_names: do iProf=1,cProfs
sFormatVar=trim(sFormatVar)//' "'//trim(vsProfs(iProf))//'"'
end do add_var_names
sFormatVar=trim(sFormatVar)//"')"
write (self%lu,sFormatVar)

I am sure this can be compacted, but my limited fortran knowledge,
small comfort zone, and time constraints limit further optimization at
this point.

Thanks again,

Mirko
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com