Read delta t values from external file. * record structure: year(whitespace)delta_t in 0.01 sec. */
| 3092 | * record structure: year(whitespace)delta_t in 0.01 sec. |
| 3093 | */ |
| 3094 | static int init_dt(void) |
| 3095 | { |
| 3096 | FILE *fp; |
| 3097 | int year; |
| 3098 | int tab_index; |
| 3099 | int tabsiz; |
| 3100 | int i; |
| 3101 | char s[AS_MAXCH]; |
| 3102 | char *sp; |
| 3103 | if (!swed.init_dt_done) { |
| 3104 | swed.init_dt_done = TRUE; |
| 3105 | /* no error message if file is missing */ |
| 3106 | if ((fp = swi_fopen(-1, "swe_deltat.txt", swed.ephepath, NULL)) == NULL |
| 3107 | && (fp = swi_fopen(-1, "sedeltat.txt", swed.ephepath, NULL)) == NULL) |
| 3108 | return TABSIZ; |
| 3109 | while(fgets(s, AS_MAXCH, fp) != NULL) { |
| 3110 | sp = s; |
| 3111 | while (strchr(" \t", *sp) != NULL && *sp != '\0') |
| 3112 | sp++; /* was *sp++ fixed by Alois 2-jul-2003 */ |
| 3113 | if (*sp == '#' || *sp == '\n') |
| 3114 | continue; |
| 3115 | year = atoi(s); |
| 3116 | tab_index = year - TABSTART; |
| 3117 | /* table space is limited. no error msg, if exceeded */ |
| 3118 | if (tab_index >= TABSIZ_SPACE) |
| 3119 | continue; |
| 3120 | sp += 4; |
| 3121 | while (strchr(" \t", *sp) != NULL && *sp != '\0') |
| 3122 | sp++; /* was *sp++ fixed by Alois 2-jul-2003 */ |
| 3123 | /*dt[tab_index] = (short) (atof(sp) * 100 + 0.5);*/ |
| 3124 | dt[tab_index] = atof(sp); |
| 3125 | } |
| 3126 | fclose(fp); |
| 3127 | } |
| 3128 | /* find table size */ |
| 3129 | tabsiz = 2001 - TABSTART + 1; |
| 3130 | for (i = tabsiz - 1; i < TABSIZ_SPACE; i++) { |
| 3131 | if (dt[i] == 0) |
| 3132 | break; |
| 3133 | else |
| 3134 | tabsiz++; |
| 3135 | } |
| 3136 | tabsiz--; |
| 3137 | return tabsiz; |
| 3138 | } |
| 3139 | |
| 3140 | /* Astronomical Almanac table is corrected by adding the expression |
| 3141 | * -0.000091 (ndot + 26)(year-1955)^2 seconds |