Re: netcdf to ascii conversion

From: Arindam Chakraborty <arindam_at_nyahnyahspammersnyahnyah>
Date: Sun, 03 Jun 2007 18:45:28 -0400

hi Debasish,
there may be an easy way out for this in NCL, but the following should
also work:

...
...

; var is the variable name,
; lon is the longitude dimension name,
; lat is the latitude dimension name.

lon = var&lon
lat = var&lat

; the following assumes the order of dimensions in the variables as
(time,lat,lon)
dimsz = dimsizes(var)
nt = dimsz(0)
ny = dimsz(1)
nx = dimsz(2)

fout = "ascfile.dat" ; output ascii file name
system("echo > "+fout) ; create an empty file. Existing file will be
overwritten.

do j = 0, ny-1
do i = 0, nx-1
ascval = ""
ascval = ascval+sprintf("%8.2f %8.2f ",lat(j),lon(i))
do k = 0, nt-1
ascval = ascval+sprintf("%6.1f ",var(k,j,i))
end do
system("echo "+ascval+" >> "+fout)
end do
end do

...
...

Hope this helps,

arindam

Debasish Pai Mazumder wrote:
>
> Hi all,
>
> I have a netcdf file for air temperature. The dimension of air
> temperature is given below,
>
> Air_temp(time,lat,lon) where time=124, lat=16, lon=59
>
> I am trying to convert this fie in to ascii file. I used the code
> provided by Dennis Shea in website
> http://www.ncl.ucar.edu/Support/talk_archives/2006/0113.html and the
> program gave me different ascii files for lat, lon and temperature but
> all those values in ascii file are written in a one column. I also
> used write_matrix option but I guess it only works for two dimensional
> data.
>
> I am trying to make a ascii file with different rows and columns like
>
> lat lon time=0 time=1……… time=123
>
> 41.5 25 260 262.6 267.8
>
> 41.5 27.5 261.2 262.3 264.5
>
> .
>
> .
>
> .
>
> 41.5 160 254.6 262.9 270.5
>
> 43 25 260.2 264.4 267.8
>
> 43 27.5 …………………………………………..
>
> ………………………………………………………………..
>
> ……………………………………………………………….
>
> Is there any way to get ascii file with the given format from netcdf
> file in NCL
>
> Thanks
>
> Debasish
>
> ---------------------------------------------------------------------------------
>
> Debasish Pai Mazumder
>
> Graduate Research Assistant
> Geophysical Institute,University of Alaska Fairbanks,
>
> 903 Koyukuk Drive
>
> Fairbanks, AK 99775
>
> USA
>
> Phone : +1 907 474 7618
>
> Email : debasish_at_gi.alaska.edu <mailto:debasish_at_gi.alaska.edu>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Jun 03 2007 - 16:45:28 MDT

This archive was generated by hypermail 2.2.0 : Tue Jun 05 2007 - 16:18:21 MDT