Re: String to Floating conversion [message #80323] |
Mon, 28 May 2012 06:02 |
Vincent Sarago
Messages: 34 Registered: September 2011
|
Member |
|
|
Hello,
The problem come from the way you are reading the data.
The error comes from the fact that the first element is a string and it can't be transformed to a float
It might be useful if you show us the code you're using
----
;Example of what I do normally in this case !!!
nb_line_of_you_file = file_lines('path_to_your_file')
arr = strarr(nb_line_of_you_file)
openr, f, 'path_to_your_file', /get_lun
read, f, arr
free_lun, f
; If you are using IDL 8.* you can use the hash variable
; if not you can construct a structure containing the different elements of your data
str = replicate({name:'', val1:0d, val2:0d, .... nb_elements }, nb_line_of_you_file)
for ii = 0, n_elements(arr) - 1 do begin
st = strsplit(arr[ii], /Extract)
str[ii].name = string(st[0])
str[ii].val1 = double(st[1])
...
endFor
end
On Monday, May 28, 2012 2:01:12 PM UTC+2, Baro wrote:
> Dear Friends
>
> I am a new user of IDL. this time I am trying to read the data of this
> type.
>
> GRCOF2 0 0 0.100000000000E+01 0.000000000000E+00 0.0000E+00
> 0.0000E+00 20030301.0000 20030401.0000 nnnn
> GRCOF2 1 0 0.000000000000E+00 0.000000000000E+00 0.0000E+00
> 0.0000E+00 20030301.0000 20030401.0000 nnnn
> GRCOF2 2 0 -.484169137464E-03 0.000000000000E+00 0.1256E-10
> 0.0000E+00 20030301.0000 20030401.0000 ynnn
>
> It is a GRACE satellite data
>
> But I am getting error which says "Unable to convert String to
> Floating"
>
> Can any one help me in reading it, cause i have 122 files with 1895
> lines for each, using IDL will simplify it a lot for me. I will wait
> for your golden responses
|
|
|