routine READ.DATA
   define PORT, BERTH.NO as integer variables


   open 1 for input, name is "pacship.dat"
   use 1 for input

     '' first read in the title window and the shoreline
   call READ.WINDOW
   call READ.WINDOW

   .SKIP.TEXT
   read INIT.X1, INIT.Y1, INIT.X2, INIT.Y2

   .SKIP.TEXT
   read NO.OF.PORTS
   create every PORT(NO.OF.PORTS)

     '' read in all ports
   for PORT = 1 to NO.OF.PORTS,
   do
      .SKIP.TEXT
      read PORT.X.LOCATION(PORT), PORT.Y.LOCATION(PORT)
      read PORT.NAME(PORT) as T *

      .SKIP.TEXT
      read PORT.X.ENTRANCE(PORT), PORT.Y.ENTRANCE(PORT)

      .SKIP.TEXT
      read PORT.LOADING.TIME(PORT)

      call READ.WINDOW

      .SKIP.TEXT
      read PORT.NO.OF.BERTHS(PORT)

      for BERTH.NO = 1 TO PORT.NO.OF.BERTHS(PORT),
      do
         create a BERTH
         let BERTH.PORT(BERTH) = PORT
         file this BERTH in PORT.BERTH.SET(PORT)

         .SKIP.TEXT
         read BERTH.X.LOCATION(BERTH), BERTH.Y.LOCATION(BERTH)
      loop

   loop

   close 1

   call DISPLAY.INITIAL.DIALOG

   return

end   ''READ.DATA

routine READ.WINDOW
   define BACKGROUND.ICON as a pointer variable
   define NAME as a text variable
   define WIN.XLO, WIN.XHI, WIN.YLO, WIN.YHI, WIN.MAPPING as integer variables
   define WIN.TITLE as a text variable
   define WORLD.XLO, WORLD.XHI, WORLD.YLO, WORLD.YHI as real variables
   define WIN, WIN.RED, WIN.GREEN, WIN.BLUE as integer variables

   .SKIP.TEXT
   read VXFORM.V
  
   .SKIP.TEXT
   read WORLD.XLO, WORLD.XHI, WORLD.YLO, WORLD.YHI
   read WIN.XLO, WIN.XHI, WIN.YLO, WIN.YHI
   read WIN.TITLE as T *
   read WIN.MAPPING
   read WIN.RED, WIN.GREEN, WIN.BLUE
   read NAME as T *   '' name of icon to go in background

   call GCOLOR.R(0, WIN.RED, WIN.GREEN, WIN.BLUE)   '' window background color
   call OPENWINDOW.R(WIN.XLO, WIN.XHI, WIN.YLO, WIN.YHI, WIN.TITLE, 
         WIN.MAPPING) yielding WIN
   let DDVAL.A(DFIELD.F("SUBWINDOW", WIN)) = 1   '' make this a mdi subwindow
   call SETWINDOW.R(WIN)
   call SETWORLD.R(WORLD.XLO, WORLD.XHI, WORLD.YLO, WORLD.YHI)

   create an ICON called BACKGROUND.ICON
   display BACKGROUND.ICON with NAME at (WORLD.XLO, WORLD.YLO)

   let WORLDS(VXFORM.V,1) = WORLD.XLO
   let WORLDS(VXFORM.V,2) = WORLD.XHI
   let WORLDS(VXFORM.V,3) = WORLD.YLO
   let WORLDS(VXFORM.V,4) = WORLD.YHI
   
   return
end '' READ WINDOW




Routine DISPLAY.INITIAL.DIALOG

   define FIELD.ID as text variable
   define FORM.PTR as pointer variable
   define I as integer variable

   show FORM.PTR with "init.frm"
   let VXFORM.V = 2
   let FIELD.ID = accept.f( FORM.PTR, 'INITIAL.DIALOG.HANDLER')
   if FIELD.ID eq "OK"
      let NO.OF.FREIGHTERS = ddval.a(dfield.f("FREIGHTER.CNT",FORM.PTR))
      let NO.OF.TANKERS    = ddval.a(dfield.f("TANKER.CNT",FORM.PTR))
      let RUN.LENGTH       = ddval.a(dfield.f("SIMULATION.LENGTH",FORM.PTR))
      let I = ddval.a(dfield.f("TIMESCALE",FORM.PTR))
      if I < 0
         let COMPRESS.TIME = 1
      else
         let COMPRESS.TIME = 0
      endif
      let TIMESCALE = abs.f(I)*100
   endif

End ''DISPLAY.INITIAL.DIALOG





Routine INITIAL.DIALOG.HANDLER given FIELD.ID, FORM.PTR
   yielding FIELD.STATUS

   define FIELD.ID as text variable
   define FORM.PTR as pointer variable
   define FIELD.STATUS as integer variable

   define HELP as pointer variable

   select case FIELD.ID
      case "INITIALIZE"
      case "BACKGROUND"
      case "OK","CANCEL"
         let FIELD.STATUS = 1
      case "HELP"
         display HELP with "help.frm"
      default
   endselect
      
   let FORM.PTR = FORM.PTR

End ''INITIAL.DIALOG.HANDLER
