More than one variable in NETCDF!!!

Lee Byerle labyerle at MET.UTAH.EDU
Thu Jul 20 23:44:25 EDT 2006


Shilpy,

If you want to use ncdump to get ascii, another option is w/some unix
commands to get rid of the extra information (;, }'s, header info).  I
have been doing it with ncdump for multiple variables.  It is sometimes
slow depending upon your grid, but it works.

As a crude example, consider two variables, uwind and vwind, in an
(unpacked) netCDF file and you want to dump them both to ascii (to
separate asciiI files in this case):

ncdump -v uwind your.nc > uwind_dump

#remove extraneous characters
sed 's/,/ /g' uwind_dump > temp1.out
sed 's/;/ /g' temp1.out > temp2.out
sed 's/}/ /g' temp2.out > temp3.out

#Strip top lines of header
tail +94 temp3.out > uwind_ascii.out

echo OKAY uwind is in new file uwind_ascii.out
#

#Repeat for v-wind

ncdump -v vwind your.nc > vwind_dump

#remove extraneous characters
sed 's/,/ /g' vwind_dump > temp1.out
sed 's/;/ /g' temp1.out > temp2.out
sed 's/}/ /g' temp2.out > temp3.out

#Strip top lines of header
tail +94 temp3.out > vwind_ascii.out

echo OKAY vwind is in new file vwind_ascii.out
#

etc...for other variables.

You must play with the 'tail' command (e.g., tail +94..) because it will
vary based upon how much header information you have.

Lee


> I don't know why you think that about ncdump.  If you use "ncdump"
> with only the path to the file as all of the arguments, *EVERYTHING*
> will get dumped.  This could get quite large.  Also, if the data is
> packed, the ncdump command does NOT unpack the data.
>
> I would think it would be easier to write a program (NetCDF has APIs
> for several popular languages) and, in the program, choose what you
> want and how you want it to appear in the output file.  My two cents....
>
> -Hoop
>> From owner-gradsusr at LIST.CINECA.IT  Thu Jul 20 11:36:49 2006
>> From: Shilpy <shilpy at PRL.RES.IN>
>>
>> Grads Gurus!!
>>
>> I am facing problem to convert NETCDF file to ASCII  file. I tried with
>> ncdump but i think it works only if you hav one variable in your NETCDF
>> file, if you have more than one variable in your NETCDF
>> file what we should do to read the data?
>>
>>
>> Please let me know how to read NETCDF file if you have more than one
>> variable in your datafile.
>>
>>
>> Thanks in advance.
>>
>> Best regards
>> Shilpy
>



More information about the gradsusr mailing list