Re: Reading special sentence in txt file in IDL [message #80890] |
Wed, 18 July 2012 06:25 |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, July 18, 2012 2:48:23 PM UTC+2, Ursa Kanjir wrote:
> Hey all,
>
> I'm a new user and I would like to create a program that would read exact sentence in txt file (exactly: "acquisition time/date") and later that would read value that is written after ":" that exist in txt file.
>
> I have written the program up to the phase where it opens and reads my txt file, but I just don't know exactly what should I tell so that IDl would read me this numers.
>
> Anyone can help?
> Thanks hundred times in advance!
> u.
Hi,
I suppose that if you were able to read you data, then you must have some variable (scalar or array) from where you can extract the (numerical) value after the colon.
You might try the following
MyString = 'Some text here : 1536'
StartPos = STRPOS(MyString,':')
IF StartPos[0] GE 0 THEN ResultNumber = FIX(STRMID(MyString,StartPos+1))
There are a few things to be careful about. Look in the help for the optional parameters in STRPOS. For instance, to avoid errors cause by strings like 'Some:test:here: 1536', you might use the /REVERSE_SEARCH keyword.
Notice that I used FIX to convert the string to an integer. There are other functions you should use for floating point data or different types (FLOAT(), DOUBLE(),...).
Also the NASA IDL repository you will find a quite useful test function to check if the string is actually a number or not (http://idlastro.gsfc.nasa.gov/ftp/pro/misc/valid_num.pro).
Hope it helps,
Helder
|
|
|