Re: use (/ .. /) if this is not the desired result

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu, 30 Mar 2006 11:58:13 -0700 (MST)

Tom,
>
>I am always messing up this sort of thing in NCL. The error messages
>below are totally cryptic to me.

Agreed :-)

>Do you have any general comments about
>what these things mean? Any help would be appreciated.
>These are warning messages, and the output netcdf file
>I want actually does get written. But what???
>
>Code snippets:
>;Make a bunch of netcdf variables for output
>var_names3D = (/"tide_Ephase","tide_Eamp","tide_Cphase",\
> "tide_Cangle","tide_Cmin","tide_Cmax"/)
>var_types3D = (/ "double", "double", "double", "double", "double",
>"double" /)
>filevardef( out, var_names3D, var_types3D, \
> (/ "tide_period", "eta_rho", "xi_rho" /) )
>
>
>; Make a scratch array and zero it out
>grd=out->tide_Ephase
>grd=0.0

---
So, you are reading from the output file? or did u mean
                                          grd=intide->tide_Ephase
If u do a                                     ^^^^^^
 printVarSummary(grd)
 
You will see that "grid" has meta data associated with it.
meta data: attributes and named dimensions.
values:    all 0.0
>
>
>; Fill the scratch array and write it back out to pre-defined variable
>; Cangle
>print("Cangle")
>nodevalues=intide->tide_Cangle
Again the variable "nodevalues" will (presumably) have 
meta data associated with it.
  printVarSummary(nodevalues)
>print("After nodevalues=")
>do iperiod = 0,tide_period-1
>  kperiod = periodpointer(iperiod)
>  Fperiod = tidefacpointer(iperiod)
>   do k = 0,node-1
>     grd(iperiod,i_rho(k),j_rho(k))=nodevalues(k,kperiod)
Here is where the error messages occur. 
The above is what NCL calls a "variable-to-variable" assignment.
[No operation is being performed on the right hand
 side of the = symbol.] 
 
When performing variable-to-variable  assignment NCL will 
transfer [copy] meta data from the rhs variable to the lhs
variable. When there are conflicts, NCL will use meta data 
associated with the rhs variable to overwrite the corresponding
meta data associated with the lhs variable.
http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml#VariableToVariable
      warning:VarVarWrite: 
      Dimension names for dimension number (0) don't match,
      assigning name of rhs dimension to lhs, 
      use "(/../)" if this change is not desired
      
      lhs - left hand side   [included so that non-native
      rhs - right hand side   English speakers know what
                              the abreviations mean]
I'll bet that the 0th [leftmost] dimension  name of
variable "grd" [lhs variable] does not match the 0th  
[leftmost] dimension name of "nodevalues" [rhs variable].
The warning message is informing you that it will
overwrite variable "grd" 0th dimension name with 
"nodevalues" 0th dimension name.
Same for the 1-th dimension name.
   grd(iperiod,i_rho(k),j_rho(k)) = (/ nodevalues(k,kperiod) /)
means that the values will be transferred but 
no meta data will be transferred. Thus, the "grd" variable
will retain its original meta data.
If you want "grd" to have the same dimension name as "nodevalues"
you can do the following after the loop
   grd!0 = nodevalues!0    ; the leftmost dimension 
                           ; is the 0th dimension
Note: I am attaching a code snippet that creates a netCDF file.
      It uses the "setfileoption" procedure [available
      in v033] to set "DefineMode" for netCDF.
      
      This can *substantially* reduce the time
      it takes to write netCDF files.
      
Regards
D

; ----------------Create a netCDF file----------------------------------
; (1) create (addfile) new netcdf file
; (2) create globe attributes of the netCDF file
; (2) pre-define "time" as an unlimited dimension
; (3) create dimensions of variables (needed before any writing can be done)
; (4) Loop through all "nrec" records
; (5) write the netCDF file

  print("=================================================== " )
  print("======> netCDF: "+systemfunc("date")+" <====== " )
  print("=================================================== " )
  nline = inttochar(10)

  globeAtt = 1
  globeAtt_at_title = "Seasonal Means of Eddy Quantities"
  globeAtt_at_source = diri+keyDir+"_EP_*"

  globeAtt_at_story = nline + \
                         "Daily model data were averaged to monthly means."+nline+\
                         "All products were computed on the hybrid levels,"+nline+\
                         "then interpolated to the NCEP pressure levels using "+nline+\
                         "vinth2p_ecmwf. The variable T was not treated differently"+nline+\
                         "because PHIS was not available."+nline + \
                         "-------------------------------"+nline + \
                         "The individual months for each year were averaged together"+nline+\
                         " to create the Nov-Mar seasonal means"+nline
  globeAtt_at_NCL = nline + \
                         "/fs/cgd/home0/shea/ncld/epFlux/epPlotSeaNc.ncl"+nline
  globeAtt_at_creation_date= systemfunc ("date" )

      filo = "Test.nc"
      NCFILE = diro+filo
      system ("/bin/rm -f " + NCFILE) ; remove any pre-exist file
      
      ncdf = addfile(NCFILE,"c") ; (1) create the file reference

      setfileoption(ncdf,"DefineMode",True); (2) Makes nc write ***MUCH*** faster

      fileattdef( ncdf, globeAtt ) ; (3) globe file attributes
                                    
                                           ; (4) define assorted dimensions
      dimNames = (/"time", "lat", "lon", "lev", "ncl_scalar" /) ; names
      dimSizes = (/ -1 , nlat, mlon, klev , 1 /) ; sizes
      dimUnlim = (/ True , False, False, False, False /) ; unlimited?
      filedimdef(ncdf, dimNames , dimSizes, dimUnlim )

                                           ; (5) define each variable on file
      filevardef (ncdf, "time" , typeof(time), getvardims(time) )
      filevarattdef(ncdf, "time", time) ; NCL will automatically define all
                                           ; all attributes associated with
                                           ; variable time

      filevardef (ncdf, "lev" , typeof(lev) , getvardims(lev) )
      filevarattdef(ncdf, "lev", lev)
     
      filevardef (ncdf, "lat", typeof(lat), getvardims(lat))
      filevarattdef(ncdf, "lat", lat)
     
      filevardef (ncdf, "lon", typeof(lon), getvardims(lon))
      filevarattdef(ncdf, "lon", lon)
                                            ; special for writing scalars to netCDF
      filevardef (ncdf, "con", typeof(con), "ncl_scalar")
      filevarattdef(ncdf, "con", con)
                                            ; Static stability (s)
      filevardef(ncdf, "S" , typeof(s) , getvardims(s) )
      filevarattdef(ncdf, "S", s)
                                            ; u'u'
      filevardef(ncdf, "UpUp" , typeof(upup) , getvardims(upup) )
      filevarattdef(ncdf, "UpUp", upup)
                                            ; v'v'
      filevardef(ncdf, "VpVp" , typeof(vpvp) , getvardims(vpvp) )
      filevarattdef(ncdf, "VpVp", vpvp)
                                            ; u'v'
      filevardef(ncdf, "UpVp" , typeof(upvp) , getvardims(upvp))
      filevarattdef(ncdf, "UpVp", upvp)
                                            ; v't'
      filevardef(ncdf, "VpTp" , typeof(vptp) , getvardims(vptp) )
      filevarattdef(ncdf, "VpTp", vptp)
                                            
      filevardef(ncdf, "S_VpTp" , typeof(svptp) , getvardims(svptp) )
      filevarattdef(ncdf, "S_VpTp", svptp)

      setfileoption(ncdf,"DefineMode",False)
                                            ; write values [no meta data]
                                            ; to predefined "locations"
      ncdf->time = (/ time /) ; (/ ... /) values only
      ncdf->lev = (/ lev /)
      ncdf->lat = (/ lat /)
      ncdf->lon = (/ lon /)
 
      ncdf->R = (/ con /)

      ncdf->S = (/ s /)
      ncdf->UpUp = (/ upup /)
      ncdf->VpVp = (/ vpvp /)
      ncdf->UpVp = (/ upvp /)
      ncdf->VpTp = (/ vptp /)
      ncdf->S_VpTp = (/ svptp /)

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Mar 30 2006 - 11:58:13 MST

This archive was generated by hypermail 2.2.0 : Thu Mar 30 2006 - 15:04:24 MST