예제 #1
0
/*! determines qso points based on grid squares
 */
void Stew::addQso(Qso *qso)
{
    if (qso->band != BAND160) {
        qso->pts = 0;
        addQsoMult(qso);
        return; // not on 160, does not count
    }

    // qso points
    if (myGrid.size()) {
        double lat, lon;
        locator2longlat(&lon, &lat, qso->rcv_exch[0].data());
        lon *= -1.0;
        double dist, head;
        if (qrb(myLon * -1.0, myLat, lon * -1.0, lat, &dist, &head) != RIG_OK) {
            dist = 0.0;
        }
        qso->pts = ceil(dist / 500.0);
        if (qso->pts <= 0) qso->pts = 1;
    } else {
        // grid entered incorrectly
        qso->pts = 1;
    }
    if (qso->dupe || !qso->valid) qso->pts = 0;
    qsoPts += qso->pts;
    addQsoMult(qso);
}
예제 #2
0
파일: qth-data.c 프로젝트: csete/gpredict
/**
 * Compute the distance between a location in a qth_t structure and
 * qth_small_t structure.
 * 
 * \param qth the qth data structure
 * \param qth_small the data structure
 * 
 * This is intended for measuring distance between the current qth and
 * the position that tagged some data in qth_small.
 */
double qth_small_dist(qth_t * qth, qth_small_t qth_small)
{
    double          distance, azimuth;

    qrb(qth->lon, qth->lat, qth_small.lon, qth_small.lat, &distance, &azimuth);

    return (distance);
}
예제 #3
0
static bool run_query(ds::query::SqlDatabase& db,  const std::string& select, ds::query::Result& qr, const int flags = 0)
{
	qr.clear();
	if (select.empty()) return false;

	ds::query::SqlResultBuilder		qrb(qr, db.rawSelect(select));
	qrb.build((flags&ds::query::Client::INCLUDE_COLUMN_NAMES_F) != 0);
	return qrb.isValid();
}
예제 #4
0
/** \brief Compute the distance between a location in a qth_t structure and qth_small_t structure.
 * \param qth the qth data structure
 * \param qth_small the data structure
 * This is intended for measuring distance between the current qth and the position that tagged some data in qth_small.
 */
double qth_small_dist(qth_t * qth, qth_small_t qth_small)
{
    double distance, azimuth;

    /* FIXME Is this the right coordinate system to use? */
    /* a 3d coordinate system might make more sense long term */
    qrb(qth->lon, qth->lat, qth_small.lon, qth_small.lat, &distance, &azimuth);
    return (distance);
}
예제 #5
0
void Client::Request::run()
{
	int							errorCode = 0;
	SqlDatabase					resourceDB(mDatabase, SQLITE_OPEN_READONLY, &errorCode);
	if (errorCode != SQLITE_OK) {
		DS_DBG_CODE(std::cout << "ds::query::Client::Request: Unable to access the resource database (SQLite error " << errorCode << ").");
	} else {
		SqlResultBuilder		qrb(mResult, resourceDB.rawSelect(mQuery));
		qrb.build();

		ResultBuilder::setRequestTime(mResult, mRequestTime);
		ResultBuilder::setClientId(mResult, mRunId);
	}
}
예제 #6
0
파일: qrb.c 프로젝트: thatchristoph/tlf
int qrb_(double *range, double *bearing) {

    extern double QTH_Lat;
    extern double QTH_Long;
    extern double DEST_Lat;
    extern double DEST_Long;
    extern char hiscall[];

    if (*hiscall == '\0')
	return (0);

    return qrb(-1.0 * QTH_Long, QTH_Lat, -1.0 * DEST_Long, DEST_Lat,
	    range, bearing);
}
예제 #7
0
파일: testloc.c 프로젝트: DF4OR/hamlib
int main (int argc, char *argv[]) {
	char recodedloc[13], *loc1, *loc2, sign;
	double lon1, lat1, lon2, lat2;
	double distance, az, mmm, sec;
	int  deg, min, retcode, loc_len, nesw = 0;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <locator1> <precision> [<locator2>]\n", argv[0]);
		exit(1);
	}

	loc1 = argv[1];
       	loc_len = argc > 2 ? atoi(argv[2]) : strlen(loc1)/2;
	loc2 = argc > 3 ? argv[3] : NULL;

	printf("Locator1:\t%s\n", loc1);

        /* hamlib function to convert maidenhead to decimal degrees */
	retcode = locator2longlat(&lon1, &lat1, loc1);
	if (retcode != RIG_OK) {
		fprintf(stderr, "locator2longlat() failed with malformed input.\n");
		exit(2);
	}

        /* hamlib function to convert decimal degrees to deg, min, sec */
	retcode = dec2dms(lon1, &deg, &min, &sec, &nesw);
	if (retcode != RIG_OK) {
		fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
		exit(2);
	}
	if (nesw == 1)
		sign = '-';
	else
                sign = '\0';
	printf("  Longitude:\t%f\t%c%d %d' %.2f\"\n", lon1, sign, deg, min, sec);

        /* hamlib function to convert deg, min, sec to decimal degrees */
	lon1 = dms2dec(deg, min, sec, nesw);
	printf("  Recoded lon:\t%f\n", lon1);

        /* hamlib function to convert decimal degrees to deg decimal minutes */
	retcode = dec2dmmm(lon1, &deg, &mmm, &nesw);
	if (retcode != RIG_OK) {
		fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
		exit(2);
	}
	if (nesw == 1)
		sign = '-';
	else
                sign = '\0';
	printf("  GPS lon:\t%f\t%c%d %.3f'\n", lon1, sign, deg, mmm);

        /* hamlib function to convert deg, decimal min to decimal degrees */
	lon1 = dmmm2dec(deg, mmm, nesw);
	printf("  Recoded GPS:\t%f\n", lon1);

        /* hamlib function to convert decimal degrees to deg, min, sec */
	retcode = dec2dms(lat1, &deg, &min, &sec, &nesw);
	if (retcode != RIG_OK) {
		fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
		exit(2);
	}
	if (nesw == 1)
		sign = '-';
	else
                sign = '\0';
	printf("  Latitude:\t%f\t%c%d %d' %.2f\"\n", lat1, sign, deg, min, sec);

        /* hamlib function to convert deg, min, sec to decimal degrees */
	lat1 = dms2dec(deg, min, sec, nesw);
	printf("  Recoded lat:\t%f\n", lat1);

        /* hamlib function to convert decimal degrees to deg decimal minutes */
	retcode = dec2dmmm(lat1, &deg, &mmm, &nesw);
	if (retcode != RIG_OK) {
		fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
		exit(2);
	}
	if (nesw == 1)
		sign = '-';
	else
                sign = '\0';
	printf("  GPS lat:\t%f\t%c%d %.3f'\n", lat1, sign, deg, mmm);

        /* hamlib function to convert deg, decimal min to decimal degrees */
	lat1 = dmmm2dec(deg, mmm, nesw);
	printf("  Recoded GPS:\t%f\n", lat1);

        /* hamlib function to convert decimal degrees to maidenhead */
	retcode = longlat2locator(lon1, lat1, recodedloc, loc_len);
	if (retcode != RIG_OK) {
		fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
		exit(2);
	}
	printf("  Recoded:\t%s\n", recodedloc);

	if (loc2 == NULL)
		exit(0);

	/* Now work on the second locator */
	printf("\nLocator2:\t%s\n", loc2);

	retcode = locator2longlat(&lon2, &lat2, loc2);
	if (retcode != RIG_OK) {
		fprintf(stderr, "locator2longlat() failed with malformed input.\n");
		exit(2);
	}

	/* hamlib function to convert decimal degrees to deg, min, sec */
	retcode = dec2dms(lon2, &deg, &min, &sec, &nesw);
	if (retcode != RIG_OK) {
		fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
		exit(2);
	}
	if (nesw == 1)
		sign = '-';
	else
                sign = '\0';
	printf("  Longitude:\t%f\t%c%d %d' %.2f\"\n", lon2, sign, deg, min, sec);

	/* hamlib function to convert deg, min, sec to decimal degrees */
	lon2 = dms2dec(deg, min, sec, nesw);
	printf("  Recoded lon:\t%f\n", lon2);

	/* hamlib function to convert decimal degrees to deg decimal minutes */
	retcode = dec2dmmm(lon2, &deg, &mmm, &nesw);
	if (retcode != RIG_OK) {
		fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
		exit(2);
	}
	if (nesw == 1)
		sign = '-';
	else
                sign = '\0';
	printf("  GPS lon:\t%f\t%c%d %.3f'\n", lon2, sign, deg, mmm);

	/* hamlib function to convert deg, decimal min to decimal degrees */
	lon2 = dmmm2dec(deg, mmm, nesw);
	printf("  Recoded GPS:\t%f\n", lon2);

	/* hamlib function to convert decimal degrees to deg, min, sec */
	retcode = dec2dms(lat2, &deg, &min, &sec, &nesw);
	if (retcode != RIG_OK) {
		fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
		exit(2);
	}
	if (nesw == 1)
		sign = '-';
	else
                sign = '\0';
	printf("  Latitude:\t%f\t%c%d %d' %.2f\"\n", lat2, sign, deg, min, sec);

	/* hamlib function to convert deg, min, sec to decimal degrees */
	lat2 = dms2dec(deg, min, sec, nesw);
	printf("  Recoded lat:\t%f\n", lat2);

	/* hamlib function to convert decimal degrees to deg decimal minutes */
	retcode = dec2dmmm(lat2, &deg, &mmm, &nesw);
	if (retcode != RIG_OK) {
		fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
		exit(2);
	}
	if (nesw == 1)
		sign = '-';
	else
                sign = '\0';
	printf("  GPS lat:\t%f\t%c%d %.3f'\n", lat2, sign, deg, mmm);

        /* hamlib function to convert deg, decimal min to decimal degrees */
	lat2 = dmmm2dec(deg, mmm, nesw);
	printf("  Recoded GPS:\t%f\n", lat2);

        /* hamlib function to convert decimal degrees to maidenhead */
	retcode = longlat2locator(lon2, lat2, recodedloc, loc_len);
	if (retcode != RIG_OK) {
		fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
		exit(2);
	}
	printf("  Recoded:\t%s\n", recodedloc);

	retcode = qrb(lon1, lat1, lon2, lat2, &distance, &az);
	if (retcode != RIG_OK) {
		fprintf(stderr, "QRB error: %d\n", retcode);
		exit(2);
	}

	dec2dms(az, &deg, &min, &sec, &nesw);
	printf("\nDistance: %.6fkm\n", distance);
	if (nesw == 1)
		sign = '-';
	else
		sign = '\0';
        /* Beware printf() rounding error! */
	printf("Bearing: %.2f, %c%d %d' %.2f\"\n", az, sign, deg, min, sec);

	exit(0);
}
예제 #8
0
파일: main.c 프로젝트: patlc/tlf
int main(int argc, char *argv[])
{
    int j;
    pthread_t thrd1, thrd2;
    int ret;
    int retval;
    char keyerbuff[3];
    char tlfversion[80] = "";
    int status;

    while ((argc > 1) && (argv[1][0] == '-')) {
	switch (argv[1][1]) {
	    /* verbose option */
	case 'f':
	    if (strlen(argv[1] + 2) > 0) {
		if ((*(argv[1] + 2) == '~') && (*(argv[1] + 3) == '/')) {
		    /* tilde expansion */
		    config_file = g_strconcat( g_get_home_dir(),
			    argv[1] + 3, NULL);
		}
	    	else {
		    config_file = g_strdup(argv[1] + 2);
		}
	    }
	    break;
	case 's':
	    if (strlen(argv[1] + 2) > 0)
		strcpy(synclogfile, argv[1] + 2);
	    break;
	case 'd':		// debug rigctl
	    debugflag = 1;
	    break;
	case 'v':		// verbose startup
	    verbose = 1;
	    break;
	case 'V':		// output version
	    printf("Version: tlf-%s\n", VERSION);
	    exit(0);
	    break;
	case 'n':		// output version
	    nopacket = 1;
	    break;
	default:
	    printf("Use: tlf [-v] Verbose\n");
	    printf("         [-V] Version\n");
	    printf("         [-f] Configuration file\n");
	    printf("         [-d] Debug mode\n");
	    printf("         [-h] This message\n");
	    printf("         [-n] Start without cluster hookup\n");
	    exit(0);
	    break;
	}
	--argc;
	++argv;
    }

    buffer[0] = '\0';
    buffer[79] = '\0';
    bufloc = 0;

    strcat(logline0, backgrnd_str);
    strcat(logline1, backgrnd_str);
    strcat(logline2, backgrnd_str);
    strcat(logline3, backgrnd_str);
    strcat(logline4, backgrnd_str);

    strcat(terminal1, backgrnd_str);
    strcat(terminal2, backgrnd_str);
    strcat(terminal3, backgrnd_str);
    strcat(terminal4, backgrnd_str);

    termbuf[0] = '\0';
    hiscall[0] = '\0';

/* getting users terminal string and (if RXVT) setting rxvt colours on it */
/* LZ3NY hack :) */
    if (strcasecmp(getenv("TERM"), "rxvt") == 0) {
	use_rxvt = 1;
	printf("terminal is:%s", getenv("TERM"));
    } else if (strcasecmp(getenv("TERM"), "xterm") == 0) {
	use_xterm = 1;
	use_rxvt = 1;
    } else
	putenv("TERM=rxvt");	/*or going to native console linux driver */

    if ((mainscreen = newterm(NULL, stdout, stdin)) == NULL) {	/* activate ncurses terminal control */
	perror("initscr");
	printf
	    ("\n Sorry, wrong terminal type !!!!! \nTry a  linux text terminal or set TERM=linux !!!");
	sleep(5);

	exit(EXIT_FAILURE);
    }
//keypad(stdscr,TRUE);

    InitSearchPanel();	/* at least one panel has to be defined
				   for refreshp() to work */

    getmaxyx(stdscr, ymax, xmax);
    if ((ymax < 25) || (xmax < 80)) {
	char c;

	showmsg( "!! TLF needs at least 25 lines and 80 columns !!");
	showmsg( "   Continue anyway? Y/(N)" );
	c = toupper( getch() );
	if (c != 'Y') {
	    showmsg( "73 es cuagn" );
	    sleep(1);
	    endwin();
	    exit(1);
	}
	showmsg("");
    }

    noecho();
    crmode();

    strcpy(sp_return, message[12]);
    strcpy(cq_return, message[13]);

    refreshp();

    if (has_colors()) {
	if (start_color() == ERR) {
	    perror("start_color");
	    endwin();
	    printf
		("\n Sorry, wrong terminal type !!!!! \n\nTry a linux text terminal or set TERM=linux !!!");
	    sleep(5);
	    exit(EXIT_FAILURE);
	}

	sprintf(tlfversion,
		"        Welcome to tlf-%s by PA0R!!" , VERSION);
	showmsg(tlfversion);
	showmsg("");

	showmsg("reading country data");
	readctydata();		/* read ctydb.dat */

	showmsg("reading configuration data");

	status = read_logcfg(); /* read the configuration file */
	status |= read_rules();	/* read the additional contest rules in "rules/contestname"  LZ3NY */

	if (status != PARSE_OK) {
	    showmsg( "Problems in logcfg.dat or rule file detected! Continue Y/(N)?");
	    if (toupper( getchar() ) != 'Y') {
		endwin();
		exit(1);
	    }
	}

	/* make sure logfile is there and has the right format */
	if (checklogfile_new(logfile) != 0) {
	    showmsg( "Giving up" );
	    sleep(2);
	    endwin();
	    exit(1);
	}

//              if (strlen(synclogfile) > 0)
//                      synclog(synclogfile);

	if (*call == '\0') {
	    showmsg
		("WARNING: No callsign defined in logcfg.dat! exiting...\n\n\n");
	    exit(1);
	}

	if (use_rxvt == 1) {	// use rxvt colours
	    init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_RED);
	    if (use_xterm == 1) {
		init_pair(C_HEADER, COLOR_GREEN, COLOR_BLUE);
		init_pair(COLOR_RED, COLOR_WHITE, 8);
		init_pair(C_WINDOW, COLOR_CYAN, COLOR_MAGENTA);
		init_pair(C_DUPE, COLOR_WHITE, COLOR_MAGENTA);
		init_pair(C_INPUT, COLOR_BLUE, COLOR_WHITE);
	    } else {
		init_pair(C_HEADER, COLOR_GREEN, COLOR_YELLOW);
		init_pair(COLOR_RED, COLOR_WHITE, COLOR_RED);
		init_pair(C_WINDOW, COLOR_CYAN, COLOR_RED);
		init_pair(C_DUPE, COLOR_RED, COLOR_MAGENTA);
		init_pair(C_INPUT, COLOR_BLUE, COLOR_YELLOW);
	    }
	    init_pair(C_LOG, COLOR_WHITE, COLOR_BLACK);
	    init_pair(C_BORDER, COLOR_CYAN, COLOR_YELLOW);
	} else {
	    // use linux console colours
	    init_pair(COLOR_BLACK, tlfcolors[0][0], tlfcolors[0][1]); // b/w
	    init_pair(C_HEADER, tlfcolors[1][0], tlfcolors[1][1]);    // Gn/Ye
	    init_pair(COLOR_RED, tlfcolors[2][0], tlfcolors[2][1]);   // W/R
	    init_pair(C_WINDOW, tlfcolors[3][0], tlfcolors[3][1]);    // Cy/W
	    init_pair(C_LOG, tlfcolors[4][0], tlfcolors[4][1]);       // W/B
	    init_pair(C_DUPE, tlfcolors[5][0], tlfcolors[5][1]);      // W/Mag
	    init_pair(C_INPUT, tlfcolors[6][0], tlfcolors[6][1]);     // Bl/Y
	    init_pair(C_BORDER, tlfcolors[7][0], tlfcolors[7][1]);    // W/B
	}

	mults_possible = g_ptr_array_new();

	if (multlist == 1) {
	    showmsg("reading multiplier data      ");
	    load_multipliers();

	}

	attron(COLOR_PAIR(COLOR_BLACK));
	showmsg("reading callmaster data");

	nr_callmastercalls = load_callmaster();

	if (*exchange_list != '\0') {
	    // read initial exchange file
	    main_ie_list = make_ie_list(exchange_list);
	    if (main_ie_list == NULL) {
		showmsg( "Problems in initial exchange file detected! Continue Y/(N)?");
		if (toupper( getchar() ) != 'Y') {
		    endwin();
		    exit(1);
		}
		else {
		    showmsg( "Initial exchange data not loaded! Continuing ...");
		    sleep(2);
		}
	    }
	}

#ifdef HAVE_LIBHAMLIB		// Code for hamlib interface

	showmsg("HAMLIB defined");

	if (trx_control != 0) {

	    shownr("Rignumber is", (int) myrig_model);
	    shownr("Rig speed is", serial_rate);

	    showmsg("Trying to start rig ctrl");

	    /** \todo fix exclusion of newer hamlib models */
	    if ((int) myrig_model > 1999)
		status = init_native_rig();
	    else
		status = init_tlf_rig();
	}
#else
	if (trx_control != 0) {
//                      trx_control = 0;
	    showmsg("No Hamlib library, using native driver");
	    shownr("Rignumber is", rignumber);
	    shownr("Rig speed is", serial_rate);
	    status = init_native_rig();
	    sleep(1);
	}
#endif				// end code for hamlib interface

	if (status  != 0) {
	    showmsg( "Continue without rig control Y/(N)?");
	    if (toupper( getchar() ) != 'Y') {
		endwin();
		exit(1);
	    }
	    trx_control = 0;
	    showmsg( "Disabling rig control!");
	    sleep(1);
	}


	if (keyerport == NET_KEYER) {
	    showmsg("Keyer is cwdaemon");
	}
	if (keyerport == MFJ1278_KEYER || keyerport == GMFSK) {
	    init_controller();
	}

	if (lan_active == 1) {
	    retval = lanrecv_init();

	    if (retval < 0)	/* set up the network */
		shownr("LAN receive  init failed", retval);
	    else
		showmsg("LAN receive  initialized");

	    if (lan_send_init() < 0)
		showmsg("LAN send init failed");
	    else
		showmsg("LAN send initialized");
	}

	checkparameters();	/* check .paras file */

	clear();
	mvprintw(0, 0, "        Welcome to tlf-%s by PA0R!!\n\n" , VERSION);
	refreshp();
	getmessages();		/* read .paras file */

	if (nopacket == 1)
	    packetinterface = 0;

	set_term(mainscreen);

	refreshp();

	if ((nopacket == 0) && (packetinterface != 0)) {

	    if (init_packet() == 0)
		packet();
	    else
		cleanup_telnet();

	}

	if (keyerport == NET_KEYER) {
	    if (netkeyer_init() < 0) {
		mvprintw(24, 0, "Cannot open NET keyer daemon ");
		refreshp();
		sleep(1);

	    } else {
		netkeyer(K_RESET, "0");

		sprintf(weightbuf, "%d", weight);

		write_tone();

		snprintf(keyerbuff, 3, "%2d", GetCWSpeed());
		netkeyer(K_SPEED, keyerbuff);		// set speed

		netkeyer(K_WEIGHT, weightbuf);		// set weight

		if (*keyer_device != '\0')
		    netkeyer(K_DEVICE, keyer_device);	// set device

		sprintf(keyerbuff, "%d", txdelay);
		netkeyer(K_TOD, keyerbuff);		// set TOD

		if (sc_sidetone != 0)			// set soundcard output
		    netkeyer(K_SIDETONE, "");

		if (*sc_volume != '\0')			// set soundcard volume
			netkeyer(K_STVOLUME, sc_volume);
	    }

	    if (keyerport != NET_KEYER)
		write_tone();
	}

	getwwv();		/* get the latest wwv info from packet */

	scroll_log();		/* read the last 5  log lines and set the qso number */

	nr_qsos = readcalls();	/* read the logfile for score and dupe */

	clear_display();	/* tidy up the display */

	qrb();

	attron(COLOR_PAIR(C_LOG) | A_STANDOUT);

	for (j = 13; j <= 23; j++) {	/* wipe lower window */
	    mvprintw(j, 0, backgrnd_str);
	}

	bm_init();			/* initialize bandmap */

	/* Create the first thread */
	ret = pthread_create(&thrd1, NULL, (void *) logit, NULL);
	if (ret) {
	    perror("pthread_create: logit");
	    endwin();
	    exit(EXIT_FAILURE);
	}

	/* Create the second thread */
	ret =
	    pthread_create(&thrd2, NULL, (void *) background_process,
			   NULL);
	if (ret) {
	    perror("pthread_create: backgound_process");
	    endwin();
	    exit(EXIT_FAILURE);
	}

	pthread_join(thrd2, NULL);
	pthread_join(thrd1, NULL);
	endwin();
	exit(EXIT_SUCCESS);

    } else {
	printf("Terminal does not support color\n");
	printf("\nTry TERM=linux  or use a text console !!\n");
	refreshp();
	sleep(2);
    }
    cleanup_telnet();

    if (trxmode == CWMODE && keyerport == NET_KEYER)
	netkeyer_close();
    else
	close(cfd);		/* close keyer */

    endwin();

    return (0);
}
예제 #9
0
/*! parses .cty file, makes country list

      -  lat=latitude of station +=N
   -  lon=longitude of station +=W
   -  ZoneType: 0: read CQ zones/countries  1: read ITU zones/ARRL countries

 */
void Cty::initialize(double la, double lo, int ZoneType)
{
/*! CTY file format

   Column   Length      Description

   -    1           26  country Name
   -    27          5   CQ Zone
   -    32          5   ITU Zone
   -    37          5   2-letter continent abbreviation
   -    42          9   Latitude in degrees, + for North
   -    51          10  Longitude in degrees, + for West
   -    61          9   Local time offset from GMT
   -    70          6   Primary DXCC Prefix (A "*" preceding this prefix indicates
                        that the country is on the DARC WAEDC list, and counts in
                        CQ-sponsored contests, but not ARRL-sponsored contests).
 */
    double mylat=la;
    double mylon=lo;

    QFile file(dataDirectory()+"/"+settings.value(c_cty,c_cty_def).toString());
    int   indx;

    // sunrise/sunset times for station
    sunTimes(mylat, mylon, mySun);

    // sunrise/sunset times and bearings for CQ or ITU zones. These are used for
    // certain countries that span many zones
    QString zoneFileName;
    switch (ZoneType) {
    case 0:zoneFileName=dataDirectory()+"/cq_zone_latlong.dat";break;
    case 1:zoneFileName=dataDirectory()+"/itu_zone_latlong.dat";break;
    }
    QFile file2(zoneFileName);
    if (file2.open(QIODevice::ReadOnly | QIODevice::Text)) {
        // add blank for 0, zones start with 1
        zoneBearing.append(0);
        zoneSun.append("");
        while (!file2.atEnd()) {
            QString buffer;
            buffer=file2.readLine(80);
            if (buffer.contains('#')) continue; // #=comment line

            buffer=buffer.trimmed();
            QStringList field = buffer.split(" ", QString::SkipEmptyParts);
            double lat=field.at(1).toDouble();
            double lon=field.at(2).toDouble();
            QString sunTime;
            QString set;
            sunTimes(lat, -lon, sunTime);
            zoneSun.append(sunTime);

            double dist;
            double head;
            qrb(mylon * -1.0, mylat, lon , lat, &dist, &head);
            zoneBearing.append(qRound(head));
        }
        file2.close();
    } else {
        // file missing, just make these blank
        int nz=40;
        if (ZoneType==1) nz=80;
        for (int i=0;i<nz;i++) {
            zoneBearing.append(0);
            zoneSun.append("ERR");
        }
    }
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QString tmp = "ERROR: can't open file " + settings.value(c_cty,c_cty_def).toString();
        emit(ctyError(tmp));
        return;
    }
    nARRLCty = 0;
    nCQCty   = 0;
    indx     = 0;

    while (!file.atEnd()) {
        QByteArray buffer, tmp, tmp2, buffer_a, buffer_e;
        int        i0, i1, i2, i3, i4, cqz, ituz;

        // get one record
        // all records are at least one line
        buffer = file.readLine();
        tmp    = file.readLine();
        buffer_e.clear();

        // zone exceptions for main pfx
        while (tmp.contains("#")) {
            buffer_e.append(tmp);
            while (!tmp.contains(";")) {
                tmp = file.readLine();
                buffer_e.append(tmp);
            }
            tmp = file.readLine();
        }

        // alias pfx; may include zone exceptions as well
        buffer_a = tmp;
        while (!tmp.contains(";")) {
            tmp = file.readLine();
            buffer_a.append(tmp);
        }
        buffer   = buffer.trimmed();
        buffer_a = buffer_a.trimmed();
        buffer_e = buffer_e.trimmed();

        // now process parts
        // main line
        Country* new_country = new Country;
        new_country->multipleZones = false;
        new_country->indx          = indx;

        i1                = buffer.indexOf(":", 0);
        new_country->name = buffer.mid(0, i1);

        // insert some common abbrieviations (I=Island,...)
        // to save screen space
        if (new_country->name.contains("Island")) {
            new_country->name.replace("Island", "I");
        }
        i2 = buffer.indexOf(":", i1 + 1);
        int cqzone = buffer.mid(i1 + 1, i2 - i1 - 1).toInt();

        i1 = buffer.indexOf(":", i2 + 1);
        int ituzone = buffer.mid(i2 + 1, i1 - i2 - 1).toInt();
        if (ZoneType) {
            new_country->Zone = ituzone;
        } else {
            new_country->Zone = cqzone;
        }
        i2  = buffer.indexOf(":", i1 + 1);
        tmp = buffer.mid(i1 + 1, i2 - i1 - 1);

        tmp = tmp.trimmed();
        if (tmp == "NA") {
            new_country->Continent = NA;
        } else if (tmp == "SA") {
            new_country->Continent = SA;
        } else if (tmp == "EU") {
            new_country->Continent = EU;
        } else if (tmp == "AF") {
            new_country->Continent = AF;
        } else if (tmp == "AS") {
            new_country->Continent = AS;
        } else if (tmp == "OC") {
            new_country->Continent = OC;
        }
        i1 = buffer.indexOf(":", i2 + 1);
        double lat = buffer.mid(i2 + 1, i1 - i2 - 1).trimmed().toFloat();

        i2 = buffer.indexOf(":", i1 + 1);
        double lon = buffer.mid(i1 + 1, i2 - i1 - 1).trimmed().toFloat();

        double dist;
        double head;
        qrb(mylon * -1.0, mylat, lon * -1.0, lat, &dist, &head);
        new_country->bearing = qRound(head); // round azimuth to nearest degree
        sunTimes(lat, lon, new_country->sun);

        i1                   = buffer.indexOf(":", i2 + 1);
        new_country->delta_t = buffer.mid(i2 + 1, i1 - i2 - 1).trimmed().toFloat();

        i2                   = buffer.indexOf(":", i1 + 1);
        new_country->MainPfx = buffer.mid(i1 + 1, i2 - i1 - 1);
        new_country->MainPfx = new_country->MainPfx.trimmed();

        if (new_country->MainPfx.contains("*")) {
            if (ZoneType == 0) {
                // CQ country
                new_country->MainPfx.replace("*", "");
                nCQCty++;
            } else {
                // only keeping ARRL countries, skip this one
                delete new_country;
                continue;
            }
        } else {
            nARRLCty++;
        }

        // country has multiple zones?
        if (buffer_e != "") {
            new_country->multipleZones = true;
            QList<QByteArray> tmpl = buffer_e.split(';');
            tmpl.removeLast();  // for some reason get 1 too many here
            for (int i = 0; i < tmpl.size(); i++) {
                i1 = tmpl[i].indexOf("#");
                i2 = tmpl[i].indexOf(":");
                QByteArray pf = tmpl[i].mid(i1 + 1, i2 - i1 - 1);
                pf = pf.trimmed();

                // remove any final digit in the prefix
                if (isDigit(pf.at(pf.size() - 1))) {
                    pf.chop(1);
                }

                // remove initial pfx and final ;
                tmpl[i] = tmpl[i].mid(i2 + 1, tmpl[i].size() - 2);
                QList<QByteArray> tmpl2 = tmpl[i].split(',');  // separate
                for (int j = 0; j < tmpl2.size(); j++) {
                    tmpl2[j] = tmpl2[j].trimmed();
                    tmpl2[j].replace(pf, "");

                    // does it have a ITU zone exception?
                    ituz = 0;
                    if (tmpl2[j].contains("[")) {
                        i3 = tmpl2[j].indexOf("[");
                        i4 = tmpl2[j].indexOf("]");
                        if (i3 != -1 && i4 != -1) {
                            tmp2     = tmpl2[j].mid(i3 + 1, i4 - i3 - 1);
                            ituz     = tmp2.toInt();
                            tmp2     = tmpl2[j].mid(i3, i4 - i3 + 1);
                            tmpl2[j] = tmpl2[j].replace(tmp2, "");
                        }
                    }
                    cqz = 0;

                    // does it have a CQ zone exception?
                    if (tmpl2[j].contains("(")) {
                        i3 = tmpl2[j].indexOf("(");
                        i4 = tmpl2[j].indexOf(")");
                        if (i3 != -1 && i4 != -1) {
                            tmp2     = tmpl2[j].mid(i3 + 1, i4 - i3 - 1);
                            cqz      = tmp2.toInt();
                            tmp2     = tmpl2[j].mid(i3, i4 - i3 + 1);
                            tmpl2[j] = tmpl2[j].replace(tmp2, "");
                        }
                    }
                    new_country->zonePfx.append(tmpl2[j]);
                    if (ZoneType) {
                        if (ituz) {
                            new_country->zones.append(ituz);
                        } else {
                            new_country->zones.append(ituzone);
                        }
                    } else {
                        if (cqz) {
                            new_country->zones.append(cqz);
                        } else {
                            new_country->zones.append(cqzone);
                        }
                    }
                }
            }
        }

        // alias prefixes, may include zone exceptions
        i1 = 0;
        i2 = buffer_a.indexOf(",", i1 + 1);
        if (i2 == -1) i2 = buffer_a.size() - 1;
        int nalias = 0;
        while (i1 < (buffer_a.size() - 1)) {
            tmp = buffer_a.mid(i1, i2 - i1);
            tmp = tmp.trimmed();
            if (tmp.startsWith("=")) {
                i0 = 1; // call exception
            } else {
                i0 = 0; // alias prefix
                nalias++;
            }
            ituz = -1; // -1 is marker to use regular zone in pfx list
            cqz  = -1;

            // does it have a ITU zone exception?
            if (tmp.contains("[")) {
                i3 = tmp.indexOf("[");
                i4 = tmp.indexOf("]");
                if (i3 != -1 && i4 != -1) {
                    tmp2 = tmp.mid(i3 + 1, i4 - i3 - 1);
                    ituz = tmp2.toInt();
                    tmp2 = tmp.mid(i3, i4 - i3 + 1);
                    tmp  = tmp.replace(tmp2, "");
                }
            }

            // does it have a CQ zone exception?
            if (tmp.contains("(")) {
                i3 = tmp.indexOf("(");
                i4 = tmp.indexOf(")");
                if (i3 != -1 && i4 != -1) {
                    tmp2 = tmp.mid(i3 + 1, i4 - i3 - 1);
                    cqz  = tmp2.toInt();
                    tmp2 = tmp.mid(i3, i4 - i3 + 1);
                    tmp  = tmp.replace(tmp2, "");
                }
            }

            if (!i0) {
                // new alias prefix
                Pfx* new_pfx = new Pfx;
                new_pfx->CtyIndx      = indx;
                new_pfx->zoneOverride = true;
                if (ZoneType) {
                    new_pfx->Zone = ituz;
                } else {
                    new_pfx->Zone = cqz;
                }
                if (new_pfx->Zone == -1) {
                    new_pfx->Zone         = new_country->Zone;
                    new_pfx->zoneOverride = false;
                }

                new_pfx->prefix = tmp;
                pfxList.append(new_pfx);
            } else {
                // new exception call
                CtyCall* new_call = new CtyCall;
                new_call->call = tmp.right(tmp.size() - 1);
                if (ZoneType) {
                    if (ituz != -1) {
                        new_call->Zone = ituz;
                    } else {
                        new_call->Zone = new_country->Zone;
                    }
                } else {
                    if (cqz != -1) {
                        new_call->Zone = cqz;
                    } else {
                        new_call->Zone = new_country->Zone;
                    }
                }
                if (cqz == -1 && ituz == -1) {
                    // it NEITHER zone was defined, add call to exception list
                    // (with default zones set above). This is mostly for weird/unexpected calls
                    new_call->CtyIndx = indx;
                    new_call->sun=new_country->sun;
                    CallE.append(new_call);
                } else if ((!ZoneType && cqz == -1) || (ZoneType && ituz == -1)) {
                    // the exception doesn't have ONE of the zones defined, remove it
                    // (some entries in cty file only have CQ or ITU zones defined, but
                    // not both. In IARU contest for example, do not want CQ zone exceptions
                    // to be kept
                    delete new_call;
                } else {
                    new_call->CtyIndx = indx;
                    new_call->sun=zoneSun.at(new_call->Zone);
                    CallE.append(new_call);
                }
            }

            i1 = i2 + 1;
            i2 = buffer_a.indexOf(",", i1 + 1);
            if (i2 == -1) {
                i2 = buffer_a.size() - 1;
            }
        }
        countryList.append(new_country);

        // special case: some countries (4U1U, ...) have no alias prefixes listed, only exception calls.
        // make sure to add to main pfx list!
        if (nalias == 0) {
            Pfx* new_pfx = new Pfx;
            new_pfx->zoneOverride = false;
            new_pfx->CtyIndx      = indx;
            if (ZoneType) {
                new_pfx->Zone = ituz;
            } else {
                new_pfx->Zone = cqz;
            }
            if (new_pfx->Zone == -1) {
                new_pfx->Zone = new_country->Zone;
            }
            new_pfx->prefix = new_country->MainPfx;
            pfxList.append(new_pfx);
        }

        indx++;
    }

    /*!
       @todo define < operator so qsort can be used sort prefix and call exception lists
     */

    // prefix
    for (int i = 1; i < pfxList.size(); i++) {
        QByteArray tmp = pfxList[i]->prefix;
        int        i0  = pfxList[i]->Zone;
        int        i1  = pfxList[i]->CtyIndx;
        bool       i2  = pfxList[i]->zoneOverride;
        int        j   = i - 1;
        while (j >= 0 && pfxList[j]->prefix > tmp) {
            pfxList[j + 1]->prefix       = pfxList[j]->prefix;
            pfxList[j + 1]->Zone         = pfxList[j]->Zone;
            pfxList[j + 1]->CtyIndx      = pfxList[j]->CtyIndx;
            pfxList[j + 1]->zoneOverride = pfxList[j]->zoneOverride;
            j--;
        }
        pfxList[j + 1]->prefix       = tmp;
        pfxList[j + 1]->Zone         = i0;
        pfxList[j + 1]->CtyIndx      = i1;
        pfxList[j + 1]->zoneOverride = i2;
    }

    // exception
    for (int i = 1; i < CallE.size(); i++) {
        QByteArray tmp = CallE[i]->call;
        QString suntmp= CallE[i]->sun;
        int        i0  = CallE[i]->Zone;
        int        i1  = CallE[i]->CtyIndx;
        int        j   = i - 1;
        while (j >= 0 && CallE[j]->call > tmp) {
            CallE[j + 1]->call    = CallE[j]->call;
            CallE[j + 1]->sun    = CallE[j]->sun;
            CallE[j + 1]->Zone    = CallE[j]->Zone;
            CallE[j + 1]->CtyIndx = CallE[j]->CtyIndx;
            j--;
        }
        CallE[j + 1]->call    = tmp;
        CallE[j + 1]->sun    = suntmp;
        CallE[j + 1]->Zone    = i0;
        CallE[j + 1]->CtyIndx = i1;
    }

    // save index for US
    Qso  tmpqso;
    tmpqso.call = "W1AW";
    bool b;
    usaIndx = idPfx(&tmpqso, b);
}
예제 #10
0
파일: showinfo.c 프로젝트: patlc/tlf
int showinfo(int x)
{

    extern int use_rxvt;
    extern char cqzone[];
    extern char ituzone[];
    extern char C_DEST_Lat[];
    extern char C_DEST_Long[];
    extern double bearing;
    extern double range;
    extern int timeoffset;
    extern int timecorr;
    extern char itustr[];
    extern int mycountrynr;

    int cury, curx;
    char pxstr[16];
    char countrystr[26];
    char zonestr[3];
    char contstr[3] = "";
    char timebuff[80];

    dxcc_data *dx;
    double d;
    time_t now;
    struct tm *ptr1;

    dx = dxcc_by_index(x);

    strcpy(pxstr, dx->pfx);
    strcpy(countrystr, dx->countryname);	/* country */

    if (strlen(cqzone) < 2) {
	sprintf(zonestr, "%02d", dx->cq); 	/* cqzone */
	strcpy(cqzone, zonestr);
    } else {
	strncpy(zonestr, cqzone, 2);
	zonestr[2] = '\0';
    }

    if (strlen(ituzone) < 2) {
	sprintf(itustr, "%02d", dx->itu);	/* itu zone */
    } else {
	strncpy(itustr, ituzone, 2);
	itustr[2] = '\0';
    }

    d = dx->timezone;				/* GMT difference */

    now = (time(0) + ((timeoffset - d) * 3600) + timecorr);
    ptr1 = gmtime(&now);
    strftime(timebuff, 80, "%H:%M", ptr1);

    sprintf(C_DEST_Lat, "%6.2f", dx->lat);	/* where is he? */
    sprintf(C_DEST_Long, "%7.2f", dx->lon);

    strncpy(contstr, dx->continent, 2);	/* continent */
    contstr[2] = '\0';

    getyx(stdscr, cury, curx);
    attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);

    mvprintw(24, 0, " %s  %s             ", pxstr, countrystr);

    mvprintw(24, 26,
	 " %s %s                                           ",
	 contstr, zonestr);

    if (x != 0 && x != mycountrynr) {
	qrb();
	mvprintw(24, 35, "%.0f km/%.0f deg ", range, bearing);
    }

    mvprintw(24, 64, "  DX time: %s", timebuff);
 
    if (use_rxvt == 0)
	attron(COLOR_PAIR(NORMCOLOR) | A_BOLD);
    else
	attron(COLOR_PAIR(NORMCOLOR));

    mvprintw(cury, curx, "");

    return (0);

}