From: Mirko.Vukovic on
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
From: e p chandler on
On Jan 30, 5:38 pm, Mirko.Vuko...(a)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=achar(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

From: Steven G. Kargl on
In article <c706bb0b-6fc4-409f-b487-8519cf2326ac(a)k39g2000hsf.googlegroups.com>,
Mirko.Vukovic(a)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/
From: Mirko.Vukovic on
On Jan 30, 6:10 pm, ka...(a)troutmask.apl.washington.edu (Steven G.
Kargl) wrote:
> In article <c706bb0b-6fc4-409f-b487-8519cf232...(a)k39g2000hsf.googlegroups.com>,
> Mirko.Vuko...(a)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
>
> --
> 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