Using fill value

From: Gina Henderson <ginah_at_nyahnyahspammersnyahnyah>
Date: Fri, 21 Nov 2008 17:32:48 -0500

Hi all,

I am trying to read data from an ascii file and set a missing value code of
-9. However no matter what I set the _FillValue to be it just comes out as
-999 and doesn't register in my output .nc file. I need the missing value
set as I am performing an if test in a later program and ncl won't let me do
an if on data without a missing value code.

Also, I am trying to use an if statement to convert a value from cm to m if
there is no missing data only and cannot seem to get it to work.

Any tips on using this function or the if statement?
Thanks, Gina.

; Load some resources
 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/shea_util.ncl"

begin
;
; Read the ascii file.
;
; Read in the data as an nlat*nlon x14 array

  nlat = 64
  nlon = 128

  snow_data=asciiread("minavg_t42.txt",(/nlat*nlon,14/),"float")

; Extract the lat coordinates from the data array.
; Since the latitude values are repeated, we only need to
; grab every nlon-th value.

  lat1d = snow_data(::nlon,0)
  lat1d_at_units = "degrees_north"

; Same for lon

  lon1d = snow_data(0:nlon-1,1)
  lon1d_at_units = "degrees_east"

; Define new variable for snow depth for all 12 months

  snowdepth_minavg_meters = new((/12,64,128/), float)
  snowdepth_minavg_meters!0 = "time"
  snowdepth_minavg_meters!1 = "lat"
  snowdepth_minavg_meters!2 = "lon"

  time = (/1,2,3,4,5,6,7,8,9,10,11,12/)
  snowdepth_minavg_meters&time = time
  snowdepth_minavg_meters&lat = lat1d
  snowdepth_minavg_meters&lon = lon1d
  snowdepth_minavg_meters&lat_at_units = "degrees_north"
  snowdepth_minavg_meters&lon_at_units = "degrees_east"
  snowdepth_minavg_meters@_FillValue = -9.

; set attributes
  snowdepth_minavg_meters_at_long_name = "snow depth"
  snowdepth_minavg_meters_at_units = "cm"

do n=0,11

; Convert data to a 2D grid 64x128

  snowdepth1D = snow_data(:,n+2) ; first create 1D array
  snowdepth2D = onedtond(snowdepth1D,(/nlat,nlon/)) ; convert to 2D

; Assign named dimensions

  snowdepth2D!0 = "lat"
  snowdepth2D!1 = "lon"

; Assign coordinate variables

  snowdepth2D&lat = lat1d
  snowdepth2D&lon = lon1d

; Write snow data to new array containing all months and change value
; to meters except for missing values which are -9.0

  snowdepth_minavg_meters(n,:,:) = snowdepth2D
  if ((snowdepth_minavg_meters(n,:,:) .ne. snowdepth_minavg_meters@_FillValue))
then
  snowdepth_minavg_meters(n,:,:) = snowdepth_minavg_meters(n,:,:) / 100.
  end if

end do

  printVarSummary(snowdepth_minavg_meters)

; Mask out over ocean
  a = addfile("landmask.nc","r")
  clm_t42 = a->landmask

  snowdepthms_minavg_meters = snowdepth_minavg_meters

; Mask out all ocean points from t42
  snowdepthms_minavg_meters =
mask(snowdepth_minavg_meters,clm_t42.eq.0,False)

  printVarSummary(snowdepthms_minavg_meters)

;=====================================================================
; Write data to new netcdf file
;=====================================================================
  system("/bin/rm -f snowdepth_minavg_meters.nc") ; remove any
pre-existing file
  ncdf = addfile("snowdepth_minavg_meters.nc" ,"c") ; open output
netCDF file

; make time and UNLIMITED dimension ; recommended for most
applications
  filedimdef(ncdf,"time",-1,True)

; output variables directly
  ncdf->snowdepthms_minavg_meters = snowdepthms_minavg_meters ;
write file

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Nov 21 2008 - 15:32:48 MST

This archive was generated by hypermail 2.2.0 : Tue Nov 25 2008 - 10:18:44 MST