Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor edits for C best practices #66

Merged
merged 20 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ distclean: distclean-local
.PHONY: check
check:
@echo " [check]"
@cppcheck $(CPPFLAGS) $(CHECKOPTS) src
@cppcheck $(CPPFLAGS) $(CHECKOPTS) $(SRC) -I$(INC)
kiranshila marked this conversation as resolved.
Show resolved Hide resolved

# Doxygen documentation (HTML and man pages) under apidocs/
.PHONY: dox
Expand Down
4 changes: 2 additions & 2 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CC ?= gcc
CPPFLAGS += -I$(INC)

# Base compiler options (if not defined externally...)
CFLAGS ?= -Os -Wall
CFLAGS ?= -Os -Wall -std=c99

# Extra warnings (not supported on all compilers)
#CFLAGS += -Wextra
Expand Down Expand Up @@ -97,7 +97,7 @@ DEFAULT_SOLSYS ?= 3
# cppcheck options for 'check' target. You can add additional options by
# setting the CHECKEXTRA variable (e.g. in shell) prior to invoking 'make'.
CHECKOPTS ?= --enable=performance,warning,portability,style --language=c \
--error-exitcode=1 $(CHECKEXTRA)
--error-exitcode=1 --std=c99$(CHECKEXTRA)
kiranshila marked this conversation as resolved.
Show resolved Hide resolved

# Exhaustive checking for newer cppcheck...
#CHECKOPTS += --check-level=exhaustive
Expand Down
6 changes: 5 additions & 1 deletion include/novas.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
#ifndef _NOVAS_
#define _NOVAS_

#include <math.h> // for M_PI
#include <math.h> // for sin, cos
#include <stdlib.h> // NULL
#include <stdint.h>
#include <time.h>

#ifndef M_PI
# define M_PI 3.14159265358979323846
kiranshila marked this conversation as resolved.
Show resolved Hide resolved
#endif

// The upstream NOVAS library had a set of include statements that really were not necessary
// First, including standard libraries here meant that those libraries were included in the
// source code of any application that included 'novas.h', even if that source code did not
Expand Down
3 changes: 3 additions & 0 deletions src/frames.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ int novas_app_to_geom(const novas_frame *frame, enum novas_reference_system sys,
break;
default:
// nothing to do.
;
kiranshila marked this conversation as resolved.
Show resolved Hide resolved
}

// Undo aberration correction
Expand Down Expand Up @@ -1064,6 +1065,7 @@ int novas_make_transform(const novas_frame *frame, enum novas_reference_system f

default:
// nothing to do...
;
}
}
else {
Expand Down Expand Up @@ -1092,6 +1094,7 @@ int novas_make_transform(const novas_frame *frame, enum novas_reference_system f

default:
// nothing to do...
;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/novas.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ int obs_posvel(double jd_tdb, double ut1_to_tt, enum novas_accuracy accuracy, co

default:
// Nothing to do
;
}

return 0;
Expand Down Expand Up @@ -1665,6 +1666,7 @@ short place(double jd_tt, const object *source, const observer *location, double

default:
// Nothing else to do.
;
}

// ---------------------------------------------------------------------
Expand Down Expand Up @@ -3900,6 +3902,7 @@ int obs_planets(double jd_tdb, enum novas_accuracy accuracy, const double *pos_o
*/
short grav_def(double jd_tdb, enum novas_observer_place unused, enum novas_accuracy accuracy, const double *pos_src, const double *pos_obs,
double *out) {
(void)unused;
static const char *fn = "grav_def";

novas_planet_bundle planets = {};
Expand Down
9 changes: 6 additions & 3 deletions src/refract.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ double novas_inv_refract(RefractionModel model, double jd_tt, const on_surface *
/**
* Returns an optical refraction correction for a standard atmosphere.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian data of observation
* @param jd_tt [day] Terrestrial Time (TT) based Julian data of observation (currently unused)
kiranshila marked this conversation as resolved.
Show resolved Hide resolved
* @param loc Pointer to structure defining the observer's location on earth, and local weather
* @param type Whether the input elevation is observed or astrometric: REFRACT_OBSERVED (-1) or
* REFRACT_ASTROMETRIC (0).
Expand All @@ -93,6 +93,7 @@ double novas_inv_refract(RefractionModel model, double jd_tt, const on_surface *
* @sa refract_astro()
*/
double novas_standard_refraction(double jd_tt, const on_surface *loc, enum novas_refraction_type type, double el) {
(void)jd_tt;
double dz = novas_refraction(NOVAS_STANDARD_ATMOSPHERE, loc, type, el);
if(isnan(dz))
return novas_trace_nan("novas_optical_refraction");
Expand All @@ -102,7 +103,7 @@ double novas_standard_refraction(double jd_tt, const on_surface *loc, enum novas
/**
* Returns an optical refraction correction using the weather parameters defined for the observer location.
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian data of observation
* @param jd_tt [day] Terrestrial Time (TT) based Julian data of observation (currently unused)
* @param loc Pointer to structure defining the observer's location on earth, and local weather
* @param type Whether the input elevation is observed or astrometric: REFRACT_OBSERVED (-1) or
* REFRACT_ASTROMETRIC (0).
Expand All @@ -117,6 +118,7 @@ double novas_standard_refraction(double jd_tt, const on_surface *loc, enum novas
* @sa refract_astro()
*/
double novas_optical_refraction(double jd_tt, const on_surface *loc, enum novas_refraction_type type, double el) {
(void)jd_tt;
double dz = novas_refraction(NOVAS_WEATHER_AT_LOCATION, loc, type, el);
if(isnan(dz))
return novas_trace_nan("novas_optical_refraction");
Expand All @@ -136,7 +138,7 @@ double novas_optical_refraction(double jd_tt, const on_surface *loc, enum novas_
* <li>Berman, Allan L., and Rockwell, Stephen T. (1976), NASA JPL Technical Report 32-1601</li>
* </ol>
*
* @param jd_tt [day] Terrestrial Time (TT) based Julian data of observation
* @param jd_tt [day] Terrestrial Time (TT) based Julian data of observation (currently unused)
* @param loc Pointer to structure defining the observer's location on earth, and local weather.
* Make sure all weather values, including humidity (added in v1.1), are fully
* populated.
Expand All @@ -151,6 +153,7 @@ double novas_optical_refraction(double jd_tt, const on_surface *loc, enum novas_
* @sa on_surface
*/
double novas_radio_refraction(double jd_tt, const on_surface *loc, enum novas_refraction_type type, double el) {
(void)jd_tt;
kiranshila marked this conversation as resolved.
Show resolved Hide resolved
static const char *fn = "novas_radio_refraction";
// Various coefficients...
static const double E[] = { 0.0, 46.625, 45.375, 4.1572, 1.4468, 0.25391, 2.2716, -1.3465, -4.3877, 3.1484, 4.520, -1.8982, 0.8900 };
Expand Down
47 changes: 0 additions & 47 deletions tatus

This file was deleted.