;Reading HDF4-SDS files
;*********** Load Libraries ************************************
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" 
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" 
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" 
;**************************************************************
begin
;***************************************************************
; User Input
;***************************************************************
                                             ; INPUT
   diri    = "./"                            ; input directory
   fili    = "2A12.090515.65505.6.HDF"       ;       file

                                             ; OUTPUT
;***************************************************************
; Read hdf 
;***************************************************************

   f      = addfile (diri+fili, "r")

   lat  = f->geolocation(:,:,0)            ; (scan, pixel)
   lon  = f->geolocation(:,:,1)            

   lat@units = "degrees_north"             ; add units
   lon@units = "degrees_east"
   print(lat@hdf_name)

;-------------------------------
data=f->surfaceRain(:,:)
data@lon2d=lon
data@lat2d=lat
var_name=data@hdf_name
   printVarSummary(data)
;   print(data)                       
;-------------------------------
  ;printMinMax(lat, True)
  ;printMinMax(lon, True)
;-------------------------------
  xwks=gsn_open_wks("ps",fili+var_name)
colors =(/"white","black","white","royal blue","yellow","red"/)
gsn_define_colormap(xwks,colors)            
;
; another way of defining colors;;;;
;res@cnFillPalette = "ncl_default"
;res@vcLevelPalette = "ncl_default"
;cmap =read_colormap_file("ncl_default")
;gsn_define_colormap(xwks,"ncl_default")
;
;gsn_define_colormap(xwks,"CBR_wet") ;didn't work CBR_wet in 6.2.1 higher 
;
;gsn_define_colormap(xwks,"uniform")   ;  this worked   
;
;gsn_define_colormap(xwks,"WhBlYeRd")   ; Didn't work     
res=True
;-----------Title-----------
res@tiMainString=fili
res@gsnCenterString=var_name
;---------------------------
;Map resouces------------------
res@mpFillOn = False
;res@mpOutlineOn = True
res@mpOutlineBoundarySets = "National"
res@mpGeophysicalLineColor =  "Blue" ;Color of Conuntry Outline
res@mpGeophysicalLineThicknessF =  1.5    ;thickness of Country Outline
res@mpMinLonF=50
res@mpMaxLonF=120
res@mpMinLatF=5
res@mpMaxLatF=35
;
;-----------Contour resources----------
res@cnFillOn = True
res@cnMonoFillColor = False
res@cnLevelSelectionMode="ExplicitLevels"    ;
res@cnLevels            =(/0,1,10,30/)
;--------resources end------------------
; TEXT resources------------------------
;res@
plot=gsn_csm_contour_map_ce(xwks,data,res)
end  

