'open /httpd/htdocs/daten/proficharts/en/modtemps/daten/2025/01/28/basis00/modell08011_138.ctl'
'set lon 1'
'set lat 1'
'set lev 1000 300'
rc=run plotskew(TT,DD,WS,WR)
'close 1'
'quit'
function plotskew(sndtemp,snddewp,sndspd,snddir)
ClrScrn = 1
P1 = 1000
T1 = -40
P2 = 1000
T2 = 40
P3 = 200
T3 = -50
thetaint= 10
thetwint= 5
tempint = 10
wsclevs = '1 2 3 4 6 8 10 15 20 25 30 35 40'
DrawBarb= 1
DrawThet= 1
DrawThtw= 1
DrawTemp= 1
DrawMix = 1
DrawTSnd= 1
DrawDSnd= 1
DrawRH  = 0
DrawPrcl= 1
DrawPMax= 0
DrawIndx= 1
DrawHeli= 1
DrawHodo= 1
DrawPLev= 1
DrawZLev= 2
DrawZSTD= 0
LblAxes = 1
ThtwStop = 200
MixStop  = 600
SfcElev = 168.000000
Text1XC = -1
Text1YC = -1
Text2XC = -1
Text2YC = -1
Text3XC = -1
Text3YC = -1
barbint = 1
poleloc = -1
polelen = 0.35
len05   = 0.07
len10   = 0.15
len50   = 0.15
wid50   = 0.06
spac50  = 0.07
spac10  = 0.05
spac05  = 0.05
Fill50  = 1
flagbase= 1
barbline= 1
HodXcent= -1
HodYcent= -1
'set gxout stat'
'd 'sndspd
rec=sublin(result,8)
MaxWs=subwrd(rec,5)
if MaxWs<45
 HodSize = 2
 NumRing = 3
 HodRing = 15
 HodoDep = 250
 TickInt = 5
 TickSize= 0.05
else
 if MaxWs<75
  HodSize = 2
  NumRing = 3
  HodRing = 25
  HodoDep = 250
  TickInt = 5
  TickSize= 0.05
 else
  HodSize = 2
  NumRing = 3
  HodRing = 40
  HodoDep = 250
  TickInt = 10
  TickSize= 0.05
 endif
endif
Text4XC = -1
Text4YC = -1
MeanVTop= 300
MeanVBot= 850
HelicDep= 300
StormMot= 1
FillArrw= 1
ThetCol = 8
TempCol = 11
MixCol  = 6
ThtwCol = 3
TSndCol = 2
DSndCol = 4
RHCol   = 3
PrclCol = 15
BarbCol = -1
HodoCol = 1
ThetLine = 1
TempLine = 1
MixLine  = 5
ThtwLine = 3
TSndLine = 1
DSndLine = 1
RHLine   = 1
PrclLine = 1
HodoLine = 1
ThetThk = 3
TempThk = 3
MixThk  = 3
ThtwThk = 3
TSndThk = 8
DSndThk = 8
RHThk   = 8
PrclThk = 7
HodoThk = 4
BarbThk = 3
TSndMrk = 0
DSndMrk = 0
RHMrk   = 0
MrkSize = 0.1
'q dims'
rec=sublin(result,2)
_xtype=subwrd(rec,3)
_xval=subwrd(rec,9)
rec=sublin(result,3)
_yval=subwrd(rec,9)
_ytype=subwrd(rec,3)
rec=sublin(result,4)
_ptype=subwrd(rec,3)
_pmax=subwrd(rec,6)
_pmin=subwrd(rec,8)
_zmin=subwrd(rec,11)
_zmax=subwrd(rec,13)
rec=sublin(result,5)
_ttype=subwrd(rec,3)
_tval=subwrd(rec,9)
'q file'
rec=sublin(result,5)
_zmaxfile=subwrd(rec,9)
dimrc=0
If (_xtype != 'fixed')
  say 'X-Dims Error:  Not fixed.  Use 'set lon' or 'set x' to specify a value.'
  dimrc=-1
Endif
If (_ytype != 'fixed')
  say 'Y-Dims Error:  Not fixed.  Use 'set lat' or 'set y' to specify a value'
  dimrc=-1
Endif
If (_ptype != 'varying')
   say 'Z-Dims Error:  Not varying.  Use 'set lev' or 'set z' to specify a range.'
   dimrc=-1
Endif
If (_ttype != 'fixed')
  say 'Time Error:     Not fixed.  Use 'set time' or 'set t' to specify a value'
  dimrc=-1
Endif
If (dimrc < 0)
  Return(-1)
Endif
_pi=3.14159265
_dtr=_pi/180
_rtd=1/_dtr
_ktm=0.514444
_mtk=1/_ktm
_C0=0.99999683
_C1=-0.90826951/100
_C2= 0.78736169/10000
_C3=-0.61117958/1000000
_C4= 0.43884187/pow(10,8)
_C5=-0.29883885/pow(10,10)
_C6= 0.21874425/pow(10,12)
_C7=-0.17892321/pow(10,14)
_C8= 0.11112018/pow(10,16)
_C9=-0.30994571/pow(10,19)
zz=1100
while (zz > 10)
    subscr=zz/10
    _powpres.subscr=pow(zz,0.286)
    zz=zz-10
endwhile
If (ClrScrn = 1)
  'clear'
Endif
If (sndspd = -1 | snddir = -1)
  DrawBarb = 0
  DrawHodo = 0
  DrawHeli = 0
Endif
If (snddewp = -1)
  DrawDSnd = 0
  DrawRH   = 0
  DrawPrcl = 0
  DrawPMax = 0
  DrawIndx = 0
Endif
If (sndtemp = -1)
  DrawTSnd = 0
  DrawRH   = 0
  DrawPrcl = 0
  DrawPMax = 0
  DrawIndx = 0
  DrawZLev = 0
Endif
If (NumRing < 1)
  DrawHodo = 0
Endif
'q gxinfo'
rec=sublin(result,2)
xsize=subwrd(rec,4)
If (xsize = 11)
   PageType = 'Landscape'
Else
   PageType = 'Portrait'
Endif
'set x 1'
'set y 1'
'set z 1'
'set t 1'
_m1=(T1+T2-2*T3)/(2*log10(P2/P3))
_m2=(T2-T3-_m1*log10(P2/P3))/50
_m3=(T1-_m1*log10(P1))
'set z '_zmin' '_zmax
'set zlog on'
'set xlab off'
'set gxout stat'
'set x '_xval
'set y '_yval
'set t '_tval
'define tempx=('sndtemp'-'_m1'*log10(lev)-'_m3')/'_m2
'define dewpx=('snddewp'-'_m1'*log10(lev)-'_m3')/'_m2
If (PageType = 'Portrait')
   'set parea 0.7 7 0.75 10.5'
Else
   'set parea 0.7 6.5 0.5 8'
Endif
'set axlim 0 100'
'set lon 0 100'
'set grid on 1 1'

'set z '_zmin ' ' _zmax
'set lon 0 100'
'set clevs -900'
'set gxout contour'
If (DrawPLev = 0)
   'set ylab off'
Else
   'set ylab on'
   'set ylopts 1 3 0.125'
   'set xlopts 1 3 0.125'
Endif
'd lon'
'q w2xy 100 '_pmin
rxloc=subwrd(result,3)
tyloc=subwrd(result,6)
'q w2xy 0 '_pmax
lxloc=subwrd(result,3)
byloc=subwrd(result,6)
If (DrawPLev = 1 & LblAxes = 1)
   'set strsiz 0.125'
   'set string 1 c 3 0'
   If (PageType = 'Portrait')
      'draw string 0.5 10.85 hPa'
   Else
      'draw string 0.5 8.35 hPa'
   Endif
Endif
If (DrawZLev > 0)
   say 'Calculating observed height levels from temp/pressure data.'
   zz=1
   'set gxout stat'
   'set x '_xval
   'set y '_yval
   'set t '_tval
   count=0
   while (zz < _zmax)
      'set z 'zz
      pp.zz=subwrd(result,4)
      lpp.zz=log(pp.zz)
      'd 'sndtemp
      rec=sublin(result,8)
      tt=subwrd(rec,4)
      told.zz=tt+273.15
      if (tt > -900)
         tk=tt+273.15
         count=count+1
         zzm=zz-1
         if(told.zzm<-300)
           zzm=zz-2
           if(told.zzm<-300)
             zzm=zz-3
             if(told.zzm<-300)
               zzm=zz-4
               if(told.zzm<-300)
                 zzm=zz-5
               endif
             endif
           endif
         endif
         If (count = 1)
            If (DrawZLev = 2)
               htlb='ASL'
               height.zz=SfcElev
            Else
               htlb='AGL'
               height.zz=0
            Endif
            sfcz=height.zz
         Else
            DZ=29.2857*(lpp.zzm-lpp.zz)*(lpp.zz*tk+lpp.zzm*told.zzm)/(lpp.zz+lpp.zzm)
            height.zz=height.zzm+DZ
            highz=height.zz
         Endif
      else
         height.zz = -9999
         fehlwert = 1
      endif
      tkold=tk
      zz=zz+1
   endwhile
   maxht=int(highz/1000)
   if (int(sfcz/1000) = sfcz/1000)
      minht=int(sfcz/1000)
   else
      minht=1+int(sfcz/1000)
   endif
   ht=minht
   'set line 1 1 1'
   'set strsiz 0.125'
   'set string 1 l 3 0'
   while (ht <= maxht)
       zz=1
       while (height.zz/1000 <= ht)
          zz=zz+1
       endwhile
       zzm=zz-1
       if(told.zzm<-300)
         zzm=zz-2
         if(told.zzm<-300)
           zzm=zz-3
           if(told.zzm<-300)
             zzm=zz-4
             if(told.zzm<-300)
               zzm=zz-5
             endif
           endif
         endif
       endif
       PBelow=pp.zzm
       PAbove=pp.zz
       HBelow=height.zzm
       HAbove=height.zz
       DZ=HAbove-HBelow
       DP=PAbove-PBelow
       Del=ht*1000-HBelow
       Est=PBelow+Del*DP/DZ
       If (Est >= _pmin & Est <= _pmax)
          'q w2xy 1 ' Est
          yloc=subwrd(result,6)
          'draw line 6.50 ' yloc ' 6.56 ' yloc
          'draw string 6.60 'yloc-0.00' 'ht
       Endif
       ht=ht+1
   endwhile
   'set strsiz 0.125'
   'set string 1'
   If (LblAxes = 1)
      If (PageType = 'Portrait')
         'draw string 0.25 10.85 km'
         'draw string 0.25 10.75 'htlb
         'draw string 0.25 10.65 OBS'
      Else
         'draw string 6.55 8.35 km'
         'draw string 6.55 8.10 u'
         'draw string 6.675 8.10 NN'
         'draw string 6.56 8.2125 .'
         'draw string 6.60 8.2125 .'
*         'draw string 6.55 8.10 'htlb
*         'draw string 6.55 8.15 OBS'
      Endif
   Endif
Endif
If (DrawZSTD = 1)
   'set strsiz 0.10'
   minht=30.735*(1-pow(_pmax/1013.26,0.287))
   minht=int(minht+0.5)
   maxht=30.735*(1-pow(_pmin/1013.26,0.287))
   maxht=int(maxht)
   'set gxout stat'
   zcount=minht
   while (zcount <= maxht)
      plev=1013.26*pow((1-zcount/30.735),3.4843)
      'q w2xy 0 'plev
      yloc=subwrd(result,6)
      'draw string 0 'yloc-0.05' 'zcount
      zcount=zcount+1
   endwhile
   'set strsiz 0.10'
   If (LblAxes = 1)
      If (PageType = 'Portrait')
         'draw string 0 10.85 km'
         'draw string 0 10.75 ASL'
         'draw string 0 10.65 STD'
      Else
         'draw string 0 8.35 km'
         'draw string 0 8.25 ASL'
         'draw string 0 8.15 STD'
      Endif
  Endif
Endif
If (DrawTemp = 1)
   'set strsiz 0.125'
   'set z '_zmin ' ' _zmax
   'set line 'TempCol ' ' TempLine ' 'TempThk
   'set string 1 c 3 0'
   'set gxout stat'
   maxtline=GetTemp(100,_pmax)
   mintline=GetTemp(0,_pmin)
   maxtline=tempint*int(maxtline/tempint)
   mintline=tempint*int(mintline/tempint)
   tloop=mintline
   While (tloop <= maxtline)
       Botxtemp=GetXLoc(tloop,_pmax)
       'q w2xy 'Botxtemp ' ' _pmax
       Botxloc=subwrd(result,3)
       Botyloc=byloc
       Topxtemp=GetXLoc(tloop,_pmin)
        'q w2xy 'Topxtemp ' ' _pmin
       Topxloc=subwrd(result,3)
       Topyloc=tyloc
       If (Botxtemp <= 100 | Topxtemp <= 100)
          If (Topxtemp > 100)
             Slope=(Topyloc-Botyloc)/(Topxtemp-Botxtemp)
             b=Topyloc-Slope*Topxtemp
             Topyloc=Slope*100+b
             Topxloc=rxloc
          Endif
          If (Botxtemp < 0)
             Slope=(Topyloc-Botyloc)/(Topxtemp-Botxtemp)
             b=Botyloc-Slope*Botxtemp
             Botyloc=b
             Botxloc=lxloc
          Else
             'draw string ' Botxloc-0.05 ' ' Botyloc-0.15 ' ' tloop
          Endif
          'draw line 'Botxloc ' ' Botyloc ' ' Topxloc ' ' Topyloc
       Endif
       tloop=tloop+tempint
   EndWhile
   If (LblAxes = 1)
      'set strsiz 0.15'
      'set string 1 c'
      If (PageType = 'Portrait')
         'draw string 4.0 0.35 Temperature (`3.`0C)'
      Else
         'draw string 2.75 0.15 Taupunkt / '
         'draw string 4.5 0.15 Temperatur (`3.`0C)'
      Endif
   Endif
Endif
If (DrawThet = 1)
   temp=GetTemp(100,_pmin)
   maxtheta=GetThet2(temp,-100,_pmin)
   maxtheta=thetaint*int(maxtheta/thetaint)
   temp=GetTemp(0,_pmax)
   mintheta=GetThet2(temp,-100,_pmax)
   mintheta=thetaint*int(mintheta/thetaint)
   'set lon 0 100'
   'set y 1'
   'set z 1'
   tloop=mintheta
   'set line 'ThetCol' 'ThetLine ' 'ThetThk
   While (tloop <= maxtheta)
     PTemp=LiftDry(tloop,1000,_pmin,1,_pmin,_pmax)
     tloop=tloop+thetaint
   Endwhile
Endif
If (DrawMix = 1)
   If (MixStop < _pmin)
      MixStop = _pmin
   Endif
   'set string 1 l'
   'set z '_zmin ' ' _zmax
   'set cint 1'
   'set line 'MixCol' ' MixLine ' 'MixThk
   cont = 1
   mloop=subwrd(wsclevs,1)
   count = 1
   While (cont = 1)
       BotCoef=log(mloop*_pmax/3801.66)
       BotTval=-245.5*BotCoef/(BotCoef-17.67)
       Botxtemp=GetXLoc(BotTval,_pmax)
       'q w2xy 'Botxtemp ' ' _pmax
       Botxloc=subwrd(result,3)
       Botyloc=byloc
       TopCoef=log(mloop*MixStop/3801.66)
       TopTval=-245.5*TopCoef/(TopCoef-17.67)
       Topxtemp=GetXLoc(TopTval,MixStop)
       'q w2xy 'Topxtemp ' ' MixStop
       Topxloc=subwrd(result,3)
       Topyloc=subwrd(result,6)
       'set string 'MixCol' l 3'
       'set strsiz 0.09'
       If (Botxtemp <= 100 | Topxtemp <= 100)
          If (Topxtemp > 100)
             Slope=(Topyloc-Botyloc)/(Topxtemp-Botxtemp)
             b=Topyloc-Slope*Topxtemp
             Topyloc=Slope*100+b
             Topxloc=rxloc
*             'draw string ' Topxloc+0.05 ' ' Topyloc  ' ' mloop
          Else
            IF mloop<30
              'draw string ' Topxloc ' ' Topyloc+0.1 ' ' mloop
            ENDIF
          Endif
          If (Botxtemp < 0)
             Slope=(Topyloc-Botyloc)/(Topxtemp-Botxtemp)
             b=Botyloc-Slope*Botxtemp
             Botyloc=b
             Botxloc=lxloc
          Endif
          'draw line 'Botxloc ' ' Botyloc ' ' Topxloc ' ' Topyloc
       Endif
       count=count+1
       mloop=subwrd(wsclevs,count)
       If (mloop = '' | count > 50)
          cont = 0
       Endif
   EndWhile
   If (LblAxes = 1)
      'set strsiz 0.125'
      'set string 6 c 3 90'
      If (PageType = 'Portrait')
         'draw string 7.40 4.75 Mischungsverh. (g/kg)'
      Else
         'draw string 6.85 3.600 Mischungsverhaltnis (g/kg)'
         'draw string 6.74 3.705 .'
         'draw string 6.74 3.745 .'
      Endif
      'set string 1 c 3 0'
   Endif
Endif
If (DrawThtw = 1)
   'set lon 0 100'
   'set y 1'
   'set z 1'
   'set gxout stat'
   tloop=80
   'set line 'ThtwCol' 'ThtwLine ' 'ThtwThk
   While (tloop > -80)
     PTemp=LiftWet(tloop,1000,ThtwStop,1,_pmin,_pmax)
     tloop=tloop-thetwint
   Endwhile
Endif
If (DrawTSnd = 1)
   say 'Drawing temperature sounding.'
   'set gxout line'
   'set x '_xval
   'set y '_yval
   'set z '_zmin' '_zmax
   'set ccolor 'TSndCol
   'set cstyle 'TSndLine
   'set cmark 'TSndMrk
   'set digsiz 'MrkSize
   'set cthick 'TSndThk
   'set missconn on'
   'd tempx'
Endif
If (DrawDSnd = 1)
   say 'Drawing dewpoint sounding.'
   'set gxout line'
   'set x '_xval
   'set y '_yval
   'set z '_zmin' '_zmax
   'set cmark 'DSndMrk
   'set digsiz 'MrkSize
   'set ccolor 'DSndCol
   'set cstyle 'DSndLine
   'set cthick 'DSndThk
   'set missconn on'
   'd dewpx'
Endif
If (DrawTSnd = 1)
   field=sndtemp
Else
   field=sndspd
Endif
'set gxout stat'
'set x '_xval
'set y '_yval
'set t '_tval
'set lev ' _pmax ' ' _pmin
'd maskout(lev,'field'+300)'
rec=sublin(result,1)
check=substr(rec,1,6)
If (check = 'Notice')
    rec=sublin(result,9)
Else
    rec=sublin(result,8)
Endif
SfcPlev=subwrd(rec,5)
If (DrawTSnd = 1 & DrawDSnd = 1)
   'set lev 'SfcPlev
   'd 'sndtemp
   rec=sublin(result,8)
   Sfctemp=subwrd(rec,4)
   'd 'snddewp
   rec=sublin(result,8)
   Sfcdewp=subwrd(rec,4)
   SfcThee=Thetae(Sfctemp,Sfcdewp,SfcPlev)
   TLcl=Templcl(Sfctemp,Sfcdewp)
   PLcl=Preslcl(Sfctemp,Sfcdewp,SfcPlev)
Endif
If (DrawPrcl = 1)
   say 'Drawing parcel path from surface upward.'
   If (PageType = 'Portrait')
      xloc=7.15
   Else
      xloc=6.65
   Endif
   'q w2xy 1 'PLcl
   rec=sublin(result,1)
   yloc=subwrd(rec,6)
   'set strsiz 0.125'
   If (PLcl < _pmax)
      'set string 1 l'
      'draw string 'xloc+0.05' 'yloc' HKN'
      xlocHKN=xloc
      ylocHKN=yloc
      'set line 1 1 1'
      'draw line 'xloc-0.15' 'yloc' 'xloc-0.05' 'yloc
   Endif
   'set lon 0 100'
   'set gxout stat'
   'set line 'PrclCol' 'PrclLine ' ' PrclThk
   PTemp=LiftDry(Sfctemp,SfcPlev,PLcl,1,_pmin,_pmax)
   Ptemp=LiftWet(TLcl,PLcl,_pmin,1,_pmin,_pmax)
Endif
If (DrawTSnd = 1 & DrawDSnd = 1)
  'set x '_xval
  'set y '_yval
  'set t '_tval
   zz=1
   MaxThee=-9999
   'set gxout stat'
   while (zz <= _zmax & pp > _pmax-250)
       'set z 'zz
       pp=subwrd(result,4)
       'd 'sndtemp
       rec=sublin(result,8)
       tt=subwrd(rec,4)
       'd 'snddewp
       rec=sublin(result,8)
       dd=subwrd(rec,4)
       If (abs(tt) < 130 & abs(dd) < 130)
          Thee=Thetae(tt,dd,pp)
          If (Thee > MaxThee)
             MaxThee=Thee
             TMaxThee=tt
             DMaxThee=dd
             PMaxThee=pp
          Endif
       endif
       zz=zz+1
   Endwhile
   If (PMaxThee = SfcPlev-250)
      PMaxThee = SfcPlev
   Endif
   If (SfcPlev != PMaxThee)
      TLclMax=Templcl(TMaxThee,DMaxThee)
      PLclMax=Preslcl(TMaxThee,DMaxThee,PMaxThee)
   Endif
Endif
If (DrawPMax = 1 & SfcPlev != PMaxThee)
   say 'Drawing parcel path from most unstable level upward.'
   If (PageType = 'Portrait')
      xloc=7.15
   Else
      xloc=6.65
   Endif
   'q w2xy 1 'PLclMax
   rec=sublin(result,1)
   yloc=subwrd(rec,6)
   'set strsiz 0.125'
   If (PLclMax < _pmax)
      'set string 1 l'
      'draw string 'xloc+0.05' 'yloc' HKN'
      'set line 1 1 1'
      'draw line 'xloc-0.15' 'yloc' 'xloc-0.05' 'yloc
   Endif
   'set lon 0 100'
   'set gxout stat'
   'set line 'PrclCol' 'PrclLine ' ' PrclThk
   PTemp=LiftDry(TMaxThee,PMaxThee,PLclMax,1,_pmin,_pmax)
   Ptemp=LiftWet(TLclMax,PLclMax,_pmin,1,_pmin,_pmax)
Endif
If (DrawIndx = 1)
   'set string 1 l'
   'set strsiz 0.125'
   'set x '_xval
   'set y '_yval
   'set t '_tval
   say 'Calculating precipitable water.'
   pw=precipw(sndtemp,snddewp,_pmax,_pmin)
   say 'Calculating thermodynamic indices.'
   Temp850=interp(sndtemp,850)
   Temp700=interp(sndtemp,700)
   Temp500=interp(sndtemp,500)
   Dewp850=interp(snddewp,850)
   Dewp700=interp(snddewp,700)
   Dewp500=interp(snddewp,500)
   If (Temp850>-900 & Dewp850>-900 & Dewp700>-900 & Temp700>-900 & Temp500>-900)
      K=Temp850+Dewp850+Dewp700-Temp700-Temp500
   Else
      K=-9999
   Endif
   If (Temp850 > -900 & Dewp850 > -900 & Temp500 > -900)
      tt=Temp850+Dewp850-2*Temp500
   Else
      tt=-9999
   Endif
   Temp500V=virtual2(Temp500+273.15,Dewp500+273.15,500)-273.15
   PclTemp=LiftWet(TLcl,PLcl,500,0)
   PclTempV=virtual2(PclTemp+273.15,PclTemp+273.15,500)-273.15
   SLI=Temp500V-PclTempV
   rec=CAPE(TLcl,PLcl,100,sndtemp,snddewp)
   Pos=subwrd(rec,1)
   CIN=subwrd(rec,2)
   If (SfcPlev != PMaxThee)
      PclTemp=LiftWet(TLclMax,PLclMax,500,0)
      PclTempV=virtual2(PclTemp+273.15,PclTemp+273.15,500)-273.15
      LIMax=Temp500V-PclTempV
      rec=CAPE(TLclMax,PLclMax,100,sndtemp,snddewp)
      PosMax=subwrd(rec,1)
      CINMax=subwrd(rec,2)
   Else
      LIMax=SLI
      PosMax=Pos
      CINMax=CIN
      MaxThee=SfcThee
   Endif
   If (PageType = 'Portrait')
      If (Text1XC = -1)
         Text1XC=rxloc-0.75
      Endif
      If (Text1YC = -1)
         Text1YC=tyloc-2.25
      Endif
      If (Text2XC = -1)
         Text2XC=rxloc-0.75
      Endif
      If (Text2YC = -1)
         Text2YC=tyloc-3.25
      Endif
      If (Text3XC = -1)
          Text3XC=rxloc-0.75
      Endif
      If (Text3YC = -1)
         Text3YC=tyloc-4.40
      Endif
   Else
      If (Text1XC = -1)
         Text1XC=rxloc+2.50
      Endif
      If (Text1YC = -1)
         Text1YC=tyloc-2.45
      Endif
      If (Text2XC = -1)
         Text2XC=rxloc+2.50
      Endif
      If (Text2YC = -1)
         Text2YC=tyloc-3.65
      Endif
      If (Text3XC = -1)
         Text3XC=rxloc+2.50
      Endif
      If (Text3YC = -1)
         Text3YC=tyloc-5.35
      Endif
   Endif
   'set string 1 l 3'
   'set line 0 1 3'
   'draw recf  'Text1XC-1.00 ' ' Text1YC-0.60 ' ' Text1XC+1.2 ' ' Text1YC+0.25
   'set line 1 1 3'
   'draw rec  'Text1XC-1.00 ' ' Text1YC-0.60 ' ' Text1XC+1.2 ' ' Text1YC+0.25
   'draw string 'Text1XC-0.95 ' ' Text1YC+0.10'  K Index'
   'draw string 'Text1XC+0.60 ' ' Text1YC+0.10' ' int(K)
   'draw string 'Text1XC-0.95 ' ' Text1YC-0.15 '  Totals Totals'
   'draw string 'Text1XC+0.60 ' ' Text1YC-0.15 ' ' int(tt)
   'draw string 'Text1XC-0.95 ' ' Text1YC-0.40 '  PW (cm)'
   'draw string 'Text1XC+0.60 ' ' Text1YC-0.40 ' ' int(pw*100)/100
   'set line 0 1 3'
   'draw recf  'Text2XC-1.00 ' ' Text2YC-1.15 ' ' Text2XC+1.2 ' ' Text2YC+0.65
   'set line 1 1 3'
   'draw rec  'Text2XC-1.00 ' ' Text2YC-1.15 ' ' Text2XC+1.2 ' ' Text2YC+0.65
   'draw string 'Text2XC-0.35 ' ' Text2YC+0.50 ' Boden'
   'draw string 'Text2XC-0.95 ' ' Text2YC+0.25 '  Temperatur(`3.`0C)'
   'draw string 'Text2XC+0.60 ' ' Text2YC+0.25 ' ' int(Sfctemp*10)/10
   'draw string 'Text2XC-0.95 ' ' Text2YC+0.00 '  Taupunkt (`3.`0C)'
   'draw string 'Text2XC+0.60 ' ' Text2YC+0.00 ' ' int(Sfcdewp*10)/10
   'draw string 'Text2XC-0.95 ' ' Text2YC-0.25 '   `3z`0`bE`n(K)'
   'draw string 'Text2XC+0.60 ' ' Text2YC-0.25 ' ' int(SfcThee)
   'draw string 'Text2XC-0.95 ' ' Text2YC-0.50 '  Lifted Index'
   'draw string 'Text2XC+0.60 ' ' Text2YC-0.50 ' ' round(SLI)
   'draw string 'Text2XC-0.95 ' ' Text2YC-0.75 '  CAPE (J)'
   'draw string 'Text2XC+0.60 ' ' Text2YC-0.75 ' ' int(Pos)
   'draw string 'Text2XC-0.95 ' ' Text2YC-1.00 '  CIN (J)'
   'draw string 'Text2XC+0.60 ' ' Text2YC-1.00 ' ' int(CIN)
   'set line 0 1 3'
   'draw recf  'Text3XC-1.00 ' ' Text3YC-1.00 ' '  Text3XC+1.2 ' ' Text3YC+0.55
   'set line 1 1 3'
   'draw rec  'Text3XC-1.00 ' ' Text3YC-1.00 ' '  Text3XC+1.2 ' ' Text3YC+0.55
   'draw string 'Text3XC-0.725 ' ' Text3YC+0.4 ' Instabilster Wert'
   'draw string 'Text3XC-0.95 ' ' Text3YC+0.15 '  Druck (mb)'
   'draw string 'Text3XC+0.60 ' ' Text3YC+0.15 ' ' int(PMaxThee)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.10 ' `3z`0`bE`n (K)'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.10 ' ' int(MaxThee)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.35 ' Lifted Index'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.35 ' 'round(LIMax)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.60 ' CAPE (J)'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.60 ' 'int(PosMax)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.85 ' CIN (J)'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.85 ' ' int(CINMax)
Endif
If (DrawBarb = 1)
   say 'Drawing Wind Profile.'
   If (poleloc = -1)
      If (PageType = 'Portrait')
         poleloc = 8.0
      Else
         poleloc = 7.5
      Endif
   Endif
   If (barbline = 1)
      'set line 1 1 3'
      'draw line 'poleloc ' ' byloc ' ' poleloc ' ' tyloc
   Endif
   If (BarbCol = -1)
      'set rgb 20 200 0 150'
      'set rgb 41 255 0 132'
      'set rgb 42 255 0 168'
      'set rgb 43 255 0 204'
      'set rgb 44 255 0 240'
      'set rgb 45 255 0 255'
      'set rgb 46 204 0 255'
      'set rgb 47 174 0 255'
      'set rgb 48 138 0 255'
      'set rgb 49 108 0 255'
      'set rgb 50 84 0 255'
      'set rgb 51 40 0 255'
      'set rgb 52 0 0  255'
      'set rgb 53 0 42 255'
      'set rgb 54 0 84 255'
      'set rgb 55 0 120 255'
      'set rgb 56 0 150 255'
      'set rgb 57 0 192 255'
      'set rgb 58 0 240 255'
      'set rgb 59 0 255 210'
      'set rgb 60 0 255 160'
      'set rgb 61 0 255 126'
      'set rgb 62 0 255 78'
      'set rgb 63 84 255 0'
      'set rgb 64 138 255 0'
      'set rgb 65 188 255 0'
      'set rgb 66 236 255 0'
      'set rgb 67 255 255 0'
      'set rgb 68 255 222 0'
      'set rgb 69 255 192 0'
      'set rgb 70 255 162 0'
      'set rgb 71 255 138 0'
      'set rgb 72 255 108 0'
      'set rgb 73 255 84 0'
      'set rgb 74 255 54 0'
      'set rgb 75 255 12 0'
      'set rgb 76 255 0 34'
      'set rgb 77 255 0 70'
      'set rgb 78 255 0 105'
      'set rgb 79 255 0 140'
      'set rgb 80 255 0 175'
      'set rgb 81 255 0 215'
      'set rgb 82 255 0 255'
      'set rgb 83 255 255 255'
      col1='83 83 83 83 83 83 83 83 83 83 82 81 80 79 78'
      col2='77 76 75 74 73 72 71 70 69 68 67 66 65 64 63'
      col3='62 61 60 59 58 57 56 55 54 53 52 51 50 49 48'
      'set rbcols 'col1' 'col2' 'col3
   Endif
   'set z '_zmin' '_zmax
   'set gxout stat'
   zz=1
   wspd=-9999
   cont=1
   While (cont = 1 & zz < _zmax)
      'set z 'zz
      pres=subwrd(result,4)
      'd 'sndspd
      rec=sublin(result,8)
      wspd=subwrd(rec,4)
      if (wspd < 0 | pres > _pmax)
          zz=zz+1
      else
          cont=0
      Endif
   Endwhile
   While (zz <= _zmax)
      'd 'sndspd'(z='zz')'
      rec=sublin(result,8)
      wspd=subwrd(rec,4)
      If (BarbCol >= 0)
         'set line 'BarbCol ' 1 'BarbThk
      Else
         tempbcol=GetBCol(wspd)
         'set line 'tempbcol ' 1 'BarbThk
      Endif
      'd 'snddir'(z='zz')'
      rec=sublin(result,8)
      wdir=subwrd(rec,4)
      xwind=GetUWnd(wspd,wdir)
      ywind=GetVWnd(wspd,wdir)
      'query gr2xy 5 'zz
      y1=subwrd(result,6)
      if (wspd > 0)
         cc=polelen/wspd
         xendpole=poleloc-xwind*cc
         yendpole=y1-ywind*cc
      endif
      if (xendpole>0 & wspd >= 0.5)
        if (flagbase = 1)
           'draw mark 3 'poleloc ' ' y1 ' 0.05'
        endif
           'draw line ' poleloc ' ' y1 '  ' xendpole ' ' yendpole
        flagloop=wspd/10
        windcount=wspd
        flagcount=0
        xflagstart=xendpole
        yflagstart=yendpole
        dx=cos((180-wdir)*_dtr)
        dy=sin((180-wdir)*_dtr)
        while (windcount > 47.5)
           flagcount=flagcount+1
           dxflag=-len50*dx
           dyflag=-len50*dy
           xflagend=xflagstart+dxflag
           yflagend=yflagstart+dyflag
           windcount=windcount-50
           x1=xflagstart+0.5*wid50*xwind/wspd
           y1=yflagstart+0.5*wid50*ywind/wspd
           x2=xflagstart-0.5*wid50*xwind/wspd
           y2=yflagstart-0.5*wid50*ywind/wspd
           If (Fill50 = 1)
              'draw polyf 'x1' 'y1' 'x2' 'y2' 'xflagend' 'yflagend' 'x1' 'y1
           Else
              'draw line 'x1 ' 'y1 ' ' xflagend ' ' yflagend ' '
              'draw line 'x2 ' 'y2 ' ' xflagend ' ' yflagend
              'draw line 'x1 ' 'y1 ' ' x2 ' ' y2
           Endif
           xflagstart=xflagstart+spac50*xwind/wspd
           yflagstart=yflagstart+spac50*ywind/wspd
        endwhile
        while (windcount > 7.5 )
           flagcount=flagcount+1
           dxflag=-len10*dx
           dyflag=-len10*dy
           xflagend=xflagstart+dxflag
           yflagend=yflagstart+dyflag
           windcount=windcount-10
           'draw line ' xflagstart ' ' yflagstart ' ' xflagend ' ' yflagend
           xflagstart=xflagstart+spac10*xwind/wspd
           yflagstart=yflagstart+spac10*ywind/wspd
        endwhile
        if (windcount > 2.5)
           flagcount=flagcount+1
           if (flagcount = 1)
              xflagstart=xflagstart+spac05*xwind/wspd
              yflagstart=yflagstart+spac05*ywind/wspd
           endif
           dxflag=-len05*dx
           dyflag=-len05*dy
           xflagend=xflagstart+dxflag
           yflagend=yflagstart+dyflag
           windcount=windcount-5
           'draw line ' xflagstart ' ' yflagstart ' ' xflagend ' ' yflagend
        endif
      else
        if (wspd < 0.5 & wspd >= 0)
           'draw mark 2 ' poleloc ' ' y1 ' 0.08'
        endif
      endif
      zz=zz+barbint
   endwhile
Endif
If (DrawHodo = 1)
   say 'Drawing Hodograph.'
   If (HodXcent = -1 | HodYcent = -1)
      If (PageType = 'Portrait')
         HodXcent=6
         HodYcent=9.5
      Else
         HodXcent=9
         HodYcent=7.0
      Endif
   Endif
   HodL=HodXcent-HodSize/2.0
   HodR=HodXcent+HodSize/2.0
   HodT=HodYcent+HodSize/2.0
   HodB=HodYcent-HodSize/2.0
   RingSpac=HodSize/(NumRing*2)
   'set line 0'
   'draw recf 'HodL' 'HodB' 'HodR' 'HodT
   'set line 'HodoCol' 1 6'
   'draw rec 'HodL' 'HodB' 'HodR' 'HodT
   'set line 1 1 3'
   'set string 1 c'
   'draw mark 1 'HodXcent ' 'HodYcent ' ' HodSize
   i=1
   While (i <= NumRing)
     'set strsiz 0.10'
     'set string 15 c 3 45'
     uwnd=-i*HodRing*cos(45*_dtr)
     xloc=HodXcent+uwnd*RingSpac/HodRing
     yloc=HodYcent+uwnd*RingSpac/HodRing
     'set line 15'
     'draw mark 2 'HodXcent ' ' HodYcent ' ' i*HodSize/NumRing
     'draw string 'xloc ' ' yloc ' ' HodRing*i
     i=i+1
   Endwhile
   'set string 1 l 3 0'
   If (TickInt > 0)
      i=0
      while (i < HodRing*NumRing)
         dist=i*RingSpac/HodRing
         hrxloc=HodXcent+dist
         hlxloc=HodXcent-dist
         htyloc=HodYcent+dist
         hbyloc=HodYcent-dist
         'set line 1 1 3'
         'draw line 'hrxloc ' ' HodYcent-TickSize/2 ' ' hrxloc ' ' HodYcent+TickSize/2
         'draw line 'hlxloc ' ' HodYcent-TickSize/2 ' ' hlxloc ' ' HodYcent+TickSize/2
         'draw line 'HodXcent+TickSize/2 ' ' htyloc ' ' HodXcent-TickSize/2 ' ' htyloc
         'draw line 'HodXcent+TickSize/2 ' ' hbyloc ' ' HodXcent-TickSize/2 ' ' hbyloc
         i=i+TickInt
      endwhile
   Endif
   'set line 'HodoCol ' ' HodoLine ' 'HodoThk
   'draw string 'HodL+0.05 ' ' HodT-0.1 ' kt'
   zloop=_zmin
   xold=-9999
   yold=-9999
   count=0
   Depth=0
   While (zloop < _zmax & Depth < HodoDep)
      'set z 'zloop
      pres=subwrd(result,4)
      'd 'sndspd
      rec=sublin(result,8)
      wspd=subwrd(rec,4)
      'd 'snddir
      rec=sublin(result,8)
      wdir=subwrd(rec,4)
      uwnd=GetUWnd(wspd,wdir)
      vwnd=GetVWnd(wspd,wdir)
      If (wspd >= 0)
         xloc=HodXcent+uwnd*RingSpac/HodRing
         yloc=HodYcent+vwnd*RingSpac/HodRing
         If (xloc > 0 & yloc > 0 & xold > 0 & yold > 0)
            Depth=Depth+pold-pres
            count=count+1
            If (count = 1)
               'draw mark 3 'xold ' ' yold ' 0.05'
            Endif
            'draw line 'xold' 'yold' 'xloc' 'yloc
         Endif
         xold=xloc
         yold=yloc
      Endif
      zloop=zloop+1
      pold=pres
   EndWhile
   If (count > 0)
      'draw mark 3 'xold ' ' yold ' 0.05'
   Endif
Endif
If (DrawHeli = 1)
   say 'Calculating Helicity & SR Helicity.'
   delp=10
   UTotal=0
   VTotal=0
   'set lev '_pmax ' ' _pmin
   'define uwndarr='sndspd'*cos((270-'snddir')*'_dtr')'
   'define vwndarr='sndspd'*sin((270-'snddir')*'_dtr')'
   pres=MeanVBot
   While (pres >= MeanVTop)
      uwnd=interp(uwndarr,pres)*_ktm
      vwnd=interp(vwndarr,pres)*_ktm
      If (uwnd > -900 & vwnd > -900)
         UTotal=UTotal+uwnd
         VTotal=VTotal+vwnd
      Endif
      pres=pres-delp
   EndWhile
   vcount=1+(MeanVBot-MeanVTop)/delp
   Umean=UTotal/vcount
   Vmean=VTotal/vcount
   Spdmean=GetWSpd(Umean,Vmean)
   MeanDir=GetWDir(Umean,Vmean)
   If (StormMot = 1)
      If (Spdmean < 15)
         Reduct=0.25
         Rotate=30
      Else
         Reduct=0.20
         Rotate=20
      Endif
   Else
      Reduct=0.0
      Rotate=0.0
   Endif
   UReduce=(1-Reduct)*Umean
   VReduce=(1-Reduct)*Vmean
   StormSpd=GetWSpd(UReduce,VReduce)
   StormDir=GetWDir(UReduce,VReduce)+Rotate
   If (StormDir >= 360)
      StormDir=StormDir-360
   Endif
   StormU=GetUWnd(StormSpd,StormDir)
   StormV=GetVWnd(StormSpd,StormDir)
   xloc=HodXcent+_mtk*StormU*RingSpac/HodRing
   yloc=HodYcent+_mtk*StormV*RingSpac/HodRing
   'set line 1 1 4'
   'draw line 'HodXcent ' ' HodYcent ' ' xloc ' ' yloc
   Arr1U=GetUWnd(HodRing/10,StormDir+30)
   Arr1V=GetVWnd(HodRing/10,StormDir+30)
   Arr2U=GetUWnd(HodRing/10,StormDir-30)
   Arr2V=GetVWnd(HodRing/10,StormDir-30)
   xloc2=xloc-Arr1U/HodRing
   xloc3=xloc-Arr2U/HodRing
   yloc2=yloc-Arr1V/HodRing
   yloc3=yloc-Arr2V/HodRing
   'set line 1 1 3'
   If (FillArrw = 0)
      'draw line 'xloc' 'yloc' 'xloc2' 'yloc2
      'draw line 'xloc' 'yloc' 'xloc3' 'yloc3
   Else
      'draw polyf 'xloc' 'yloc' 'xloc2' 'yloc2' 'xloc3' 'yloc3' 'xloc' 'yloc
   Endif
   helic=0
   SRhelic=0
   MinP=SfcPlev-HelicDep
   pres=SfcPlev
   uwndold=-9999
   vwndold=-9999
   While (pres >= MinP)
      uwnd=interp(uwndarr,pres)*_ktm
      vwnd=interp(vwndarr,pres)*_ktm
      If (uwnd > -900 & uwndold > -900)
          du=uwnd-uwndold
          dv=vwnd-vwndold
          ubar=0.5*(uwnd+uwndold)
          vbar=0.5*(vwnd+vwndold)
          uhelic=-dv*ubar
          vhelic=du*vbar
          SRuhelic=-dv*(ubar-StormU)
          SRvhelic=du*(vbar-StormV)
          SRhelic=SRhelic+SRuhelic+SRvhelic
          helic=helic+uhelic+vhelic
      Endif
      uwndold=uwnd
      vwndold=vwnd
      pres=pres-delp
   EndWhile
   'set strsiz 0.125'
   'set string 1 l 3'
   If (PageType = 'Portrait')
      If (Text4XC = -1)
         Text4XC=rxloc-0.75
      Endif
      If (Text4YC = -1)
         Text4YC=tyloc-5.45
      Endif
   Else
      If (Text4XC = -1)
         Text4XC=rxloc+2.50
      Endif
      If (Text4YC = -1)
         Text4YC=tyloc-6.85
      Endif
   Endif
   'set line 0 1 3'
   'draw recf  'Text4XC-1.0 ' 'Text4YC-0.8 ' ' Text4XC+1.2 ' ' Text4YC+0.5
   'set line 1 1 3'
   'draw rec  'Text4XC-1.0 ' 'Text4YC-0.8 ' ' Text4XC+1.2 ' ' Text4YC+0.5
   'draw string 'Text4XC-0.525 ' ' Text4YC+0.35 ' Hodograph'
   'draw string 'Text4XC-0.95 ' ' Text4YC+0.10 ' EH'
   'draw string 'Text4XC+0.60 ' ' Text4YC+0.10 ' 'int(helic)
   'draw string 'Text4XC-0.95 ' ' Text4YC-0.15 ' SREH'
   'draw string 'Text4XC+0.60 ' ' Text4YC-0.15 ' ' int(SRhelic)
   'draw string 'Text4XC-0.95 ' ' Text4YC-0.40 ' StmDir'
   'draw string 'Text4XC+0.60 ' ' Text4YC-0.40 ' ' int(StormDir)'`3.`0'
   'draw string 'Text4XC-0.95 ' ' Text4YC-0.65 ' StmSpd (kt)'
   'draw string 'Text4XC+0.60 ' ' Text4YC-0.65 ' ' int(_mtk*StormSpd)
Endif
If (DrawRH = 1)
  'set z '_zmin' '_zmax
  'set x '_xval
  'set y '_yval
  'set t '_tval
  'set zlog on'
  'set gxout line'
  'set ccolor 'RHCol
  'set cstyle 'RHLine
  'set cmark 'RHMrk
  'set digsiz 'MrkSize
  'set missconn on'
  'set xlab on'
  'set frame off'
  'set vrange 0 350'
  'set xlpos 0 t'
  'set xlevs 25 50 75 100'
  'set grid vertical 5'
  'define rh=100*exp((17.2694*'snddewp')/('snddewp'+237.3)-(17.2694*'sndtemp')/('sndtemp'+237.3))'
  'd rh'
   If (LblAxes = 1)
     'set string 1 c 3 0'
     'set strsiz 0.125'
     If (PageType = 'Portrait')
       'draw string 1.5 10.85 RH (%)'
     Else
       'draw string 1.75 8.35 RH (%)'
     Endif
   Endif
Endif
*------------------------------------------
* Texte plotten
*------------------------------------------
 'set strsiz 0.15'
 'set string 1 l 3'
 'set font 4'
 'draw string 7.15 8.25 02.02.2025 18GMT (Basis: 00)'
 'set font 3'
 'set strsiz 0.25'
 'draw string 7.87 0.15 5'
 'set font 1'
 'set strsiz 0.13'
 'draw string 7.90 0.15 c'
 'set font 4'
 'set strsiz 0.15'
 'draw string 8.1 0.15 WeatherOnline'
 'set font 0'
 'set line 0 1 3'
 'set strsiz 0.120'
 'draw recf 4.25 6.850 6.465 7.96'
 'set line 2 1 8'
 'draw line 4.3 7.890 4.5 7.890'
 'draw string 4.6 7.890 Temperatur'
 'set line 4 1 8'
 'draw line 4.3 7.740 4.5 7.740'
 'draw string 4.6 7.740 Taupunkt'
 'set line 15 1 8'
 'draw line 4.3 7.590 4.5 7.590'
 'draw string 4.6 7.590 Aufstiegstrajektorie'
 'set line 8 1 3'
 'draw line 4.3 7.440 4.5 7.440'
 'draw string 4.6 7.440 Trockenadiabate'
 'set line 3 1 3'
 'draw line 4.3 7.290 4.5 7.290'
 'draw string 4.6 7.290 Feuchtadiabate'
 'set line 11 1 3'
 'draw line 4.3 7.140 4.5 7.140'
 'draw string 4.6 7.140 Isotherme'
 'set line 6 5 3'
 'draw line 4.3 6.990 4.5 6.990'
 'draw string 4.6 6.990 Mischungsverhaltnis'
 'draw string 5.940 7.100 .'
 'draw string 5.970 7.100 .'
 'set line 1 1 3'
 'draw line 4.25 8.0 4.25 6.900'
 'draw line 4.25 6.900 6.5 6.900'
*------------------------------------------
* Bild machen
*------------------------------------------
*------------------------------------------
* Englische Texte plotten
*------------------------------------------
 'set strsiz 0.15'
 'set string 1 l 3'
 'set font 4'
   'set string 1 l 3'
   'set line 0 1 3'
   'draw recf  2.0 0.0 6.0 0.25'
   'set font 0'
   'set string 1 c 3'
   'draw string 2.75 0.15 Dewpoint / '
   'draw string 4.5 0.15 Temperature (`3.`0C)'
   'set string 1 l 3'
   'set strsiz 0.125'
   'set line 0 1 3'
   'draw recf  6.5 8.0 7.0 8.5'
   'draw string 6.55 8.35 km'
   'draw string 6.55 8.10 ASL'
   'set strsiz 0.125'
   'set string 0 c 3 90'
    If (PageType = 'Portrait')
      'draw string 7.40 4.75 Mischungsverh. (g/kg)'
    Else
      'draw string 6.85 3.600 Mischungsverhaltnis (g/kg)'
      'draw string 6.74 3.705 .'
      'draw string 6.74 3.745 .'
    Endif
   'set string 1 c 3 90'
    If (PageType = 'Portrait')
      'draw string 7.40 4.75 Mixing Ratio (g/kg)'
    Else
      'draw string 6.85 3.600 Mixing Ratio (g/kg)'
    Endif
   'set string 1 c 3 0'
   'set string 0 l 3'
   'draw string 'xlocHKN+0.05' 'ylocHKN' HKN'
   'set string 1 l 3'
   'draw string 'xlocHKN+0.05' 'ylocHKN' LCL'
   'set string 0 l 3'
   'set line 0 1 3'
   'draw recf  'Text1XC-1.00 ' ' Text1YC-0.60 ' ' Text1XC+1.2 ' ' Text1YC+0.25
   'set line 1 1 3'
   'draw rec  'Text1XC-1.00 ' ' Text1YC-0.60 ' ' Text1XC+1.2 ' ' Text1YC+0.25
   'draw string 'Text1XC-0.95 ' ' Text1YC+0.10'  K Index'
   'draw string 'Text1XC+0.60 ' ' Text1YC+0.10' ' int(K)
   'draw string 'Text1XC-0.95 ' ' Text1YC-0.15 '  Totals Totals'
   'draw string 'Text1XC+0.60 ' ' Text1YC-0.15 ' ' int(tt)
   'draw string 'Text1XC-0.95 ' ' Text1YC-0.40 '  PW (cm)'
   'draw string 'Text1XC+0.60 ' ' Text1YC-0.40 ' ' int(pw*100)/100
   'set line 0 1 3'
   'draw recf  'Text2XC-1.00 ' ' Text2YC-1.15 ' ' Text2XC+1.2 ' ' Text2YC+0.65
   'set line 1 1 3'
   'draw rec  'Text2XC-1.00 ' ' Text2YC-1.15 ' ' Text2XC+1.2 ' ' Text2YC+0.65
   'draw string 'Text2XC-0.35 ' ' Text2YC+0.50 ' Boden'
   'draw string 'Text2XC-0.95 ' ' Text2YC+0.25 '  Temperatur(`3.`0C)'
   'draw string 'Text2XC+0.60 ' ' Text2YC+0.25 ' ' int(Sfctemp*10)/10
   'draw string 'Text2XC-0.95 ' ' Text2YC+0.00 '  Taupunkt (`3.`0C)'
   'draw string 'Text2XC+0.60 ' ' Text2YC+0.00 ' ' int(Sfcdewp*10)/10
   'draw string 'Text2XC-0.95 ' ' Text2YC-0.25 '   `3z`0`bE`n(K)'
   'draw string 'Text2XC+0.60 ' ' Text2YC-0.25 ' ' int(SfcThee)
   'draw string 'Text2XC-0.95 ' ' Text2YC-0.50 '  Lifted Index'
   'draw string 'Text2XC+0.60 ' ' Text2YC-0.50 ' ' round(SLI)
   'draw string 'Text2XC-0.95 ' ' Text2YC-0.75 '  CAPE (J)'
   'draw string 'Text2XC+0.60 ' ' Text2YC-0.75 ' ' int(Pos)
   'draw string 'Text2XC-0.95 ' ' Text2YC-1.00 '  CIN (J)'
   'draw string 'Text2XC+0.60 ' ' Text2YC-1.00 ' ' int(CIN)
   'set line 0 1 3'
   'draw recf  'Text3XC-1.00 ' ' Text3YC-1.00 ' '  Text3XC+1.2 ' ' Text3YC+0.55
   'set line 1 1 3'
   'draw rec  'Text3XC-1.00 ' ' Text3YC-1.00 ' '  Text3XC+1.2 ' ' Text3YC+0.55
   'draw string 'Text3XC-0.725 ' ' Text3YC+0.4 ' Instabilster Wert'
   'draw string 'Text3XC-0.95 ' ' Text3YC+0.15 '  Druck (mb)'
   'draw string 'Text3XC+0.60 ' ' Text3YC+0.15 ' ' int(PMaxThee)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.10 ' `3z`0`bE`n (K)'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.10 ' ' int(MaxThee)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.35 ' Lifted Index'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.35 ' 'round(LIMax)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.60 ' CAPE (J)'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.60 ' 'int(PosMax)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.85 ' CIN (J)'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.85 ' ' int(CINMax)
   'set string 1 l 3'
   'set line 0 1 3'
   'draw recf  'Text1XC-1.00 ' ' Text1YC-0.60 ' ' Text1XC+1.2 ' ' Text1YC+0.25
   'set line 1 1 3'
   'draw rec  'Text1XC-1.00 ' ' Text1YC-0.60 ' ' Text1XC+1.2 ' ' Text1YC+0.25
   'draw string 'Text1XC-0.95 ' ' Text1YC+0.10'  K '
   'draw string 'Text1XC+0.60 ' ' Text1YC+0.10' ' int(K)
   'draw string 'Text1XC-0.95 ' ' Text1YC-0.15 '  Totals Totals'
   'draw string 'Text1XC+0.60 ' ' Text1YC-0.15 ' ' int(tt)
   'draw string 'Text1XC-0.95 ' ' Text1YC-0.40 '  PW (cm)'
   'draw string 'Text1XC+0.60 ' ' Text1YC-0.40 ' ' int(pw*100)/100
   'set line 0 1 3'
   'draw recf  'Text2XC-1.00 ' ' Text2YC-1.15 ' ' Text2XC+1.2 ' ' Text2YC+0.65
   'set line 1 1 3'
   'draw rec  'Text2XC-1.00 ' ' Text2YC-1.15 ' ' Text2XC+1.2 ' ' Text2YC+0.65
   'draw string 'Text2XC-0.35 ' ' Text2YC+0.50 ' Surface'
   'draw string 'Text2XC-0.95 ' ' Text2YC+0.25 '  Temp (`3.`0C)'
   'draw string 'Text2XC+0.60 ' ' Text2YC+0.25 ' ' int(Sfctemp*10)/10
   'draw string 'Text2XC-0.95 ' ' Text2YC+0.00 '  Dewp (`3.`0C)'
   'draw string 'Text2XC+0.60 ' ' Text2YC+0.00 ' ' int(Sfcdewp*10)/10
   'draw string 'Text2XC-0.95 ' ' Text2YC-0.25 '   `3z`0`bE`n(K)'
   'draw string 'Text2XC+0.60 ' ' Text2YC-0.25 ' ' int(SfcThee)
   'draw string 'Text2XC-0.95 ' ' Text2YC-0.50 '  Lifted Index'
   'draw string 'Text2XC+0.60 ' ' Text2YC-0.50 ' ' round(SLI)
   'draw string 'Text2XC-0.95 ' ' Text2YC-0.75 '  CAPE (J)'
   'draw string 'Text2XC+0.60 ' ' Text2YC-0.75 ' ' int(Pos)
   'draw string 'Text2XC-0.95 ' ' Text2YC-1.00 '  CIN (J)'
   'draw string 'Text2XC+0.60 ' ' Text2YC-1.00 ' ' int(CIN)
   'set line 0 1 3'
   'draw recf  'Text3XC-1.00 ' ' Text3YC-1.00 ' '  Text3XC+1.2 ' ' Text3YC+0.55
   'set line 1 1 3'
   'draw rec  'Text3XC-1.00 ' ' Text3YC-1.00 ' '  Text3XC+1.2 ' ' Text3YC+0.55
   'draw string 'Text3XC-0.725 ' ' Text3YC+0.4 ' Most Unstable'
   'draw string 'Text3XC-0.95 ' ' Text3YC+0.15 '  Pressure (mb)'
   'draw string 'Text3XC+0.60 ' ' Text3YC+0.15 ' ' int(PMaxThee)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.10 ' `3z`0`bE`n (K)'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.10 ' ' int(MaxThee)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.35 ' Lifted Index'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.35 ' 'round(LIMax)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.60 ' CAPE (J)'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.60 ' 'int(PosMax)
   'draw string 'Text3XC-0.95 ' ' Text3YC-0.85 ' CIN (J)'
   'draw string 'Text3XC+0.60 ' ' Text3YC-0.85 ' ' int(CINMax)
 'set strsiz 0.15'
 'set string 0 l 3'
 'set font 4'
 'draw string 7.15 8.25 02.02.2025 18GMT (Basis: 00)'
 'set font 3'
 'set strsiz 0.25'
 'draw string 7.87 0.15 5'
 'set font 1'
 'set strsiz 0.13'
 'draw string 7.90 0.15 c'
 'set font 4'
 'set strsiz 0.15'
 'draw string 8.1 0.15 WeatherOnline'
 'set font 0'
 'set line 0 1 3'
 'set strsiz 0.120'
 'draw recf 4.25 6.850 6.465 7.96'
 'set line 2 1 8'
 'draw line 4.3 7.890 4.5 7.890'
 'draw string 4.6 7.890 Temperatur'
 'set line 4 1 8'
 'draw line 4.3 7.740 4.5 7.740'
 'draw string 4.6 7.740 Taupunkt'
 'set line 15 1 8'
 'draw line 4.3 7.590 4.5 7.590'
 'draw string 4.6 7.590 Aufstiegstrajektorie'
 'set line 8 1 3'
 'draw line 4.3 7.440 4.5 7.440'
 'draw string 4.6 7.440 Trockenadiabate'
 'set line 3 1 3'
 'draw line 4.3 7.290 4.5 7.290'
 'draw string 4.6 7.290 Feuchtadiabate'
 'set line 11 1 3'
 'draw line 4.3 7.140 4.5 7.140'
 'draw string 4.6 7.140 Isotherme'
 'set line 6 5 3'
 'draw line 4.3 6.990 4.5 6.990'
 'draw string 4.6 6.990 Mischungsverhaltnis'
 'draw string 5.940 7.100 .'
 'draw string 5.970 7.100 .'
 'set line 1 1 3'
 'draw line 4.25 8.0 4.25 6.900'
 'draw line 4.25 6.900 6.5 6.900'
 'set strsiz 0.15'
 'set string 1 l 3'
 'set font 4'
 "draw string 1.0 8.25  43`3.`433'N 353`3.`402'W 168m ASL"
 'draw string 7.15 8.25 02.02.2025 18GMT (Base: 00)'
 'set font 3'
 'set strsiz 0.25'
 'draw string 7.87 0.15 5'
 'set font 1'
 'set strsiz 0.13'
 'draw string 7.90 0.15 c'
 'set font 4'
 'set strsiz 0.15'
 'draw string 8.1 0.15 weatheronline.co.uk'
 'set font 0'
 'set line 0 1 3'
 'set strsiz 0.120'
 'draw recf 4.25 6.850 6.465 7.96'
 'set line 2 1 8'
 'draw line 4.3 7.890 4.5 7.890'
 'draw string 4.6 7.890 Temperature'
 'set line 4 1 8'
 'draw line 4.3 7.740 4.5 7.740'
 'draw string 4.6 7.740 Dewpoint'
 'set line 15 1 8'
 'draw line 4.3 7.590 4.5 7.590'
 'draw string 4.6 7.590 Parcel Trajectory'
 'set line 8 1 3'
 'draw line 4.3 7.440 4.5 7.440'
 'draw string 4.6 7.440 Dry Adiabat'
 'set line 3 1 3'
 'draw line 4.3 7.290 4.5 7.290'
 'draw string 4.6 7.290 Wet Adiabat'
 'set line 11 1 3'
 'draw line 4.3 7.140 4.5 7.140'
 'draw string 4.6 7.140 Isotherm'
 'set line 6 5 3'
 'draw line 4.3 6.990 4.5 6.990'
 'draw string 4.6 6.990 Mixing Ratio'
 'set line 1 1 3'
 'draw line 4.25 8.0 4.25 6.900'
 'draw line 4.25 6.900 6.5 6.900'
*------------------------------------------
* Bild machen
'printim /httpd/htdocs/daten/proficharts/en/modtemps/2025/01/28/basis00/08011_25020218_2800.gif gif x629 y486 white'
'printim /httpd/htdocs/daten/proficharts/en/modtemps/2025/01/28/basis00/08011_25020218_2_2800.gif gif x1000 y733 white'
*------------------------------------------
 'set font 0'
 'set line 0 1 3'
 'set strsiz 0.095'
 'draw recf 7.80 0.05 11.000 0.225'
 'set font 3'
 'set strsiz 0.25'
 'draw string 7.87 0.15 5'
 'set font 1'
 'set strsiz 0.13'
 'draw string 7.90 0.15 c'
 'set font 4'
 'set strsiz 0.15'
 'draw string 8.1 0.15 WeatherOnline'
*------------------------------------------
* Bild machen
*------------------------------------------
'set t '_tval
'set x '_xval
'set y '_yval
'set z '_zmin ' '_zmax
say 'Done.'
Return(0)
*************************************************************************
function Templcl(temp,dewp)
tempk=temp+273.15
dewpk=dewp+273.15
Parta=1/(dewpk-56)
Partb=log(tempk/dewpk)/800
Tlcl=1/(Parta+Partb)+56
return(Tlcl-273.15)
**************************************************************************
function Preslcl(temp,dewp,pres)
Tlclk=Templcl(temp,dewp)+273.15
tempk=temp+273.15
theta=tempk*pow(1000/pres,0.286)
plcl=1000*pow(Tlclk/theta,3.48)
return(plcl)
**************************************************************************
function LiftWet(startt,startp,endp,display,Pmin,Pmax)
temp=startt
pres=startp
cont = 1
delp=10
While (pres >= endp & cont = 1)
    If (display = 1)
       xtemp=GetXLoc(temp,pres)
       'q w2xy 'xtemp' 'pres
       xloc=subwrd(result,3)
       yloc=subwrd(result,6)
       If (xtemp < 0 | xtemp > 100)
          cont=0
       Else
          If (pres >= Pmin & pres < Pmax & pres < startp)
             'draw line 'xold' 'yold' 'xloc' 'yloc
          Endif
       Endif
    Endif
    xold=xloc
    yold=yloc
    temp=temp-100*delp*gammaw(temp,pres-delp/2,100)
    pres=pres-delp
EndWhile
return(temp)
**************************************************************************
function LiftDry(startt,startp,endp,display,Pmin,Pmax)
starttk=startt+273.15
cont = 1
delp=10
round=int(startp/10)*10
subscr=0.1*round
powstart=pow(startp,-0.286)
temp=starttk*_powpres.subscr*powstart-273.15
pres=round-10
While (pres >= endp & cont = 1)
    subscr=0.1*pres
    temp=starttk*_powpres.subscr*powstart-273.15
    If (display = 1)
       xtemp=GetXLoc(temp,pres)
       'q w2xy 'xtemp' 'pres
       xloc=subwrd(result,3)
       yloc=subwrd(result,6)
       If (xtempold > 0 & xtempold < 100 & xtemp > 0 & xtemp < 100)
          If (pres >= Pmin & pres < Pmax & pres < startp)
             'draw line 'xold' 'yold' 'xloc' 'yloc
          Endif
       Endif
    Endif
    xold=xloc
    xtempold=xtemp
    yold=yloc
    pres=pres-delp
EndWhile
return(temp)
**************************************************************************
function CAPE(startt,startp,endp,sndtemp,snddewp)
pres=startp
PclTemp=startt
PclTempV=virtual2(PclTemp+273.15,PclTemp+273.15,pres)-273.15
delp=10
Pos=0
Neg=0
Neg2=0
count=0
While (pres >= endp)
   EnvTemp=interp(sndtemp,pres)
   EnvDewp=interp(snddewp,pres)
   EnvTempV=virtual2(EnvTemp+273.15,EnvDewp+273.15,pres)-273.15
   DelT=PclTempV-EnvTempV
   If (abs(EnvTempV) < 130 & abs(PclTempV) < 130)
     count=count+1
     If (count > 1)
       Val=DelT/pres+Prev
       If (Val > 0)
          Pos=Pos+Val
          Neg2=0
       Else
          Neg=Neg+abs(Val)
          Neg2=Neg2+abs(Val)
       Endif
     Endif
     Prev=DelT/pres
   Endif
   pres=pres-delp
   PclTemp=PclTemp-100*delp*gammaw(PclTemp,pres,100)
   PclTempV=virtual2(PclTemp+273.15,PclTemp+273.15,pres)-273.15
Endwhile
Pos=0.5*Pos*287*delp
CIN=0.5*(Neg-Neg2)*287*delp
return(Pos' 'CIN)
***************************************************************************
function gammaw(tempc,pres,rh)
tempk=tempc+273.15
es=satvap2(tempc)
ws=mixratio(es,pres)
w=rh*ws/100
tempv=virtual(tempk,w)
latent=latentc(tempc)
A=1.0+latent*ws/(287*tempk)
B=1.0+0.622*latent*latent*ws/(1005*287*tempk*tempk)
Density=100*pres/(287*tempv)
lapse=(A/B)/(1005*Density)
return(lapse)
*************************************************************************
function latentc(tempc)
val=2502.2-2.43089*tempc
return(val*1000)
*************************************************************************
function precipw(sndtemp,snddewp,startp,endp)
ppold=-9999
ttold=-9999
ddold=-9999
delp=10
Int=0
mix=0
pres=startp
logpp=log(pres)
logppm=log(pres-delp)
while (pres >= endp)
   tt=interp(sndtemp,pres)
   dd=interp(snddewp,pres)
   if (tt>-900 & ttold>-900 & dd>-900 & ddold>-900)
      e=satvap2(dd)
      mix=mixratio(e,pres)
      mixavg=(logpp*mix+logppm*mixold)/(logpp+logppm)
      Int=Int+1.020408*mixavg*delp
   endif
   ttold=tt
   ddold=dd
   ppold=pp
   mixold=mix
   pres=pres-delp
   logpp=logppm
   logppm=log(pres-delp)
endwhile
return(Int)
*************************************************************************
function virtual(temp,mix)
tempv=temp*(1.0+0.6*mix)
return (tempv)
************************************************************************
function virtual2(temp,dewp,pres)
if (temp > 0 & dewp > 0)
  vap=satvap2(dewp-273.15)
  mix=mixratio(vap,pres)
  tempv=virtual(temp,mix)
else
  tempv=-9999
endif
return (tempv)
************************************************************************
function satvapor(temp)
pol=_C0+temp*(_C1+temp*(_C2+temp*(_C3+temp*(_C4+temp*(_C5+temp*(_C6+temp*(_C7+temp*(_C8+temp*(_C9)))))))))
return(6.1078/pow(pol,8))
************************************************************************
function satvap2(temp)
es=6.112*exp(17.67*temp/(temp+243.5))
return(es)
*************************************************************************
function mixratio(e,p)
mix=0.622*e/(p-e)
return(mix)
************************************************************************
function getrh(temp,dewp,pres)
tempk=temp+273.15
dewpk=dewp+273.15
es=satvap2(temp)
If (temp > 0)
   A=2.53*pow(10,9)
   B=5420
Else
   A=3.41*pow(10,10)
   B=6130
Endif
w=A*0.622*exp(-B/dewpk)/pres
ws=mixratio(es,pres)
return(100*w/ws)
************************************************************************
function interp(array,pres)
'set gxout stat'
'set lev 'pres
altpres=subwrd(result,4)
'q dims'
rec=sublin(result,4)
zlev=subwrd(rec,9)
If (zlev < 2 | zlev > _zmaxfile)
  Vest = -9999.0
Else
  If (altpres > pres)
    zlev=zlev+1
  Endif
  'set z 'zlev
  PAbove=subwrd(result,4)
  'd 'array'(lev='PAbove')'
  rec=sublin(result,8)
  VAbove=subwrd(rec,4)
  'set z 'zlev-1
  PBelow=subwrd(result,4)
  'd 'array'(lev='PBelow')'
  rec=sublin(result,8)
  VBelow=subwrd(rec,4)
  If (abs(VAbove) > 130 & zlev > 1 & zlev < _zmaxfile)
     zz=zlev
     While (abs(VAbove) > 130 & zz < _zmaxfile)
       zz=zz+1
       'set z 'zz
       PAbove=subwrd(result,4)
       'd 'array'(lev='PAbove')'
       rec=sublin(result,8)
       VAbove=subwrd(rec,4)
     EndWhile
  Endif
  If (abs(VBelow) > 130 & zlev > 1 & zlev < _zmaxfile)
      zz=zlev-1
      While (abs(VBelow) > 130 & zz > 1)
        zz=zz-1
        'set z 'zz
        PBelow=subwrd(result,4)
        'd 'array'(lev='PBelow')'
        rec=sublin(result,8)
        VBelow=subwrd(rec,4)
      EndWhile
  Endif
  If (abs(VAbove) < 130 & abs(VBelow) < 130)
    If (PBelow=PAbove)
       Vest=-9999.0
    Else
       Vest=VBelow+log(PBelow/pres)*(VAbove-VBelow)/log(PBelow/PAbove)
    Endif
  Else
     Vest=-9999.0
  Endif
Endif
Return(Vest)
****************************************************************************
function GetUWnd(wspd,wdir)
If (wspd >= 0)
   xwind=wspd*cos((270-wdir)*_dtr)
Else
   xwind = -9999.0
Endif
return(xwind)
**************************************************************************
function GetVWnd(wspd,wdir)
If (wspd >= 0)
   ywind=wspd*sin((270-wdir)*_dtr)
Else
   ywind = -9999.0
Endif
return(ywind)
*************************************************************************
function GetWSpd(xwind,ywind)
'set gxout stat'
'd mag('xwind','ywind')'
rec=sublin(result,8)
val=subwrd(rec,4)
return (val)
*************************************************************************
function GetWDir(xwind,ywind)
* Return wind direction given x and y components
'set gxout stat'
'define theta=270-'_rtd'*atan2('ywind','xwind')'
'd theta'
rec=sublin(result,8)
Dir=subwrd(rec,4)
If (Dir > 360)
   Dir=Dir-360
Endif
If (Dir < 0)
   Dir=360+Dir
Endif
return(Dir)
*************************************************************************
function GetXLoc(temp,pres)
xloc=(temp-_m1*log10(pres)-_m3)/_m2
return(xloc)
*************************************************************************
function GetTemp(xloc,pres)
tempval=_m1*log10(pres)+_m2*xloc+_m3
return(tempval)
**************************************************************************
function GetTheta(temp,pres)
theta=(temp+273.15)*pow(1000/pres,0.286)-273.15
return(theta)
*************************************************************************
function GetThet2(temp,dewp,pres)
tempk=273.15+temp
dewpk=273.15+dewp
es=satvap2(temp)
ws=mixratio(es,pres)
mix=10*getrh(temp,dewp,pres)*ws
exponent=0.2854*(1.0-0.00028*mix)
theta=(temp+273.15)*pow(1000/pres,exponent)-273.15
return(theta)
*************************************************************************
function Thetae(temp,dewp,pres)
es=satvap2(temp)
ws=mixratio(es,pres)
mix=10*getrh(temp,dewp,pres)*ws
theta=GetThet2(temp,dewp,pres)+273.15
TLcl=Templcl(temp,dewp)+273.15
thetae=theta*exp((3.376/TLcl-0.00254)*mix*(1.0+0.00081*mix))
return(thetae)
**************************************************************************
function int(i0)
  i=0
  while(i<12)
    i=i+1
    if(substr(i0,i,1)='.')
      i0=substr(i0,1,i-1)
      break
    endif
  endwhile
return(i0)
*************************************************************************
function abs(i)
  if (i < 0)
     absval=-i
  else
     absval=i
  endif
return(absval)
*************************************************************************
function log(i)
'set gxout stat'
'd log('i')'
rec=sublin(result,8)
val=subwrd(rec,4)
return(val)
*************************************************************************
function log10(i)
'set gxout stat'
'd log10('i')'
rec=sublin(result,8)
val=subwrd(rec,4)
return(val)
*************************************************************************
function pow(i,j)
'set gxout stat'
'd pow('i','j')'
rec=sublin(result,8)
val=subwrd(rec,4)
return(val)
************************************************************************
function cos(i)
'set gxout stat'
'd cos('i')'
rec=sublin(result,8)
val=subwrd(rec,4)
return(val)
************************************************************************
function sin(i)
'set gxout stat'
'd sin('i')'
rec=sublin(result,8)
val=subwrd(rec,4)
return(val)
************************************************************************
function exp(i)
'set gxout stat'
'd exp('i')'
rec=sublin(result,8)
val=subwrd(rec,4)
return(val)
***********************************************************************
function round(i)
rr=abs(1.0*i)
rr=int(rr+0.5)
if (i < 0)
   rr=-1*rr
endif
return(rr)
************************************************************************
function GetBCol(i)
if (i < 7.5)
 val = 7
else
 if (i < 12.5)
  val = 10
 else
  if (i < 17.5)
   val = 3
  else
   if (i < 22.5)
    val = 13
   else
    if (i < 27.5)
     val = 5
    else
     if (i < 32.5)
      val = 11
     else
      if (i < 37.5)
       val = 4
      else
       if (i < 42.5)
        val = 14
       else
        if (i < 47.5)
         val = 9
        else
         if (i < 52.5)
          val = 20
         else
          if (i < 57.5)
           val = 6
          else
           val = 2
          endif
         endif
        endif
       endif
      endif
     endif
    endif
   endif
  endif
 endif
endif
return(val)
************************************************************************
