[ncl-talk] Reading and writing data

Appo derbetini appopson4 at gmail.com
Wed Feb 20 04:44:19 MST 2019


Dear Adam,
Thank you for your kind help
The script proposed by you is very clear and optimized.
But there is an error appearing at this line
mod_data({data(0)*100+1:data(0)*100+12},{lat_coord},{lon_coord}) = (/
data(1:) /)

Telling

fatal:NclOneDValGetClosestIndex: finish coordinate index out of range,
can't continue
fatal:Could not obtain coordinate indexes, unable to perform subscript
fatal:["Execute.c":8637]:Execute: Error occurred at or near line 48 in file
read_NCwrite_NC131_Adam.ncl

Since a hour I am looking how to correct it without success

Thanks again

Appo

Le mar. 19 févr. 2019 à 21:54, Adam Phillips <asphilli at ucar.edu> a écrit :

> Hi Appo,
> The nice aspect of your ascii file is that it is regular: Each grid
> point's data is given over 100 rows, and each is monthly running from
> 1920-2014. I would strongly recommend developing a new script that operates
> on each 100 row chunk of data, and that uses coordinate subscripting to put
> the data in the proper place in your final data array. One negative to this
> method is the possibility exists that multiple nearby data points get
> assigned to the same grid point, but this can be countered by setting your
> master array grid appropriately. An example:
>
> ; Untested! Review the code below.
>  yrStrt = 1920
>  yrLast = 2014
>  file_name   = "Rain_estimate_2.5DegGrid.txt"
>  rain    = asciiread(file_name, -1, "string")
>
> lat = fspan(6.25,43.75,16)
> lat at units = "degrees_north"
> lat!0 = "lat"
> lat&lat = lat
> lon = fspan(-23.75, 11.25,15)
> lon at units = "degrees_east"
> lon!0 = "lon"
> lon&lon = lon
> time = yyyymm_time(yrStrt,yrLast,"integer")
> mod_data =
> new((/(yrLast-yrStrt+1)*12,dimsizes(lat),dimsizes(lon)/),float,-999.)
> ;Set up master array that will be filled in.
> mod_data!0  = "time"
> mod_data&time = time
> mod_data!1 = "lat"
> mod_data&lat = lat
> mod_data!2 = "lon"
> mod_data&lon = lon
>
> nrow = numAsciiRow("file_name")
>
> do gg = 0,nrow-1,100   ; Run a do loop over each 100 row segment
>      temp = rain(gg:gg+99)
>      coords = str_split(temp(1)," ")
>      print(coords)     ; examine results of text split
>      lat_coord = tofloat(coords(2))
>      lon_coord = tofloat(coords(5))
>      do hh = 5,99   ; operate on rows 5-99 of temp
>           data = tofloat(str_split(temp(hh)," "))
>           mod_data({data(0)*100+1:data(0)*100+12},{lat_coord},{lon_coord})
> = (/ data(1:) /)
>           delete(data)
>     end do
>      delete(temp)
>     print("Now done with lat="+lat_coord+", lon="+lon_coord)
> end do
>
> The above should at least get you going. If further changes need to be
> made to the above you will need to make them. If you have any further
> questions let ncl-talk know.
> Adam
>
>
> On Tue, Feb 19, 2019 at 8:27 AM Appo derbetini <appopson4 at gmail.com>
> wrote:
>
>>
>> Dear NCL users,
>>
>> Here a script that i am using to read rainfall data.
>> Data are given for each grid point.
>> But points are not regularly distributed.
>> for some grid point there is no data
>>
>> I want to construct  regular matrix (lat, lon) where point without data
>> will be created and filled by missing value (-999.0 in the script).
>>
>> My script is giving wrong result !!!
>>
>> Any help will be appreciated
>>
>>
>> Regards
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
> --
> Adam Phillips
> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
> www.cgd.ucar.edu/staff/asphilli/   303-497-1726
>
> <http://www.cgd.ucar.edu/staff/asphilli>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190220/b6fd087b/attachment.html>


More information about the ncl-talk mailing list