/ src / sat-vis.c
sat-vis.c
  1  /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2  /*
  3      Gpredict: Real-time satellite tracking and orbit prediction program
  4  
  5      Copyright (C)  2001-2009  Alexandru Csete, OZ9AEC.
  6  
  7      Authors: Alexandru Csete <oz9aec@gmail.com>
  8  
  9      Comments, questions and bugreports should be submitted via
 10      http://sourceforge.net/projects/gpredict/
 11      More details can be found at the project home page:
 12  
 13              http://gpredict.oz9aec.net/
 14   
 15      This program is free software; you can redistribute it and/or modify
 16      it under the terms of the GNU General Public License as published by
 17      the Free Software Foundation; either version 2 of the License, or
 18      (at your option) any later version.
 19    
 20      This program is distributed in the hope that it will be useful,
 21      but WITHOUT ANY WARRANTY; without even the implied warranty of
 22      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 23      GNU General Public License for more details.
 24    
 25      You should have received a copy of the GNU General Public License
 26      along with this program; if not, visit http://www.fsf.org/
 27  */
 28  /** \brief Satellite visibility calculations. */
 29  #include <gtk/gtk.h>
 30  #include <glib/gi18n.h>
 31  #include "sgpsdp/sgp4sdp4.h"
 32  #include "gtk-sat-data.h"
 33  #include "sat-vis.h"
 34  #include "sat-cfg.h"
 35  
 36  
 37  static gchar VIS2CHR[SAT_VIS_NUM] = { '-', 'V', 'D', 'E'};
 38  
 39  static gchar *VIS2STR[SAT_VIS_NUM] = {
 40      N_("Unknown"),
 41      N_("Visible"),
 42      N_("Daylight"),
 43      N_("Eclipsed")
 44  };
 45  
 46  
 47  
 48  /** \brief Calculate satellite visibility.
 49   *  \param sat The satellite structure.
 50   *  \param qth The QTH
 51   *  \param jul_utc The time at which the visibility should be calculated.
 52   *  \return The visibility code.
 53   *
 54   */
 55  sat_vis_t
 56  get_sat_vis (sat_t *sat, qth_t *qth, gdouble jul_utc)
 57  {
 58      gboolean sat_sun_status;
 59      gdouble  sun_el;
 60      gdouble  threshold;
 61      gdouble  eclipse_depth;
 62      sat_vis_t vis = SAT_VIS_NONE;
 63      vector_t zero_vector = {0,0,0,0};
 64      geodetic_t obs_geodetic;
 65  
 66      /* Solar ECI position vector  */
 67      vector_t solar_vector=zero_vector;
 68  
 69      /* Solar observed az and el vector  */
 70      obs_set_t solar_set;
 71  
 72      /* FIXME: could be passed as parameter */
 73      obs_geodetic.lon = qth->lon * de2ra;
 74      obs_geodetic.lat = qth->lat * de2ra;
 75      obs_geodetic.alt = qth->alt / 1000.0;
 76      obs_geodetic.theta = 0;
 77  
 78  
 79      Calculate_Solar_Position (jul_utc, &solar_vector);
 80      Calculate_Obs (jul_utc, &solar_vector, &zero_vector, &obs_geodetic, &solar_set);
 81  
 82      if (Sat_Eclipsed (&sat->pos, &solar_vector, &eclipse_depth)) {
 83          /* satellite is eclipsed */
 84          sat_sun_status = FALSE;
 85      }
 86      else {
 87          /* satellite in sunlight => may be visible */
 88          sat_sun_status = TRUE;
 89      }
 90  
 91  
 92      if (sat_sun_status) {
 93          sun_el = Degrees (solar_set.el);
 94          threshold = (gdouble) sat_cfg_get_int (SAT_CFG_INT_PRED_TWILIGHT_THLD);
 95          
 96          if (sun_el <= threshold && sat->el >= 0.0)
 97              vis = SAT_VIS_VISIBLE;
 98          else
 99              vis = SAT_VIS_DAYLIGHT;
100      }
101      else
102          vis = SAT_VIS_ECLIPSED;
103  
104  
105      return vis;
106  }
107  
108  
109  
110  /** \brief Convert visibility to character code. */
111  gchar
112  vis_to_chr       (sat_vis_t vis)
113  {
114      return VIS2CHR[vis];
115  }
116  
117  
118  /** \brief Convert visibility to character string.
119   *  \param vis The visibility code
120   *
121   * The returned string must be freed when no longer needed.
122   */
123  gchar *
124  vis_to_str       (sat_vis_t vis)
125  {
126      return g_strdup (_(VIS2STR[vis]));
127  }
128