1 /* Copyright (c) 2014-2019, The University of Oxford. See LICENSE file. */
2 
3 #define OSKAR_CONVERT_LON_LAT_TO_REL_DIR(NAME, IS_3D, FP) KERNEL_PUB(NAME) (\
4         const int num, GLOBAL_IN(FP, lon_rad), GLOBAL_IN(FP, lat_rad),\
5         const FP lon0_rad, const FP cos_lat0, const FP sin_lat0,\
6         GLOBAL_OUT(FP, l), GLOBAL_OUT(FP, m), GLOBAL_OUT(FP, n))\
7 {\
8     KERNEL_LOOP_X(int, i, 0, num)\
9     FP sin_lon, cos_lon, sin_lat, cos_lat;\
10     const FP lon = lon_rad[i] - lon0_rad, lat = lat_rad[i];\
11     SINCOS(lon, sin_lon, cos_lon);\
12     SINCOS(lat, sin_lat, cos_lat);\
13     l[i] = cos_lat * sin_lon;\
14     m[i] = cos_lat0 * sin_lat - sin_lat0 * cos_lat * cos_lon;\
15     if (IS_3D) n[i] = sin_lat0 * sin_lat + cos_lat0 * cos_lat * cos_lon;\
16     KERNEL_LOOP_END\
17 }\
18 OSKAR_REGISTER_KERNEL(NAME)
19