[ncl-talk] How to read ascii data and subscript a three dimension arry

Dennis Shea shea at ucar.edu
Fri Oct 21 08:19:19 MDT 2016


The text file looks like it contains grid points from 'some' pre-existing
(time,lat,lon) array.

ntim = ??   ; number of unique time steps
nlat  = ??
mlon = ??

RAIN = new( (/ntim,nlat,mlon/), "float", -999.9)
lat = ....    ; lat(lat)     ; coordinate variables for the grid
lon = ...    ; lon(lon)

=== As suggested by Forrest ...

  diri = "./"              ; input diectory
  fili = "RAIN.txt"    ; whatever the text file name is
  pthi = diri+fili
  data = asciiread(pthi, -1, "string")

  delim= " ,-_:"

  rain = tofloat( str_get_field(data(1:), 1, delim) )
  yyyy = toint( str_get_field(data(1:), 2, delim) )
  mm   = toint( str_get_field(data(1:), 3, delim) )
  dd   = toint( str_get_field(data(1:), 4, delim) )
  hh   = toint( str_get_field(data(1:), 5, delim) )
  mn   = toint( str_get_field(data(1:), 6, delim) )
  sc   = todouble( str_get_field(data(1:),7, delim) )

  LAT  = todouble( str_get_field(data(1:),8, delim) )
  LON = todouble( str_get_field(data(1:),9, delim) )

  npts = dimsizes(lat)

; Fill array

  eps = 0.001      ; arbitrary 'distance'
  do np=0,npts-1
        nt = ???
       nl = ind(LAT(np).gt.(lat-eps) .and. LAT(np).lt.(lat+eps))       ;
lat index
       ml = ind(LON(np).gt.(lon-eps) .and. LON(np).lt.(lon+eps))  ; lon
index
       RAIN(nt,nl,ml) = RAIN(np)
  end do

  RAIN!0 = "time"
  RAIN!1 = "lat"
  RAIN!2 = "lon"
  RAIN&lat = lat
  RAIN&lon = lon
  RAIN at long_name = "Rain Density"
  RAIN at units = "..."
  printVarSummary(RAIN)
  printMinMax(RAIN,0)



plot RAIN variable

Good luck



On Thu, Oct 20, 2016 at 7:29 AM, Black, Forrest (LARC-D318)[UNIVERSITIES
SPACE RESEARCH ASSOCIATION] <forrest.black at nasa.gov> wrote:

> Hi Tao,
>
>
>
> The attached script reads in asci data and creates a new table by column,
> but gives you an idea how the NCL asciiread function works.
>
> Once the date column is read you can use the str_split function to split
> up your date in NCL (https://www.ncl.ucar.edu/Document/Functions/Built-in/
> str_split.shtml).
>
>
>
> I hope this helps,
>
>
>
> -        Forrest
>
>
>
> *From:* ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] *On
> Behalf Of *Tao Lu
> *Sent:* Thursday, October 20, 2016 3:35 AM
> *To:* ncl-talk at ucar.edu
> *Subject:* [ncl-talk] How to read ascii data and subscript a three
> dimension arry
>
>
>
> Hello ncl-talk
>
>
>
> I am Tao.
>
>
>
> I have a time series data. I want to use this data to plot a contour graph.
>
> [image: Inline image 1]
>
> As you see, I get the data in this format. This data is rain data of
> 100x100 grid with different time.
>
> How can I make an array rain(ntime, nlat, nlon) from this data?
>
>
>
> Please help me, thanks in advance.
>
>
>
>
>
> --
>
>
>
> ******************************************************
>
> Tao Lu    (M. Eng)
>
> Laboratory of River Engineering and Hydrology,
> Dept. of Civil and Environmental Engineering,
> Graduate School of Science and Engineering,
> Chuo University
>
> 1-13-27,Kasuga,Bunkyo-ku,Tokyo
> 112-8551, Japan
> TEL: 03-3817-1805;   Phone: 070-2188-7509
> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
> *****************************************************
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161021/74f1e366/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 202361 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161021/74f1e366/attachment.png 


More information about the ncl-talk mailing list