npp/02.read_binary_Npp.ncl.0
author Forrest Hoffman <forrest@climatemodeling.org>
Mon, 26 Jan 2009 22:08:20 -0500
changeset 0 0c6405ab2ff4
permissions -rw-r--r--
Initial commit of C-LAMP Diagnostics from Jeff Lee
forrest@0
     1
;************************************************
forrest@0
     2
;    Read ascii, Write nc                         
forrest@0
     3
;************************************************
forrest@0
     4
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"  
forrest@0
     5
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"  
forrest@0
     6
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"   
forrest@0
     7
;************************************************
forrest@0
     8
begin
forrest@0
     9
;---------------------------------------------------
forrest@0
    10
; final data                                    
forrest@0
    11
  c = addfile("Npp_0.05deg_mean_2.nc","c")
forrest@0
    12
  filedimdef(c,"time",-1,True) 
forrest@0
    13
       
forrest@0
    14
  nlat  = 180*20 
forrest@0
    15
  nlon  = 360*20  
forrest@0
    16
 
forrest@0
    17
;---------------------------------------------------
forrest@0
    18
; input data
forrest@0
    19
  b = "Npp_0.05deg_mean.int16"                    
forrest@0
    20
forrest@0
    21
  x        = new((/nlat*nlon/),float)   
forrest@0
    22
  t        = new((/1,nlat,nlon/),float)
forrest@0
    23
  lon      = new((/nlon/),float)
forrest@0
    24
  lat      = new((/nlat/),float)
forrest@0
    25
  time     = new((/1/),integer)
forrest@0
    26
forrest@0
    27
; sam result
forrest@0
    28
; lon = fspan(-180.,179.95,nlon)
forrest@0
    29
; lat = fspan(-90. , 89.95,nlat)
forrest@0
    30
 
forrest@0
    31
  do i = 0,nlon-1
forrest@0
    32
     lon(i) = -180. + i*(360./nlon)
forrest@0
    33
  end do
forrest@0
    34
 
forrest@0
    35
  do j = 0,nlat-1
forrest@0
    36
     lat(j) =  -90. + j*(180./nlat)
forrest@0
    37
  end do
forrest@0
    38
 
forrest@0
    39
  time = 1
forrest@0
    40
forrest@0
    41
; print (lon)
forrest@0
    42
; print (lat)       
forrest@0
    43
; print (time) 
forrest@0
    44
;=============================
forrest@0
    45
    ;  create lat and long coordinate variables
forrest@0
    46
    ;============================                                         
forrest@0
    47
     lon!0          = "lon"
forrest@0
    48
     lon@long_name  = "lon"
forrest@0
    49
     lon@units      = "degrees-east"
forrest@0
    50
     lon&lon        = lon
forrest@0
    51
forrest@0
    52
     lat!0          = "lat"
forrest@0
    53
     lat@long_name  = "lat"
forrest@0
    54
     lat@units      = "degrees_north"
forrest@0
    55
     lat&lat        = lat
forrest@0
    56
    ;=============================
forrest@0
    57
    ;  name dimensions of t and assign coordinate variables
forrest@0
    58
    ;============================
forrest@0
    59
     t!0    = "time"  
forrest@0
    60
     t!1    = "lat"
forrest@0
    61
     t!2    = "lon"
forrest@0
    62
     t&time = time
forrest@0
    63
     t&lat  = lat
forrest@0
    64
     t&lon  = lon
forrest@0
    65
     t@long_name = "net primary production"
forrest@0
    66
     t@units     = "gC/m^2/year"
forrest@0
    67
     t@_FillValue= 1.e+36         
forrest@0
    68
     t@missing_value= 1.e+36 
forrest@0
    69
        
forrest@0
    70
;  t = fbinrecread(b,0,(/nlat,nlon/),"float")
forrest@0
    71
          
forrest@0
    72
   do j = 0,nlat-1
forrest@0
    73
print (j)
forrest@0
    74
   do i = 0,nlon-1
forrest@0
    75
      nrec = j*nlon + i
forrest@0
    76
      x(nrec) = fbindirread(b,nrec,1,"float")
forrest@0
    77
   end do
forrest@0
    78
   end do
forrest@0
    79
print (lat)
forrest@0
    80
   t = onedtond(x,(/nlat,nlon/))
forrest@0
    81
forrest@0
    82
  c->NPP  = t
forrest@0
    83
  c->lat  = lat
forrest@0
    84
  c->lon  = lon
forrest@0
    85
  c->time = time
forrest@0
    86
forrest@0
    87
;  do i = 0,nlon-1           
forrest@0
    88
;  do j = 0,nlat-1                                                       
forrest@0
    89
;  if (t(0,j,i) .gt. 0.) then
forrest@0
    90
;     print (t(0,j,i))
forrest@0
    91
;  end if
forrest@0
    92
;  end do
forrest@0
    93
;  end do
forrest@0
    94
end