output to netcdf file

From: Erik Noble <enoble_at_nyahnyahspammersnyahnyah>
Date: Thu, 15 Nov 2007 14:47:37 -0500

Hi.
I am trying to create a netcdf file. I have to read in 4-hourly data
for at each time step to grab a precipitation variable.
My goal to just to have "1" netcdf file that contains this variable
over all timesteps. I followed example one, here, http://www.ncl.ucar.edu/Applications/method_1.shtml
, yet when I look at my resulting file, it looks empty, or I am not
defining time correctly
I am trying to make the dimensions go from (lat, lon) to (time, lat,
lon)
May I have some help here?
-Erik

Erik_at_noble:/Volumes/Data_and_Models/ncl_scripts:ncdump -h simple-WRF-
precip.nc
netcdf simple-WRF-precip {
dimensions:
        time = UNLIMITED ; // (0 currently)
        lat = 109 ;
        lon = 139 ;
variables:
        float rain_tot_tend(lat, lon) ;
                rain_tot_tend:units = "mm" ;
                rain_tot_tend:long_name = "Accumulated Precipitation" ;
                rain_tot_tend:description = "Precipitation Tendency" ;
}
Erik_at_noble:/Volumes/Data_and_Models/ncl_scripts:

; Example script to produce plots for a WRF real-data run,
; with the ARW coordinate dynamics option.

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

begin

; The WRF ARW input file.
diri1 ="/Volumes/Data_and_Models/Model-Output/Athena/"
ifile1 ="WRF-SOP3_Athena_3_1_2.nc"
title = "WRF-R2_Precipitation_00UT-SOP3"
a=addfile(diri1+ifile1,"r") ;read .nc file
ncdf=addfile("simple-WRF-precip.nc","c") ;output .nc file
filedimdef(ncdf,"time",-1,True)
; What times and how many time steps are in the data set?
   FirstTime = True
   times = wrf_user_list_times(a) ; get times in the file
   ntimes = dimsizes(times) ; number of times in the file

   ;do it = 0,ntimes-1 ; TIME LOOP
do it =248, ntimes-1 ; TIME LOOP

  if (FirstTime) then ; Save some times for tracking
tendencies
       times_sav = times(it)
  end if

;;;;;;;;;;;; ; First get the variables we will need
        
; Get non-convective, convective and total precipitation
   ; Calculate tendency values
     rain_exp = wrf_user_getvar(a,"RAINNC",it)
     rain_con = wrf_user_getvar(a,"RAINC",it)
     rain_tot = rain_exp + rain_con
     rain_tot_at_description = "Total Precipitation"

     if( FirstTime ) then
       if ( it .eq. 0 ) then
         rain_exp_save = rain_exp
         rain_con_save = rain_con
         rain_tot_save = rain_tot
       else
         rain_exp_save = wrf_user_getvar(a,"RAINNC",it-1)
         rain_con_save = wrf_user_getvar(a,"RAINC",it-1)
         rain_tot_save = rain_exp_save + rain_con_save
         FirstTime = False
         times_sav = times(it-1)
       end if
     end if

     rain_tot_tend = rain_tot - rain_tot_save ; Our variable of
interest!!!!!
     rain_tot_tend_at_description = "Precipitation Tendency" ;Rain within
time period spcified in loop

   ; Bookkeeping, just to allow the tendency at the next time step
     rain_exp_save = rain_exp
     rain_con_save = rain_con
     rain_tot_save = rain_tot
        
;;;;;;;;;;;;; ;OutPut to netcdf file
        rain_tot_tend!0 = "lat" ; assign named
dimensions
        rain_tot_tend!1 = "lon"

        rain_tot_tend_at_long_name = "Accumulated
Precipitation" ; assign attributes
        rain_tot_tend_at_units = "mm"

   ncdf->rain_tot_tend = rain_tot_tend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

     end do ; END OF TIME LOOP

end

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Nov 15 2007 - 12:47:37 MST

This archive was generated by hypermail 2.2.0 : Sun Nov 25 2007 - 07:21:25 MST