static gint colsb_left[NUMBER_OF_CONTESTS] = {
        [DX]=55, [WPX]=55, [FD]=55, [WAE]=54, [NYQP]=54, [WW]=57, [SS]=54,
        [A160]=54, [TEN]=54, [WAA]=55};
static gint itime_off = 0;
static void rate_box(GtkWidget *widget, gint idraw);
static void keyer_box(GtkWidget *widget, gint idraw);
static void zone_box(GtkWidget *widget, gint idraw);
static void summary_box(GtkWidget *widget, gint idraw);
static void traffic_lights(GtkWidget *widget);
static void beam_heading(GtkWidget *widget, guint istate);
static gint vertical_switch_position(gint ibearing);
static gdouble fact(gint num);
static gdouble ci(gdouble x);

static void rate_box(GtkWidget *widget, gint idraw)
{
  GdkRectangle update_rect;
  gchar rate_hold[7];
  gchar rate_calls[2][4], rate_labels[3][16], rate_lines[5][12];
  gint i, j, col2, dt_qso, dt_off, issc9, q0, q1, cadd, last_calls[3];
  gdouble rate;
  gint row1=4, col1=1, row2=8, mtx=FALSE, nqs=0;

  col2 = colsb_left[isel_contest]-2;
  if(isel_contest==WW)
   col2 -= 14;
  if(fp_keyer && mode==CW)
   col2 -= 10;
  update_rect.x = col1*wcol;
  update_rect.y = row1*hrow;
  update_rect.width = (col2-col1-1)*wcol;
  update_rect.height = (row2-row1-1)*hrow;
  if(idraw) 
   draw_box (row1, col1, row2, col2, 2, LT_GRAY, BLACK,
             "Rate", WHITE, "", LT_GRAY, SAVEPIX);
  draw_rectangle (&update_rect, RED, SAVEPIX);
  issc9 = 60*atoi(set_screen_choices[9]);
  for(i=4; i<7; i++)
   if(!strcmp(category_bracket[i], init_screen_choices[11]))
    {
     mtx = TRUE;
     strcpy(rate_lines[3], "(N/A)");
     strcpy(rate_lines[4], "(N/A)");
     break;
    }
  for(i=0; i<2; i++)
   {
    strcpy(rate_calls[i], set_screen_choices[i+7]);
    left_blank_pad (rate_calls[i], sizeof(rate_calls[i]));
    strcpy(rate_labels[i], "Last ");
    strcat(rate_labels[i], rate_calls[i]);
   }
  strcpy(rate_labels[2], "Overall");
  for(i=0; i<2; i++)
   last_calls[i] = atoi(rate_calls[i]);
  last_calls[2] = icall_count-1;
  for(i=0; i<3; i++)
   {
    if(icall_count>5 && icall_count>last_calls[i])
     {
      dt_off = 0;
      for(j=icall_count; j>icall_count-last_calls[i]; j--)
       {
        dt_qso = idelta_time (cr_array[j-1].date,
                              cr_array[j].date,
                              cr_array[j-1].time,
                              cr_array[j].time);
        if(dt_qso>issc9)
         dt_off += dt_qso;
       }
      if(i==2)
       itime_off = dt_off/60;
      dt_qso = idelta_time (cr_array[icall_count-last_calls[i]].date,
                            cr_array[icall_count].date,
                            cr_array[icall_count-last_calls[i]].time,
                            cr_array[icall_count].time);
      rate = ((gdouble) (last_calls[i]*3600))/
              ((gdouble) (dt_qso-dt_off));
      real_to_char (rate, rate_hold, 1);
      left_blank_pad (rate_hold, sizeof(rate_hold));
      strcpy(rate_lines[i], rate_hold);
     }
    else
     strcpy(rate_lines[i], "     N/A");
   }
  if(mtx && icall_count>5)
   {
    dt_off = 0;
    for(j=icall_count; j>0; j--)
     {
      if(cr_array[j].mode==mode && cr_array[j].iband==iband)
       {
        if(nqs)
         {
          dt_qso = idelta_time (cr_array[j].date,
                                cr_array[q1].date,
                                cr_array[j].time,
                                cr_array[q1].time);
          if(dt_qso>issc9)
           dt_off += dt_qso;
          q1 = j;
         }
        else
         {
          q0 = j;
          q1 = j;
         }
        nqs++;
        if(nqs==last_calls[0]+1)
         {
          dt_qso = idelta_time (cr_array[j].date,
                                cr_array[q0].date,
                                cr_array[j].time,
                                cr_array[q0].time);
          if(dt_qso==dt_off)
           break;
          rate = ((gdouble) (last_calls[0]*3600))/
                  ((gdouble) (dt_qso-dt_off));
          real_to_char (rate, rate_hold, 1);
          strcpy(rate_lines[3], "(");
          strcat(rate_lines[3], rate_hold);
          strcat(rate_lines[3], ")");
          if(nqs==last_calls[1]+1)
           strcpy(rate_lines[4], rate_lines[3]);
          else if(nqs>last_calls[1]+1)
           break;
         }
        else if(nqs==last_calls[1]+1)
         {
          dt_qso = idelta_time (cr_array[j].date,
                                cr_array[q0].date,
                                cr_array[j].time,
                                cr_array[q0].time);
          if(dt_qso==dt_off)
           break;
          rate = ((gdouble) (last_calls[1]*3600))/
                  ((gdouble) (dt_qso-dt_off));
          real_to_char (rate, rate_hold, 1);
          strcpy(rate_lines[4], "(");
          strcat(rate_lines[4], rate_hold);
          strcat(rate_lines[4], ")");
          if(nqs==last_calls[0]+1)
           strcpy(rate_lines[3], rate_lines[4]);
          else if(nqs>last_calls[0]+1)
           break;
         }
       }
     }
   }
  if(mtx && isel_contest==WW && mode==CW)
   cadd = 10;
  else
   {
    cadd = 17;
    for(i=0; i<2; i++)
     strcat(rate_labels[i], " Calls");
    strcat(rate_labels[2], " Contest");
   }
  for(i=0; i<3; i++)
   {
    if(kb_index (rate_lines[i], "N/A")<0)
     {
      if(cadd==17)
       strcat(rate_lines[i], "/hour");
      else
       strcat(rate_lines[i], "/hr");
     }
    write_line (row1+i, col1+1, rate_labels[i], WHITE, SAVEPIX);
    write_line (row1+i, col1+cadd, rate_lines[i], WHITE, SAVEPIX);
   }
  if(mtx)
   {
    if(cadd==17)
     cadd += 12;
    else
     cadd += 10;
    write_line (row1, col1+cadd, rate_lines[3], WHITE, SAVEPIX);
    write_line (row1+1, col1+cadd, rate_lines[4], WHITE, SAVEPIX);
   }
  gtk_widget_queue_draw_area (widget,
                              update_rect.x-idraw*wcol,
                              update_rect.y-idraw*hrow,
                              update_rect.width+idraw*2*wcol,
                              update_rect.height+idraw*2*hrow);
}

static void keyer_box(GtkWidget *widget, gint idraw)
{
  GdkRectangle update_rect;
  gint col1, col2;
  gchar spd[5];
  gint row1=4, row2=8;
  
  col2 = colsb_left[isel_contest]-2;
  if(isel_contest==WW)
   col2 -= 14;
  col1 = col2-8;
  update_rect.x = col1*wcol;
  update_rect.y = row1*hrow;
  update_rect.width = (col2-col1-1)*wcol;
  update_rect.height = (row2-row1-1)*hrow;
  if(idraw)
   {
    draw_box (row1, col1, row2, col2, 2, LT_GRAY, BLACK,
              "Keyer", WHITE, "", LT_GRAY, SAVEPIX);
    black_bar (widget, row1, col1-1, row2, col1-1);
   }
  draw_rectangle (&update_rect, ORANGE, SAVEPIX);
  concat(spd, keyer_screen_choices[0], 1, 4, COPY);
  write_line (row1+1, col1+2, spd, WHITE, SAVEPIX);
  gtk_widget_queue_draw_area (widget,
                              update_rect.x-idraw*wcol,
                              update_rect.y-idraw*hrow,
                              update_rect.width+idraw*2*wcol,
                              update_rect.height+idraw*2*hrow);
}

static void message_box(GtkWidget *widget, const gchar *message_line,
                        gint idraw, gint iclear)
{
  GdkRectangle update_rect;
  gint i, col2, iamp;
  gchar message_hold[123];
  static gchar message_array[4][123];
  gint maxml=4;
  gint row1=9, col1=1, row2=14;

  if(iclear)
   for(i=0; i<4; i++)
    message_array[i][0] = '\0';
  if(strlen(message_line))
   {
    iamp = kb_index (message_line, "&");
    if(iamp>-1)
     {
      concat(message_hold, message_line, 0, iamp-1, COPY);
      strcat(message_hold, "&amp;");
      concat(message_hold, message_line, iamp+1,
             strlen(message_line)-1, !COPY);
     }
    else
     strcpy(message_hold, message_line);
    for(i=maxml-1; i>0; i--)
     strcpy(message_array[i], message_array[i-1]);
    strcpy(message_array[0], message_hold);
   }
  if(idisplay_type==IDT_SUMMARY && !ireset_display)
   {
    col2 = colsb_left[isel_contest]-2;
    if(isel_contest==WW)
     {
      col2 -= 14;
      row2--;
      maxml--;
     }
    update_rect.x = col1*wcol;
    update_rect.y = row1*hrow;
    update_rect.width = (col2-col1-1)*wcol;
    update_rect.height = (row2-row1-1)*hrow;
    if(idraw)
     draw_box (row1, col1, row2, col2, 2, LT_GRAY, BLACK,
               "Messages", WHITE, "", LT_GRAY, SAVEPIX);
    draw_rectangle (&update_rect, MAGENTA, SAVEPIX);
    for(i=0; i<maxml; i++)
     write_markup_line (row1+i, col1+1, message_array[i], WHITE, SAVEPIX);
    gtk_widget_queue_draw_area (widget,
                                update_rect.x-idraw*wcol,
                                update_rect.y-idraw*hrow,
                                update_rect.width+idraw*2*wcol,
                                update_rect.height+idraw*2*hrow);
   }
  else
   {
    row1 = 23-log_lines[idisplay_type];
    col1 = 1;
    row2 = row1+1;
    col2 = 80;
    update_rect.x = col1*wcol;
    update_rect.y = row1*hrow;
    update_rect.width = (col2-col1+1)*wcol;
    update_rect.height = (row2-row1)*hrow;
    black_bar (widget, row1, col1, row1, col2);
    write_markup_line (row1-1, col1, message_array[0], GREEN, SAVEPIX);
    if(strlen(message_array[1]))
     write_markup_line (row1-1, col1+strlen(message_array[0])+1,
                        message_array[1], GREEN, SAVEPIX);
    gtk_widget_queue_draw_area (widget,
                                update_rect.x,
                                update_rect.y,
                                update_rect.width,
                                update_rect.height);
   }
}

static void knowledge_box(GtkWidget *widget, gint idraw)
{
  GdkRectangle update_rect;
  gchar title[32], lc_abv[8], k_px[6], k_zn[3];
  gint i, mb_color, col2, iscountry, k_idx, lcw, ipx, j;
  gint row1=15, col1=1, row2=17;
  const gchar *px10_char[10] = {"1", "2", "3", "4", "5",
                                "6", "7", "8", "9", "0"};
  
  col2 = colsb_left[isel_contest]-2;
  if(isel_contest==WW)
   {
    col2 -= 14;
    row1--;
   }
  update_rect.x = col1*wcol;
  update_rect.y = row1*hrow;
  update_rect.width = (col2-col1-1)*wcol;
  update_rect.height = (row2-row1-1)*hrow;
  if(knowledge_index>MAX_COUNTRIES)
   {
    iscountry = FALSE;
    k_idx = knowledge_index-1000;
   }
  else
   {
    iscountry = TRUE;
    k_idx = knowledge_index;
   }
  if(k_idx<0)
   strcpy(title, "Knowledge");
  else if(iscountry)
   strcpy(title, countries.country_name[k_idx]);
  else
   strcpy(title, loci.locus_name[k_idx]);
  if(idraw)
   draw_box (row1, col1, row2, col2, 2, LT_GRAY, BLACK,
             title, WHITE, "", LT_GRAY, SAVEPIX);
  draw_rectangle (&update_rect, BLUE, SAVEPIX);
  switch (isel_contest)
   {
    case DX :
     if(k_idx>-1)
      {
       write_line (row1, col1+1,
        countries.country_abv[k_idx], WHITE, SAVEPIX);
       for(i=0; i<6; i++)
        {
         if(countries.icountry_worked[i][k_idx])
          mb_color = BLACK;
         else
          mb_color = YELLOW;
         write_line (row1, col2-30+5*i, bandw[i], mb_color, SAVEPIX);
        }
      }
     break;
    case WPX :
     if(k_idx>-1)
      {
       i = 0;
       ipx = -1;
       while(knowledge_prefix[i])
        {
         if(isdigit(knowledge_prefix[i]))
          ipx = i;
         i++;
        }
       if(!ipx)
        {
         ipx = strlen(knowledge_prefix);
         ipx = ipx<5 ? ipx-1 : 3;
         concat(k_px, knowledge_prefix, 0, ipx, COPY);
         strcat(k_px, "0");
         ipx++;
        }
       else if(ipx<0)
        {
         ipx = strlen(knowledge_prefix)<2 ? 0 : 1;
         concat(k_px, knowledge_prefix, 0, ipx, COPY);
         strcat(k_px, "0");
         ipx++;
        }
       else
        {
         if(ipx>4)
          ipx = 4;
         concat(k_px, knowledge_prefix, 0, ipx, COPY);
        }
       k_px[ipx] = '\0';
       write_line (row1, col1+1, k_px, WHITE, SAVEPIX);
       for(i=0; i<10; i++)
        {
         strcpy(cr_array[6499].prefix, k_px);
         strcat(cr_array[6499].prefix, px10_char[i]);
         search_px_tree (6499);
         if(px_tree.pmatch>0)
          mb_color = BLACK;
         else
          mb_color = YELLOW;
         write_line (row1, col2-39+4*i, px10_char[i], mb_color, SAVEPIX);
        }
      }
     break;
    case FD :
    case WAA :
     if(k_idx>-1)
      {
       if(iscountry)
        strcpy(lc_abv, countries.country_abv[k_idx]);
       else
        strcpy(lc_abv, loci.locus_abv[k_idx]);
       write_line (row1, col1+1, lc_abv, WHITE, SAVEPIX);
       for(i=0; i<6; i++)
        {
         if(iscountry)
          lcw = countries.icountry_worked[i][k_idx];
         else
          lcw = loci.locus_worked[6*mode+i][k_idx];
         if(lcw)
          mb_color = BLACK;
         else
          mb_color = YELLOW;
         write_line (row1, col2-30+5*i, bandw[i], mb_color, SAVEPIX);
        }
      }
     break;
    case NYQP :
     if(k_idx>-1)
      {
       if(iscountry)
        strcpy(lc_abv, countries.country_abv[k_idx]);
       else
        strcpy(lc_abv, loci.locus_abv[k_idx]);
       write_line (row1, col1+1, lc_abv, WHITE, SAVEPIX);
       for(i=0; i<12; i++)
        {
         if(iscountry)
          lcw = countries.icountry_worked[i%6][k_idx];
         else
          lcw = loci.locus_worked[i][k_idx];
         if(lcw)
          break;
        }
       if(lcw)
        write_line (row1, col2-9, "WORKED", BLACK, SAVEPIX);
       else
        write_line (row1, col2-9, "NEEDED", WHITE, SAVEPIX);
      }
     break;
    case WW :
     if(k_idx>-1)
      {
       write_line (row1, col1+1, countries.country_abv[k_idx],
                   WHITE, SAVEPIX);
       for(i=0; i<6; i++)
        {
         if(countries.icountry_worked[i][k_idx])
          mb_color = BLACK;
         else
          mb_color = YELLOW;
         write_line (row1, col2-30+5*i, bandw[i], mb_color, SAVEPIX);
        }
       write_line (row1+1, col1+1, "Zone", WHITE, SAVEPIX);
       strcpy(k_zn, zone_chars[knowledge_zindex]);
       left_blank_unpad (k_zn);
       write_line (row1+1, col1+6, k_zn, WHITE, SAVEPIX);
       for(i=0; i<6; i++)
        {
         if(countries.izone_worked[i][knowledge_zindex])
          mb_color = BLACK;
         else
          mb_color = YELLOW;
         write_line (row1+1, col2-30+5*i, bandw[i], mb_color, SAVEPIX);
        }
      }
     break;
    case SS :
     if(k_idx>-1)
      {
       if(iscountry)
        strcpy(lc_abv, countries.country_abv[k_idx]);
       else
        strcpy(lc_abv, loci.locus_abv[k_idx]);
       write_line (row1, col1+1, lc_abv, WHITE, SAVEPIX);
       for(i=0; i<2; i++)
        {
         mb_color = BLUE;
         if(i==mode)
          {
           mb_color = WHITE;
           for(j=0; j<6; j++)
            {
             if(iscountry)
              lcw = countries.icountry_worked[j][k_idx];
             else
              lcw = loci.locus_worked[j][k_idx];
             if(lcw)
              {
               mb_color = BLACK;
               break;
              }
            }
          }
         write_line (row1, col2-10+5*i, mode_char[i], mb_color, SAVEPIX);
        }
      }
     break;
    case A160 :
     if(k_idx>-1)
      {
       if(iscountry)
        strcpy(lc_abv, countries.country_abv[k_idx]);
       else
        strcpy(lc_abv, loci.locus_abv[k_idx]);
       write_line (row1, col1+1, lc_abv, WHITE, SAVEPIX);
       for(i=0; i<2; i++)
        {
         mb_color = BLUE;
         if(i==mode)
          {
           mb_color = WHITE;
           if(iscountry)
            lcw = countries.icountry_worked[i][k_idx];
           else
            lcw = loci.locus_worked[i][k_idx];
           if(lcw)
            mb_color = BLACK;
          }
         write_line (row1, col2-10+5*i, mode_char[i], mb_color, SAVEPIX);
        }
      }
     break;
    case TEN :
     if(k_idx>-1)
      {
       if(iscountry)
        strcpy(lc_abv, countries.country_abv[k_idx]);
       else
        strcpy(lc_abv, loci.locus_abv[k_idx]);
       write_line (row1, col1+1, lc_abv, WHITE, SAVEPIX);
       for(i=0; i<2; i++)
        {
         if(iscountry)
          lcw = countries.icountry_worked[i][k_idx];
         else
          lcw = loci.locus_worked[i][k_idx];
         if(lcw)
          mb_color = BLACK;
         else
          mb_color = WHITE;
         write_line (row1, col2-10+5*i, mode_char[i], mb_color, SAVEPIX);
        }
      }
     break;
   }
  gtk_widget_queue_draw_area (widget,
                              update_rect.x-idraw*wcol,
                              update_rect.y-idraw*hrow,
                              update_rect.width+idraw*2*wcol,
                              update_rect.height+idraw*2*hrow);
}

static void zone_box(GtkWidget *widget, gint idraw)
{
  GdkRectangle update_rect;
  gint i, ii, mb, zone_color, jcol;
  gint col1, col2;
  gint ic=0;
  gint row1=4, row2=17;

  col2 = colsb_left[isel_contest]-2;
  col1=col2-12;
  jcol = col1-3;
  mb = iband;
  update_rect.x = col1*wcol;
  update_rect.y = row1*hrow;
  update_rect.width = (col2-col1-1)*wcol;
  update_rect.height = (row2-row1-1)*hrow;
  if(idraw)
   {
    draw_box (row1, col1, row2, col2, 2, LT_GRAY, BLACK,
              "Zones", WHITE, "", LT_GRAY, SAVEPIX);
    black_bar (widget, row1, col1-1, row2, col1-1);
   }
  draw_rectangle (&update_rect, RED, SAVEPIX);
  for(i=1; i<MAX_ZONES; i++)
   {
    ii = ic%10;
    if(!ii) jcol+=3;
    ic++;
    if(countries.izone_worked[mb][i])
     zone_color = BLACK;
    else
     zone_color = WHITE;
    write_line (row1+ii+1, jcol, zone_chars[i], zone_color, SAVEPIX);
   }
  gtk_widget_queue_draw_area (widget,
                              update_rect.x-idraw*wcol,
                              update_rect.y-idraw*hrow,
                              update_rect.width+idraw*2*wcol,
                              update_rect.height+idraw*2*hrow);
}

static void summary_box(GtkWidget *widget, gint idraw)
{
  GdkRectangle update_rect;
  gint i, j, col1, cw_color, ph_color, qmcw_color, qmph_color;
  gint band_color;
  gchar points_char[6], dupes_char[5], qsos_char[5], time_off_char[6];
  gchar mults_char[5], zones_char[4], score_char[12], trade_char[4];
  gchar time_off_line[23], trade_line[23];
  gint points=0, dupes=0, mults=0, zones=0, score=0, itrade=3;
  gint qm[2] = {0, 0}, dm[2] = {0, 0}, nlw[2] = {0, 0};
  gint row1=4, row2=17, col2=80;

  col1 = colsb_left[isel_contest];
  update_rect.x = col1*wcol;
  update_rect.y = row1*hrow;
  update_rect.width = (col2-col1-1)*wcol;
  update_rect.height = (row2-row1-1)*hrow;
  if(idraw)
   {
    draw_box (row1, col1, row2, col2, 2, LT_GRAY, BLACK,
              "Summary", WHITE, "", LT_GRAY, SAVEPIX);
    black_bar (widget, row1, col1-1, row2, col1-1);
   }
  draw_rectangle (&update_rect, BLACK, SAVEPIX);
  int_to_char (itime_off, time_off_char);
  strcpy(time_off_line, "TIMEOFF: ");
  strcat(time_off_line, time_off_char);
  strcat(time_off_line, " MINUTES");
  for(j=0; j<2; j++)
   for(i=0; i<6; i++)
    {
     dupes += score_mb.dupes[j][i];
     points += score_mb.points[j][i];
     mults += score_mb.mults[j][i];
     zones += score_mb.zones[j][i];
     qm[j] += score_mb.qsos[j][i];
     dm[j] += score_mb.dupes[j][i];
    }
  if(mults+zones)
   itrade = nint(1.+((gdouble) (icall_count-dupes))/
                 ((gdouble) (mults+zones)));
  int_to_char (itrade, trade_char);
  strcpy(trade_line, "1 NEW MULT = ");
  strcat(trade_line, trade_char);
  strcat(trade_line, " QSOs");
  switch (isel_contest)
   {
    case DX :
    case WPX :
     color_bar (widget, row1+iband+2, col1+4, row1+iband+2, col2-5, BLUE);
     traffic_lights (widget);
     write_line (row1, col1+2, "BAND", CYAN, SAVEPIX);
     write_line (row1, col1+12, "Q", CYAN, SAVEPIX);
     if(isel_contest==WPX)
      write_line (row1, col1+19, "P", CYAN, SAVEPIX);
     else
      write_line (row1, col1+19, "C", CYAN, SAVEPIX);
     write_line (row1+7, col1+3, "ALL", CYAN, SAVEPIX);
     write_line (row1+8, col1+2, "DUPES:", LT_GRAY, SAVEPIX);
     write_line (row1+9, col1+2, "SCORE:", CYAN, SAVEPIX);
     write_line (row1+10, col1+2, trade_line, CYAN, SAVEPIX);
     write_line (row1+11, col1+2, time_off_line, LT_GRAY, SAVEPIX);
     for(i=0; i<6; i++)
      {
       if(i==iband)
        band_color = WHITE;
       else
        band_color = LT_GRAY;
       write_line (row1+i+1, col1+3, bandw[i], band_color, SAVEPIX);
       int_to_char (score_mb.qsos[mode][i]-score_mb.dupes[mode][i],
                    qsos_char);
       left_blank_pad (qsos_char, sizeof(qsos_char));
       write_line (row1+i+1, col1+9, qsos_char, band_color, SAVEPIX);
       int_to_char (score_mb.mults[mode][i], mults_char);
       left_blank_pad (mults_char, sizeof(mults_char));
       write_line (row1+i+1, col1+16, mults_char, band_color, SAVEPIX);
      }
     int_to_char (icall_count-dupes, qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+7, col1+9, qsos_char, CYAN, SAVEPIX);
     int_to_char (mults, mults_char);
     left_blank_pad (mults_char, sizeof(mults_char));
     write_line (row1+7, col1+16, mults_char, CYAN, SAVEPIX);
     int_to_char (dupes, dupes_char);
     write_line (row1+8, col1+9, dupes_char, LT_GRAY, SAVEPIX);
     score = points*mults;
     int_to_comma (score, score_char);
     write_line (row1+9, col1+9, score_char, CYAN, SAVEPIX);
     break;
    case FD :
     if(mode==CW)
      {
       cw_color = YELLOW;
       ph_color = CYAN;
      }
     else
      {
       cw_color = CYAN;
       ph_color = YELLOW;
      }
     color_bar (widget, row1+iband+2, col1+4, row1+iband+2, col2-5, BLUE);
     if(!strcmp(init_screen_choices[12], power_bracket[0]))
      mults = 5;
     else if(!strcmp(init_screen_choices[12], power_bracket[1]))
      mults = 2;
     else
      mults = 1;
     write_line (row1, col1+2, "BAND", CYAN, SAVEPIX);
     write_line (row1, col1+11, "CW", cw_color, SAVEPIX);
     write_line (row1, col1+18, "PH", ph_color, SAVEPIX);
     write_line (row1+7, col1+3, "ALL", CYAN, SAVEPIX);
     write_line (row1+8, col1+2, "QSOS:", LT_GRAY, SAVEPIX);
     write_line (row1+9, col1+2, "DUPES:", LT_GRAY, SAVEPIX);
     write_line (row1+10, col1+2, "SCORE:", CYAN, SAVEPIX);
     write_line (row1+11, col1+2, time_off_line, LT_GRAY, SAVEPIX);
     for(i=0; i<6; i++)
      {
       if(i==iband)
        {
         band_color = WHITE;
         if(mode==CW)
          {
           qmcw_color = WHITE;
           qmph_color = LT_GRAY;
          }
         else
          {
           qmcw_color = LT_GRAY;
           qmph_color = WHITE;
          }
        }
       else
        {
         band_color = LT_GRAY;
         qmcw_color = LT_GRAY;
         qmph_color = LT_GRAY;
        }
       write_line (row1+i+1, col1+3, bandw[i], band_color, SAVEPIX);
       int_to_char (score_mb.qsos[CW][i]-score_mb.dupes[CW][i], qsos_char);
       left_blank_pad (qsos_char, sizeof(qsos_char));
       write_line (row1+i+1, col1+9, qsos_char, qmcw_color, SAVEPIX);
       int_to_char (score_mb.qsos[PH][i]-score_mb.dupes[PH][i], qsos_char);
       left_blank_pad (qsos_char, sizeof(qsos_char));
       write_line (row1+i+1, col1+16, qsos_char, qmph_color, SAVEPIX);
      }
     int_to_char (qm[CW]-dm[CW], qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+7, col1+9, qsos_char, CYAN, SAVEPIX);
     int_to_char (qm[PH]-dm[PH], qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+7, col1+16, qsos_char, CYAN, SAVEPIX);
     int_to_char (icall_count-dupes, qsos_char);
     write_line (row1+8, col1+9, qsos_char, LT_GRAY, SAVEPIX);
     int_to_char (dupes, dupes_char);
     write_line (row1+9, col1+9, dupes_char, LT_GRAY, SAVEPIX);
     score = points*mults;
     int_to_comma (score, score_char);
     write_line (row1+10, col1+9, score_char, CYAN, SAVEPIX);
     break;
    case NYQP :
     if(mode==CW)
      {
       cw_color = YELLOW;
       ph_color = CYAN;
      }
     else
      {
       cw_color = CYAN;
       ph_color = YELLOW;
      }
     color_bar (widget, row1+iband+2, col1+4, row1+iband+2, col2-5, BLUE);
     write_line (row1, col1+2, "BAND", CYAN, SAVEPIX);
     write_line (row1, col1+11, "CW", cw_color, SAVEPIX);
     write_line (row1, col1+18, "PH", ph_color, SAVEPIX);
     write_line (row1+7, col1+3, "ALL", CYAN, SAVEPIX);
     write_line (row1+8, col1+2, "QSOs:", LT_GRAY, SAVEPIX);
     write_line (row1+8, col1+13, "DUPES:", LT_GRAY, SAVEPIX);
     write_line (row1+9, col1+2, "CTYs:", LT_GRAY, SAVEPIX);
     if(!strcmp(init_screen_choices[6], "NY"))
      write_line (row1+9, col1+13, "ST/PR:", LT_GRAY, SAVEPIX);
     write_line (row1+10, col1+2, "SCORE:", CYAN, SAVEPIX);
     write_line (row1+11, col1+2, time_off_line, LT_GRAY, SAVEPIX);
     for(i=0; i<6; i++)
      {
       if(i==iband)
        {
         band_color = WHITE;
         if(mode==CW)
          {
           qmcw_color = WHITE;
           qmph_color = LT_GRAY;
          }
         else
          {
           qmcw_color = LT_GRAY;
           qmph_color = WHITE;
          }
        }
       else
        {
         band_color = LT_GRAY;
         qmcw_color = LT_GRAY;
         qmph_color = LT_GRAY;
        }
       write_line (row1+i+1, col1+3, bandw[i], band_color, SAVEPIX);
       int_to_char (score_mb.qsos[CW][i]-score_mb.dupes[CW][i], qsos_char);
       left_blank_pad (qsos_char, sizeof(qsos_char));
       write_line (row1+i+1, col1+9, qsos_char, qmcw_color, SAVEPIX);
       int_to_char (score_mb.qsos[PH][i]-score_mb.dupes[PH][i], qsos_char);
       left_blank_pad (qsos_char, sizeof(qsos_char));
       write_line (row1+i+1, col1+16, qsos_char, qmph_color, SAVEPIX);
      }
     int_to_char (qm[CW]-dm[CW], qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+7, col1+9, qsos_char, CYAN, SAVEPIX);
     int_to_char (qm[PH]-dm[PH], qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+7, col1+16, qsos_char, CYAN, SAVEPIX);
     int_to_char (icall_count-dupes, qsos_char);
     write_line (row1+8, col1+8, qsos_char, LT_GRAY, SAVEPIX);
     int_to_char (dupes, dupes_char);
     write_line (row1+8, col1+20, dupes_char, LT_GRAY, SAVEPIX);
     for(i=0; i<12; i++)
      for(j=1; j<loci.number_of_loci; j++)
       if(loci.locus_worked[i][j])
        {
         if(j>loci.number_of_countyloci)
          nlw[1]++;
         else
          nlw[0]++;
        }
     int_to_char (nlw[0], mults_char);
     write_line (row1+9, col1+8, mults_char, LT_GRAY, SAVEPIX);
     if(!strcmp(init_screen_choices[6], "NY"))
      {
       int_to_char (nlw[1], mults_char);
       write_line (row1+9, col1+20, mults_char, LT_GRAY, SAVEPIX);
      }
     score = points*mults;
     int_to_comma (score, score_char);
     write_line (row1+10, col1+9, score_char, CYAN, SAVEPIX);
     break;
    case WW :
     color_bar (widget, row1+iband+2, col1+3, row1+iband+2, col2-2, BLUE);
     traffic_lights (widget);
     write_line (row1, col1+1, "BAND", CYAN, SAVEPIX);
     write_line (row1, col1+10, "Q", CYAN, SAVEPIX);
     write_line (row1, col1+15, "C", CYAN, SAVEPIX);
     write_line (row1, col1+20, "Z", CYAN, SAVEPIX);
     write_line (row1+7, col1+2, "ALL", CYAN, SAVEPIX);
     write_line (row1+8, col1+1, "DUPES:", LT_GRAY, SAVEPIX);
     write_line (row1+9, col1+1, "SCORE:", CYAN, SAVEPIX);
     write_line (row1+10, col1+1, trade_line, CYAN, SAVEPIX);
     write_line (row1+11, col1+1, time_off_line, LT_GRAY, SAVEPIX);
     for(i=0; i<6; i++)
      {
       if(i==iband)
        band_color = WHITE;
       else
        band_color = LT_GRAY;
       write_line (row1+i+1, col1+2, bandw[i], band_color, SAVEPIX);
       int_to_char (score_mb.qsos[mode][i]-score_mb.dupes[mode][i],
                    qsos_char);
       left_blank_pad (qsos_char, sizeof(qsos_char));
       write_line (row1+i+1, col1+7, qsos_char, band_color, SAVEPIX);
       int_to_char (score_mb.mults[mode][i], mults_char);
       left_blank_pad (mults_char, sizeof(mults_char));
       write_line (row1+i+1, col1+12, mults_char, band_color, SAVEPIX);
       int_to_char (score_mb.zones[mode][i], zones_char);
       left_blank_pad (zones_char, sizeof(zones_char));
       write_line (row1+i+1, col1+18, zones_char, band_color, SAVEPIX);
      }
     int_to_char (icall_count-dupes, qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+7, col1+7, qsos_char, CYAN, SAVEPIX);
     int_to_char (mults, mults_char);
     left_blank_pad (mults_char, sizeof(mults_char));
     write_line (row1+7, col1+12, mults_char, CYAN, SAVEPIX);
     int_to_char (zones, zones_char);
     left_blank_pad (zones_char, sizeof(zones_char));
     write_line (row1+7, col1+18, zones_char, CYAN, SAVEPIX);
     int_to_char (dupes, dupes_char);
     write_line (row1+8, col1+8, dupes_char, LT_GRAY, SAVEPIX);
     score = points*(mults+zones);
     int_to_comma (score, score_char);
     write_line (row1+9, col1+8, score_char, CYAN, SAVEPIX);
     break;
    case SS :
     color_bar (widget, row1+iband+2, col1+4, row1+iband+2, col2-5, BLUE);
     write_line (row1, col1+2, "BAND", CYAN, SAVEPIX);
     write_line (row1, col1+12, "Q", CYAN, SAVEPIX);
     write_line (row1, col1+19, "S", CYAN, SAVEPIX);
     write_line (row1+7, col1+3, "ALL", CYAN, SAVEPIX);
     write_line (row1+8, col1+2, "DUPES:", LT_GRAY, SAVEPIX);
     write_line (row1+9, col1+2, "SCORE:", CYAN, SAVEPIX);
     if(mults==loci.number_of_loci)
      write_line (row1+10, col1+2, "Clean Sweep!", YELLOW, SAVEPIX);
     write_line (row1+11, col1+2, time_off_line, LT_GRAY, SAVEPIX);
     for(i=0; i<6; i++)
      {
       if(i==iband)
        band_color = WHITE;
       else
        band_color = LT_GRAY;
       write_line (row1+i+1, col1+3, bandw[i], band_color, SAVEPIX);
       int_to_char (score_mb.qsos[mode][i]-score_mb.dupes[mode][i],
                    qsos_char);
       left_blank_pad (qsos_char, sizeof(qsos_char));
       write_line (row1+i+1, col1+9, qsos_char, band_color, SAVEPIX);
       int_to_char (score_mb.mults[mode][i], mults_char);
       left_blank_pad (mults_char, sizeof(mults_char));
       write_line (row1+i+1, col1+16, mults_char, band_color, SAVEPIX);
      }
     int_to_char (icall_count-dupes, qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+7, col1+9, qsos_char, CYAN, SAVEPIX);
     int_to_char (mults, mults_char);
     left_blank_pad (mults_char, sizeof(mults_char));
     write_line (row1+7, col1+16, mults_char, CYAN, SAVEPIX);
     int_to_char (dupes, dupes_char);
     write_line (row1+8, col1+9, dupes_char, LT_GRAY, SAVEPIX);
     score = points*mults;
     int_to_comma (score, score_char);
     write_line (row1+9, col1+9, score_char, CYAN, SAVEPIX);
     break;
    case A160 :
     if(mode==CW)
      {
       cw_color = YELLOW;
       ph_color = CYAN;
       qmcw_color = WHITE;
       qmph_color = LT_GRAY;
      }
     else
      {
       cw_color = CYAN;
       ph_color = YELLOW;
       qmcw_color = LT_GRAY;
       qmph_color = WHITE;
      }
     write_line (row1, col1+3, "MODE", CYAN, SAVEPIX);
     write_line (row1, col1+12, "CW", cw_color, SAVEPIX);
     write_line (row1+1, col1+3, "QSOs", LT_GRAY, SAVEPIX);
     write_line (row1+2, col1+3, "SECTNs", LT_GRAY, SAVEPIX);
     write_line (row1+3, col1+3, "CTRYs", LT_GRAY, SAVEPIX);
     write_line (row1+5, col1+9, "TOTALS", LT_GRAY, SAVEPIX);
     write_line (row1+6, col1+3, "QSOs:", CYAN, SAVEPIX);
     write_line (row1+6, col1+14, "DUPES:", LT_GRAY, SAVEPIX);
     write_line (row1+7, col1+3, "MLTs:", CYAN, SAVEPIX);
     write_line (row1+7, col1+14, "PTS:", LT_GRAY, SAVEPIX);
     write_line (row1+8, col1+3, "SCORE:", CYAN, SAVEPIX);
     write_line (row1+10, col1+3, trade_line, CYAN, SAVEPIX);
     write_line (row1+11, col1+3, time_off_line, LT_GRAY, SAVEPIX);
     score = points*mults;
     int_to_comma (score, score_char);
     write_line (row1+8, col1+10, score_char, CYAN, SAVEPIX);
     int_to_char (mults, mults_char);
     write_line (row1+7, col1+9, mults_char, CYAN, SAVEPIX);
     int_to_char (points, points_char);
     write_line (row1+7, col1+19, points_char, LT_GRAY, SAVEPIX);
     int_to_char (dupes, dupes_char);
     write_line (row1+6, col1+21, dupes_char, LT_GRAY, SAVEPIX);
     int_to_char (icall_count-dupes, qsos_char);
     write_line (row1+6, col1+9, qsos_char, CYAN, SAVEPIX);
     int_to_char (score_mb.qsos[CW][iband]-score_mb.dupes[CW][iband],
                  qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+1, col1+10, qsos_char, qmcw_color, SAVEPIX);
     for(i=0; i<2; i++)
      for(j=1; j<=loci.number_of_loci; j++)
       if(loci.locus_worked[i][j])
        nlw[i]++;
     int_to_char (nlw[CW], mults_char);
     left_blank_pad (mults_char, sizeof(mults_char));
     write_line (row1+2, col1+10, mults_char, qmcw_color, SAVEPIX);
     nlw[0] = 0;
     nlw[1] = 0;
     for(i=0; i<2; i++)
      for(j=1; j<=countries.number_of_countries; j++)
       if(countries.icountry_worked[i][j])
        nlw[i]++;
     int_to_char (nlw[CW], mults_char);
     left_blank_pad (mults_char, sizeof(mults_char));
     write_line (row1+3, col1+10, mults_char, qmcw_color, SAVEPIX);
     break;
    case TEN :
     if(mode==CW)
      {
       cw_color = YELLOW;
       ph_color = CYAN;
       qmcw_color = WHITE;
       qmph_color = LT_GRAY;
      }
     else
      {
       cw_color = CYAN;
       ph_color = YELLOW;
       qmcw_color = LT_GRAY;
       qmph_color = WHITE;
      }
     write_line (row1, col1+3, "MODE", CYAN, SAVEPIX);
     write_line (row1, col1+12, "CW", cw_color, SAVEPIX);
     write_line (row1, col1+19, "PH", ph_color, SAVEPIX);
     write_line (row1+1, col1+3, "QSOs", LT_GRAY, SAVEPIX);
     write_line (row1+2, col1+3, "STATEs", LT_GRAY, SAVEPIX);
     write_line (row1+3, col1+3, "CTRYs", LT_GRAY, SAVEPIX);
     write_line (row1+5, col1+9, "TOTALS", LT_GRAY, SAVEPIX);
     write_line (row1+6, col1+3, "QSOs:", CYAN, SAVEPIX);
     write_line (row1+6, col1+14, "DUPES:", LT_GRAY, SAVEPIX);
     write_line (row1+7, col1+3, "MLTs:", CYAN, SAVEPIX);
     write_line (row1+7, col1+14, "PTS:", LT_GRAY, SAVEPIX);
     write_line (row1+8, col1+3, "SCORE:", CYAN, SAVEPIX);
     write_line (row1+10, col1+3, trade_line, CYAN, SAVEPIX);
     write_line (row1+11, col1+3, time_off_line, LT_GRAY, SAVEPIX);
     score = points*mults;
     int_to_comma (score, score_char);
     write_line (row1+8, col1+10, score_char, CYAN, SAVEPIX);
     int_to_char (mults, mults_char);
     write_line (row1+7, col1+9, mults_char, CYAN, SAVEPIX);
     int_to_char (points, points_char);
     write_line (row1+7, col1+19, points_char, LT_GRAY, SAVEPIX);
     int_to_char (dupes, dupes_char);
     write_line (row1+6, col1+21, dupes_char, LT_GRAY, SAVEPIX);
     int_to_char (icall_count-dupes, qsos_char);
     write_line (row1+6, col1+9, qsos_char, CYAN, SAVEPIX);
     int_to_char (score_mb.qsos[CW][iband]-score_mb.dupes[CW][iband],
                  qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+1, col1+10, qsos_char, qmcw_color, SAVEPIX);
     for(i=0; i<2; i++)
      for(j=1; j<=loci.number_of_loci; j++)
       if(loci.locus_worked[i][j])
        nlw[i]++;
     int_to_char (nlw[CW], mults_char);
     left_blank_pad (mults_char, sizeof(mults_char));
     write_line (row1+2, col1+10, mults_char, qmcw_color, SAVEPIX);
     int_to_char (score_mb.qsos[PH][iband]-score_mb.dupes[PH][iband],
                  qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+1, col1+17, qsos_char, qmph_color, SAVEPIX);
     int_to_char (nlw[PH], mults_char);
     left_blank_pad (mults_char, sizeof(mults_char));
     write_line (row1+2, col1+17, mults_char, qmph_color, SAVEPIX);
     nlw[0] = 0;
     nlw[1] = 0;
     for(i=0; i<2; i++)
      for(j=1; j<=countries.number_of_countries; j++)
       if(countries.icountry_worked[i][j])
        nlw[i]++;
     int_to_char (nlw[CW], mults_char);
     left_blank_pad (mults_char, sizeof(mults_char));
     write_line (row1+3, col1+10, mults_char, qmcw_color, SAVEPIX);
     int_to_char (nlw[PH], mults_char);
     left_blank_pad (mults_char, sizeof(mults_char));
     write_line (row1+3, col1+17, mults_char, qmph_color, SAVEPIX);
     break;
    case WAA :
     if(mode==CW)
      {
       cw_color = YELLOW;
       ph_color = CYAN;
      }
     else
      {
       cw_color = CYAN;
       ph_color = YELLOW;
      }
     color_bar (widget, row1+iband+2, col1+4, row1+iband+2, col2-5, BLUE);
     mults = 1;
     write_line (row1, col1+2, "BAND", CYAN, SAVEPIX);
     write_line (row1, col1+11, "CW", cw_color, SAVEPIX);
     write_line (row1, col1+18, "PH", ph_color, SAVEPIX);
     write_line (row1+7, col1+3, "ALL", CYAN, SAVEPIX);
     write_line (row1+8, col1+2, "QSOS:", LT_GRAY, SAVEPIX);
     write_line (row1+9, col1+2, "DUPES:", LT_GRAY, SAVEPIX);
     write_line (row1+10, col1+2, "SCORE:", CYAN, SAVEPIX);
     write_line (row1+11, col1+2, time_off_line, LT_GRAY, SAVEPIX);
     for(i=0; i<6; i++)
      {
       if(i==iband)
        {
         band_color = WHITE;
         if(mode==CW)
          {
           qmcw_color = WHITE;
           qmph_color = LT_GRAY;
          }
         else
          {
           qmcw_color = LT_GRAY;
           qmph_color = WHITE;
          }
        }
       else
        {
         band_color = LT_GRAY;
         qmcw_color = LT_GRAY;
         qmph_color = LT_GRAY;
        }
       write_line (row1+i+1, col1+3, bandw[i], band_color, SAVEPIX);
       int_to_char (score_mb.qsos[CW][i]-score_mb.dupes[CW][i], qsos_char);
       left_blank_pad (qsos_char, sizeof(qsos_char));
       write_line (row1+i+1, col1+9, qsos_char, qmcw_color, SAVEPIX);
       int_to_char (score_mb.qsos[PH][i]-score_mb.dupes[PH][i], qsos_char);
       left_blank_pad (qsos_char, sizeof(qsos_char));
       write_line (row1+i+1, col1+16, qsos_char, qmph_color, SAVEPIX);
      }
     int_to_char (qm[CW]-dm[CW], qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+7, col1+9, qsos_char, CYAN, SAVEPIX);
     int_to_char (qm[PH]-dm[PH], qsos_char);
     left_blank_pad (qsos_char, sizeof(qsos_char));
     write_line (row1+7, col1+16, qsos_char, CYAN, SAVEPIX);
     int_to_char (icall_count-dupes, qsos_char);
     write_line (row1+8, col1+9, qsos_char, LT_GRAY, SAVEPIX);
     int_to_char (dupes, dupes_char);
     write_line (row1+9, col1+9, dupes_char, LT_GRAY, SAVEPIX);
     score = points*mults;
     int_to_comma (score, score_char);
     write_line (row1+10, col1+9, score_char, CYAN, SAVEPIX);
     break;
   }
  gtk_widget_queue_draw_area (widget,
                              update_rect.x-idraw*wcol,
                              update_rect.y-idraw*hrow,
                              update_rect.width+idraw*2*wcol,
                              update_rect.height+idraw*2*hrow);
}

static void traffic_lights(GtkWidget *widget)
{
  GdkRectangle update_rect;
  gint i, istar, istar_by_band[6], star_color[6];
  gint col1, col2;
  gint row1=6, row2=12;
  gint max_band_score=-1, min_band_score=100000000;

  col1 = colsb_left[isel_contest]+2;
  if(isel_contest==WW)
   col1--;
  col2=col1+1;
  update_rect.x = (col1-1)*wcol;
  update_rect.y = (row1-1)*hrow;
  update_rect.width = (col2-col1)*wcol;
  update_rect.height = (row2-row1)*hrow;
  black_bar (widget, row1, col1, row2, col1);
  istar = iband;
  if(!istar)
   istar++;
  else if(istar==5)
   istar--;
  for(i=istar-1; i<istar+2; i++)
   {
    if(isel_contest==WW)
     istar_by_band[i] = (score_mb.qsos[mode][i]-score_mb.dupes[mode][i])*
                         (score_mb.mults[mode][i]+score_mb.zones[mode][i]);
    else
     istar_by_band[i] = (score_mb.qsos[mode][i]-score_mb.dupes[mode][i])*
                         score_mb.mults[mode][i];
    if(isel_contest==WPX)
     istar_by_band[i] *= (1+i/3);
    if(istar_by_band[i]>max_band_score)
     max_band_score = istar_by_band[i];
    if(istar_by_band[i]<min_band_score)
     min_band_score = istar_by_band[i];
   }
  if(max_band_score==min_band_score)
   for(i=istar-1; i<istar+2; i++)
    star_color[i] = HI_GREEN;
  else
   for(i=istar-1; i<istar+2; i++)
    {
     star_color[i] = YELLOW;
     if(istar_by_band[i]==max_band_score)
      star_color[i] = HI_RED;
     if(istar_by_band[i]==min_band_score)
      star_color[i] = HI_GREEN;
    }
  for(i=istar-1; i<istar+2; i++)
   {
    write_line (row1+i-1, col1, "*", star_color[i], SAVEPIX);
   }
  gtk_widget_queue_draw_area (widget,
                              update_rect.x,
                              update_rect.y,
                              update_rect.width,
                              update_rect.height);
}

static void beam_heading(GtkWidget *widget, guint istate)
{
  gint irange, ibearing, lp, lml, iscountry, b_idx;
  gdouble op_lat, op_long, dest_lat, dest_long;
  gdouble rad_per_deg, bearing, range, denom1, denom2;
  gchar sp_char[4], lp_char[4], range_char[6], msg[3][123], msg_line[59];
  gchar sp_ind[3], lp_ind[3];
  const gchar *deg_symbol = "<span size='xx-small' rise='9000'>o</span>";
  const gchar *bearing_ind[5] = {" ", "\\", "|", "/", "*"};
  gint ivertp=0, iplus=0;
  gdouble operator_latitude=0.0, operator_longitude=0.0;
  gdouble miles_per_degree=69.055013;

  rad_per_deg = G_PI/180.;
  if(beam_index>MAX_COUNTRIES)
   {
    iscountry = FALSE;
    b_idx = beam_index-1000;
   }
  else
   {
    iscountry = TRUE;
    b_idx = beam_index;
   }
  if(b_idx>-1)
   {
    lml = strlen(init_screen_choices[8]);
    if(lml)
     {
      operator_latitude = atof(init_screen_choices[8]);
      if(init_screen_choices[8][lml-1]=='S')
       operator_latitude *= -1;
     }
    lml = strlen(init_screen_choices[9]);
    if(lml)
     {
      operator_longitude = atof(init_screen_choices[9]);
      if(init_screen_choices[9][lml-1]=='E')
       operator_longitude *= -1;
     }
    if(istate==20)
     {
      strcpy(msg_line, "From: ");
      dest_lat = operator_latitude;
      dest_long = operator_longitude;
      if(iscountry)
       {
        op_lat = countries.country_lat[b_idx];
        op_long = countries.country_long[b_idx];
       }
      else
       {
        op_lat = loci.locus_lat[b_idx];
        op_long = loci.locus_long[b_idx];
       }
     }
    else
     {
      strcpy(msg_line, "To: ");
      op_lat = operator_latitude;
      op_long = operator_longitude;
      if(iscountry)
       {
        dest_lat = countries.country_lat[b_idx];
        dest_long = countries.country_long[b_idx];
       }
      else
       {
        dest_lat = loci.locus_lat[b_idx];
        dest_long = loci.locus_long[b_idx];
       }
     }
    range = miles_per_degree/rad_per_deg
             *acos(sin(rad_per_deg*op_lat)
             *sin(rad_per_deg*dest_lat)+cos(rad_per_deg*op_lat)
             *cos(rad_per_deg*dest_lat)
             *cos(rad_per_deg*(dest_long-op_long)));
    irange = nint(range);
    denom1 = fabs(sin(rad_per_deg*range/miles_per_degree));
    denom2 = fabs(cos(rad_per_deg*op_lat));
    if(denom1>0.001 && denom2>0.001)
     {
      bearing = acos((sin(rad_per_deg*dest_lat)-sin(rad_per_deg*op_lat)
                 *cos(rad_per_deg*range/miles_per_degree))
                 /(sin(rad_per_deg*range/miles_per_degree)
                 *cos(rad_per_deg*op_lat)))/rad_per_deg;
      if(sin(rad_per_deg*(dest_long-op_long))>=0)
       bearing = 360.-bearing;
     }
    if(denom1<=0.001) bearing = 0;
    if(denom2<=0.001)
     {
      bearing = dest_long;
      if(bearing<0) bearing += 360.;
     }
    ibearing = (nint(bearing))%360;
    lp = (ibearing+180)%360;
    int_to_char (irange, range_char);
    int_to_char (ibearing, sp_char);
    int_to_char (lp, lp_char);
    if(istate!=20 && (!strcmp(init_screen_choices[0], "WA1KKM") ||
                      !strcmp(init_screen_choices[0], "N2LBR")))
     {
      ivertp = vertical_switch_position (ibearing);
      strcpy(sp_ind, bearing_ind[ivertp]);
      ivertp = vertical_switch_position (lp);
      strcpy(lp_ind, bearing_ind[ivertp]);
     }
    else
     {
      strcpy(sp_ind, bearing_ind[ivertp]);
      strcpy(lp_ind, bearing_ind[ivertp]);
     }
    if(iscountry)
     {
      if(countries.country_abv[b_idx][0]=='+')
       iplus = 1;
      concat(msg_line, countries.country_abv[b_idx], iplus,
             strlen(countries.country_abv[b_idx])-1, !COPY);
      strcat(msg_line, " - ");
      strcat(msg_line, countries.country_name[b_idx]);
      if(iplus)
       strcat(msg_line, " (Regional)");
     }
    else
     {
      strcat(msg_line,loci.locus_abv[b_idx]);
      strcat(msg_line, " - ");
      strcat(msg_line, loci.locus_name[b_idx]);
     }
    lml = strlen(msg_line);
    if(lml>38)
     concat(msg[0], msg_line, 0, 37, COPY);
    else
     strcpy(msg[0], msg_line);
    strcpy(msg[1], sp_char);
    strcat(msg[1], deg_symbol);
    strcat(msg[1], " (Short Path) ");
    strcat(msg[1], sp_ind);
    strcat(msg[1], " ");
    strcat(msg[1], lp_char);
    strcat(msg[1], deg_symbol);
    strcat(msg[1], " (Long Path) ");
    strcat(msg[1], lp_ind);
    strcpy(msg[2], range_char);
    strcat(msg[2], " (SP Distance in Statute Miles)");
    message_box (widget, msg[2], !REDRAW, CLEAR);
    message_box (widget, msg[1], !REDRAW, !CLEAR);
    message_box (widget, msg[0], !REDRAW, !CLEAR);
   }
}

static gint vertical_switch_position(gint ibearing)
{
  gint i;
  gdouble beta, d, r, dr, term1, term2, term3, x1, x2, x3;
  gdouble del, terma, termb, phi, gain[3];
  gint ivertp=4;
  gdouble xmax_gain=0., r0=36.565, el=.5;

  if(iband<2)
   ivertp = 0;
  else
   {
    beta = 2.*G_PI;
    d = .25*(iband-1);
    dr = beta*d;
    phi = (gdouble) (ibearing-55);
    if(phi<0.) phi = phi+360.;
    phi = phi*G_PI/180.;
    x1 = beta*d;
    term1 = ci(x1);
    x2 = beta*(sqrt(d*d+el*el)+el);
    term2 = ci(x2);
    x3 = beta*(sqrt(d*d+el*el)-el);
    term3 = ci(x3);
    r = 15.*(2.*term1-term2-term3);
    for(i=0; i<3; i++)
     {
      if(i==0) 
       del = d;
      else if(i==1)
       del = -d;
      else
       del=0.;
      del = beta*del;
      terma = 2.*r0/(r0+r*cos(del));
      termb = pow(cos((dr*cos(phi)+del)/2.), 2);
      gain[i] = 10.*log10(terma*termb);
     }
    gain[0] -= .01;
    gain[2] -= .01;
    for(i=0; i<3; i++)
     if(gain[i]>xmax_gain)
      {
       ivertp = i+1;
       xmax_gain = gain[i];
      }
   }
  return ivertp;
}

static gdouble fact(gint num)
{
  gint n;
  gdouble prod=1.;

  for(n=2; n<=num; n++)
   prod *= n;
  return prod;
}

static gdouble ci(gdouble x)
{
  gdouble gamma, sum;
  gint i=2, isign=1;

  gamma = exp(0.5772156649);
  sum = log10(gamma*x);
  while(i<33)
   {
    isign *= -1;
    sum += isign*pow(x,i)/(fact(i)*i);
    i += 2;
   }
  return sum;
}
