writing time array as string to netcdf file?

From: Kelly Mahoney <Kelly.Mahoney_at_nyahnyahspammersnyahnyah>
Date: Fri Mar 11 2011 - 13:41:17 MST

Hi,
I found a similar question from 2006
<http://www.ncl.ucar.edu/Support/talk_archives/2006/0808.html> in the
help archives, but I was wondering if this is since possible?
Like the 2006 message, I also am trying to write my time array (defined
as type "string") to an output netcdf file, but when it gets to the
writing stage, my error says:
> fatal:Assignment type mismatch, right hand side can't be coerced to
> type of left hand side
> fatal:Execute: Error occurred at or near line 126 in file
> Freezing_Level_Height_Basic.ncl

A snippet of my code is below -- if this can be done, or if there is a
viable workaround, I'd be very appreciative to learn more!
Thanks,
Kelly Mahoney

****************************************************************************************************************************************

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

begin
setvalues NhlGetWorkspaceObjectId()
         "wsMaximumSize" : 100000000000
end setvalues
setfileoption("nc", "SuppressClose", False)

;**********************************************************
; open files, make outfile, and read in required data
;**********************************************************
outname = "FZLH_GFDLts_COMP_WSM6_PAST.nc"
outfile=addfile(outname,"c")

diri_fut = "WSM6_fut/"
fils = systemfunc("ls "+diri_fut+"wrfout_d02_2040*")+".nc"
nfil = dimsizes(fils)

;km Also make array for cumulative field of freezing level at all times
frz_lev_alltimes = new((/nfil,1,600,573/),float)
alltimes = new((/nfil/),string)

;km do nf=0,nfil-1
   do nf=1,1

   isolevs=0.
   isolevs!0="level"
   isolevs&level=isolevs
   isolevs@units="degree_C"
   isolevs@positive="up"

   f=addfile(fils(nf),"r")
   times = wrf_user_list_times(f) ; get time(s) in the file
   ntimes = dimsizes(times)

lat=f->XLAT(0,:,:)
lon=f->XLONG(0,:,:)
hgt=f->HGT(0,:,:)
...
t = wrf_user_getvar(f,"tc",-1) ; read in temp in celsius
p = wrf_user_getvar(f, "pressure",-1) ; pressure is our vertical
coordinate
z = wrf_user_getvar(f, "z",-1) ; grid point height
...
   alllevel=t
...
   xlvl =
int2p_n_Wrap(t(Time|:,bottom_top|:,south_north|:,west_east|:),z(Time|:,bottom_top|:,south_north|:,west_east|:),
isolevs, 1, 1)
...
;check to see if interpolation failed due to inversion
slice=ndtooned(xlvl) ;; convert depths to 1D slice in order to find
missing values
retry=(ind(ismissing(slice))) ;; store locations that have missing values
;; loop trough model levels to get past inversions that may be causing
interpolation to fail
  do ilev=1,27
;km print("At level "+ilev+", points undefined = "+dimsizes(retry))
   mytmp =
int2p_n_Wrap(t(Time|:,bottom_top|:,south_north|:,west_east|:),z(Time|:,bottom_top|:,south_north|:,west_east|:),
isolevs, 1, 1)
  mytmp@missing_value=-999.
  mytmp@_FillValue=-999.

   slice2=ndtooned(mytmp) ;; convert new depths to 1D slice
   slice(retry)=slice2(retry) ;; replace old depths with new depths in slice
   delete(retry) ;delete locations of missing values in previous depth
computation
   retry=(ind(ismissing(slice))) ;; check for values that are still
missing and compute depths one layer deeper
  end do ; levels
;; after looping through model levels the 1D variable "slice" contains
the updated depths
;; and must be converted back to it's multidimensional state.
   xlvl=onedtond(slice,dimsizes(xlvl))

;km: Find and print avg frz lev ht for whole domain:
   avg_frz_lev_ht = dim_avg_Wrap(dim_avg_Wrap(xlvl))
   print("For File #"+nf+", avg FRZLEV ht is "+avg_frz_lev_ht+"m")

;km: Write to cumulative field,

frz_lev_alltimes(nf,:,:,:)=xlvl

alltimes(nf)=times

;km: End file loop
   delete(t)
   delete(xlvl)
   delete(retry)
   delete(slice)
   delete(f)
end do ; files

;km: Write cumulative field to output netcdf file:

alltimes!0="time"
alltimes&time=alltimes

frz_lev_alltimes!0 = "time"
frz_lev_alltimes!1 = "level"
frz_lev_alltimes!2 = "south_north"
frz_lev_alltimes!3 = "west_east"

frz_lev_alltimes@units = "m above sea level"
frz_lev_alltimes@long_name = "Frz Lev Height (m)"
frz_lev_alltimes&time = alltimes
print(alltimes)

dimNames=(/"time","level","south_north","west_east"/) ;predefine
coordinate vars
dimSizes=(/nfil,1,600,573/)
dimUnlim=(/True,False,False,False/)
filedimdef(outfile,dimNames,dimSizes,dimUnlim)

outfile->FZLH = frz_lev_alltimes

delete(frz_lev_alltimes)

end

exit

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Mar 11 13:41:23 2011

This archive was generated by hypermail 2.1.8 : Wed Mar 16 2011 - 09:22:37 MDT