comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Output file with string blanks and float
items: Re: Output file with string blanks and float

Output file with string blanks and float
type: item
description: 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
creator: Miguel
date: 2015-05-03T08:26:37-00:00

Re: Output file with string blanks and float
type: item
description: 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
creator: Miguel
date: 2015-05-03T09:07:07-00:00

Re: Output file with string blanks and float
type: item
description: 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.")
creator: David Fanning
date: 2015-05-03T12:35:44-00:00

Re: Output file with string blanks and float
type: item
description: > 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
creator: Miguel
date: 2015-05-03T15:14:11-00:00

Re: Output file with string blanks and float
type: item
description: >> 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.
creator: Matthew Argall
date: 2015-05-03T20:44:09-00:00

Re: Output file with string blanks and float
type: item
description: > 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
creator: Miguel
date: 2015-05-04T09:51:01-00:00

Re: Output file with string blanks and float
type: item
description: 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'
creator: Matthew Argall
date: 2015-05-04T13:47:50-00:00

Re: Output file with string blanks and float
type: item
description: > Instead of writing a space, simply advance the file pointer to the right. Thanks, I will try that ;) Miguel
creator: Miguel
date: 2015-05-04T16:01:38-00:00