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

Home » Public Forums » archive » Re: fsc_Inputfield feature request
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
Re: fsc_Inputfield feature request [message #82219] Fri, 30 November 2012 05:20
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
markbates writes:

> OK, I looked into the code and it seems like a pretty simple fix. The
> routine adding the 'd' is the DBLTOSTR.pro from the Coyote library,
> and the d is there for the general case when scientific notation is
> used. I think I've fixed the problem with the unusual output when
> there is no exponent by adding one line of code just before the final
> output string is generated. I added the line:
>
> if indx eq '' then typeExt = ''
>
> which removes the type extension (d) when there is no exponent text.
> The modified DBLTOSTR routine is below. David, what do you think?

Works for me. Thanks for doing the leg work. :-)

Generally, when I have to open these old programs up for
some reason, I retire them, convert the documentation to
IDL-Doc style, and reincarnate them with a "cg" prefix
to mark them as a Coyote Library routine. I'll do that
with this one as well, so it might take a day or so
to get back into the Library.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: fsc_Inputfield feature request [message #82220 is a reply to message #82219] Fri, 30 November 2012 02:40 Go to previous message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
OK, I looked into the code and it seems like a pretty simple fix. The
routine adding the 'd' is the DBLTOSTR.pro from the Coyote library,
and the d is there for the general case when scientific notation is
used. I think I've fixed the problem with the unusual output when
there is no exponent by adding one line of code just before the final
output string is generated. I added the line:

if indx eq '' then typeExt = ''

which removes the type extension (d) when there is no exponent text.
The modified DBLTOSTR routine is below. David, what do you think?


FUNCTION DBLTOSTR, value

; Error handling.
On_Error, 2
IF N_Elements(value) EQ 0 THEN Message, $
'Double precision or floaing value must be passed to the
function.'

; Get the data type.
theType = Size(value, /Type)
IF theType NE 4 AND theType NE 5 THEN BEGIN
value = Double(value)
theType = 5
ENDIF

; Data extension.
typeExt = theType EQ 4 ? 'e' : 'd'

; Create a string, using the full-widtet G format.
rawstr = StrTrim(String(value, Format = '(g)'), 2)

; Extract the sign from the string and remove it for the moment.
sign = StrMid(rawstr, 0, 1) EQ '-' ? '-' : ''
rawstr = sign EQ '' ? rawstr:StrMid(rawstr, 1)

; Is there an exponent in the string?
; If so, remove that for the moment.
epos = StrPos(rawstr, 'e')
indx = epos gt -1 ? StrMid(rawstr, epos+1) : ''
rawstr = indx EQ '' ? rawstr:StrMid(rawstr, 0, epos)

; Find the position of the decimal point.
dpos = StrPos(rawstr, '.')

; Rounding process (assumes 14 significant digits).
outstr = StrArr(15)
FOR i = 0, 14 DO outstr[i] = StrMid(rawstr, i, 1)
aux = Fix(StrMid(rawstr, 16, 1)) GE 5?1:0
FOR i = 14, 0, -1 DO BEGIN
IF i NE dpos then BEGIN
sumstr = StrTrim(String(aux+fix(outstr[i])), 2)
sumlen = StrLen(sumstr)
outstr[i] = StrMid(sumstr, sumlen-1, 1)
aux = sumlen EQ 1 ? 0 : 1
ENDIF
ENDFOR

; Throw away '0's at the end.
ii = 14
WHILE outstr[ii] EQ '0' DO BEGIN
ii = ii-1
ENDWHILE

; Reconstruct the string.
saux = aux NE 0 ? '1' : ''

if indx eq '' then typeExt = ''

outstr = sign + saux + StrJoin(outstr[0:ii]) + typeExt + indx

; Return it.
RETURN, outstr

END
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: fsc_Inputfield feature request
Next Topic: Re: x-axis label in plot procedure

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

Current Time: Wed Oct 08 13:54:38 PDT 2025

Total time taken to generate the page: 0.00387 seconds