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

Home » Public Forums » archive » Format codes in IDL
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
Format codes in IDL [message #31077] Tue, 18 June 2002 09:34 Go to next message
astib is currently offline  astib
Messages: 15
Registered: June 2002
Junior Member
Hi everybody,

I am having a problem applying format codes to 'NaN', i.e.
!VALUES.F_NAN. When I try to assign this value to some variable and
read it from the command line in Macintosh and Linux, it gives me
error that 'Format code ... cannot be applied to 'variable'. It gives
it for all format codes. The interesting thing is, I have one such
statement in my code, it runs okay under Linux machine, but crashes
under Macintosh. I do not understand this. If anybody has got any
experience regarding the same and would help me, I would appreciate
that.

Thanks,
Asti
Re: Format codes in IDL [message #31185 is a reply to message #31077] Thu, 20 June 2002 09:19 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Asti Bhatt wrote:
>
> Hi-
>
> If you try to assign any other value to x, it will give the same
> error. e.g.
> IDL>x = 2.2
> IDL> read,format='(f10.3)',b
> : x
> % Unable to apply format code F to input: "x".
> % Execution halted at: $MAIN$
>
> The thing is, it doesn't accept any "variable" as input to READ or
> READF. Why that ?
>
> On my Linux, it runs fine. Also, I am generating NaN's in my code and
> NaN is Not a Number, but indeed a value. It is not character or string
> surely. I have whole data set as float and NaN is generated when there
> is no data. So it is right alligned only, since it is treated as a
> value. Now what ??
>
> Asti
>
> Nigel Wade <nmw@ion.le.ac.uk> wrote in message news:<aes7s4$b6h8$1@rook.le.ac.uk>...
>> Asti Bhatt wrote:
>>
>>> Yes, exactly. I get the same message and that is specific to Mac. This
>>> works under Linux alright.
>>>
>>> Thanks Reiumar for the code, but there is so much data and I have
>>> applied different format codes to different fields. This way I will
>>> have to convert all the data in required form again and then apply the
>>> format codes. Than again NaN problem will be there. The thing is, my
>>> code with formats applied works perfectly under Linux but not under
>>> Mac. Why is that ??
>>>
>>> Asti
>>>
>>
>>
>> It doesn't on my Linux:
>>
>>
>> IDL Version 5.5a (linux x86). (c) 2001, Research Systems, Inc.
>> Installation number: 3437-9.
>> Licensed for use by: Radio and Space Plasma Physics Group
>>
>> IDL> x=!values.f_nan
>> IDL> read,format='(f10.3)',b
>> : x
>> % Unable to apply format code F to input: "x".
>> % Execution halted at: $MAIN$
>>
>>
>> Which is what I would expect to happen. x is not valid input for a floating
>> point conversion - it's a character not a number.


Dear Asti,

I got an error on my linux if I try what you have
described.

read,format = '(3f10.3)', b
: x
% Unable to apply format code F to input: "x".

If I like to have a NaN code I have to type:

IDL> read,format='(f10.3)',b
: NaN

help,b
B FLOAT = NaN

I believe this goes the normal way.

With a small piece of code definig an
error handler by a catch this could be solved.

Please can you check if something like this
is defined may be in a startup which is not
the same on all tested machines.


PRO test
errvar =0
CATCH,errvar
IF errvar NE 0 THEN BEGIN
catch,/CANCEL
b=!values.f_nan
HELP,b
RETURN
ENDIF
READ,format = '(3f10.3)', b

END


IDL> test
: x
B FLOAT = NaN


hope this helps a bit
regards

Reimar

--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
============================================================ =======
Re: Format codes in IDL [message #31186 is a reply to message #31077] Thu, 20 June 2002 08:57 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Asti Bhatt wrote:
>
> Yes, exactly. I get the same message and that is specific to Mac. This
> works under Linux alright.
>
> Thanks Reiumar for the code, but there is so much data and I have
> applied different format codes to different fields. This way I will
> have to convert all the data in required form again and then apply the
> format codes.

Dear Asti,

the routine read_data_file does not require format codes.
It requires only a separator between data which could be
a comma (,) a tab (string(9b)) ,a blank (string(32b))
or different blanks.

And I have to add I was not knowing this before it reads
NaN too.

e.g. a file

1 2 3 NaN
10 29 40 60

x=read_data_file('test.dat')

help,x,/str
** Structure <824ccbc>, 3 tags, length=88, data length=88, refs=1:
FILE STRING 'test.dat'
SEPARATOR STRING ' '
DATA DOUBLE Array[4, 2]


print,x.data
1.0000000 2.0000000 3.0000000 NaN
10.000000 29.000000 40.000000 60.000000


I have tested on windows and linux with the same result.


At this version of the routine a NaN in first line and column will
be inerpreted as header information. I will improve the routine
for this case.
The reading of data is very very fast because it reads array orientated.
This is the fastest way to read data.



regards

Reimar


> Than again NaN problem will be there. The thing is, my
> code with formats applied works perfectly under Linux but not under
> Mac. Why is that ??
>
> Asti
>
> thompson@orpheus.nascom.nasa.gov (William Thompson) wrote in message news:<aeq601$s69$1@skates.gsfc.nasa.gov>...
>> astib@cc.usu.edu (Asti Bhatt) writes:
>>
>>> No, if I do like -
>>> IDL>x = !values.f_nan
>>> IDL> read,format = '(3f10.3)', b
>>> and if in the input i give x, it will give me an error. Not only NaN,
>>> but if I say x=2 and try to give it as input to read with format
>>> specified, it will give me error. And this is typical to Macintosh. I
>>> tried same thing under Linux and it works fine. Actually I have a .dat
>>> file from which I need to read data, there are some NaN's also, and on
>>> macintosh, it refuses to read it by giving this error - %Unable to
>>> apply format code blah blah to 'variable'(whatever it is).
>>
>> You mean that you're reading in from the keyboard, and instead of typing in a
>> number, you type in the character name of an IDL variable? That certainly
>> doesn't work on my machine under 5.4. Was this something added to 5.5? I get
>>
>> IDL> x=3
>> IDL> read,format='(3f10.3)',b
>> : x
>> % Unable to apply format code F to input: "x".
>> % Execution halted at: $MAIN$
>>
>> I'm very confused,
>>
>> Bill Thompson
>>
>>
>>> Do you know if rsi has any patch for this ? I searched the website for
>>> this, but couldn't get anything.
>>
>>> Thanks,
>>> Asti
>>
>>

--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
============================================================ =======
Re: Format codes in IDL [message #31188 is a reply to message #31077] Thu, 20 June 2002 08:30 Go to previous message
astib is currently offline  astib
Messages: 15
Registered: June 2002
Junior Member
Hi-

If you try to assign any other value to x, it will give the same
error. e.g.
IDL>x = 2.2
IDL> read,format='(f10.3)',b
: x
% Unable to apply format code F to input: "x".
% Execution halted at: $MAIN$

The thing is, it doesn't accept any "variable" as input to READ or
READF. Why that ?

On my Linux, it runs fine. Also, I am generating NaN's in my code and
NaN is Not a Number, but indeed a value. It is not character or string
surely. I have whole data set as float and NaN is generated when there
is no data. So it is right alligned only, since it is treated as a
value. Now what ??

Asti


Nigel Wade <nmw@ion.le.ac.uk> wrote in message news:<aes7s4$b6h8$1@rook.le.ac.uk>...
> Asti Bhatt wrote:
>
>> Yes, exactly. I get the same message and that is specific to Mac. This
>> works under Linux alright.
>>
>> Thanks Reiumar for the code, but there is so much data and I have
>> applied different format codes to different fields. This way I will
>> have to convert all the data in required form again and then apply the
>> format codes. Than again NaN problem will be there. The thing is, my
>> code with formats applied works perfectly under Linux but not under
>> Mac. Why is that ??
>>
>> Asti
>>
>
>
> It doesn't on my Linux:
>
>
> IDL Version 5.5a (linux x86). (c) 2001, Research Systems, Inc.
> Installation number: 3437-9.
> Licensed for use by: Radio and Space Plasma Physics Group
>
> IDL> x=!values.f_nan
> IDL> read,format='(f10.3)',b
> : x
> % Unable to apply format code F to input: "x".
> % Execution halted at: $MAIN$
>
>
> Which is what I would expect to happen. x is not valid input for a floating
> point conversion - it's a character not a number.
Re: Format codes in IDL [message #31189 is a reply to message #31077] Thu, 20 June 2002 02:39 Go to previous message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
Asti Bhatt wrote:

> Yes, exactly. I get the same message and that is specific to Mac. This
> works under Linux alright.
>
> Thanks Reiumar for the code, but there is so much data and I have
> applied different format codes to different fields. This way I will
> have to convert all the data in required form again and then apply the
> format codes. Than again NaN problem will be there. The thing is, my
> code with formats applied works perfectly under Linux but not under
> Mac. Why is that ??
>
> Asti
>


It doesn't on my Linux:


IDL Version 5.5a (linux x86). (c) 2001, Research Systems, Inc.
Installation number: 3437-9.
Licensed for use by: Radio and Space Plasma Physics Group

IDL> x=!values.f_nan
IDL> read,format='(f10.3)',b
: x
% Unable to apply format code F to input: "x".
% Execution halted at: $MAIN$


Which is what I would expect to happen. x is not valid input for a floating
point conversion - it's a character not a number.

--
-----------------------------------------------------------
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555
Re: Format codes in IDL [message #31195 is a reply to message #31077] Wed, 19 June 2002 12:58 Go to previous message
astib is currently offline  astib
Messages: 15
Registered: June 2002
Junior Member
Yes, exactly. I get the same message and that is specific to Mac. This
works under Linux alright.

Thanks Reiumar for the code, but there is so much data and I have
applied different format codes to different fields. This way I will
have to convert all the data in required form again and then apply the
format codes. Than again NaN problem will be there. The thing is, my
code with formats applied works perfectly under Linux but not under
Mac. Why is that ??

Asti


thompson@orpheus.nascom.nasa.gov (William Thompson) wrote in message news:<aeq601$s69$1@skates.gsfc.nasa.gov>...
> astib@cc.usu.edu (Asti Bhatt) writes:
>
>> No, if I do like -
>> IDL>x = !values.f_nan
>> IDL> read,format = '(3f10.3)', b
>> and if in the input i give x, it will give me an error. Not only NaN,
>> but if I say x=2 and try to give it as input to read with format
>> specified, it will give me error. And this is typical to Macintosh. I
>> tried same thing under Linux and it works fine. Actually I have a .dat
>> file from which I need to read data, there are some NaN's also, and on
>> macintosh, it refuses to read it by giving this error - %Unable to
>> apply format code blah blah to 'variable'(whatever it is).
>
> You mean that you're reading in from the keyboard, and instead of typing in a
> number, you type in the character name of an IDL variable? That certainly
> doesn't work on my machine under 5.4. Was this something added to 5.5? I get
>
> IDL> x=3
> IDL> read,format='(3f10.3)',b
> : x
> % Unable to apply format code F to input: "x".
> % Execution halted at: $MAIN$
>
> I'm very confused,
>
> Bill Thompson
>
>
>> Do you know if rsi has any patch for this ? I searched the website for
>> this, but couldn't get anything.
>
>> Thanks,
>> Asti
>
>
Re: Format codes in IDL [message #31208 is a reply to message #31077] Wed, 19 June 2002 08:23 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
thompson@orpheus.nascom.nasa.gov (William Thompson) writes:

> astib@cc.usu.edu (Asti Bhatt) writes:

>> No, if I do like -
>> IDL>x = !values.f_nan
>> IDL> read,format = '(3f10.3)', b
>> and if in the input i give x, it will give me an error. Not only NaN,
>> but if I say x=2 and try to give it as input to read with format
>> specified, it will give me error. And this is typical to Macintosh. I
>> tried same thing under Linux and it works fine. Actually I have a .dat
>> file from which I need to read data, there are some NaN's also, and on
>> macintosh, it refuses to read it by giving this error - %Unable to
>> apply format code blah blah to 'variable'(whatever it is).

> You mean that you're reading in from the keyboard, and instead of typing in a
> number, you type in the character name of an IDL variable? That certainly
> doesn't work on my machine under 5.4. Was this something added to 5.5? I get

> IDL> x=3
> IDL> read,format='(3f10.3)',b
> : x
> % Unable to apply format code F to input: "x".
> % Execution halted at: $MAIN$

Actually, I think I've figured out what it is your trying to say. You're
trying to read the actual characters "NaN" into a variable.

Maybe it's an IDL version issue. On my Alpha workstation running Tru64 Unix
with IDL/v5.4 I can read in NaN with format statements, but only if the
characters "NaN" are aligned with the left side of the field. Preceeding blank
characters cause the error message

% Unable to apply format code F to input: " NaN ".

Maybe this is fixed in later versions of IDL?

Bill Thompson
Re: Format codes in IDL [message #31211 is a reply to message #31077] Wed, 19 June 2002 07:54 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
astib@cc.usu.edu (Asti Bhatt) writes:

> No, if I do like -
> IDL>x = !values.f_nan
> IDL> read,format = '(3f10.3)', b
> and if in the input i give x, it will give me an error. Not only NaN,
> but if I say x=2 and try to give it as input to read with format
> specified, it will give me error. And this is typical to Macintosh. I
> tried same thing under Linux and it works fine. Actually I have a .dat
> file from which I need to read data, there are some NaN's also, and on
> macintosh, it refuses to read it by giving this error - %Unable to
> apply format code blah blah to 'variable'(whatever it is).

You mean that you're reading in from the keyboard, and instead of typing in a
number, you type in the character name of an IDL variable? That certainly
doesn't work on my machine under 5.4. Was this something added to 5.5? I get

IDL> x=3
IDL> read,format='(3f10.3)',b
: x
% Unable to apply format code F to input: "x".
% Execution halted at: $MAIN$

I'm very confused,

Bill Thompson


> Do you know if rsi has any patch for this ? I searched the website for
> this, but couldn't get anything.

> Thanks,
> Asti


> thompson@orpheus.nascom.nasa.gov (William Thompson) wrote in message news:<aeo3f4$3g1$1@skates.gsfc.nasa.gov>...
>> astib@cc.usu.edu (Asti Bhatt) writes:
>>
>>> Hi everybody,
>>
>>> I am having a problem applying format codes to 'NaN', i.e.
>>> !VALUES.F_NAN. When I try to assign this value to some variable and
>>> read it from the command line in Macintosh and Linux, it gives me
>>> error that 'Format code ... cannot be applied to 'variable'. It gives
>>> it for all format codes. The interesting thing is, I have one such
>>> statement in my code, it runs okay under Linux machine, but crashes
>>> under Macintosh. I do not understand this. If anybody has got any
>>> experience regarding the same and would help me, I would appreciate
>>> that.
>>
>> I'm not sure what you mean. Do you mean that if you do something like
>>
>> IDL> a = !values.f_nan
>> idl> READ, prompt='Input A: ', a, format='(F10.7)'
>>
>> that it will cause an error?
>>
>> Bill Thompson
Re: Format codes in IDL [message #31218 is a reply to message #31077] Tue, 18 June 2002 23:55 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Asti Bhatt wrote:
>
> Hi,
>
> No, if I do like -
> IDL>x = !values.f_nan
> IDL> read,format = '(3f10.3)', b
> and if in the input i give x, it will give me an error. Not only NaN,
> but if I say x=2 and try to give it as input to read with format
> specified, it will give me error. And this is typical to Macintosh. I
> tried same thing under Linux and it works fine. Actually I have a .dat
> file from which I need to read data, there are some NaN's also, and on
> macintosh, it refuses to read it by giving this error - %Unable to
> apply format code blah blah to 'variable'(whatever it is).
>
> Do you know if rsi has any patch for this ? I searched the website for
> this, but couldn't get anything.
>
> Thanks,
> Asti

What's with this workaround.


Read in the data as string array.
Then do a replace of NaN by a fill_falue

e.g. data.txt

something like this:

1 NaN 100 200 NaN
1 10 1.2331 200 NaN
1 NaN NaN 200 NaN
1 NaN 100 200 NaN


pro conv
n=fileline('data.txt')
txt=make_array(n,/string)
openr,lun,'data.txt',/get_lun
readf,lun,txt
free_lun,lun

ix=where(strpos(txt,'NaN') gt -1,count)
if count gt 0 then txt[ix]=replace_string(txt[ix],'NaN','9999')

openw,lun,'new_data.txt',/get_lun
printf,lun,transpose(txt)
free_lun,lun

d=read_data_file('new_data.txt')
; could examine header and trailer too
end
IDL> conv

help,d,/str
** Structure <81bd584>, 3 tags, length=184, data length=184, refs=1:
FILE STRING 'new_data.txt'
SEPARATOR STRING ' '
DATA DOUBLE Array[5, 4]



used routines are:

http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/fileline.tar.gz
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/replace_string.tar.gz
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/read_data_file.tar.gz




For further routines and licensing please have a look at

http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml


regards
Reimar


>
> thompson@orpheus.nascom.nasa.gov (William Thompson) wrote in message news:<aeo3f4$3g1$1@skates.gsfc.nasa.gov>...
>> astib@cc.usu.edu (Asti Bhatt) writes:
>>
>>> Hi everybody,
>>
>>> I am having a problem applying format codes to 'NaN', i.e.
>>> !VALUES.F_NAN. When I try to assign this value to some variable and
>>> read it from the command line in Macintosh and Linux, it gives me
>>> error that 'Format code ... cannot be applied to 'variable'. It gives
>>> it for all format codes. The interesting thing is, I have one such
>>> statement in my code, it runs okay under Linux machine, but crashes
>>> under Macintosh. I do not understand this. If anybody has got any
>>> experience regarding the same and would help me, I would appreciate
>>> that.
>>
>> I'm not sure what you mean. Do you mean that if you do something like
>>
>> IDL> a = !values.f_nan
>> idl> READ, prompt='Input A: ', a, format='(F10.7)'
>>
>> that it will cause an error?
>>
>> Bill Thompson

--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
============================================================ =======
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Lost my 'info' structure
Next Topic: Using COM objects in IDL (Win32 only)

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

Current Time: Mon Oct 13 00:12:37 PDT 2025

Total time taken to generate the page: 1.67872 seconds