; --------------------------------------------------------------------------- ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;  Program Name: hgt_correction.ncl                                           ;
;                                                                             ;
;  National Water Model (NWM) WRF-hydro forcing engine is developed by        ;
;  National Center for Atmospheric Research (NCAR), under the sponsorship     ;
;  of National Water Center (NWC).                                            ;
;                                                                             ;
;   Team Members:                                                             ;
;     NCAR Staff: Linlin Pan, Wei Yu, and David Gochis                        ;
;      NWC/OWP Staff: Brian Cosgrove, Zhengtao Cui, Cham Pham, and James Taft ;
;                                                                             ;
;  This is a ncl program to perform height correction.                        ;
;                                                                             ;
;  Input: hgt1, hgt2, source file, output file                                ;
;                                                                             ;
;  Output: height adjusted variables                                          ;
;                                                                             ;
; For non-fatal errors output is witten to $DATA/logs                         ;
;                                                                             ;
; Author(s)/Contact(s): Linlin Pan, lpan@ucar.edu                             ;
; Origination                                                   June, 2015    ;
;                                                                             ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;----------------------------------------------------------------------

begin
           inputFile1 = getenv("inputFile1") ; GFS data
           inputFile2 = getenv("inputFile2") ; GFS data
           inputFile3 = getenv("inputFile3") ; GFS data
           outFile = getenv("outFile") ; outFile data
           
     
           f1 = addfile(inputFile1,"r") 
           f2 = addfile(inputFile2,"r") 
           f3 = addfile(inputFile3,"r") 

           fout = addfile(outFile,"w")

           HGT1 = f1->HGT
           HGT2 = f2->HGT_M(0,:,:)
           T2D  = f3->T2D
	printVarSummary(HGT1)
	printVarSummary(HGT2)
	   DHGT  = HGT1-HGT2
	   
	   T2D=T2D+DHGT*6.49/1000.
           fout->T2D = T2D
	   delete(T2D)
;

end