comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: Code cluttered with 'STRTRIM(variable,2)' ?

Re: Code cluttered with 'STRTRIM(variable,2)' ?
type: item
description: 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 One way to do it would be to use the STRCOMPRESS function, which converts multiple spaces in a string to a single space. However, this doesn't really help in your example because you'd still have to convert the integers to string. Thus, msg=strcompress($ 'Warning: '+string(n_sizes)+' size combinations fitted against '+$ string(n_peaks)+' peak combinations means '+ $ string(n_sizes*n_peaks)+' individual curve fits will be done.') print,msg isn't much better. > I guess possible solutions include defining a 'wrapper' for > strtrim, like: > FUNCTION str,s > return,strtrim(s,2) > END That's basically what I do. Bill Thompson
creator: thompson
date: 1995-09-14T07:00:00-00:00

Re: Code cluttered with 'STRTRIM(variable,2)' ?
type: item
description: 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
creator: zawodny
date: 1995-09-14T07:00:00-00:00

Re: Code cluttered with 'STRTRIM(variable,2)' ?
type: item
description: In article <43a0h0$fq5@post.gsfc.nasa.gov>, thompson@orpheus.nascom.nasa.gov (William Thompson) writes: |>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 |> |>One way to do it would be to use the STRCOMPRESS function, which converts |>multiple spaces in a string to a single space. However, this doesn't really |>help in your example because you'd still have to convert the integers to |>string. Thus, |> |> msg=strcompress($ |> 'Warning: '+string(n_sizes)+' size combinations fitted against '+$ |> string(n_peaks)+' peak combinations means '+ $ |> string(n_sizes*n_peaks)+' individual curve fits will be done.') |> print,msg |> |>isn't much better. |> Following up on Bill's strcompress suggestion, how about: msg=strcompress(string($ 'Warning: ',n_sizes,' size combinations fitted against ',$ n_peaks,' peak combinations means ', $ n_sizes*n_peaks,' individual curve fits will be done.')) print,msg -tom fredian twf@pfc.mit.edu
creator: twf
date: 1995-09-15T07:00:00-00:00

Re: Code cluttered with 'STRTRIM(variable,2)' ?
type: item
description: William Thompson (thompson@orpheus.nascom.nasa.gov) wrote: : 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 Perhaps you try: IDL> print, 'test',1 test 1 But as you see, there are lots of spaces. Another way is: IDL> test = strtrim([n_sizes, n_peaks, n_sizes*n_peaks],2) ; All Variables must be of the same type IDL> msg=$ IDL> 'Warning: '+test(0)+' size combinations fitted against '+$ IDL> test(1)+' peak combinations means '+ $ IDL> test(2)+' individual curve fits will be done.' IDL> print, msg ciao volker -- Volker Groll uni: Ludwig Maximilians Universit"at, Institut f"ur Medizinische Optik, Abteilung Theoretische Biophysik, Theresienstr. 37, 80333 M"unchen Raum 204, Tel.: 089/2394-4107 e-mail: Volker.Groll@imo.physik.uni-muenchen.de privat: Fritz-Berne-Str. 54, 81241 M"unchen Tel.: 089 / 8340723
creator: volker
date: 1995-09-15T07:00:00-00:00