RE: [ncl-talk] netcdf to ascii conversion

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon, 4 Jun 2007 13:36:30 -0600 (MDT)

On Mon, 4 Jun 2007, Debasish Pai Mazumder wrote:

> Hi,
>
> Thanks Dennis and Arindam for helping me.
>
> I use the script mentioned in example3 in website
> http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiwrite.shtml
> but I got a error massage
>
> fatal:new: data type must either be a keyword or string
>
> in the line where new variable data is declared i.e.
> data = new(fName, npts, "string")
>
> Thanks
> Debasish

Hi Debasish,

In example 3, the "new" statement is used as follows:

  data = new(npts, "string")

In your script, it appears that you have added an extra argument:

    data = new(fName, npts, "string")

The "fName" should not be in the "new" statement. The first argument
should be the dimension sizes that you want for the new variable (npts
in this case), and the second argument the type ("string").

--Mary

>
>
> -----Original Message-----
> From: Dennis Shea [mailto:shea_at_ucar.edu]
> Sent: Monday, June 04, 2007 7:51 AM
> To: Arindam Chakraborty
> Cc: Debasish Pai Mazumder; ncl-talk_at_ucar.edu
> Subject: Re: netcdf to ascii conversion
>
> Based on Debasish's question and Arindam's responses, I created
> a new Example 3 at:
>
> http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiwrite.shtml
>
> =======================
> Arindam Chakraborty wrote:
>> Oh, sorry Debasish, I did a last minute editing on that line before
>> sending. sprintf takes two arguments and while testing I used lat and
>> lon separately. But at the time of sending I though of combining them
>> together keeping c in mind, but I was wrong. You can replace that line
>> with the followings lines:
>> ascval = ascval+sprintf("%8.2f ",lat(j))
>> ascval = ascval+sprintf("%8.2f ",lon(i))
>>
>>
>> It should work after this. Thanks for pointing this out.
>>
>> arindam
>>
>> Debasish Pai Mazumder wrote:
>>> Hi Arindam,
>>>
>>> Thanks for your reply
>>>
>>> I used your code but it give some error massage in line
>>>
>>> ascval = ascval+sprintf("%8.2f %8.2f ",lat(j),lon(i))
>>>
>>> Error massage: fatal:syntax error: function sprintf expects 2 arguments,
> got
>>> 3
>>> fatal:Syntax Error in block, block not executed
>>>
>>> Thanks
>>>
>>> Debasish
>>>
>>>
>>> -----Original Message-----
>>> From: Arindam Chakraborty [mailto:arindam_at_met.fsu.edu]
>>> Sent: Sunday, June 03, 2007 2:45 PM
>>> To: Debasish Pai Mazumder
>>> Cc: ncl-talk_at_ucar.edu
>>> Subject: Re: netcdf to ascii conversion
>>>
>>> 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
>>>>
>>>>
>>>>
>
>
> _______________________________________________
> 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 Mon Jun 04 2007 - 13:36:30 MDT

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