Skip to content

Commit

Permalink
Use fixed-width types in libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-graj committed Aug 9, 2022
1 parent 060c759 commit f7b763e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 48 deletions.
10 changes: 5 additions & 5 deletions lib/sgp4/SGP4.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@
const double zsings = -0.98088458;

/* --------------------- local variables ------------------------ */
int lsflg;
int32_t lsflg;
double a1, a2, a3, a4, a5, a6, a7,
a8, a9, a10, betasq, cc, ctem, stem,
x1, x2, x3, x4, x5, x6, x7,
Expand Down Expand Up @@ -871,7 +871,7 @@

void dspace(double tc, ElsetRec *rec)
{
int iretn;
int32_t iretn;
double delt, ft, theta, x2li, x2omi, xl, xldot, xnddt, xndt, xomi, g22, g32,
g44, g52, g54, fasx2, fasx4, fasx6, rptim, step2, stepn, stepp;

Expand Down Expand Up @@ -1558,7 +1558,7 @@
xmdf, xmx, xmy, nodedf, xnode, tc,
x2o3, vkmpersec, delmtemp;

int ktr;
int32_t ktr;

/* ------------------ set mathematical constants --------------- */
/* sgp4fix divisor for divide by zero check on inclination
Expand Down Expand Up @@ -1854,7 +1854,7 @@
* vallado, crawford, hujsak, kelso 2006
--------------------------------------------------------------------------- */

void getgravconst(int whichconst, ElsetRec *rec)
void getgravconst(int32_t whichconst, ElsetRec *rec)
{
rec->whichconst = whichconst;
switch (whichconst)
Expand Down Expand Up @@ -1972,7 +1972,7 @@
* vallado 2013, 183, alg 14, ex 3-4
* --------------------------------------------------------------------------- */

void jday(int year, int mon, int day, int hr, int minute, double sec, double *jd, double *jdfrac)
void jday(int32_t year, int32_t mon, int32_t day, int32_t hr, int32_t minute, double sec, double *jd, double *jdfrac)
{

*jd = 367.0 * year -
Expand Down
26 changes: 14 additions & 12 deletions lib/sgp4/SGP4.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
typedef int bool;
#endif

#include <stdint.h>

/**
* This class implements the elsetrec data type from Vallado's SGP4 code.
*
Expand All @@ -25,11 +27,11 @@ typedef int bool;
*
*/
typedef struct ElsetRec {
int whichconst;
int32_t whichconst;
char satid[6];
int epochyr;
int epochtynumrev;
int error;
int32_t epochyr;
int32_t epochtynumrev;
int32_t error;
char operationmode;
char init;
char method;
Expand All @@ -53,9 +55,9 @@ typedef struct ElsetRec {
/* sgp4fix add new variables from tle */
char classification;
char intldesg[12];
int ephtype;
long elnum;
long revnum;
int32_t ephtype;
int64_t elnum;
int64_t revnum;

/* sgp4fix add unkozai'd variable */
double no_unkozai;
Expand All @@ -81,7 +83,7 @@ typedef struct ElsetRec {
double j3oj2;

/* Additional elements to capture relevant TLE and object information: */
long dia_mm; /* RSO dia in mm */
int64_t dia_mm; /* RSO dia in mm */
double period_sec; /* Period in seconds */
char active; /* "Active S/C" flag (0=n, 1=y) */
char not_orbital; /* "Orbiting S/C" flag (0=n, 1=y) */
Expand All @@ -95,7 +97,7 @@ typedef struct ElsetRec {
double mp;


int isimp;
int32_t isimp;
double aycof;
double con41;
double cc1;
Expand All @@ -122,7 +124,7 @@ typedef struct ElsetRec {
double nodecf;

/* deep space */
int irez;
int32_t irez;
double d2201;
double d2211;
double d3210;
Expand Down Expand Up @@ -268,10 +270,10 @@ bool sgp4init ( char opsmode,ElsetRec *satrec);

bool sgp4 ( ElsetRec *satrec, double tsince, double *r, double *v);

void getgravconst(int whichconst, ElsetRec *rec);
void getgravconst(int32_t whichconst, ElsetRec *rec);

double gstime(double jdut1);

void jday(int year, int mon, int day, int hr, int minute, double sec, double *jd, double *jdfrac);
void jday(int32_t year, int32_t mon, int32_t day, int32_t hr, int32_t minute, double sec, double *jd, double *jdfrac);

#endif
44 changes: 22 additions & 22 deletions lib/sgp4/TLE.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#define FALSE 0

/* parse the double */
static double gd(char *str, int ind1, int ind2);
static double gd(char *str, int32_t ind1, int32_t ind2);

/* parse the double with implied decimal */
static double gdi(char *str, int ind1, int ind2);
static double gdi(char *str, int32_t ind1, int32_t ind2);

static void setValsToRec(TLE *tle, ElsetRec *rec);

Expand All @@ -35,7 +35,7 @@ void parseLines(TLE *tle, char *line1, char *line2)

tle->rec.classification=line1[7];

tle->objectNum = (int)gd(line1,2,7);
tle->objectNum = (int32_t)gd(line1,2,7);
strncpy(tle->objectID,&line1[2],5);
tle->objectID[5]=0;

Expand All @@ -50,15 +50,15 @@ void parseLines(TLE *tle, char *line1, char *line2)
if(line1[53]=='-') tle->bstar *= -1.0;
tle->bstar *= pow(10.0, gd(line1,59,61));

tle->elnum = (int)gd(line1,64,68);
tle->elnum = (int32_t)gd(line1,64,68);

tle->incDeg = gd(line2,8,16);
tle->raanDeg = gd(line2,17,25);
tle->ecc = gdi(line2,26,33);
tle->argpDeg = gd(line2,34,42);
tle->maDeg = gd(line2,43,51);
tle->n = gd(line2,52,63);
tle->revnum = (int)gd(line2,63,68);
tle->revnum = (int32_t)gd(line2,63,68);

tle->sgp4Error = 0;

Expand All @@ -67,7 +67,7 @@ void parseLines(TLE *tle, char *line1, char *line2)
setValsToRec(tle, &tle->rec);
}

bool isLeap(int year)
bool isLeap(int32_t year)
{
if(year % 4 != 0)
{
Expand All @@ -89,16 +89,16 @@ bool isLeap(int year)
return TRUE;
}

long parseEpoch(ElsetRec *rec, char *str)
int64_t parseEpoch(ElsetRec *rec, char *str)
{
char tmp[16], tmp2[16];
int year, doy, hr, mn, sc/*, milli */, mon, day;
int32_t year, doy, hr, mn, sc/*, milli */, mon, day;
double dfrac;
double sec;
int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int ind;
int32_t days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int32_t ind;
double diff, diff2;
long epoch;
int64_t epoch;

strncpy(tmp,str,14);
tmp[15]=0;
Expand Down Expand Up @@ -132,16 +132,16 @@ long parseEpoch(ElsetRec *rec, char *str)


dfrac *= 24.0;
hr = (int)dfrac;
hr = (int32_t)dfrac;
dfrac = 60.0*(dfrac - hr);
mn = (int)dfrac;
mn = (int32_t)dfrac;
dfrac = 60.0*(dfrac - mn);
sc = (int)dfrac;
sc = (int32_t)dfrac;



dfrac = 1000.0*(dfrac-sc);
/* milli = (int)dfrac; */
/* milli = (int32_t)dfrac; */

sec = ((double)sc)+dfrac/1000.0;

Expand All @@ -165,12 +165,12 @@ long parseEpoch(ElsetRec *rec, char *str)
diff2 = 86400000.0*rec->jdsatepochF;
diff*=86400000.0;

epoch = (long)diff2;
epoch+=(long)diff;
epoch = (int64_t)diff2;
epoch+=(int64_t)diff;
return epoch;
}

void getRVForDate(TLE *tle, long millisSince1970, double r[3], double v[3])
void getRVForDate(TLE *tle, int64_t millisSince1970, double r[3], double v[3])
{
double diff = millisSince1970-tle->epoch;
diff/=60000.0;
Expand All @@ -184,23 +184,23 @@ void getRV(TLE *tle, double minutesAfterEpoch, double r[3], double v[3])
tle->sgp4Error = tle->rec.error;
}

double gd(char *str, int ind1, int ind2)
double gd(char *str, int32_t ind1, int32_t ind2)
{
double num = 0;
char tmp[50];
int cnt = ind2-ind1;
int32_t cnt = ind2-ind1;
strncpy(tmp,&str[ind1],cnt);
tmp[cnt]=0;
num = strtod(tmp,NULL);
return num;
}

/* parse with an implied decimal place */
double gdi(char *str, int ind1, int ind2)
double gdi(char *str, int32_t ind1, int32_t ind2)
{
double num = 0;
char tmp[52];
int cnt;
int32_t cnt;

tmp[0]='0';
tmp[1]='.';
Expand Down
14 changes: 7 additions & 7 deletions lib/sgp4/TLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ typedef struct TLE {
char line2[70];
char intlid[12];
char objectID[6];
int objectNum;
long epoch;
int32_t objectNum;
int64_t epoch;
double ndot;
double nddot;
double bstar;
int elnum;
int32_t elnum;
double incDeg;
double raanDeg;
double ecc;
double argpDeg;
double maDeg;
double n;
int revnum;
int sgp4Error;
int32_t revnum;
int32_t sgp4Error;
} TLE;

void parseLines(TLE *tle, char *line1, char *line2);

long parseEpoch(ElsetRec *rec, char *str);
int64_t parseEpoch(ElsetRec *rec, char *str);

void getRVForDate(TLE *tle, long millisSince1970, double r[3], double v[3]);
void getRVForDate(TLE *tle, int64_t millisSince1970, double r[3], double v[3]);

void getRV(TLE *tle, double minutesAfterEpoch, double r[3], double v[3]);

Expand Down
4 changes: 2 additions & 2 deletions lib/stb_image/stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,8 @@ static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, in
#ifndef STBI_NO_STDIO

#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
STBI_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide);
STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default);
STBI_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned int64_t flags, const char *str, int cbmb, wchar_t *widestr, int cchwide);
STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned int64_t flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default);
#endif

#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
Expand Down

0 comments on commit f7b763e

Please sign in to comment.