npp/02.read.ascii.ncl.x
changeset 1 4be95183fbcd
equal deleted inserted replaced
-1:000000000000 0:ea4ddfc79104
       
     1 ;************************************************
       
     2 ;    Read ascii, Write nc                         
       
     3 ;************************************************
       
     4 ;load "/fs/cgd/data0/shea/nclGSUN/gsn_code.ncl"   
       
     5 ;load "/fs/cgd/data0/shea/nclGSUN/gsn_csm.ncl"    
       
     6 ;load "/fs/cgd/data0/shea/nclGSUN/shea_util.ncl"  
       
     7 ;************************************************
       
     8 begin
       
     9 ;---------------------------------------------------
       
    10 ; final data                                    
       
    11   c = addfile("Npp_0.05deg_mean4.nc","c")
       
    12   filedimdef(c,"time",-1,True) 
       
    13        
       
    14   nlat  = 180*20 
       
    15   nlon  = 360*20  
       
    16  
       
    17 ;---------------------------------------------------
       
    18 ; input data
       
    19   b = "Npp_0.05deg_mean.ASCII2"                    
       
    20  
       
    21   t        = new((/1,nlat,nlon/),float)
       
    22   lon      = new((/nlon/),float)
       
    23   lat      = new((/nlat/),float)
       
    24   time     = new((/1/),integer)
       
    25 
       
    26 ; sam result
       
    27 ; lon = fspan(-180.,179.95,nlon)
       
    28 ; lat = fspan(-90. , 89.95,nlat)
       
    29  
       
    30   do i = 0,nlon-1
       
    31      lon(i) = -180. + i*(360./nlon)
       
    32   end do
       
    33  
       
    34   do j = 0,nlat-1
       
    35      lat(j) =  -90. + j*(180./nlat)
       
    36   end do
       
    37  
       
    38   time = 1
       
    39 
       
    40 ; print (lon)
       
    41 ; print (lat)       
       
    42 ; print (time) 
       
    43 ;=============================
       
    44     ;  create lat and long coordinate variables
       
    45     ;============================                                         
       
    46      lon!0          = "lon"
       
    47      lon@long_name  = "lon"
       
    48      lon@units      = "degrees-east"
       
    49      lon&lon        = lon
       
    50 
       
    51      lat!0          = "lat"
       
    52      lat@long_name  = "lat"
       
    53      lat@units      = "degrees_north"
       
    54      lat&lat        = lat
       
    55     ;=============================
       
    56     ;  name dimensions of t and assign coordinate variables
       
    57     ;============================
       
    58      t!0    = "time"  
       
    59      t!1    = "lat"
       
    60      t!2    = "lon"
       
    61      t&time = time
       
    62      t&lat  = lat
       
    63      t&lon  = lon
       
    64      t@long_name = "net primary production"
       
    65      t@units     = "gC/m^2/year"
       
    66      t@_FillValue= 1.e+36         
       
    67      t@missing_value= 1.e+36         
       
    68 
       
    69   t(0,:,:) = asciiread(b,(/nlat,nlon/),"float")
       
    70 
       
    71   c->NPP  = t
       
    72   c->lat  = lat
       
    73   c->lon  = lon
       
    74   c->time = time
       
    75 
       
    76   do i = 0,nlon-1           
       
    77   do j = 0,nlat-1                                                       
       
    78   if (t(0,j,i) .gt. 0.) then
       
    79      print (t(0,j,i))
       
    80   end if
       
    81   end do
       
    82   end do
       
    83 end