# -*- coding: euc-jp -*-

require "numru/ggraph"
require "numru/gphys"
include NumRu

MAX = 150
MIN = 0.0

# Case A: Newton Crater
#LON = 202.5
#LAT = -42.6776
#Offset = 13.0

# Case B: Nili Fossae
#LON = 75.0
#LAT = 20.4112
#Offset = 5.0

# Case C: Isdis Planitia
LON = 86.25
LAT = 9.27785
Offset = 5.75


# Starting time 
TimeA = 95040.0
TimeB = 94728.0
TimeC = 97056.0
TimeD = 103272.0

TimeA_s = TimeA - Offset
TimeB_s = TimeB - Offset
TimeC_s = TimeC - Offset
TimeD_s = TimeD - Offset

#############################################################################

GPH_local   = GPhys::IO.open('Height.nc', 'Height').cut('lon'=>LON, 'lat'=>LAT )
Topo        = GPhys::IO.open('sp_for_Mars_T031_MGS.nc', 'topog').cut('lon'=>LON, 'lat'=>LAT )

Ls_All = GPhys::IO.open('PlanetLonFromVE_rank000000.nc', 'PlanetLonFromVE')

lt = VArray.new(NArray.float(24).indgen!,
                {"long_name"=>"local time","unit"=>"hour"}, "lt")
lta = Axis.new.set_pos(lt)
grid = Grid.new(lta)

#DCL.swlset('ldump', true )
DCL.swlset('lwnd', false )

DCL.gropn(4)
DCL.sgpset('lcntl', false)
DCL.uzfact(0.7)

time = NArray.float(4)
time = [TimeA_s, TimeB_s, TimeC_s, TimeD_s]

for k in 0..3
for i in [0,1,2,3,4,5,6]

  t_start = time[k] + i * 360.0 - 1.0
  t_end   = t_start + 25.0

  GPH_1     = GPH_local.cut('time'=>t_start..t_end, 'sig'=>0.9997) - Topo
  GPH_2     = GPH_local.cut('time'=>t_start..t_end, 'sig'=>0.998801) - Topo
  GPH_3     = GPH_local.cut('time'=>t_start..t_end, 'sig'=>0.997005) - Topo
  GPH_4     = GPH_local.cut('time'=>t_start..t_end, 'sig'=>0.993424) - Topo
  GPH_5     = GPH_local.cut('time'=>t_start..t_end, 'sig'=>0.987484) - Topo

  Ls_val = Ls_All.cut('time'=>t_start..t_end).val.to_i
  Ls_str = Ls_val[0].to_s
  label  ='Ls='+Ls_str

  t = GPH_1.axis(0).pos
  lt = t - t_start
  lt.long_name = "local time"
  GPH_1.axis(0).set_pos(lt)
  GPH_2.axis(0).set_pos(lt)
  GPH_3.axis(0).set_pos(lt)
  GPH_4.axis(0).set_pos(lt)
  GPH_5.axis(0).set_pos(lt)


  GGraph.line( GPH_1, true, \
             'max'=>MAX, 'min'=>MIN, \
             'index'=>2, 'type'=>1, 'label'=>label )

  GGraph.line( GPH_2, false, \
             'max'=>MAX, 'min'=>MIN, \
             'index'=>2, 'type'=>2  )

  GGraph.line( GPH_3, false, \
             'max'=>MAX, 'min'=>MIN, \
             'index'=>2, 'type'=>3  )

  GGraph.line( GPH_4, false, \
             'max'=>MAX, 'min'=>MIN, \
             'index'=>2, 'type'=>4  )

  GGraph.line( GPH_5, false, \
             'max'=>MAX, 'min'=>MIN, \
             'index'=>1, 'type'=>1  )

end
end 


DCL.grcls
