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

Home » Public Forums » archive » assigning integer and string value to same variable one by one
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
assigning integer and string value to same variable one by one [message #93013] Sat, 09 April 2016 04:34 Go to next message
Sapna Mishra is currently offline  Sapna Mishra
Messages: 66
Registered: December 2015
Member
Pro tt

for i=0,25 do begin
Print,'By seeing mplot give obj_col:'
Read,obj_col
wait,1

if (STRMATCH(datatype(obj_col), 'STR', /FOLD_CASE) EQ 1) then i=i+1

print,i
endfor
return
end


IDL> .compile tt.pro
% Compiled module: TT.
IDL> tt
By seeing mplot give obj_col:
: 1
% Compiled module: DATATYPE.
0
By seeing mplot give obj_col:
: 'q'
% READ: Input conversion error. Unit: 0, File: <stdin>
% Execution halted at: TT 5 /home/cs/dN_dz/Ana/tt.pro
% $MAIN$
IDL>


Can't I give integer and string value to same variable if I want to jump on loop if the value of that input variable is a string??
Any way out?
Re: assigning integer and string value to same variable one by one [message #93014 is a reply to message #93013] Sat, 09 April 2016 12:00 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
I would always read the user input as a string and use a function like

http://idlastro.gsfc.nasa.gov/ftp/pro/misc/strnumber.pro

to determine if the string can be converted to a numeric value.

ans = ''
for i=0,25 do begin
Read,'By seeing mplot give obj_col:' ans
if ~strnumber(ans,obj_col) then break
print,i
endfor

On Saturday, April 9, 2016 at 7:34:17 AM UTC-4, Sapna Mishra wrote:
> Pro tt
>
> for i=0,25 do begin
> Print,'By seeing mplot give obj_col:'
> Read,obj_col
> wait,1
>
> if (STRMATCH(datatype(obj_col), 'STR', /FOLD_CASE) EQ 1) then i=i+1
>
> print,i
> endfor
> return
> end
>
>
> IDL> .compile tt.pro
> % Compiled module: TT.
> IDL> tt
> By seeing mplot give obj_col:
> : 1
> % Compiled module: DATATYPE.
> 0
> By seeing mplot give obj_col:
> : 'q'
> % READ: Input conversion error. Unit: 0, File: <stdin>
> % Execution halted at: TT 5 /home/cs/dN_dz/Ana/tt.pro
> % $MAIN$
> IDL>
>
>
> Can't I give integer and string value to same variable if I want to jump on loop if the value of that input variable is a string??
> Any way out?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: assigning integer and string value to same variable one by one
Next Topic: Plot with X-Axis ticks as string

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

Current Time: Wed Oct 08 07:17:00 PDT 2025

Total time taken to generate the page: 0.00452 seconds