; WthrNantes

channel(5)

.channelcheck
  channelid(A)
  if (A ! &804F) message("Please set satellite receiver to CNN.")
  if (A ! &804F) go("channelcheck")

getframes(463)
set F to status(frames)

;cache_loaddirectory("IDEFS::Willow.$.Coding.Projects.BASIC.Teletext.!Teletext.Scripts.oldish.wtr")
;set F to 3

; turn off polling to speed it up a little
poll_nomessages()
poll_disable()

fileupdate("<Teletext$Temp>.WthrNantes")

set G to 2
.frameloop
  selectframes(463, G)

  set L to 2
  .lineloop
    find(B,"NANTES",L)

    if (B = 0) go("continue") ; no Nantes here...
      ; got Nantes
      setchar(35,5,32)        ; remove 'x/x' pagecount
      setchar(36,5,32)
      setchar(37,5,32)
      appendline(5,2)         ; the date
      filewritebyte(10)
      appendline(L,2)         ; the report line
      filewritebyte(10)

      ; work out the temperature
      add(B,15)
      readvalue(M,B,L)
      filewritestring("Temperature for Nantes : ")
      filewritevar(M,2)       ; allows "-9" to "99"
      filewritestring(", in Farenheit: ")
      set Z to M              ; Farenheit is...
      add(Z,40)               ; Celcuis plus 40
      mul(Z,Z,9)              ; multiplied by nine
      div(Z,Z,5)              ; divided by five
      sub(Z,40)               ; minus 40
      filewritevar(Z,1)
      filewritebyte(10)
      filewritebyte(10)
      go("finish") ; don't need to scan any further

    .continue
    L++
    if (L [ 24) go("lineloop")

  G++
  if (G [ F) go("frameloop")

.finish
fileclose()

; re-pollify
poll_enable

; reopen "the usual" windows
getframe(100)                 ; force it back to 'index'
showviewer()
showcontrols()
poll_now()                    ; extra poll for windowopens

; ensure file is Text, then run file (loads into !Edit (etc))
filetype("<Teletext$Temp>.WthrNantes", &FFF)
oscall("Filer_Run <Teletext$Temp>.WthrNantes")
poll_now()                    ; poll, so file has a chance to load
pushkey(&1AE)                 ; Ctrl-cursordown

; we're done
terminate()
