Example #1
0
/*!
    Construct a GSM key filter and attach it to \a parent.
*/
GsmKeyFilter::GsmKeyFilter( QObject *parent )
    : QObject( parent )
{
    d = new GsmKeyFilterPrivate();

    // Add the standard call actions from GSM 02.30, section 4.5.5.
    addAction( "0", this, SIGNAL(setBusy()), Send | Incoming );
    addAction( QRegExp( "4\\*([0-9]+)" ), this, SIGNAL(deflect(QString)),
               Send | Incoming );
    addAction( "0", this, SIGNAL(releaseHeld()), Send | OnCall );
    addAction( "0", this, SIGNAL(releaseActive()), Send | Incoming );
    addAction( "1", this, SIGNAL(releaseAllAcceptIncoming()), Send | Incoming );
    addAction( "1", this, SIGNAL(releaseActive()), Send | OnCall );
    addAction( QRegExp( "1([1-9])" ), this, SLOT(releaseId(QString)),
               Send | OnCall );
    addAction( "2", this, SIGNAL(swap()), Send | OnCall );
    addAction( QRegExp( "2([1-9])" ), this, SLOT(activateId(QString)),
               Send | OnCall );
    addAction( "3", this, SIGNAL(join()), Send | OnCall );
    addAction( "4", this, SIGNAL(transfer()), Send | OnCall );
}
Example #2
0
/* fill equatoreal and horizontal op-> fields; stern
 *
 *    input:          lam/bet/rho geocentric mean ecliptic and equinox of day
 * 
 * algorithm at EOD:
 *   ecl_eq	--> ra/dec	geocentric mean equatoreal EOD (via mean obliq)
 *   deflect	--> ra/dec	  relativistic deflection
 *   nut_eq	--> ra/dec	geocentric true equatoreal EOD
 *   ab_eq	--> ra/dec	geocentric apparent equatoreal EOD
 *					if (PREF_GEO)  --> output
 *   ta_par	--> ra/dec	topocentric apparent equatoreal EOD
 *					if (!PREF_GEO)  --> output
 *   hadec_aa	--> alt/az	topocentric horizontal
 *   refract	--> alt/az	observed --> output
 *
 * algorithm at fixed equinox:
 *   ecl_eq	--> ra/dec	geocentric mean equatoreal EOD (via mean obliq)
 *   deflect	--> ra/dec	  relativistic deflection [for alt/az only]
 *   nut_eq	--> ra/dec	geocentric true equatoreal EOD [for aa only]
 *   ab_eq	--> ra/dec	geocentric apparent equatoreal EOD [for aa only]
 *   ta_par	--> ra/dec	topocentric apparent equatoreal EOD
 *     precess	--> ra/dec	topocentric equatoreal fixed equinox [eq only]
 *					--> output
 *   hadec_aa	--> alt/az	topocentric horizontal
 *   refract	--> alt/az	observed --> output
 */
static void
cir_pos (
Now *np,
double bet,	/* geo lat (mean ecliptic of date) */
double lam,	/* geo long (mean ecliptic of date) */
double *rho,	/* in: geocentric dist in AU; out: geo- or topocentic dist */
Obj *op)	/* object to set s_ra/dec as per equinox */
{
	double ra, dec;		/* apparent ra/dec, corrected for nut/ab */
	double tra, tdec;	/* astrometric ra/dec, no nut/ab */
	double lsn, rsn;	/* solar geocentric (mean ecliptic of date) */
	double ha_in, ha_out;	/* local hour angle before/after parallax */
	double dec_out;		/* declination after parallax */
	double dra, ddec;	/* parallax correction */
	double alt, az;		/* current alt, az */
	double lst;             /* local sidereal time */
	double rho_topo;        /* topocentric distance in earth radii */

	/* convert to equatoreal [mean equator, with mean obliquity] */
	ecl_eq (mjed, bet, lam, &ra, &dec);
	tra = ra;	/* keep mean coordinates */
	tdec = dec;

	/* precess and save astrometric coordinates */
	if (mjed != epoch)
	    precess (mjed, epoch, &tra, &tdec);
	op->s_astrora = tra;
	op->s_astrodec = tdec;

	/* get sun position */
	sunpos(mjed, &lsn, &rsn, NULL);

	/* allow for relativistic light bending near the sun.
	 * (avoid calling deflect() for the sun itself).
	 */
	if (!is_planet(op,SUN) && !is_planet(op,MOON))
	    deflect (mjed, op->s_hlong, op->s_hlat, lsn, rsn, *rho, &ra, &dec);

	/* correct ra/dec to form geocentric apparent */
	nut_eq (mjed, &ra, &dec);
	if (!is_planet(op,MOON))
	    ab_eq (mjed, lsn, &ra, &dec);
	op->s_gaera = ra;
	op->s_gaedec = dec;

	/* find parallax correction for equatoreal coords */
	now_lst (np, &lst);
	ha_in = hrrad(lst) - ra;
	rho_topo = *rho * MAU/ERAD;             /* convert to earth radii */
	ta_par (ha_in, dec, lat, elev, &rho_topo, &ha_out, &dec_out);

	/* transform into alt/az and apply refraction */
	hadec_aa (lat, ha_out, dec_out, &alt, &az);
	refract (pressure, temp, alt, &alt);
	op->s_alt = alt;
	op->s_az = az;

	/* Get parallax differences and apply to apparent or astrometric place
	 * as needed.  For the astrometric place, rotating the CORRECTIONS
	 * back from the nutated equator to the mean equator will be
	 * neglected.  This is an effect of about 0.1" at moon distance.
	 * We currently don't have an inverse nutation rotation.
	 */
	if (pref_get(PREF_EQUATORIAL) == PREF_GEO) {
	    /* no topo corrections to eq. coords */
	    dra = ddec = 0.0;
	} else {
	    dra = ha_in - ha_out;	/* ra sign is opposite of ha */
	    ddec = dec_out - dec;
	    *rho = rho_topo * ERAD/MAU; /* return topocentric distance in AU */

	    ra = ra + dra;
	    dec = dec + ddec;
	}
	range(&ra, 2*PI);
	op->s_ra = ra;
	op->s_dec = dec;
}
Example #3
0
static int
obj_fixed (Now *np, Obj *op)
{
	double lsn, rsn;	/* true geoc lng of sun, dist from sn to earth*/
	double lam, bet;	/* geocentric ecliptic long and lat */
	double ha;		/* local hour angle */
	double el;		/* elongation */
	double alt, az;		/* current alt, az */
	double ra, dec;		/* ra and dec at equinox of date */
	double rpm, dpm; 	/* astrometric ra and dec with PM to now */
	double lst;

	/* on the assumption that the user will stick with their chosen display
	 * epoch for a while, we move the defining values to match and avoid
	 * precession for every call until it is changed again.
	 * N.B. only compare and store jd's to lowest precission (f_epoch).
	 * N.B. maintaining J2k ref (which is arbitrary) helps avoid accum err
	 */
	if (0 /* disabled in PyEphem */
            && epoch != EOD && epoch != op->f_epoch) {
	    double pr = op->f_RA, pd = op->f_dec, fe = epoch;
	    /* first bring back to 2k */
	    precess (op->f_epoch, J2000, &pr, &pd);
	    pr += op->f_pmRA*(J2000-op->f_epoch);
	    pd += op->f_pmdec*(J2000-op->f_epoch);
	    /* then to epoch */
	    pr += op->f_pmRA*(fe-J2000);
	    pd += op->f_pmdec*(fe-J2000);
	    precess (J2000, fe, &pr, &pd);
	    op->f_RA = pr;
	    op->f_dec = pd;
	    op->f_epoch = fe;
	}

	/* apply proper motion .. assume pm epoch reference equals equinox */
	rpm = op->f_RA + op->f_pmRA*(mjd-op->f_epoch);
	dpm = op->f_dec + op->f_pmdec*(mjd-op->f_epoch);

	/* set ra/dec to astrometric @ equinox of date */
	ra = rpm;
	dec = dpm;
	if (op->f_epoch != mjed)
	    precess (op->f_epoch, mjed, &ra, &dec);

	/* compute astrometric @ requested equinox */
	op->s_astrora = rpm;
	op->s_astrodec = dpm;
	if (op->f_epoch != epoch)
	    precess (op->f_epoch, epoch, &op->s_astrora, &op->s_astrodec);

	/* convert equatoreal ra/dec to mean geocentric ecliptic lat/long */
	eq_ecl (mjed, ra, dec, &bet, &lam);

	/* find solar ecliptical long.(mean equinox) and distance from earth */
	sunpos (mjed, &lsn, &rsn, NULL);

	/* allow for relativistic light bending near the sun */
	deflect (mjed, lam, bet, lsn, rsn, 1e10, &ra, &dec);

	/* TODO: correction for annual parallax would go here */

	/* correct EOD equatoreal for nutation/aberation to form apparent 
	 * geocentric
	 */
	nut_eq(mjed, &ra, &dec);
	ab_eq(mjed, lsn, &ra, &dec);
	op->s_gaera = ra;
	op->s_gaedec = dec;

	/* set s_ra/dec -- apparent */
	op->s_ra = ra;
	op->s_dec = dec;

	/* compute elongation from ecliptic long/lat and sun geocentric long */
	elongation (lam, bet, lsn, &el);
	el = raddeg(el);
	op->s_elong = (float)el;

	/* these are really the same fields ...
	op->s_mag = op->f_mag;
	op->s_size = op->f_size;
	*/

	/* alt, az: correct for refraction; use eod ra/dec. */
	now_lst (np, &lst);
	ha = hrrad(lst) - ra;
	hadec_aa (lat, ha, dec, &alt, &az);
	refract (pressure, temp, alt, &alt);
	op->s_alt = alt;
	op->s_az = az;

	return (0);
}
int main(int argc, const char *argv[])
{
  float increment_x, increment_y;
  int pixel_x = 512, pixel_y = 512, it;
  unsigned int rpp = 500;
  int ncells = 4;
  float accuracy = 0.6;
  count = 0;
  root = NULL;
  curr = NULL;
  
  // Load relevant settings and data
  if (argc < 2) error("Requires argument with lens positions and optional mass");
  setup_constants();
  read_lenses(argv[1]);
  
  setup_root(-lens_rad, lens_rad, lens_rad, -lens_rad, ncells);
  
  build_tree(ncells, root);
  calculate_cm(root, ncells);

  //printf("All cells\n");
  //printf("index, centre mass x, centre mass y, total mass\n"); 
  remove_empty_cells(root, ncells);
  //print_tree(root, ncells);

  fprintf(stderr, "X %f and Y %f\n", image_scale_x, image_scale_y);
  increment_x = (image_scale_x * 2) / pixel_x;
  increment_y = (image_scale_y * 2) / pixel_y;
  fprintf(stderr, "Increments for X %f and Y %f\n", increment_x, increment_y);

  unsigned int *results = (int *)calloc(pixel_x * pixel_y, sizeof(unsigned int));
  if (!results) error("calloc failed in allocating the result array");
  int highest = 0;

  // Fire off the light rays and record their end locations
  int complete_iterations = 0;
  //#pragma omp parallel for
  for(it = 0; it < rpp; ++it) {
    float x, y, dx, dy;
    for(y = -image_scale_y; y < image_scale_y; y += increment_y) {
      for(x = -image_scale_x; x < image_scale_x; x += increment_x) {
        // Noise is uniformly distributed -- i.e. it's not really noise
        float noise_x = it * increment_x / rpp;
        float noise_y = it * increment_y / rpp;
        dx = x + noise_x;
        dy = y + noise_y;
        
        count_included_bodies(root, accuracy, dx, dy);
        cells = (cell *)malloc(sizeof(cell) * count);
        count = 0;
        get_included_bodies(root, accuracy, dx, dy);
        
        deflect(&dx, &dy);
        // Source plan (where collected) is -source_scale/2 to source_scale/2
        if ((dx > -source_scale/2) && (dx < source_scale/2) &&
            (dy > -source_scale/2) && (dy < source_scale/2)) {
          // Work out the nearest pixel to put this in to
          // Add to remove the negative part of source_scale and then source_scale / pixels
          int px = (dx + source_scale/2) / (source_scale/pixel_x);
          int py = source_scale/ (source_scale/pixel_y) - (dy + source_scale/2) / (source_scale/pixel_y);
          results[py * pixel_x + px] += 1;
          if (results[py * pixel_x + px] > highest) highest = results[py * pixel_x + px];
        }
        count = 0;
        free(cells);
		cells = NULL;
      }
    }
     	fprintf(stderr, "\r%4d/%4d Complete\r", ++complete_iterations, rpp);
  }
  assert(highest > 0 && "No pixels were written on the output map");
  write_pgm(results, pixel_x, pixel_y, highest);
  
  // Free the memory allocated during processing
  free(lens_x);
  free(lens_y);
  free(lens_mass);
  free(results);
  free(curr);

  return 0;
}