scem.c (1655B)
1 /* Copyright (C) 2025 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #include "scem.h" 17 #include "scem_c.h" 18 19 /******************************************************************************* 20 * Exported functions 21 ******************************************************************************/ 22 res_T 23 scem_sun_position_from_earth 24 (const struct tm* time, /* In UTC */ 25 const struct scem_location* pos, /* Local position */ 26 const enum scem_sun_algo algo, 27 struct scem_sun_pos* sun) 28 { 29 res_T res = RES_OK; 30 31 if(!time || !pos || !sun || (unsigned)algo >= SCEM_SUN_ALGO_NONE__) 32 return RES_BAD_ARG; 33 34 if(pos->latitude < -90 35 || pos->latitude > +90 36 || pos->longitude < -180 37 || pos->longitude > +180) 38 return RES_BAD_ARG; 39 40 switch(algo) { 41 case SCEM_SUN_MEEUS: 42 res = sun_position_from_earth_meeus(time, pos, sun); 43 break; 44 case SCEM_SUN_PSA: 45 res = sun_position_from_earth_psa(time, pos, sun); 46 break; 47 default: FATAL("Unreachable code\n"); break; 48 } 49 return res; 50 }