npp/02.read.ascii.ncl.x
changeset 0 0c6405ab2ff4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/npp/02.read.ascii.ncl.x	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,83 @@
     1.4 +;************************************************
     1.5 +;    Read ascii, Write nc                         
     1.6 +;************************************************
     1.7 +;load "/fs/cgd/data0/shea/nclGSUN/gsn_code.ncl"   
     1.8 +;load "/fs/cgd/data0/shea/nclGSUN/gsn_csm.ncl"    
     1.9 +;load "/fs/cgd/data0/shea/nclGSUN/shea_util.ncl"  
    1.10 +;************************************************
    1.11 +begin
    1.12 +;---------------------------------------------------
    1.13 +; final data                                    
    1.14 +  c = addfile("Npp_0.05deg_mean4.nc","c")
    1.15 +  filedimdef(c,"time",-1,True) 
    1.16 +       
    1.17 +  nlat  = 180*20 
    1.18 +  nlon  = 360*20  
    1.19 + 
    1.20 +;---------------------------------------------------
    1.21 +; input data
    1.22 +  b = "Npp_0.05deg_mean.ASCII2"                    
    1.23 + 
    1.24 +  t        = new((/1,nlat,nlon/),float)
    1.25 +  lon      = new((/nlon/),float)
    1.26 +  lat      = new((/nlat/),float)
    1.27 +  time     = new((/1/),integer)
    1.28 +
    1.29 +; sam result
    1.30 +; lon = fspan(-180.,179.95,nlon)
    1.31 +; lat = fspan(-90. , 89.95,nlat)
    1.32 + 
    1.33 +  do i = 0,nlon-1
    1.34 +     lon(i) = -180. + i*(360./nlon)
    1.35 +  end do
    1.36 + 
    1.37 +  do j = 0,nlat-1
    1.38 +     lat(j) =  -90. + j*(180./nlat)
    1.39 +  end do
    1.40 + 
    1.41 +  time = 1
    1.42 +
    1.43 +; print (lon)
    1.44 +; print (lat)       
    1.45 +; print (time) 
    1.46 +;=============================
    1.47 +    ;  create lat and long coordinate variables
    1.48 +    ;============================                                         
    1.49 +     lon!0          = "lon"
    1.50 +     lon@long_name  = "lon"
    1.51 +     lon@units      = "degrees-east"
    1.52 +     lon&lon        = lon
    1.53 +
    1.54 +     lat!0          = "lat"
    1.55 +     lat@long_name  = "lat"
    1.56 +     lat@units      = "degrees_north"
    1.57 +     lat&lat        = lat
    1.58 +    ;=============================
    1.59 +    ;  name dimensions of t and assign coordinate variables
    1.60 +    ;============================
    1.61 +     t!0    = "time"  
    1.62 +     t!1    = "lat"
    1.63 +     t!2    = "lon"
    1.64 +     t&time = time
    1.65 +     t&lat  = lat
    1.66 +     t&lon  = lon
    1.67 +     t@long_name = "net primary production"
    1.68 +     t@units     = "gC/m^2/year"
    1.69 +     t@_FillValue= 1.e+36         
    1.70 +     t@missing_value= 1.e+36         
    1.71 +
    1.72 +  t(0,:,:) = asciiread(b,(/nlat,nlon/),"float")
    1.73 +
    1.74 +  c->NPP  = t
    1.75 +  c->lat  = lat
    1.76 +  c->lon  = lon
    1.77 +  c->time = time
    1.78 +
    1.79 +  do i = 0,nlon-1           
    1.80 +  do j = 0,nlat-1                                                       
    1.81 +  if (t(0,j,i) .gt. 0.) then
    1.82 +     print (t(0,j,i))
    1.83 +  end if
    1.84 +  end do
    1.85 +  end do
    1.86 +end