1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ameriflux/07.missing_year.ncl Mon Jan 26 22:08:20 2009 -0500
1.3 @@ -0,0 +1,63 @@
1.4 +;************************************************************
1.5 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
1.6 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
1.7 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
1.8 +;************************************************************
1.9 +
1.10 +begin
1.11 +
1.12 + year_new = 2000
1.13 + file_input = "1999_L4_m.nc"
1.14 + file_output = year_new+"_L4_m.nc"
1.15 +
1.16 + a = addfile(file_input,"r")
1.17 + b = addfile(file_output,"c")
1.18 +;-------------------------------------------------------------------
1.19 +; Enter predefine phase.
1.20 +
1.21 +; Write global attributes to file. It's okay to do this before
1.22 +; predefining the file's variables. We are still in "define" mode.
1.23 +
1.24 + fAtt = True
1.25 + fAtt@description = "Data read in from " + file_input
1.26 + fAtt@creation_date = systemfunc ("date")
1.27 + fileattdef( b, fAtt )
1.28 +
1.29 + filedimdef( b,"year",-1,True)
1.30 +;-------------------------------------------------------------------
1.31 + month_of_year = (/1,2,3,4,5,6,7,8,9,10,11,12/)
1.32 +
1.33 + Var = getfilevarnames(a)
1.34 + nVar= dimsizes(Var)
1.35 +
1.36 +; do n = 0,nVar-1
1.37 +; print( (/Var(n)/))
1.38 +; end do
1.39 +
1.40 + do n = 0,nVar-1
1.41 +
1.42 + if (Var(n).ne."year" .and. Var(n).ne."Month" .and. Var(n).ne."n_days" .and. Var(n).ne."lat" .and. Var(n).ne."lon" ) then
1.43 +
1.44 + temp = a->$Var(n)$
1.45 + temp(0,:) = -999.
1.46 + b->$Var(n)$ = temp
1.47 + else
1.48 +
1.49 + if (Var(n).eq."year") then
1.50 + b->$Var(n)$ = year_new
1.51 + end if
1.52 +
1.53 + if (Var(n).eq."Month") then
1.54 + Month = a->$Var(n)$
1.55 + Month(0,:)= month_of_year + year_new * 100
1.56 + b->$Var(n)$ = Month
1.57 + end if
1.58 +
1.59 + if (Var(n).eq."n_days" .or. Var(n).eq."lat" .or. Var(n).eq."lon") then
1.60 + b->$Var(n)$ = a->$Var(n)$
1.61 + end if
1.62 +
1.63 + end if
1.64 + end do
1.65 +
1.66 +end