Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
Re: Help with data gaps and interpolation
There is a lot going wrong in this example. index = where(Bx_array eq 9999.99, count) if (count gt 9999.99) then Bx_array[index] = !values.f_nan "count" is an integer telling you how man fill values you have. It should not be compared to your fill value. if Bx_array lt 9999.99 then begin temp=(Bx_array, count) result=interpol(Bx_array[temp],temp, time[temp]) endif Bx_array is an array and comparing it to a scalar (9999.99) will cause an error. The line temp = (Bx_array, count) will append the scalar integer "count" to the end of the Bx_array. Bx_array[temp] indexes an array with another array. This would be ok if "temp" were an array of indices, but it is not. Thus, your call to "interpol" does not give you what you expect. Something like this should work: ;Create data with fill values Bx = randomu(3, 50) Bx[[3, 4, 5, 12, 30, 33, 39, 45]] = 9999.99 ;Find the good index values iGood = where(Bx ne 9999.99, nGood) ;Create a time array indicating where you want points nPts = n_elements(Bx) time_out = findgen(nPts) ;Times where you have good data time_in = time_out[iGood] Bx_in = Bx[iGood] ;Interpolate over fill values Bx_out = Interpol(Bx_in, time_in, time_out)
On Friday, March 20, 2015 at 4:18:50 PM UTC+2, zolile...@gmail.com wrote: > Dear All, > I would to get help, sugestions on the ff program. i have tried many ways but I did not succed, any help will be highly appreciated. > > 1. I want to plot with data gaps which are represented by values such as 9999.99. > > 2. I would like to interpolate the data again to fill the data gaps. > > the data look like this > > > 06-10-2006 19:01:00.000 1.45000 -2.15000 0.120000 > 06-10-2006 19:02:00.000 1.36000 -2.31000 0.120000 > 06-10-2006 19:03:00.000 1.39000 -1.76000 0.140000 > 06-10-2006 19:04:00.000 9999.99 9999.99 9999.99 > 06-10-2006 19:05:00.000 9999.99 9999.99 9999.99 > 06-10-2006 19:06:00.000 1.20000 -1.91000 0.220000 > 06-10-2006 19:07:00.000 1.23000 -1.87000 0.230000 > 06-10-2006 19:08:00.000 1.22000 -1.84000 0.230000 > 06-10-2006 19:09:00.000 1.14000 -1.86000 0.310000 > 06-10-2006 19:10:00.000 1.05000 -1.86000 0.440000 > 06-10-2006 19:11:00.000 0.920000 -1.87000 0.660000 > 06-10-2006 19:12:00.000 0.790000 -1.60000 0.420000 > 06-10-2006 19:13:00.000 0.180000 -1.38000 0.810000 > 06-10-2006 19:14:00.000 0.900000 -0.970000 0.310000 > 06-10-2006 19:15:00.000 1.64000 -0.680000 -0.270000 > 06-10-2006 19:16:00.000 1.73000 -0.680000 -0.210000 > 06-10-2006 19:17:00.000 1.83000 -0.710000 0.0500000 > > The program looks like this > > File = Dialog_PickFile(Filter='*.txt') > > Date_array = 0 > time_array = 0 > Bx_array = 0 > By_array = 0 > Bz_array = 0 > > str = '' > > openR, Lun, File,/Get_Lun > readf, Lun, str > while~eof(lun) do begin > > readf,lun,date,time,Bx,By,Bz > ;print,date,time,Bx,By,Bz > > Bx_array = [Bx_array, Bx] > By_array = [By_array, By] > Bz_array = [Bz_array, Bz] > endwhile > free_lun,lun > Bx_array=Bx_array[1:*] > By_array=By_array[1:*] > Bz_array=Bz_array[1:*] > > index = where(Bx_array eq 9999.99, count) > if (count gt 9999.99) then Bx_array[index] = !values.f_nan > > ; interpolate > if Bx_array lt 9999.99 then begin > temp=(Bx_array, count) > result=interpol(Bx_array[temp],temp, time[temp]) > endif > > Nx = n_elements(Bx_array) > time = findgen(Nx) > time = time/60 > > ; plot with data gaps > plot, time, Bx_array[index]; > > plot,time, Result > > end > > Thank in advance for your time. > Zolile Thank you so much Matthew for ur help. Thanks