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

Home » Public Forums » archive » Output file with string blanks and float
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
Output file with string blanks and float [message #90874] Sun, 03 May 2015 01:26 Go to next message
Miguel is currently offline  Miguel
Messages: 18
Registered: April 2015
Junior Member
Hi,

I'm trying to create an output file with these specific conditions :

1) If the result is negative, the corresponding output is a blank
2) If the result is ok, the output is a number with a specific number of decimal

For example, I have this initial output

-1 2.312 54.124
547.5460 -1.0 65.321

And I want

2.31 54.12
547.55 65.32

For the blank, I convert each line into a string array and I put "String(Replicate(32B, 8))" to create a blank with specific width.
However, if I convert into a string array, I cannot use the format F[w].[d] to specify the number of decimal.

I thought I could use STRNSIGNIF but the number of decimal won't be the same for each numbers.

Do you have an idea to have the output file with these two conditions ?
Is this possible to create a blank in float and not in string format ?

Thanks

Miguel
Re: Output file with string blanks and float [message #90875 is a reply to message #90874] Sun, 03 May 2015 02:07 Go to previous messageGo to next message
Miguel is currently offline  Miguel
Messages: 18
Registered: April 2015
Junior Member
Ok, I just found a way :

x=21.4567
print,strnsignif( x,strlen(strcompress(fix(x)))-1+2 )

gives : x=21.46

If you have a better way, please tell me.
Moreover, I still want to know if a blank arrray is possible in float format

Thanks
Miguel
Re: Output file with string blanks and float [message #90876 is a reply to message #90874] Sun, 03 May 2015 05:35 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
miguelfigueirasebastiao@gmail.com writes:

> I'm trying to create an output file with these specific conditions :
>
> 1) If the result is negative, the corresponding output is a blank
> 2) If the result is ok, the output is a number with a specific number of decimal

Humm. Good way to make yourself the most hated person on the planet when
someone else has to read this data file. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Output file with string blanks and float [message #90877 is a reply to message #90876] Sun, 03 May 2015 08:14 Go to previous messageGo to next message
Miguel is currently offline  Miguel
Messages: 18
Registered: April 2015
Junior Member
> Humm. Good way to make yourself the most hated person on the planet when
> someone else has to read this data file. :-)
>

Well, if I put a blamk, it is because the result just doesn't exist.

Finally, I'm still with my problem because "strnsignif(x,strlen(strcompress(fix(x)))-1+2 )" does not work when the integer part of the number is 0

Miguel
Re: Output file with string blanks and float [message #90878 is a reply to message #90877] Sun, 03 May 2015 13:44 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
>> Humm. Good way to make yourself the most hated person on the planet when
>> someone else has to read this data file. :-)
>>
>
> Well, if I put a blamk, it is because the result just doesn't exist.

It is much much better to define a fill value (e.g. -999.99) for your data, and specify what that value is in the header of the file.
Re: Output file with string blanks and float [message #90880 is a reply to message #90878] Mon, 04 May 2015 02:51 Go to previous messageGo to next message
Miguel is currently offline  Miguel
Messages: 18
Registered: April 2015
Junior Member
> It is much much better to define a fill value (e.g. -999.99) for your data, and specify what that value is in the header of the file.

If I had to use my output file as a input file, I completely agree with you (and the output with fill value of -1 is already made).

Miguel
Re: Output file with string blanks and float [message #90881 is a reply to message #90880] Mon, 04 May 2015 06:47 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
Instead of writing a space, simply advance the file pointer to the right.

Take this example

;A line of data
data = [1.0, -1.0, 6.0]

;Search for and remove negative numbers
ipos = where(data ge 0, npos, COMPLEMENT=ineg, NCOMPLEMENT=nneg)
data = data[ipos]

;Create a format code with floats for positive numbers and spaces for negative numbers
fmt = strarr(npos + nneg)
if npos gt 0 then fmt[ipos] = 'f8.2'
if nneg gt 0 then fmt[ineg] = '8x'
fmt = '(' + strjoin(fmt, ',') + ')'

;Results
help, string(data, FORMAT=fmt)
<Expression> STRING = ' 1.00 6.00'
Re: Output file with string blanks and float [message #90884 is a reply to message #90881] Mon, 04 May 2015 09:01 Go to previous message
Miguel is currently offline  Miguel
Messages: 18
Registered: April 2015
Junior Member
> Instead of writing a space, simply advance the file pointer to the right.

Thanks, I will try that ;)

Miguel
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Mapping southern in Northern map
Next Topic: counting points falling inside a Voronoi cell

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

Current Time: Wed Oct 08 11:39:59 PDT 2025

Total time taken to generate the page: 0.00598 seconds