Re: Re: Using fill value

From: Gina Henderson <ginah_at_nyahnyahspammersnyahnyah>
Date: Sun, 23 Nov 2008 15:36:06 -0500

Thanks Adam and Dave for your suggestions. I got the missing value to work
:) I am now trying to use the 'where' function but am getting a fatal error
saying: 'Undefined identifier: (where) is undefined. I am trying to take one
grid and for any value that exists for that grid (ie. not a missing/fill
value) put into that space in another grid.

Any suggestions on how I might be using 'where' incorrectly ?
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/contributed.ncl"
 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"

begin

 a = addfile("snowfile_clim_eur.nc","w")
 b = addfile("snowdepth_minavg_meters.nc","r")

 snowdp = a->SNOWDP
 snowdp_eur = b->snowdepth_minavg_meters

 printVarSummary(snowdp)
 printVarSummary(snowdp_eur)

 snowdp = where((snowdp_eur .ge. 0.), snowdp, snowdp_eur)

end

On Fri, Nov 21, 2008 at 7:40 PM, Adam Phillips <asphilli_at_cgd.ucar.edu>wrote:

> Hi Gina,
> I believe the -'s in the netCDF file means that those values are already
> set to _FillValue..
> Adam
>
> Gina Henderson wrote:
>
>> Hi there,
>>
>> also just to add, is there any way when I apply my land mask that the
>> masked gridpoints can be set to the missing value also? As presently they
>> are set to - in my output .nc file.
>>
>> Thanks, Gina.
>>
>> On Fri, Nov 21, 2008 at 5:32 PM, Gina Henderson <ginah_at_udel.edu <mailto:
>> ginah_at_udel.edu>> wrote:
>>
>> 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 <http://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
>> <http://snowdepth_minavg_meters.nc>") ; remove any pre-existing file
>> ncdf = addfile("snowdepth_minavg_meters.nc
>> <http://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
>>
>>
>>
>>
>>
>> --
>> Gina Henderson
>> Graduate Student
>> Department of Geography
>> 215 Pearson Hall
>> University of Delaware
>> Newark DE
>> 19718-2541
>>
>> Email: ginah_at_udel.edu <mailto:ginah_at_udel.edu>
>> Ph: 302-831-2344
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
> --
> --------------------------------------------------------------
> Adam Phillips asphilli_at_ucar.edu
> National Center for Atmospheric Research tel: (303) 497-1726
> ESSL/CGD/CAS fax: (303) 497-1333
> P.O. Box 3000
> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>

-- 
Gina Henderson
Graduate Student
Department of Geography
215 Pearson Hall
University of Delaware
Newark DE
19718-2541
Email: ginah_at_udel.edu
Ph: 302-831-2344

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Nov 23 2008 - 13:36:06 MST

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