naming PS plots: variable+ string? [message #47543] |
Thu, 16 February 2006 23:48  |
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 #47641 is a reply to message #47543] |
Fri, 17 February 2006 00:44  |
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
|
|
|