gives warning that dimension already exists

From: Donna Cote <d-cote_at_nyahnyahspammersnyahnyah>
Date: Wed, 05 Nov 2008 12:21:11 -0600

The purpose of my little script is to read a WRF file
(wrfout_d01...blah.blah.blah) and change the Time variable from
character to a Time Coordinate var.
I am reading in a file with the "w" option [ f=addfile(outname,"w") ]

I am wondering if I need to "undefine" the Time dimension in order to
replace it or change it.

Thanks,
Donna Cote

$ /share/apps/ncl/bin/ncl 'fn="wrfout_d01_2008-09-27_10:00:00"'
'initdateyyyy="2008"' 'initdatemm="09"' 'initdatedd="24"'
'initdateHH="00"' 'initdateMM="00"'
/home/wrfuser/ncl/addTimeCoordVarToWRF.ncl
 Copyright (C) 1995-2007 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 4.3.1
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
(0) have namedatepart as

Variable: namedatepart
Type: string
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) wrfout_d01_20080927
(0) have nametimepart as

Variable: nametimepart
Type: string
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 1000
(0) have outname as

Variable: outname
Type: string
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) wrfout_d01_20080927_1000.nc
(0) mydatestring is set to

Variable: mydatestring
Type: string
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 2008-09-24 00:00:00 00
warning:FileAddDim: Dimension Time is already defined
$ ncl_filedump -c Time wrfout_d01_2008-09-27_10:00:00.nc
 Copyright (C) 1995-2007 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 5.0.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
Variable: f (file variable)

filename: wrfout_d01_2008-09-27_10:00:00
path: /data8a/wrfuser/00z/20080924/wrfout_d01_2008-09-27_10:00:00
   file global attributes:
      TITLE : OUTPUT FROM WRF V2.2.1 MODEL
      START_DATE : 2008-09-24_00:00:00
      SIMULATION_START_DATE : 2008-09-24_00:00:00
      WEST-EAST_GRID_DIMENSION : 560
      SOUTH-NORTH_GRID_DIMENSION : 420
      BOTTOM-TOP_GRID_DIMENSION : 28
      DX : 12000
      DY : 12000
      GRIDTYPE : C
      DYN_OPT : 2
      DIFF_OPT : 1
      KM_OPT : 4
      DAMP_OPT : 0
      KHDIF : 0
      KVDIF : 0
      MP_PHYSICS : 2
      RA_LW_PHYSICS : 1
      RA_SW_PHYSICS : 1
      SF_SFCLAY_PHYSICS : 1
      SF_SURFACE_PHYSICS : 2
      BL_PBL_PHYSICS : 1
      CU_PHYSICS : 1
      SURFACE_INPUT_SOURCE : 1
      SST_UPDATE : 0
      GRID_FDDA : 0
      GFDDA_INTERVAL_M : 0
      GFDDA_END_H : 0
      UCMCALL : 0
      FEEDBACK : 1
      SMOOTH_OPTION : 0
      SWRAD_SCAT : 1
      W_DAMPING : 0
      PD_MOIST : 0
      PD_SCALAR : 0
      PD_TKE : 0
      DIFF_6TH_OPT : 0
      DIFF_6TH_FACTOR : 0.12
      OBS_NUDGE_OPT : 0
      WEST-EAST_PATCH_START_UNSTAG : 1
      WEST-EAST_PATCH_END_UNSTAG : 559
      WEST-EAST_PATCH_START_STAG : 1
      WEST-EAST_PATCH_END_STAG : 560
      SOUTH-NORTH_PATCH_START_UNSTAG : 1
      SOUTH-NORTH_PATCH_END_UNSTAG : 419
      SOUTH-NORTH_PATCH_START_STAG : 1
      SOUTH-NORTH_PATCH_END_STAG : 420
      BOTTOM-TOP_PATCH_START_UNSTAG : 1
      BOTTOM-TOP_PATCH_END_UNSTAG : 27
      BOTTOM-TOP_PATCH_START_STAG : 1
      BOTTOM-TOP_PATCH_END_STAG : 28
      GRID_ID : 1
      PARENT_ID : 0
      I_PARENT_START : 0
      J_PARENT_START : 0
      PARENT_GRID_RATIO : 1
      DT : 72
      CEN_LAT : 28.00001
      CEN_LON : -68.39999
      TRUELAT1 : 15
      TRUELAT2 : 45
      MOAD_CEN_LAT : 28.00001
      STAND_LON : -70
      GMT : 0
      JULYR : 2008
      JULDAY : 268
      MAP_PROJ : 1
      MMINLU : USGS
      ISWATER : 16
      ISICE : 24
      ISURBAN : 1
      ISOILWATER : 14
   dimensions:
      Time = 1 // unlimited
      DateStrLen = 19
      west_east = 559
      south_north = 419
      west_east_stag = 560
      bottom_top = 27
      south_north_stag = 420
      bottom_top_stag = 28
      soil_layers_stag = 4
   variables:
      character Times ( Time, DateStrLen )

      float LU_INDEX ( Time, south_north, west_east )
         FieldType : 104
         MemoryOrder : XY
         description : LAND USE CATEGORY
         units :
         stagger :
         coordinates : XLONG XLAT

      float U ( Time, bottom_top, south_north, west_east_stag )
         FieldType : 104
         MemoryOrder : XYZ
         description : x-wind component
         units : m s-1
         stagger : X
         coordinates : XLONG_U XLAT_U

      float V ( Time, bottom_top, south_north_stag, west_east )
         FieldType : 104
         MemoryOrder : XYZ
         description : y-wind component
         units : m s-1
         stagger : Y
         coordinates : XLONG_V XLAT_V

      float W ( Time, bottom_top_stag, south_north, west_east )
         FieldType : 104
         MemoryOrder : XYZ
         description : z-wind component
         units : m s-1
         stagger : Z
         coordinates : XLONG XLAT

      float PH ( Time, bottom_top_stag, south_north, west_east )
         FieldType : 104
         MemoryOrder : XYZ
         description : perturbation geopotential
         units : m2 s-2
         stagger : Z
         coordinates : XLONG XLAT
 <snip ... a lot of other variables ... /snip>

$ cat /home/wrfuser/ncl/addTimeCoordVarToWRF.ncl
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
;
;load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
;;;;;load "/home/wrfuser/ncarg/WRFUserARW.ncl"
;
; use of WRF_Times2Udunits_c function needs WRF_contributed.ncl
; use of wrf_user_getvar function needs this function copied
; from WRFUserARW.ncl
;
; ver 20081015 18:21Z first test dlc
; Note about WRF_Times2Udunits_c function:
; convert WRF character variable "Times" to a coordinate variable
"Time"
; opt can be "integer" or "string"
; . integer: opt = 0 : hours since initial time: Times(0,:)
; . opt = 1 : hours since 1901-01-01 00:00:00
; . string: opt = 'any udunits compatible string'
;
begin

;===============================================================
; expecting a CLA (Command Language Argument) of a
; filename, a beginning date-time value in YYYYMMDDhhmm format
;===============================================================
  if (.not. isvar("fn")) then ; testing for CLA
    print ("fn is not found. Need an input file name, expecting name
form to be wrfout_d01_...:00")
    exit
  end if
  if (.not. isvar("initdateyyyy")) then ; testing for CLA
    print ("initdateyyyy is not found. Need the input argument of the
YYYY (year) part of a init date-time value")
    exit
  end if
  if (.not. isvar("initdatemm")) then ; testing for CLA
    print ("initdatemm is not found. Need the input argument of the mm
(month) part of a init date-time value")
    exit
  end if
  if (.not. isvar("initdatedd")) then ; testing for CLA
    print ("initdatedd is not found. Need the input argument of the dd
(day of month) part of a init date-time value")
    exit
  end if
  if (.not. isvar("initdateHH")) then ; testing for CLA
    print ("initdateHH is not found. Need the input argument of the HH
(hour) part of a init date-time value")
    exit
  end if
  if (.not. isvar("initdateMM")) then ; testing for CLA
; will have a default minute of zero
    initdateMM=00
  end if
; note that in this routine, will rename
; wrfout_d01_2008-09-24_00:00:00
; to the format: wrfout_d01_20080924_0000.nc

;===============================================================
; copy file to target and will modify target file
;===============================================================
; [wrfuser_at_windfarm ~]$ echo 'wrfout_d01_2008-09-24_00:00:00' | cut -c
1-15,17-18,20-21
; wrfout_d01_20080924
; [wrfuser_at_windfarm ~]$ echo 'wrfout_d01_2008-09-24_00:00:00' | cut -c
23-24,26-27
; 0000
; [wrfuser_at_windfarm ~]$
  namedatepart=systemfunc("echo '"+fn+"' | /bin/cut -c 1-15,17-18,20-21")
print("have namedatepart as ")
print(namedatepart)
  nametimepart=systemfunc("echo '"+fn+"' | /bin/cut -c 23-24,26-27")
print("have nametimepart as ")
print(nametimepart)
  outname=namedatepart+"_"+nametimepart+".nc"
print("have outname as ")
print(outname)
  system("/bin/cp -f "+fn+" "+outname)

;===============================================================
; read the input file
;===============================================================
  f=addfile(outname,"w")

;===============================================================
; here, testing if this file does indeed have
; the char variable called Times
; Also testing if this Times variable is or is not
; an unlimited record
;===============================================================
  if ( (isfilevar(f, "Times")) ) then
    if ( sizeof(f->Times) .ge. 1) then

;===============================================================
; knowing there is a variable named Times, get the value
; of Times and assign it to Time making use of a function in
; the loaded set of scripts in WRF_contributed.ncl, to create
; a Udunits type of Time var from the char Times variable
; where using the second parameter's option for a custom
; string formatted, in this case as
; : hours since 1901-01-01 00:00:00
;
;===============================================================
; given CLA initdateyyyy initdatemm initdatedd initdateHH
initdateMM
;
      mydatestring=initdateyyyy+"-"+initdatemm+"-"+initdatedd+"
"+initdateHH+":"+initdateMM+":00 00"
print("mydatestring is set to ")
print(mydatestring)
; Time = WRF_Times2Udunits_c((/f->Times/), "hours since
"+initdateyyyy+"-"+initdatemm+"-"+initdatedd+"
"+initdateHH+":"+initdateMM+":00 00")
      Time = WRF_Times2Udunits_c((/f->Times/), "hours since "+mydatestring)

;===============================================================
; assign the metadata of Time to this new Time var
;===============================================================
      Time!0="Time"

;===============================================================
; make sure the Time variable is the record dimension
;===============================================================
      filedimdef(f, "Time", -1, True)

;===============================================================
; this is the else of whether the file just read in
; has an unlimited record variable named Times; above if stmt is:
; if ( sizeof(f->Times) .ge. 1) then
; if else: notify with print statement and skip the file
;===============================================================
    else
      print ("this file ("+outname+") has a bad Times var where the
dimension size of Times is less than 1")
    end if

;===============================================================
; this is the else of whether the file just read in
; has a char variable named Times; above if stmt is:
; if ( (isfilevar(f, "Times")) ) then
; if else: notify with print statement and skip the file
;===============================================================
  else
    print ("this file ("+outname+") does not have a Times var")
  end if

;===================================================================
; explicit end of script
;===================================================================
end

$

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Nov 05 2008 - 11:21:11 MST

This archive was generated by hypermail 2.2.0 : Fri Nov 07 2008 - 13:41:15 MST