* \brief Pretty print a frequency * \param str for result (may need up to 17 char) * \param freq input in Hz * * rig_freq_snprintf? * pretty print frequencies * str must be long enough. max can be as long as 17 chars */
| 382 | * str must be long enough. max can be as long as 17 chars |
| 383 | */ |
| 384 | int HAMLIB_API sprintf_freq(char *str, int str_len, freq_t freq) |
| 385 | { |
| 386 | double f; |
| 387 | const char *hz; |
| 388 | int decplaces = 10; |
| 389 | int retval; |
| 390 | |
| 391 | // too verbose |
| 392 | //rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); |
| 393 | |
| 394 | if (llabs(freq) >= GHz(1)) |
| 395 | { |
| 396 | hz = "GHz"; |
| 397 | f = (double)freq / GHz(1); |
| 398 | } |
| 399 | else if (llabs(freq) >= MHz(1)) |
| 400 | { |
| 401 | hz = "MHz"; |
| 402 | f = (double)freq / MHz(1); |
| 403 | decplaces = 7; |
| 404 | } |
| 405 | else if (llabs(freq) >= kHz(1)) |
| 406 | { |
| 407 | hz = "kHz"; |
| 408 | f = (double)freq / kHz(1); |
| 409 | decplaces = 4; |
| 410 | } |
| 411 | else |
| 412 | { |
| 413 | hz = "Hz"; |
| 414 | f = (double)freq; |
| 415 | decplaces = 1; |
| 416 | } |
| 417 | |
| 418 | SNPRINTF(str, str_len, "%.*f %s", decplaces, f, hz); |
| 419 | retval = strlen(str); |
| 420 | return retval; |
| 421 | } |
| 422 | |
| 423 | |
| 424 | /** |
no outgoing calls
no test coverage detected