lai/03.land_class_to_1.9.ncl
changeset 0 0c6405ab2ff4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lai/03.land_class_to_1.9.ncl	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,139 @@
     1.4 +; ***********************************************
     1.5 +; interpolate into model grids (T42)
     1.6 +; output: lat: S->N    lon: 0->360
     1.7 +; input : lat: N->S    lon: -180->180 
     1.8 +; ***********************************************
     1.9 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    1.10 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
    1.11 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
    1.12 +;************************************************
    1.13 +begin
    1.14 +
    1.15 +  nclass = 20
    1.16 +
    1.17 +;************************************************
    1.18 +; output data
    1.19 +;************************************************
    1.20 +  diro  = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/"
    1.21 +  filo  = "land_class_1.9.nc"
    1.22 +  c = addfile(diro+filo,"c")
    1.23 +
    1.24 +;************************************************
    1.25 +; read in observed data
    1.26 +;************************************************
    1.27 +  diri  = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/"
    1.28 +  fili  = "land_class_0.25deg_new.nc"
    1.29 +  g     = addfile (diri+fili,"r")
    1.30 +  bi    = g->LAND_CLASS   
    1.31 +  xi    = g->lon 
    1.32 +  yi    = g->lat
    1.33 +
    1.34 +;************************************************
    1.35 +; change into 0-360E, 90S-90N
    1.36 +;************************************************
    1.37 + 
    1.38 + yi    = (/ yi(::-1) /)
    1.39 + bi    = (/ bi(::-1,:) /)
    1.40 + printVarSummary(bi)
    1.41 +
    1.42 + b2    = bi
    1.43 + x2    = xi   
    1.44 + 
    1.45 + nx  = dimsizes(xi)
    1.46 + nx2 = nx/2
    1.47 +
    1.48 + do i= 0,nx-1
    1.49 +    if (i .lt. nx2) then
    1.50 +       p = i + nx2
    1.51 +       xi(p) = x2(i) + 360.      
    1.52 +    else
    1.53 +       p = i - nx2
    1.54 +       xi(p) = x2(i)
    1.55 +    end if
    1.56 +    bi(:,p)= b2(:,i) 
    1.57 + end do
    1.58 +
    1.59 + bi&lat =  yi
    1.60 + bi&lon =  xi
    1.61 +
    1.62 + print (xi)
    1.63 + print (yi)
    1.64 +;exit
    1.65 +
    1.66 +;************************************************
    1.67 +; read in model data
    1.68 +;************************************************
    1.69 + diri2  = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
    1.70 + fili2  = "newcn05_ncep_1i_MONS_climo_lnd.nc"
    1.71 + f     = addfile (diri2+fili2,"r")
    1.72 +
    1.73 + lon    = f->lon     
    1.74 + lat    = f->lat
    1.75 + nlon   = dimsizes(lon)
    1.76 + nlat   = dimsizes(lat)      
    1.77 +
    1.78 +; print (xi)
    1.79 +; print (yi)
    1.80 +; print (xo)
    1.81 +; print (yo)
    1.82 +
    1.83 + bo = new((/nlat,nlon/),integer)
    1.84 + count = new((/nclass/),integer)
    1.85 +
    1.86 +  do j=0,nlat-1
    1.87 +     if (j.eq.0 .or. j.eq.nlat-1) then
    1.88 +        if (j.eq.0) then
    1.89 +           LATS = -90.          
    1.90 +           LATN = lat(j)+0.5*(lat(j+1)-lat(j))
    1.91 +        end if
    1.92 +        if (j.eq.nlat-1) then
    1.93 +           LATS = lat(j)-0.5*(lat(j)-lat(j-1))
    1.94 +           LATN = 90.                  
    1.95 +        end if
    1.96 +     else
    1.97 +        LATS = lat(j)-0.5*(lat(j)-lat(j-1))
    1.98 +        LATN = lat(j)+0.5*(lat(j+1)-lat(j))
    1.99 +     end if
   1.100 + 
   1.101 +     do i=0,nlon-1
   1.102 +        if (i.eq.0 .or. i.eq.nlon-1) then
   1.103 +           if (i.eq.0) then
   1.104 +              LONL = 0.          
   1.105 +              LONR = lon(i)+0.5*(lon(i+1)-lon(i))
   1.106 +           end if
   1.107 +           if (i.eq.nlon-1) then
   1.108 +              LONL = lon(i)-0.5*(lon(i)-lon(i-1))
   1.109 +              LONR = 360.                 
   1.110 +           end if
   1.111 +        else
   1.112 +           LONL = lon(i)-0.5*(lon(i)-lon(i-1))
   1.113 +           LONR = lon(i)+0.5*(lon(i+1)-lon(i))
   1.114 +        end if
   1.115 +
   1.116 +;print (LATS)
   1.117 +;print (LATN)
   1.118 +;print (LONL)
   1.119 +;print (LONR)
   1.120 +
   1.121 +        count = 0
   1.122 +
   1.123 +        do n = 0,nclass-1
   1.124 +           count(n) = num (bi({LATS:LATN},{LONL:LONR}).eq.n)
   1.125 +        end do
   1.126 + 
   1.127 +        bo(j,i) = maxind(count)  
   1.128 +     end do     
   1.129 +  end do
   1.130 +
   1.131 +  bo!0   = "lat"
   1.132 +  bo!1   = "lon"
   1.133 +  bo&lat = lat
   1.134 +  bo&lon = lon
   1.135 +  bo@units      = bi@units
   1.136 +  bo@long_name  = bi@long_name
   1.137 +  bo@_FillValue = bi@_FillValue
   1.138 +
   1.139 +  print (min(bo) + "/" + max(bo))
   1.140 +
   1.141 +  c->LAND_CLASS  = bo
   1.142 +end
   1.143 \ No newline at end of file