[Thread Prev][Thread Next][Index]

Re: how to add lat/lon/depth to an existing netcdf file



Hi Prasad,
            If you want to solve your problem using ferret then
the solution is regridding as suggested by Edward. Since you have
a big file with many grid points, regridding in ferret will be time 
consuming. Again the regridding will depend on how your lat. lon & 
depth axes are....wether they are uniformly spaced or not. Ofcourse 
you can modify much easily if you are familiar with editing netcdf  
using fortran or c. 

	Here is an example for adding lat lon and depth dimension to 
a netcdf file through regridding in ferret. I took a case with
10 lat, 10 lon &  5 depth  points.  


Hope this helps


With Regards 

Jaison

 if your x, y & z axes are uniformly spaced like ......
                           ----------------
 lon : 42,44,46,48,50....60    ! 10 points
 lat : 11,12,13.....20         ! 10 points
 dep : 0,10,..40               !  5 points 
         
        use data.nc ! in your case tavg.icecpl.199001.nc  

	define axis/x=42:60:2/units=longitudes xax  
	define axis/y=11:20:1/units=latitudes  yax
	define axis/z=0:40:10/units=meters/DEPTH  zax  ! /DEPTH
				  ! for "positive=down" z-axis
        define grid/x=xax/y=yax/z=zax gr_xyz
        define grid/x=xax/y=yax gr_xy
       
        let/title="something"/unit="something" HDIFT_new = HDIFT[g=gr_xy@asn] 
        let/title="something"/unit="something" UET_new   = UET[g=gr_xyz@asn]
        let/title="something"/unit="something" VNT_new   = VNT[g=gr_xyz@asn]

        fill/k=1 UET_new

! saving to a file

        save/file="./regridded_data.nc"/append HDIFT_new, UET_new, VNT_new
------------------------------------------------------------------

 suppose you have non-uniform spacing for axes..then
                  -------------------
 it will be easier to read the values of lat, lon and dep from
    an ascci file since you have many grid points. 
  suppose  lon   is in 1st column
           lat   is in 2nd   "
           depth is in 3rd   "    like

40 0  0 
42 2  2
46 3  5
50 5  10 
55 8  25
60 10 
63 14 
65 15 
67 17 
74 20

  in a file...say "axis_values.dat"

! since these three columns have different lengths (in your
! case 900,601,40) little care should be taken to read them

        define axis/x=1:10:1 dummyx  ! in your case 1:900:1
        define axis/y=1:10:1 dummyy  ! in your case 1:601:1
        define axis/z=1:5:1 dummyz   ! in your case 1:40:1
        define grid/x=dummyx grx
        define grid/y=dummyy gry
        define grid/z=dummyz grz

!   /skip is to skip "rows" and "-" is to skip "columns"

!   read lon/x values and define x-axis from those values   

	file/skip=0/var="xdat,-,-"/grid=grx axis_values.dat
	define axis/from_data/x/units=longitudes/name=xaxis xdat

!   read lat/y values and define y-axis from those values

	file/skip=0/var="-,ydat,-"/grid=gry axis_values.dat
        define axis/from_data/y/units=latitudes/name=yaxis ydat

!   read dep/z values and define z-axis from those values

	file/skip=0/var="-,-,zdat"/grid=grz axis_values.dat
        define axis/from_data/z/units=meters/DEPTH/name=zaxis zdat

        define grid/x=xaxis/y=yaxis gr_xy         ! for 2-D variable
        define grid/x=xaxis/y=yaxis/z=zaxis gr_xyz ! for 3-D variables

        use data.nc  ! in your case tavg.icecpl.199001.nc

! regridding via @asn will directly associate the axis vales (from
!      defined grid ) to the newly defined variable

        let HDIFT_2 = HDIFT[g=gr_xy2@asn]
        let UET_2   = UET[g=gr_xyz@asn]
        let VNT_2   = VNT[g=gr_xyz@asn]

        plot/i=1/j=1 VNT_2

! for saving to file/putting title and units see first section above
------------------------------------------------------------------------


On Thu, 22 Apr 2004, Thoppil, Prasad IND wrote:

> Hi ferret users:
> 
> I have model outputs written in netcdf format. There is no lat/lon/depth
> information in these files and I would like to add them into an existing
> netcdf file. It is impossible to dump this file using ncdump and add
> lat/lon because it is a huge file (800 MB). I hope someone out there can
> help me with this. 
> 
> Thanks, 
> 
> Prasad.
> 
> Following is the ncdump output
> 
> netcdf tavg.icecpl.199001 {
> dimensions:
>         i = 900 ;
>         j = 601 ;
>         k = 40 ;
> variables:
>         float HDIFT(j, i) ;
>                 HDIFT:long_name = "Vertically integrated horz mix T
> tend" ;
>                 HDIFT:units = "degC/cm^2" ;
>                 HDIFT:grid_loc = "2110" ;
>                 HDIFT:missing_value = -12345.f ;
>         float UET(k, j, i) ;
>                 UET:long_name = "East Flux of Heat" ;
>                 UET:units = "degC/s" ;
>                 UET:grid_loc = "3211" ;
>                 UET:missing_value = -12345.f ;
>         float VNT(k, j, i) ;
>                 VNT:long_name = "North Flux of Heat" ;
>                 VNT:units = "degC/s" ;
>                 VNT:grid_loc = "3121" ;
>                 VNT:missing_value = -12345.f ;
> 

-- 
___________________________________________________

    Jaison Kurian                           
    Centre for Atmospheric and Oceanic Sciences
    Indian Institute of Science
    B A N G A L O R E   560 012
    Ph: +91-80-3942505
        +91-80-3600450
    Fax:+91-80-3600865
___________________________________________________



[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement