/** * @file vtime.c * @brief Sample program of VL2 GCSC to LLT conversion * @author Yukio Yamamoto * @date 2015-03-24 */ /* * This program is converted from FORTRAN version 'vtimec.f'. * http://www.ig.utexas.edu/people/staff/yosio/Viking/Programs/vtimec.f */ #include #include #define SOL_CSEC 8877525 /** * @brief gcsc to llt conversion based on algorithm on page V1-143 * * @param[in] gcsc GCSC Count * @param[in] doy Day-Of-Year 1976 * @param[out] sol SOL of local lander time * @param[out] hour hours of LLT in SOL * @param[out] min minutes of LLT in SOL * @param[out] csec centiseconds of LLT in SOL */ void gcsc2llt(int gcsc, int doy, int* sol, int* hour, int* min, int* csec) { int i, ige; double ge16, t, tr; const double lo0 = 2344400; const int maxg[] = { 11242789,36555517,67108864,93338597,134217728,201326592,320000000 }; const double cg[] = { 8.4276E-6,8.99984E-6,1.01318E-5,1.81923E-5,1.38394E-5,1.36977E-5,1.47743E-5 }; const int lo[] = { 0,103,765,9420,2919,2614,6082 }; ige = (doy-232)*540000-gcsc; ige &= 0xff000000; ige += gcsc; for (i=0; i<7; ++i) { if (ige <= maxg[i]) { break; } } ge16 = ige * 16.0; t = (ge16-cg[i]*ge16+lo[i]+lo0)/SOL_CSEC; *sol = t; tr = (t-*sol)*(SOL_CSEC/360000.0); *hour = tr; tr = (tr-*hour)*60; *min = tr; *csec = (tr-*min)*6000+0.5; } /* * sample main program */ int main() { int gcsc = 8145579; /* GCSC example */ int doy = 261; /* Sep. 17, 1976 */ int sol, hour, min, csec; gcsc2llt(gcsc, doy, &sol, &hour, &min, &csec); printf("%d %02d:%02d:%02d.%02d\n", sol,hour,min,(int)(csec/100),csec%100); return EXIT_SUCCESS; }