I don’t know if anyone knows why I get a segmentation fault when I compile the following code, but if anyone can tell me why that would be extremely helpful

 

You can email me directly @ kalberry@ati.sl.on.ca .

 

Thanks,

            Keith Alberry

 

Command line: sdcc –c radec.c

 

 

Code

 

#include <math.h>

#include <time.h>

#define sin sinf

#define cos cosf

#define floor floorf

#define exp expf

#define log logf

#define asin asinf

#define acos acosf

//#define PI          3.14159265358979323846

#define THREE60               86164

//#define LATITUDE    44.2666666666666666667

//#define LONGITUDE   -76.5

#define LATITUDE    43.65

#define LONGITUDE   -79.383

#define RADEG       (180.0/PI)

#define DEGRAD      (PI/180.0)

#define sind(x)     sin((x)*DEGRAD)

#define cosd(x)     cos((x)*DEGRAD)

#define tand(x)     tan((x)*DEGRAD)

#define asind(x)    (RADEG*asin(x))

#define acosd(x)    (RADEG*acos(x))

#define atand(x)    (RADEG*atan(x))

#define atan2d(y,x) (RADEG*atan2((y),(x)))

#define Sec2Deg(x)  (360*x/THREE60)

float rev( float x );

float cbrt( float x );

float SetupSidereal( float RA);

void SetAltAz( float DEC, float HA);

float SetRA( int hour, int minute, int second);

float SetDEC( int degrees, int minute, int second);

/*****************************************************************

            Global Variables

*****************************************************************/

float L=0.0; // L used for Sidereal time calculatiuon

                                    // t=Sidereal time

//float t =0.0;

float TargetAz, TargetAlt;

int hour,minute,second,degree;

float RA,DEC,HA;

/*****************************************************************

            Functions

*****************************************************************/

float rev( float x )

/*****************************************************************

            Normalize An angle between 0 and 360 degrees.

*****************************************************************/

{

  return  x - floor(x/360.0)*360.0;

}

 

 

float cbrt( float x )

/*****************************************************************

            Cube Root.

*****************************************************************/

{

    if ( x > 0.0 )

            return exp( log(x) / 3.0 );

    else if ( x < 0.0 )

            return -cbrt(-x);

    else /* x == 0.0 */

            return 0.0;

}

 

float SetupSidereal(float RA)

/*****************************************************************

            Setup Global variable for calculating Sidereal time.

*****************************************************************/

{

  time_t T,blah;

  struct tm *gmt;

  float day,month,year,testday;

  float UT,HA,t,t1;

  float hour, minute,second,garbage;

  T = time(&blah);

  gmt = gmtime(&T);

  hour = (float)gmt->tm_hour;

  minute = (float)gmt->tm_min;

  second = (float)gmt->tm_sec;

  day = (float)gmt->tm_mday;

  month = (float)(gmt->tm_mon+1);

  year = (float)(gmt->tm_year+1900);

  UT=hour+minute/60+second/60/60;//+5 - (LONGITUDE/360)*24;

  if(UT>=24) UT-=24;

  month++;

  if (month<4)

    {

    year--;

    month+=12;

    }

  testday= (float)(2-floor(year/100) +floor(floor(year/100)/4)+ floor(365.25*year) + floor(30.6001*(month)) + day + 1720994.5);

  t1=(float)((testday-2451545.0)/36525.0);

  t=(float)(6.697374558+(2400.051336*t1)+(0.000025862*t1*t1)+(UT*1.0027379093));

  while((t<0)||(t>=24))

    {

    if(t<0) t+=24;

    if(t>=24) t-=24;

    }

  t1=(float)((t+LONGITUDE/15)/24*THREE60);

  t= Sec2Deg(t1);

  HA = rev(t - RA);

  return(HA);

}

 

void SetAltAz(float DEC, float HA)

/*****************************************************************

            Set the target Altitude and Azimuth.

*****************************************************************/

{

  TargetAlt         = asind( sind(DEC)* sind(LATITUDE) + cosd(HA)*cosd(DEC)*cosd(LATITUDE) );

  TargetAz         = asind( ( cosd(DEC)*sind(HA) )/( -cosd(TargetAlt) ));

  if (TargetAz<0) TargetAz+=360;

  return;

}

 

float SetRA(int hour, int minute, int second)

{

  return ((float)(hour*15+minute/60*15+second/60/60*15));

}

 

float SetDEC(int degrees, int minute, int second)

{

  return ((float)(degrees + minute/60*15+second/60/60*15) );

}