function plthgf(args)

cs=subwrd(args,1)
if (cs='-h')
  say ' '
  say ' Plots the Adimensional Field of Winds and Height of the Horizontal Modes'
  say ' (Rossby, Gravity West, Grevity East, Kelvin and Mixed)'
  say ' '
  say ' Usage:'
  say ' uvh cs var ssd lld [Mmax]'
  say ' '
  say ' default: cs = br ; var = rb ; ssd = 01 ; lld = 01 ; Mmax = 126'
  say ' '
  say ' Must be runned under grads -p (portrait)'
  say ' '
  say ' args meaning:'
  say ' '
  say ' cs : br (barotropic mode) or bc baroclinic mode closest to 250 m'
  say ' var = rb (Rossby), gw (gravity west), ge (gravity east),'
  say '       kv (Kelvin) or mx (Mixed)'
  say '  ssd : two digit wave number: ssd = 01, 02, 03, 04, 05, 06'
  say '  lld : two digit meridional index: lld = -1, 00, 01, 02, 03, 04, 05, 06'
  say ' Mmax : Rhomb+1 (even), Rhomb is the zonal wave truncation (Rhomb odd number)'
  say '        is the total number of zonal waves plus the zonal mean (+1)'
  say ' '
  say ' Obs: It is not expected use ssd > 06 and lld > 06'
  say '      lld = -1 for Kelvin mode (var = kv)'
  say '      lld = 00 for Mixed mode (var = mx)'
  say ' '
  return
endif
if (cs='') ; cs='br' ; endif
if (cs!='br' & cs!='bc')
  say 'Wrong cs: 'cs' ; must be br or bc'
  return
endif
vrd=subwrd(args,2)
if (vrd='') ; vrd='rb' ; endif
if (vrd!='rb' & vrd!='gw' & vrd!='ge' & vrd!='kv' & vrd!='mx')
  say 'Wrong var: 'var' ; must be rb or gw or ge or kv or mx'
  return
endif
ssd=subwrd(args,3)
if (ssd='') ; ssd=01 ; endif
lld=subwrd(args,4)
if (lld='') ; lld=01 ; endif
Mmax=subwrd(args,5)
if (Mmax='') ; Mmax=126 ; endif
mrb=Mmax-1
if (mrb < 100)
  Rhomb='RB00'mrb
endif
if (mrb >= 100 & mrb < 1000)
  Rhomb='RB0'mrb
endif
if (mrb >= 1000)
  Rhomb='RB'mrb
endif
skp=math_int(Mmax/10)
say ' '
say ' Mmax = 'Mmax'   skp = 'skp
say ' '

rec=chkmdpt()
if (rec!=0)
  return
endif

* Getting Kmax (number of pressure levels) and csvm (reference case)
'run ../../Config/Case_Dates.gs 'MONAN' 1 'ZCAS' 'no
filecsdt='./Case_Dates.dgs'
rec=read(filecsdt)
lrec=sublin(rec,2)
Kmax=subwrd(lrec,1)
csvm=subwrd(lrec,5)
rec=close(filecsdt)

say ' '
say ' csvm = 'csvm'  Kmax = 'Kmax'  cs = 'cs'  var = 'var'  ssd = 'ssd'  lld = 'lld'  Mmax = 'Mmax
say ' '

if (cs='br')
  hh=01
  hl=00
else
  hh=08
  hl=07
endif
mmx=Mmax-1
Trunc=Rhomb'L0'Kmax
ext=Trunc'_'csvm'_h0'hh

fldgs='./dgs/uvh_'vrd'_s'ssd'_l'lld'_'ext'.dgs'
rec=read(fldgs)
lrec=sublin(rec,2)
xa=subwrd(lrec,1)
xb=subwrd(lrec,2)
ya=subwrd(lrec,3)
yb=subwrd(lrec,4)
say ' xa = 'xa'  xb = 'xb'  ya = 'ya'  yb = 'yb
ym=0.5*(ya+yb)
rec=read(fldgs)
lrec=sublin(rec,2)
eps=subwrd(lrec,1)
say ' eps = 'eps
zwn=subwrd(lrec,2)
mind=subwrd(lrec,3)
freq=subwrd(lrec,4)
hn=subwrd(lrec,5)
say ' hn = 'hn
rec=close(fldgs)
say ' '

fcg='dir.cfg'
rec=read(fcg)
lrec=sublin(rec,2)
diri=subwrd(lrec,1)
rec=close(fcg)

refname=vrd'_s'ssd'_l'lld'_'ext
filei=refname'.ctl'
say ' '
say ' filei = 'filei
say ' '

'reinit'

dfilei=diri''filei
rec=chkopfl(dfilei)
if (rec!=0)
  return
endif

'open 'dfilei

if (vrd=rb)
  mode='ROSSBY'
  if (zwn=1 & mind=1)
    if (cs='br') 
      wdsc=1.25
      clvs='-0.5 -0.4 -0.3 -0.2 -0.1 -0.05 0 0.05 0.1 0.2 0.3 0.4 0.5'
    endif
    if (cs='bc') 
      wdsc=1.25
      clvs='-0.8 -0.6 -0.4 -0.2 -0.1 -0.05 -0.02 0 0.02 0.05 0.1 0.2 0.4 0.6 0.8'
    endif
  endif
  if (zwn=1 & mind=6)
    if (cs='br') 
      wdsc=2.5
      clvs='-0.5 -0.4 -0.3 -0.2 -0.1 -0.05 -0.02 -0.01 0 0.01 0.02 0.05 0.1 0.2 0.3 0.4 0.5'
    endif
    if (cs='bc') 
      wdsc=1.25
      clvs='-1.0 -0.8 -0.6 -0.4 -0.2 -0.1 -0.05 -0.02 -0.01 0 0.01 0.02 0.05 0.1 0.2 0.4 0.6 0.8 1.0'
    endif
  endif
  if (zwn=6 & mind=1)
    if (cs='br') 
      wdsc=1.75
      clvs='-0.15 -0.1 -0.05 -0.02 -0.01 0 0.01 0.02 0.05 0.1 0.15'
    endif
    if (cs='bc') 
      wdsc=1.75
      clvs='-0.6 -0.4 -0.2 -0.1 -0.05 -0.02 -0.01 0 0.01 0.02 0.05 0.1 0.2 0.4 0.6'
    endif
  endif
  if (zwn=6 & mind=6)
    if (cs='br') 
      wdsc=2.0
      clvs='-0.2 -0.15 -0.1 -0.05 -0.02 -0.01 0 0.01 0.02 0.05 0.1 0.15 0.2'
     endif
    if (cs='bc') 
      wdsc=1.5
      clvs='-0.8 -0.6 -0.4 -0.2 -0.1 -0.05 -0.02 0 0.02 0.05 0.1 0.2 0.4 0.6 0.8'
     endif
 endif
endif
if (vrd=mx)
mode='MIXED'
  if (zwn=1 & mind=0)
    if (cs='br')
      wdsc=1.5
      clvs='-0.3 -0.2 -0.1 -0.06 -0.04 -0.02 0 0.02 0.04 0.06 0.1 0.2 0.3'
    endif
    if (cs='bc') 
      wdsc=1.5
      clvs='-0.6 -0.5 -0.4 -0.3 -0.2 -0.1 -0.04 -0.02 0 0.02 0.04 0.1 0.2 0.3 0.4 0.5 0.6'
    endif
  endif
  if (zwn=6 & mind=0)
    if (cs='br')
      wdsc=1.5
      clvs='-0.1 -0.08 -0.06 -0.04 -0.02 -0.01 0 0.01 0.02 0.04 0.06 0.08 0.1'
    endif
    if (cs='bc')
      wdsc=1.5
      clvs='-0.4 -0.3 -0.2 -0.1 -0.05 -0.02 -0.01 -0.001 0 0.001 0.01 0.02 0.05 0.1 0.2 0.3 0.4'
    endif
  endif
endif
if (vrd=kv)
  mode='KELVIN'
  if (zwn=1 & mind=-1)
    if (cs='br')
      wdsc=1.5
      clvs='-0.7 -0.6 -0.4 -0.2 -0.1 -0.05 -0.02 0 0.02 0.05 0.1 0.2 0.4 0.6 0.7'
    endif
    if (cs='bc')
      wdsc=1.5
      clvs='-1.0 -0.8 -0.6 -0.4 -0.2 -0.1 -0.05 -0.02 0 0.02 0.05 0.1 0.2 0.4 0.6 0.8 1.0'
    endif
  endif
  if (zwn=6 & mind=-1)
    if (cs='br')
      wdsc=1.25
      clvs='-0.8 -0.6 -0.4 -0.2 -0.1 -0.05 -0.02 -0.005 0 0.005 0.02 0.05 0.1 0.2 0.4 0.6 0.8'
    endif
    if (cs='bc')
      wdsc=1.75
      clvs='-1.0 -0.8 -0.6 -0.4 -0.2 -0.1 -0.05 -0.02 -0.005 0 0.005 0.02 0.05 0.1 0.2 0.4 0.6 0.8 1.0'
    endif
  endif
endif
if (vrd=ge)
mode='GRAV EAST'
  if (zwn=1 & mind=1)
    if (cs='br')
      wdsc=1.5
      clvs='-0.5 -0.4 -0.2 -0.1 -0.05 0 0.05 0.1 0.2 0.4 0.6'
    endif
    if (cs='bc')
      wdsc=1.75
      clvs='-0.8 -0.6 -0.4 -0.2 -0.1 -0.05 0 0.05 0.1 0.2 0.4 0.6 0.8'
    endif
  endif
  if (zwn=6 & mind=1)
    if (cs='br')
      wdsc=1.25
      clvs='-0.6 -0.4 -0.2 -0.1 -0.04 -0.02 -0.004 0 0.004 0.02 0.04 0.1 0.2 0.4 0.6 0.7'
    endif
    if (cs='bc')
      wdsc=1.5
      clvs='-0.8 -0.6 -0.4 -0.2 -0.1 -0.04 -0.02 -0.004 0 0.004 0.02 0.04 0.1 0.2 0.4 0.6 0.8'
    endif
  endif
endif
if (vrd=gw)
    mode='GRAV WEST'
  if (zwn=1 & mind=1)
    if (cs='br')
      wdsc=1.5
      clvs='-0.5 -0.4 -0.2 -0.1 -0.06 -0.04 -0.03 -0.02 0 0.02 0.03 0.04 0.06 0.1 0.2 0.4 0.5'
    endif
    if (cs='bc')
      wdsc=1.5
      clvs='-0.9 -0.7 -0.5 -0.3 -0.2 -0.1 -0.05 -0.02 0 0.02 0.05 0.1 0.2 0.3 0.5 0.7 0.9'
    endif
  endif
  if (zwn=6 & mind=1)
    if (cs='br')
      wdsc=1.5
      clvs='-0.8 -0.6 -0.4 -0.2 -0.1 -0.05 -0.02 -0.004 -0.001 0 0.001 0.004 0.02 0.05 0.1 0.2 0.4 0.6 0.8'
    endif
    if (cs='bc')
      wdsc=1.5
      clvs='-1.0 -0.8 -0.6 -0.4 -0.15 -0.04 -0.015 -0.004 -0.001 0 0.001 0.004 0.015 0.04 0.15 0.4 0.6 0.8 1.0'
    endif
  endif
endif

'set display grey white'
'clear'
'set grads off'
'set mproj off'
'set lon 0 360'
'set parea 'xa' 'xb' 'ya' 'yb
'set xlopts 1 8 0.15'
'set ylopts 1 8 0.15'
'set clopts 1 8 0.12'
'set xlint 30'
'set ylint 15'
'set gxout contour'
'set cthick 8'
'set clevs 'clvs
'display h'
say ' '
say result
'set gxout vector'
'set arrowhead -0.25'
len=0.5
scale=wdsc
xrit=xb
ybot=ya-0.6
'set arrscl 'len' 'scale
'set arrlab off'
'set cthick 8'
*'display skip(u,10,10);v'
'display skip(u,'skp','skp');v'
'draw title `1Wind and Geopotential Height 'mode' 'csvm':\`2E'hl'`1='eps'  `2H'hl'`1='hn'm  `2s`1='zwn'  `2l`1='mind'  `3w`1='freq
'draw xlab `2s`1 * LONGITUDE'
'set strsiz 0.2'
'set string 1 tc 6 90'
'draw string 0.1 'ym' `1LATITUDE'
xs=xa
ys=ybot+0.03
xrb=xs+1.65
yrb=ys+0.27
xra=xs-0.05
yra=yrb-0.37
'set line 0 1 6'
'draw recf 'xra' 'yra' 'xrb' 'yrb
'set line 1 1 6'
'draw rec 'xra' 'yra' 'xrb' 'yrb
'set strsiz 0.2'
'set strsiz 0.16'
'set string 1 bl 6 0'
'draw string 'xs' 'ys' `1'Trunc
rc = arrow(xrit-0.25,ybot+0.2,len,scale)

fig='../png_ERA_5/'refname'.png'
say ' 'fig
say ' '
'printim 'fig' png white'

return

function arrow(x,y,len,scale)

'set line 1 1 8'
'draw line 'x-len/2.' 'y' 'x+len/2.' 'y
'draw line 'x+len/2.-0.05' 'y+0.03' 'x+len/2.' 'y
'draw line 'x+len/2.-0.05' 'y-0.03' 'x+len/2.' 'y
'set string 1 c 8 0'
'set strsiz 0.13'
'draw string 'x' 'y-0.13' 'scale

return

function chkmdpt()
'query gxinfo'
lm=sublin(result,2)
xb=subwrd(lm,4)
yb=subwrd(lm,6)
rec=0
if (yb < xb)
  say ' '
  say ' Error: must use grads -p (portrait)'
  say ' '
  rec=1
endif
return rec

function chkopfl(file)
res=read(file)
rec=sublin(res,1)
if (rec=0)
   lrec=sublin(res,2)
   dst=subwrd(lrec,1)
   if (dst!='dset') ; rec=1 ; endif
endif
if (rec!=0)
  say ' '
  say ' Error : 'file' does not exist or is not a ctl file'
  say ' '
endif
if (rec=0)
  res=close(file)
endif
return rec
