comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » naming PS plots: variable+ string?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
naming PS plots: variable+ string? [message #47543] Thu, 16 February 2006 23:48 Go to next message
maldayeh is currently offline  maldayeh
Messages: 13
Registered: January 2006
Junior Member
Hello,
I am trying to name a PS file as a variable, for instance, if I am
using 2004 data, I'd like the output plot to be named "2004.PS"
I used:
psfilename =string(figname+'.ps')
and
psfilename =figname+'.ps'

where figname could be any number.
I always get this error message:
% Type conversion error: Unable to
convert given STRING to Integer.

Any idea!
Thanks a lot.
Re: naming PS plots: variable+ string? [message #47630 is a reply to message #47543] Fri, 17 February 2006 12:09 Go to previous message
maldayeh is currently offline  maldayeh
Messages: 13
Registered: January 2006
Junior Member
Peter,
Perfect! Thanks again for your help.

Maher
Re: naming PS plots: variable+ string? [message #47641 is a reply to message #47543] Fri, 17 February 2006 00:44 Go to previous message
peter.albert@gmx.de is currently offline  peter.albert@gmx.de
Messages: 108
Registered: July 2005
Senior Member
Hi again,

the reason for the error message is than in both examples you are
trying to add an integer variable (figname) to a string variable
('.ps'). IDL starts with interpreting

"figname + ..." so it expects that the variable after the "+" sign is
any kind of number, too. It is difficult to guess which number is
represented by the string ".ps", therefore IDL is giving up ...

You want to use the "+" sign for concatenating strings, so you must
ensure that "figname" is a string _before_ "adding" it to ".ps".

You would start with

psfilename = string(figname) + ".ps"

and be surprised about the many blanks in the filename. Hence,
something like

psfilename = string(figname, format = '(i4.4)') + ".ps"

already looks much better. Or, alternatively

psfilename = strcompress(string(figname), /remove_all) + ".ps"

The first example leaves you with 4 characters before the ".ps", no
matter which value figname has:

0001.ps
0002.ps
...
2004.ps
...

but fails when figname exceeds 9999. The second example works with all
integer values but creates filenames like

1.ps
2.ps
10.ps
...

Cheers,

Peter
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Image proccesing programs
Next Topic: Re: Fractional Pixels Origin?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 10:58:43 PDT 2025

Total time taken to generate the page: 0.00396 seconds