Degree Minute Second to Decimal Degree.

This code was written so I can later use it as a function on some larger projects.

// Compile with "gcc FILENAME.c"
//
// Copyright (c) 2012 All Right Reserved, nicholas.goumalatsas@gmail.com
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.

#include

int main()
{

double DEGREES; //set degree variable
double MINUTES; //set minute variable
double SECONDS; //set second variable
double SECONDS_TOTAL; //set sum total seconds
double DECIMAL; //set decimal
double DEC_DEG; //set decimal degree

printf("enter a DMS type number\n\n");

//ask for DMS #, to be replaced later by piping a # from another function.//
scanf("%3lf%*1c%2lf%2lf", &DEGREES, &MINUTES, &SECONDS);

//Takes first string of numbers and assigns to DEGREES, takes colon found in NMEA sentance as a one charactor string and does not store it. Finally takes the rest of the numbers in groups of two so they can be converted to a base ten system.//

printf("\n%3g--> Degrees \n", DEGREES); //This are just //
printf("%g--> Minutes \n", MINUTES); //showing the //
printf("%g--> Seconds \n", SECONDS); //numbers entered//

SECONDS_TOTAL = (MINUTES * 60) + SECONDS; //Convert minutes to seconds
DECIMAL = (SECONDS_TOTAL / 3600); //total seconds out of hour(degree)
DEC_DEG = (DEGREES + DECIMAL); //Starting degree plus seconds over hour

// printf("Total Seconds %g\n", SECONDS_TOTAL); //this code only used to troubleshooot
// printf("Decimal remainder %g\n", DECIMAL); //some rounding errors
printf("Dec Degrees %g\n", DEC_DEG); //Final answer.




return 0;
}
Updated Feb 10th 2012.