Re: syntax for creating array for data fordata from ascii file

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Mon, 08 Dec 2008 11:28:17 -0700

Hi Erik,
I think you're getting the coordinate variable assignments and the data
array entry confused. First, set up coordinate arrays for time and
longitude:

(These are just guesses on my part..)
time = ispan(0,10,1)
lon = fspan(-20,294.5,630) ; go from 20W->294.5E by 0.5

arr = new((/dimsizes(time),dimsizes(lon)/),"float",-999.)
arr!0 = "time"
arr&time = time
arr!1 = "lon"
arr&lon = lon

Next, you need to read in the ascii data into the array correctly. Note
that the syntax of your time (2006:09:01) will be read in to asciiread
as three different entries. Thus, your data should be read in as 5
columns and 630 rows.

data = asciiread("data.asc",(/630,5/),"float")
file_year = data(:,0)
file_month = data(:,1)
file_day = data(:,2)
file_lon = data(:,3)
file_data = data(:,4)
delete(data)

Here is were it can get tricky. If each ascii file contains one
timestep, then it's easy:

do gg = 0,dimsizes(file_data)-1
    arr(0,{file_lon(gg)})=(/file_data(gg)/) ; data entry for 0th timestep
end do

Notice that I am using coordinate subscripting to enter the data into
the correct longitude slot.

If each ascii file has multiple timesteps, you will have to design the
do loop to recognize that when the time index has changed and put the
data into the correct time slot of the arr data array.

This should at least get you started..
Adam

Erik Noble wrote:
> Hi. Could I have some help here with a simple question? I just want to
> make sure that I am getting the syntax right for using data from an
> ascii file to create and array. I keep running into problems.
> I have an ascii file that is three columns -" time", "longitude", and
> "rainfall amount (mm)", and 630 rows.
> 2006:09:01 -20.000 11.3280
> 2006:09:01 -19.500 12.2291
> . . .
> . . .
> . . .
>
> I am trying to create a time vs. longitude plot (hovmoller) which
> requires that data be 2 dimensional with longitude as the the right-most
> dimension.
> To correctly read in this data into an array "rain" would be the following?
> rain = new((/2/630/),float)
> rain(0,:)=data(:,0) ; to read in time
> rain(1,:)=data(:,1) ; to read in lon
>
> The next step would be to just plot the data
>
> plot = gsn_csm_hov(wks, rain, res )
>
>
> Where do the actual "rainfall amount" rainfall amount values go if I
> have already "filled" in the dimensions for time and longitude? Just
> trying to understand the concept and what else I need to do.
> Thank you for your time.
> -Erik
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
--------------------------------------------------------------
Adam Phillips			             asphilli_at_ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD/CAS                               fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000	  http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Dec 08 2008 - 11:28:17 MST

This archive was generated by hypermail 2.2.0 : Thu Dec 11 2008 - 03:51:46 MST