ncl

From: DUBOIS Clotilde <clotilde.dubois_at_nyahnyahspammersnyahnyah>
Date: Wed Oct 31 2012 - 09:18:12 MDT

Hello NCL,

I'm trying to write a new netcdf file after regriding data onto a
regional 2-D grid. The file is created but the lon/lat information are
define as variables, which cause me some trouble when i am doing some
operations afterwards especially when using CDO.
/Below is what I'm trying to do by creating a lat2d ///lon2d grid. /I am
not sure what is went wrong but any help or direction would be greatly
appreciated.

Best regards,

Clotilde

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"
begin
;*******************************************
; open file and read in data
;*******************************************

;f = addfile
("/home/dubois/LATMOS/tas_MED-44_ECMWF-ERAINT_evaluation_r1i1p1_CNRM-ALADIN52_v1_mon_201101-201112_mean.nc",
"r")
f = addfile
("/home/dubois/LATMOS/tas_MED-11_ECMWF-ERAINT_evaluation_r1i1p1_CNRM-ALADIN52_v1_mon_201101-201112_mean.nc","r")

field=f->tas
lat2d= f->lat
lon2d= f->lon

dimp = dimsizes(field)
nlat = dimp(2)
nlon = dimp(3)

f7 =
addfile("/sxeac1/data0/dubois/VALIDATION/DATA/CRU/cru_ts_3_00.1901.2006.tmp.nc","r")
lat_cru = f7->lat(200:320)
lon_cru = f7->lon(300:470)
TIME= f7->time

precip = f7->tmp

dimp1 = dimsizes(precip)
ntim = dimp1(0)

t2m_cru = new((/ntim,nlat,nlon/),"float")

i=-1

do year=1901,2006
   do month=1,12
     i=i+1
      champ = f7->tmp(i,200:320,300:470)*0.1
      t2m_cru(i,:,:)=rgrid2rcm(lat_cru,lon_cru,champ,lat2d,lon2d,1)
end do
  end do

   DATE = cd_calendar(TIME, 0)
   new_time_units = "hours since 1901-01-01 00:00"
   time = time_to_newtime(TIME, new_time_units)
printVarSummary(TIME)

;==================================================================
;==================================================================

system("/bin/rm -f foo2.nc") ; remove any pre-existing file

fout= addfile("foo2.nc","c")

   ;===================================================================
     ; explicitly declare file definition mode. Improve efficiency.
     ;==================================================================
         setfileoption(fout,"DefineMode",True)

     ;===================================================================
     ; create global attributes of the file
     ;===================================================================
         fAtt = True ; assign file attributes
     fAtt@title = "NCL Efficient Approach to netCDF Creation"
     fAtt@source_file = "original-file.nc"
     fAtt@Conventions = "None"
     fAtt@creation_date = systemfunc ("date")
     fileattdef( fout, fAtt ) ; copy file attributes

     ;===================================================================
     ; predefine the coordinate variables and their dimensionality
     ; Note: to get an UNLIMITED record dimension, we set the dimensionality
     ; to -1 (or the actual size) and set the dimension name to True.
     ;===================================================================
         dimNames = (/"x","y","time"/)
     dimSizes = (/ nlon, nlat, -1 /)
     dimUnlim = (/ False , False, True/)
     filedimdef(fout,dimNames,dimSizes,dimUnlim)

     ;===================================================================
     ; predefine the the dimensionality of the variables to be written out
     ;===================================================================
     ; Here we are using NCL functions to facilitate defining
     ; each variable's dimension name(s) and type.
     ; The following could be replaced with explicit, user defined
dimension
     ; names different from those associated with the variable in memory.
     ; Say, PS(time,lat,lon) in the NCL script. They could be redefined
for the file via:
     ; filevardef(fout, "PS" ,typeof(PS)
,(/"TIME","latitude","longitude"/))
     ;===================================================================
        filevardef(fout, "time" ,typeof(time),getvardims(time))
; filevardef(fout, "lat" ,typeof(lat),"lat")
; filevardef(fout, "lon" ,typeof(long),"lon")
; filevardef(fout, "temp" ,typeof(temp), dimNames) ;
variable name on the file
                                                                ;
different from name on script
;printVarSummary(temp)

        filevardef(fout, "t2m_cru" ,"float",(/"time","y","x"/))

     ;===================================================================
     ; Copy attributes associated with each variable to the file
     ; All attributes associated with each variable will be copied.
     ;====================================================================
  ; filevarattdef(fout,"vol_per_cel",T) ; copy T
attributes
  ; filevarattdef(fout,"lon" ,longitude) ; copy lon
attributes
; filevarattdef(fout,"lat" ,latitude) ; copy lat
attributes
        filevarattdef(fout,"time" ,time) ; copy time
attributes

t2m_cru@units="degrees"
fout->t2m_cru=t2m_cru
;t2m_cru@lat2d=lat2d
;t2m_cru@lon2d=lon2d

fout->lat2d=lat2d
fout->lon2d=lon2d
fout->time=time

end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Oct 31 09:18:38 2012

This archive was generated by hypermail 2.1.8 : Tue Nov 06 2012 - 15:05:49 MST