Re: How to Read .csv file?

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Tue, 14 Mar 2006 15:01:46 -0700

Hi Debasish,

You can use asciiread
(http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiread.shtml)

to read in the .csv file, as the function ignores commas.

So:

arr = asciiread("file.csv",(/3355,15/),"float")
print(arr(0,:)) ; to check that file is read in correctly
print(arr(15,:))

mo = (/"jan","feb","mar","apr","may","jun","jul","aug","sep", \
        "oct","nov","dec","ann1","ann2"/)

arr!0 = "Gridbox_number"
arr&Gridbox_number = arr(:,0)

do gg = 0,dimsizes(mo)-1
    b = addfile(mo(gg)+".nc","c")
    b->VAR = arr(:,gg+1)
end do

This is a very simple example, and will basically write out 1 timeseries
(with 3355 values) for each month, with the grid box number attached as
a coordinate variable to the timeseries.

Good luck,
Adam

Debasish PaiMazumder wrote:
> Hi all,
>
> I am now working on comma separated values i.e. .csv files. The file
> format is given below,
>
>
>
> 1, 15.6, 12.7, 6.8, 11.6, 4.2, 6, 33.1, 31.5, 6.3, 13.8, 28.2, 20.5,
> 14.8, 15.7
>
> 2, 19.4, 25.3, 12.3, 10.9, 5.4, 6, 71.7, 52.6, 9.6, 18.5, 62.3, 74.6,
> 33.3, 30.7
>
> 3, 21.7, 36.2, 18.2, 14.1, 10.4, 11.1, 105.3, 64.7, 13.1, 20.2, 66.5,
> 52.9, 38.7, 36.1
>
> 4, 103.2, 78.8, 88.8, 112.4, 46.7, 42.8, 73.1, 110.1, 84.1, 161.5,
> 131.7, 172.3, 99.7, 100.5
>
> 5, 120.6, 211.7, 354.3, 212.4, 152.9, 221.6, 36.6, 31.5, 71.2, 229,
> 201.8, 263, 175.6, 175.4
>
> .
> .
>
> .
> .
>
> .
> .
>
> .
> .
>
> 3355,
> .
>
>
>
> The files contain the data within 15 columns. The first column is the
> grid-box number, followed by the
>
> 12 monthly values of variables (January to December) as well as 2
> further columns. The latter contain
>
> 2 different approximations of the annual average of the variables.
>
>
>
> I have to read this .cvs file in NCL and write each column in different
> netcdf files (like January.nc,
>
> February.nc, etc). Kindly help me to do this.
>
>
>
> Thanks
>
> Debasish
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> 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
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Mar 14 2006 - 15:01:46 MST

This archive was generated by hypermail 2.2.0 : Wed Mar 29 2006 - 11:52:48 MST