Re: add variables to existed ncf

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Tue Sep 10 2013 - 16:36:58 MDT

Chao,

Try this:

   diri = "/data11/cluo/wrf/"
   nam1 = "wrfout_d01_2012-03-12_00:00:00"
   f_in = addfile(diri+nam1,"r")
   RAINC2 = f_in->RAINC(:,:,:)

   do it = 0, 47
   RAINC2(it,:,:) = RAINC2(it+1,:,:) - RAINC2(it,:,:)
   enddo

   names = getfilevarnames(ff); extract all variable names
   system("cp " + diri+nam1 + " out.nc")
   ncdf_out = addfile("out.nc", "w")
   ncdf_out->RAINC2 = RAINC2

Wei

huangwei@ucar.edu
VETS/CISL
National Center for Atmospheric Research
P.O. Box 3000 (1850 Table Mesa Dr.)
Boulder, CO 80307-3000 USA
(303) 497-8924

On Sep 10, 2013, at 3:20 PM, "Luo, Chao" <chao.luo@eas.gatech.edu> wrote:

> Hi,
>
> I want to add one variable to a existed WRF output netcdf file without writing each variable definition. The script I tried as below, but it doesn't work. Any suggestions or help are very appreciated!
>
> cl
>
> ----------------------------------------
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> begin
>
> diri = "/data11/cluo/wrf/"
> nam1 = "wrfout_d01_2012-03-12_00:00:00"
> f_in = addfile(diri+nam1,"r")
> RAINC2 = f_in->RAINC(:,:,:)
>
> do it = 0, 47
> RAINC2(it,:,:) = RAINC(it+1,:,:) - RAINC(it,:,:)
> enddo
>
> ff = f_in + RAINC2
>
> names = getfilevarnames(ff); extract all variable names
> system("rm out.nc") ; remove any pre-existing file
> ncdf_out = addfile(out.nc,"c") ; create output netCDF file
> do i = 0, dimsizes(names)-1
> ncdf_out->$names(i)$ = f_in->$names(i)$
> end do
> end
> ------------------------------------------
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Sep 10 16:37:10 2013

This archive was generated by hypermail 2.1.8 : Mon Sep 16 2013 - 13:43:52 MDT