Re: Code cluttered with 'STRTRIM(variable,2)' ? [message #5008 is a reply to message #5007] |
Thu, 14 September 1995 00:00  |
zawodny
Messages: 121 Registered: August 1992
|
Senior Member |
|
|
Russ Welti <rwelti@chroma.mbt.washington.edu> writes:
>
> A nit that has plagued me since day 1 in IDL is:
>
> What is the best way to formulate strings which contain
> variables' values without getting all cluttered up with
> strtrim(variable,2) ?? This really uglifies my code.
>
> Example:
>
>> msg=$
>> 'Warning: '+strtrim(n_sizes,2)+' size combinations fitted against '+$
> strtrim(n_peaks,2)+' peak combinations means '+ $
> strtrim(n_sizes*n_peaks,2)+' individual curve fits will be done.'
>> print,msg
I agree with your concept. IDL should be able to autoconvert
variables to the appropriate type. In fact it does this all the time
in mathematical and logical expressions such as a = 1.+2, a will be
real. IDL convert variables of different types to the same type
(according to certain rules used to establish priority) before doing
the math.
To see what is going on in the example above, I did a brief test.
IDL> print,'test '+1
% Type conversion error: Unable to convert given STRING to Integer.
% Detected at: $MAIN$
1
This tells me that IDL was trying to convert the string to an integer
rather than the integer to the string. The logic for the test of a
type mismatch is already in IDL, it just tried to do the "wrong"
conversion. I would think that in the case of a variable type
mismatch involving strings that IDL should default to converting
everything to string type and that it should be done in the same manner
as a STRTRIM(var,2) call would do. Perhaps there are others out there
who would prefer the other type of behavior. Is the default of
converting strings to numbers an artifact of the need to do such a
thing during the reading of an ASCII file? If so, could we (you - RSI)
separate the two processes and thereby make STRTRIM nearly obsolete?
Thoughts, comments, or corrections?
--
Dr. Joseph M. Zawodny KO4LW NASA Langley Research Center
E-mail: J.M.Zawodny@LaRC.NASA.gov MS-475, Hampton VA, 23681-0001
|
|
|