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

Home » Public Forums » archive » Re: printing floats/integer (ACK, new function deined here GetFormatString.pro)
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: printing floats/integer (ACK, new function deined here GetFormatString.pro) [message #24107] Thu, 08 March 2001 09:35
R.G.S. is currently offline  R.G.S.
Messages: 46
Registered: September 2000
Member
ACK, I sent off the first version of this code before finishing
a small piece (i.e. how I returned out of error situations).
Here is the "final code".

Cheers,
bob stockwell
stockwell@co-ra.com




function getformatstring,number

; this should be big enough to show everything
showallformatcommmand = '(f50.25)'

nsize = size(number,/st)
case nsize.type of
;0: Undefined
;1: Byte
;2: Integer
;3: Longword integer
4: begin; Floating point
s = STRING(FORMAT=showallformatcommmand, number)
s = strtrim(s,1) ; remove leading blanks
slen = strlen(s)
dpos=strpos(s,'.') ; find decimal posiiton
if dpos eq -1 then begin
; this shouldn't happen
print,'Error: no decimal place found'
return,'' ; null string
endif else begin
; chop off lagging 0s
zpos=0
doflag=1
while doflag do begin ; find how many lagging zeros there are
char = strmid(s,zpos,1,/reverse)
if char eq '0' then begin
zpos=zpos+1
endif else begin
doflag=0
endelse
endwhile
endelse
end
5: begin; Double-precision floating
s = STRING(FORMAT=showallformatcommmand, number)
s = strtrim(s,1) ; remove leading blanks
slen = strlen(s)
dpos=strpos(s,'.') ; find decimal posiiton
if dpos eq -1 then begin
; this shouldn't happen
print,'Error: no decimal place found'
return,'' ; null string
endif else begin
; chop off lagging 0s
zpos=0
doflag=1
while doflag do begin ; find how many lagging zeros there are
char = strmid(s,zpos,1,/reverse)
if char eq '0' then begin
zpos=zpos+1
endif else begin
doflag=0
endelse
endwhile
endelse
end
;6:; Complex floating
;7: String
;8: Structure
;9:; Double-precision complex
;10: Pointer
;11: Object reference
;12:; Unsigned Integer
;13:; Unsigned Longword Integer
;14:; 64-bit Integer
;15:; Unsigned 64-bit Integer
else: begin
print,'Error: Number not a supported type.'
return,'' ; null string
endelse
endcase

d =slen-dpos-zpos-1
w = dpos+d+1 ; 1 for the decimal place
formatstring = strcompress("(f"+string(w)+'.'+string(d)+")",/rem)
return,formatstring

end ; end of function





; __________________________________________
; ****** main level code here ***********
a = 123121.22222200000d
;must become 1.22222 without leading or trailing spaces.
print,'Normal print command:'
print,a
print,'Print command with GetFormat:'
print,a,format=getformatstring(a)

end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: astronomical coordinate conversion
Next Topic: Re: astronomical coordinate conversion

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

Current Time: Wed Oct 08 08:58:52 PDT 2025

Total time taken to generate the page: 0.00460 seconds