id
int64
15.5k
16.3M
file_name
stringlengths
3
43
file_path
stringlengths
22
137
content
stringlengths
21
332k
size
int64
21
332k
language
stringclasses
1 value
extension
stringclasses
2 values
total_lines
int64
4
7.88k
avg_line_length
float64
1.1
84.2
max_line_length
int64
2
3.13k
alphanum_fraction
float64
0.16
1
repo_name
stringlengths
9
45
repo_stars
int64
2
10.4k
repo_forks
int64
0
1.2k
repo_open_issues
int64
0
220
repo_license
stringclasses
6 values
repo_extraction_date
stringlengths
39
40
exact_duplicates_stackv2
bool
2 classes
exact_duplicates_stackv1
bool
2 classes
exact_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
1 class
near_duplicates_stackv2
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_redpajama
bool
2 classes
near_duplicates_githubcode
bool
1 class
2,914,632
411120-c.c
ps2homebrew_Fceumm-PS2/src/boards/411120-c.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2008 CaH4e3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ // actually cart ID is 811120-C, sorry ;) K-3094 - another ID #include "mapinc.h" #include "mmc3.h" static uint8 reset_flag = 0; static void BMC411120CCW(uint32 A, uint8 V) { setchr1(A, V | ((EXPREGS[0] & 3) << 7)); } static void BMC411120CPW(uint32 A, uint8 V) { if (EXPREGS[0] & (8 | reset_flag)) setprg32(0x8000, ((EXPREGS[0] >> 4) & 3) | (0x0C)); else setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 3) << 4)); } static DECLFW(BMC411120CLoWrite) { EXPREGS[0] = A; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); } static void BMC411120CReset(void) { EXPREGS[0] = 0; reset_flag ^= 4; MMC3RegReset(); } static void BMC411120CPower(void) { EXPREGS[0] = 0; GenMMC3Power(); SetWriteHandler(0x6000, 0x7FFF, BMC411120CLoWrite); } void BMC411120C_Init(CartInfo *info) { GenMMC3_Init(info, 128, 128, 8, 0); pwrap = BMC411120CPW; cwrap = BMC411120CCW; info->Power = BMC411120CPower; info->Reset = BMC411120CReset; AddExState(EXPREGS, 1, 0, "EXPR"); }
1,792
C
.c
55
30.690909
81
0.724537
ps2homebrew/Fceumm-PS2
32
10
3
GPL-2.0
9/7/2024, 9:56:41 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
2,914,633
tf-1201.c
ps2homebrew_Fceumm-PS2/src/boards/tf-1201.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2005 CaH4e3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Lethal Weapon (VRC4 mapper) */ #include "mapinc.h" static uint8 prg0, prg1, mirr, swap; static uint8 chr[8]; static uint8 IRQCount; static uint8 IRQPre; static uint8 IRQa; static SFORMAT StateRegs[] = { { &prg0, 1, "PRG0" }, { &prg0, 1, "PRG1" }, { &mirr, 1, "MIRR" }, { &swap, 1, "SWAP" }, { chr, 8, "CHR" }, { &IRQCount, 1, "IRQC" }, { &IRQPre, 1, "IRQP" }, { &IRQa, 1, "IRQA" }, { 0 } }; static void SyncPrg(void) { if (swap & 3) { setprg8(0x8000, ~1); setprg8(0xC000, prg0); } else { setprg8(0x8000, prg0); setprg8(0xC000, ~1); } setprg8(0xA000, prg1); setprg8(0xE000, ~0); } static void SyncChr(void) { int i; for (i = 0; i < 8; i++) setchr1(i << 10, chr[i]); setmirror(mirr ^ 1); } static void StateRestore(int version) { SyncPrg(); SyncChr(); } static DECLFW(UNLTF1201Write) { A = (A & 0xF003) | ((A & 0xC) >> 2); if ((A >= 0xB000) && (A <= 0xE003)) { int ind = (((A >> 11) - 6) | (A & 1)) & 7; int sar = ((A & 2) << 1); chr[ind] = (chr[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); SyncChr(); } else switch (A & 0xF003) { case 0x8000: prg0 = V; SyncPrg(); break; case 0xA000: prg1 = V; SyncPrg(); break; case 0x9000: mirr = V & 1; SyncChr(); break; case 0x9001: swap = V & 3; SyncPrg(); break; case 0xF000: IRQCount = ((IRQCount & 0xF0) | (V & 0xF)); break; case 0xF002: IRQCount = ((IRQCount & 0x0F) | ((V & 0xF) << 4)); break; case 0xF001: case 0xF003: IRQa = V & 2; X6502_IRQEnd(FCEU_IQEXT); if (scanline < 240) IRQCount -= 8; break; } } static void UNLTF1201IRQCounter(void) { if (IRQa) { IRQCount++; if (IRQCount == 237) { X6502_IRQBegin(FCEU_IQEXT); } } } static void UNLTF1201Power(void) { IRQPre = IRQCount = IRQa = 0; SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, UNLTF1201Write); SyncPrg(); SyncChr(); } void UNLTF1201_Init(CartInfo *info) { info->Power = UNLTF1201Power; GameHBIRQHook = UNLTF1201IRQCounter; GameStateRestore = StateRestore; AddExState(&StateRegs, ~0, 0, 0); }
2,841
C
.c
99
26.606061
96
0.664348
ps2homebrew/Fceumm-PS2
32
10
3
GPL-2.0
9/7/2024, 9:56:41 AM (Europe/Amsterdam)
false
true
false
true
false
true
false
false
2,952,458
popcountMain.c
CMU-SAFARI_Shifted-Hamming-Distance/popcountMain.c
/* * popcountMain.c * * Created on: Nov 7, 2013 * Author: hxin */ #include "popcount.h" #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #define MAX_CHUNKS 2048 uint8_t buffer[16 * MAX_CHUNKS] __aligned__; #define OPT_COUNT 8 char* functions[OPT_COUNT] = { "verify", "popcount", "popcount11", "builtin_popcount", "popcount_sse", "popcount11_sse", "popcount_m128i_sse", "popcount11_m128i_sse" }; void help(const char* progname) { int i; printf("%s ", progname); printf("%s", functions[0]); for (i = 1; i < OPT_COUNT; i++) printf("|%s", functions[i]); printf(" 16-byte-chunks repeat-count\n"); exit(1); } #define VERIFY(index) \ printf("%15s -> %d %s\n", \ functions[index], \ popcount, \ (popcount_ref != popcount) ? "FAILED!!!" : "" \ ); \ if (popcount_ref != popcount) \ failed = 1; char verify(int index, uint32_t (*func)(uint8_t*, int), uint8_t *buffer, int chunks16, unsigned popcount_ref) { char failed; int popcount = (*func)(buffer, chunks16); VERIFY(index); return failed; } char verify_m128i(int index, uint32_t (*func)(__m128i), uint8_t *buffer, int chunks16, unsigned popcount_ref) { char failed; int popcount = 0; __m128i reg; int i; for (i = 0; i < chunks16; i++) { reg = *((__m128i *) (buffer + i * 16)); popcount += (*func)(reg); } VERIFY(index); return failed; } int main(int argc, char* argv[]) { // prog parametrs int result; int function; int chunks_count; unsigned long long repeat_count; int default_chunks_count = 100; int default_repeat_count = 100000; double time_beg = 0; double time_end = 0; int i; // parse arguments if (argc == 1) help(argv[0]); // - function for (function = 0; function < OPT_COUNT; function++) if (strcasecmp(argv[1], functions[function]) == 0) break; if (function == OPT_COUNT) help(argv[0]); // - 16-byte chunks if (argc >= 3) { chunks_count = atoi(argv[2]); if (chunks_count <= 0 || chunks_count > MAX_CHUNKS) help(argv[0]); } else chunks_count = default_chunks_count; // - repeat count if (argc >= 4) { repeat_count = strtoull(argv[3], NULL, 10); if (repeat_count <= 0) help(argv[0]); } else repeat_count = default_repeat_count; // fill buffer with random data srand(time(NULL)); printf("Data: "); for (i = 0; i < sizeof(buffer); i++) buffer[i] = rand() % 256; for (i = 0; i < chunks_count * 16; i++) printf("%X", buffer[i]); printf("\n"); //Result data uint32_t popcount_ref, popcount_ref11; char failed = 0; // run printf("chunks=%d, repeat count=%llu\n", chunks_count, repeat_count); time_beg = clock(); switch (function) { case 0: popcount_ref = popcount1(buffer, chunks_count); popcount_ref11 = popcount11(buffer, chunks_count); // lookup result is reference printf("%10s -> %d\n", functions[1], popcount_ref); printf("%10s -> %d\n", functions[2], popcount_ref11); failed |= verify(3, &builtin_popcount, buffer, chunks_count, popcount_ref); failed |= verify(4, &popcount1_sse, buffer, chunks_count, popcount_ref); failed |= verify(5, &popcount11_sse, buffer, chunks_count, popcount_ref11); failed |= verify_m128i(6, &popcount1_m128i_sse, buffer, chunks_count, popcount_ref); failed |= verify_m128i(7, &popcount11_m128i_sse, buffer, chunks_count, popcount_ref11); if (failed) return EXIT_FAILURE; break; case 1: while (repeat_count--) popcount1(buffer, chunks_count); break; case 2: while (repeat_count--) popcount11(buffer, chunks_count); break; case 3: while (repeat_count--) builtin_popcount(buffer, chunks_count); break; case 4: while (repeat_count--) popcount1_sse(buffer, chunks_count); break; case 5: while (repeat_count--) popcount11_sse(buffer, chunks_count); break; case 6: while (repeat_count--) { result = 0; for (i = 0; i < chunks_count; i++) { __m128i reg = *((__m128i *) (buffer + i * 16)); result += popcount1_m128i_sse(reg); } } break; case 7: while (repeat_count--) { result = 0; for (i = 0; i < chunks_count; i++) { __m128i reg = *((__m128i *) (buffer + i * 16)); result += popcount11_m128i_sse(reg); } } break; } time_end = clock(); printf("Total time: %f\n", (time_end - time_beg) / CLOCKS_PER_SEC); return EXIT_SUCCESS; } // eof
4,339
C
.c
165
23.490909
74
0.649407
CMU-SAFARI/Shifted-Hamming-Distance
30
7
2
GPL-2.0
9/7/2024, 9:58:41 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
2,952,466
shiftMain.c
CMU-SAFARI_Shifted-Hamming-Distance/shiftMain.c
/* * shiftMain.c * * Created on: Nov 14, 2013 * Author: hxin */ #include "vector_filter.h" #include "mask.h" #include <stdio.h> uint8_t buff[32] __aligned__; int main(int argc, char* argv[]) { int shift_num = 0; unsigned long long repeat_count = 10000; int length = 64; if (argc >= 2) shift_num = atoi(argv[1]); if (argc >= 3) repeat_count = strtoull(argv[2], NULL, 10); if (argc >= 4) length = atoi(argv[3]); repeat_count *= (unsigned long long)( (length - 1) / 64 + 1); int i; for (i = 0; i < 16; i++) buff[i] = 0x0; for (i = 16; i < 32; i++) buff[i] = 0xff; // buff[15] = 0xc0; printf("length=%d, repeat count=%llu\n", length, repeat_count); printf("MASK_SSE_END:\n"); for (i = 0; i < 128 * 16; i++) printf("%x, ", MASK_SSE_END1[i]); // printf("Data: "); // printbytevector(buff, 32); // printf("\n"); __m128i *prev, *curr; prev = (__m128i *) buff; curr = (__m128i *) (buff + 16); __m128i zerofilled; zerofilled = _mm_set1_epi8(0x0); // *curr = shift_right_sse(*prev, *curr, 1); while (repeat_count--) shift_left_sse11(*prev, *curr, shift_num); // *curr = _mm_slli_epi16(*curr, 2); // printf("Data: "); // printbytevector(buff, 32); // printf("\n"); }
1,214
C
.c
47
23.702128
64
0.59809
CMU-SAFARI/Shifted-Hamming-Distance
30
7
2
GPL-2.0
9/7/2024, 9:58:41 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
2,963,777
prg.c
RobertGollagher_Freeputer/pre-alpha/pre-alpha2.0/dev/fvm/js/prg.c
var prgSrc = ` /* Copyright 2018, Robert Gollagher. SPDX-License-Identifier: GPL-3.0+ Program: prg.js (also known as 'prg.c') Author : Robert Gollagher [email protected] Created: 20170911 Updated: 20180515+ NOTES: - This little language is only ad hoc, what matters is the VM design. - This is written in an assembly language which aims to be C-compatible. - This is a demonstration program for FVM2 pre-alpha (see 'fvm2.js'). - This assembler does not yet support the same full syntax seen in 'fpx.m4'. - This assembler is very simplistic (see 'fvma.js') and uses little memory. - m0.x0 is the only forward reference the assembler allows - x symbols are exported from a module (e.g. x0 in m1 is m1.x0) - u symbols are local to a module (u0..uff) - s symbols are local to a unit (s0..sff) - Units begin with u{ and end with }u - Modules begin with m{ and end with }m - Modules are named by mod(m1) - The C-preprocessor would replace u{ with { __label__ s0, s1 ... - TODO Enforce use of u{ keyword prior to any locals - TODO Consider if I/O trap rather than branch on failure could be viable - TODO Consider flag- or stack-based strategy rather than traps - TODO Consider C-like call syntax as no forward refs... - See 'fvma.js' for further caveats */ // --------------------------------------------------------------------------- as(m1) module jump(m0.x0) /*main.run*/ endm // --------------------------------------------------------------------------- as(m0) /*main*/ module unit pri(s0): fail PUB(x0): tron i(0x41) out(s0) halt endu endm `;
1,671
C
.c
47
32.404255
78
0.630798
RobertGollagher/Freeputer
39
5
0
GPL-3.0
9/7/2024, 9:59:30 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,111,765
blink.c
oresat_oresat-firmware/src/l4/app_devboard/source/blink.c
#include "blink.h" /* Example blinker thread */ THD_WORKING_AREA(blink_wa, 0x40); THD_FUNCTION(blink, arg) { (void)arg; palSetLineMode(LINE_LED,PAL_MODE_OUTPUT_PUSHPULL); while (!chThdShouldTerminateX()) { palToggleLine(LINE_LED); chThdSleepMilliseconds(500); } palClearLine(LINE_LED); chThdExit(MSG_OK); }
351
C
.c
14
20.928571
54
0.690691
oresat/oresat-firmware
36
13
11
GPL-3.0
9/7/2024, 10:03:40 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,226,920
J1939.c
GreyZhang_J1939_basic/J1939 C Library for CAN-Enabled PICmicro® Microcontrollers/J1939/Examples/Example1a/J1939.c
/********************************************************************* * * J1939 Main Source Code * ********************************************************************* * FileName: J1939.c * Dependencies: See INCLUDES section below * Processor: PIC18xx8x and PIC18xx8 * Compiler: C18 X.X * Company: Microchip Technology, Inc. * * Software License Agreement * * The software supplied herewith by Microchip Technology Incorporated * (the “Company”) for its PICmicro® Microcontroller is intended and * supplied to you, the Company’s customer, for use solely and * exclusively on Microchip PICmicro Microcontroller products. The * software is owned by the Company and/or its supplier, and is * protected under applicable copyright laws. All rights are reserved. * Any use in violation of the foregoing restrictions may subject the * user to criminal sanctions under applicable laws, as well as to * civil liability for the breach of the terms and conditions of this * license. * * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. * * * Library routines for the J1939 C Library for PIC18 * devices with ECAN module. Please refer to the J1939 C Library User Guide * for information on configuring and using this library. * * This file requires the following header file: * * p18cxxx.h (MPLAB C18) * j1939.h * * Version Date Description * ---------------------------------------------------------------------- * v01.00.00 2004/06/04 Initial Release * * Copyright 2004 Kimberly Otten Software Consulting * * Author Date Comment *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Kim Otten 6/04/04 Original * Caio Gubel 6/11/04 Formatted ********************************************************************/ #ifndef __J1939_SOURCE #define __J1939_SOURCE #endif #include <p18cxxx.h> #include "J1939.H" #define J1939_TRUE 1 #define J1939_FALSE 0 // Internal definitions #define ADDRESS_CLAIM_TX 1 #define ADDRESS_CLAIM_RX 2 #define ECAN_CONFIG_MODE 0x80 #define ECAN_ERROR_INT_ENABLE 0xA0 #define ECAN_NORMAL_MODE 0x00 #define ECAN_RX_INT_ENABLE_FIFO 0x02 #define ECAN_RX_INT_ENABLE_LEGACY 0x03 #define ECAN_SELECT_RX_BUFFER 0x10 #define ECAN_SET_LEGACY_MODE 0x00 #define ECAN_SET_FIFO_MODE 0xA0 #define ECAN_TX_INT_ENABLE_LEGACY 0x0C typedef enum _BOOL { FALSE = 0, TRUE } BOOL; // Since we'll be mapping the various buffers into the access bank, we'll // create definitions for the key registers and bits of the overlayed mapping, // so it doesn't look like the wrong registers are being used. #define MAPPED_CONbits RXB0CONbits #define MAPPED_CON RXB0CON #define MAPPED_SIDH RXB0SIDH #ifdef ECAN_IS_CAN_MODULE #define MAPPED_TXREQ RXRTRRO #else #define MAPPED_TXREQ FILHIT3 #endif // Errata DS80162B, section 7 #define FIFOEMPTY_MASK 0x80 #define FIFOEMPTY_READ_BIT FIFOEMPTY #define FIFOEMPTY_WRITE_BIT RXBnOVFL // Define a macro for setting the window address bits for the network // management transmit buffer (TXB2). #if ECAN_LEGACY_MODE == J1939_TRUE #define SET_NETWORK_WINDOW_BITS {CANCON = ECAN_NORMAL_MODE | 0x04;} #else #define SET_NETWORK_WINDOW_BITS {ECANCON = ECAN_SET_FIFO_MODE | 0x05;} #endif // Global variables. Some of these will be visible to the CA. unsigned char CA_Name[J1939_DATA_LENGTH]; unsigned char CommandedAddress; #if J1939_ACCEPT_CMDADD == J1939_TRUE unsigned char CommandedAddressSource; unsigned char CommandedAddressName[J1939_DATA_LENGTH]; #endif unsigned long ContentionWaitTime; unsigned char J1939_Address; J1939_FLAG J1939_Flags; J1939_MESSAGE OneMessage; unsigned char RXHead; unsigned char RXTail; unsigned char RXQueueCount; J1939_MESSAGE RXQueue[J1939_RX_QUEUE_SIZE]; unsigned char TXHead; unsigned char TXTail; unsigned char TXQueueCount; J1939_MESSAGE TXQueue[J1939_TX_QUEUE_SIZE]; #if ECAN_LEGACY_MODE unsigned char TXIntsEnabled; #endif // Function Prototypes #if J1939_ACCEPT_CMDADD == J1939_TRUE BOOL CA_AcceptCommandedAddress( void ); #endif #if J1939_ARBITRARY_ADDRESS != 0x00 BOOL CA_RecalculateAddress( unsigned char * ); #endif /********************************************************************* CompareName This routine compares the passed in array data NAME with the CA's current NAME as stored in CA_Name. Parameters: unsigned char * Array of NAME bytes Return: -1 - CA_Name is less than the data 0 - CA_Name is equal to the data 1 - CA_Name is greater than the data *********************************************************************/ signed char CompareName( unsigned char *OtherName ) { unsigned char i; for (i = 0; (i<J1939_DATA_LENGTH) && (OtherName[i] == CA_Name[i]); i++); if (i == J1939_DATA_LENGTH) return 0; else if (CA_Name[i] < OtherName[i] ) return -1; else return 1; } /********************************************************************* CopyName This routine copies the CA's NAME into the message buffer's data array. We can afford to make this a function, since another function is always called after this is done, and we won't be using any additional stack space. Parameters: None Return: None *********************************************************************/ void CopyName(void) { unsigned char i; for (i=0; i<J1939_DATA_LENGTH; i++) OneMessage.Data[i] = CA_Name[i]; } /********************************************************************* SetECANMode This routine sets the ECAN module to a specific mode. It requests the mode, and then waits until the mode is actually set. Parameters: unsigned char ECAN module mode. Must be either ECAN_CONFIG_MODE or ECAN_NORMAL_MODE Return: None *********************************************************************/ void SetECANMode( unsigned char Mode ) { CANCON = Mode; while ((CANSTAT & 0xE0) != Mode); } /********************************************************************* SetAddressFilter This routine sets filter 3 to the specified value (destination address). It is used to allow reception of messages sent to this node specifically or simply to the global address if this node does not have an address (Address will be J1939_GLOBAL_ADDRESS). Parameters: unsigned char J1939 Address of this CA (or global) Return: None *********************************************************************/ void SetAddressFilter( unsigned char Address ) { SetECANMode( ECAN_CONFIG_MODE ); RXF3EIDH = Address; SetECANMode( ECAN_NORMAL_MODE ); } /********************************************************************* SendOneMessage This routine sends the message located at the pointer passed in. It also uses the message's data length field to determine how much of the data to load. At this point, all of the data fields, such as data length, priority, and source address, must be set. This routine will set up the CAN bits, such as the extended identifier bit and the remote transmission request bit. The window address bits for the correct operational mode must be set before this routine is called. Parameters: J1939_MESSAGE far * Pointer to message to send Return: None *********************************************************************/ void SendOneMessage( J1939_MESSAGE *MsgPtr ) { unsigned char Loop; unsigned char *RegPtr; unsigned char Temp; // Set up the final pieces of the message and make sure DataLength isn't // out of spec. MsgPtr->Res = 0; MsgPtr->RTR = 0; if (MsgPtr->DataLength > 8) MsgPtr->DataLength = 8; // Put PDUFormat into the structure to match the J1939-CAN format. This // involves splitting the original value in PDUFormat into two pieces, // leaving some holes for the TXBnSIDL register, and setting the EXIDE bit. MsgPtr->PDUFormat_Top = MsgPtr->PDUFormat >> 5; // Put the top three bits into SID5-3 Temp = MsgPtr->PDUFormat & 0x03; // Save the bottom two bits. MsgPtr->PDUFormat = (MsgPtr->PDUFormat & 0x1C) << 3;// Move up bits 4-2 into SID2-0. MsgPtr->PDUFormat |= Temp | 0x08; // Put back EID17-16, set EXIDE. // Wait until the requested buffer can be used to transmit. We shouldn't // need a time-out here unless something else in the design isn't working // (or we have to send a LOT of network management messages). while (MAPPED_CONbits.MAPPED_TXREQ); // Load the message buffer. Load the first 5 bytes of the message, // then load whatever part of the data is necessary. RegPtr = &MAPPED_SIDH; for (Loop=0; Loop<J1939_MSG_LENGTH+MsgPtr->DataLength; Loop++, RegPtr++) *RegPtr = MsgPtr->Array[Loop]; // Now tell the module to send the message. MAPPED_CONbits.MAPPED_TXREQ = 1; } /********************************************************************* J1939_AddressClaimHandling This routine is called either when the CA must claim its address on the bus or another CA is trying to claim the same address on the bus and we must either defend ourself or relinquish the address. If the CA has an address in the proprietary range of 0-127 or 248-253, it can take the address immediately. Parameters: unsigned char ADDRESS_CLAIM_RX indicates an Address Claim message has been received and this CA must either defend or give up its address. ADDRESS_CLAIM_TX indicates that the CA is initiating a claim to its address. Return: None *********************************************************************/ static void J1939_AddressClaimHandling( unsigned char Mode ) { // Get most of the message ready here, since it'll be very similar // for both messages to be sent. Note that J1939_PF_ADDRESS_CLAIMED // is the same value as J1939_PF_CANNOT_CLAIM_ADDRESS. We can't copy // the data yet because we might need to look at the old data. OneMessage.Priority = J1939_CONTROL_PRIORITY; OneMessage.PDUFormat = J1939_PF_ADDRESS_CLAIMED; OneMessage.DestinationAddress = J1939_GLOBAL_ADDRESS; OneMessage.DataLength = J1939_DATA_LENGTH; if (Mode == ADDRESS_CLAIM_TX) goto SendAddressClaim; if (OneMessage.SourceAddress != J1939_Address) return; if (CompareName( OneMessage.Data ) != -1) // Our CA_Name is not less { #if J1939_ARBITRARY_ADDRESS != 0x00 if (CA_RecalculateAddress( &CommandedAddress )) goto SendAddressClaim; #endif // Send Cannot Claim Address message CopyName(); OneMessage.SourceAddress = J1939_NULL_ADDRESS; SET_NETWORK_WINDOW_BITS; SendOneMessage( (J1939_MESSAGE *) &OneMessage ); // Set up filter to receive messages sent to the global address SetAddressFilter( J1939_GLOBAL_ADDRESS ); J1939_Flags.CannotClaimAddress = 1; J1939_Flags.WaitingForAddressClaimContention = 0; return; } SendAddressClaim: // Send Address Claim message for CommandedAddress CopyName(); OneMessage.SourceAddress = CommandedAddress; SET_NETWORK_WINDOW_BITS; SendOneMessage( (J1939_MESSAGE *) &OneMessage ); if (((CommandedAddress & 0x80) == 0) || // Addresses 0-127 ((CommandedAddress & 0xF8) == 0xF8)) // Addresses 248-253 (254,255 illegal) { J1939_Flags.CannotClaimAddress = 0; J1939_Address = CommandedAddress; // Set up filter to receive messages sent to this address SetAddressFilter( J1939_Address ); } else { // We don't have a proprietary address, so we need to wait. J1939_Flags.WaitingForAddressClaimContention = 1; ContentionWaitTime = 0; } } /********************************************************************* J1939_DequeueMessage This routine takes a message from the receive queue and places it in the caller's buffer. If there is no message to return, an appropriate return code is returned. If we're using interrupts, disable the receive interrupt around the queue manipulation. Parameters: J1939_MESSAGE * Pointer to the caller's message buffer Return: RC_SUCCESS Message dequeued successfully RC_QUEUEEMPTY No messages to return RC_CANNOTRECEIVE System cannot currently receive messages. This will be returned only after the receive queue is empty. *********************************************************************/ unsigned char J1939_DequeueMessage( J1939_MESSAGE *MsgPtr ) { unsigned char rc = RC_SUCCESS; #if J1939_POLL_ECAN == J1939_FALSE #if ECAN_LEGACY_MODE == J1939_TRUE PIE3 &= ~ECAN_RX_INT_ENABLE_LEGACY; #else PIE3bits.RXBnIE = 0; #endif #endif if (RXQueueCount == 0) { if (J1939_Flags.CannotClaimAddress) rc = RC_CANNOTRECEIVE; else rc = RC_QUEUEEMPTY; } else { *MsgPtr = RXQueue[RXHead]; RXHead ++; if (RXHead >= J1939_RX_QUEUE_SIZE) RXHead = 0; RXQueueCount --; } #if J1939_POLL_ECAN == J1939_FALSE #if ECAN_LEGACY_MODE == J1939_TRUE PIE3 |= ECAN_RX_INT_ENABLE_LEGACY; #else PIE3bits.RXBnIE = 1; #endif #endif return rc; } /********************************************************************* J1939_EnqueueMessage This routine takes a message from the caller's buffer and places it in the transmit queue. If the message cannot be queued or sent, an appropriate return code is returned. If interrupts are being used, then the transmit interrupt is enabled after the message is queued. If we are in FIFO mode and interrupts were not previously enabled, then we must also go enable an interrupt on the first available transmit buffer (TXB1). NOTE: With this module, we do not get an interrupt automatically if we set an interrupt enable on an empty buffer. So if interrupts were not previously enabled, we must enable the interrupt AND set the interrupt flag. If interrupts were already set from before, we just re-enable the interrupt. Parameters: J1939_MESSAGE * Pointer to the caller's message buffer Return: RC_SUCCESS Message dequeued successfully RC_QUEUEFULL Transmit queue full; message not queued RC_CANNOTTRANSMIT System cannot currently transmit messages. *********************************************************************/ unsigned char J1939_EnqueueMessage( J1939_MESSAGE *MsgPtr ) { unsigned char rc = RC_SUCCESS; #if J1939_POLL_ECAN == J1939_FALSE PIE3 &= ~ECAN_TX_INT_ENABLE_LEGACY; #else PIE3bits.TXBnIE = 0; #endif if (J1939_Flags.CannotClaimAddress) rc = RC_CANNOTTRANSMIT; else { if ((J1939_OVERWRITE_TX_QUEUE == J1939_TRUE) || (TXQueueCount < J1939_TX_QUEUE_SIZE)) { if (TXQueueCount < J1939_TX_QUEUE_SIZE) { TXQueueCount ++; TXTail ++; if (TXTail >= J1939_TX_QUEUE_SIZE) TXTail = 0; } TXQueue[TXTail] = *MsgPtr; } else rc = RC_QUEUEFULL; } #if J1939_POLL_ECAN == J1939_FALSE #if ECAN_LEGACY_MODE == J1939_TRUE PIE3 |= ECAN_TX_INT_ENABLE_LEGACY; if (!TXIntsEnabled) PIR3bits.TXB1IF = 1; // The module won't set the flag by itself #else PIE3bits.TXBnIE = 1; if ((TXBIE == 0) && ((BIE0 & ~ECAN_BUFFER_INTERRUPT_ENABLE) == 0)) { TXBIEbits.TXB1IE = 1; PIR3bits.TXBnIF = 1; // The module won't set the flag by itself } #endif #endif return rc; } /********************************************************************* J1939_Initialization This routine is called on system initialization. It initializes global variables, microcontroller peripherals, and interrupts. It then starts the process of claiming the CA's address. If the CA has a fixed NAME and Address, then it should call this routine with a TRUE value passed in. If it is Self-configurable or Arbitrary Address Capable, then the CA should initialize NAME and Address before calling this routine and call it with FALSE passed in. NOTE: CA NAME is initialized by setting the CA_Name byte array. The Address is initialized by setting the value of J1939_Address. NOTE: This routine will NOT enable global interrupts. The CA needs to do that when it's ready. Parameters: BOOL Whether or not to initialize NAME and Address values. Return: None *********************************************************************/ void J1939_Initialization( BOOL InitNAMEandAddress ) { unsigned char i; // Initialize global variables; J1939_Flags.FlagVal = 1; // Cannot Claim Address, all other flags cleared. ContentionWaitTime = 0l; TXHead = 0; TXTail = 0xFF; TXQueueCount = 0; RXHead = 0; RXTail = 0xFF; RXQueueCount = 0; if (InitNAMEandAddress) { J1939_Address = J1939_STARTING_ADDRESS; CA_Name[7] = J1939_CA_NAME7; CA_Name[6] = J1939_CA_NAME6; CA_Name[5] = J1939_CA_NAME5; CA_Name[4] = J1939_CA_NAME4; CA_Name[3] = J1939_CA_NAME3; CA_Name[2] = J1939_CA_NAME2; CA_Name[1] = J1939_CA_NAME1; CA_Name[0] = J1939_CA_NAME0; } CommandedAddress = J1939_Address; // Put the ECAN module into configuration mode and set it to the // desired mode. Then configure the extra buffers for receive or // transmit as selected by the user. SetECANMode( ECAN_CONFIG_MODE ); #if ECAN_LEGACY_MODE == J1939_TRUE #ifndef ECAN_IS_CAN_MODULE ECANCON = ECAN_SET_LEGACY_MODE; #endif #else ECANCON = ECAN_SET_FIFO_MODE; BSEL0 = ECAN_CONFIGURE_BUFFERS; #endif // Set up mask 0 to receive broadcast messages. Set up mask 1 to // receive messages sent to the global address (or eventually us). RXM0SIDH = 0x07; RXM0SIDL = 0x88; //0x80; RXM0EIDH = 0x00; RXM0EIDL = 0x00; RXM1SIDH = 0x00; RXM1SIDL = 0x08; RXM1EIDH = 0xFF; RXM1EIDL = 0x00; // Set up filter 0 to accept only broadcast messages (PF = 240-255). // Set up filter 2 and 3 to accept only the global address. Once we // get an address for the CA, we'll change filter 3 to accept that // address. RXF0SIDH = 0x07; RXF0SIDL = 0x88; RXF2SIDL = 0x08; RXF2EIDH = J1939_GLOBAL_ADDRESS; RXF3SIDL = 0x08; RXF3EIDH = J1939_GLOBAL_ADDRESS; // If we're in Legacy Mode, we need to set up filters 1, 4, // and 5 also, since we can't disable them. #if ECAN_LEGACY_MODE == J1939_TRUE RXF1SIDH = 0x07; RXF1SIDL = 0x88; RXF4SIDL = 0x08; RXF4EIDH = J1939_GLOBAL_ADDRESS; RXF5SIDL = 0x08; RXF5EIDH = J1939_GLOBAL_ADDRESS; #endif #if ECAN_LEGACY_MODE == J1939_FALSE // Set mask 0 to filter 0, and mask 1 to filters 2 and 3. MSEL0 = 0x5C; // Leave all filters set to RXB0. The filters will apply to // all receive buffers. RXFBCON0 = 0x00; RXFBCON1 = 0x00; RXFBCON2 = 0x00; // Enable filters 0, 2, and 3. Disable the others. RXFCON0 = 0x0D; RXFCON1 = 0x00; #endif // Set up bit timing as defined by the CA BRGCON1 = ECAN_BRGCON1; BRGCON2 = ECAN_BRGCON2; BRGCON3 = ECAN_BRGCON3; // Put the ECAN module into Normal Mode SetECANMode( ECAN_NORMAL_MODE ); // Give the network management transmit buffer the highest priority. SET_NETWORK_WINDOW_BITS; MAPPED_CON = 0x03; // Configure the port pins for CAN operation #ifdef ECAN_IS_CAN_MODULE TRISBbits.TRISB2 = 0; // CANTX TRISBbits.TRISB3 = 1; // CANRX #else #if defined(__18F4680) || defined(__18F4585) || defined(__18F2680) || defined(__18F2585) TRISBbits.TRISB3 = 1; // CANRX - Changed to accomodate 18F4680 - CG #endif #if defined(__18F8680) || defined(__18F8585) || defined(__18F6680) || defined(__18F6585) TRISGbits.TRISG3 = 1; // CANRX #endif #endif // Establish the ECAN interrupt priorities and enable the ECAN receive // interrupt. The caller must enable global interrupts when ready. #if J1939_POLL_ECAN == J1939_FALSE #if ECAN_LEGACY_MODE == J1939_TRUE TXIntsEnabled = 0; PIE3 = ECAN_RX_INT_ENABLE_LEGACY | ECAN_ERROR_INT_ENABLE; #else BIE0 = ECAN_BUFFER_INTERRUPT_ENABLE; PIE3 = ECAN_RX_INT_ENABLE_FIFO | ECAN_ERROR_INT_ENABLE; #endif #if J1939_PRIORITIZED_INT == J1939_TRUE RCONbits.IPEN = 1; #else RCONbits.IPEN = 0; #endif IPR3 &= 0xE0; IPR3 |= ECAN_INTERRUPT_PRIORITY; #endif // Start the process of claiming our address J1939_AddressClaimHandling( ADDRESS_CLAIM_TX ); } /********************************************************************* J1939_ISR This function is called by the CA if it gets an interrupt from the CAN controller. First we'll clear the interrupt flags. Then we'll call the receive and transmit functions to process any received messages and to transmit any messages in the transmit queue. NOTE: In FIFO mode, RXB0IF follows RXBnIF instead of being forced to 0 as per the data sheet, so we clear them both. The transmit interrupts do not have this issue. Parameters: None Return: None *********************************************************************/ #if J1939_POLL_ECAN == J1939_FALSE void J1939_ISR( void ) { #if ECAN_LEGACY_MODE == J1939_TRUE if (PIR3 & ECAN_RX_INT_ENABLE_LEGACY) { PIR3 &= ~ECAN_RX_INT_ENABLE_LEGACY; J1939_ReceiveMessages(); } if (PIR3 & ECAN_TX_INT_ENABLE_LEGACY) { PIR3 &= ~ECAN_TX_INT_ENABLE_LEGACY; J1939_TransmitMessages(); } if (PIR3 & ECAN_ERROR_INT_ENABLE) { if (PIR3bits.ERRIF) PIR3bits.ERRIF = 0; if (PIR3bits.IRXIF) PIR3bits.IRXIF = 0; } #else if (PIR3bits.RXBnIF) { PIR3 &= ~ECAN_RX_INT_ENABLE_LEGACY; J1939_ReceiveMessages(); } if (PIR3bits.TXBnIF) { PIR3bits.TXBnIF = 0; J1939_TransmitMessages(); } if (PIR3 & ECAN_ERROR_INT_ENABLE) { if (PIR3bits.ERRIF) // Future Errata, erroneous error flag if ((COMSTAT & 0x3F) == 0) { COMSTAT &= ~FIFOEMPTY_MASK; // Reset FIFOEMPTY bit PIR3bits.ERRIF = 0; } else PIR3bits.ERRIF = 0; if (PIR3bits.IRXIF) PIR3bits.IRXIF = 0; } #endif } #endif /********************************************************************* J1939_Poll If we're polling for messages, then this routine should be called by the CA every few milliseconds during CA processing. The routine receives any messages that are waiting and transmits any messages that are queued. Then we see if we are waiting for an address contention response. If we are and we've timed out, we accept the address as ours. If the CA is using interrupts, then this routine should be called by the CA every few milliseconds while the WaitingForAddressClaimContention flag is set after calling J1939_Initialization. If the Commanded Address message can be accepted, this routine must also be called every few milliseconds during CA processing in case we are commanded to change our address. If using interrupts, this routine will not check for received or transmit messages; it will only check for a timeout on address claim contention. Parameters: unsigned char The number of milliseconds that have passed since the last time this routine was called. This number can be approximate, and to meet spec, should be rounded down. Return: None *********************************************************************/ void J1939_Poll( unsigned long ElapsedTime ) { unsigned int Temp; // Update the Contention Wait Time. We have to do that before // we call J1939_ReceiveMessages in case the time gets reset back // to zero in that routine. ContentionWaitTime += ElapsedTime; #if J1939_POLL_ECAN == J1939_TRUE J1939_ReceiveMessages(); J1939_TransmitMessages(); #endif if (J1939_Flags.WaitingForAddressClaimContention && (ContentionWaitTime >= 250000l)) { J1939_Flags.CannotClaimAddress = 0; J1939_Flags.WaitingForAddressClaimContention = 0; J1939_Address = CommandedAddress; // Set up filter to receive messages sent to this address. // If we're using interrupts, make sure that interrupts are disabled // around this section, since it will mess up what we're doing. #if J1939_POLL_ECAN == J1939_FALSE #if (J1939_PRIORITIZED_INT == J1939_FALSE) || (ECAN_RX_INTERRUPT_PRIORITY == 0x00) || (ECAN_TX_INTERRUPT_PRIORITY == 0x00) INTCONbits.GIEL = 0; #endif #if (ECAN_RX_INTERRUPT_PRIORITY != 0x00) || (ECAN_TX_INTERRUPT_PRIORITY != 0x00) INTCONbits.GIEH = 0; #endif #endif SetAddressFilter( J1939_Address ); #if J1939_POLL_ECAN == J1939_FALSE #if (J1939_PRIORITIZED_INT == J1939_FALSE) || (ECAN_RX_INTERRUPT_PRIORITY == 0x00) || (ECAN_TX_INTERRUPT_PRIORITY == 0x00) INTCONbits.GIEL = 1; #endif #if (ECAN_RX_INTERRUPT_PRIORITY != 0x00) || (ECAN_TX_INTERRUPT_PRIORITY != 0x00) INTCONbits.GIEH = 1; #endif #endif } } /********************************************************************* J1939_ReceiveMessage This routine is called either when an interrupt is received from the ECAN or by polling. If a message has been received, it is read in. If it is a network management message, it is processed. Otherwise, it is placed in the receive queue for the user. Note that interrupts are disabled during this routine, since it is called from the interrupt handler. NOTE: To save stack space, the function J1939_CommandedAddressHandling was brought inline. Parameters: None Return: None *********************************************************************/ static void J1939_ReceiveMessages( void ) { unsigned char *RegPtr; unsigned char RXBuffer = 0; unsigned char Loop; #if ECAN_LEGACY_MODE == J1939_TRUE while (RXBuffer < 2) // Repeat for both receive buffers #else while (COMSTAT & FIFOEMPTY_MASK) // Repeat until the FIFO is empty #endif { // Set the Window Address bits to the message buffer #if ECAN_LEGACY_MODE == J1939_TRUE CANCON &= 0xF0; if (RXBuffer == 1) CANCON |= 0x0A; if (!MAPPED_CONbits.RXFUL) goto TryNextBuffer; // If no message, bail out #else ECANCON = ECAN_SET_FIFO_MODE | ECAN_SELECT_RX_BUFFER | (CANCON & 0x07); #endif // Read a message from the mapped receive buffer. RegPtr = &MAPPED_SIDH; for (Loop=0; Loop<J1939_MSG_LENGTH; Loop++, RegPtr++) OneMessage.Array[Loop] = *RegPtr; if (OneMessage.DataLength > 8) OneMessage.DataLength = 8; for (Loop=0; Loop<OneMessage.DataLength; Loop++, RegPtr++) OneMessage.Data[Loop] = *RegPtr; // Clear any receive flags MAPPED_CONbits.RXFUL = 0; #if ECAN_LEGACY_MODE == J1939_FALSE // Errata DS80162B section 6, try to clear the FIFO Empty flag COMSTAT &= ~FIFOEMPTY_MASK; // If we happen to be on the last buffer, we need to hit it twice. COMSTAT &= ~FIFOEMPTY_MASK; #endif // Format the PDU Format portion so it's easier to work with. Loop = (OneMessage.PDUFormat & 0xE0) >> 3; // Get SID2-0 ready. OneMessage.PDUFormat = (OneMessage.PDUFormat & 0x03) | Loop | ((OneMessage.PDUFormat_Top & 0x07) << 5); switch( OneMessage.PDUFormat ) { #if J1939_ACCEPT_CMDADD == J1939_TRUE case J1939_PF_TP_CM: if ((OneMessage.Data[0] == J1939_BAM_CONTROL_BYTE) && (OneMessage.Data[5] == J1939_PGN0_COMMANDED_ADDRESS) && (OneMessage.Data[6] == J1939_PGN1_COMMANDED_ADDRESS) && (OneMessage.Data[7] == J1939_PGN2_COMMANDED_ADDRESS)) { J1939_Flags.GettingCommandedAddress = 1; CommandedAddressSource = OneMessage.SourceAddress; } break; case J1939_PF_DT: if ((J1939_Flags.GettingCommandedAddress == 1) && (CommandedAddressSource == OneMessage.SourceAddress)) { // Commanded Address Handling if ((!J1939_Flags.GotFirstDataPacket) && (OneMessage.Data[0] == 1)) { for (Loop=0; Loop<7; Loop++) CommandedAddressName[Loop] = OneMessage.Data[Loop+1]; J1939_Flags.GotFirstDataPacket = 1; } else if ((J1939_Flags.GotFirstDataPacket) && (OneMessage.Data[0] == 2)) { CommandedAddressName[7] = OneMessage.Data[1]; CommandedAddress = OneMessage.Data[2]; if ((CompareName( CommandedAddressName ) == 0) && // Make sure the message is for us. CA_AcceptCommandedAddress()) // and we can change the address. J1939_AddressClaimHandling( ADDRESS_CLAIM_TX ); J1939_Flags.GotFirstDataPacket = 0; J1939_Flags.GettingCommandedAddress = 0; } else // This really shouldn't happen, but just so we don't drop the data packet goto PutInReceiveQueue; } else goto PutInReceiveQueue; break; #endif case J1939_PF_REQUEST: if ((OneMessage.Data[0] == J1939_PGN0_REQ_ADDRESS_CLAIM) && (OneMessage.Data[1] == J1939_PGN1_REQ_ADDRESS_CLAIM) && (OneMessage.Data[2] == J1939_PGN2_REQ_ADDRESS_CLAIM)) J1939_RequestForAddressClaimHandling(); else goto PutInReceiveQueue; break; case J1939_PF_ADDRESS_CLAIMED: J1939_AddressClaimHandling( ADDRESS_CLAIM_RX ); break; default: PutInReceiveQueue: if ( (J1939_OVERWRITE_RX_QUEUE == J1939_TRUE) || (RXQueueCount < J1939_RX_QUEUE_SIZE)) { if (RXQueueCount < J1939_RX_QUEUE_SIZE) { RXQueueCount ++; RXTail ++; if (RXTail >= J1939_RX_QUEUE_SIZE) RXTail = 0; } RXQueue[RXTail] = OneMessage; } else J1939_Flags.ReceivedMessagesDropped = 1; } #if ECAN_LEGACY_MODE == J1939_TRUE TryNextBuffer: RXBuffer ++; #endif } } /********************************************************************* J1939_RequestForAddressClaimHandling This routine is called if we're received a Request for Address Claim message. If we cannot claim an address, we send out a Cannot Claim Address message. Otherwise, we send out an Address Claim message for our address. NOTE: J1939_PF_CANNOT_CLAIM_ADDRESS is the same value as J1939_PF_ADDRESS_CLAIMED, so we can reduce code size by combining the two. Only the source address changes between the two messages. *********************************************************************/ static void J1939_RequestForAddressClaimHandling( void ) { if (J1939_Flags.CannotClaimAddress) OneMessage.SourceAddress = J1939_NULL_ADDRESS; // Send Cannot Claim Address message else OneMessage.SourceAddress = J1939_Address; // Send Address Claim for current address OneMessage.Priority = J1939_CONTROL_PRIORITY; OneMessage.PDUFormat = J1939_PF_ADDRESS_CLAIMED; // Same as J1939_PF_CANNOT_CLAIM_ADDRESS OneMessage.DestinationAddress = J1939_GLOBAL_ADDRESS; OneMessage.DataLength = J1939_DATA_LENGTH; CopyName(); SET_NETWORK_WINDOW_BITS; SendOneMessage( (J1939_MESSAGE *) &OneMessage ); } /********************************************************************* J1939_TransmitMessages This routine transmits as many messages from the transmit queue as it can. If the system cannot transmit messages, an error code is returned. Note that interrupts are disabled during this routine, since it is called from the interrupt handler. Since we need to maintain transmit order with more than two buffers being used when we're in FIFO mode, we set an interrupt to go off when the last used buffer finishes. If there are no more messages to send, then we disable the interrupt. Otherwise, we load the buffers back up. One extra interrupt saves us a lot of processing (and ROM) in here and in J1939_EnqueueMessage. Parameters: None Return: RC_SUCCESS Message was transmitted successfully RC_CANNOTTRANSMIT System cannot transmit messages. Either we cannot claim an address or all transmit buffers are busy. *********************************************************************/ static unsigned char LastTXBufferUsed = 0; static unsigned char J1939_TransmitMessages( void ) { unsigned char Mask = 0x04; unsigned char Status; if (TXQueueCount == 0) { // We don't have any more messages to transmit, so disable // the transmit interrupts and reset LastTXBufferUsed. #if J1939_POLL_ECAN == J1939_FALSE #if ECAN_LEGACY_MODE == J1939_TRUE TXIntsEnabled = 0; PIE3bits.TXB0IE = 0; PIE3bits.TXB1IE = 0; #else TXBIE = 0; BIE0 = ECAN_BUFFER_INTERRUPT_ENABLE; // Keep RX interrupts enabled. PIE3bits.TXBnIE = 0; #endif #endif LastTXBufferUsed = 0; } else { if (J1939_Flags.CannotClaimAddress) return RC_CANNOTTRANSMIT; // Make sure the last buffer we used last time is done transmitting. // This should be redundant if we're using interrupts, but it is required if // we're polling. If the last buffer is done, then reset our buffer pointer // to the beginning of the buffer list. if (LastTXBufferUsed != 0) { #if ECAN_LEGACY_MODE == J1939_TRUE CANCON = BUFFER_TABLE[LastTXBufferUsed-1].WindowBits; #else ECANCON = BUFFER_TABLE[LastTXBufferUsed-1].WindowBits; #endif if (MAPPED_CONbits.MAPPED_TXREQ) { #if 0 // shouldn't need this #if J1939_POLL_ECAN == J1939_FALSE #if ECAN_LEGACY_MODE == J1939_TRUE PIE3 |= BUFFER_TABLE[LastTXBufferUsed-1].PIE3Val; #else TXBIE = BUFFER_TABLE[LastTXBufferUsed-1].TXBIEVal; BIE0 = BUFFER_TABLE[LastTXBufferUsed-1].BIE0Val | ECAN_BUFFER_INTERRUPT_ENABLE; #endif #endif #endif return RC_CANNOTTRANSMIT; } else LastTXBufferUsed = 0; } // All transmit buffers are available, so fill them up. while ((TXQueueCount > 0) && (LastTXBufferUsed < ECAN_MAX_TX_BUFFERS)) { #if ECAN_LEGACY_MODE == J1939_TRUE CANCON = BUFFER_TABLE[LastTXBufferUsed].WindowBits; #else ECANCON = BUFFER_TABLE[LastTXBufferUsed].WindowBits; #endif if (!MAPPED_CONbits.MAPPED_TXREQ) // make sure buffer is free { TXQueue[TXHead].SourceAddress = J1939_Address; SendOneMessage( (J1939_MESSAGE *) &(TXQueue[TXHead]) ); TXHead ++; if (TXHead >= J1939_TX_QUEUE_SIZE) TXHead = 0; TXQueueCount --; } LastTXBufferUsed++; } // Enable the interrupt on the last used buffer #if J1939_POLL_ECAN == J1939_FALSE #if ECAN_LEGACY_MODE == J1939_TRUE TXIntsEnabled = 1; PIE3bits.TXB0IE = 0; PIE3bits.TXB1IE = 0; PIE3 |= BUFFER_TABLE[LastTXBufferUsed-1].PIE3Val; #else TXBIE = BUFFER_TABLE[LastTXBufferUsed-1].TXBIEVal; BIE0 = BUFFER_TABLE[LastTXBufferUsed-1].BIE0Val | ECAN_BUFFER_INTERRUPT_ENABLE; PIE3bits.TXBnIE = 1; #endif #endif } return RC_SUCCESS; }
33,958
C
.c
925
33.882162
125
0.68398
GreyZhang/J1939_basic
32
13
0
GPL-3.0
9/7/2024, 10:07:58 AM (Europe/Amsterdam)
true
false
false
true
true
false
false
false
3,540,703
defrfact.c
TritonDataCenter_sdcboot/freedos/source/chkdsk/fragfact/defrfact.c
/* Defrfact.c - calculate defragmentation factor. Copyright (C) 2000, 2002 Imre Leber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. If you have any questions, comments, suggestions, or fixes please email me at: [email protected] */ #include <dir.h> #include <string.h> #include <stdio.h> #include "fte.h" #include "bool.h" static int FactorCalculator(RDWRHandle handle, CLUSTER cluster, SECTOR sector, void** structure); static int FileFactCalculator(RDWRHandle handle, struct DirectoryPosition* position, void** structure); struct PipeStruct { CLUSTER total; CLUSTER consecutive; }; /************************************************************ *** PrintFileDefragFactors ************************************************************* *** Prints the defragmentation factor of the indicated files. *************************************************************/ int PrintFileDefragFactors(RDWRHandle handle, char* abspath) { return WalkWildcardPath(handle, abspath, 0, FileFactCalculator, NULL); } /************************************************************ *** FileFactCalculator ************************************************************* *** If this file is included in the count then it goes through *** the given files and scans for the number of consecutive *** clusters (and prints them off). *************************************************************/ static int FileFactCalculator(RDWRHandle handle, struct DirectoryPosition* position, void** structure) { int i, sum; CLUSTER firstcluster; struct PipeStruct pipe = {0,0}, *ppipe = &pipe; struct DirectoryEntry entry; structure = structure; if (!GetDirectory(handle, position, &entry)) { return FAIL; } if (entry.attribute & FA_LABEL) return TRUE; if (IsLFNEntry(&entry)) return TRUE; if (IsDeletedLabel(entry)) return TRUE; if (IsCurrentDir(entry)) return TRUE; if (IsPreviousDir(entry)) return TRUE; firstcluster = GetFirstCluster(&entry); if (firstcluster == 0) return TRUE; if (!FileTraverseFat(handle, firstcluster, FactorCalculator, (void**) &ppipe)) { return FAIL; } if (pipe.total) { sum = 100 - (int)(((unsigned long) pipe.consecutive * 100) / pipe.total); } else { sum = 0; } for (i = 0; i < 8; i++) printf("%c", entry.filename[i]); printf(" "); for (i = 0; i < 3; i++) printf("%c", entry.extension[i]); /* Print the attributes */ printf(" "); if (entry.attribute & FA_ARCH) printf("A"); else printf("-"); if (entry.attribute & FA_RDONLY) printf("R"); else printf("-"); if (entry.attribute & FA_HIDDEN) printf("H"); else printf("-"); if (entry.attribute & FA_SYSTEM) printf("S"); else printf("-"); if (entry.attribute & FA_DIREC) printf("D"); else printf("-"); printf (" (%d%%)\n", sum); return TRUE; } /************************************************************ *** FactorCalculator ************************************************************* *** Goes through the given file and counts the number of *** consecutive clusters. *************************************************************/ static int FactorCalculator(RDWRHandle handle, CLUSTER cluster, SECTOR sector, void** structure) { struct PipeStruct *pipe = *((struct PipeStruct**) structure); CLUSTER now = DataSectorToCluster(handle, sector); if (!now) return FAIL; pipe->total++; if ((now == cluster - 1) || (FAT_LAST(cluster))) pipe->consecutive++; return TRUE; }
4,778
C
.c
126
30.769841
81
0.540801
TritonDataCenter/sdcboot
24
14
0
MPL-2.0
9/7/2024, 10:22:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,540,714
descifat.c
TritonDataCenter_sdcboot/freedos/source/chkdsk/boot/descifat.c
/* Descifat.c - check descriptor in fat. Copyright (C) 2000, 2002 Imre Leber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. If you have any questions, comments, suggestions, or fixes please email me at: [email protected] */ /* 8/10/02 Adjusted for use in chkdsk */ #include "fte.h" #include "..\chkdrvr.h" #include "..\errmsgs\errmsgs.h" /****************************** Checking *********************************/ /************************************************************************* ** CheckDescriptorInFat ************************************************************************** ** Checks the descriptor in the FAT against the one in the boot sector. ***************************************************************************/ RETVAL CheckDescriptorInFat(RDWRHandle handle) { struct BootSectorStruct boot; SECTOR fatstart; char buffer[BYTESPERSECTOR], *p; if (!ReadBootSector(handle, &boot)) return ERROR; fatstart = GetFatStart(handle); if (!fatstart) return ERROR; if (ReadSectors(handle, 1, fatstart, buffer) == -1) return FALSE; if (boot.descriptor == buffer[0]) { return SUCCESS; } else { ReportFileSysError("Wrong descriptor value in FAT", 0, &p, 0, FALSE); } return FAILED; } /****************************** Fixing ***********************************/ /************************************************************************* ** PlaceDescriptorInFat ************************************************************************** ** Makes sure the descriptor in the FAT is equal to the one in the boot ** sector. ***************************************************************************/ RETVAL PlaceDescriptorInFat(RDWRHandle handle) { struct BootSectorStruct boot; SECTOR fatstart; char buffer[BYTESPERSECTOR], *p; if (!ReadBootSector(handle, &boot)) return ERROR; fatstart = GetFatStart(handle); if (!fatstart) return ERROR; if (ReadSectors(handle, 1, fatstart, buffer) == -1) return ERROR; if (buffer[0] != boot.descriptor) { ReportFileSysError("Wrong descriptor value in FAT", 0, &p, 0, FALSE); buffer[0] = boot.descriptor; if (WriteSectors(handle, 1, fatstart, buffer, WR_FAT) == -1) return ERROR; if (!BackupFat(handle)) return ERROR; } return SUCCESS; }
3,449
C
.c
86
32.244186
77
0.505897
TritonDataCenter/sdcboot
24
14
0
MPL-2.0
9/7/2024, 10:22:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,540,753
dircnt.c
TritonDataCenter_sdcboot/freedos/source/chkdsk/engine/high/dircnt.c
/* Dircount.c - count the number of entries in a directory. Copyright (C) 2000, 2002 Imre Leber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. If you have any questions, comments, suggestions, or fixes please email me at: [email protected] */ #include "fte.h" struct PipeStruct { long count; char attribute; }; /************************************************************** ** counter *************************************************************** ** Counts the number of entries in the directory. **************************************************************/ static BOOL counter(RDWRHandle handle, struct DirectoryPosition* pos, void** buffer) { struct DirectoryEntry* entry; struct PipeStruct* p = *((struct PipeStruct**) buffer); entry = AllocateDirectoryEntry(); if (!entry) RETURN_FTEERROR(FAIL); if (!GetDirectory(handle, pos, entry)) { FreeDirectoryEntry(entry); RETURN_FTEERROR(FAIL); } if (entry->attribute == LFN_ATTRIBUTES) { if (IsLFNEntry(entry)) p->count++; } else if ((entry->attribute & p->attribute) || (p->attribute == -1)) { p->count++; } FreeDirectoryEntry(entry); return TRUE; } /************************************************************** ** low_dircount *************************************************************** ** Counts the number of entries in a directory that has the given ** attribute. ** ** If the number of clusters equals 0, then we assume that we ** have to return the number of entries in the root directory. ** ** If attribute == -1 (0xFF), then all the files in the directory ** are counted. ** ** If attribute == LFN_ATTRIBUTES, then only the LFN entries are counted. ** ** Returns FAIL on error. ***************************************************************/ long low_dircount(RDWRHandle handle, CLUSTER cluster, char attribute) { struct PipeStruct pipe, *ppipe = &pipe; pipe.count = 0; pipe.attribute = attribute; if (!TraverseSubdir(handle, cluster, counter, (void**) &ppipe, TRUE)) RETURN_FTEERROR(FAIL); return pipe.count; }
2,986
C
.c
78
33
74
0.578065
TritonDataCenter/sdcboot
24
14
0
MPL-2.0
9/7/2024, 10:22:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,540,807
fatconst.h
TritonDataCenter_sdcboot/freedos/source/chkdsk/engine/header/fatconst.h
#ifndef FATCONST_H_ #define FATCONST_H_ #define BYTESPERSECTOR 512 /* Bytes per sector. */ /* Actualy can be one of: 512,1024,2048 and 4096, This should be fixed one day. */ #define HD32MB 33554432L /* Size of 32Mb hard disk. */ #define ENTRIESPERSECTOR 16 /* directory entries per sector. */ #define FATREADBUFSIZE 1536 /* size of buffer for working with the fat: scm(12,15,512) */ /* amount of sectors that fit in the buffer. */ #define SECTORSPERREADBUF (FATREADBUFSIZE / BYTESPERSECTOR) #endif
762
C
.c
14
40.785714
75
0.501362
TritonDataCenter/sdcboot
24
14
0
MPL-2.0
9/7/2024, 10:22:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,544,113
ems.h
TritonDataCenter_sdcboot/freedos/source/chkdsk/engine/cache/ems.h
/* +++Date last modified: 05-Jul-1997 */ /* +++Date last modified(Imre): 18-Nov-2002 */ /* ** EMS.H ** ** Header file Expanded Memory Routines */ #ifndef EMS_H_ #define EMS_H_ #define EMS_PAGE_SIZE 16384 /* Each page is this size */ unsigned EMSbaseaddress(void); int EMSversion(void); int EMSstatus(void); unsigned EMSpages(void); int EMSalloc(unsigned pages); int EMSfree(int handle); int EMSmap(int bank, int handle, unsigned page); #endif
507
C
.h
18
25.611111
61
0.655532
TritonDataCenter/sdcboot
24
14
0
MPL-2.0
9/7/2024, 10:22:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,544,150
fteerr.h
TritonDataCenter_sdcboot/freedos/source/chkdsk/engine/header/fteerr.h
#ifndef FTEERR_H_ #define FTEERR_H_ #define FTE_OK 0 #define FTE_READ_ERR 1 #define FTE_WRITE_ERR 2 #define FTE_MEM_INSUFFICIENT 3 #define FTE_WRITE_ON_READONLY 4 #define FTE_INVALID_BYTESPERSECTOR 5 #define FTE_NOT_RESERVED 6 #define FTE_INSUFFICIENT_HANDLES 7 #define FTE_FILESYSTEM_BAD 8 int GetFTEerror (void); void SetFTEerror (int error); void ClearFTEerror (void); #ifdef NDEBUG #define RETURN_FTEERR(value) return value; #define RETURN_FTEERR1(value, skip) return value; #define RETURN_FTEERROR(value) return value; #else void TrackFTEError (int line, char* file); BOOL GetFirstFTEError (int* line, char** file); BOOL GetNextFTEError (int* line, char** file); void UntrackFTEErrors (void); #define RETURN_FTEERR(value) \ { \ if (value != TRUE) \ TrackFTEError(__LINE__, __FILE__); \ return value; \ } #define RETURN_FTEERR1(value, skip) \ { \ if (value != spil) \ TrackFTEError(__LINE__, __FILE__); \ return value; \ } #define RETURN_FTEERROR(value) \ { \ TrackFTEError(__LINE__, __FILE__); \ return value; \ } #endif #endif
1,309
C
.h
42
27.880952
50
0.595984
TritonDataCenter/sdcboot
24
14
0
MPL-2.0
9/7/2024, 10:22:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,544,162
fat.h
TritonDataCenter_sdcboot/freedos/source/chkdsk/engine/header/fat.h
#ifndef FAT_H_ #define FAT_H_ #include "../../engine/header/rdwrsect.h" #define FAT12 12 #define FAT16 16 #define FAT32 32 /* FAT labels for FAT12. */ #define FAT12_FREE_LABEL 0x000 #define FAT12_BAD_LABEL 0xff7 #define FAT12_FREE(x) (x == FAT12_FREE_LABEL) #define FAT12_BAD(x) (x == FAT12_BAD_LABEL) #define FAT12_RESERVED(x) ((x >= 0xff0) && (x <= 0xff8)) #define FAT12_LAST(x) ((x >= 0xff8) && (x <= 0xfff)) #define FAT12_NORMAL(x) ((x != 0) && (x < 0xff0)) /* FAT labels for FAT16. */ #define FAT16_FREE_LABEL 0x0000 #define FAT16_BAD_LABEL 0xfff7 #define FAT16_FREE(x) (x == FAT16_FREE_LABEL) #define FAT16_BAD(x) (x == FAT16_BAD_LABEL) #define FAT16_RESERVED(x) ((x >= 0xfff0) && (x <= 0xfff8)) #define FAT16_LAST(x) ((x >= 0xfff8) && (x <= 0xffff)) #define FAT16_NORMAL(x) ((x != 0) && (x < 0xfff0)) /* FAT labels for FAT32 */ /* Takes the 28bit part of the cluster value that indicates the real cluster. */ #define FAT32_CLUSTER(x) (x & 0x0fffffffL) #define FAT32_FREE_LABEL 0x00000000L #define FAT32_BAD_LABEL 0x0ffffff7L #define FAT32_LAST_LABEL 0x0fffffffL #define FAT32_FREE(x) (FAT32_CLUSTER(x) == FAT32_FREE_LABEL) #define FAT32_BAD(x) (FAT32_CLUSTER(x) == FAT32_BAD_LABEL) #define FAT32_LAST(x) ((FAT32_CLUSTER(x) >= 0xFFFFFF8L) && \ (FAT32_CLUSTER(x) <= 0xFFFFFFFL)) /* Generalised FAT labels. */ /* Notice that we do not give atention to the first two clusters in the FAT that form the reserved clusters. */ #define FAT_CLUSTER FAT32_CLUSTER #define FAT_FREE_LABEL 0x00000000L #define FAT_BAD_LABEL 0x0ffffff7L #define FAT_LAST_LABEL 0x0fffffffL #define FAT_FREE(x) (FAT_CLUSTER(x) == FAT_FREE_LABEL) #define FAT_BAD(x) (FAT_CLUSTER(x) == FAT_BAD_LABEL) #define FAT_LAST(x) (FAT_CLUSTER(x) == FAT_LAST_LABEL) #define FAT_NORMAL(x) (!FAT_FREE(x) && !FAT_BAD(x) && !FAT_LAST(x)) typedef unsigned long CLUSTER; SECTOR GetFatStart(RDWRHandle handle); int GetFatLabelSize(RDWRHandle handle); SECTOR GetDataAreaStart(RDWRHandle handle); SECTOR ConvertToDataSector(RDWRHandle handle, CLUSTER fatcluster); int LinearTraverseFat(RDWRHandle handle, int (*func) (RDWRHandle handle, CLUSTER label, SECTOR datasector, void** structure), void** structure); int FileTraverseFat(RDWRHandle handle, CLUSTER startcluster, int (*func) (RDWRHandle handle, CLUSTER label, SECTOR datasector, void** structure), void** structure); int ReadFatLabel(RDWRHandle handle, CLUSTER labelnr, CLUSTER* label); int WriteFatLabel(RDWRHandle handle, CLUSTER labelnr, CLUSTER label); unsigned long GetBytesInFat(RDWRHandle handle); CLUSTER DataSectorToCluster(RDWRHandle handle, SECTOR sector); SECTOR ConvertToDataSector(RDWRHandle handle, CLUSTER fatcluster); void InvalidateFatCache(RDWRHandle handle); BOOL IsLabelValid(RDWRHandle handle, CLUSTER label); BOOL IsLabelValidInFile(RDWRHandle handle, CLUSTER label); #endif
3,406
C
.h
73
38.931507
72
0.631178
TritonDataCenter/sdcboot
24
14
0
MPL-2.0
9/7/2024, 10:22:45 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
3,656,269
test.c
sparky4_16/16/16/SCRC/test.c
#include <stdio.h> #include "palette.h" void main() { byte *palette; int i; /* get our starting point */ palette = newPal(); palSave(palette); /* fade to black and back */ fadeOff(1, palette); palBlack(); fadeOn(1, palette); palUpdate(palette); /* fade to white and back */ flashOff(1, palette); palWhite(); flashOn(1, palette); palUpdate(palette); free(palette); return; }
478
C
.c
21
16.857143
34
0.582393
sparky4/16
24
3
2
GPL-3.0
9/7/2024, 10:24:55 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,656,653
palette.h
sparky4_16/16/16/SCRC/palette.h
/* * Headers and definitions for the palette routines. */ #include "constant.h" /* fade and flash */ void fadeOn(word fade, byte *palette); void fadeOff(word fade, byte *palette); void flashOn(word fade, byte *palette); void flashOff(word fade, byte *palette); /* save and load */ void palSave(byte *palette); byte *newPal(); void loadPaletteFile(char *filename, byte **palette); /* blanking */ void palBlack(); void palWhite(); /* utility */ void palUpdate(); void waitborder();
511
C
.h
19
24.263158
54
0.707469
sparky4/16
24
3
2
GPL-3.0
9/7/2024, 10:24:55 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,656,654
constant.h
sparky4_16/16/16/SCRC/constant.h
#define PEL_READ_REG 0x03C7 /* Color register, read address */ #define PEL_WRITE_REG 0x03C8 /* Color register, write address */ #define PEL_DATA_REG 0x03C9 /* Color register, data port */ #define PAL_SIZE 768 /* Size of palette in bytes */ #define SC_INDEX 0x03C4 /* Sequence Controller Index */ #define CRTC_INDEX 0x03D4 /* CRT Controller Index */ #define MISC_OUTPUT 0x03C2 /* Miscellaneous Output register */ #define SCREEN_SEG 0x0a000 /* segment of display memory in mode X */ #define INPUT_STATUS_1 0x03DA /* Input Status 1 register */ #define ATC_INDEX 0x03C0 /* Attribute Controller */ #define START_ADDRESS_HIGH 0x0C /* bitmap start address high byte */ #define START_ADDRESS_LOW 0x0D /* bitmap start address low byte */ #define GC_INDEX 0x03CE #define BIT_MASK 0x08 #define MAP_MASK 0x02 #define ALL_COPY_BITS 0x00000+BIT_MASK #define ALL_DRAW_BITS 0x0FF00+BIT_MASK #define SQUARE_WIDTH 16 #define SQUARE_HEIGHT 16 #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 200 #define VIRTUAL_WIDTH 352 #define VIRTUAL_HEIGHT 240 #define PAGE_0 0 #define PAGE_1 0x05540 /* 05470h ;5540h */ #define PAGE_2 0x0AA80 /* 0A8E0h ;AA80h */ #define SCROLL_SPEED 1 /* Don't let it go above 8! */ #define MAGIC_NUM 100 #define CPU8086 0 #define CPU80286 1 #define CPU80386 2 #define CPU80486 3 /* ====================================================================== */ /* Key Assignments */ /* ====================================================================== */ #define kESC 2 #define kONE 4 #define kTWO 6 #define kTHREE 8 #define kFOUR 10 #define kFIVE 12 #define kSIX 14 #define kSEVEN 16 #define kEIGHT 18 #define kNINE 20 #define kZERO 22 #define kMINUS 24 #define kEQUAL 26 #define kBACKSPACE 28 #define kTAB 30 #define kQ 32 #define kW 34 #define kE 36 #define kR 38 #define kT 40 #define kY 42 #define kU 44 #define kI 46 #define kO 48 #define kP 50 #define kL_BRACE 52 #define kR_BRACE 54 #define kENTER 56 #define kCTRL 58 #define kA 60 #define kS 62 #define kD 64 #define kF 66 #define kG 68 #define kH 70 #define kJ 72 #define kK 74 #define kL 76 #define kSEMICOLON 78 #define kQUOTE 80 #define kBACKQUOTE 82 #define kL_SHIFT 84 #define kBACKSLASH 86 #define kZ 88 #define kX 90 #define kC 92 #define kV 94 #define kB 96 #define kN 98 #define kM 100 #define kCOMMA 102 #define kPERIOD 104 #define kSLASH 106 #define kR_SHIFT 108 #define kGREY_STAR 110 #define kALT 112 #define kSPACE 114 #define kCAPSLOCK 116 #define kF1 118 #define kF2 120 #define kF3 122 #define kF4 124 #define kF5 126 #define kF6 128 #define kF7 130 #define kF8 132 #define kF9 134 #define kF10 136 #define kNUMLOCK 138 #define kSCRLLOCK 140 #define kHOME 142 #define kUP 144 #define kPAGE_UP 146 #define kGREY_MINUS 148 #define kLEFT 150 #define kPAD_FIVE 152 #define kRIGHT 154 #define kGREY_PLUS 156 #define kEND 158 #define kDOWN 160 #define kPAGE_DOWN 162 #define kINSERT 164 #define kDELETE 166 #define kF11 174 #define kF12 176 /* handy types */ typedef char byte; typedef short word;
3,201
C
.h
123
23.878049
77
0.69281
sparky4/16
24
3
2
GPL-3.0
9/7/2024, 10:24:55 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,724,702
fdc.c
KaosOverride_CapriceRPI/src/fdc.c
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2004 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Nec uPD765A Floppy Disk Controller emulation (c) Copyright 1997-2003 Ulrich Doewich Nov 08, 2000 - 18:02 started conversion of assembly FDC routines to C Nov 22, 2000 - 17:50 added fdc_read_status() Dec 19, 2000 - 00:05 added fdc_seek() Jan 15, 2001 - 16:52 fdc_read() done Jan 17, 2001 - 19:15 updated/fixed fdc_read(), fdc_readID, fdc_intstat; added fdc_recalib Jan 18, 2001 - 23:43 inlined cmd_read(); added #defines for loading the result buffer; added fdc_drvstat() Jan 24, 2001 - 22:26 fixed fdc_readID() (the result got overwritten by LOAD_RESULT_WITH_CHRN!) Aug 03, 2001 - 00:07 added fdc_write() Aug 04, 2001 - 10:40 added fdc_writeID() Oct 06, 2001 - 23:21 added fdc_readtrk() Oct 07, 2001 - 11:37 got fdc_readtrk() to work properly Jan 12, 2003 - 18:49 fdc_drvstat now reports an error condition when accessing side 2 on a one sided disk Jan 21, 2003 - 18:13 mod to fdc_drvstat was incorrect: drive falls back to 1st side on a single head drive Jan 25, 2003 - 15:57 data transfers can now time out and will be reported via OVERRUN condition Feb 05, 2003 - 19:42 changed the OVERRUN_TIMEOUT to 26µs as per NEC's documentation Feb 08, 2003 - 16:26 added a delay to fdc_read_status in execution phase: FDC first indicates busy before starting data transfer ("Last Mission" loads) Feb 10, 2003 - 21:45 fixed cmd_read: multi-sector reads end on the first sector that is found to have the opposite of the requested AM ("Nigel Mansell's Grand Prix" loads) Feb 11, 2003 - 18:35 increased OVERRUN_TIMEOUT again ("Puffy's Saga" loads) Mar 16, 2003 - 00:19 added the missing scan equal, scan low or equal and scan high or equal commands Mar 16, 2003 - 12:22 modified find_sector: if a sector cannot be found, table index should be 0 Mar 16, 2003 - 16:12 fdc_seek now only changes track if the drive is ready (i.e. has a disk inserted) Mar 17, 2003 - 22:42 updated fdc_intstat to report status changes (drive ready/not ready) Mar 17, 2003 - 23:04 fixed fdc_drvstat: reset ready if motor is off or no disk inserted Mar 22, 2003 - 18:54 added support for the "flipped" disk condition Jun 03, 2003 - 18:34 fixed Bad Cylinder and No Cylinder handling when a sector cannot be found: ("Starfox - CPM version" loads) */ #include "cap32.h" #include "z80.h" extern t_CPC CPC; extern t_FDC FDC; extern t_z80regs z80; extern byte *pbGPBuffer; #ifdef DEBUG_FDC extern FILE *pfoDebug; dword dwBytesTransferred = 0; #endif #define CMD_CODE 0 #define CMD_UNIT 1 #define CMD_C 2 #define CMD_H 3 #define CMD_R 4 #define CMD_N 5 #define CMD_EOT 6 #define CMD_GPL 7 #define CMD_DTL 8 #define CMD_STP 8 #define RES_ST0 0 #define RES_ST1 1 #define RES_ST2 2 #define RES_C 3 #define RES_H 4 #define RES_R 5 #define RES_N 6 #define OVERRUN_TIMEOUT 128*4 #define INITIAL_TIMEOUT OVERRUN_TIMEOUT*4 void fdc_specify(void); void fdc_drvstat(void); void fdc_recalib(void); void fdc_intstat(void); void fdc_seek(void); void fdc_readtrk(void); void fdc_write(void); void fdc_read(void); void fdc_write(void); void fdc_readID(void); void fdc_read(void); void fdc_writeID(void); void fdc_scan(void); void fdc_scanlo(void); void fdc_scanhi(void); typedef struct fdc_cmd_table_def { int cmd; int cmd_length; int res_length; int cmd_direction; void (*cmd_handler)(void); } fdc_cmd_table_def; #define MAX_CMD_COUNT 15 fdc_cmd_table_def fdc_cmd_table[MAX_CMD_COUNT] = { /* syntax is: command code, number of bytes for command, number of bytes for result, direction, pointer to command handler */ {0x03, 3, 0, FDC_TO_CPU, fdc_specify}, // specify {0x04, 2, 1, FDC_TO_CPU, fdc_drvstat}, // sense device status {0x07, 2, 0, FDC_TO_CPU, fdc_recalib}, // recalibrate {0x08, 1, 2, FDC_TO_CPU, fdc_intstat}, // sense interrupt status {0x0f, 3, 0, FDC_TO_CPU, fdc_seek}, // seek {0x42, 9, 7, FDC_TO_CPU, fdc_readtrk}, // read diagnostic {0x45, 9, 7, CPU_TO_FDC, fdc_write}, // write data {0x46, 9, 7, FDC_TO_CPU, fdc_read}, // read data {0x49, 9, 7, CPU_TO_FDC, fdc_write}, // write deleted data {0x4a, 2, 7, FDC_TO_CPU, fdc_readID}, // read id {0x4c, 9, 7, FDC_TO_CPU, fdc_read}, // read deleted data {0x4d, 6, 7, CPU_TO_FDC, fdc_writeID}, // write id {0x51, 9, 7, CPU_TO_FDC, fdc_scan}, // scan equal {0x59, 9, 7, CPU_TO_FDC, fdc_scan}, // scan low or equal {0x5d, 9, 7, CPU_TO_FDC, fdc_scan}, // scan high or equal }; extern t_drive driveA; extern t_drive driveB; t_drive *active_drive; // reference to the currently selected drive t_track *active_track; // reference to the currently selected track, of the active_drive dword read_status_delay = 0; #define LOAD_RESULT_WITH_STATUS \ FDC.result[RES_ST0] |= 0x40; /* AT */ \ FDC.result[RES_ST1] |= 0x80; /* End of Cylinder */ \ if (FDC.command[CMD_CODE] != 0x42) { /* continue only if not a read track command */ \ if ((FDC.result[RES_ST1] & 0x7f) || (FDC.result[RES_ST2] & 0x7f)) { /* any 'error bits' set? */ \ FDC.result[RES_ST1] &= 0x7f; /* mask out End of Cylinder */ \ if ((FDC.result[RES_ST1] & 0x20) || (FDC.result[RES_ST2] & 0x20)) { /* DE and/or DD? */ \ FDC.result[RES_ST2] &= 0xbf; /* mask out Control Mark */ \ } \ else if (FDC.result[RES_ST2] & 0x40) { /* Control Mark? */ \ FDC.result[RES_ST0] &= 0x3f; /* mask out AT */ \ FDC.result[RES_ST1] &= 0x7f; /* mask out End of Cylinder */ \ } \ } \ } #define LOAD_RESULT_WITH_CHRN \ FDC.result[RES_C] = FDC.command[CMD_C]; /* load result with current CHRN values */ \ FDC.result[RES_H] = FDC.command[CMD_H]; \ FDC.result[RES_R] = FDC.command[CMD_R]; \ FDC.result[RES_N] = FDC.command[CMD_N]; void check_unit(void) { switch (FDC.command[CMD_UNIT] & 1) // check unit selection bits of active command { case 0: // target for command is drive A active_drive = &driveA; break; case 1: // target for command is drive B active_drive = &driveB; break; } } int init_status_regs(void) { byte val; memset(&FDC.result, 0, sizeof(FDC.result)); // clear result codes buffer val = FDC.command[CMD_UNIT] & 7; // keep head and unit of command if ((active_drive->tracks == 0) || (!FDC.motor)) { // no DSK in the drive, or drive motor is turned off? val |= 0x48; // Abnormal Termination + Not Ready } FDC.result[RES_ST0] = val; // write ST0 to result codes buffer return (val & 8); // return value indicates whether drive is ready (0) or not (8) } t_sector *find_sector(byte *requested_CHRN) { int loop_count; dword idx; t_sector *sector; sector = NULL; // return value indicates 'sector not found' by default loop_count = 0; // detection of index hole counter idx = active_drive->current_sector; // get the active sector index do { if (!(memcmp(&active_track->sector[idx].CHRN, requested_CHRN, 4))) { // sector matches requested ID? sector = &active_track->sector[idx]; // return value points to sector information if ((sector->flags[0] & 0x20) || (sector->flags[1] & 0x20)) { // any Data Errors? if (active_drive->random_DEs) { // simulate 'random' DEs? FDC.flags |= RNDDE_flag; } } FDC.result[RES_ST2] &= ~(0x02 | 0x10); // remove possible Bad Cylinder + No Cylinder flags break; } byte cylinder = active_track->sector[idx].CHRN[0]; // extract C if (cylinder == 0xff) { FDC.result[RES_ST2] |= 0x02; // Bad Cylinder } else if (cylinder != FDC.command[CMD_C]) { // does not match requested C? FDC.result[RES_ST2] |= 0x10; // No Cylinder } idx++; // increase sector table index if (idx >= active_track->sectors) { // index beyond number of sectors for this track? idx = 0; // reset index loop_count++; // increase 'index hole' count } } while (loop_count < 2); // loop until sector is found, or index hole has passed twice if (FDC.result[RES_ST2] & 0x02) { // Bad Cylinder set? FDC.result[RES_ST2] &= ~0x10; // remove possible No Cylinder flag } active_drive->current_sector = idx; // update sector table index for active drive return sector; } inline void cmd_write(void) { t_sector *sector; sector = find_sector(&FDC.command[CMD_C]); // locate the requested sector on the current track if (sector) { // sector found int sector_size; sector->flags[0] = 0; // clear ST1 for this sector if (FDC.command[CMD_CODE] == 0x45) { // write data command? sector->flags[1] = 0; // clear ST2 } else { // write deleted data sector->flags[1] = 0x40; // set Control Mark } if (FDC.command[CMD_N] == 0) { // use DTL for length? sector_size = FDC.command[CMD_DTL]; // size of sector is defined by DTL value if (sector_size > 0x80) { sector_size = 0x80; // max DTL value is 128 } } else { sector_size = 128 << FDC.command[CMD_N]; // determine number of bytes from N value } FDC.buffer_count = sector_size; // init number of bytes to transfer FDC.buffer_ptr = sector->data; // pointer to sector data FDC.buffer_endptr = active_track->data + active_track->size; // pointer beyond end of track data FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } else { // sector not found FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x04; // No Data LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } inline void cmd_read(void) { t_sector *sector; loop: sector = find_sector(&FDC.command[CMD_C]); // locate the requested sector on the current track if (sector) { // sector found FDC.result[RES_ST1] = sector->flags[0] & 0x25; // copy ST1 to result, ignoring unused bits FDC.result[RES_ST2] = sector->flags[1] & 0x61; // copy ST2 to result, ignoring unused bits if (FDC.command[CMD_CODE] == 0x4c) { // read deleted data command? FDC.result[RES_ST2] ^= 0x40; // invert Control Mark } if ((FDC.flags & SKIP_flag) && (FDC.result[RES_ST2] &= 0x40)) { // skip sector? if (FDC.command[CMD_R] != FDC.command[CMD_EOT]) { // continue looking? FDC.command[CMD_R]++; // advance to next sector goto loop; } else { // no data to transfer -> no execution phase LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // sector data is to be transferred int sector_size; if (FDC.result[RES_ST2] &= 0x40) { // does the sector have an AM opposite of what we want? FDC.command[CMD_EOT] = FDC.command[CMD_R]; // execution ends on this sector } if (FDC.command[CMD_N] == 0) { // use DTL for length? sector_size = FDC.command[CMD_DTL]; // size of sector is defined by DTL value if (sector_size > 0x80) { sector_size = 0x80; // max DTL value is 128 } } else { sector_size = 128 << FDC.command[CMD_N]; // determine number of bytes from N value } FDC.buffer_count = sector_size; // init number of bytes to transfer FDC.buffer_ptr = sector->data; // pointer to sector data FDC.buffer_endptr = active_track->data + active_track->size; // pointer beyond end of track data FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } } else { // sector not found FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x04; // No Data LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } inline void cmd_readtrk(void) { int sector_size; t_sector *sector; sector = &active_track->sector[active_drive->current_sector]; if (memcmp(&sector->CHRN, &FDC.command[CMD_C], 4)) { // sector does not match requested ID? FDC.result[RES_ST1] |= 0x04; // No Data } FDC.result[RES_ST2] &= 0xbf; // clear Control Mark, if it was set FDC.result[RES_ST1] |= sector->flags[0] & 0x25; // copy ST1 to result, ignoring unused bits FDC.result[RES_ST2] |= sector->flags[1] & 0x61; // copy ST2 to result, ignoring unused bits if (FDC.command[CMD_N] == 0) { // use DTL for length? sector_size = FDC.command[CMD_DTL]; // size of sector is defined by DTL value if (sector_size > 0x80) { sector_size = 0x80; // max DTL value is 128 } } else { sector_size = 128 << FDC.command[CMD_N]; // determine number of bytes from N value } FDC.buffer_count = sector_size; // init number of bytes to transfer FDC.buffer_ptr = sector->data; // pointer to sector data FDC.buffer_endptr = active_track->data + active_track->size; // pointer beyond end of track data FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } inline void cmd_scan(void) { t_sector *sector; loop: sector = find_sector(&FDC.command[CMD_C]); // locate the requested sector on the current track if (sector) { // sector found FDC.result[RES_ST1] = sector->flags[0] & 0x25; // copy ST1 to result, ignoring unused bits FDC.result[RES_ST2] = sector->flags[1] & 0x61; // copy ST2 to result, ignoring unused bits if ((FDC.flags & SKIP_flag) && (FDC.result[RES_ST2] &= 0x40)) { // skip sector? if (FDC.command[CMD_R] != FDC.command[CMD_EOT]) { // continue looking? FDC.command[CMD_R] += FDC.command[CMD_STP]; // advance to next sector goto loop; } else { // no data to transfer -> no execution phase LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // sector data is to be transferred int sector_size; if (FDC.result[RES_ST2] &= 0x40) { // does the sector have an AM opposite of what we want? FDC.command[CMD_EOT] = FDC.command[CMD_R]; // execution ends on this sector } sector_size = 128 << FDC.command[CMD_N]; // determine number of bytes from N value FDC.buffer_count = sector_size; // init number of bytes to transfer FDC.buffer_ptr = sector->data; // pointer to sector data FDC.buffer_endptr = active_track->data + active_track->size; // pointer beyond end of track data FDC.flags &= ~SCANFAILED_flag; // reset scan failed flag FDC.result[RES_ST2] |= 0x08; // assume data matches: set Scan Equal Hit FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } } else { // sector not found FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x04; // No Data LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_write_data(byte val) { int idx; #ifdef DEBUG_FDC if (FDC.phase == CMD_PHASE) { if (FDC.byte_count) { fprintf(pfoDebug, "%02x ", val); } else { fprintf(pfoDebug, "\n%02x: ", val); } } #endif switch (FDC.phase) { case CMD_PHASE: // in command phase? if (FDC.byte_count) { // receiving command parameters? FDC.command[FDC.byte_count++] = val; // copy to buffer if (FDC.byte_count == FDC.cmd_length) { // received all command bytes? FDC.byte_count = 0; // clear byte counter FDC.phase = EXEC_PHASE; // switch to execution phase FDC.cmd_handler(); } } else { // first command byte received if (val & 0x20) { // skip DAM or DDAM? FDC.flags |= SKIP_flag; // DAM/DDAM will be skipped val &= ~0x20; // reset skip bit in command byte } else { FDC.flags &= ~SKIP_flag; // make sure skip inidicator is off } for (idx = 0; idx < MAX_CMD_COUNT; idx++) { // loop through all known FDC commands if (fdc_cmd_table[idx].cmd == val) { // do we have a match? break; } } if (idx != MAX_CMD_COUNT) { // valid command received FDC.cmd_length = fdc_cmd_table[idx].cmd_length; // command length in bytes FDC.res_length = fdc_cmd_table[idx].res_length; // result length in bytes FDC.cmd_direction = fdc_cmd_table[idx].cmd_direction; // direction is CPU to FDC, or FDC to CPU FDC.cmd_handler = fdc_cmd_table[idx].cmd_handler; // pointer to command handler FDC.command[FDC.byte_count++] = val; // copy command code to buffer if (FDC.byte_count == FDC.cmd_length) { // already received all command bytes? FDC.byte_count = 0; // clear byte counter FDC.phase = EXEC_PHASE; // switch to execution phase FDC.cmd_handler(); } } else { // unknown command received FDC.result[0] = 0x80; // indicate invalid command FDC.res_length = 1; FDC.phase = RESULT_PHASE; // switch to result phase } } break; case EXEC_PHASE: // in execution phase? if (FDC.cmd_direction == CPU_TO_FDC) { // proper direction? FDC.timeout = OVERRUN_TIMEOUT; if ((FDC.flags & SCAN_flag)) { // processing any of the scan commands? if (val != 0xff) { // no comparison on CPU byte = 0xff switch((FDC.command[CMD_CODE] & 0x1f)) { case 0x51: // scan equal if (val != *FDC.buffer_ptr) { FDC.result[RES_ST2] &= 0xf7; // reset Scan Equal Hit FDC.flags |= SCANFAILED_flag; } break; case 0x59: // scan low or equal if (val != *FDC.buffer_ptr) { FDC.result[RES_ST2] &= 0xf7; // reset Scan Equal Hit } if (val > *FDC.buffer_ptr) { FDC.flags |= SCANFAILED_flag; } break; case 0x5d: // scan high or equal if (val != *FDC.buffer_ptr) { FDC.result[RES_ST2] &= 0xf7; // reset Scan Equal Hit } if (val < *FDC.buffer_ptr) { FDC.flags |= SCANFAILED_flag; } break; } } FDC.buffer_ptr++; // advance sector data pointer } else { *FDC.buffer_ptr++ = val; // write byte to sector } if (FDC.buffer_ptr > FDC.buffer_endptr) { FDC.buffer_ptr = active_track->data; // wrap around } if (--FDC.buffer_count == 0) { // processed all data? if ((FDC.flags & SCAN_flag)) { // processing any of the scan commands? if ((FDC.flags & SCANFAILED_flag) && (FDC.command[CMD_R] != FDC.command[CMD_EOT])) { FDC.command[CMD_R] += FDC.command[CMD_STP]; // advance to next sector cmd_scan(); } else { if ((FDC.flags & SCANFAILED_flag)) { FDC.result[RES_ST2] |= 0x04; // Scan Not Satisfied } LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else if (FDC.command[CMD_CODE] == 0x4d) { // write ID command? dword sector_size, track_size; byte *pbPtr, *pbDataPtr; if (active_track->sectors != 0) { // track is formatted? free(active_track->data); // dealloc memory for old track data } sector_size = 128 << FDC.command[CMD_C]; // determine number of bytes from N value if (((sector_size + 62 + FDC.command[CMD_R]) * FDC.command[CMD_H]) > CPC.max_tracksize) { // track size exceeds maximum? active_track->sectors = 0; // 'unformat' track } else { int sector; track_size = sector_size * FDC.command[CMD_H]; active_track->sectors = FDC.command[CMD_H]; active_track->data = (byte *)malloc(track_size); // attempt to allocate the required memory pbDataPtr = active_track->data; pbPtr = pbGPBuffer; for (sector = 0; sector < FDC.command[CMD_H]; sector++) { memcpy(active_track->sector[sector].CHRN, pbPtr, 4); // copy CHRN memset(active_track->sector[sector].flags, 0, 2); // clear ST1 & ST2 active_track->sector[sector].data = pbDataPtr; // store pointer to sector data pbDataPtr += sector_size; pbPtr += 4; } memset(active_track->data, FDC.command[CMD_N], track_size); // fill track data with specified byte value } pbPtr = pbGPBuffer + ((FDC.command[CMD_H]-1) * 4); // pointer to the last CHRN passed to writeID memcpy(&FDC.result[RES_C], pbPtr, 4); // copy sector's CHRN to result buffer FDC.result[RES_N] = FDC.command[CMD_C]; // overwrite with the N value from the writeID command active_drive->altered = 1; // indicate that the image has been modified FDC.phase = RESULT_PHASE; // switch to result phase } else if (FDC.command[CMD_R] != FDC.command[CMD_EOT]) { // haven't reached End of Track? FDC.command[CMD_R]++; // advance to next sector cmd_write(); } else { active_drive->altered = 1; // indicate that the image has been modified FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x80; // End of Cylinder LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } } break; } } byte fdc_read_status(void) { byte val; val = 0x80; // data register ready if (FDC.phase == EXEC_PHASE) { // in execution phase? if (read_status_delay) { val = 0x10; // FDC is busy read_status_delay--; } else { val |= 0x30; // FDC is executing & busy } if (FDC.cmd_direction == FDC_TO_CPU) { val |= 0x40; // FDC is sending data to the CPU } } else if (FDC.phase == RESULT_PHASE) { // in result phase? val |= 0x50; // FDC is sending data to the CPU, and is busy } else { // in command phase if (FDC.byte_count) { // receiving command parameters? val |= 0x10; // FDC is busy } } return val; } byte fdc_read_data(void) { byte val; val = 0xff; // default value switch (FDC.phase) { case EXEC_PHASE: // in execution phase? if (FDC.cmd_direction == FDC_TO_CPU) { // proper direction? FDC.timeout = OVERRUN_TIMEOUT; val = *FDC.buffer_ptr++; // read byte from current sector #ifdef DEBUG_FDC if (!(FDC.flags & OVERRUN_flag)) { dwBytesTransferred++; } #endif if (FDC.buffer_ptr >= FDC.buffer_endptr) { FDC.buffer_ptr = active_track->data; // wrap around } if (!(--FDC.buffer_count)) { // completed the data transfer? if (FDC.flags & RNDDE_flag) { // simulate random Data Errors? // ***! random DE handling } active_drive->current_sector++; // increase sector index if (FDC.flags & OVERRUN_flag) { // overrun condition detected? FDC.flags &= ~OVERRUN_flag; FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x10; // Overrun LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } else { if (FDC.command[CMD_CODE] == 0x42) { // read track command? if ((--FDC.command[CMD_EOT])) { // continue reading sectors? if (active_drive->current_sector >= active_track->sectors) { // index beyond number of sectors for this track? active_drive->current_sector = 0; // reset index } FDC.command[CMD_R]++; // advance to next sector cmd_readtrk(); } else { LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // normal read (deleted) data command if (!((FDC.result[RES_ST1] & 0x31) || (FDC.result[RES_ST2] & 0x21))) { // no error bits set? if (FDC.command[CMD_R] != FDC.command[CMD_EOT]) { // haven't reached End of Track? FDC.command[CMD_R]++; // advance to next sector cmd_read(); } else { LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } } } } break; case RESULT_PHASE: // in result phase? val = FDC.result[FDC.byte_count++]; // copy value from buffer #ifdef DEBUG_FDC if (dwBytesTransferred) { fprintf(pfoDebug, "{%d} ", dwBytesTransferred); dwBytesTransferred = 0; } fprintf(pfoDebug, "[%02x] ", val); #endif if (FDC.byte_count == FDC.res_length) { // sent all result bytes? FDC.flags &= ~SCAN_flag; // reset scan command flag FDC.byte_count = 0; // clear byte counter FDC.phase = CMD_PHASE; // switch to command phase FDC.led = 0; // turn the drive LED off } break; } return val; } void fdc_specify(void) { FDC.phase = CMD_PHASE; // switch back to command phase (fdc_specify has no result phase!) } void fdc_drvstat(void) { byte val; check_unit(); // switch to target drive val = FDC.command[CMD_UNIT] & 7; // keep head and unit of command if ((active_drive->write_protected) || (active_drive->tracks == 0)) { // write protected, or disk missing? val |= 0x48; // set Write Protect + Two Sided (?) } if ((active_drive->tracks) && (FDC.motor)) { val |= 0x20; // set Ready } if (active_drive->current_track == 0) { // drive head is over track 0? val |= 0x10; // set Track 0 } FDC.result[RES_ST0] = val; FDC.phase = RESULT_PHASE; // switch to result phase } void fdc_recalib(void) { FDC.command[CMD_C] = 0; // seek to track 0 fdc_seek(); } void fdc_intstat(void) { byte val; val = FDC.result[RES_ST0] & 0xf8; // clear Head Address and Unit bits if (FDC.flags & SEEKDRVA_flag) { // seek completed on drive A? val |= 0x20; // set Seek End FDC.flags &= ~(SEEKDRVA_flag | STATUSDRVA_flag); // clear seek done and status change flags FDC.result[RES_ST0] = val; FDC.result[RES_ST1] = driveA.current_track; } else if (FDC.flags & SEEKDRVB_flag) { // seek completed on drive B? val |= 0x21; // set Seek End FDC.flags &= ~(SEEKDRVB_flag | STATUSDRVB_flag); // clear seek done and status change flags FDC.result[RES_ST0] = val; FDC.result[RES_ST1] = driveB.current_track; } else if (FDC.flags & STATUSDRVA_flag) { // has the status of drive A changed? val = 0xc0; // status change if ((driveA.tracks == 0) || (!FDC.motor)) { // no DSK in the drive, or drive motor is turned off? val |= 0x08; // not ready } FDC.flags &= ~STATUSDRVA_flag; // clear status change flag FDC.result[RES_ST0] = val; FDC.result[RES_ST1] = driveA.current_track; } else if (FDC.flags & STATUSDRVB_flag) { // has the status of drive B changed? val = 0xc1; // status change if ((driveB.tracks == 0) || (!FDC.motor)) { // no DSK in the drive, or drive motor is turned off? val |= 0x08; // not ready } FDC.flags &= ~STATUSDRVB_flag; // clear status change flag FDC.result[RES_ST0] = val; FDC.result[RES_ST1] = driveB.current_track; } else { val = 0x80; // Invalid Command FDC.result[RES_ST0] = val; FDC.res_length = 1; } FDC.phase = RESULT_PHASE; // switch to result phase } void fdc_seek(void) { check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_track = FDC.command[CMD_C]; if (active_drive->current_track >= DSK_TRACKMAX) { // beyond valid range? active_drive->current_track = DSK_TRACKMAX-1; // limit to maximum } } FDC.flags |= (FDC.command[CMD_UNIT] & 1) ? SEEKDRVB_flag : SEEKDRVA_flag; // signal completion of seek operation FDC.phase = CMD_PHASE; // switch back to command phase (fdc_seek has no result phase!) } void fdc_readtrk(void) { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_track->sectors != 0) { // track is formatted? FDC.command[CMD_R] = 1; // set sector ID to 1 active_drive->current_sector = 0; // reset sector table index cmd_readtrk(); } else { // unformatted track FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_write(void) { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_drive->write_protected) { // is write protect tab set? FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x02; // Not Writable LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } else if (active_track->sectors != 0) { // track is formatted? cmd_write(); } else { // unformatted track FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_read(void) { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_track->sectors != 0) { // track is formatted? cmd_read(); } else { // unformatted track FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_readID(void) { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_track->sectors != 0) { // track is formatted? dword idx; idx = active_drive->current_sector; // get the active sector index if (idx >= active_track->sectors) { // index beyond number of sectors for this track? idx = 0; // reset index } memcpy(&FDC.result[RES_C], &active_track->sector[idx].CHRN, 4); // copy sector's CHRN to result buffer active_drive->current_sector = idx + 1; // update sector table index for active drive } else { // unformatted track FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN } } FDC.phase = RESULT_PHASE; // switch to result phase } void fdc_writeID(void) { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_drive->write_protected) { // is write protect tab set? FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x02; // Not Writable LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } else { FDC.buffer_count = FDC.command[CMD_H] << 2; // number of sectors * 4 = number of bytes still outstanding FDC.buffer_ptr = pbGPBuffer; // buffer to temporarily hold the track format FDC.buffer_endptr = pbGPBuffer + FDC.buffer_count; FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_scan(void) { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_track->sectors != 0) { // track is formatted? if (FDC.command[CMD_STP] > 2) { FDC.command[CMD_STP] = 2; // step can only be 1 or 2 } FDC.flags |= SCAN_flag; // scan command active cmd_scan(); } else { // unformatted track FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } }
39,743
C
.c
877
35.177879
139
0.567165
KaosOverride/CapriceRPI
22
7
9
GPL-2.0
9/7/2024, 10:26:35 AM (Europe/Amsterdam)
true
false
false
true
true
false
false
false
3,751,184
leaks-c.c
ssbssa_dwarfstack/examples/leak-detector/leaks-c.c
// Copyright Hannes Domani 2013. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file ../LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include "inc/leaks.i"
238
C
.c
5
46.2
61
0.670996
ssbssa/dwarfstack
28
5
0
LGPL-2.1
9/7/2024, 10:26:52 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
3,792,111
omp-fesdr.c
apc-llc_gcc-5_1_1-knc/gcc/testsuite/gcc.dg/debug/dwarf2/omp-fesdr.c
/* { dg-do compile } */ /* { dg-require-effective-target fopenmp } */ /* { dg-options "-g -fopenmp -gdwarf-2 -femit-struct-debug-reduced" } */ struct aa { int a; }; int f7 (void) { int v7i = 6, v7j = 7, v7k = 9, v7l = 0, v7n = 0, v7o = 1; #pragma omp parallel { #pragma omp master v7o++; #pragma omp for private (v7i) firstprivate (v7k) reduction (+:v7l) for (v7n = 0; v7n < 3; v7n++) { int v7m = v7j + v7k; v7i = 8; v7l++; } } return v7i + v7j + v7k + v7l + v7n; } int main (void) { f7 (); return 0; }
567
C
.c
31
15.258065
72
0.555556
apc-llc/gcc-5.1.1-knc
20
15
1
GPL-2.0
9/7/2024, 10:27:42 AM (Europe/Amsterdam)
false
true
false
true
true
true
false
false
3,967,713
OperatingSystem.h
praaline_Praaline/pngui/nodeeditor/OperatingSystem.h
#pragma once #if \ defined (__CYGWIN__) || \ defined (__CYGWIN32__) # define NODE_EDITOR_PLATFORM "Cygwin" # define NODE_EDITOR_PLATFORM_CYGWIN # define NODE_EDITOR_PLATFORM_UNIX # define NODE_EDITOR_PLATFORM_WINDOWS #elif \ defined (_WIN16) || \ defined (_WIN32) || \ defined (_WIN64) || \ defined (__WIN32__) || \ defined (__TOS_WIN__) || \ defined (__WINDOWS__) # define NODE_EDITOR_PLATFORM "Windows" # define NODE_EDITOR_PLATFORM_WINDOWS #elif \ defined (macintosh) || \ defined (Macintosh) || \ defined (__TOS_MACOS__) || \ (defined (__APPLE__) && defined (__MACH__)) # define NODE_EDITOR_PLATFORM "Mac" # define NODE_EDITOR_PLATFORM_MAC # define NODE_EDITOR_PLATFORM_UNIX #elif \ defined (linux) || \ defined (__linux) || \ defined (__linux__) || \ defined (__TOS_LINUX__) # define NODE_EDITOR_PLATFORM "Linux" # define NODE_EDITOR_PLATFORM_LINUX # define NODE_EDITOR_PLATFORM_UNIX #elif \ defined (__FreeBSD__) || \ defined (__OpenBSD__) || \ defined (__NetBSD__) || \ defined (__bsdi__) || \ defined (__DragonFly__) # define NODE_EDITOR_PLATFORM "BSD" # define NODE_EDITOR_PLATFORM_BSD # define NODE_EDITOR_PLATFORM_UNIX #elif \ defined (sun) || \ defined (__sun) # define NODE_EDITOR_PLATFORM "Solaris" # define NODE_EDITOR_PLATFORM_SOLARIS # define NODE_EDITOR_PLATFORM_UNIX #elif \ defined (_AIX) || \ defined (__TOS_AIX__) # define NODE_EDITOR_PLATFORM "AIX" # define NODE_EDITOR_PLATFORM_AIX # define NODE_EDITOR_PLATFORM_UNIX #elif \ defined (hpux) || \ defined (_hpux) || \ defined (__hpux) # define NODE_EDITOR_PLATFORM "HPUX" # define NODE_EDITOR_PLATFORM_HPUX # define NODE_EDITOR_PLATFORM_UNIX #elif \ defined (__QNX__) # define NODE_EDITOR_PLATFORM "QNX" # define NODE_EDITOR_PLATFORM_QNX # define NODE_EDITOR_PLATFORM_UNIX #elif \ defined (unix) || \ defined (__unix) || \ defined (__unix__) # define NODE_EDITOR_PLATFORM "Unix" # define NODE_EDITOR_PLATFORM_UNIX #endif #ifndef NODE_EDITOR_PLATFORM # error "Current platform is not supported." #endif
3,949
C
.h
76
50.092105
80
0.349264
praaline/Praaline
27
5
1
GPL-3.0
9/7/2024, 10:29:21 AM (Europe/Amsterdam)
false
false
false
true
false
true
false
false
3,999,743
SUPLibAll.c
TusharPardhe_Unknown-OS/lib/dkms/virtualbox/5.0.40/build/vboxdrv/SUPLibAll.c
/* $Id: SUPLibAll.cpp $ */ /** @file * VirtualBox Support Library - All Contexts Code. */ /* * Copyright (C) 2006-2015 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * General Public License (GPL) as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. * * The contents of this file may alternatively be used under the terms * of the Common Development and Distribution License Version 1.0 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the * VirtualBox OSE distribution, in which case the provisions of the * CDDL are applicable instead of those of the GPL. * * You may elect to license modified versions of this file under the * terms and conditions of either the GPL or the CDDL or both. */ /********************************************************************************************************************************* * Header Files * *********************************************************************************************************************************/ #include <VBox/sup.h> #ifdef IN_RC # include <VBox/vmm/vm.h> # include <VBox/vmm/vmm.h> #endif #ifdef IN_RING0 # include <iprt/mp.h> #endif #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) # include <iprt/asm-amd64-x86.h> #endif #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) /** * The slow case for SUPReadTsc where we need to apply deltas. * * Must only be called when deltas are applicable, so please do not call it * directly. * * @returns TSC with delta applied. * @param pGip Pointer to the GIP. * * @remarks May be called with interrupts disabled in ring-0! This is why the * ring-0 code doesn't attempt to figure the delta. * * @internal */ SUPDECL(uint64_t) SUPReadTscWithDelta(PSUPGLOBALINFOPAGE pGip) { uint64_t uTsc; uint16_t iGipCpu; AssertCompile(RT_IS_POWER_OF_TWO(RTCPUSET_MAX_CPUS)); AssertCompile(RT_ELEMENTS(pGip->aiCpuFromCpuSetIdx) >= RTCPUSET_MAX_CPUS); Assert(pGip->enmUseTscDelta > SUPGIPUSETSCDELTA_PRACTICALLY_ZERO); /* * Read the TSC and get the corresponding aCPUs index. */ #ifdef IN_RING3 if (pGip->fGetGipCpu & SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS) { /* RDTSCP gives us all we need, no loops/cli. */ uint32_t iCpuSet; uTsc = ASMReadTscWithAux(&iCpuSet); iCpuSet &= RTCPUSET_MAX_CPUS - 1; iGipCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet]; } else if (pGip->fGetGipCpu & SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS) { /* Storing the IDTR is normally very quick, but we need to loop. */ uint32_t cTries = 0; for (;;) { uint16_t cbLim = ASMGetIdtrLimit(); uTsc = ASMReadTSC(); if (RT_LIKELY(ASMGetIdtrLimit() == cbLim)) { uint16_t iCpuSet = cbLim - 256 * (ARCH_BITS == 64 ? 16 : 8); iCpuSet &= RTCPUSET_MAX_CPUS - 1; iGipCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet]; break; } if (cTries >= 16) { iGipCpu = UINT16_MAX; break; } cTries++; } } else { /* Get APIC ID via the slow CPUID instruction, requires looping. */ uint32_t cTries = 0; for (;;) { uint8_t idApic = ASMGetApicId(); uTsc = ASMReadTSC(); if (RT_LIKELY(ASMGetApicId() == idApic)) { iGipCpu = pGip->aiCpuFromApicId[idApic]; break; } if (cTries >= 16) { iGipCpu = UINT16_MAX; break; } cTries++; } } #elif defined(IN_RING0) /* Ring-0: Use use RTMpCpuId(), no loops. */ RTCCUINTREG uFlags = ASMIntDisableFlags(); int iCpuSet = RTMpCpuIdToSetIndex(RTMpCpuId()); if (RT_LIKELY((unsigned)iCpuSet < RT_ELEMENTS(pGip->aiCpuFromCpuSetIdx))) iGipCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet]; else iGipCpu = UINT16_MAX; uTsc = ASMReadTSC(); ASMSetFlags(uFlags); # elif defined(IN_RC) /* Raw-mode context: We can get the host CPU set index via VMCPU, no loops. */ RTCCUINTREG uFlags = ASMIntDisableFlags(); /* Are already disable, but play safe. */ uint32_t iCpuSet = VMMGetCpu(&g_VM)->iHostCpuSet; if (RT_LIKELY(iCpuSet < RT_ELEMENTS(pGip->aiCpuFromCpuSetIdx))) iGipCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet]; else iGipCpu = UINT16_MAX; uTsc = ASMReadTSC(); ASMSetFlags(uFlags); #else # error "IN_RING3, IN_RC or IN_RING0 must be defined!" #endif /* * If the delta is valid, apply it. */ if (RT_LIKELY(iGipCpu < pGip->cCpus)) { int64_t iTscDelta = pGip->aCPUs[iGipCpu].i64TSCDelta; if (RT_LIKELY(iTscDelta != INT64_MAX)) return uTsc - iTscDelta; # ifdef IN_RING3 /* * The delta needs calculating, call supdrv to get the TSC. */ int rc = SUPR3ReadTsc(&uTsc, NULL); if (RT_SUCCESS(rc)) return uTsc; AssertMsgFailed(("SUPR3ReadTsc -> %Rrc\n", rc)); uTsc = ASMReadTSC(); # endif /* IN_RING3 */ } /* * This shouldn't happen, especially not in ring-3 and raw-mode context. * But if it does, return something that's half useful. */ AssertMsgFailed(("iGipCpu=%d (%#x) cCpus=%d fGetGipCpu=%#x\n", iGipCpu, iGipCpu, pGip->cCpus, pGip->fGetGipCpu)); return uTsc; } /** * Internal worker for getting the GIP CPU array index for the calling CPU. * * @returns Index into SUPGLOBALINFOPAGE::aCPUs or UINT16_MAX. * @param pGip The GIP. */ DECLINLINE(uint16_t) supGetGipCpuIndex(PSUPGLOBALINFOPAGE pGip) { uint16_t iGipCpu; #ifdef IN_RING3 if (pGip->fGetGipCpu & SUPGIPGETCPU_IDTR_LIMIT_MASK_MAX_SET_CPUS) { /* Storing the IDTR is normally very fast. */ uint16_t cbLim = ASMGetIdtrLimit(); uint16_t iCpuSet = cbLim - 256 * (ARCH_BITS == 64 ? 16 : 8); iCpuSet &= RTCPUSET_MAX_CPUS - 1; iGipCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet]; } else if (pGip->fGetGipCpu & SUPGIPGETCPU_RDTSCP_MASK_MAX_SET_CPUS) { /* RDTSCP gives us what need need and more. */ uint32_t iCpuSet; ASMReadTscWithAux(&iCpuSet); iCpuSet &= RTCPUSET_MAX_CPUS - 1; iGipCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet]; } else { /* Get APIC ID via the slow CPUID instruction. */ uint8_t idApic = ASMGetApicId(); iGipCpu = pGip->aiCpuFromApicId[idApic]; } #elif defined(IN_RING0) /* Ring-0: Use use RTMpCpuId() (disables cli to avoid host OS assertions about unsafe CPU number usage). */ RTCCUINTREG uFlags = ASMIntDisableFlags(); int iCpuSet = RTMpCpuIdToSetIndex(RTMpCpuId()); if (RT_LIKELY((unsigned)iCpuSet < RT_ELEMENTS(pGip->aiCpuFromCpuSetIdx))) iGipCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet]; else iGipCpu = UINT16_MAX; ASMSetFlags(uFlags); # elif defined(IN_RC) /* Raw-mode context: We can get the host CPU set index via VMCPU. */ uint32_t iCpuSet = VMMGetCpu(&g_VM)->iHostCpuSet; if (RT_LIKELY(iCpuSet < RT_ELEMENTS(pGip->aiCpuFromCpuSetIdx))) iGipCpu = pGip->aiCpuFromCpuSetIdx[iCpuSet]; else iGipCpu = UINT16_MAX; #else # error "IN_RING3, IN_RC or IN_RING0 must be defined!" #endif return iGipCpu; } /** * Slow path in SUPGetTscDelta, don't call directly. * * @returns See SUPGetTscDelta. * @param pGip The GIP. * @internal */ SUPDECL(uint64_t) SUPGetTscDeltaSlow(PSUPGLOBALINFOPAGE pGip) { uint16_t iGipCpu = supGetGipCpuIndex(pGip); if (RT_LIKELY(iGipCpu < pGip->cCpus)) { int64_t iTscDelta = pGip->aCPUs[iGipCpu].i64TSCDelta; if (iTscDelta != INT64_MAX) return iTscDelta; } AssertFailed(); return 0; } /** * Slow path in SUPGetCpuHzFromGip, don't call directly. * * @returns See SUPGetCpuHzFromGip. * @param pGip The GIP. * @internal */ SUPDECL(uint64_t) SUPGetCpuHzFromGipForAsyncMode(PSUPGLOBALINFOPAGE pGip) { uint16_t iGipCpu = supGetGipCpuIndex(pGip); if (RT_LIKELY(iGipCpu < pGip->cCpus)) return pGip->aCPUs[iGipCpu].u64CpuHz; AssertFailed(); return pGip->u64CpuHz; } /** * Worker for SUPIsTscFreqCompatible(). * * @returns true if it's compatible, false otherwise. * @param uBaseCpuHz The reference CPU frequency of the system. * @param uCpuHz The CPU frequency to compare with the base. * @param fRelax Whether to use a more relaxed threshold (like * for when running in a virtualized environment). * * @remarks Don't use directly, use SUPIsTscFreqCompatible() instead. This is * to be used by tstGIP-2 or the like. */ SUPDECL(bool) SUPIsTscFreqCompatibleEx(uint64_t uBaseCpuHz, uint64_t uCpuHz, bool fRelax) { if (uBaseCpuHz != uCpuHz) { /* Arbitrary tolerance threshold, tweak later if required, perhaps more tolerance on lower frequencies and less tolerance on higher. */ uint16_t uFact = !fRelax ? 666 /* 0.15% */ : 125 /* 0.8% */; uint64_t uThr = uBaseCpuHz / uFact; uint64_t uLo = uBaseCpuHz - uThr; uint64_t uHi = uBaseCpuHz + uThr; if ( uCpuHz < uLo || uCpuHz > uHi) return false; } return true; } /** * Checks if the provided TSC frequency is close enough to the computed TSC * frequency of the host. * * @returns true if it's compatible, false otherwise. * @param uCpuHz The TSC frequency to check. * @param puGipCpuHz Where to store the GIP TSC frequency used * during the compatibility test - optional. * @param fRelax Whether to use a more relaxed threshold (like * for when running in a virtualized environment). */ SUPDECL(bool) SUPIsTscFreqCompatible(uint64_t uCpuHz, uint64_t *puGipCpuHz, bool fRelax) { PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage; bool fCompat = false; uint64_t uGipCpuHz = 0; if ( pGip && pGip->u32Mode != SUPGIPMODE_ASYNC_TSC) { uGipCpuHz = pGip->u64CpuHz; fCompat = SUPIsTscFreqCompatibleEx(uGipCpuHz, uCpuHz, fRelax); } if (puGipCpuHz) *puGipCpuHz = uGipCpuHz; return fCompat; } #endif /* RT_ARCH_AMD64 || RT_ARCH_X86 */
10,964
C
.c
307
30.283388
130
0.616101
TusharPardhe/Unknown-OS
24
0
0
GPL-3.0
9/7/2024, 10:30:28 AM (Europe/Amsterdam)
true
false
false
true
true
false
false
false
3,999,751
SUPDrvDTrace.c
TusharPardhe_Unknown-OS/lib/dkms/virtualbox/5.0.40/build/vboxdrv/SUPDrvDTrace.c
/* $Id: SUPDrv-dtrace.cpp $ */ /** @file * VBoxDrv - The VirtualBox Support Driver - DTrace Provider. */ /* * Copyright (C) 2012-2015 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * General Public License (GPL) as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. * * The contents of this file may alternatively be used under the terms * of the Common Development and Distribution License Version 1.0 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the * VirtualBox OSE distribution, in which case the provisions of the * CDDL are applicable instead of those of the GPL. * * You may elect to license modified versions of this file under the * terms and conditions of either the GPL or the CDDL or both. */ /********************************************************************************************************************************* * Header Files * *********************************************************************************************************************************/ #define LOG_GROUP LOG_GROUP_SUP_DRV #include "SUPDrvInternal.h" #include <VBox/err.h> #include <VBox/log.h> #include <VBox/VBoxTpG.h> #include <iprt/assert.h> #include <iprt/ctype.h> #include <iprt/mem.h> #include <iprt/errno.h> #ifdef RT_OS_DARWIN # include <iprt/dbg.h> #endif #ifdef RT_OS_DARWIN # include VBOX_PATH_MACOSX_DTRACE_H #elif defined(RT_OS_LINUX) /* Avoid type and define conflicts. */ # undef UINT8_MAX # undef UINT16_MAX # undef UINT32_MAX # undef UINT64_MAX # undef INT64_MAX # undef INT64_MIN # define intptr_t dtrace_intptr_t # if 0 /* DTrace experiments with the Unbreakable Enterprise Kernel (UEK2) (Oracle Linux). 1. The dtrace.h here is from the dtrace module source, not /usr/include/sys/dtrace.h nor /usr/include/dtrace.h. 2. To generate the missing entries for the dtrace module in Module.symvers of UEK: nm /lib/modules/....../kernel/drivers/dtrace/dtrace.ko \ | grep _crc_ \ | sed -e 's/^......../0x/' -e 's/ A __crc_/\t/' \ -e 's/$/\tdrivers\/dtrace\/dtrace\tEXPORT_SYMBOL/' \ >> Module.symvers Update: Althernative workaround (active), resolve symbols dynamically. 3. No tracepoints in vboxdrv, vboxnet* or vboxpci yet. This requires yasm and VBoxTpG and build time. */ # include "dtrace.h" # else /* DTrace experiments with the Unbreakable Enterprise Kernel (UEKR3) (Oracle Linux). 1. To generate the missing entries for the dtrace module in Module.symvers of UEK: nm /lib/modules/....../kernel/drivers/dtrace/dtrace.ko \ | grep _crc_ \ | sed -e 's/^......../0x/' -e 's/ A __crc_/\t/' \ -e 's/$/\tdrivers\/dtrace\/dtrace\tEXPORT_SYMBOL/' \ >> Module.symvers Update: Althernative workaround (active), resolve symbols dynamically. 2. No tracepoints in vboxdrv, vboxnet* or vboxpci yet. This requires yasm and VBoxTpG and build time. */ # include <dtrace/provider.h> # include <dtrace/enabling.h> /* Missing from provider.h. */ # include <dtrace/arg.h> /* Missing from provider.h. */ # endif # include <linux/kallsyms.h> /** Status code fixer (UEK uses linux convension unlike the others). */ # define FIX_UEK_RC(a_rc) (-(a_rc)) #else # include <sys/dtrace.h> #endif /** * The UEK DTrace port is trying to be smart and seems to have turned all * errno return codes negative. While this conforms to the linux kernel way of * doing things, it breaks with the way the interfaces work on Solaris and * Mac OS X. */ #ifndef FIX_UEK_RC # define FIX_UEK_RC(a_rc) (a_rc) #endif /********************************************************************************************************************************* * Structures and Typedefs * *********************************************************************************************************************************/ /* Seems there is some return code difference here. Keep the return code and case it to whatever the host desires. */ #ifdef RT_OS_DARWIN # if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 typedef void FNPOPS_ENABLE(void *, dtrace_id_t, void *); # else typedef int FNPOPS_ENABLE(void *, dtrace_id_t, void *); # endif #else typedef int FNPOPS_ENABLE(void *, dtrace_id_t, void *); #endif /** Caller indicator. */ typedef enum VBOXDTCALLER { kVBoxDtCaller_Invalid = 0, kVBoxDtCaller_Generic, kVBoxDtCaller_ProbeFireUser, kVBoxDtCaller_ProbeFireKernel } VBOXDTCALLER; /** * Stack data planted before calling dtrace_probe so that we can easily find the * stack argument later. */ typedef struct VBDTSTACKDATA { /** Eyecatcher no. 1 (SUPDRVDT_STACK_DATA_MAGIC2). */ uint32_t u32Magic1; /** Eyecatcher no. 2 (SUPDRVDT_STACK_DATA_MAGIC2). */ uint32_t u32Magic2; /** The format of the caller specific data. */ VBOXDTCALLER enmCaller; /** Caller specific data. */ union { /** kVBoxDtCaller_ProbeFireKernel. */ struct { /** Pointer to the stack arguments of a probe function call. */ uintptr_t *pauStackArgs; } ProbeFireKernel; /** kVBoxDtCaller_ProbeFireUser. */ struct { /** The user context. */ PCSUPDRVTRACERUSRCTX pCtx; /** The argument displacement caused by 64-bit arguments passed directly to * dtrace_probe. */ int offArg; } ProbeFireUser; } u; /** Pointer to this structure. * This is the final bit of integrity checking. */ struct VBDTSTACKDATA *pSelf; } VBDTSTACKDATA; /** Pointer to the on-stack thread specific data. */ typedef VBDTSTACKDATA *PVBDTSTACKDATA; /********************************************************************************************************************************* * Defined Constants And Macros * *********************************************************************************************************************************/ /** The first magic value. */ #define SUPDRVDT_STACK_DATA_MAGIC1 RT_MAKE_U32_FROM_U8('S', 'U', 'P', 'D') /** The second magic value. */ #define SUPDRVDT_STACK_DATA_MAGIC2 RT_MAKE_U32_FROM_U8('D', 'T', 'r', 'c') /** The alignment of the stack data. * The data doesn't require more than sizeof(uintptr_t) alignment, but the * greater alignment the quicker lookup. */ #define SUPDRVDT_STACK_DATA_ALIGN 32 /** Plants the stack data. */ #define VBDT_SETUP_STACK_DATA(a_enmCaller) \ uint8_t abBlob[sizeof(VBDTSTACKDATA) + SUPDRVDT_STACK_DATA_ALIGN - 1]; \ PVBDTSTACKDATA pStackData = (PVBDTSTACKDATA)( (uintptr_t)&abBlob[SUPDRVDT_STACK_DATA_ALIGN - 1] \ & ~(uintptr_t)(SUPDRVDT_STACK_DATA_ALIGN - 1)); \ pStackData->u32Magic1 = SUPDRVDT_STACK_DATA_MAGIC1; \ pStackData->u32Magic2 = SUPDRVDT_STACK_DATA_MAGIC2; \ pStackData->enmCaller = a_enmCaller; \ pStackData->pSelf = pStackData /** Passifies the stack data and frees up resource held within it. */ #define VBDT_CLEAR_STACK_DATA() \ do \ { \ pStackData->u32Magic1 = 0; \ pStackData->u32Magic2 = 0; \ pStackData->pSelf = NULL; \ } while (0) /** Simple SUPR0Printf-style logging. */ #if 0 /*def DEBUG_bird*/ # define LOG_DTRACE(a) SUPR0Printf a #else # define LOG_DTRACE(a) do { } while (0) #endif /********************************************************************************************************************************* * Global Variables * *********************************************************************************************************************************/ #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) /** @name DTrace kernel interface used on Darwin and Linux. * @{ */ static void (* g_pfnDTraceProbeFire)(dtrace_id_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t); static dtrace_id_t (* g_pfnDTraceProbeCreate)(dtrace_provider_id_t, const char *, const char *, const char *, int, void *); static dtrace_id_t (* g_pfnDTraceProbeLookup)(dtrace_provider_id_t, const char *, const char *, const char *); static int (* g_pfnDTraceProviderRegister)(const char *, const dtrace_pattr_t *, uint32_t, /*cred_t*/ void *, const dtrace_pops_t *, void *, dtrace_provider_id_t *); static void (* g_pfnDTraceProviderInvalidate)(dtrace_provider_id_t); static int (* g_pfnDTraceProviderUnregister)(dtrace_provider_id_t); #define dtrace_probe g_pfnDTraceProbeFire #define dtrace_probe_create g_pfnDTraceProbeCreate #define dtrace_probe_lookup g_pfnDTraceProbeLookup #define dtrace_register g_pfnDTraceProviderRegister #define dtrace_invalidate g_pfnDTraceProviderInvalidate #define dtrace_unregister g_pfnDTraceProviderUnregister /** @} */ #endif /** * Gets the stack data. * * @returns Pointer to the stack data. Never NULL. */ static PVBDTSTACKDATA vboxDtGetStackData(void) { /* * Locate the caller of probe_dtrace. */ int volatile iDummy = 1; /* use this to get the stack address. */ PVBDTSTACKDATA pData = (PVBDTSTACKDATA)( ((uintptr_t)&iDummy + SUPDRVDT_STACK_DATA_ALIGN - 1) & ~(uintptr_t)(SUPDRVDT_STACK_DATA_ALIGN - 1)); for (;;) { if ( pData->u32Magic1 == SUPDRVDT_STACK_DATA_MAGIC1 && pData->u32Magic2 == SUPDRVDT_STACK_DATA_MAGIC2 && pData->pSelf == pData) return pData; pData = (PVBDTSTACKDATA)((uintptr_t)pData + SUPDRVDT_STACK_DATA_ALIGN); } } /* * * Helpers for handling VTG structures. * Helpers for handling VTG structures. * Helpers for handling VTG structures. * */ /** * Converts an attribute from VTG description speak to DTrace. * * @param pDtAttr The DTrace attribute (dst). * @param pVtgAttr The VTG attribute descriptor (src). */ static void vboxDtVtgConvAttr(dtrace_attribute_t *pDtAttr, PCVTGDESCATTR pVtgAttr) { pDtAttr->dtat_name = pVtgAttr->u8Code - 1; pDtAttr->dtat_data = pVtgAttr->u8Data - 1; pDtAttr->dtat_class = pVtgAttr->u8DataDep - 1; } /** * Gets a string from the string table. * * @returns Pointer to the string. * @param pVtgHdr The VTG object header. * @param offStrTab The string table offset. */ static const char *vboxDtVtgGetString(PVTGOBJHDR pVtgHdr, uint32_t offStrTab) { Assert(offStrTab < pVtgHdr->cbStrTab); return (const char *)pVtgHdr + pVtgHdr->offStrTab + offStrTab; } /* * * DTrace Provider Interface. * DTrace Provider Interface. * DTrace Provider Interface. * */ /** * @callback_method_impl{dtrace_pops_t,dtps_provide} */ static void vboxDtPOps_Provide(void *pvProv, const dtrace_probedesc_t *pDtProbeDesc) { PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv; AssertPtrReturnVoid(pProv); LOG_DTRACE(("%s: %p / %p pDtProbeDesc=%p\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, pDtProbeDesc)); if (pDtProbeDesc) return; /* We don't generate probes, so never mind these requests. */ if (pProv->TracerData.DTrace.fZombie) return; dtrace_provider_id_t const idProvider = pProv->TracerData.DTrace.idProvider; AssertPtrReturnVoid(idProvider); AssertPtrReturnVoid(pProv->pHdr); AssertReturnVoid(pProv->pHdr->offProbeLocs != 0); uint32_t const cProbeLocs = pProv->pHdr->cbProbeLocs / sizeof(VTGPROBELOC); /* Need a buffer for extracting the function names and mangling them in case of collision. */ size_t const cbFnNmBuf = _4K + _1K; char *pszFnNmBuf = (char *)RTMemAlloc(cbFnNmBuf); if (!pszFnNmBuf) return; /* * Itereate the probe location list and register all probes related to * this provider. */ uint16_t const idxProv = (uint16_t)((PVTGDESCPROVIDER)((uintptr_t)pProv->pHdr + pProv->pHdr->offProviders) - pProv->pDesc); uint32_t idxProbeLoc; for (idxProbeLoc = 0; idxProbeLoc < cProbeLocs; idxProbeLoc++) { /* Skip probe location belonging to other providers or once that we've already reported. */ PCVTGPROBELOC pProbeLocRO = &pProv->paProbeLocsRO[idxProbeLoc]; PVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe; if (pProbeDesc->idxProvider != idxProv) continue; uint32_t *pidProbe; if (!pProv->fUmod) pidProbe = (uint32_t *)&pProbeLocRO->idProbe; else pidProbe = &pProv->paR0ProbeLocs[idxProbeLoc].idProbe; if (*pidProbe != 0) continue; /* The function name may need to be stripped since we're using C++ compilers for most of the code. ASSUMES nobody are brave/stupid enough to use function pointer returns without typedef'ing properly them (e.g. signal). */ const char *pszPrbName = vboxDtVtgGetString(pProv->pHdr, pProbeDesc->offName); const char *pszFunc = pProbeLocRO->pszFunction; const char *psz = strchr(pProbeLocRO->pszFunction, '('); size_t cch; if (psz) { /* skip blanks preceeding the parameter parenthesis. */ while ( (uintptr_t)psz > (uintptr_t)pProbeLocRO->pszFunction && RT_C_IS_BLANK(psz[-1])) psz--; /* Find the start of the function name. */ pszFunc = psz - 1; while ((uintptr_t)pszFunc > (uintptr_t)pProbeLocRO->pszFunction) { char ch = pszFunc[-1]; if (!RT_C_IS_ALNUM(ch) && ch != '_' && ch != ':') break; pszFunc--; } cch = psz - pszFunc; } else cch = strlen(pszFunc); RTStrCopyEx(pszFnNmBuf, cbFnNmBuf, pszFunc, cch); /* Look up the probe, if we have one in the same function, mangle the function name a little to avoid having to deal with having multiple location entries with the same probe ID. (lazy bird) */ Assert(!*pidProbe); if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) != DTRACE_IDNONE) { RTStrPrintf(pszFnNmBuf+cch, cbFnNmBuf - cch, "-%u", pProbeLocRO->uLine); if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) != DTRACE_IDNONE) { unsigned iOrd = 2; while (iOrd < 128) { RTStrPrintf(pszFnNmBuf+cch, cbFnNmBuf - cch, "-%u-%u", pProbeLocRO->uLine, iOrd); if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) == DTRACE_IDNONE) break; iOrd++; } if (iOrd >= 128) { LogRel(("VBoxDrv: More than 128 duplicate probe location instances %s at line %u in function %s [%s], probe %s\n", pProbeLocRO->uLine, pProbeLocRO->pszFunction, pszFnNmBuf, pszPrbName)); continue; } } } /* Create the probe. */ AssertCompile(sizeof(*pidProbe) == sizeof(dtrace_id_t)); *pidProbe = dtrace_probe_create(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName, 1 /*aframes*/, (void *)(uintptr_t)idxProbeLoc); pProv->TracerData.DTrace.cProvidedProbes++; } RTMemFree(pszFnNmBuf); LOG_DTRACE(("%s: returns\n", __FUNCTION__)); } /** * @callback_method_impl{dtrace_pops_t,dtps_enable} */ static int vboxDtPOps_Enable(void *pvProv, dtrace_id_t idProbe, void *pvProbe) { PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv; LOG_DTRACE(("%s: %p / %p - %#x / %p\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe)); AssertPtrReturn(pProv->TracerData.DTrace.idProvider, EINVAL); if (!pProv->TracerData.DTrace.fZombie) { uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe; PVTGPROBELOC32 pProbeLocEn = (PVTGPROBELOC32)( (uintptr_t)pProv->pvProbeLocsEn + idxProbeLoc * pProv->cbProbeLocsEn); PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc]; PCVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe; uint32_t const idxProbe = pProbeDesc->idxEnabled; if (!pProv->fUmod) { if (!pProbeLocEn->fEnabled) { pProbeLocEn->fEnabled = 1; ASMAtomicIncU32(&pProv->pacProbeEnabled[idxProbe]); } } else { /* Update kernel mode structure */ if (!pProv->paR0ProbeLocs[idxProbeLoc].fEnabled) { pProv->paR0ProbeLocs[idxProbeLoc].fEnabled = 1; ASMAtomicIncU32(&pProv->paR0Probes[idxProbe].cEnabled); } /* Update user mode structure. */ pProbeLocEn->fEnabled = 1; pProv->pacProbeEnabled[idxProbe] = pProv->paR0Probes[idxProbe].cEnabled; } } return 0; } /** * @callback_method_impl{dtrace_pops_t,dtps_disable} */ static void vboxDtPOps_Disable(void *pvProv, dtrace_id_t idProbe, void *pvProbe) { PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv; AssertPtrReturnVoid(pProv); LOG_DTRACE(("%s: %p / %p - %#x / %p\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe)); AssertPtrReturnVoid(pProv->TracerData.DTrace.idProvider); if (!pProv->TracerData.DTrace.fZombie) { uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe; PVTGPROBELOC32 pProbeLocEn = (PVTGPROBELOC32)( (uintptr_t)pProv->pvProbeLocsEn + idxProbeLoc * pProv->cbProbeLocsEn); PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc]; PCVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe; uint32_t const idxProbe = pProbeDesc->idxEnabled; if (!pProv->fUmod) { if (pProbeLocEn->fEnabled) { pProbeLocEn->fEnabled = 0; ASMAtomicDecU32(&pProv->pacProbeEnabled[idxProbe]); } } else { /* Update kernel mode structure */ if (pProv->paR0ProbeLocs[idxProbeLoc].fEnabled) { pProv->paR0ProbeLocs[idxProbeLoc].fEnabled = 0; ASMAtomicDecU32(&pProv->paR0Probes[idxProbe].cEnabled); } /* Update user mode structure. */ pProbeLocEn->fEnabled = 0; pProv->pacProbeEnabled[idxProbe] = pProv->paR0Probes[idxProbe].cEnabled; } } } /** * @callback_method_impl{dtrace_pops_t,dtps_getargdesc} */ static void vboxDtPOps_GetArgDesc(void *pvProv, dtrace_id_t idProbe, void *pvProbe, dtrace_argdesc_t *pArgDesc) { PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv; unsigned uArg = pArgDesc->dtargd_ndx; pArgDesc->dtargd_ndx = DTRACE_ARGNONE; AssertPtrReturnVoid(pProv); LOG_DTRACE(("%s: %p / %p - %#x / %p uArg=%d\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe, uArg)); AssertPtrReturnVoid(pProv->TracerData.DTrace.idProvider); if (!pProv->TracerData.DTrace.fZombie) { uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe; PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc]; PCVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe; PCVTGDESCARGLIST pArgList = (PCVTGDESCARGLIST)( (uintptr_t)pProv->pHdr + pProv->pHdr->offArgLists + pProbeDesc->offArgList); AssertReturnVoid(pProbeDesc->offArgList < pProv->pHdr->cbArgLists); if (uArg < pArgList->cArgs) { const char *pszType = vboxDtVtgGetString(pProv->pHdr, pArgList->aArgs[uArg].offType); size_t cchType = strlen(pszType); if (cchType < sizeof(pArgDesc->dtargd_native)) { memcpy(pArgDesc->dtargd_native, pszType, cchType + 1); /** @todo mapping? */ pArgDesc->dtargd_ndx = uArg; LOG_DTRACE(("%s: returns dtargd_native = %s\n", __FUNCTION__, pArgDesc->dtargd_native)); return; } } } } /** * @callback_method_impl{dtrace_pops_t,dtps_getargval} * * * We just cook our own stuff here, using a stack marker for finding the * required information. That's more reliable than subjecting oneself to the * solaris bugs and 32-bit apple peculiarities. * * * @remarks Solaris Bug * * dtrace_getarg on AMD64 has a different opinion about how to use the cFrames * argument than dtrace_caller() and/or dtrace_getpcstack(), at least when the * probe is fired by dtrace_probe() the way we do. * * Setting aframes to 1 when calling dtrace_probe_create gives me the right * arguments, but the wrong 'caller'. Since I cannot do anything about * 'caller', the only solution is this hack. * * Not sure why the Solaris guys hasn't seen this issue before, but maybe there * isn't anyone using the default argument getter path for ring-0 dtrace_probe() * calls, SDT surely isn't. * * @todo File a solaris bug on dtrace_probe() + dtrace_getarg(). * * * @remarks 32-bit XNU (Apple) * * The dtrace_probe arguments are 64-bit unsigned integers instead of uintptr_t, * so we need to make an extra call. * */ static uint64_t vboxDtPOps_GetArgVal(void *pvProv, dtrace_id_t idProbe, void *pvProbe, int iArg, int cFrames) { PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv; AssertPtrReturn(pProv, UINT64_MAX); LOG_DTRACE(("%s: %p / %p - %#x / %p iArg=%d cFrames=%u\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe, iArg, cFrames)); AssertReturn(iArg >= 5, UINT64_MAX); if (pProv->TracerData.DTrace.fZombie) return UINT64_MAX; uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe; PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc]; PCVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe; PCVTGDESCARGLIST pArgList = (PCVTGDESCARGLIST)( (uintptr_t)pProv->pHdr + pProv->pHdr->offArgLists + pProbeDesc->offArgList); AssertReturn(pProbeDesc->offArgList < pProv->pHdr->cbArgLists, UINT64_MAX); PVBDTSTACKDATA pData = vboxDtGetStackData(); /* * Get the stack data. This is a wee bit complicated on 32-bit systems * since we want to support 64-bit integer arguments. */ uint64_t u64Ret; if (iArg >= 20) u64Ret = UINT64_MAX; else if (pData->enmCaller == kVBoxDtCaller_ProbeFireKernel) { #if ARCH_BITS == 64 u64Ret = pData->u.ProbeFireKernel.pauStackArgs[iArg - 5]; #else if ( !pArgList->fHaveLargeArgs || iArg >= pArgList->cArgs) u64Ret = pData->u.ProbeFireKernel.pauStackArgs[iArg - 5]; else { /* Similar to what we did for mac in when calling dtrace_probe(). */ uint32_t offArg = 0; for (int i = 5; i < iArg; i++) if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iArg].fType)) offArg++; u64Ret = pData->u.ProbeFireKernel.pauStackArgs[iArg - 5 + offArg]; if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iArg].fType)) u64Ret |= (uint64_t)pData->u.ProbeFireKernel.pauStackArgs[iArg - 5 + offArg + 1] << 32; } #endif } else if (pData->enmCaller == kVBoxDtCaller_ProbeFireUser) { int offArg = pData->u.ProbeFireUser.offArg; PCSUPDRVTRACERUSRCTX pCtx = pData->u.ProbeFireUser.pCtx; AssertPtrReturn(pCtx, UINT64_MAX); if (pCtx->cBits == 32) { if ( !pArgList->fHaveLargeArgs || iArg >= pArgList->cArgs) { if (iArg + offArg < (int)RT_ELEMENTS(pCtx->u.X86.aArgs)) u64Ret = pCtx->u.X86.aArgs[iArg + offArg]; else u64Ret = UINT64_MAX; } else { int i; for (i = 5; i < iArg; i++) if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iArg].fType)) offArg++; if (offArg + iArg < (int)RT_ELEMENTS(pCtx->u.X86.aArgs)) { u64Ret = pCtx->u.X86.aArgs[iArg + offArg]; if ( VTG_TYPE_IS_LARGE(pArgList->aArgs[iArg].fType) && offArg + iArg + 1 < (int)RT_ELEMENTS(pCtx->u.X86.aArgs)) u64Ret |= (uint64_t)pCtx->u.X86.aArgs[iArg + offArg + 1] << 32; } else u64Ret = UINT64_MAX; } } else { if (iArg + offArg < (int)RT_ELEMENTS(pCtx->u.Amd64.aArgs)) u64Ret = pCtx->u.Amd64.aArgs[iArg + offArg]; else u64Ret = UINT64_MAX; } } else AssertFailedReturn(UINT64_MAX); LOG_DTRACE(("%s: returns %#llx\n", __FUNCTION__, u64Ret)); return u64Ret; } /** * @callback_method_impl{dtrace_pops_t,dtps_destroy} */ static void vboxDtPOps_Destroy(void *pvProv, dtrace_id_t idProbe, void *pvProbe) { PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv; AssertPtrReturnVoid(pProv); LOG_DTRACE(("%s: %p / %p - %#x / %p\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe)); AssertReturnVoid(pProv->TracerData.DTrace.cProvidedProbes > 0); AssertPtrReturnVoid(pProv->TracerData.DTrace.idProvider); if (!pProv->TracerData.DTrace.fZombie) { uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe; PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc]; uint32_t *pidProbe; if (!pProv->fUmod) { pidProbe = (uint32_t *)&pProbeLocRO->idProbe; Assert(!pProbeLocRO->fEnabled); Assert(*pidProbe == idProbe); } else { pidProbe = &pProv->paR0ProbeLocs[idxProbeLoc].idProbe; Assert(!pProv->paR0ProbeLocs[idxProbeLoc].fEnabled); Assert(*pidProbe == idProbe); NOREF(idProbe); } *pidProbe = 0; } pProv->TracerData.DTrace.cProvidedProbes--; } /** * DTrace provider method table. */ static const dtrace_pops_t g_vboxDtVtgProvOps = { /* .dtps_provide = */ vboxDtPOps_Provide, /* .dtps_provide_module = */ NULL, /* .dtps_enable = */ (FNPOPS_ENABLE *)vboxDtPOps_Enable, /* .dtps_disable = */ vboxDtPOps_Disable, /* .dtps_suspend = */ NULL, /* .dtps_resume = */ NULL, /* .dtps_getargdesc = */ vboxDtPOps_GetArgDesc, /* .dtps_getargval = */ vboxDtPOps_GetArgVal, /* .dtps_usermode = */ NULL, /* .dtps_destroy = */ vboxDtPOps_Destroy }; /* * * Support Driver Tracer Interface. * Support Driver Tracer Interface. * Support Driver Tracer Interface. * */ /** * interface_method_impl{SUPDRVTRACERREG,pfnProbeFireKernel} */ static DECLCALLBACK(void) vboxDtTOps_ProbeFireKernel(struct VTGPROBELOC *pVtgProbeLoc, uintptr_t uArg0, uintptr_t uArg1, uintptr_t uArg2, uintptr_t uArg3, uintptr_t uArg4) { AssertPtrReturnVoid(pVtgProbeLoc); LOG_DTRACE(("%s: %p / %p\n", __FUNCTION__, pVtgProbeLoc, pVtgProbeLoc->idProbe)); AssertPtrReturnVoid(pVtgProbeLoc->pProbe); AssertPtrReturnVoid(pVtgProbeLoc->pszFunction); VBDT_SETUP_STACK_DATA(kVBoxDtCaller_ProbeFireKernel); pStackData->u.ProbeFireKernel.pauStackArgs = &uArg4 + 1; #if defined(RT_OS_DARWIN) && ARCH_BITS == 32 /* * Convert arguments from uintptr_t to uint64_t. */ PVTGDESCPROBE pProbe = (PVTGDESCPROBE)((PVTGPROBELOC)pVtgProbeLoc)->pProbe; AssertPtrReturnVoid(pProbe); PVTGOBJHDR pVtgHdr = (PVTGOBJHDR)((uintptr_t)pProbe + pProbe->offObjHdr); AssertPtrReturnVoid(pVtgHdr); PVTGDESCARGLIST pArgList = (PVTGDESCARGLIST)((uintptr_t)pVtgHdr + pVtgHdr->offArgLists + pProbe->offArgList); AssertPtrReturnVoid(pArgList); if (!pArgList->fHaveLargeArgs) dtrace_probe(pVtgProbeLoc->idProbe, uArg0, uArg1, uArg2, uArg3, uArg4); else { uintptr_t *auSrcArgs = &uArg0; uint32_t iSrcArg = 0; uint32_t iDstArg = 0; uint64_t au64DstArgs[5]; while ( iDstArg < RT_ELEMENTS(au64DstArgs) && iSrcArg < pArgList->cArgs) { au64DstArgs[iDstArg] = auSrcArgs[iSrcArg]; if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iDstArg].fType)) au64DstArgs[iDstArg] |= (uint64_t)auSrcArgs[++iSrcArg] << 32; iSrcArg++; iDstArg++; } while (iDstArg < RT_ELEMENTS(au64DstArgs)) au64DstArgs[iDstArg++] = auSrcArgs[iSrcArg++]; pStackData->u.ProbeFireKernel.pauStackArgs = &auSrcArgs[iSrcArg]; dtrace_probe(pVtgProbeLoc->idProbe, au64DstArgs[0], au64DstArgs[1], au64DstArgs[2], au64DstArgs[3], au64DstArgs[4]); } #else dtrace_probe(pVtgProbeLoc->idProbe, uArg0, uArg1, uArg2, uArg3, uArg4); #endif VBDT_CLEAR_STACK_DATA(); LOG_DTRACE(("%s: returns\n", __FUNCTION__)); } /** * interface_method_impl{SUPDRVTRACERREG,pfnProbeFireUser} */ static DECLCALLBACK(void) vboxDtTOps_ProbeFireUser(PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, PCSUPDRVTRACERUSRCTX pCtx, PCVTGOBJHDR pVtgHdr, PCVTGPROBELOC pProbeLocRO) { LOG_DTRACE(("%s: %p / %p\n", __FUNCTION__, pCtx, pCtx->idProbe)); AssertPtrReturnVoid(pProbeLocRO); AssertPtrReturnVoid(pVtgHdr); VBDT_SETUP_STACK_DATA(kVBoxDtCaller_ProbeFireUser); if (pCtx->cBits == 32) { pStackData->u.ProbeFireUser.pCtx = pCtx; pStackData->u.ProbeFireUser.offArg = 0; #if ARCH_BITS == 64 || defined(RT_OS_DARWIN) /* * Combine two 32-bit arguments into one 64-bit argument where needed. */ PVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe; AssertPtrReturnVoid(pProbeDesc); PVTGDESCARGLIST pArgList = (PVTGDESCARGLIST)((uintptr_t)pVtgHdr + pVtgHdr->offArgLists + pProbeDesc->offArgList); AssertPtrReturnVoid(pArgList); if (!pArgList->fHaveLargeArgs) dtrace_probe(pCtx->idProbe, pCtx->u.X86.aArgs[0], pCtx->u.X86.aArgs[1], pCtx->u.X86.aArgs[2], pCtx->u.X86.aArgs[3], pCtx->u.X86.aArgs[4]); else { uint32_t const *auSrcArgs = &pCtx->u.X86.aArgs[0]; uint32_t iSrcArg = 0; uint32_t iDstArg = 0; uint64_t au64DstArgs[5]; while ( iDstArg < RT_ELEMENTS(au64DstArgs) && iSrcArg < pArgList->cArgs) { au64DstArgs[iDstArg] = auSrcArgs[iSrcArg]; if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iDstArg].fType)) au64DstArgs[iDstArg] |= (uint64_t)auSrcArgs[++iSrcArg] << 32; iSrcArg++; iDstArg++; } while (iDstArg < RT_ELEMENTS(au64DstArgs)) au64DstArgs[iDstArg++] = auSrcArgs[iSrcArg++]; pStackData->u.ProbeFireUser.offArg = iSrcArg - RT_ELEMENTS(au64DstArgs); dtrace_probe(pCtx->idProbe, au64DstArgs[0], au64DstArgs[1], au64DstArgs[2], au64DstArgs[3], au64DstArgs[4]); } #else dtrace_probe(pCtx->idProbe, pCtx->u.X86.aArgs[0], pCtx->u.X86.aArgs[1], pCtx->u.X86.aArgs[2], pCtx->u.X86.aArgs[3], pCtx->u.X86.aArgs[4]); #endif } else if (pCtx->cBits == 64) { pStackData->u.ProbeFireUser.pCtx = pCtx; pStackData->u.ProbeFireUser.offArg = 0; dtrace_probe(pCtx->idProbe, pCtx->u.Amd64.aArgs[0], pCtx->u.Amd64.aArgs[1], pCtx->u.Amd64.aArgs[2], pCtx->u.Amd64.aArgs[3], pCtx->u.Amd64.aArgs[4]); } else AssertFailed(); VBDT_CLEAR_STACK_DATA(); LOG_DTRACE(("%s: returns\n", __FUNCTION__)); } /** * interface_method_impl{SUPDRVTRACERREG,pfnTracerOpen} */ static DECLCALLBACK(int) vboxDtTOps_TracerOpen(PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg, uintptr_t *puSessionData) { NOREF(pThis); NOREF(pSession); NOREF(uCookie); NOREF(uArg); *puSessionData = 0; return VERR_NOT_SUPPORTED; } /** * interface_method_impl{SUPDRVTRACERREG,pfnTracerClose} */ static DECLCALLBACK(int) vboxDtTOps_TracerIoCtl(PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uintptr_t uSessionData, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal) { NOREF(pThis); NOREF(pSession); NOREF(uSessionData); NOREF(uCmd); NOREF(uArg); NOREF(piRetVal); return VERR_NOT_SUPPORTED; } /** * interface_method_impl{SUPDRVTRACERREG,pfnTracerClose} */ static DECLCALLBACK(void) vboxDtTOps_TracerClose(PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uintptr_t uSessionData) { NOREF(pThis); NOREF(pSession); NOREF(uSessionData); return; } /** * interface_method_impl{SUPDRVTRACERREG,pfnProviderRegister} */ static DECLCALLBACK(int) vboxDtTOps_ProviderRegister(PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore) { LOG_DTRACE(("%s: %p %s/%s\n", __FUNCTION__, pThis, pCore->pszModName, pCore->pszName)); AssertReturn(pCore->TracerData.DTrace.idProvider == 0, VERR_INTERNAL_ERROR_3); PVTGDESCPROVIDER pDesc = pCore->pDesc; dtrace_pattr_t DtAttrs; vboxDtVtgConvAttr(&DtAttrs.dtpa_provider, &pDesc->AttrSelf); vboxDtVtgConvAttr(&DtAttrs.dtpa_mod, &pDesc->AttrModules); vboxDtVtgConvAttr(&DtAttrs.dtpa_func, &pDesc->AttrFunctions); vboxDtVtgConvAttr(&DtAttrs.dtpa_name, &pDesc->AttrNames); vboxDtVtgConvAttr(&DtAttrs.dtpa_args, &pDesc->AttrArguments); /* Note! DTrace may call us back before dtrace_register returns, so we have to point it to pCore->TracerData.DTrace.idProvider. */ AssertCompile(sizeof(dtrace_provider_id_t) == sizeof(pCore->TracerData.DTrace.idProvider)); int rc = dtrace_register(pCore->pszName, &DtAttrs, DTRACE_PRIV_KERNEL, NULL /* cred */, &g_vboxDtVtgProvOps, pCore, &pCore->TracerData.DTrace.idProvider); if (!rc) { LOG_DTRACE(("%s: idProvider=%p\n", __FUNCTION__, pCore->TracerData.DTrace.idProvider)); AssertPtr(pCore->TracerData.DTrace.idProvider); rc = VINF_SUCCESS; } else { pCore->TracerData.DTrace.idProvider = 0; rc = RTErrConvertFromErrno(FIX_UEK_RC(rc)); } LOG_DTRACE(("%s: returns %Rrc\n", __FUNCTION__, rc)); return rc; } /** * interface_method_impl{SUPDRVTRACERREG,pfnProviderDeregister} */ static DECLCALLBACK(int) vboxDtTOps_ProviderDeregister(PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore) { uintptr_t idProvider = pCore->TracerData.DTrace.idProvider; LOG_DTRACE(("%s: %p / %p\n", __FUNCTION__, pThis, idProvider)); AssertPtrReturn(idProvider, VERR_INTERNAL_ERROR_3); dtrace_invalidate(idProvider); int rc = dtrace_unregister(idProvider); if (!rc) { pCore->TracerData.DTrace.idProvider = 0; rc = VINF_SUCCESS; } else { AssertMsg(FIX_UEK_RC(rc) == EBUSY, ("%d\n", rc)); pCore->TracerData.DTrace.fZombie = true; rc = VERR_TRY_AGAIN; } LOG_DTRACE(("%s: returns %Rrc\n", __FUNCTION__, rc)); return rc; } /** * interface_method_impl{SUPDRVTRACERREG,pfnProviderDeregisterZombie} */ static DECLCALLBACK(int) vboxDtTOps_ProviderDeregisterZombie(PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore) { uintptr_t idProvider = pCore->TracerData.DTrace.idProvider; LOG_DTRACE(("%s: %p / %p\n", __FUNCTION__, pThis, idProvider)); AssertPtrReturn(idProvider, VERR_INTERNAL_ERROR_3); Assert(pCore->TracerData.DTrace.fZombie); int rc = dtrace_unregister(idProvider); if (!rc) { pCore->TracerData.DTrace.idProvider = 0; rc = VINF_SUCCESS; } else { AssertMsg(FIX_UEK_RC(rc) == EBUSY, ("%d\n", rc)); rc = VERR_TRY_AGAIN; } LOG_DTRACE(("%s: returns %Rrc\n", __FUNCTION__, rc)); return rc; } /** * The tracer registration record of the VBox DTrace implementation */ static SUPDRVTRACERREG g_VBoxDTraceReg = { SUPDRVTRACERREG_MAGIC, SUPDRVTRACERREG_VERSION, vboxDtTOps_ProbeFireKernel, vboxDtTOps_ProbeFireUser, vboxDtTOps_TracerOpen, vboxDtTOps_TracerIoCtl, vboxDtTOps_TracerClose, vboxDtTOps_ProviderRegister, vboxDtTOps_ProviderDeregister, vboxDtTOps_ProviderDeregisterZombie, SUPDRVTRACERREG_MAGIC }; /** * Module initialization code. */ const SUPDRVTRACERREG * VBOXCALL supdrvDTraceInit(void) { #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) /* * Resolve the kernel symbols we need. */ # ifndef RT_OS_LINUX RTDBGKRNLINFO hKrnlInfo; int rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0); if (RT_FAILURE(rc)) { SUPR0Printf("supdrvDTraceInit: RTR0DbgKrnlInfoOpen failed with rc=%d.\n", rc); return NULL; } # endif static const struct { const char *pszName; PFNRT *ppfn; } s_aDTraceFunctions[] = { { "dtrace_probe", (PFNRT*)&dtrace_probe }, { "dtrace_probe_create", (PFNRT*)&dtrace_probe_create }, { "dtrace_probe_lookup", (PFNRT*)&dtrace_probe_lookup }, { "dtrace_register", (PFNRT*)&dtrace_register }, { "dtrace_invalidate", (PFNRT*)&dtrace_invalidate }, { "dtrace_unregister", (PFNRT*)&dtrace_unregister }, }; unsigned i; for (i = 0; i < RT_ELEMENTS(s_aDTraceFunctions); i++) { # ifndef RT_OS_LINUX rc = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_aDTraceFunctions[i].pszName, (void **)s_aDTraceFunctions[i].ppfn); if (RT_FAILURE(rc)) { SUPR0Printf("supdrvDTraceInit: Failed to resolved '%s' (rc=%Rrc, i=%u).\n", s_aDTraceFunctions[i].pszName, rc, i); break; } # else unsigned long ulAddr = kallsyms_lookup_name(s_aDTraceFunctions[i].pszName); if (!ulAddr) { SUPR0Printf("supdrvDTraceInit: Failed to resolved '%s' (i=%u).\n", s_aDTraceFunctions[i].pszName, i); return NULL; } *s_aDTraceFunctions[i].ppfn = (PFNRT)ulAddr; # endif } # ifndef RT_OS_LINUX RTR0DbgKrnlInfoRelease(hKrnlInfo); if (RT_FAILURE(rc)) return NULL; # else /** @todo grab a reference to the dtrace module... */ # endif #endif return &g_VBoxDTraceReg; } #ifndef VBOX_WITH_NATIVE_DTRACE # error "VBOX_WITH_NATIVE_DTRACE is not defined as it should" #endif
40,872
C
.c
985
34.014213
155
0.599115
TusharPardhe/Unknown-OS
24
0
0
GPL-3.0
9/7/2024, 10:30:28 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
4,191,901
debugScreen.c
windsurfer1122_Vita-Account-Manager/src/debugScreen.c
#ifndef DEBUG_SCREEN_C #define DEBUG_SCREEN_C /* * debugScreen.c of Vita SDK * * - psvDebugScreenInit() * Initializes debug screen for output. * * - psvDebugScreenPuts() * Similar to the C library function puts() writes a string to the debug * screen up to but not including the NUL character. * Supports the most important CSI sequences of ECMA-48 / ISO/IEC 6429:1992. * Graphic Rendition Combination Mode (GRCM) supported is Cumulative. * Modifications: * - CSI SGR codes 30-37/38/39 & 40-47/48/49 set standard/fitting/default intensity, so instead of "\e[1;31m" use "\e31;1m" * - ANSI color #8 is made darker (40<>80), so that "dark" white is still lighter than "bright" dark * - support 16 save storages for CSI s and CSI u, e.g "\e[8s" and "\e[8u" * [1] https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences * [2] https://jonasjacek.github.io/colors/ * [3] https://www.ecma-international.org/publications/standards/Ecma-048.htm * [4] https://invisible-island.net/xterm/ctlseqs/ctlseqs.html * [5] http://man7.org/linux/man-pages/man4/console_codes.4.html * * (CSI = "\e[") * CSI [n] s = Save Cursor Position to slot #n (0-15). Default 0. * CSI [n] u = Restore Cursor Position from slot #n (0-15). Default 0. * CSI n A = Cursor Up <n> times. * CSI n B = Cursor Down <n> times. * CSI n C = Cursor Forward <n> times. * CSI n D = Cursor Back <n> times. * CSI n E = Cursor Next Line <n> times and to Beginning of that Line. * CSI n F = Cursor Previous Line <n> times and to Beginning of that Line. * CSI n G = Cursor to Column <n>. The value is 1-based and defaults to 1 (first column) if omitted. * CSI n ; m H = Cursor to Row <n> and Column <m>. The values are 1-based and default to 1 (top left corner) if omitted. * CSI n ; m f = Cursor to Row <n> and Column <m>. The values are 1-based and default to 1 (top left corner) if omitted. * CSI [n] J = Clears part of the screen. Cursor position does not change. * 0 (default) from cursor to end of screen. * 1 from cursor to beginning of the screen. * 2 entire screen * CSI [n] K = Clears part of the line. Cursor position does not change. * 0 (default) from cursor to end of line. * 1 from cursor to beginning of line. * 2 clear entire line. * CSI [n] m = Sets the appearance of the following characters. * 0 Reset all (colors and inversion) (default) * 1 Increased intensity ("bright" color) * 2 Decreased intensity ("faint"/"dark" color) * 7 Enable inversion * 22 Standard intensity ("normal" color) * 27 Disable inversion * 30–37 Set ANSI foreground color with standard intensity * 38 Set foreground color. Arguments are 5;<n> or 2;<r>;<g>;<b> * 39 Default foreground color * 40–47 Set standard ANSI background color with standard intensity * 48 Set background color. Arguments are 5;<n> or 2;<r>;<g>;<b> * 49 Default background color * 90–97 Set ANSI foreground color with increased intensity * 100–107 Set ANSI background color with increased intensity * * - psvDebugScreenPrintf() * Similar to the C library function printf() formats a string and ouputs * it via psvDebugScreenPuts() to the debug screen. * * - psvDebugScreenGetColorStateCopy(ColorState *copy) * Get copy of current color state. * * - psvDebugScreenGetCoordsXY(int *x, int *y) * Get copy of current pixel coordinates. * Allows for multiple and custom position stores. * Allows correct positioning when using different font sizes. * * - psvDebugScreenSetCoordsXY(int *x, int *y) * Set pixel coordinates. * Allows for multiple and custom position stores. * Allows correct positioning when using different font sizes. * * - PsvDebugScreenFont *psvDebugScreenGetFont() * Get current font. * * - PsvDebugScreenFont *psvDebugScreenSetFont(PsvDebugScreenFont *font) { * Set font. Returns current font. * * - PsvDebugScreenFont *psvDebugScreenScaleFont2x(PsvDebugScreenFont *source_font) { * Scales a font by 2 (e.g. 8x8 to 16x16) and returns new scaled font. * * Also see the following samples: * - debugscreen * - debug_print * */ #include <stdlib.h> // for malloc(), free() #include <stdio.h> // for vsnprintf() #include <string.h> // for memset(), memcpy() #include <stdarg.h> // for va_list, va_start(), va_end() #include <inttypes.h> #include "debugScreen.h" #include "debugScreenFont.c" #define SCREEN_FB_WIDTH (960) // frame buffer aligned width for accessing vram #define SCREEN_FB_SIZE (2 * 1024 * 1024) // Must be 256KB aligned #ifndef SCREEN_TAB_SIZE // this allows easy overriding #define SCREEN_TAB_SIZE (8) #endif #define SCREEN_TAB_W ((F)->size_w * (SCREEN_TAB_SIZE)) #define F psvDebugScreenFontCurrent #define FROM_FULL_RGB(r,g,b ) ( ((b)<<16) | ((g)<<8) | (r) ) #define CONVERT_RGB_BGR(rgb) rgb = ( (((rgb)&0x0000FF)<<16) | ((rgb)&0x00FF00) | (((rgb)&0xFF0000)>>16) ) #define CLEARSCRNBLOCK(H,toH,W,toW,color) for (int h = (H); h < (toH); h++) for (int w = (W); w < (toW); w++) ((uint32_t*)base)[h*(SCREEN_FB_WIDTH) + w] = (color); #define CLEARSCRNLINES(H,toH,color) { uint32_t *pixel = (uint32_t *)base + ((H) * (SCREEN_FB_WIDTH)); int i = (((toH) - (H)) * (SCREEN_FB_WIDTH)); for (; i > 0; i--) *pixel++ = (color); } #define SAVE_STORAGES 16 static int mutex, coordX, coordY; static int savedX[SAVE_STORAGES] = { 0 }, savedY[SAVE_STORAGES] = { 0 }; static ColorState colors = { 0, 0, // truecolor flags 0, 0, // truecolors 0, 0, 0, 0, 0, // ANSI/VTERM/GREYSCALE colors 7, 22, 0, 22, 0, // default colors (ANSI/VTERM/GREYSCALE) }; static PsvDebugScreenFont *psvDebugScreenFontCurrent = &psvDebugScreenFont; #ifdef __vita__ #include <psp2/display.h> #include <psp2/kernel/sysmem.h> #include <psp2/kernel/threadmgr.h> static void* base; // pointer to frame buffer #else #define NO_psvDebugScreenInit #ifndef psvDebugScreenInitReplacement #define psvDebugScreenInitReplacement(...) #endif #define sceKernelLockMutex(m,v,x) m=v #define sceKernelUnlockMutex(m,v) m=v static char base[(SCREEN_FB_WIDTH) * (SCREEN_HEIGHT) * 4]; #endif static uint32_t DARK_COLORS_BGR[8] = { 0x000000, 0x000040, 0x004000, 0x004040, 0x400000, 0x400040, 0x404000, 0x808080, // 0-7 }; // ANSI/VTERM/GREYSCALE palette: https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit // modifications: // - #8 is made darker (40<>80), so that "dark" white is still lighter than "bright" dark static uint32_t ANSI_COLORS_BGR[256] = { 0x000000, 0x000080, 0x008000, 0x008080, 0x800000, 0x800080, 0x808000, 0xc0c0c0, // 0-7 0x404040, 0x0000ff, 0x00ff00, 0x00ffff, 0xff0000, 0xff00ff, 0xffff00, 0xffffff, // 8-15 0x000000, 0x5f0000, 0x870000, 0xaf0000, 0xd70000, 0xff0000, 0x005f00, 0x5f5f00, // 16-23 0x875f00, 0xaf5f00, 0xd75f00, 0xff5f00, 0x008700, 0x5f8700, 0x878700, 0xaf8700, // 24-31 0xd78700, 0xff8700, 0x00af00, 0x5faf00, 0x87af00, 0xafaf00, 0xd7af00, 0xffaf00, // 32-39 0x00d700, 0x5fd700, 0x87d700, 0xafd700, 0xd7d700, 0xffd700, 0x00ff00, 0x5fff00, // 40-47 0x87ff00, 0xafff00, 0xd7ff00, 0xffff00, 0x00005f, 0x5f005f, 0x87005f, 0xaf005f, // 48-55 0xd7005f, 0xff005f, 0x005f5f, 0x5f5f5f, 0x875f5f, 0xaf5f5f, 0xd75f5f, 0xff5f5f, // 56-63 0x00875f, 0x5f875f, 0x87875f, 0xaf875f, 0xd7875f, 0xff875f, 0x00af5f, 0x5faf5f, // 64-71 0x87af5f, 0xafaf5f, 0xd7af5f, 0xffaf5f, 0x00d75f, 0x5fd75f, 0x87d75f, 0xafd75f, // 72-79 0xd7d75f, 0xffd75f, 0x00ff5f, 0x5fff5f, 0x87ff5f, 0xafff5f, 0xd7ff5f, 0xffff5f, // 80-87 0x000087, 0x5f0087, 0x870087, 0xaf0087, 0xd70087, 0xff0087, 0x005f87, 0x5f5f87, // 88-95 0x875f87, 0xaf5f87, 0xd75f87, 0xff5f87, 0x008787, 0x5f8787, 0x878787, 0xaf8787, // 96-103 0xd78787, 0xff8787, 0x00af87, 0x5faf87, 0x87af87, 0xafaf87, 0xd7af87, 0xffaf87, // 104-111 0x00d787, 0x5fd787, 0x87d787, 0xafd787, 0xd7d787, 0xffd787, 0x00ff87, 0x5fff87, // 112-119 0x87ff87, 0xafff87, 0xd7ff87, 0xffff87, 0x0000af, 0x5f00af, 0x8700af, 0xaf00af, // 120-127 0xd700af, 0xff00af, 0x005faf, 0x5f5faf, 0x875faf, 0xaf5faf, 0xd75faf, 0xff5faf, // 128-135 0x0087af, 0x5f87af, 0x8787af, 0xaf87af, 0xd787af, 0xff87af, 0x00afaf, 0x5fafaf, // 136-143 0x87afaf, 0xafafaf, 0xd7afaf, 0xffafaf, 0x00d7af, 0x5fd7af, 0x87d7af, 0xafd7af, // 144-151 0xd7d7af, 0xffd7af, 0x00ffaf, 0x5fffaf, 0x87ffaf, 0xafffaf, 0xd7ffaf, 0xffffaf, // 152-159 0x0000d7, 0x5f00d7, 0x8700d7, 0xaf00d7, 0xd700d7, 0xff00d7, 0x005fd7, 0x5f5fd7, // 160-167 0x875fd7, 0xaf5fd7, 0xd75fd7, 0xff5fd7, 0x0087d7, 0x5f87d7, 0x8787d7, 0xaf87d7, // 168-175 0xd787d7, 0xff87d7, 0x00afd7, 0x5fafd7, 0x87afd7, 0xafafd7, 0xd7afd7, 0xffafd7, // 176-183 0x00d7d7, 0x5fd7d7, 0x87d7d7, 0xafd7d7, 0xd7d7d7, 0xffd7d7, 0x00ffd7, 0x5fffd7, // 184-191 0x87ffd7, 0xafffd7, 0xd7ffd7, 0xffffd7, 0x0000ff, 0x5f00ff, 0x8700ff, 0xaf00ff, // 192-199 0xd700ff, 0xff00ff, 0x005fff, 0x5f5fff, 0x875fff, 0xaf5fff, 0xd75fff, 0xff5fff, // 200-207 0x0087ff, 0x5f87ff, 0x8787ff, 0xaf87ff, 0xd787ff, 0xff87ff, 0x00afff, 0x5fafff, // 208-215 0x87afff, 0xafafff, 0xd7afff, 0xffafff, 0x00d7ff, 0x5fd7ff, 0x87d7ff, 0xafd7ff, // 216-223 0xd7d7ff, 0xffd7ff, 0x00ffff, 0x5fffff, 0x87ffff, 0xafffff, 0xd7ffff, 0xffffff, // 224-231 0x080808, 0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e, // 232-239 0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e, // 240-247 0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee, // 248-255 }; /* * Reset foreground color to default */ static void psvDebugScreenResetFgColor(void) { colors.fgTrueColorFlag = 0; colors.fgTrueColor = 0; colors.fgIndex = colors.fgIndexDefault; colors.fgIntensity = colors.fgIntensityDefault; } /* * Reset background color to default */ static void psvDebugScreenResetBgColor(void) { colors.bgTrueColorFlag = 0; colors.bgTrueColor = 0; colors.bgIndex = colors.bgIndexDefault; colors.bgIntensity = colors.bgIntensityDefault; } /* * Reset inversion state to default */ static void psvDebugScreenResetInversion(void) { colors.inversion = colors.inversionDefault; } /* * Determine colors according to current color state */ static void psvDebugScreenSetColors(void) { uint32_t *color_fg, *color_bg; // special case: inversion if (!colors.inversion) { color_fg = &colors.color_fg; color_bg = &colors.color_bg; } else { color_fg = &colors.color_bg; color_bg = &colors.color_fg; } // foregound color if ((colors.fgIndex<=7) && (colors.fgIntensity==1)) { // ANSI palette with increased intensity colors.fgIndex |= 0x8; } else if ((colors.fgIndex<=15) && (colors.fgIntensity!=1)) { // ANSI palette with standard/decreased intensity colors.fgIndex &= 0x7; } if (colors.fgTrueColorFlag) { *color_fg = colors.fgTrueColor; } else { if ((colors.fgIndex<=7) && (colors.fgIntensity==2)) { // "ANSI" palette with decreased intensity *color_fg = DARK_COLORS_BGR[colors.fgIndex]; } else { // ANSI/VTERM/GREYSCALE palette *color_fg = ANSI_COLORS_BGR[colors.fgIndex]; } } *color_fg |= 0xFF000000; // opaque // backgound color if ((colors.bgIndex<=7) && (colors.bgIntensity==1)) { // ANSI palette with increased intensity colors.bgIndex |= 0x8; } else if ((colors.bgIndex<=15) && (colors.bgIntensity!=1)) { // ANSI palette with standard/decreased intensity colors.bgIndex &= 0x7; } if (colors.bgTrueColorFlag) { *color_bg = colors.bgTrueColor; } else { if ((colors.bgIndex<=7) && (colors.bgIntensity==2)) { // "ANSI" palette with decreased intensity *color_bg = DARK_COLORS_BGR[colors.bgIndex]; } else { // ANSI/VTERM/GREYSCALE palette *color_bg = ANSI_COLORS_BGR[colors.bgIndex]; } } *color_bg |= 0xFF000000; // opaque } /* * Parse CSI sequences */ static size_t psvDebugScreenEscape(const unsigned char *str) { unsigned int i, argc, arg[32] = { 0 }; unsigned int c; uint32_t unit, mode; int *colorTrueColorFlag; uint32_t *colorTrueColor; unsigned char *colorIndex, *colorIntensity; for (i = 0, argc = 0; (argc < (sizeof(arg)/sizeof(*arg))) && (str[i] != '\0'); i++) { switch (str[i]) { // numeric char case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': arg[argc] = (arg[argc] * 10) + (str[i] - '0'); continue; // argument separator case ';': argc++; continue; // CSI commands // save/restore position case 's': if (arg[0]<SAVE_STORAGES) { savedX[arg[0]] = coordX; savedY[arg[0]] = coordY; } return i; case 'u': if (arg[0]<SAVE_STORAGES) { coordX = savedX[arg[0]]; coordY = savedY[arg[0]]; } return i; // cursor movement case 'A': coordY -= arg[0] * (F)->size_h; return i; case 'B': coordY += arg[0] * (F)->size_h; return i; case 'C': coordX += arg[0] * (F)->size_w; return i; case 'D': coordX -= arg[0] * (F)->size_w; return i; // cursor movement to beginning of next/previous line(s) case 'E': coordY += arg[0] * (F)->size_h; coordX = 0; return i; case 'F': coordY -= arg[0] * (F)->size_h; coordX = 0; return i; // cursor positioning case 'G': coordX = (arg[0]-1) * (F)->size_w; return i; case 'H': case 'f': coordY = (arg[0]-1) * (F)->size_h; coordX = (arg[1]-1) * (F)->size_w; return i; // clear part of "J"=screen or "K"=Line, so J code re-uses part of K case 'J': case 'K': if (arg[0]==0) { // from cursor to end of line/screen CLEARSCRNBLOCK(coordY, coordY + (F)->size_h, coordX, (SCREEN_WIDTH), colors.color_bg); // line if (str[i]=='J') CLEARSCRNLINES(coordY + (F)->size_h, (SCREEN_HEIGHT), colors.color_bg); // screen } else if (arg[0]==1) { // from beginning of line/screen to cursor CLEARSCRNBLOCK(coordY, coordY + (F)->size_h, 0, coordX, colors.color_bg); // line if (str[i]=='J') CLEARSCRNLINES(0, coordY, colors.color_bg); // screen } else if (arg[0]==2) { // whole line/screen if (str[i]=='K') CLEARSCRNLINES(coordY, coordY + (F)->size_h, colors.color_bg) // line else if (str[i]=='J') CLEARSCRNLINES(0, (SCREEN_HEIGHT), colors.color_bg); // screen } return i; // color case 'm': for (c = 0; c <= argc; c++) { switch (arg[c]) { // reset all case 0: psvDebugScreenResetFgColor(); psvDebugScreenResetBgColor(); psvDebugScreenResetInversion(); continue; break; // intensity case 1: // increased = "bright" color case 2: // decreased = "dark" color case 22: // standard = "normal" color colors.fgIntensity = arg[c]; continue; break; // inversion case 7: // enable colors.inversion = 1; continue; break; case 27: // disable colors.inversion = 0; continue; break; // set from color map or truecolor case 38: // foreground color case 48: // background color mode = arg[c] / 10; colorTrueColorFlag = mode&1 ? &colors.fgTrueColorFlag : &colors.bgTrueColorFlag; if (arg[c+1]==5) { // 8-bit: [0-15][16-231][232-255] color map *colorTrueColorFlag = 0; colorIndex = mode&1 ? &colors.fgIndex : &colors.bgIndex; *colorIndex = arg[c+2] & 0xFF; colorIntensity = mode&1 ? &colors.fgIntensity : &colors.bgIntensity; *colorIntensity = ((*colorIndex>=8) && (*colorIndex<=15)) ? 1 : 22; c+=2; // extra arguments } else if (arg[c+1]==2) { // 24-bit color space *colorTrueColorFlag = 1; colorTrueColor = mode&1 ? &colors.fgTrueColor : &colors.bgTrueColor; *colorTrueColor = FROM_FULL_RGB(arg[c+2], arg[c+3], arg[c+4]); c+=4; // extra arguments } continue; break; // default color case 39: // foreground color psvDebugScreenResetFgColor(); continue; break; case 49: // background color psvDebugScreenResetBgColor(); continue; break; // custom color reset default: // ANSI colors (30-37, 40-47, 90-97, 100-107) mode = arg[c] / 10; if ((mode!=3) && (mode!=4) && (mode!=9) && (mode!=10)) continue; // skip unsupported modes unit = arg[c] % 10; if (unit>7) continue; // skip unsupported modes colorTrueColorFlag = mode&1 ? &colors.fgTrueColorFlag : &colors.bgTrueColorFlag; *colorTrueColorFlag = 0; colorIndex = mode&1 ? &colors.fgIndex : &colors.bgIndex; *colorIndex = unit; colorIntensity = mode&1 ? &colors.fgIntensity : &colors.bgIntensity; *colorIntensity = mode&8 ? 1 : 22; break; } } psvDebugScreenSetColors(); return i; } } return 0; } /* * Initialize debug screen */ int psvDebugScreenInit() { psvDebugScreenResetFgColor(); psvDebugScreenResetBgColor(); psvDebugScreenResetInversion(); psvDebugScreenSetColors(); #ifdef NO_psvDebugScreenInit psvDebugScreenInitReplacement(); return 0; // avoid linking non-initializer (prx) with sceDisplay/sceMemory #else mutex = sceKernelCreateMutex("log_mutex", 0, 0, NULL); SceUID displayblock = sceKernelAllocMemBlock("display", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, (SCREEN_FB_SIZE), NULL); sceKernelGetMemBlockBase(displayblock, (void**)&base); SceDisplayFrameBuf frame = { sizeof(frame), base, (SCREEN_FB_WIDTH), 0, (SCREEN_WIDTH), (SCREEN_HEIGHT) }; return sceDisplaySetFrameBuf(&frame, SCE_DISPLAY_SETBUF_NEXTFRAME); #endif } /* * Draw text onto debug screen */ int psvDebugScreenPuts(const char * _text) { const unsigned char*text = (const unsigned char*)_text; int c; unsigned char t; unsigned char drawDummy; // uint32_t *vram; int bits_per_glyph = ((F)->width * (F)->height); int bitmap_offset; unsigned char *font; int row; int max_row; int col; unsigned char mask; uint32_t *pixel; sceKernelLockMutex(mutex, 1, NULL); for (c = 0; text[c] ; c++) { t = text[c]; // handle CSI sequence if ((t == '\e') && (text[c+1] == '[')) { c += psvDebugScreenEscape(text + c + 2) + 2; if (coordX < 0) coordX = 0; // CSI position are 1-based, if (coordY < 0) coordY = 0; // prevent 0-based coordinate from producing a negative X/Y continue; } // handle non-printable characters #1 (line-dependent codes) if (t == '\n') { coordX = 0; coordY += (F)->size_h; continue; } if (t == '\r') { coordX = 0; continue; } // check if glyph fits in line if ((coordX + (F)->width) > (SCREEN_WIDTH)) { coordY += (F)->size_h; coordX = 0; } // check if glyph fits in screen if ((coordY + (F)->height) > (SCREEN_HEIGHT)) { coordX = coordY = 0; } // handle non-printable characters #2 if (t == '\t') { coordX += (SCREEN_TAB_W) - (coordX % (SCREEN_TAB_W)); continue; } // draw glyph or dummy glyph (dotted line in the middle) // works also with not byte-aligned glyphs vram = ((uint32_t*)base) + coordX + (coordY * (SCREEN_FB_WIDTH)); row = 0; // check if glyph is available in font if ((t > (F)->last) || (t < (F)->first)) { drawDummy = 1; } else { drawDummy = 0; bitmap_offset = (t - (F)->first) * bits_per_glyph; font = &(F)->glyphs[ (bitmap_offset / 8) ]; mask = 1 << 7; for (col = (bitmap_offset % 8); col > 0; col--, mask >>= 1); } // special case: dummy glyph, clear to middle height max_row = 0; if (drawDummy) { max_row = (F)->height / 2; for (; row < max_row; row++, vram += (SCREEN_FB_WIDTH)) { pixel = vram; col = 0; for (; col < (F)->size_w ; col++) { *pixel++ = colors.color_bg; } } } // draw font glyph or dummy glyph if (drawDummy) { max_row++; if (max_row > (F)->height) max_row = (F)->height; } else { max_row = (F)->height; } for (; row < max_row; row++, vram += (SCREEN_FB_WIDTH)) { pixel = vram; col = 0; for (; col < (F)->width ; col++, mask >>= 1) { if (drawDummy) { *pixel++ = (col&1) ? colors.color_fg : colors.color_bg; } else { if (!mask) { font++; mask = 1 << 7; } // no more bits: we exhausted this byte *pixel++ = (*font&mask) ? colors.color_fg : colors.color_bg; } } // right margin for (; col < (F)->size_w ; col++) *pixel++ = colors.color_bg; } // draw bottom margin max_row = (F)->size_h; for (; row < (F)->size_h; row++, vram += (SCREEN_FB_WIDTH)) for (pixel = vram, col = 0; col < (F)->size_w ; col++) *pixel++ = colors.color_bg; // advance X position coordX += (F)->size_w; } sceKernelUnlockMutex(mutex, 1); return c; } /* * Printf text onto debug screen */ __attribute__((__format__ (__printf__, 1, 2))) int psvDebugScreenPrintf(const char *format, ...) { char buf[4096]; va_list opt; va_start(opt, format); int ret = vsnprintf(buf, sizeof(buf), format, opt); psvDebugScreenPuts(buf); va_end(opt); return ret; } /* * Return copy of color state */ void psvDebugScreenGetColorStateCopy(ColorState *copy) { if (copy) { memcpy(copy, &colors, sizeof(ColorState)); CONVERT_RGB_BGR(copy->fgTrueColor); CONVERT_RGB_BGR(copy->bgTrueColor); CONVERT_RGB_BGR(copy->color_fg); CONVERT_RGB_BGR(copy->color_bg); } } /* * Return copy of pixel coordinates */ void psvDebugScreenGetCoordsXY(int *x, int *y) { if (x) *x = coordX; if (y) *y = coordY; } /* * Set pixel coordinates */ void psvDebugScreenSetCoordsXY(int *x, int *y) { if (x) { coordX = *x; if (coordX < 0) coordX = 0; } if (y) { coordY = *y; if (coordY < 0) coordY = 0; } } /* * Return pointer to current font */ PsvDebugScreenFont *psvDebugScreenGetFont(void) { return F; } /* * Set font */ PsvDebugScreenFont *psvDebugScreenSetFont(PsvDebugScreenFont *font) { if ((font) && (font->glyphs)) F = font; return F; } /* * Return scaled-by-2 copy of font */ PsvDebugScreenFont *psvDebugScreenScaleFont2x(PsvDebugScreenFont *source_font) { // works also with not byte-aligned glyphs PsvDebugScreenFont *target_font; size_t size; size_t align; int glyph; int row; int col; int count; unsigned char *source_bitmap; unsigned char source_mask; unsigned char *target_bitmap, *target_bitmap2; unsigned char target_mask, target_mask2; int target_next_row_bytes, target_next_row_bits; unsigned char pixel; if (!source_font) return NULL; // allocate target structure and bitmap target_font = (PsvDebugScreenFont *)malloc(sizeof(PsvDebugScreenFont)); memset(target_font, 0, sizeof(PsvDebugScreenFont)); // copy and scale meta information target_font->width = 2 * source_font->width; target_font->height = 2 * source_font->height; target_font->first = source_font->first; target_font->last = source_font->last; target_font->size_w = 2 * source_font->size_w; target_font->size_h = 2 * source_font->size_h; // calculate size of target bitmap size = target_font->width * target_font->height * (target_font->last - target_font->first + 1); if (size <= 0) { free(target_font); return NULL; } align = size % 8; size /= 8; if (align) size++; // allocate and initialize target bitmap target_font->glyphs = (unsigned char *)malloc(size); memset(target_font->glyphs, 0, size); // scale source bitmap and store in target bitmap source_bitmap = source_font->glyphs; source_mask = 1 << 7; // target_bitmap = target_font->glyphs; target_mask = 1 << 7; target_next_row_bytes = target_font->width / 8; target_next_row_bits = target_font->width % 8; // for (glyph = source_font->first; glyph <= source_font->last; glyph++) { for (row = source_font->height; row > 0; row--) { // Find beginning of next target row target_bitmap2 = target_bitmap + target_next_row_bytes; // advance full bytes target_mask2 = target_mask; // advance remaining bits for (col = target_next_row_bits; col > 0; col--, target_mask2 >>= 1) { if (!target_mask2) { target_bitmap2++; target_mask2 = 1 << 7; } // no more bits: we advance to the next target byte } // Get pixel from source bitmap for (col = source_font->width; col > 0; col--, source_mask >>= 1) { if (!source_mask) { source_bitmap++; source_mask = 1 << 7; } // no more bits: we advance to the next source byte pixel = *source_bitmap & source_mask; // Put pixels into target bitmap for (count = 2; count > 0; count--) { // duplicate column in origial row if (!target_mask) { target_bitmap++; target_mask = 1 << 7; } // no more bits: we advance to the next target byte if (pixel) *target_bitmap |= target_mask; target_mask >>= 1; // duplicate column in duplicated row if (!target_mask2) { target_bitmap2++; target_mask2 = 1 << 7; } // no more bits: we advance to the next target byte if (pixel) *target_bitmap2 |= target_mask2; target_mask2 >>= 1; } } // Next target row is directly behind duplicated row target_bitmap = target_bitmap2; target_mask = target_mask2; } } return target_font; } #undef SCREEN_TAB_W #undef F #endif
25,064
C
.c
656
35.22561
187
0.662958
windsurfer1122/Vita-Account-Manager
22
1
0
GPL-3.0
9/7/2024, 10:33:22 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
4,240,769
dll.c
hac425xxx_trapfuzzer-gdb/gdb/gdbserver/dll.c
/* Copyright (C) 2002-2020 Free Software Foundation, Inc. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "server.h" #include "dll.h" #include <algorithm> /* An "unspecified" CORE_ADDR, for match_dll. */ #define UNSPECIFIED_CORE_ADDR (~(CORE_ADDR) 0) std::list<dll_info> all_dlls; int dlls_changed; /* Record a newly loaded DLL at BASE_ADDR. */ void loaded_dll (const char *name, CORE_ADDR base_addr) { all_dlls.emplace_back (name != NULL ? name : "", base_addr); dlls_changed = 1; } /* Record that the DLL with NAME and BASE_ADDR has been unloaded. */ void unloaded_dll (const char *name, CORE_ADDR base_addr) { auto pred = [&] (const dll_info &dll) { if (base_addr != UNSPECIFIED_CORE_ADDR && base_addr == dll.base_addr) return true; if (name != NULL && dll.name == name) return true; return false; }; auto iter = std::find_if (all_dlls.begin (), all_dlls.end (), pred); if (iter == all_dlls.end ()) /* For some inferiors we might get unloaded_dll events without having a corresponding loaded_dll. In that case, the dll cannot be found in ALL_DLL, and there is nothing further for us to do. This has been observed when running 32bit executables on Windows64 (i.e. through WOW64, the interface between the 32bits and 64bits worlds). In that case, the inferior always does some strange unloading of unnamed dll. */ return; else { /* DLL has been found so remove the entry and free associated resources. */ all_dlls.erase (iter); dlls_changed = 1; } } void clear_dlls (void) { all_dlls.clear (); }
2,286
C
.c
62
32.951613
76
0.697643
hac425xxx/trapfuzzer-gdb
20
7
0
GPL-2.0
9/7/2024, 10:34:45 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
4,240,791
debug.c
hac425xxx_trapfuzzer-gdb/gdb/gdbserver/debug.c
/* Debugging routines for the remote server for GDB. Copyright (C) 2014-2020 Free Software Foundation, Inc. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "server.h" #include <chrono> #if !defined (IN_PROCESS_AGENT) int remote_debug = 0; #endif /* Output file for debugging. Default to standard error. */ FILE *debug_file = stderr; /* See debug.h. */ int debug_threads; /* Include timestamps in debugging output. */ int debug_timestamp; #if !defined (IN_PROCESS_AGENT) /* See debug.h. */ void debug_set_output (const char *new_debug_file) { /* Close any existing file and reset to standard error. */ if (debug_file != stderr) { fclose (debug_file); } debug_file = stderr; /* Catch empty filenames. */ if (new_debug_file == nullptr || strlen (new_debug_file) == 0) return; FILE *fptr = fopen (new_debug_file, "w"); if (fptr == nullptr) { debug_printf ("Cannot open %s for writing. %s. Switching to stderr.\n", new_debug_file, safe_strerror (errno)); return; } debug_file = fptr; } #endif /* Print a debugging message. If the text begins a new line it is preceded by a timestamp. We don't get fancy with newline checking, we just check whether the previous call ended with "\n". */ void debug_vprintf (const char *format, va_list ap) { #if !defined (IN_PROCESS_AGENT) /* N.B. Not thread safe, and can't be used, as is, with IPA. */ static int new_line = 1; if (debug_timestamp && new_line) { using namespace std::chrono; steady_clock::time_point now = steady_clock::now (); seconds s = duration_cast<seconds> (now.time_since_epoch ()); microseconds us = duration_cast<microseconds> (now.time_since_epoch ()) - s; fprintf (debug_file, "%ld.%06ld ", (long) s.count (), (long) us.count ()); } #endif vfprintf (debug_file, format, ap); #if !defined (IN_PROCESS_AGENT) if (*format) new_line = format[strlen (format) - 1] == '\n'; #endif } /* Flush debugging output. This is called, for example, when starting an inferior to ensure all debug output thus far appears before any inferior output. */ void debug_flush (void) { fflush (debug_file); } /* Notify the user that the code is entering FUNCTION_NAME. FUNCTION_NAME is the name of the calling function, or NULL if unknown. This is intended to be called via the debug_enter macro. */ void do_debug_enter (const char *function_name) { if (function_name != NULL) debug_printf (">>>> entering %s\n", function_name); } /* Notify the user that the code is exiting FUNCTION_NAME. FUNCTION_NAME is the name of the calling function, or NULL if unknown. This is intended to be called via the debug_exit macro. */ void do_debug_exit (const char *function_name) { if (function_name != NULL) debug_printf ("<<<< exiting %s\n", function_name); } /* See debug.h. */ ssize_t debug_write (const void *buf, size_t nbyte) { int fd = fileno (debug_file); return write (fd, buf, nbyte); }
3,656
C
.c
106
31.349057
82
0.69909
hac425xxx/trapfuzzer-gdb
20
7
0
GPL-2.0
9/7/2024, 10:34:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
4,240,890
common-exceptions.c
hac425xxx_trapfuzzer-gdb/gdb/gdbsupport/common-exceptions.c
/* Exception (throw catch) mechanism, for GDB, the GNU debugger. Copyright (C) 1986-2020 Free Software Foundation, Inc. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "common-defs.h" #include "common-exceptions.h" #include <forward_list> /* Possible catcher states. */ enum catcher_state { /* Initial state, a new catcher has just been created. */ CATCHER_CREATED, /* The catch code is running. */ CATCHER_RUNNING, CATCHER_RUNNING_1, /* The catch code threw an exception. */ CATCHER_ABORTING }; /* Possible catcher actions. */ enum catcher_action { CATCH_ITER, CATCH_ITER_1, CATCH_THROWING }; struct catcher { enum catcher_state state = CATCHER_CREATED; /* Jump buffer pointing back at the exception handler. */ jmp_buf buf; /* Status buffer belonging to the exception handler. */ struct gdb_exception exception; }; /* Where to go for throw_exception(). */ static std::forward_list<struct catcher> catchers; jmp_buf * exceptions_state_mc_init () { catchers.emplace_front (); return &catchers.front ().buf; } /* Catcher state machine. Returns non-zero if the m/c should be run again, zero if it should abort. */ static int exceptions_state_mc (enum catcher_action action) { switch (catchers.front ().state) { case CATCHER_CREATED: switch (action) { case CATCH_ITER: /* Allow the code to run the catcher. */ catchers.front ().state = CATCHER_RUNNING; return 1; default: internal_error (__FILE__, __LINE__, _("bad state")); } case CATCHER_RUNNING: switch (action) { case CATCH_ITER: /* No error/quit has occured. */ return 0; case CATCH_ITER_1: catchers.front ().state = CATCHER_RUNNING_1; return 1; case CATCH_THROWING: catchers.front ().state = CATCHER_ABORTING; /* See also throw_exception. */ return 1; default: internal_error (__FILE__, __LINE__, _("bad switch")); } case CATCHER_RUNNING_1: switch (action) { case CATCH_ITER: /* The did a "break" from the inner while loop. */ return 0; case CATCH_ITER_1: catchers.front ().state = CATCHER_RUNNING; return 0; case CATCH_THROWING: catchers.front ().state = CATCHER_ABORTING; /* See also throw_exception. */ return 1; default: internal_error (__FILE__, __LINE__, _("bad switch")); } case CATCHER_ABORTING: switch (action) { case CATCH_ITER: { /* Exit normally if this catcher can handle this exception. The caller analyses the func return values. */ return 0; } default: internal_error (__FILE__, __LINE__, _("bad state")); } default: internal_error (__FILE__, __LINE__, _("bad switch")); } } int exceptions_state_mc_catch (struct gdb_exception *exception, int mask) { *exception = std::move (catchers.front ().exception); catchers.pop_front (); if (exception->reason < 0) { if (mask & RETURN_MASK (exception->reason)) { /* Exit normally and let the caller handle the exception. */ return 1; } /* The caller didn't request that the event be caught, relay the event to the next exception_catch/CATCH_SJLJ. */ throw_exception_sjlj (*exception); } /* No exception was thrown. */ return 0; } int exceptions_state_mc_action_iter (void) { return exceptions_state_mc (CATCH_ITER); } int exceptions_state_mc_action_iter_1 (void) { return exceptions_state_mc (CATCH_ITER_1); } /* Return EXCEPTION to the nearest containing CATCH_SJLJ block. */ void throw_exception_sjlj (const struct gdb_exception &exception) { /* Jump to the nearest CATCH_SJLJ block, communicating REASON to that call via setjmp's return value. Note that REASON can't be zero, by definition in common-exceptions.h. */ exceptions_state_mc (CATCH_THROWING); enum return_reason reason = exception.reason; catchers.front ().exception = exception; longjmp (catchers.front ().buf, reason); } /* Implementation of throw_exception that uses C++ try/catch. */ void throw_exception (gdb_exception &&exception) { if (exception.reason == RETURN_QUIT) throw gdb_exception_quit (std::move (exception)); else if (exception.reason == RETURN_ERROR) throw gdb_exception_error (std::move (exception)); else gdb_assert_not_reached ("invalid return reason"); } static void ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0) throw_it (enum return_reason reason, enum errors error, const char *fmt, va_list ap) { if (reason == RETURN_QUIT) throw gdb_exception_quit (fmt, ap); else if (reason == RETURN_ERROR) throw gdb_exception_error (error, fmt, ap); else gdb_assert_not_reached ("invalid return reason"); } void throw_verror (enum errors error, const char *fmt, va_list ap) { throw_it (RETURN_ERROR, error, fmt, ap); } void throw_vquit (const char *fmt, va_list ap) { throw_it (RETURN_QUIT, GDB_NO_ERROR, fmt, ap); } void throw_error (enum errors error, const char *fmt, ...) { va_list args; va_start (args, fmt); throw_verror (error, fmt, args); va_end (args); } void throw_quit (const char *fmt, ...) { va_list args; va_start (args, fmt); throw_vquit (fmt, args); va_end (args); }
5,810
C
.c
205
25.297561
76
0.697937
hac425xxx/trapfuzzer-gdb
20
7
0
GPL-2.0
9/7/2024, 10:34:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
4,240,891
common-inferior.c
hac425xxx_trapfuzzer-gdb/gdb/gdbsupport/common-inferior.c
/* Functions to deal with the inferior being executed on GDB or GDBserver. Copyright (C) 2019-2020 Free Software Foundation, Inc. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "gdbsupport/common-defs.h" #include "gdbsupport/common-inferior.h" /* See common-inferior.h. */ bool startup_with_shell = true;
955
C
.c
18
49.444444
76
0.763186
hac425xxx/trapfuzzer-gdb
20
7
0
GPL-2.0
9/7/2024, 10:34:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
4,240,918
new-op.c
hac425xxx_trapfuzzer-gdb/gdb/gdbsupport/new-op.c
/* Replace operator new/new[], for GDB, the GNU debugger. Copyright (C) 2016-2020 Free Software Foundation, Inc. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* GCC does not understand __has_feature. */ #if !defined(__has_feature) # define __has_feature(x) 0 #endif #if !__has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__) #include "common-defs.h" #include "host-defs.h" #include <new> /* Override operator new / operator new[], in order to internal_error on allocation failure and thus query the user for abort/core dump/continue, just like xmalloc does. We don't do this from a new-handler function instead (std::set_new_handler) because we want to catch allocation errors from within global constructors too. Skip overriding if building with -fsanitize=address though. Address sanitizer wants to override operator new/delete too in order to detect malloc+delete and new+free mismatches. Our versions would mask out ASan's, with the result of losing that useful mismatch detection. Note that C++ implementations could either have their throw versions call the nothrow versions (libstdc++), or the other way around (clang/libc++). For that reason, we replace both throw and nothrow variants and call malloc directly. */ void * operator new (std::size_t sz) { /* malloc (0) is unpredictable; avoid it. */ if (sz == 0) sz = 1; void *p = malloc (sz); /* ARI: malloc */ if (p == NULL) { /* If the user decides to continue debugging, throw a gdb_quit_bad_alloc exception instead of a regular QUIT gdb_exception. The former extends both std::bad_alloc and a QUIT gdb_exception. This is necessary because operator new can only ever throw std::bad_alloc, or something that extends it. */ try { malloc_failure (sz); } catch (gdb_exception &ex) { throw gdb_quit_bad_alloc (std::move (ex)); } } return p; } void * operator new (std::size_t sz, const std::nothrow_t&) noexcept { /* malloc (0) is unpredictable; avoid it. */ if (sz == 0) sz = 1; return malloc (sz); /* ARI: malloc */ } void * operator new[] (std::size_t sz) { return ::operator new (sz); } void* operator new[] (std::size_t sz, const std::nothrow_t&) noexcept { return ::operator new (sz, std::nothrow); } #endif
2,954
C
.c
80
33.8625
76
0.718433
hac425xxx/trapfuzzer-gdb
20
7
0
GPL-2.0
9/7/2024, 10:34:45 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
4,529,620
SSLtest.c
Wolframe_Wolframe/.Attic/SSLtest.c
// // server.cpp // ~~~~~~~~~~ // // Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include <cstdlib> #include <iostream> #include <boost/bind.hpp> #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket; class session { public: session( boost::asio::io_service& io_service, boost::asio::ssl::context& context ) : socket_( io_service, context ) { } ssl_socket::lowest_layer_type& socket() { return socket_.lowest_layer(); } void start() { socket_.async_handshake( boost::asio::ssl::stream_base::server, boost::bind( &session::handle_handshake, this, boost::asio::placeholders::error )); } void handle_handshake(const boost::system::error_code& error) { if ( !error ) { socket_.async_read_some( boost::asio::buffer( data_, max_length ), boost::bind( &session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred )); } else { delete this; } } void handle_read(const boost::system::error_code& error, size_t bytes_transferred) { if ( !error ) { boost::asio::async_write( socket_, boost::asio::buffer( data_, bytes_transferred ), boost::bind( &session::handle_write, this, boost::asio::placeholders::error )); } else { delete this; } } void handle_write(const boost::system::error_code& error) { if ( !error ) { socket_.async_read_some( boost::asio::buffer( data_, max_length ), boost::bind( &session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred )); } else { delete this; } } private: ssl_socket socket_; enum { max_length = 1024 }; char data_[max_length]; }; class server { public: server(boost::asio::io_service& io_service, unsigned short port) : io_service_( io_service ), acceptor_( io_service, boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), port )), context_( io_service, boost::asio::ssl::context::sslv23 ) { context_.set_options( boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::single_dh_use ); context_.set_password_callback( boost::bind( &server::get_password, this )); context_.use_certificate_chain_file( "server.pem" ); context_.use_private_key_file( "server.pem", boost::asio::ssl::context::pem ); context_.use_tmp_dh_file( "dh512.pem" ); session* new_session = new session( io_service_, context_ ); acceptor_.async_accept( new_session->socket(), boost::bind( &server::handle_accept, this, new_session, boost::asio::placeholders::error )); } std::string get_password() const { return "test"; } void handle_accept( session* new_session, const boost::system::error_code& error ) { if ( !error ) { new_session->start(); new_session = new session( io_service_, context_ ); acceptor_.async_accept( new_session->socket(), boost::bind( &server::handle_accept, this, new_session, boost::asio::placeholders::error )); } else { delete new_session; } } private: boost::asio::io_service& io_service_; boost::asio::ip::tcp::acceptor acceptor_; boost::asio::ssl::context context_; }; int main( int argc, char* argv[] ) { try { if ( argc != 2 ) { std::cerr << "Usage: server <port>\n"; return 1; } boost::asio::io_service io_service; using namespace std; // For atoi. server s( io_service, atoi( argv[1] )); io_service.run(); } catch ( std::exception& e ) { std::cerr << "Exception: " << e.what() << "\n"; } return 0; }
3,959
C
.c
142
24.049296
83
0.645866
Wolframe/Wolframe
12
0
88
GPL-3.0
9/7/2024, 10:45:27 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
4,545,589
ilu_noise.c
LuaDist_libdevil/src-ILU/src/ilu_noise.c
//----------------------------------------------------------------------------- // // ImageLib Utility Sources // Copyright (C) 2000-2002 by Denton Woods // Last modified: 05/25/2001 <--Y2K Compliant! =] // // Filename: src-ILU/src/ilu_noise.c // // Description: Noise generation functions // //----------------------------------------------------------------------------- #include "ilu_internal.h" #include <math.h> //#include <time.h> #include <limits.h> // Very simple right now. // This will probably use Perlin noise and parameters in the future. ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance) { ILuint i, j, c, Factor, Factor2, NumPix; ILint Val; ILushort *ShortPtr; ILuint *IntPtr; ILubyte *RegionMask; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { ilSetError(ILU_ILLEGAL_OPERATION); return IL_FALSE; } RegionMask = iScanFill(); // @TODO: Change this to work correctly without time()! //srand(time(NULL)); NumPix = iluCurImage->SizeOfData / iluCurImage->Bpc; switch (iluCurImage->Bpc) { case 1: Factor = (ILubyte)(Tolerance * (UCHAR_MAX / 2)); if (Factor == 0) return IL_TRUE; Factor2 = Factor + Factor; for (i = 0, j = 0; i < NumPix; i += iluCurImage->Bpp, j++) { if (RegionMask) { if (!RegionMask[j]) continue; } Val = (ILint)((ILint)(rand() % Factor2) - Factor); for (c = 0; c < iluCurImage->Bpp; c++) { if ((ILint)iluCurImage->Data[i + c] + Val > UCHAR_MAX) iluCurImage->Data[i + c] = UCHAR_MAX; else if ((ILint)iluCurImage->Data[i + c] + Val < 0) iluCurImage->Data[i + c] = 0; else iluCurImage->Data[i + c] += Val; } } break; case 2: Factor = (ILushort)(Tolerance * (USHRT_MAX / 2)); if (Factor == 0) return IL_TRUE; Factor2 = Factor + Factor; ShortPtr = (ILushort*)iluCurImage->Data; for (i = 0, j = 0; i < NumPix; i += iluCurImage->Bpp, j++) { if (RegionMask) { if (!RegionMask[j]) continue; } Val = (ILint)((ILint)(rand() % Factor2) - Factor); for (c = 0; c < iluCurImage->Bpp; c++) { if ((ILint)ShortPtr[i + c] + Val > USHRT_MAX) ShortPtr[i + c] = USHRT_MAX; else if ((ILint)ShortPtr[i + c] + Val < 0) ShortPtr[i + c] = 0; else ShortPtr[i + c] += Val; } } break; case 4: Factor = (ILuint)(Tolerance * (UINT_MAX / 2)); if (Factor == 0) return IL_TRUE; Factor2 = Factor + Factor; IntPtr = (ILuint*)iluCurImage->Data; for (i = 0, j = 0; i < NumPix; i += iluCurImage->Bpp, j++) { if (RegionMask) { if (!RegionMask[j]) continue; } Val = (ILint)((ILint)(rand() % Factor2) - Factor); for (c = 0; c < iluCurImage->Bpp; c++) { if (IntPtr[i + c] + Val > UINT_MAX) IntPtr[i + c] = UINT_MAX; else if ((ILint)IntPtr[i + c] + Val < 0) IntPtr[i + c] = 0; else IntPtr[i + c] += Val; } } break; } ifree(RegionMask); return IL_TRUE; } // Information on Perlin Noise taken from // http://freespace.virgin.net/hugo.elias/models/m_perlin.htm /*ILdouble Noise(ILint x, ILint y) { ILint n; n = x + y * 57; n = (n<<13) ^ n; return (1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); } ILdouble SmoothNoise(ILint x, ILint y) { ILdouble corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16; ILdouble sides = ( Noise(x-1, y) +Noise(x+1, y) +Noise(x, y-1) +Noise(x, y+1) ) / 8; ILdouble center = Noise(x, y) / 4; return corners + sides + center; } ILdouble Interpolate(ILdouble a, ILdouble b, ILdouble x) { ILdouble ft = x * 3.1415927; ILdouble f = (1 - cos(ft)) * .5; return a*(1-f) + b*f; } ILdouble InterpolatedNoise(ILdouble x, ILdouble y) { ILint integer_X, integer_Y; ILdouble fractional_X, fractional_Y, v1, v2, v3, v4, i1, i2; integer_X = (ILint)x; fractional_X = x - integer_X; integer_Y = (ILint)y; fractional_Y = y - integer_Y; v1 = SmoothNoise(integer_X, integer_Y); v2 = SmoothNoise(integer_X + 1, integer_Y); v3 = SmoothNoise(integer_X, integer_Y + 1); v4 = SmoothNoise(integer_X + 1, integer_Y + 1); i1 = Interpolate(v1, v2, fractional_X); i2 = Interpolate(v3, v4, fractional_X); return Interpolate(i1, i2, fractional_Y); } ILdouble PerlinNoise(ILdouble x, ILdouble y) { ILuint i, n; ILdouble total = 0, p, frequency, amplitude; //p = persistence; //n = Number_Of_Octaves - 1; n = 2; //p = .5; p = (ILdouble)(rand() % 1000) / 1000.0; for (i = 0; i < n; i++) { frequency = pow(2, i); amplitude = pow(p, i); total = total + InterpolatedNoise(x * frequency, y * frequency) * amplitude; } return total; } ILboolean ILAPIENTRY iluNoisify() { ILuint x, y, c; ILint Val; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { ilSetError(ILU_ILLEGAL_OPERATION); return IL_FALSE; } for (y = 0; y < iluCurImage->Height; y++) { for (x = 0; x < iluCurImage->Width; x++) { Val = (ILint)(PerlinNoise(x, y) * 50.0); for (c = 0; c < iluCurImage->Bpp; c++) { if ((ILint)iluCurImage->Data[y * iluCurImage->Bps + x * iluCurImage->Bpp + c] + Val > 255) iluCurImage->Data[y * iluCurImage->Bps + x * iluCurImage->Bpp + c] = 255; else if ((ILint)iluCurImage->Data[y * iluCurImage->Bps + x * iluCurImage->Bpp + c] + Val < 0) iluCurImage->Data[y * iluCurImage->Bps + x * iluCurImage->Bpp + c] = 0; else iluCurImage->Data[y * iluCurImage->Bps + x * iluCurImage->Bpp + c] += Val; } } } return IL_TRUE; }*/
5,531
C
.c
182
26.983516
97
0.596306
LuaDist/libdevil
11
9
1
LGPL-2.1
9/7/2024, 10:46:24 AM (Europe/Amsterdam)
false
true
false
true
false
true
false
false
4,545,590
ilu_internal.c
LuaDist_libdevil/src-ILU/src/ilu_internal.c
#define ILU_INTERNAL_C #include "ilu_internal.h" const ILdouble IL_PI = 3.1415926535897932384626; const ILdouble IL_DEGCONV = 0.0174532925199432957692; ILimage *iluCurImage = NULL;
190
C
.c
5
36.2
53
0.79558
LuaDist/libdevil
11
9
1
LGPL-2.1
9/7/2024, 10:46:24 AM (Europe/Amsterdam)
false
true
false
true
true
true
false
false
4,545,597
ilu_alloc.c
LuaDist_libdevil/src-ILU/src/ilu_alloc.c
#include <stdio.h> #if defined(_WIN32) && defined(_MEM_DEBUG) #include <windows.h> int bAtexit = 0; typedef struct ALLOC_INFO { unsigned long address; unsigned long size; char file[64]; unsigned long line; struct ALLOC_INFO *Next; } ALLOC_INFO; ALLOC_INFO *AllocList; void AddTrack(unsigned long addr, unsigned long size, const char *file, unsigned long line) { ALLOC_INFO *Temp; if (AllocList == NULL) { AllocList = (ALLOC_INFO*)malloc(sizeof(ALLOC_INFO)); // Just assume it succeeds. AllocList->address = addr; AllocList->size = size; AllocList->line = line; strncpy(AllocList->file, file, 63); AllocList->Next = NULL; } else { Temp = AllocList; AllocList = (ALLOC_INFO*)malloc(sizeof(ALLOC_INFO)); // Just assume it succeeds. AllocList->address = addr; AllocList->size = size; AllocList->line = line; strncpy(AllocList->file, file, 63); AllocList->Next = Temp; } return; } void RemoveTrack(unsigned long addr) { ALLOC_INFO *Temp, *Prev; Temp = AllocList; Prev = NULL; if (Temp == NULL) return; while (Temp != NULL) { if (Temp->address == addr) { if (Prev == NULL) { AllocList = Temp->Next; free(Temp); } else { Prev->Next = Temp->Next; free(Temp); } break; } Prev = Temp; Temp = Temp->Next; } return; } void DumpUnfreed(void) { unsigned long TotalSize = 0; char buf[1024]; ALLOC_INFO *i = AllocList; OutputDebugString("ILU Unfreed Information:\n"); while (i != NULL) { sprintf(buf, "%s(%d) : %d bytes unfreed at %d\n", i->file, i->line, i->size, i->address); OutputDebugString(buf); TotalSize += i->size; AllocList = i->Next; free(i); i = AllocList; } sprintf(buf, "-----------------------------------------------------------\n"); OutputDebugString(buf); sprintf(buf, "Total Unfreed: %d bytes\n\n\n", TotalSize); OutputDebugString(buf); } void AddToAtexit() { if (bAtexit) return; atexit(DumpUnfreed); bAtexit = 1; } void *c_alloc(unsigned long size, unsigned long num, const char *file, unsigned long line) { ILvoid *ptr; ptr = calloc(size, num); if (!ptr) return NULL; AddToAtexit(); AddTrack((unsigned long)ptr, size * num, file, line); return ptr; } void *m_alloc(unsigned long size, const char *file, unsigned long line) { ILvoid *ptr; ptr = malloc(size); if (!ptr) return NULL; AddToAtexit(); AddTrack((unsigned long)ptr, size, file, line); return ptr; } void f_ree(void *ptr) { RemoveTrack((unsigned long)ptr); free(ptr); return; } #endif//defined(_WIN32) && defined(_MEM_DEBUG)
2,662
C
.c
112
20.366071
92
0.644189
LuaDist/libdevil
11
9
1
LGPL-2.1
9/7/2024, 10:46:24 AM (Europe/Amsterdam)
false
true
false
true
false
true
false
false
4,545,663
ilut_main.c
LuaDist_libdevil/src-ILUT/src/ilut_main.c
//----------------------------------------------------------------------------- // // ImageLib Utility Toolkit Sources // Copyright (C) 2000-2002 by Denton Woods // Last modified: 05/28/2001 <--Y2K Compliant! =] // // Filename: src-ILUT/src/ilut_main.c // // Description: Startup functions // //----------------------------------------------------------------------------- #include "ilut_internal.h" #ifdef _WIN32 #ifndef IL_STATIC_LIB //#define WIN32_LEAN_AND_MEAN #include <windows.h> #ifdef _WIN32 #if (defined(IL_USE_PRAGMA_LIBS)) #if defined(_MSC_VER) || defined(__BORLANDC__) #pragma comment(lib, "ILU.lib") #endif #endif #endif BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { hModule; lpReserved; // only initialize when attached to a new process. setup can cause errors in OpenIL // when called on a per thread basis if (ul_reason_for_call == DLL_PROCESS_ATTACH) { //ilutInit(); } return TRUE; } #endif #else // Should check if gcc? // Should be able to condense this... static void GccMain() __attribute__((constructor)); static void GccMain() { //ilutInit(); } #endif void ILAPIENTRY ilutInit() { ilutDefaultStates(); // Set states to their defaults // Can cause crashes if DevIL is not initialized yet #ifdef ILUT_USE_OPENGL ilutGLInit(); // default renderer is OpenGL #endif #ifdef ILUT_USE_DIRECTX8 ilutD3D8Init(); #endif #ifdef ILUT_USE_DIRECTX9 ilutD3D9Init(); #endif return; }
1,479
C
.c
57
24.157895
84
0.654312
LuaDist/libdevil
11
9
1
LGPL-2.1
9/7/2024, 10:46:24 AM (Europe/Amsterdam)
false
true
false
true
true
true
false
false
4,545,765
il_rot.c
LuaDist_libdevil/src-IL/src/il_rot.c
//----------------------------------------------------------------------------- // // ImageLib Sources // Copyright (C) 2000-2009 by Denton Woods // Last modified: 02/15/2009 // // Filename: src-IL/src/il_rot.c // // Description: Reads from a Homeworld 2 - Relic Texture (.rot) file. // //----------------------------------------------------------------------------- // @TODO: // Note: I am not certain about which is DXT3 and which is DXT5. According to // http://forums.relicnews.com/showthread.php?t=20512, DXT3 is 1030, and DXT5 // is 1029. However, neither way seems to work quite right for the alpha. #include "il_internal.h" #ifndef IL_NO_ROT #include "il_dds.h" ILboolean iLoadRotInternal(void); #define ROT_RGBA32 1024 #define ROT_DXT1 1028 #define ROT_DXT3 1029 #define ROT_DXT5 1030 //! Reads a ROT file ILboolean ilLoadRot(ILconst_string FileName) { ILHANDLE RotFile; ILboolean bRot = IL_FALSE; RotFile = iopenr(FileName); if (RotFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return bRot; } bRot = ilLoadRotF(RotFile); icloser(RotFile); return bRot; } //! Reads an already-opened ROT file ILboolean ilLoadRotF(ILHANDLE File) { ILuint FirstPos; ILboolean bRet; iSetInputFile(File); FirstPos = itell(); bRet = iLoadRotInternal(); iseek(FirstPos, IL_SEEK_SET); return bRet; } //! Reads from a memory "lump" that contains a ROT ILboolean ilLoadRotL(const void *Lump, ILuint Size) { iSetInputLump(Lump, Size); return iLoadRotInternal(); } // Internal function used to load the ROT. ILboolean iLoadRotInternal(void) { ILubyte Form[4], FormName[4]; ILuint FormLen, Width, Height, Format, Channels, CompSize; ILuint MipSize, MipLevel, MipWidth, MipHeight; ILenum FormatIL; ILimage *Image; ILboolean BaseCreated = IL_FALSE; ILubyte *CompData = NULL; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } // The first entry in the file must be 'FORM', 0x20 in a big endian integer and then 'HEAD'. iread(Form, 1, 4); FormLen = GetBigUInt(); iread(FormName, 1, 4); if (strncmp(Form, "FORM", 4) || FormLen != 0x14 || strncmp(FormName, "HEAD", 4)) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } // Next follows the width, height and format in the header. Width = GetLittleUInt(); Height = GetLittleUInt(); Format = GetLittleUInt(); //@TODO: More formats. switch (Format) { case ROT_RGBA32: // 32-bit RGBA format Channels = 4; FormatIL = IL_RGBA; break; case ROT_DXT1: // DXT1 (no alpha) Channels = 4; FormatIL = IL_RGBA; break; case ROT_DXT3: // DXT3 case ROT_DXT5: // DXT5 Channels = 4; FormatIL = IL_RGBA; // Allocates the maximum needed (the first width/height given in the file). CompSize = ((Width + 3) / 4) * ((Height + 3) / 4) * 16; CompData = ialloc(CompSize); if (CompData == NULL) return IL_FALSE; break; default: ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } if (Width == 0 || Height == 0) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } //@TODO: Find out what this is. GetLittleUInt(); // Skip this for the moment. This appears to be the number of channels. // Next comes 'FORM', a length and 'MIPS'. iread(Form, 1, 4); FormLen = GetBigUInt(); iread(FormName, 1, 4); //@TODO: Not sure if the FormLen has to be anything specific here. if (strncmp(Form, "FORM", 4) || strncmp(FormName, "MIPS", 4)) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } //@TODO: Can these mipmap levels be in any order? Some things may be easier if the answer is no. Image = iCurImage; do { // Then we have 'FORM' again. iread(Form, 1, 4); // This is the size of the mipmap data. MipSize = GetBigUInt(); iread(FormName, 1, 4); if (strncmp(Form, "FORM", 4)) { if (!BaseCreated) { // Our file is malformed. ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } // We have reached the end of the mipmap data. break; } if (strncmp(FormName, "MLVL", 4)) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } // Next is the mipmap attributes (level number, width, height and length) MipLevel = GetLittleUInt(); MipWidth = GetLittleUInt(); MipHeight = GetLittleUInt(); MipSize = GetLittleUInt(); // This is the same as the previous size listed -20 (for attributes). // Lower level mipmaps cannot be larger than the main image. if (MipWidth > Width || MipHeight > Height || MipSize > CompSize) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } // Just create our images here. if (!BaseCreated) { if (!ilTexImage(MipWidth, MipHeight, 1, Channels, FormatIL, IL_UNSIGNED_BYTE, NULL)) return IL_FALSE; BaseCreated = IL_TRUE; } else { Image->Mipmaps = ilNewImageFull(MipWidth, MipHeight, 1, Channels, FormatIL, IL_UNSIGNED_BYTE, NULL); Image = Image->Mipmaps; } switch (Format) { case ROT_RGBA32: // 32-bit RGBA format if (iread(Image->Data, Image->SizeOfData, 1) != 1) return IL_FALSE; break; case ROT_DXT1: // Allocates the size of the compressed data. CompSize = ((MipWidth + 3) / 4) * ((MipHeight + 3) / 4) * 8; if (CompSize != MipSize) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } CompData = ialloc(CompSize); if (CompData == NULL) return IL_FALSE; // Read in the DXT1 data... if (iread(CompData, CompSize, 1) != 1) return IL_FALSE; // ...and decompress it. if (!DecompressDXT1(Image, CompData)) { ifree(CompData); return IL_FALSE; } if (ilGetInteger(IL_KEEP_DXTC_DATA) == IL_TRUE) { Image->DxtcSize = CompSize; Image->DxtcData = CompData; Image->DxtcFormat = IL_DXT1; CompData = NULL; } break; case ROT_DXT3: // Allocates the size of the compressed data. CompSize = ((MipWidth + 3) / 4) * ((MipHeight + 3) / 4) * 16; if (CompSize != MipSize) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } CompData = ialloc(CompSize); if (CompData == NULL) return IL_FALSE; // Read in the DXT3 data... if (iread(CompData, MipSize, 1) != 1) return IL_FALSE; // ...and decompress it. if (!DecompressDXT3(Image, CompData)) { ifree(CompData); return IL_FALSE; } if (ilGetInteger(IL_KEEP_DXTC_DATA) == IL_TRUE) { Image->DxtcSize = CompSize; Image->DxtcData = CompData; Image->DxtcFormat = IL_DXT3; CompData = NULL; } break; case ROT_DXT5: // Allocates the size of the compressed data. CompSize = ((MipWidth + 3) / 4) * ((MipHeight + 3) / 4) * 16; if (CompSize != MipSize) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } CompData = ialloc(CompSize); if (CompData == NULL) return IL_FALSE; // Read in the DXT5 data... if (iread(CompData, MipSize, 1) != 1) return IL_FALSE; // ...and decompress it. if (!DecompressDXT5(Image, CompData)) { ifree(CompData); return IL_FALSE; } // Keeps a copy if (ilGetInteger(IL_KEEP_DXTC_DATA) == IL_TRUE) { Image->DxtcSize = CompSize; Image->DxtcData = CompData; Image->DxtcFormat = IL_DXT5; CompData = NULL; } break; } ifree(CompData); // Free it if it was not saved. } while (!ieof()); //@TODO: Is there any other condition that should end this? return ilFixImage(); } #endif//IL_NO_ROT
7,434
C
.c
248
26.451613
103
0.654158
LuaDist/libdevil
11
9
1
LGPL-2.1
9/7/2024, 10:46:24 AM (Europe/Amsterdam)
false
true
false
true
false
true
true
false
4,896,530
serial.c
mgrennan_oswabox/src/serial.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <termios.h> #include <inttypes.h> #include <string.h> #include "serial.h" int uart0_filestream = -1; void serial_init(void) { uart0_filestream = open(PORTNAME, O_RDWR | O_NOCTTY | O_NDELAY); if (uart0_filestream == -1) { //TODO error handling... } } void serial_config(void) { struct termios options; tcgetattr(uart0_filestream, &options); options.c_cflag = B9600 | CS8 | CLOCAL | CREAD; options.c_iflag = IGNPAR; options.c_oflag = 0; options.c_lflag = 0; tcflush(uart0_filestream, TCIFLUSH); tcsetattr(uart0_filestream, TCSANOW, &options); } void serial_println(const char *line, int len) { if (uart0_filestream != -1) { char *cpstr = (char *)malloc((len+1) * sizeof(char)); strcpy(cpstr, line); cpstr[len-1] = '\r'; cpstr[len] = '\n'; int count = write(uart0_filestream, cpstr, len+1); if (count < 0) { //TODO: handle errors... } free(cpstr); } } // Read a line from UART. // Return a 0 len string in case of problems with UART void serial_readln(char *buffer, int len) { char c; char *b = buffer; int rx_length = -1; while(1) { rx_length = read(uart0_filestream, (void*)(&c), 1); if (rx_length <= 0) { //wait for messages sleep(1); } else { if (c == '\n') { *b++ = '\0'; break; } *b++ = c; } } } void serial_close(void) { close(uart0_filestream); }
1,645
C
.c
67
18.985075
68
0.565857
mgrennan/oswabox
10
0
1
LGPL-2.1
9/7/2024, 10:52:19 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
4,942,947
timer.c
mryndzionek_sdr_rec/src/timer.c
/* * Copyright (c) 2011 Joseph Gaeddert * Copyright (c) 2011 Virginia Polytechnic Institute & State University * * This file is part of liquid. * * liquid is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * liquid is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with liquid. If not, see <http://www.gnu.org/licenses/>. */ // // timer // #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <sys/time.h> #include "timer.h" // tiemr data structure struct timer_s { struct timeval tic; struct timeval toc; int timer_started; }; // create timer object timer timer_create() { timer q = (timer) malloc(sizeof(struct timer_s)); q->timer_started = 0; return q; } // destroy timer object void timer_destroy(timer _q) { // free main object memory free(_q); } // reset timer void timer_tic(timer _q) { int rc = gettimeofday(&_q->tic, NULL); if (rc != 0) { fprintf(stderr,"warning: timer_tic(), gettimeofday() returned invalid flag\n"); } _q->timer_started = 1; } // get elapsed time since 'tic' in seconds float timer_toc(timer _q) { if (!_q->timer_started) { fprintf(stderr,"warning: timer_toc(), timer was never started\n"); return 0; } int rc = gettimeofday(&_q->toc, NULL); if (rc != 0) { fprintf(stderr,"warning: timer_toc(), gettimeofday() returned invalid flag\n"); } // compute execution time (in seconds) float s = (float)(_q->toc.tv_sec - _q->tic.tv_sec); float us = (float)(_q->toc.tv_usec - _q->tic.tv_usec); return s + us*1e-6f; }
1,954
C
.c
71
25.661972
81
0.711075
mryndzionek/sdr_rec
15
6
0
GPL-3.0
9/7/2024, 10:52:37 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
4,949,318
test.c
christianhujer_sclog4c/test/test.c
/* Copyright (C) 2014 Christian Hujer. * All rights reserved. * Licensed under LGPLv3. * See file LICENSE in the root directory of this project. */ #include "sclog4c/sclog4c.h" int main(void) { const char *functionName = __func__; sclog4c_level = SL4C_INFO; logm(SL4C_ERROR, "buh (expected)!"); logm(SL4C_DEBUG, "debug (unexpected)!"); logm(SL4C_INFO, "This is %s in function %s (expected).", "foo", functionName); return 0; }
459
C
.c
15
27.466667
82
0.679545
christianhujer/sclog4c
19
3
1
LGPL-3.0
9/7/2024, 10:52:54 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
5,142,095
event.c
zoff99_zanavi/navit/support/espeak/event.c
/*************************************************************************** * Copyright (C) 2007, Gilles Casse <[email protected]> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "speech.h" #ifdef USE_ASYNC // This source file is only used for asynchronious modes //<includes #include <unistd.h> #include <assert.h> #include <string.h> #include <stdlib.h> #include <pthread.h> #include <semaphore.h> #include <sys/time.h> #include <errno.h> #include "speak_lib.h" #include "event.h" #include "wave.h" #include "debug.h" //> //<decls and function prototypes // my_mutex: protects my_thread_is_talking, static pthread_mutex_t my_mutex; static sem_t my_sem_start_is_required; static sem_t my_sem_stop_is_required; static sem_t my_sem_stop_is_acknowledged; // my_thread: polls the audio duration and compares it to the duration of the first event. static pthread_t my_thread; static t_espeak_callback* my_callback = NULL; static int my_event_is_running=0; enum {MIN_TIMEOUT_IN_MS=10, ACTIVITY_TIMEOUT=50, // in ms, check that the stream is active MAX_ACTIVITY_CHECK=6 }; typedef struct t_node { void* data; t_node *next; } node; static node* head=NULL; static node* tail=NULL; static int node_counter=0; static espeak_ERROR push(void* data); static void* pop(); static void init(); static void* polling_thread(void*); //> //<event_init void event_set_callback(t_espeak_callback* SynthCallback) { my_callback = SynthCallback; } void event_init(void) { ENTER("event_init"); my_event_is_running=0; // security pthread_mutex_init( &my_mutex, (const pthread_mutexattr_t *)NULL); init(); assert(-1 != sem_init(&my_sem_start_is_required, 0, 0)); assert(-1 != sem_init(&my_sem_stop_is_required, 0, 0)); assert(-1 != sem_init(&my_sem_stop_is_acknowledged, 0, 0)); pthread_attr_t a_attrib; if (pthread_attr_init (& a_attrib) || pthread_attr_setdetachstate(&a_attrib, PTHREAD_CREATE_JOINABLE) || pthread_create( &my_thread, & a_attrib, polling_thread, (void*)NULL)) { assert(0); } pthread_attr_destroy(&a_attrib); } //> //<event_display static void event_display(espeak_EVENT* event) { ENTER("event_display"); #ifdef DEBUG_ENABLED if (event==NULL) { SHOW("event_display > event=%s\n","NULL"); } else { static const char* label[] = { "LIST_TERMINATED", "WORD", "SENTENCE", "MARK", "PLAY", "END", "MSG_TERMINATED" }; SHOW("event_display > event=0x%x\n",event); SHOW("event_display > type=%s\n",label[event->type]); SHOW("event_display > uid=%d\n",event->unique_identifier); SHOW("event_display > text_position=%d\n",event->text_position); SHOW("event_display > length=%d\n",event->length); SHOW("event_display > audio_position=%d\n",event->audio_position); SHOW("event_display > sample=%d\n",event->sample); SHOW("event_display > user_data=0x%x\n",event->user_data); } #endif } //> //<event_copy static espeak_EVENT* event_copy (espeak_EVENT* event) { ENTER("event_copy"); if (event==NULL) { return NULL; } espeak_EVENT* a_event=(espeak_EVENT*)malloc(sizeof(espeak_EVENT)); if (a_event) { memcpy(a_event, event, sizeof(espeak_EVENT)); switch(event->type) { case espeakEVENT_MARK: case espeakEVENT_PLAY: if (event->id.name) { a_event->id.name = strdup(event->id.name); } break; default: break; } } event_display(a_event); return a_event; } //> //<event_notify // Call the user supplied callback // // Note: the current sequence is: // // * First call with: event->type = espeakEVENT_SENTENCE // * 0, 1 or several calls: event->type = espeakEVENT_WORD // * Last call: event->type = espeakEVENT_MSG_TERMINATED // static void event_notify(espeak_EVENT* event) { ENTER("event_notify"); static unsigned int a_old_uid = 0; espeak_EVENT events[2]; memcpy(&events[0],event,sizeof(espeak_EVENT)); // the event parameter in the callback function should be an array of eventd memcpy(&events[1],event,sizeof(espeak_EVENT)); events[1].type = espeakEVENT_LIST_TERMINATED; // ... terminated by an event type=0 if (event && my_callback) { event_display(event); switch(event->type) { case espeakEVENT_SENTENCE: my_callback(NULL, 0, events); a_old_uid = event->unique_identifier; break; case espeakEVENT_MSG_TERMINATED: case espeakEVENT_MARK: case espeakEVENT_WORD: case espeakEVENT_END: case espeakEVENT_PHONEME: { // jonsd - I'm not sure what this is for. gilles says it's for when Gnome Speech reads a file of blank lines if (a_old_uid != event->unique_identifier) { espeak_EVENT_TYPE a_new_type = events[0].type; events[0].type = espeakEVENT_SENTENCE; my_callback(NULL, 0, events); events[0].type = a_new_type; usleep(50000); } my_callback(NULL, 0, events); a_old_uid = event->unique_identifier; } break; default: case espeakEVENT_LIST_TERMINATED: case espeakEVENT_PLAY: break; } } } //> //<event_delete static int event_delete(espeak_EVENT* event) { ENTER("event_delete"); event_display(event); if(event==NULL) { return 0; } switch(event->type) { case espeakEVENT_MSG_TERMINATED: event_notify(event); break; case espeakEVENT_MARK: case espeakEVENT_PLAY: if(event->id.name) { free((void*)(event->id.name)); } break; default: break; } free(event); return 1; } //> //<event_declare espeak_ERROR event_declare (espeak_EVENT* event) { ENTER("event_declare"); event_display(event); if (!event) { return EE_INTERNAL_ERROR; } int a_status = pthread_mutex_lock(&my_mutex); espeak_ERROR a_error = EE_OK; if (!a_status) { SHOW_TIME("event_declare > locked\n"); espeak_EVENT* a_event = event_copy(event); a_error = push(a_event); if (a_error != EE_OK) { event_delete(a_event); } SHOW_TIME("event_declare > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); } // TBD: remove the comment // reminder: code in comment. // This wait can lead to an underrun // // if (!a_status && !my_event_is_running && (a_error == EE_OK)) // { // // quit when command is actually started // // (for possible forthcoming 'end of command' checks) SHOW_TIME("event_declare > post my_sem_start_is_required\n"); sem_post(&my_sem_start_is_required); // int val=1; // while (val) // { // usleep(50000); // TBD: event? // sem_getvalue(&my_sem_start_is_required, &val); // } // } if (a_status != 0) { a_error = EE_INTERNAL_ERROR; } return a_error; } //> //<event_clear_all espeak_ERROR event_clear_all () { ENTER("event_clear_all"); int a_status = pthread_mutex_lock(&my_mutex); int a_event_is_running = 0; SHOW_TIME("event_stop > locked\n"); if (a_status != 0) { return EE_INTERNAL_ERROR; } if (my_event_is_running) { SHOW_TIME("event_stop > post my_sem_stop_is_required\n"); sem_post(&my_sem_stop_is_required); a_event_is_running = 1; } else { init(); // clear pending events } SHOW_TIME("event_stop > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); if (a_status != 0) { return EE_INTERNAL_ERROR; } if (a_event_is_running) { SHOW_TIME("event_stop > wait for my_sem_stop_is_acknowledged\n"); while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } SHOW_TIME("event_stop > get my_sem_stop_is_acknowledged\n"); } SHOW_TIME("LEAVE event_stop\n"); return EE_OK; } //> //<sleep_until_timeout_or_stop_request static int sleep_until_timeout_or_stop_request(uint32_t time_in_ms) { ENTER("sleep_until_timeout_or_stop_request"); int a_stop_is_required=0; struct timespec ts, to; struct timeval tv; int err=0; clock_gettime2( &ts); to.tv_sec = ts.tv_sec; to.tv_nsec = ts.tv_nsec; add_time_in_ms( &ts, time_in_ms); SHOW("polling_thread > sleep_until_timeout_or_stop_request > start sem_timedwait from %d.%09lu to %d.%09lu \n", to.tv_sec, to.tv_nsec, ts.tv_sec, ts.tv_nsec); while ((err = sem_timedwait(&my_sem_stop_is_required, &ts)) == -1 && errno == EINTR) { continue; // Restart when interrupted by handler } assert (gettimeofday(&tv, NULL) != -1); SHOW("polling_thread > sleep_until_timeout_or_stop_request > stop sem_timedwait %d.%09lu \n", tv.tv_sec, tv.tv_usec*1000); if (err == 0) { SHOW("polling_thread > sleep_until_timeout_or_stop_request > %s\n","stop required!"); a_stop_is_required=1; // stop required } return a_stop_is_required; } //> //<get_remaining_time // Asked for the time interval required for reaching the sample. // If the stream is opened but the audio samples are not played, // a timeout is started. static int get_remaining_time(uint32_t sample, uint32_t* time_in_ms, int* stop_is_required) { ENTER("get_remaining_time"); int err = 0; *stop_is_required = 0; int i=0; for (i=0; i < MAX_ACTIVITY_CHECK && (*stop_is_required == 0); i++) { err = wave_get_remaining_time( sample, time_in_ms); if (err || wave_is_busy(NULL) || (*time_in_ms == 0)) { // if err, stream not available: quit // if wave is busy, time_in_ms is known: quit // if wave is not busy but remaining time == 0, event is reached: quit break; } // stream opened but not active // // Several possible states: // * the stream is opened but not yet started: // // wait for the start of stream // // * some samples have already been played, // ** the end of stream is reached // ** or there is an underrun // // wait for the close of stream *stop_is_required = sleep_until_timeout_or_stop_request( ACTIVITY_TIMEOUT); } return err; } //> //<polling_thread static void* polling_thread(void*) { ENTER("polling_thread"); while(1) { int a_stop_is_required=0; SHOW_TIME("polling_thread > locking\n"); int a_status = pthread_mutex_lock(&my_mutex); SHOW_TIME("polling_thread > locked (my_event_is_running = 0)\n"); my_event_is_running = 0; pthread_mutex_unlock(&my_mutex); SHOW_TIME("polling_thread > unlocked\n"); SHOW_TIME("polling_thread > wait for my_sem_start_is_required\n"); while ((sem_wait(&my_sem_start_is_required) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } SHOW_TIME("polling_thread > get my_sem_start_is_required\n"); a_status = pthread_mutex_lock(&my_mutex); SHOW_TIME("polling_thread > locked (my_event_is_running = 1)\n"); my_event_is_running = 1; pthread_mutex_unlock(&my_mutex); SHOW_TIME("polling_thread > unlocked\n"); a_stop_is_required=0; a_status = sem_getvalue(&my_sem_stop_is_required, &a_stop_is_required); if ((a_status==0) && a_stop_is_required) { SHOW("polling_thread > stop required (%d)\n", __LINE__); while(0 == sem_trywait(&my_sem_stop_is_required)) { }; } else { a_stop_is_required=0; } // In this loop, my_event_is_running = 1 while (head && !a_stop_is_required) { SHOW_TIME("polling_thread > check head\n"); while(0 == sem_trywait(&my_sem_start_is_required)) { }; espeak_EVENT* event = (espeak_EVENT*)(head->data); assert(event); uint32_t time_in_ms = 0; int err = get_remaining_time((uint32_t)event->sample, &time_in_ms, &a_stop_is_required); if (a_stop_is_required) { break; } else if (err != 0) { // No available time: the event is deleted. SHOW("polling_thread > %s\n","audio device down"); a_status = pthread_mutex_lock(&my_mutex); SHOW_TIME("polling_thread > locked\n"); event_delete( (espeak_EVENT*)pop()); a_status = pthread_mutex_unlock(&my_mutex); SHOW_TIME("polling_thread > unlocked\n"); } else if (time_in_ms==0) { // the event is already reached. if (my_callback) { event_notify(event); // the user_data (and the type) are cleaned to be sure // that MSG_TERMINATED is called twice (at delete time too). event->type=espeakEVENT_LIST_TERMINATED; event->user_data=NULL; } a_status = pthread_mutex_lock(&my_mutex); SHOW_TIME("polling_thread > locked\n"); event_delete( (espeak_EVENT*)pop()); a_status = pthread_mutex_unlock(&my_mutex); SHOW_TIME("polling_thread > unlocked\n"); a_stop_is_required=0; a_status = sem_getvalue(&my_sem_stop_is_required, &a_stop_is_required); if ((a_status==0) && a_stop_is_required) { SHOW("polling_thread > stop required (%d)\n", __LINE__); while(0 == sem_trywait(&my_sem_stop_is_required)) { }; } else { a_stop_is_required=0; } } else { // The event will be notified soon: sleep until timeout or stop request a_stop_is_required = sleep_until_timeout_or_stop_request(time_in_ms); } } a_status = pthread_mutex_lock(&my_mutex); SHOW_TIME("polling_thread > locked\n"); SHOW_TIME("polling_thread > my_event_is_running = 0\n"); my_event_is_running = 0; if(!a_stop_is_required) { a_status = sem_getvalue(&my_sem_stop_is_required, &a_stop_is_required); if ((a_status==0) && a_stop_is_required) { SHOW("polling_thread > stop required (%d)\n", __LINE__); while(0 == sem_trywait(&my_sem_stop_is_required)) { }; } else { a_stop_is_required=0; } } a_status = pthread_mutex_unlock(&my_mutex); SHOW_TIME("polling_thread > unlocked\n"); if (a_stop_is_required) { SHOW("polling_thread > %s\n","stop required!"); // no mutex required since the stop command is synchronous // and waiting for my_sem_stop_is_acknowledged init(); // acknowledge the stop request SHOW_TIME("polling_thread > post my_sem_stop_is_acknowledged\n"); a_status = sem_post(&my_sem_stop_is_acknowledged); } } return NULL; } //> //<push, pop, init enum {MAX_NODE_COUNTER=1000}; // return 1 if ok, 0 otherwise static espeak_ERROR push(void* the_data) { ENTER("event > push"); assert((!head && !tail) || (head && tail)); if (the_data == NULL) { SHOW("event > push > event=0x%x\n", NULL); return EE_INTERNAL_ERROR; } if (node_counter >= MAX_NODE_COUNTER) { SHOW("event > push > %s\n", "EE_BUFFER_FULL"); return EE_BUFFER_FULL; } node *n = (node *)malloc(sizeof(node)); if (n == NULL) { return EE_INTERNAL_ERROR; } if (head == NULL) { head = n; tail = n; } else { tail->next = n; tail = n; } tail->next = NULL; tail->data = the_data; node_counter++; SHOW("event > push > counter=%d (uid=%d)\n",node_counter,((espeak_EVENT*)the_data)->unique_identifier); return EE_OK; } static void* pop() { ENTER("event > pop"); void* the_data = NULL; assert((!head && !tail) || (head && tail)); if (head != NULL) { node* n = head; the_data = n->data; head = n->next; free(n); node_counter--; SHOW("event > pop > event=0x%x (counter=%d, uid=%d)\n",the_data, node_counter,((espeak_EVENT*)the_data)->unique_identifier); } if(head == NULL) { tail = NULL; } return the_data; } static void init() { ENTER("event > init"); while (event_delete( (espeak_EVENT*)pop() )) {} node_counter = 0; } //> //<event_terminate void event_terminate() { ENTER("event_terminate"); if (my_thread) { pthread_cancel(my_thread); pthread_join(my_thread,NULL); pthread_mutex_destroy(&my_mutex); sem_destroy(&my_sem_start_is_required); sem_destroy(&my_sem_stop_is_required); sem_destroy(&my_sem_stop_is_acknowledged); init(); // purge event } } #endif //>
16,757
C
.c
602
24.835548
128
0.64217
zoff99/zanavi
13
4
19
GPL-2.0
9/7/2024, 10:54:05 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
5,142,099
wave.c
zoff99_zanavi/navit/support/espeak/wave.c
/*************************************************************************** * Copyright (C) 2007, Gilles Casse <[email protected]> * * based on AudioIO.cc (Audacity-1.2.4b) and wavegen.cpp * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "speech.h" #ifdef USE_ASYNC // This source file is only used for asynchronious modes #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <sys/time.h> #include <time.h> #include "portaudio.h" #ifndef PLATFORM_WINDOWS #include <unistd.h> #endif #include "wave.h" #include "debug.h" //<Definitions enum {ONE_BILLION=1000000000}; #ifdef USE_PORTAUDIO #undef USE_PORTAUDIO // determine portaudio version by looking for a #define which is not in V18 #ifdef paNeverDropInput #define USE_PORTAUDIO 19 #else #define USE_PORTAUDIO 18 #endif static t_wave_callback* my_callback_is_output_enabled=NULL; #define N_WAV_BUF 10 #define SAMPLE_RATE 22050 #define FRAMES_PER_BUFFER 512 #define BUFFER_LENGTH (SAMPLE_RATE*2*sizeof(uint16_t)) #define THRESHOLD (BUFFER_LENGTH/5) static char myBuffer[BUFFER_LENGTH]; static char* myRead=NULL; static char* myWrite=NULL; static int out_channels=1; static int my_stream_could_start=0; static int mInCallbackFinishedState = false; #if (USE_PORTAUDIO == 18) static PortAudioStream *pa_stream=NULL; #endif #if (USE_PORTAUDIO == 19) static struct PaStreamParameters myOutputParameters; static PaStream *pa_stream=NULL; #endif static int userdata[4]; static PaError pa_init_err=0; // time measurement // The read and write position audio stream in the audio stream are measured in ms. // // * When the stream is opened, myReadPosition and myWritePosition are cleared. // * myWritePosition is updated in wave_write. // * myReadPosition is updated in pa_callback (+ sample delay). static uint32_t myReadPosition = 0; // in ms static uint32_t myWritePosition = 0; //> //<init_buffer, get_used_mem static void init_buffer() { myWrite = myBuffer; myRead = myBuffer; memset(myBuffer,0,BUFFER_LENGTH); myReadPosition = myWritePosition = 0; SHOW("init_buffer > myRead=0x%x, myWrite=0x%x, BUFFER_LENGTH=0x%x, myReadPosition = myWritePosition = 0\n", (int)myRead, (int)myWrite, BUFFER_LENGTH); } static unsigned int get_used_mem() { char* aRead = myRead; char* aWrite = myWrite; unsigned int used = 0; assert ((aRead >= myBuffer) && (aRead <= myBuffer + BUFFER_LENGTH) && (aWrite >= myBuffer) && (aWrite <= myBuffer + BUFFER_LENGTH)); if (aRead < aWrite) { used = aWrite - aRead; } else { used = aWrite + BUFFER_LENGTH - aRead; } SHOW("get_used_mem > %d\n", used); return used; } //> //<start stream static void start_stream() { PaError err; SHOW_TIME("start_stream"); my_stream_could_start=0; mInCallbackFinishedState = false; err = Pa_StartStream(pa_stream); SHOW("start_stream > Pa_StartStream=%d (%s)\n", err, Pa_GetErrorText(err)); #if USE_PORTAUDIO == 19 if(err == paStreamIsNotStopped) { SHOW_TIME("start_stream > restart stream (begin)"); // not sure why we need this, but PA v19 seems to need it err = Pa_StopStream(pa_stream); SHOW("start_stream > Pa_StopStream=%d (%s)\n", err, Pa_GetErrorText(err)); err = Pa_StartStream(pa_stream); SHOW("start_stream > Pa_StartStream=%d (%s)\n", err, Pa_GetErrorText(err)); SHOW_TIME("start_stream > restart stream (end)"); } #endif } //> //<pa_callback /* This routine will be called by the PortAudio engine when audio is needed. ** It may called at interrupt level on some machines so don't do anything ** that could mess up the system like calling malloc() or free(). */ #if USE_PORTAUDIO == 18 static int pa_callback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTimestamp outTime, void *userData ) #else static int pa_callback(const void *inputBuffer, void *outputBuffer, long unsigned int framesPerBuffer, const PaStreamCallbackTimeInfo *outTime, PaStreamCallbackFlags flags, void *userData ) #endif { int aResult=0; // paContinue char* aWrite = myWrite; size_t n = out_channels*sizeof(uint16_t)*framesPerBuffer; myReadPosition += framesPerBuffer; SHOW("pa_callback > myReadPosition=%u, framesPerBuffer=%lu (n=0x%x) \n",(int)myReadPosition, framesPerBuffer, n); if (aWrite >= myRead) { if((size_t)(aWrite - myRead) >= n) { memcpy(outputBuffer, myRead, n); myRead += n; } else { SHOW_TIME("pa_callback > underflow"); aResult=1; // paComplete; mInCallbackFinishedState = true; size_t aUsedMem=0; aUsedMem = (size_t)(aWrite - myRead); if (aUsedMem) { memcpy(outputBuffer, myRead, aUsedMem); } char* p = (char*)outputBuffer + aUsedMem; memset(p, 0, n - aUsedMem); // myReadPosition += aUsedMem/(out_channels*sizeof(uint16_t)); myRead = aWrite; } } else // myRead > aWrite { if ((size_t)(myBuffer + BUFFER_LENGTH - myRead) >= n) { memcpy(outputBuffer, myRead, n); myRead += n; } else if ((size_t)(aWrite + BUFFER_LENGTH - myRead) >= n) { int aTopMem = myBuffer + BUFFER_LENGTH - myRead; if (aTopMem) { SHOW("pa_callback > myRead=0x%x, aTopMem=0x%x\n",(int)myRead, (int)aTopMem); memcpy(outputBuffer, myRead, aTopMem); } int aRest = n - aTopMem; if (aRest) { SHOW("pa_callback > myRead=0x%x, aRest=0x%x\n",(int)myRead, (int)aRest); char* p = (char*)outputBuffer + aTopMem; memcpy(p, myBuffer, aRest); } myRead = myBuffer + aRest; } else { SHOW_TIME("pa_callback > underflow"); aResult=1; // paComplete; int aTopMem = myBuffer + BUFFER_LENGTH - myRead; if (aTopMem) { SHOW("pa_callback > myRead=0x%x, aTopMem=0x%x\n",(int)myRead, (int)aTopMem); memcpy(outputBuffer, myRead, aTopMem); } int aRest = aWrite - myBuffer; if (aRest) { SHOW("pa_callback > myRead=0x%x, aRest=0x%x\n",(int)myRead, (int)aRest); char* p = (char*)outputBuffer + aTopMem; memcpy(p, myBuffer, aRest); } size_t aUsedMem = aTopMem + aRest; char* p = (char*)outputBuffer + aUsedMem; memset(p, 0, n - aUsedMem); // myReadPosition += aUsedMem/(out_channels*sizeof(uint16_t)); myRead = aWrite; } } SHOW("pa_callback > myRead=%x\n",(int)myRead); // #if USE_PORTAUDIO == 18 // if(aBufferEmpty) // { // static int end_timer = 0; // if(end_timer == 0) // end_timer = 4; // if(end_timer > 0) // { // end_timer--; // if(end_timer == 0) // return(1); // } // } // return(0); // #else #ifdef ARCH_BIG { // BIG-ENDIAN, swap the order of bytes in each sound sample in the portaudio buffer int c; unsigned char *out_ptr; unsigned char *out_end; out_ptr = (unsigned char *)outputBuffer; out_end = out_ptr + framesPerBuffer*2 * out_channels; while(out_ptr < out_end) { c = out_ptr[0]; out_ptr[0] = out_ptr[1]; out_ptr[1] = c; out_ptr += 2; } } #endif return(aResult); //#endif } // end of WaveCallBack //> void wave_flush(void* theHandler) { ENTER("wave_flush"); if (my_stream_could_start) { // #define buf 1024 // static char a_buffer[buf*2]; // memset(a_buffer,0,buf*2); // wave_write(theHandler, a_buffer, buf*2); start_stream(); } } //<wave_open_sound static int wave_open_sound() { ENTER("wave_open_sound"); PaError err=paNoError; PaError active; #if USE_PORTAUDIO == 18 active = Pa_StreamActive(pa_stream); #else active = Pa_IsStreamActive(pa_stream); #endif if(active == 1) { SHOW_TIME("wave_open_sound > already active"); return(0); } if(active < 0) { out_channels = 1; #if USE_PORTAUDIO == 18 // err = Pa_OpenDefaultStream(&pa_stream,0,1,paInt16,SAMPLE_RATE,FRAMES_PER_BUFFER,N_WAV_BUF,pa_callback,(void *)userdata); PaDeviceID playbackDevice = Pa_GetDefaultOutputDeviceID(); PaError err = Pa_OpenStream( &pa_stream, /* capture parameters */ paNoDevice, 0, paInt16, NULL, /* playback parameters */ playbackDevice, out_channels, paInt16, NULL, /* general parameters */ SAMPLE_RATE, FRAMES_PER_BUFFER, 0, //paClipOff | paDitherOff, paNoFlag, pa_callback, (void *)userdata); SHOW("wave_open_sound > Pa_OpenDefaultStream(1): err=%d (%s)\n",err, Pa_GetErrorText(err)); if(err == paInvalidChannelCount) { SHOW_TIME("wave_open_sound > try stereo"); // failed to open with mono, try stereo out_channels = 2; // myOutputParameters.channelCount = out_channels; PaError err = Pa_OpenStream( &pa_stream, /* capture parameters */ paNoDevice, 0, paInt16, NULL, /* playback parameters */ playbackDevice, out_channels, paInt16, NULL, /* general parameters */ SAMPLE_RATE, FRAMES_PER_BUFFER, 0, //paClipOff | paDitherOff, paNoFlag, pa_callback, (void *)userdata); // err = Pa_OpenDefaultStream(&pa_stream,0,2,paInt16, // SAMPLE_RATE, // FRAMES_PER_BUFFER, // N_WAV_BUF,pa_callback,(void *)userdata); SHOW("wave_open_sound > Pa_OpenDefaultStream(2): err=%d (%s)\n",err, Pa_GetErrorText(err)); err=0; // avoid warning } mInCallbackFinishedState = false; // v18 only #else myOutputParameters.channelCount = out_channels; unsigned long framesPerBuffer = paFramesPerBufferUnspecified; err = Pa_OpenStream( &pa_stream, NULL, /* no input */ &myOutputParameters, SAMPLE_RATE, framesPerBuffer, paNoFlag, // paClipOff | paDitherOff, pa_callback, (void *)userdata); if ((err!=paNoError) && (err!=paInvalidChannelCount)) //err==paUnanticipatedHostError { fprintf(stderr, "wave_open_sound > Pa_OpenStream : err=%d (%s)\n",err,Pa_GetErrorText(err)); framesPerBuffer = FRAMES_PER_BUFFER; err = Pa_OpenStream( &pa_stream, NULL, /* no input */ &myOutputParameters, SAMPLE_RATE, framesPerBuffer, paNoFlag, // paClipOff | paDitherOff, pa_callback, (void *)userdata); } if(err == paInvalidChannelCount) { SHOW_TIME("wave_open_sound > try stereo"); // failed to open with mono, try stereo out_channels = 2; myOutputParameters.channelCount = out_channels; err = Pa_OpenStream( &pa_stream, NULL, /* no input */ &myOutputParameters, SAMPLE_RATE, framesPerBuffer, paNoFlag, // paClipOff | paDitherOff, pa_callback, (void *)userdata); // err = Pa_OpenDefaultStream(&pa_stream,0,2,paInt16,(double)SAMPLE_RATE,FRAMES_PER_BUFFER,pa_callback,(void *)userdata); } mInCallbackFinishedState = false; #endif } SHOW("wave_open_sound > %s\n","LEAVE"); return (err != paNoError); } //> //<select_device #if (USE_PORTAUDIO == 19) static void update_output_parameters(int selectedDevice, const PaDeviceInfo *deviceInfo) { // const PaDeviceInfo *pdi = Pa_GetDeviceInfo(i); myOutputParameters.device = selectedDevice; // myOutputParameters.channelCount = pdi->maxOutputChannels; myOutputParameters.channelCount = 1; myOutputParameters.sampleFormat = paInt16; // Latency greater than 100ms for avoiding glitches // (e.g. when moving a window in a graphical desktop) // deviceInfo = Pa_GetDeviceInfo(selectedDevice); if (deviceInfo) { double aLatency = deviceInfo->defaultLowOutputLatency; double aCoeff = round(0.100 / aLatency); // myOutputParameters.suggestedLatency = aCoeff * aLatency; // to avoid glitches ? myOutputParameters.suggestedLatency = aLatency; // for faster response ? SHOW("Device=%d, myOutputParameters.suggestedLatency=%f, aCoeff=%f\n", selectedDevice, myOutputParameters.suggestedLatency, aCoeff); } else { myOutputParameters.suggestedLatency = (double)0.1; // 100ms SHOW("Device=%d, myOutputParameters.suggestedLatency=%f (default)\n", selectedDevice, myOutputParameters.suggestedLatency); } //pdi->defaultLowOutputLatency; myOutputParameters.hostApiSpecificStreamInfo = NULL; } #endif static void select_device(const char* the_api) { ENTER("select_device"); #if (USE_PORTAUDIO == 19) int numDevices = Pa_GetDeviceCount(); if( numDevices < 0 ) { SHOW( "ERROR: Pa_CountDevices returned 0x%x\n", numDevices ); assert(0); } PaDeviceIndex i=0, selectedIndex=0, defaultAlsaIndex=numDevices; const PaDeviceInfo *deviceInfo=NULL; const PaDeviceInfo *selectedDeviceInfo=NULL; if(option_device_number >= 0) { selectedIndex = option_device_number; selectedDeviceInfo = Pa_GetDeviceInfo(selectedIndex); } if(selectedDeviceInfo == NULL) { for( i=0; i<numDevices; i++ ) { deviceInfo = Pa_GetDeviceInfo( i ); if (deviceInfo == NULL) { break; } const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); if (hostInfo && hostInfo->type == paALSA) { // Check (once) the default output device if (defaultAlsaIndex == numDevices) { defaultAlsaIndex = hostInfo->defaultOutputDevice; const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo( defaultAlsaIndex ); update_output_parameters(defaultAlsaIndex, deviceInfo); if (Pa_IsFormatSupported(NULL, &myOutputParameters, SAMPLE_RATE) == 0) { SHOW( "select_device > ALSA (default), name=%s (#%d)\n", deviceInfo->name, defaultAlsaIndex); selectedIndex = defaultAlsaIndex; selectedDeviceInfo = deviceInfo; break; } } // if the default output device does not match, // look for the device with the highest number of output channels SHOW( "select_device > ALSA, i=%d (numDevices=%d)\n", i, numDevices); update_output_parameters(i, deviceInfo); if (Pa_IsFormatSupported(NULL, &myOutputParameters, SAMPLE_RATE) == 0) { SHOW( "select_device > ALSA, name=%s (#%d)\n", deviceInfo->name, i); if (!selectedDeviceInfo || (selectedDeviceInfo->maxOutputChannels < deviceInfo->maxOutputChannels)) { selectedIndex = i; selectedDeviceInfo = deviceInfo; } } } } } if (selectedDeviceInfo) { update_output_parameters(selectedIndex, selectedDeviceInfo); } else { i = Pa_GetDefaultOutputDevice(); deviceInfo = Pa_GetDeviceInfo( i ); update_output_parameters(i, deviceInfo); } #endif } //> // int wave_Close(void* theHandler) // { // SHOW_TIME("WaveCloseSound"); // // PaError active; // // check whether speaking has finished, and close the stream // if(pa_stream != NULL) // { // Pa_CloseStream(pa_stream); // pa_stream = NULL; // init_buffer(); // // #if USE_PORTAUDIO == 18 // // active = Pa_StreamActive(pa_stream); // // #else // // active = Pa_IsStreamActive(pa_stream); // // #endif // // if(active == 0) // // { // // SHOW_TIME("WaveCloseSound > ok, not active"); // // Pa_CloseStream(pa_stream); // // pa_stream = NULL; // // return(1); // // } // } // return(0); // } //<wave_set_callback_is_output_enabled void wave_set_callback_is_output_enabled(t_wave_callback* cb) { my_callback_is_output_enabled = cb; } //> //<wave_init // TBD: the arg could be "alsa", "oss",... void wave_init() { ENTER("wave_init"); PaError err; pa_stream = NULL; mInCallbackFinishedState = false; init_buffer(); // PortAudio sound output library err = Pa_Initialize(); pa_init_err = err; if(err != paNoError) { SHOW_TIME("wave_init > Failed to initialise the PortAudio sound"); } } //> //<wave_open void* wave_open(const char* the_api) { ENTER("wave_open"); static int once=0; // TBD: the_api (e.g. "alsa") is not used at the moment // select_device is called once if (!once) { select_device("alsa"); once=1; } return((void*)1); } //> //<copyBuffer static size_t copyBuffer(char* dest, char* src, const size_t theSizeInBytes) { size_t bytes_written = 0; unsigned int i = 0; uint16_t* a_dest = NULL; uint16_t* a_src = NULL; if ((src != NULL) && dest != NULL) { // copy for one channel (mono)? if(out_channels==1) { SHOW("copyBuffer > 1 channel > memcpy %x (%d bytes)\n", (int)myWrite, theSizeInBytes); memcpy(dest, src, theSizeInBytes); bytes_written = theSizeInBytes; } else // copy for 2 channels (stereo) { SHOW("copyBuffer > 2 channels > memcpy %x (%d bytes)\n", (int)myWrite, theSizeInBytes); i = 0; a_dest = (uint16_t* )dest; a_src = (uint16_t* )src; for(i=0; i<theSizeInBytes/2; i++) { a_dest[2*i] = a_src[i]; a_dest[2*i+1] = a_src[i]; } bytes_written = 2*theSizeInBytes; } // end if(out_channels==1) } // end if ((src != NULL) && dest != NULL) return bytes_written; } //> //<wave_write size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSize) { ENTER("wave_write"); size_t bytes_written = 0; // space in ringbuffer for the sample needed: 1x mono channel but 2x for 1 stereo channel size_t bytes_to_write = (out_channels==1) ? theSize : theSize*2; my_stream_could_start = 0; if(pa_stream == NULL) { SHOW_TIME("wave_write > wave_open_sound\n"); if (0 != wave_open_sound()) { SHOW_TIME("wave_write > wave_open_sound fails!"); return 0; } my_stream_could_start=1; } else if (!wave_is_busy(NULL)) { my_stream_could_start = 1; } assert(BUFFER_LENGTH >= bytes_to_write); if (myWrite >= myBuffer + BUFFER_LENGTH) { myWrite = myBuffer; } // end if (myWrite >= myBuffer + BUFFER_LENGTH) size_t aTotalFreeMem=0; char* aRead = myRead; SHOW("wave_write > aRead=%x, myWrite=%x\n", (int)aRead, (int)myWrite); while (1) { if (my_callback_is_output_enabled && (0==my_callback_is_output_enabled())) { SHOW_TIME("wave_write > my_callback_is_output_enabled: no!"); return 0; } aRead = myRead; // write pointer is before read pointer? if (myWrite >= aRead) { aTotalFreeMem = aRead + BUFFER_LENGTH - myWrite; } else // read pointer is before write pointer! { aTotalFreeMem = aRead - myWrite; } // end if (myWrite >= aRead) if (aTotalFreeMem>1) { // -1 because myWrite must be different of aRead // otherwise buffer would be considered as empty aTotalFreeMem -= 1; } // end if (aTotalFreeMem>1) if (aTotalFreeMem >= bytes_to_write) { break; } // end if (aTotalFreeMem >= bytes_to_write) //SHOW_TIME("wave_write > wait"); SHOW("wave_write > wait: aTotalFreeMem=%d\n", aTotalFreeMem); SHOW("wave_write > aRead=%x, myWrite=%x\n", (int)aRead, (int)myWrite); usleep(10000); } // end while (1) aRead = myRead; // write pointer is ahead the read pointer? if (myWrite >= aRead) { SHOW_TIME("wave_write > myWrite >= aRead"); // determine remaining free memory to the end of the ringbuffer size_t aFreeMem = myBuffer + BUFFER_LENGTH - myWrite; // is enough linear space available (regardless 1 or 2 channels)? if (aFreeMem >= bytes_to_write) { // copy direct - no wrap around at end of ringbuffer needed myWrite += copyBuffer(myWrite, theMono16BitsWaveBuffer, theSize); } else // not enough linear space available { // 2 channels (stereo)? if (out_channels == 2) { // copy with wrap around at the end of ringbuffer copyBuffer(myWrite, theMono16BitsWaveBuffer, aFreeMem/2); myWrite = myBuffer; myWrite += copyBuffer(myWrite, theMono16BitsWaveBuffer+aFreeMem/2, theSize - aFreeMem/2); } else // 1 channel (mono) { // copy with wrap around at the end of ringbuffer copyBuffer(myWrite, theMono16BitsWaveBuffer, aFreeMem); myWrite = myBuffer; myWrite += copyBuffer(myWrite, theMono16BitsWaveBuffer+aFreeMem, theSize - aFreeMem); } // end if (out_channels == 2) } // end if (aFreeMem >= bytes_to_write) } // if (myWrite >= aRead) else // read pointer is ahead the write pointer { SHOW_TIME("wave_write > myWrite <= aRead"); myWrite += copyBuffer(myWrite, theMono16BitsWaveBuffer, theSize); } // end if (myWrite >= aRead) bytes_written = bytes_to_write; myWritePosition += theSize/sizeof(uint16_t); // add number of samples if (my_stream_could_start && (get_used_mem() >= out_channels * sizeof(uint16_t) * FRAMES_PER_BUFFER)) { start_stream(); } // end if (my_stream_could_start && (get_used_mem() >= out_channels * sizeof(uint16_t) * FRAMES_PER_BUFFER)) SHOW_TIME("wave_write > LEAVE"); return bytes_written; } //> //<wave_close int wave_close(void* theHandler) { SHOW_TIME("wave_close > ENTER"); static int aStopStreamCount = 0; #if (USE_PORTAUDIO == 19) if( pa_stream == NULL ) { SHOW_TIME("wave_close > LEAVE (NULL stream)"); return 0; } if( Pa_IsStreamStopped( pa_stream ) ) { SHOW_TIME("wave_close > LEAVE (stopped)"); return 0; } #else if( pa_stream == NULL ) { SHOW_TIME("wave_close > LEAVE (NULL stream)"); return 0; } if( Pa_StreamActive( pa_stream ) == false && mInCallbackFinishedState == false ) { SHOW_TIME("wave_close > LEAVE (not active)"); return 0; } #endif // Avoid race condition by making sure this function only // gets called once at a time aStopStreamCount++; if (aStopStreamCount != 1) { SHOW_TIME("wave_close > LEAVE (stopStreamCount)"); return 0; } // Comment from Audacity-1.2.4b adapted to the eSpeak context. // // We got here in one of two ways: // // 1. The calling program calls the espeak_Cancel function and we // therefore want to stop as quickly as possible. // So we use AbortStream(). If this is // the case the portaudio stream is still in the Running state // (see PortAudio state machine docs). // // 2. The callback told PortAudio to stop the stream since it had // reached the end of the selection. // The event polling thread discovered this by noticing that // wave_is_busy() returned false. // wave_is_busy() (which calls Pa_GetStreamActive()) will not return // false until all buffers have finished playing, so we can call // AbortStream without losing any samples. If this is the case // we are in the "callback finished state" (see PortAudio state // machine docs). // // The moral of the story: We can call AbortStream safely, without // losing samples. // // DMM: This doesn't seem to be true; it seems to be necessary to // call StopStream if the callback brought us here, and AbortStream // if the user brought us here. // #if (USE_PORTAUDIO == 19) if (pa_stream) { Pa_AbortStream( pa_stream ); SHOW_TIME("wave_close > Pa_AbortStream (end)"); Pa_CloseStream( pa_stream ); SHOW_TIME("wave_close > Pa_CloseStream (end)"); pa_stream = NULL; mInCallbackFinishedState = false; } #else if (pa_stream) { if (mInCallbackFinishedState) { Pa_StopStream( pa_stream ); SHOW_TIME("wave_close > Pa_StopStream (end)"); } else { Pa_AbortStream( pa_stream ); SHOW_TIME("wave_close > Pa_AbortStream (end)"); } Pa_CloseStream( pa_stream ); SHOW_TIME("wave_close > Pa_CloseStream (end)"); pa_stream = NULL; mInCallbackFinishedState = false; } #endif init_buffer(); aStopStreamCount = 0; // last action SHOW_TIME("wave_close > LEAVE"); return 0; } // int wave_close(void* theHandler) // { // ENTER("wave_close"); // if(pa_stream != NULL) // { // PaError err = Pa_AbortStream(pa_stream); // SHOW_TIME("wave_close > Pa_AbortStream (end)"); // SHOW("wave_close Pa_AbortStream > err=%d\n",err); // while(1) // { // PaError active; // #if USE_PORTAUDIO == 18 // active = Pa_StreamActive(pa_stream); // #else // active = Pa_IsStreamActive(pa_stream); // #endif // if (active != 1) // { // break; // } // SHOW("wave_close > active=%d\n",err); // usleep(10000); /* sleep until playback has finished */ // } // err = Pa_CloseStream( pa_stream ); // SHOW_TIME("wave_close > Pa_CloseStream (end)"); // SHOW("wave_close Pa_CloseStream > err=%d\n",err); // pa_stream = NULL; // init_buffer(); // } // return 0; // } //> //<wave_is_busy int wave_is_busy(void* theHandler) { PaError active=0; SHOW_TIME("wave_is_busy"); if (pa_stream) { #if USE_PORTAUDIO == 18 active = Pa_StreamActive(pa_stream) && (mInCallbackFinishedState == false); #else active = Pa_IsStreamActive(pa_stream) && (mInCallbackFinishedState == false); #endif } SHOW("wave_is_busy: %d\n",active); return (active==1); } //> //<wave_terminate void wave_terminate() { ENTER("wave_terminate"); Pa_Terminate(); } //> //<wave_get_read_position, wave_get_write_position, wave_get_remaining_time uint32_t wave_get_read_position(void* theHandler) { SHOW("wave_get_read_position > myReadPosition=%u\n", myReadPosition); return myReadPosition; } uint32_t wave_get_write_position(void* theHandler) { SHOW("wave_get_write_position > myWritePosition=%u\n", myWritePosition); return myWritePosition; } int wave_get_remaining_time(uint32_t sample, uint32_t* time) { double a_time=0; if (!time || !pa_stream) { SHOW("event get_remaining_time> %s\n","audio device not available"); return -1; } if (sample > myReadPosition) { // TBD: take in account time suplied by portaudio V18 API a_time = sample - myReadPosition; a_time = 0.5 + (a_time * 1000.0) / SAMPLE_RATE; } else { a_time = 0; } SHOW("wave_get_remaining_time > sample=%d, time=%d\n", sample, (uint32_t)a_time); *time = (uint32_t)a_time; return 0; } //> //<wave_test_get_write_buffer void *wave_test_get_write_buffer() { return myWrite; } #else // notdef USE_PORTAUDIO void wave_init() {} void* wave_open(const char* the_api) {return (void *)1;} size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSize) {return theSize;} int wave_close(void* theHandler) {return 0;} int wave_is_busy(void* theHandler) {return 0;} void wave_terminate() {} uint32_t wave_get_read_position(void* theHandler) {return 0;} uint32_t wave_get_write_position(void* theHandler) {return 0;} void wave_flush(void* theHandler) {} typedef int (t_wave_callback)(void); void wave_set_callback_is_output_enabled(t_wave_callback* cb) {} extern void* wave_test_get_write_buffer() {return NULL;} int wave_get_remaining_time(uint32_t sample, uint32_t* time) { if (!time) return(-1); *time = (uint32_t)0; return 0; } #endif // of USE_PORTAUDIO //> //<clock_gettime2, add_time_in_ms void clock_gettime2(struct timespec *ts) { struct timeval tv; if (!ts) { return; } assert (gettimeofday(&tv, NULL) != -1); ts->tv_sec = tv.tv_sec; ts->tv_nsec = tv.tv_usec*1000; } void add_time_in_ms(struct timespec *ts, int time_in_ms) { if (!ts) { return; } uint64_t t_ns = (uint64_t)ts->tv_nsec + 1000000 * (uint64_t)time_in_ms; while(t_ns >= ONE_BILLION) { SHOW("event > add_time_in_ms ns: %d sec %Lu nsec \n", ts->tv_sec, t_ns); ts->tv_sec += 1; t_ns -= ONE_BILLION; } ts->tv_nsec = (long int)t_ns; } #endif // USE_ASYNC //>
28,900
C
.c
950
26.765263
152
0.644932
zoff99/zanavi
13
4
19
GPL-2.0
9/7/2024, 10:54:05 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
5,142,102
fifo.c
zoff99_zanavi/navit/support/espeak/fifo.c
/*************************************************************************** * Copyright (C) 2007, Gilles Casse <[email protected]> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "speech.h" #ifdef USE_ASYNC // This source file is only used for asynchronious modes //<includes #include <unistd.h> #include <assert.h> #include <string.h> #include <stdlib.h> #include <pthread.h> #include <semaphore.h> #include <wchar.h> #include <errno.h> #include <sys/time.h> #include <time.h> #include "fifo.h" #include "wave.h" #include "debug.h" //> //<decls and function prototypes // my_mutex: protects my_thread_is_talking, // my_stop_is_required, and the command fifo static pthread_mutex_t my_mutex; static int my_command_is_running = 0; static int my_stop_is_required = 0; // + fifo // // my_thread: reads commands from the fifo, and runs them. static pthread_t my_thread; static sem_t my_sem_start_is_required; static sem_t my_sem_stop_is_acknowledged; static void* say_thread(void*); static espeak_ERROR push(t_espeak_command* the_command); static t_espeak_command* pop(); static void init(); static int node_counter=0; enum {MAX_NODE_COUNTER=400, INACTIVITY_TIMEOUT=50, // in ms, check that the stream is inactive MAX_INACTIVITY_CHECK=2 }; //> //<fifo_init void fifo_init() { ENTER("fifo_init"); // security pthread_mutex_init( &my_mutex, (const pthread_mutexattr_t *)NULL); init(); assert(-1 != sem_init(&my_sem_start_is_required, 0, 0)); assert(-1 != sem_init(&my_sem_stop_is_acknowledged, 0, 0)); pthread_attr_t a_attrib; if (pthread_attr_init (& a_attrib) || pthread_attr_setdetachstate(&a_attrib, PTHREAD_CREATE_JOINABLE) || pthread_create( &my_thread, & a_attrib, say_thread, (void*)NULL)) { assert(0); } pthread_attr_destroy(&a_attrib); // leave once the thread is actually started SHOW_TIME("fifo > wait for my_sem_stop_is_acknowledged\n"); while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } SHOW_TIME("fifo > get my_sem_stop_is_acknowledged\n"); } //> //<fifo_add_command espeak_ERROR fifo_add_command (t_espeak_command* the_command) { ENTER("fifo_add_command"); int a_status = pthread_mutex_lock(&my_mutex); espeak_ERROR a_error = EE_OK; if (!a_status) { SHOW_TIME("fifo_add_command > locked\n"); a_error = push(the_command); SHOW_TIME("fifo_add_command > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); } if (!a_status && !my_command_is_running && (a_error == EE_OK)) { // quit when command is actually started // (for possible forthcoming 'end of command' checks) SHOW_TIME("fifo_add_command > post my_sem_start_is_required\n"); sem_post(&my_sem_start_is_required); int val=1; while (val) { usleep(50000); // TBD: event? sem_getvalue(&my_sem_start_is_required, &val); } } if (a_status != 0) { a_error = EE_INTERNAL_ERROR; } SHOW_TIME("LEAVE fifo_add_command"); return a_error; } //> //<fifo_add_commands espeak_ERROR fifo_add_commands (t_espeak_command* command1, t_espeak_command* command2) { ENTER("fifo_add_command"); int a_status = pthread_mutex_lock(&my_mutex); espeak_ERROR a_error = EE_OK; if (!a_status) { SHOW_TIME("fifo_add_commands > locked\n"); if (node_counter+1 >= MAX_NODE_COUNTER) { SHOW("push > %s\n", "EE_BUFFER_FULL"); a_error = EE_BUFFER_FULL; } else { push(command1); push(command2); } SHOW_TIME("fifo_add_command > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); } if (!a_status && !my_command_is_running && (a_error == EE_OK)) { // quit when one command is actually started // (for possible forthcoming 'end of command' checks) SHOW_TIME("fifo_add_command > post my_sem_start_is_required\n"); sem_post(&my_sem_start_is_required); int val=1; while (val) { usleep(50000); // TBD: event? sem_getvalue(&my_sem_start_is_required, &val); } } if (a_status != 0) { a_error = EE_INTERNAL_ERROR; } SHOW_TIME("LEAVE fifo_add_commands"); return a_error; } //> //<fifo_stop espeak_ERROR fifo_stop () { ENTER("fifo_stop"); int a_command_is_running = 0; int a_status = pthread_mutex_lock(&my_mutex); SHOW_TIME("fifo_stop > locked\n"); if (a_status != 0) { return EE_INTERNAL_ERROR; } if (my_command_is_running) { a_command_is_running = 1; my_stop_is_required = 1; SHOW_TIME("fifo_stop > my_stop_is_required = 1\n"); } SHOW_TIME("fifo_stop > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); if (a_status != 0) { return EE_INTERNAL_ERROR; } if (a_command_is_running) { SHOW_TIME("fifo_stop > wait for my_sem_stop_is_acknowledged\n"); while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } SHOW_TIME("fifo_stop > get my_sem_stop_is_acknowledged\n"); } SHOW_TIME("fifo_stop > my_stop_is_required = 0\n"); my_stop_is_required = 0; SHOW_TIME("LEAVE fifo_stop\n"); return EE_OK; } //> //<fifo_is_speaking int fifo_is_busy () { // ENTER("isSpeaking"); // int aResult = (int) (my_command_is_running || WaveIsPlaying()); SHOW("fifo_is_busy > aResult = %d\n",my_command_is_running); return my_command_is_running; } // int pause () // { // ENTER("pause"); // // TBD // // if (espeakPause (espeakHandle, 1)) // return true; // } // int resume () // { // ENTER("resume"); // // TBD // // if (espeakPause (espeakHandle, 0)) // return true; // } //> //<sleep_until_start_request_or_inactivity static int sleep_until_start_request_or_inactivity() { SHOW_TIME("fifo > sleep_until_start_request_or_inactivity > ENTER"); int a_start_is_required=0; // Wait for the start request (my_sem_start_is_required). // Besides this, if the audio stream is still busy, // check from time to time its end. // The end of the stream is confirmed by several checks // for filtering underflow. // int i=0; while((i<= MAX_INACTIVITY_CHECK) && !a_start_is_required) { if (wave_is_busy( NULL) ) { i = 0; } else { i++; } int err=0; struct timespec ts, to; struct timeval tv; clock_gettime2( &ts); to.tv_sec = ts.tv_sec; to.tv_nsec = ts.tv_nsec; add_time_in_ms( &ts, INACTIVITY_TIMEOUT); SHOW("fifo > sleep_until_start_request_or_inactivity > start sem_timedwait (start_is_required) from %d.%09lu to %d.%09lu \n", to.tv_sec, to.tv_nsec, ts.tv_sec, ts.tv_nsec); while ((err = sem_timedwait(&my_sem_start_is_required, &ts)) == -1 && errno == EINTR) { continue; } assert (gettimeofday(&tv, NULL) != -1); SHOW("fifo > sleep_until_start_request_or_inactivity > stop sem_timedwait (start_is_required, err=%d) %d.%09lu \n", err, tv.tv_sec, tv.tv_usec*1000); if (err==0) { a_start_is_required = 1; } } SHOW_TIME("fifo > sleep_until_start_request_or_inactivity > LEAVE"); return a_start_is_required; } //> //<close_stream static void close_stream() { SHOW_TIME("fifo > close_stream > ENTER\n"); // Warning: a wave_close can be already required by // an external command (espeak_Cancel + fifo_stop), if so: // my_stop_is_required = 1; int a_status = pthread_mutex_lock(&my_mutex); assert (!a_status); int a_stop_is_required = my_stop_is_required; if (!a_stop_is_required) { my_command_is_running = 1; } a_status = pthread_mutex_unlock(&my_mutex); if (!a_stop_is_required) { wave_close(NULL); int a_status = pthread_mutex_lock(&my_mutex); assert (!a_status); my_command_is_running = 0; a_stop_is_required = my_stop_is_required; a_status = pthread_mutex_unlock(&my_mutex); if (a_stop_is_required) { // acknowledge the stop request SHOW_TIME("fifo > close_stream > post my_sem_stop_is_acknowledged\n"); int a_status = sem_post(&my_sem_stop_is_acknowledged); assert( a_status != -1); } } SHOW_TIME("fifo > close_stream > LEAVE\n"); } //> //<say_thread static void* say_thread(void*) { ENTER("say_thread"); SHOW_TIME("say_thread > post my_sem_stop_is_acknowledged\n"); // announce that thread is started sem_post(&my_sem_stop_is_acknowledged); int look_for_inactivity=0; while(1) { SHOW_TIME("say_thread > wait for my_sem_start_is_required\n"); int a_start_is_required = 0; if (look_for_inactivity) { a_start_is_required = sleep_until_start_request_or_inactivity(); if (!a_start_is_required) { close_stream(); } } look_for_inactivity = 1; if (!a_start_is_required) { while ((sem_wait(&my_sem_start_is_required) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } } SHOW_TIME("say_thread > get my_sem_start_is_required\n"); SHOW_TIME("say_thread > my_command_is_running = 1\n"); my_command_is_running = 1; while( my_command_is_running) { SHOW_TIME("say_thread > locking\n"); int a_status = pthread_mutex_lock(&my_mutex); assert (!a_status); t_espeak_command* a_command = (t_espeak_command*)pop(); if (a_command == NULL) { SHOW_TIME("say_thread > text empty (talking=0) \n"); a_status = pthread_mutex_unlock(&my_mutex); SHOW_TIME("say_thread > unlocked\n"); SHOW_TIME("say_thread > my_command_is_running = 0\n"); my_command_is_running = 0; } else { display_espeak_command(a_command); // purge start semaphore SHOW_TIME("say_thread > purge my_sem_start_is_required\n"); while(0 == sem_trywait(&my_sem_start_is_required)) { }; if (my_stop_is_required) { SHOW_TIME("say_thread > my_command_is_running = 0\n"); my_command_is_running = 0; } SHOW_TIME("say_thread > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); if (my_command_is_running) { process_espeak_command(a_command); } delete_espeak_command(a_command); } } if (my_stop_is_required) { // no mutex required since the stop command is synchronous // and waiting for my_sem_stop_is_acknowledged init(); // purge start semaphore SHOW_TIME("say_thread > purge my_sem_start_is_required\n"); while(0==sem_trywait(&my_sem_start_is_required)) { }; // acknowledge the stop request SHOW_TIME("say_thread > post my_sem_stop_is_acknowledged\n"); int a_status = sem_post(&my_sem_stop_is_acknowledged); assert( a_status != -1); } // and wait for the next start SHOW_TIME("say_thread > wait for my_sem_start_is_required\n"); } return NULL; } int fifo_is_command_enabled() { SHOW("ENTER fifo_is_command_enabled=%d\n",(int)(0 == my_stop_is_required)); return (0 == my_stop_is_required); } //> //<fifo typedef struct t_node { t_espeak_command* data; t_node *next; } node; static node* head=NULL; static node* tail=NULL; // return 1 if ok, 0 otherwise static espeak_ERROR push(t_espeak_command* the_command) { ENTER("fifo > push"); assert((!head && !tail) || (head && tail)); if (the_command == NULL) { SHOW("push > command=0x%x\n", NULL); return EE_INTERNAL_ERROR; } if (node_counter >= MAX_NODE_COUNTER) { SHOW("push > %s\n", "EE_BUFFER_FULL"); return EE_BUFFER_FULL; } node *n = (node *)malloc(sizeof(node)); if (n == NULL) { return EE_INTERNAL_ERROR; } if (head == NULL) { head = n; tail = n; } else { tail->next = n; tail = n; } tail->next = NULL; tail->data = the_command; node_counter++; SHOW("push > counter=%d\n",node_counter); the_command->state = CS_PENDING; display_espeak_command(the_command); return EE_OK; } static t_espeak_command* pop() { ENTER("fifo > pop"); t_espeak_command* the_command = NULL; assert((!head && !tail) || (head && tail)); if (head != NULL) { node* n = head; the_command = n->data; head = n->next; free(n); node_counter--; SHOW("pop > command=0x%x (counter=%d)\n",the_command, node_counter); } if(head == NULL) { tail = NULL; } display_espeak_command(the_command); return the_command; } static void init() { ENTER("fifo > init"); while (delete_espeak_command( pop() )) {} node_counter = 0; } //> //<fifo_init void fifo_terminate() { ENTER("fifo_terminate"); pthread_cancel(my_thread); pthread_join(my_thread,NULL); pthread_mutex_destroy(&my_mutex); sem_destroy(&my_sem_start_is_required); sem_destroy(&my_sem_stop_is_acknowledged); init(); // purge fifo } #endif //>
14,234
C
.c
489
25.03681
132
0.612841
zoff99/zanavi
13
4
19
GPL-2.0
9/7/2024, 10:54:05 AM (Europe/Amsterdam)
false
false
true
true
false
false
false
false
5,142,105
debug.c
zoff99_zanavi/navit/support/espeak/debug.c
#include <stdio.h> #include <stdarg.h> #include "speech.h" #include "debug.h" #ifdef DEBUG_ENABLED #include <sys/time.h> #include <unistd.h> static FILE* fd_log=NULL; static const char* FILENAME="/tmp/espeak.log"; void debug_init() { if((fd_log = fopen(FILENAME,"a")) != NULL) setvbuf(fd_log, NULL, _IONBF, 0); } void debug_enter(const char* text) { struct timeval tv; gettimeofday(&tv, NULL); // fd_log = fopen(FILENAME,"a"); if (!fd_log) { debug_init(); } if (fd_log) { fprintf(fd_log, "%03d.%03dms > ENTER %s\n",(int)(tv.tv_sec%1000), (int)(tv.tv_usec/1000), text); // fclose(fd_log); } } void debug_show(const char *format, ...) { va_list args; va_start(args, format); // fd_log = fopen(FILENAME,"a"); if (!fd_log) { debug_init(); } if (fd_log) { vfprintf(fd_log, format, args); // fclose(fd_log); } va_end(args); } void debug_time(const char* text) { struct timeval tv; gettimeofday(&tv, NULL); // fd_log = fopen(FILENAME,"a"); if (!fd_log) { debug_init(); } if (fd_log) { fprintf(fd_log, "%03d.%03dms > %s\n",(int)(tv.tv_sec%1000), (int)(tv.tv_usec/1000), text); // fclose(fd_log); } } #endif
1,307
C
.c
61
17.311475
102
0.56691
zoff99/zanavi
13
4
19
GPL-2.0
9/7/2024, 10:54:05 AM (Europe/Amsterdam)
true
false
false
true
true
false
false
false
5,142,116
wave_pulse.c
zoff99_zanavi/navit/support/espeak/wave_pulse.c
/*************************************************************************** * Copyright (C) 2007, Gilles Casse <[email protected]> * * eSpeak driver for PulseAudio * * based on the XMMS PulseAudio Plugin * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ // TBD: // * ARCH_BIG // * uint64? a_timing_info.read_index // * prebuf,... size? // * 0.9.6: pb pulse_free using tlength=8820 (max size never returned -> tlength=10000 ok, but higher drain). // #include "speech.h" #ifdef USE_ASYNC // This source file is only used for asynchronious modes #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <sys/time.h> #include <time.h> #include <pulse/pulseaudio.h> #include <pthread.h> #ifndef PLATFORM_WINDOWS #include <unistd.h> #endif #include "wave.h" #include "debug.h" //<Definitions enum {ONE_BILLION=1000000000}; enum { // /* 100ms. // If a greater value is set (several seconds), // please update _pulse_timeout_start accordingly */ // PULSE_TIMEOUT_IN_USEC = 100000, /* return value */ PULSE_OK = 0, PULSE_ERROR = -1, PULSE_NO_CONNECTION = -2 }; #ifdef USE_PULSEAUDIO static t_wave_callback* my_callback_is_output_enabled=NULL; #define SAMPLE_RATE 22050 #define ESPEAK_FORMAT PA_SAMPLE_S16LE #define ESPEAK_CHANNEL 1 #define MAXLENGTH 132300 #define TLENGTH 4410 #define PREBUF 2200 #define MINREQ 880 #define FRAGSIZE 0 static pthread_mutex_t pulse_mutex; static pa_context *context = NULL; static pa_stream *stream = NULL; static pa_threaded_mainloop *mainloop = NULL; static pa_cvolume volume; static int volume_valid = 0; static int do_trigger = 0; static uint64_t written = 0; static int time_offset_msec = 0; static int just_flushed = 0; static int connected = 0; #define CHECK_DEAD_GOTO(label, warn) do { \ if (!mainloop || \ !context || pa_context_get_state(context) != PA_CONTEXT_READY || \ !stream || pa_stream_get_state(stream) != PA_STREAM_READY) { \ if (warn) \ SHOW("Connection died: %s\n", context ? pa_strerror(pa_context_errno(context)) : "NULL"); \ goto label; \ } \ } while(0); #define CHECK_CONNECTED(retval) \ do { \ if (!connected) return retval; \ } while (0); #define CHECK_CONNECTED_NO_RETVAL(id) \ do { \ if (!connected){ SHOW("CHECK_CONNECTED_NO_RETVAL: !pulse_connected\n", ""); return; } \ } while (0); //> // static void display_timing_info(const pa_timing_info* the_time) // { // const struct timeval *tv=&(the_time->timestamp); // SHOW_TIME("ti>"); // SHOW("ti> timestamp=%03d.%03dms\n",(int)(tv->tv_sec%1000), (int)(tv->tv_usec/1000)); // SHOW("ti> synchronized_clocks=%d\n",the_time->synchronized_clocks); // SHOW("ti> sink_usec=%ld\n",the_time->sink_usec); // SHOW("ti> source_usec=%ld\n",the_time->source_usec); // SHOW("ti> transport=%ld\n",the_time->transport_usec); // SHOW("ti> playing=%d\n",the_time->playing); // SHOW("ti> write_index_corrupt=%d\n",the_time->write_index_corrupt); // SHOW("ti> write_index=0x%lx\n",the_time->write_index); // SHOW("ti> read_index_corrupt=%d\n",the_time->read_index_corrupt); // SHOW("ti> read_index=0x%lx\n",the_time->read_index); // } static void info_cb(struct pa_context *c, const struct pa_sink_input_info *i, int is_last, void *userdata) { ENTER(__FUNCTION__); assert(c); if (!i) return; volume = i->volume; volume_valid = 1; } static void subscribe_cb(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata) { pa_operation *o; ENTER(__FUNCTION__); assert(c); if (!stream || index != pa_stream_get_index(stream) || (t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE) && t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW))) return; if (!(o = pa_context_get_sink_input_info(c, index, info_cb, NULL))) { SHOW("pa_context_get_sink_input_info() failed: %s\n", pa_strerror(pa_context_errno(c))); return; } pa_operation_unref(o); } static void context_state_cb(pa_context *c, void *userdata) { ENTER(__FUNCTION__); assert(c); switch (pa_context_get_state(c)) { case PA_CONTEXT_READY: case PA_CONTEXT_TERMINATED: case PA_CONTEXT_FAILED: pa_threaded_mainloop_signal(mainloop, 0); break; case PA_CONTEXT_UNCONNECTED: case PA_CONTEXT_CONNECTING: case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: break; } } static void stream_state_cb(pa_stream *s, void * userdata) { ENTER(__FUNCTION__); assert(s); switch (pa_stream_get_state(s)) { case PA_STREAM_READY: case PA_STREAM_FAILED: case PA_STREAM_TERMINATED: pa_threaded_mainloop_signal(mainloop, 0); break; case PA_STREAM_UNCONNECTED: case PA_STREAM_CREATING: break; } } static void stream_success_cb(pa_stream *s, int success, void *userdata) { ENTER(__FUNCTION__); assert(s); if (userdata) *(int*) userdata = success; pa_threaded_mainloop_signal(mainloop, 0); } static void context_success_cb(pa_context *c, int success, void *userdata) { ENTER(__FUNCTION__); assert(c); if (userdata) *(int*) userdata = success; pa_threaded_mainloop_signal(mainloop, 0); } static void stream_request_cb(pa_stream *s, size_t length, void *userdata) { ENTER(__FUNCTION__); assert(s); pa_threaded_mainloop_signal(mainloop, 0); } static void stream_latency_update_cb(pa_stream *s, void *userdata) { // ENTER(__FUNCTION__); assert(s); pa_threaded_mainloop_signal(mainloop, 0); } static int pulse_free(void) { ENTER(__FUNCTION__); size_t l = 0; pa_operation *o = NULL; CHECK_CONNECTED(0); SHOW("pulse_free: %s (call)\n", "pa_threaded_main_loop_lock"); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); if ((l = pa_stream_writable_size(stream)) == (size_t) -1) { SHOW("pa_stream_writable_size() failed: %s", pa_strerror(pa_context_errno(context))); l = 0; goto fail; } SHOW("pulse_free: %s (ret=%d)\n", "pa_stream_writable_size", l); /* If this function is called twice with no pulse_write() call in * between this means we should trigger the playback */ if (do_trigger) { int success = 0; SHOW("pulse_free: %s (call)\n", "pa_stream_trigger"); if (!(o = pa_stream_trigger(stream, stream_success_cb, &success))) { SHOW("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } SHOW("pulse_free: %s (call)\n", "pa_threaded_main_loop"); while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } SHOW("pulse_free: %s (ret)\n", "pa_threaded_main_loop"); if (!success) SHOW("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); } fail: SHOW("pulse_free: %s (call)\n", "pa_operation_unref"); if (o) pa_operation_unref(o); SHOW("pulse_free: %s (call)\n", "pa_threaded_main_loop_unlock"); pa_threaded_mainloop_unlock(mainloop); do_trigger = !!l; SHOW("pulse_free: %d (ret)\n", (int)l); return (int) l; } static int pulse_playing(const pa_timing_info *the_timing_info) { ENTER(__FUNCTION__); int r = 0; const pa_timing_info *i; assert(the_timing_info); CHECK_CONNECTED(0); pa_threaded_mainloop_lock(mainloop); for (;;) { CHECK_DEAD_GOTO(fail, 1); if ((i = pa_stream_get_timing_info(stream))) { break; } if (pa_context_errno(context) != PA_ERR_NODATA) { SHOW("pa_stream_get_timing_info() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } pa_threaded_mainloop_wait(mainloop); } r = i->playing; memcpy((void*)the_timing_info, (void*)i, sizeof(pa_timing_info)); // display_timing_info(i); fail: pa_threaded_mainloop_unlock(mainloop); return r; } // static void pulse_flush(int time) { // ENTER(__FUNCTION__); // pa_operation *o = NULL; // int success = 0; // CHECK_CONNECTED(); // pa_threaded_mainloop_lock(mainloop); // CHECK_DEAD_GOTO(fail, 1); // if (!(o = pa_stream_flush(stream, stream_success_cb, &success))) { // SHOW("pa_stream_flush() failed: %s", pa_strerror(pa_context_errno(context))); // goto fail; // } // while (pa_operation_get_state(o) != PA_OPERATION_DONE) { // CHECK_DEAD_GOTO(fail, 1); // pa_threaded_mainloop_wait(mainloop); // } // if (!success) // SHOW("pa_stream_flush() failed: %s", pa_strerror(pa_context_errno(context))); // written = (uint64_t) (((double) time * pa_bytes_per_second(pa_stream_get_sample_spec(stream))) / 1000); // just_flushed = 1; // time_offset_msec = time; // fail: // if (o) // pa_operation_unref(o); // pa_threaded_mainloop_unlock(mainloop); // } static void pulse_write(void* ptr, int length) { ENTER(__FUNCTION__); SHOW("pulse_write > length=%d\n", length); CHECK_CONNECTED(); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); if (pa_stream_write(stream, ptr, length, NULL, PA_SEEK_RELATIVE, (pa_seek_mode_t)0) < 0) { SHOW("pa_stream_write() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } do_trigger = 0; written += length; fail: pa_threaded_mainloop_unlock(mainloop); } static int drain(void) { pa_operation *o = NULL; int success = 0; int ret = PULSE_ERROR; ENTER(__FUNCTION__); CHECK_CONNECTED(ret); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 0); SHOW_TIME("pa_stream_drain (call)"); if (!(o = pa_stream_drain(stream, stream_success_cb, &success))) { SHOW("pa_stream_drain() failed: %s\n", pa_strerror(pa_context_errno(context))); goto fail; } SHOW_TIME("pa_threaded_mainloop_wait (call)"); while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } SHOW_TIME("pa_threaded_mainloop_wait (ret)"); if (!success) { SHOW("pa_stream_drain() failed: %s\n", pa_strerror(pa_context_errno(context))); } else { ret = PULSE_OK; } fail: SHOW_TIME("pa_operation_unref (call)"); if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); SHOW_TIME("drain (ret)"); return ret; } static void pulse_close(void) { ENTER(__FUNCTION__); drain(); connected = 0; if (mainloop) pa_threaded_mainloop_stop(mainloop); connected = 0; if (context) { SHOW_TIME("pa_context_disconnect (call)"); pa_context_disconnect(context); pa_context_unref(context); context = NULL; } if (mainloop) { SHOW_TIME("pa_threaded_mainloop_free (call)"); pa_threaded_mainloop_free(mainloop); mainloop = NULL; } SHOW_TIME("pulse_close (ret)"); } static int pulse_open() { ENTER(__FUNCTION__); pa_sample_spec ss; pa_operation *o = NULL; int success; int ret = PULSE_ERROR; assert(!mainloop); assert(!context); assert(!stream); assert(!connected); pthread_mutex_init( &pulse_mutex, (const pthread_mutexattr_t *)NULL); ss.format = ESPEAK_FORMAT; ss.rate = SAMPLE_RATE; ss.channels = ESPEAK_CHANNEL; if (!pa_sample_spec_valid(&ss)) return false; /* if (!volume_valid) { */ pa_cvolume_reset(&volume, ss.channels); volume_valid = 1; /* } else if (volume.channels != ss.channels) */ /* pa_cvolume_set(&volume, ss.channels, pa_cvolume_avg(&volume)); */ SHOW_TIME("pa_threaded_mainloop_new (call)"); if (!(mainloop = pa_threaded_mainloop_new())) { SHOW("Failed to allocate main loop\n",""); goto fail; } pa_threaded_mainloop_lock(mainloop); SHOW_TIME("pa_context_new (call)"); if (!(context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), "eSpeak"))) { SHOW("Failed to allocate context\n",""); goto unlock_and_fail; } pa_context_set_state_callback(context, context_state_cb, NULL); pa_context_set_subscribe_callback(context, subscribe_cb, NULL); SHOW_TIME("pa_context_connect (call)"); if (pa_context_connect(context, NULL, (pa_context_flags_t)0, NULL) < 0) { SHOW("Failed to connect to server: %s", pa_strerror(pa_context_errno(context))); ret = PULSE_NO_CONNECTION; goto unlock_and_fail; } SHOW_TIME("pa_threaded_mainloop_start (call)"); if (pa_threaded_mainloop_start(mainloop) < 0) { SHOW("Failed to start main loop",""); goto unlock_and_fail; } /* Wait until the context is ready */ SHOW_TIME("pa_threaded_mainloop_wait"); pa_threaded_mainloop_wait(mainloop); if (pa_context_get_state(context) != PA_CONTEXT_READY) { SHOW("Failed to connect to server: %s", pa_strerror(pa_context_errno(context))); ret = PULSE_NO_CONNECTION; if (mainloop) pa_threaded_mainloop_stop(mainloop); goto unlock_and_fail; } SHOW_TIME("pa_stream_new"); if (!(stream = pa_stream_new(context, "unknown", &ss, NULL))) { SHOW("Failed to create stream: %s", pa_strerror(pa_context_errno(context))); goto unlock_and_fail; } pa_stream_set_state_callback(stream, stream_state_cb, NULL); pa_stream_set_write_callback(stream, stream_request_cb, NULL); pa_stream_set_latency_update_callback(stream, stream_latency_update_cb, NULL); pa_buffer_attr a_attr; a_attr.maxlength = MAXLENGTH; a_attr.tlength = TLENGTH; a_attr.prebuf = PREBUF; a_attr.minreq = MINREQ; a_attr.fragsize = 0; SHOW_TIME("pa_connect_playback"); if (pa_stream_connect_playback(stream, NULL, &a_attr, (pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE), &volume, NULL) < 0) { SHOW("Failed to connect stream: %s", pa_strerror(pa_context_errno(context))); goto unlock_and_fail; } /* Wait until the stream is ready */ SHOW_TIME("pa_threaded_mainloop_wait"); pa_threaded_mainloop_wait(mainloop); if (pa_stream_get_state(stream) != PA_STREAM_READY) { SHOW("Failed to connect stream: %s", pa_strerror(pa_context_errno(context))); goto unlock_and_fail; } /* Now subscribe to events */ SHOW_TIME("pa_context_subscribe"); if (!(o = pa_context_subscribe(context, PA_SUBSCRIPTION_MASK_SINK_INPUT, context_success_cb, &success))) { SHOW("pa_context_subscribe() failed: %s", pa_strerror(pa_context_errno(context))); goto unlock_and_fail; } success = 0; SHOW_TIME("pa_threaded_mainloop_wait"); while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } if (!success) { SHOW("pa_context_subscribe() failed: %s", pa_strerror(pa_context_errno(context))); goto unlock_and_fail; } pa_operation_unref(o); /* Now request the initial stream info */ if (!(o = pa_context_get_sink_input_info(context, pa_stream_get_index(stream), info_cb, NULL))) { SHOW("pa_context_get_sink_input_info() failed: %s", pa_strerror(pa_context_errno(context))); goto unlock_and_fail; } SHOW_TIME("pa_threaded_mainloop_wait 2"); while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } /* if (!volume_valid) { */ /* SHOW("pa_context_get_sink_input_info() failed: %s", pa_strerror(pa_context_errno(context))); */ /* goto unlock_and_fail; */ /* } */ do_trigger = 0; written = 0; time_offset_msec = 0; just_flushed = 0; connected = 1; // volume_time_event = NULL; pa_threaded_mainloop_unlock(mainloop); SHOW_TIME("pulse_open (ret true)"); // return true; return PULSE_OK; unlock_and_fail: if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); fail: // pulse_close(); if (ret == PULSE_NO_CONNECTION) { if (context) { SHOW_TIME("pa_context_disconnect (call)"); pa_context_disconnect(context); pa_context_unref(context); context = NULL; } if (mainloop) { SHOW_TIME("pa_threaded_mainloop_free (call)"); pa_threaded_mainloop_free(mainloop); mainloop = NULL; } } else { pulse_close(); } SHOW_TIME("pulse_open (ret false)"); return ret; } void wave_flush(void* theHandler) { ENTER("wave_flush"); // if (my_stream_could_start) // { // // #define buf 1024 // // static char a_buffer[buf*2]; // // memset(a_buffer,0,buf*2); // // wave_write(theHandler, a_buffer, buf*2); // start_stream(); // } } //<wave_set_callback_is_output_enabled void wave_set_callback_is_output_enabled(t_wave_callback* cb) { my_callback_is_output_enabled = cb; } //> //<wave_init void wave_init() { ENTER("wave_init"); stream = NULL; pulse_open(); } //> //<wave_open void* wave_open(const char* the_api) { ENTER("wave_open"); return((void*)1); } //> //<wave_write size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSize) { ENTER("wave_write"); size_t bytes_to_write = theSize; char* aBuffer=theMono16BitsWaveBuffer; assert(stream); size_t aTotalFreeMem=0; pthread_mutex_lock(&pulse_mutex); while (1) { if (my_callback_is_output_enabled && (0==my_callback_is_output_enabled())) { SHOW_TIME("wave_write > my_callback_is_output_enabled: no!"); theSize=0; goto terminate; } aTotalFreeMem = pulse_free(); if (aTotalFreeMem >= bytes_to_write) { SHOW("wave_write > aTotalFreeMem(%d) >= bytes_to_write(%d)\n", aTotalFreeMem, bytes_to_write); break; } // TBD: check if really helpful if (aTotalFreeMem >= MAXLENGTH*2) { aTotalFreeMem = MAXLENGTH*2; } SHOW("wave_write > wait: aTotalFreeMem(%d) < bytes_to_write(%d)\n", aTotalFreeMem, bytes_to_write); // 500: threshold for avoiding too many calls to pulse_write if (aTotalFreeMem>500) { pulse_write(aBuffer, aTotalFreeMem); bytes_to_write -= aTotalFreeMem; aBuffer += aTotalFreeMem; } usleep(10000); } pulse_write(aBuffer, bytes_to_write); terminate: pthread_mutex_unlock(&pulse_mutex); SHOW("wave_write: theSize=%d", theSize); SHOW_TIME("wave_write > LEAVE"); return theSize; } //> //<wave_close int wave_close(void* theHandler) { SHOW_TIME("wave_close > ENTER"); int a_status = pthread_mutex_lock(&pulse_mutex); if (a_status) { SHOW("Error: pulse_mutex lock=%d (%s)\n", a_status, __FUNCTION__); return PULSE_ERROR; } drain(); pthread_mutex_unlock(&pulse_mutex); SHOW_TIME("wave_close (ret)"); return PULSE_OK; } //> //<wave_is_busy int wave_is_busy(void* theHandler) { SHOW_TIME("wave_is_busy"); pa_timing_info a_timing_info; int active = pulse_playing(&a_timing_info); SHOW("wave_is_busy: %d\n",active); return active; } //> //<wave_terminate void wave_terminate() { ENTER("wave_terminate"); // Pa_Terminate(); int a_status; pthread_mutex_t* a_mutex = NULL; a_mutex = &pulse_mutex; a_status = pthread_mutex_lock(a_mutex); pulse_close(); SHOW_TIME("unlock mutex"); a_status = pthread_mutex_unlock(a_mutex); pthread_mutex_destroy(a_mutex); } //> //<wave_get_read_position, wave_get_write_position, wave_get_remaining_time uint32_t wave_get_read_position(void* theHandler) { pa_timing_info a_timing_info; pulse_playing(&a_timing_info); SHOW("wave_get_read_position > %lx\n", a_timing_info.read_index); return a_timing_info.read_index; } uint32_t wave_get_write_position(void* theHandler) { pa_timing_info a_timing_info; pulse_playing(&a_timing_info); SHOW("wave_get_read_position > %lx\n", a_timing_info.write_index); return a_timing_info.write_index; } int wave_get_remaining_time(uint32_t sample, uint32_t* time) { double a_time=0; if (!time || !stream) { SHOW("event get_remaining_time> %s\n","audio device not available"); return -1; } pa_timing_info a_timing_info; pulse_playing(&a_timing_info); if (sample > a_timing_info.read_index) { // TBD: take in account time suplied by portaudio V18 API a_time = sample - a_timing_info.read_index; a_time = 0.5 + (a_time * 1000.0) / SAMPLE_RATE; } else { a_time = 0; } SHOW("wave_get_remaining_time > sample=%d, time=%d\n", sample, (uint32_t)a_time); *time = (uint32_t)a_time; return 0; } //> //<wave_test_get_write_buffer void *wave_test_get_write_buffer() { return NULL; } #else // notdef USE_PULSEAUDIO void wave_init() {} void* wave_open(const char* the_api) {return (void *)1;} size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSize) {return theSize;} int wave_close(void* theHandler) {return 0;} int wave_is_busy(void* theHandler) {return 0;} void wave_terminate() {} uint32_t wave_get_read_position(void* theHandler) {return 0;} uint32_t wave_get_write_position(void* theHandler) {return 0;} void wave_flush(void* theHandler) {} typedef int (t_wave_callback)(void); void wave_set_callback_is_output_enabled(t_wave_callback* cb) {} extern void* wave_test_get_write_buffer() {return NULL;} int wave_get_remaining_time(uint32_t sample, uint32_t* time) { if (!time) return(-1); *time = (uint32_t)0; return 0; } #endif // of USE_PORTAUDIO //> //<clock_gettime2, add_time_in_ms void clock_gettime2(struct timespec *ts) { struct timeval tv; if (!ts) { return; } assert (gettimeofday(&tv, NULL) != -1); ts->tv_sec = tv.tv_sec; ts->tv_nsec = tv.tv_usec*1000; } void add_time_in_ms(struct timespec *ts, int time_in_ms) { if (!ts) { return; } uint64_t t_ns = (uint64_t)ts->tv_nsec + 1000000 * (uint64_t)time_in_ms; while(t_ns >= ONE_BILLION) { SHOW("event > add_time_in_ms ns: %d sec %Lu nsec \n", ts->tv_sec, t_ns); ts->tv_sec += 1; t_ns -= ONE_BILLION; } ts->tv_nsec = (long int)t_ns; } #endif // USE_ASYNC //>
23,905
C
.c
711
29.213783
159
0.628234
zoff99/zanavi
13
4
19
GPL-2.0
9/7/2024, 10:54:05 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
5,142,118
synth_mbrola.c
zoff99_zanavi/navit/support/espeak/synth_mbrola.c
/*************************************************************************** * Copyright (C) 2005 to 2007 by Jonathan Duddington * * email: [email protected] * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write see: * * <http://www.gnu.org/licenses/>. * ***************************************************************************/ #include "StdAfx.h" #include <stdio.h> #include <ctype.h> #include <wctype.h> #include <stdlib.h> #include <string.h> #include <math.h> #include "speak_lib.h" #include "speech.h" #include "phoneme.h" #include "synthesize.h" #include "translate.h" #include "voice.h" extern int Read4Bytes(FILE *f); extern void SetPitch2(voice_t *voice, int pitch1, int pitch2, int *pitch_base, int *pitch_range); #ifdef USE_MBROLA_LIB extern unsigned char *outbuf; #ifndef PLATFORM_WINDOWS #include "mbrolib.h" void * mb_handle; #else #include <windows.h> typedef void (WINAPI *PROCVV)(void); typedef void (WINAPI *PROCVI)(int); typedef void (WINAPI *PROCVF)(float); typedef int (WINAPI *PROCIV)(); typedef int (WINAPI *PROCIC) (char *); typedef int (WINAPI *PROCISI)(short *,int); typedef char* (WINAPI *PROCVCI)(char *,int); PROCIC init_MBR; PROCIC write_MBR; PROCIV flush_MBR; PROCISI read_MBR; PROCVV close_MBR; PROCVV reset_MBR; PROCIV lastError_MBR; PROCVCI lastErrorStr_MBR; PROCVI setNoError_MBR; PROCVI setFreq_MBR; PROCVF setVolumeRatio_MBR; HINSTANCE hinstDllMBR = NULL; BOOL load_MBR() { if(hinstDllMBR != NULL) return TRUE; // already loaded if (!(hinstDllMBR=LoadLibraryA("mbrola.dll"))) return FALSE; init_MBR =(PROCIC) GetProcAddress(hinstDllMBR,"init_MBR"); write_MBR =(PROCIC) GetProcAddress(hinstDllMBR,"write_MBR"); flush_MBR =(PROCIV) GetProcAddress(hinstDllMBR,"flush_MBR"); read_MBR =(PROCISI) GetProcAddress(hinstDllMBR,"read_MBR"); close_MBR =(PROCVV) GetProcAddress(hinstDllMBR,"close_MBR"); reset_MBR =(PROCVV) GetProcAddress(hinstDllMBR,"reset_MBR"); lastError_MBR =(PROCIV) GetProcAddress(hinstDllMBR,"lastError_MBR"); lastErrorStr_MBR =(PROCVCI) GetProcAddress(hinstDllMBR,"lastErrorStr_MBR"); setNoError_MBR =(PROCVI) GetProcAddress(hinstDllMBR,"setNoError_MBR"); setVolumeRatio_MBR =(PROCVF) GetProcAddress(hinstDllMBR,"setVolumeRatio_MBR"); return TRUE; } void unload_MBR() { if (hinstDllMBR) { FreeLibrary (hinstDllMBR); hinstDllMBR=NULL; } } #endif // windows #endif // USE_MBROLA_LIB static MBROLA_TAB *mbrola_tab = NULL; static int mbrola_control = 0; espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int srate) {//=================================================================================== // Load a phoneme name translation table from espeak-data/mbrola int size; int ix; int *pw; FILE *f_in; char path[sizeof(path_home)+15]; mbrola_name[0] = 0; mbrola_delay = 0; if(mbrola_voice == NULL) { samplerate = samplerate_native; SetParameter(espeakVOICETYPE,0,0); return(EE_OK); } sprintf(path,"%s/mbrola/%s",path_home,mbrola_voice); #ifdef USE_MBROLA_LIB #ifdef PLATFORM_WINDOWS if(load_MBR() == FALSE) // load mbrola.dll return(EE_INTERNAL_ERROR); if(init_MBR(path) != 0) // initialise the required mbrola voice return(EE_NOT_FOUND); setNoError_MBR(1); // don't stop on phoneme errors #else mb_handle = mbrolib_init(srate); mbrolib_parameter m_parameters; if(mb_handle == NULL) return(EE_INTERNAL_ERROR); MBROLIB_ERROR a_status = mbrolib_set_voice(mb_handle, mbrola_voice); if(a_status != MBROLIB_OK) return(EE_NOT_FOUND); #endif // not windows #endif // USE_MBROLA_LIB // read eSpeak's mbrola phoneme translation data, eg. en1_phtrans sprintf(path,"%s/mbrola_ph/%s",path_home,phtrans); size = GetFileLength(path); if((f_in = fopen(path,"r")) == NULL) return(EE_NOT_FOUND); if((mbrola_tab = (MBROLA_TAB *)realloc(mbrola_tab,size)) == NULL) { fclose(f_in); return(EE_INTERNAL_ERROR); } mbrola_control = Read4Bytes(f_in); pw = (int *)mbrola_tab; for(ix=4; ix<size; ix+=4) { *pw++ = Read4Bytes(f_in); } fread(mbrola_tab,size,1,f_in); fclose(f_in); #ifdef USE_MBROLA_LIB #ifdef PLATFORM_WINDOWS setVolumeRatio_MBR((float)(mbrola_control & 0xff) /16.0f); #else mbrolib_get_parameter(mb_handle,&m_parameters); m_parameters.ignore_error = 1; m_parameters.volume_ratio = (float)(mbrola_control & 0xff) /16.0; mbrolib_set_parameter(mb_handle,&m_parameters); #endif // not windows #endif // USE_MBROLA_LIB option_quiet = 1; samplerate = srate; if(srate == 22050) SetParameter(espeakVOICETYPE,0,0); else SetParameter(espeakVOICETYPE,1,0); strcpy(mbrola_name,mbrola_voice); mbrola_delay = 3800; // improve synchronization of events return(EE_OK); } // end of LoadMbrolaTable static int GetMbrName(PHONEME_LIST *plist, PHONEME_TAB *ph, PHONEME_TAB *ph_prev, PHONEME_TAB *ph_next, int *name2, int *split, int *control) {//========================================================================================================================================== // Look up a phoneme in the mbrola phoneme name translation table // It may give none, 1, or 2 mbrola phonemes int mnem = ph->mnemonic; MBROLA_TAB *pr; PHONEME_TAB *other_ph; int found = 0; // control // bit 0 skip the next phoneme // bit 1 match this and Previous phoneme // bit 2 only at the start of a word // bit 3 don't match two phonemes across a word boundary pr = mbrola_tab; while(pr->name != 0) { if(mnem == pr->name) { if(pr->next_phoneme == 0) found = 1; else if((pr->next_phoneme == ':') && (plist->synthflags & SFLAG_LENGTHEN)) { found = 1; } else { if(pr->control & 2) other_ph = ph_prev; else if((pr->control & 8) && ((plist+1)->newword)) other_ph = phoneme_tab[phPAUSE]; // don't match the next phoneme over a word boundary else other_ph = ph_next; if((pr->next_phoneme == other_ph->mnemonic) || ((pr->next_phoneme == 2) && (other_ph->type == phVOWEL)) || ((pr->next_phoneme == '_') && (other_ph->type == phPAUSE))) { found = 1; } } if((pr->control & 4) && (plist->newword == 0)) // only at start of word found = 0; if(found) { *name2 = pr->mbr_name2; *split = pr->percent; *control = pr->control; return(pr->mbr_name); } } pr++; } *name2=0; *split=0; *control=0; return(mnem); } static char *WritePitch(int env, int pitch1, int pitch2, int split, int final) {//=========================================================================== // final=1: only give the final pitch value. int x; int ix; int pitch_base; int pitch_range; int p1,p2,p_end; unsigned char *pitch_env; int max = -1; int min = 999; int y_max=0; int y_min=0; int env100 = 80; // apply the pitch change only over this proportion of the mbrola phoneme(s) int y2; int y[4]; int env_split; char buf[50]; static char output[50]; output[0] = 0; pitch_env = envelope_data[env]; SetPitch2(voice, pitch1, pitch2, &pitch_base, &pitch_range); env_split = (split * 128)/100; if(env_split < 0) env_split = 0-env_split; // find max and min in the pitch envelope for(x=0; x<128; x++) { if(pitch_env[x] > max) { max = pitch_env[x]; y_max = x; } if(pitch_env[x] < min) { min = pitch_env[x]; y_min = x; } } // set an additional pitch point half way through the phoneme. // but look for a maximum or a minimum and use that instead y[2] = 64; if((y_max > 0) && (y_max < 127)) { y[2] = y_max; } if((y_min > 0) && (y_min < 127)) { y[2] = y_min; } y[1] = y[2] / 2; y[3] = y[2] + (127 - y[2])/2; // set initial pitch p1 = ((pitch_env[0]*pitch_range)>>8) + pitch_base; // Hz << 12 p_end = ((pitch_env[127]*pitch_range)>>8) + pitch_base; if(split >= 0) { sprintf(buf," 0 %d",p1/4096); strcat(output,buf); } // don't use intermediate pitch points for linear rise and fall if(env > 1) { for(ix=1; ix<4; ix++) { p2 = ((pitch_env[y[ix]]*pitch_range)>>8) + pitch_base; if(split > 0) { y2 = (y[ix] * env100)/env_split; } else if(split < 0) { y2 = ((y[ix]-env_split) * env100)/env_split; } else { y2 = (y[ix] * env100)/128; } if((y2 > 0) && (y2 <= env100)) { sprintf(buf," %d %d",y2,p2/4096); strcat(output,buf); } } } p_end = p_end/4096; if(split <= 0) { sprintf(buf," %d %d",env100,p_end); strcat(output,buf); } if(env100 < 100) { sprintf(buf," %d %d",100,p_end); strcat(output,buf); } strcat(output,"\n"); if(final) sprintf(output,"\t100 %d\n",p_end); return(output); } // end of WritePitch #ifdef USE_MBROLA_LIB static void MbrolaMarker(int type, int char_posn, int length, int value) {//===================================================================== MarkerEvent(type,(char_posn & 0xffffff) | (length << 24),value,outbuf); } static void MbrolaEmbedded(int &embix, int sourceix) {//================================================= // There were embedded commands in the text at this point unsigned int word; // bit 7=last command for this word, bits 5,6 sign, bits 0-4 command unsigned int value; int command; int sign=0; do { word = embedded_list[embix++]; value = word >> 8; command = word & 0x1f; if((word & 0x60) == 0x60) sign = -1; else if((word & 0x60) == 0x40) sign = 1; if(command < N_EMBEDDED_VALUES) { if(sign == 0) embedded_value[command] = value; else embedded_value[command] += (value * sign); } switch(command & 0x1f) { case EMBED_M: // named marker MbrolaMarker(espeakEVENT_MARK, (sourceix & 0x7ff) + clause_start_char, 0, value); break; } } while ((word & 0x80) == 0); } #ifdef PLATFORM_WINDOWS static int MbrolaSynth(char *p_mbrola) {//=================================== // p_mbrola is a string of mbrola pho lines - Windows int len; int finished; int result=0; if(synth_callback == NULL) return(1); if(p_mbrola == NULL) flush_MBR(); else result = write_MBR(p_mbrola); finished = 0; while(!finished && ((len = read_MBR((short *)outbuf, outbuf_size/2)) > 0)) { out_ptr = outbuf + len*2; if(event_list) { event_list[event_list_ix].type = espeakEVENT_LIST_TERMINATED; // indicates end of event list event_list[event_list_ix].user_data = 0; } count_samples += len; finished = synth_callback((short *)outbuf, len, event_list); event_list_ix=0; } if(finished) { // cancelled by user, discard any unused mbrola speech flush_MBR(); while((len = read_MBR((short *)outbuf, outbuf_size/2)) > 0); } return(finished); } // end of SynthMbrola #else static int MbrolaSynth(char *p_mbrola) {//=================================== // p_mbrola is a string of mbrola pho lines - Linux // This is wrong // It must be called from WavegenFill() int len; int finished; int result=0; if(synth_callback == NULL) return(1); if(p_mbrola == NULL) mbrolib_flush(mb_handle); else result = mbrolib_write(mb_handle,p_mbrola,strlen(p_mbrola)); finished = 0; while(!finished && (mbrolib_read(mb_handle, (short *)out_ptr, (out_end - out_ptr)/2, &len) == MBROLIB_OK)) { if(len == 0) break; out_ptr += (len*2); if(event_list) { event_list[event_list_ix].type = espeakEVENT_LIST_TERMINATED; // indicates end of event list event_list[event_list_ix].user_data = 0; } count_samples += len; finished = synth_callback((short *)outbuf, len, event_list); event_list_ix=0; } if(finished) { // cancelled by user, discard any unused mbrola speech mbrolib_flush(mb_handle); while(mbrolib_read(mb_handle, (short *)outbuf, outbuf_size/2, &len) == MBROLIB_OK) { if(len == 0) break; } } return(finished); } // end of SynthMbrola #endif // not windows #endif // USE_MBROLA_LIB void MbrolaTranslate(PHONEME_LIST *plist, int n_phonemes, FILE *f_mbrola) {//====================================================================== // Generate a mbrola pho file unsigned int name; int phix; int len; int len1; PHONEME_TAB *ph; PHONEME_TAB *ph_next; PHONEME_TAB *ph_prev; PHONEME_LIST *p; PHONEME_LIST *next; PHONEME_LIST *prev; int pause = 0; int released; int name2; int control; int done; int len_percent; const char *final_pitch; char buf[80]; char mbr_buf[120]; #ifdef USE_MBROLA_LIB int embedded_ix=0; int word_count=0; event_list_ix = 0; out_ptr = outbuf; #ifdef PLATFORM_WINDOWS setNoError_MBR(1); // don't stop on phoneme errors #endif #else // fprintf(f_mbrola,";; v=%.2f\n",(float)(mbrola_control & 0xff)/16.0); // ;; v= has no effect on mbrola #endif for(phix=1; phix < n_phonemes; phix++) { mbr_buf[0] = 0; p = &plist[phix]; next = &plist[phix+1]; prev = &plist[phix-1]; ph = p->ph; ph_prev = plist[phix-1].ph; ph_next = plist[phix+1].ph; #ifdef USE_MBROLA_LIB if(p->synthflags & SFLAG_EMBEDDED) { MbrolaEmbedded(embedded_ix, p->sourceix); } if(p->newword & 4) MbrolaMarker(espeakEVENT_SENTENCE, (p->sourceix & 0x7ff) + clause_start_char, 0, count_sentences); if(p->newword & 1) MbrolaMarker(espeakEVENT_WORD, (p->sourceix & 0x7ff) + clause_start_char, p->sourceix >> 11, clause_start_word + word_count++); #endif name = GetMbrName(p,ph,ph_prev,ph_next,&name2,&len_percent,&control); if(control & 1) phix++; if(name == 0) continue; // ignore this phoneme if((ph->type == phPAUSE) && (name == ph->mnemonic)) { // a pause phoneme, which has not been changed by the translation name = '_'; len = (p->length * speed.speed_factor1)/256; // if(len == 0) continue; if(len == 0) len = 1; } else len = (80 * speed.speed_factor2)/256; #ifdef USE_MBROLA_LIB MbrolaMarker(espeakEVENT_PHONEME, (p->sourceix & 0x7ff) + clause_start_char, 0, ph->mnemonic); #endif sprintf(buf,"%s\t",WordToString(name)); strcat(mbr_buf,buf); if(name2 == '_') { // add a pause after this phoneme pause = PauseLength(len_percent,0); name2 = 0; } done = 0; final_pitch = ""; switch(ph->type) { case phVOWEL: len = ph->std_length; if(p->synthflags & SFLAG_LENGTHEN) len += phoneme_tab[phonLENGTHEN]->std_length; // phoneme was followed by an extra : symbol if(ph_next->type == phPAUSE) len += 50; // lengthen vowels before a pause len = (len * p->length)/256; if(name2 == 0) { sprintf(buf,"%d\t%s", len, WritePitch(p->env,p->pitch1,p->pitch2,0,0)); strcat(mbr_buf,buf); } else { len1 = (len * len_percent)/100; sprintf(buf,"%d\t%s", len1, WritePitch(p->env,p->pitch1,p->pitch2,len_percent,0)); strcat(mbr_buf,buf); sprintf(buf,"%s\t%d\t%s", WordToString(name2), len-len1, WritePitch(p->env,p->pitch1,p->pitch2,-len_percent,0)); strcat(mbr_buf,buf); } done = 1; break; case phSTOP: released = 0; if(next->type==phVOWEL) released = 1; if(next->type==phLIQUID && !next->newword) released = 1; if(released) len = DoSample(p->ph,next->ph,2,0,-1); else len = DoSample(p->ph,phoneme_tab[phonPAUSE],2,0,-1); len = (len * 1000)/samplerate; // convert to mS len += PauseLength(p->prepause,1); break; case phVSTOP: len = (80 * speed.speed_factor2)/256; break; case phFRICATIVE: len = 0; if(p->synthflags & SFLAG_LENGTHEN) len = DoSample(ph,ph_next,2,p->length,-1); // play it twice for [s:] etc. len += DoSample(ph,ph_next,2,p->length,-1); len = (len * 1000)/samplerate; // convert to mS break; case phNASAL: if(next->type != phVOWEL) { len = DoSpect(p->ph,prev->ph,phoneme_tab[phonPAUSE],2,p,-1); len = (len * 1000)/samplerate; if(next->type == phPAUSE) len += 50; final_pitch = WritePitch(p->env,p->pitch1,p->pitch2,0,1); } break; case phLIQUID: if(next->type == phPAUSE) { len += 50; final_pitch = WritePitch(p->env,p->pitch1,p->pitch2,0,1); } break; } if(!done) { if(name2 != 0) { len1 = (len * len_percent)/100; sprintf(buf,"%d\n%s\t",len1,WordToString(name2)); strcat(mbr_buf,buf); len -= len1; } sprintf(buf,"%d%s\n",len,final_pitch); strcat(mbr_buf,buf); } if(pause) { sprintf(buf,"_ \t%d\n",PauseLength(pause,0)); strcat(mbr_buf,buf); pause = 0; } if(f_mbrola) { fwrite(mbr_buf,1,strlen(mbr_buf),f_mbrola); // write .pho to a file } else { #ifdef USE_MBROLA_LIB if(MbrolaSynth(mbr_buf) != 0) return; #endif } } #ifdef USE_MBROLA_LIB MbrolaSynth(NULL); #endif } // end of MbrolaTranslate #ifdef TEST_MBROLA static PHONEME_LIST mbrola_phlist; static int mbrola_n_ph; static int mbrola_phix; int MbrolaFill(int fill_zeros) {//=========================== } int MbrolaGenerate(PHONEME_LIST *phoneme_list, int *n_ph, int resume) {//================================================================== if(resume == 0) { mbrola_phlist = phoneme_list; mbrola_n_ph = n_ph; mbrola_phix = 0; } resume(0); // finished phoneme list } #endif
18,028
C
.c
631
25.767036
141
0.618022
zoff99/zanavi
13
4
19
GPL-2.0
9/7/2024, 10:54:05 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
5,414,625
2016-7-1-astar.c
ice1000_OI-codes/none-oj-codes/2016-7-1-astar.c
#include <stdio.h> typedef struct node { // location x int x; // location y int y; int t; // parent node *p; } node ; int isBlocked(char a) { // TODO: check if it's blocked return 0; } int main(int argc, char *argv[]) { int i, j, size, oli = 0; node s, e; node ol[1000]; char a[1000][1000]; scanf("%d", &size); for(i = 0; i < size; i++) scanf("%s", a[i]); for(i = 0; i < size; i++) { for(j = 0; j < size; j++) { if(isBlocked(a[i][j])) { // } if(isStart(a[i][j])) { s.x = i; s.y = j; } if(isEnd(a[i][j])) { e.x = i; e.y = j; } } } ol[oli++] = s; do { // } while(); return 0; }
646
C
.c
43
12.395349
34
0.505
ice1000/OI-codes
14
4
0
AGPL-3.0
9/7/2024, 10:55:53 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
5,442,364
crc.h
gonk23_HXCFE_Amiga_copy_utility/crc.h
/* * CRC16 "Register". This is implemented as two 8bit values */ void CRC16_Update(unsigned char *CRC16_High, unsigned char *CRC16_Low, unsigned char val ); void CRC16_Init( unsigned char *CRC16_High, unsigned char *CRC16_Low);
239
C
.c
5
44.6
92
0.73913
gonk23/HXCFE_Amiga_copy_utility
11
1
3
GPL-3.0
9/7/2024, 10:56:02 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
5,442,366
crc.c
gonk23_HXCFE_Amiga_copy_utility/crc.c
/************************************************************************* * Example Table Driven CRC16 Routine using 4-bit message chunks * * By Ashley Roll * Digital Nemesis Pty Ltd * www.digitalnemesis.com * * The following is an example of implementing a restricted size CRC16 * table lookup. No optimisation as been done so the code is clear and * easy to understand. * * Test Vector: "123456789" (character string, no quotes) * Generated CRC: 0x29B1 * *************************************************************************/ #include "crc.h" /* * CRC16 Lookup tables (High and Low Byte) for 4 bits per iteration. */ unsigned short CRC16_LookupHigh[16] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1 }; unsigned short CRC16_LookupLow[16] = { 0x00, 0x21, 0x42, 0x63, 0x84, 0xA5, 0xC6, 0xE7, 0x08, 0x29, 0x4A, 0x6B, 0x8C, 0xAD, 0xCE, 0xEF }; /* * Before each message CRC is generated, the CRC register must be * initialised by calling this function */ void CRC16_Init( unsigned char *CRC16_High, unsigned char *CRC16_Low) { // Initialise the CRC to 0xFFFF for the CCITT specification *CRC16_High = 0xFF; *CRC16_Low = 0xFF; } /* * Process 4 bits of the message to update the CRC Value. * * Note that the data must be in the low nibble of val. */ void CRC16_Update4Bits(unsigned char *CRC16_High, unsigned char *CRC16_Low, unsigned char val ) { unsigned char t; // Step one, extract the Most significant 4 bits of the CRC register t = *CRC16_High >> 4; // XOR in the Message Data into the extracted bits t = t ^ val; // Shift the CRC Register left 4 bits *CRC16_High = (*CRC16_High << 4) | (*CRC16_Low >> 4); *CRC16_Low = *CRC16_Low << 4; // Do the table lookups and XOR the result into the CRC Tables *CRC16_High = *CRC16_High ^ CRC16_LookupHigh[t]; *CRC16_Low = *CRC16_Low ^ CRC16_LookupLow[t]; } /* * Process one Message Byte to update the current CRC Value */ void CRC16_Update(unsigned char *CRC16_High, unsigned char *CRC16_Low, unsigned char val ) { CRC16_Update4Bits(CRC16_High,CRC16_Low, (unsigned char)(val >> 4) ); // High nibble first CRC16_Update4Bits(CRC16_High,CRC16_Low, (unsigned char)(val & 0x0F) ); // Low nibble }
2,351
C
.c
64
33.21875
96
0.644719
gonk23/HXCFE_Amiga_copy_utility
11
1
3
GPL-3.0
9/7/2024, 10:56:02 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
5,625,708
mrmuldv.c
dwu4_genome-privacy/OTExtension/util/Miracl/source/mrmuldv.c
/* * Borland C++ 32-bit compiler (BCC32). Use with mirdef.h32 * Uses inline assembly feature. Suitable for Win32 Apps * Also compatible with Microsoft Visual C++ 32-bit compiler */ #define ASM _asm int muldiv(a,b,c,m,rp) int a,b,c,m,*rp; { ASM mov eax,DWORD PTR a ASM mul DWORD PTR b ASM add eax,DWORD PTR c ASM adc edx,0h ASM div DWORD PTR m ASM mov ebx,DWORD PTR rp ASM mov [ebx],edx } int muldvm(a,c,m,rp) int a,c,m,*rp; { ASM mov edx,DWORD PTR a ASM mov eax,DWORD PTR c ASM div DWORD PTR m ASM mov ebx,DWORD PTR rp ASM mov [ebx],edx } int muldvd(a,b,c,rp) int a,b,c,*rp; { ASM mov eax,DWORD PTR a ASM mul DWORD PTR b ASM add eax,DWORD PTR c ASM adc edx,0h ASM mov ebx,DWORD PTR rp ASM mov [ebx],eax ASM mov eax,edx } void muldvd2(a,b,c,rp) int a,b,*c,*rp; { ASM mov eax,DWORD PTR a ASM mul DWORD PTR b ASM mov ebx,DWORD PTR c ASM add eax,[ebx] ASM adc edx,0h ASM mov esi,DWORD PTR rp ASM add eax,[esi] ASM adc edx,0h ASM mov [esi],eax ASM mov [ebx],edx }
1,460
C
.c
51
19
61
0.479686
dwu4/genome-privacy
12
7
2
GPL-3.0
9/7/2024, 10:57:14 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
5,700,656
mt64.c
Bill-Gray_prngs/mt64.c
/* A C-program for MT19937-64 Coded by Takuji Nishimura and Makoto Matsumoto. (With a lot of changes by Bill J. Gray; see below.) This is a 64-bit version of Mersenne Twister pseudorandom number generator. Before using, initialize the state by using init_mt64(seed, state_array) or init_mt64_by_array( init_key, key_length, state_array). Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. References: T. Nishimura, ``Tables of 64-bit Mersenne Twisters'' ACM Transactions on Modeling and Computer Simulation 10. (2000) 348--357. M. Matsumoto and T. Nishimura, ``Mersenne Twister: a 623-dimensionally equidistributed uniform pseudorandom number generator'' ACM Transactions on Modeling and Computer Simulation 8. (Jan. 1998) 3--30. Any feedback is very welcome. http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces) (BEFORE PROVIDING FEEDBACK, BE AWARE THAT THE FOLLOWING IS NOT THE ORIGINAL CODE! It's been very heavily revised, to the point where it may not be particularly familiar to the original authors. You may want to send feedback to me, Bill Gray, pluto(at)projectpluto(dot)com.) 2011 Apr 2: BJG: removed static variables to make code re-entrant (and therefore thread-safe, I hope). Changed 'unsigned long long's to 'uint64_t'. Used a UCONST( ) macro to allow the code to compile in Microsoft VC, which has a somewhat different way (of course) for defining 64-bit constants. There is now a function to get N bits at a time, where N <= 64. Certain ways of getting double-precision random numbers are given. I moved the 'test' routines into a separate mt64test.c module, added a timing test, and created a header file. */ #include <stdint.h> #include "mt64.h" #ifndef UINT64_C #ifdef _MSC_VER #define UINT64_C( a) (a##ui64) #else #ifdef _WIN32 #define UINT64_C( a) (a##ULL) #else #define UINT64_C( a) ((uint64_t)(a##UL)) #endif #endif #endif #define MM 156 #define MATRIX_A UINT64_C( 0xB5026F5AA96619E9) #define UM UINT64_C( 0xFFFFFFFF80000000) /* Most significant 33 bits */ #define LM UINT64_C( 0x7FFFFFFF) /* Least significant 31 bits */ #define MT_SIZE 312 #define LOC mt[MT_SIZE] #define N_BITS_LEFT mt[MT_SIZE + 1] #define LEFTOVER_BITS mt[MT_SIZE + 2] /* Initializes mt[MT_SIZE] with a seed, using a */ /* modified linear congruential generator. */ void init_mt64( const uint64_t seed, uint64_t *mt) { int i; mt[0] = seed; for( i = 1; i < MT_SIZE; i++) mt[i] = (UINT64_C( 6364136223846793005) * (mt[i-1] ^ (mt[i-1] >> 62)) + i); LOC = MT_SIZE; N_BITS_LEFT = (uint32_t)0; LEFTOVER_BITS = (uint64_t)0; } /* initialize by an array with array-length */ /* init_key is the array for initializing keys */ /* key_length is its length */ void init_mt64_by_array( const uint64_t init_key[], const uint64_t key_length, uint64_t *mt) { uint64_t i, j, k; init_mt64( UINT64_C( 19650218), mt); i=1; j=0; k = (MT_SIZE>key_length ? MT_SIZE : key_length); for (; k; k--) { mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * UINT64_C( 3935559000370003845))) + init_key[j] + j; /* non linear */ i++; j++; if (i>=MT_SIZE) { mt[0] = mt[MT_SIZE-1]; i=1; } if (j>=key_length) j=0; } for (k=MT_SIZE-1; k; k--) { mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * UINT64_C( 2862933555777941757))) - i; /* non linear */ i++; if (i>=MT_SIZE) { mt[0] = mt[MT_SIZE-1]; i=1; } } mt[0] = UINT64_C( 1) << 63; /* MSB is 1; assuring non-zero initial array */ } /* generates a random number on [0, 2^64-1]-interval */ uint64_t mt64( uint64_t * RESTRICT mt) { uint64_t x; if (LOC >= MT_SIZE) { /* generate MT_SIZE words at one time */ static const uint64_t mag01[2]={ UINT64_C( 0), MATRIX_A}; uint64_t * RESTRICT endptr = mt + MT_SIZE - MM; while( mt < endptr) { x = (mt[0] & UM) | (mt[1] & LM); *mt = mt[MM] ^ (x >> 1) ^ mag01[(unsigned)x & 1u]; mt++; } endptr += MM - 1; while( mt < endptr) { x = (mt[0] & UM) | (mt[1] & LM); *mt = mt[MM - MT_SIZE] ^ (x >> 1) ^ mag01[(unsigned)x & 1u]; mt++; } mt -= MT_SIZE - 1; x = (mt[MT_SIZE-1] & UM) | (mt[0] & LM); mt[MT_SIZE-1] = mt[MM-1] ^ (x >> 1) ^ mag01[(unsigned)x & 1u]; LOC = 0; } x = mt[LOC++]; x ^= (x >> 29) & UINT64_C( 0x5555555555555555); x ^= (x << 17) & UINT64_C( 0x71D67FFFEDA60000); x ^= (x << 37) & UINT64_C( 0xFFF7EEE000000000); x ^= (x >> 43); return x; } /* The following (currently unused) function allows one to get n_bits of random bits at a time. Thus, for example, mt64_get_bits( mt, 2) will return a random value from 0 to 3. The benefit of this is that the full mt64() function would then be called only once every 32 times, and one has somewhat faster code. Another example: if you called mt64_get_bits( mt, 25) three times in a row, mt64( ) would be called the first time, generating 64 new random bits. 25 would be returned to the user, with 39 saved in LEFTOVER_BITS (and therefore, N_BITS_LEFT == 39). On the second call, 25 more bits would be extracted from LEFTOVER_BITS, with N_BITS_LEFT reset to 39-25=14. On the third call, we would see that we had only fourteen random bits; another call to mt64() would be made, with 25 of the resulting bits returned to the user and the remaining 39 put back into LEFTOVER_BITS. That would reset N_BITS_LEFT to 14+39 = 53 random bits. The potential pitfall is that it assumes that mt64() really returns random bits, and that no unexpected correlations will appear when examining them in, say, seven-bit increments. With a truly "random" source, the order in which bits are sent is obviously unimportant. But I don't _know_ for a certainty that MT-64 is sufficiently "random", and most tests run on it have presumably looked for correlations over 64-bit intervals rather than, say, seven-bit ones. As was said of the infamous RANDU generator (in _Numerical Recipes in C_): "We guarantee that each number is random individually, but we don't guarantee that more than one of them is random." MT64 is immensely more "random" than that generator, and I believe it's safe to get bits in this manner (and if it isn't, the solution should be to use a still better PRNG, rather than ignoring the problem; the "randomness" of a PRNG should not depend on the order in which bits are examined.) But, "caveat user". */ #ifdef CURRENTLY_UNUSED uint64_t mt64_get_bits( uint64_t *mt, const int n_bits) { uint64_t rval; if( (unsigned)n_bits <= N_BITS_LEFT) { /* yes, can just use bits */ rval = LEFTOVER_BITS; /* computed on previous calls */ LEFTOVER_BITS >>= n_bits; N_BITS_LEFT -= n_bits; } else /* no, gotta generate new bits */ { rval = mt64( mt); LEFTOVER_BITS ^= rval >> (n_bits - N_BITS_LEFT); N_BITS_LEFT += 64 - n_bits; } /* Mask off and return only the lowest 'n_bits' bits: */ return( rval & (((uint64_t)1 << n_bits) - (uint64_t)1)); } #endif /* The following generates a double on the [0,1) interval. I tried three methods: (1) the original one in the MT64 code, which takes a pseudo-random number, shifts it down, casts it to double, and multiplies it by 2^-53; (2) a modification of a method described in _Numerical Recipes_ that assumes 64-bit doubles in IEEE format, but which gets a type-punning warning in gcc; and (3) almost the same method, except by doing a memcpy(), the type-punning warning is avoided. (Any of the three methods can be selected with suitable #defines.) All three methods work Just Fine. The last two could have trouble if doubles aren't 64 bits or if they aren't in IEEE format. And it turns out (after running timing tests) that the performance of all three is essentially identical. About 80% of the time is spent in mt64() anyway; the efforts to convert the result to a double take up the remaining 20%, and that did not vary much between the three methods. Incidentally, I also tried the commented-out version: // const uint64_t rval = jflone | mt64_get_bits( mt, 52); My thought was that this would cut down on calls to mt64() by a factor of 52/64 = .8125, since we'd be only using 52 random bits at a time. However, mt64_get_bits() has some overhead; it actually was a little slower this way. It _could_ be a useful trick if one's PRNG was slower, though. Another completely commented out version attempts to be faster and provide somewhat better results. It's actually a little slower. The "better results" refers to the fact that the "usual" mt64_double has a granularity of 2^-53, even though doubles can represent numbers from .25 to .5 down to 2^-54, those from .125 to .25 down to 2^-55, and so on. It's hard to persuade me that this is really a problem. But if it were, something resembling the commented-out version would address it. */ #ifdef AVOID_TYPE_PUNNING #include <string.h> /* for memcpy( ) prototype */ #endif #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif double mt64_double( uint64_t * RESTRICT mt) { #ifdef NON_IEEE_WAY const double two_to_the_53rd_power = 9007199254740992.0; return (int64_t)(mt64( mt) >> 11) * (1.0 / two_to_the_53rd_power); #else const uint64_t jflone = UINT64_C( 0x3ff0000000000000); const uint64_t jflmsk = UINT64_C( 0x000fffffffffffff); const uint64_t rval = jflone | (jflmsk & mt64( mt)); // const uint64_t rval = jflone | mt64_get_bits( mt, 52); #ifndef AVOID_TYPE_PUNNING return( *((const double * RESTRICT)&rval) - 1.); #else double d_rval; memcpy( &d_rval, &rval, sizeof( double)); d_rval -= 1.; return( d_rval); #endif #endif } #ifdef __GNUC__ #pragma GCC diagnostic warning "-Wstrict-aliasing" #endif // double mt64_double( uint64_t * RESTRICT mt) // { // const uint64_t jflmsk = UINT64_C( 0x000fffffffffffff); // uint64_t rval = mt64( mt); // // if( rval & (UINT64_C( 1) << 63)) /* .5 <= returned value < 1 */ // rval = UINT64_C( 0x3fe0000000000000) | (jflmsk & rval); // else if( rval & (UINT64_C( 1) << 62)) /* .25 <= returned value < .5 */ // rval = UINT64_C( 0x3fd0000000000000) | (jflmsk & rval); // else if( rval & (UINT64_C( 1) << 61)) /* .125 <= returned value < .25 */ // rval = UINT64_C( 0x3fc0000000000000) | (jflmsk & rval); // else // { // const double two_to_the_64th_power = 65536. * 65536. * 65536. * 65536.; // return( (double)( (int64_t)rval) * (1. / two_to_the_64th_power)); // } // #ifndef AVOID_TYPE_PUNNING // return( *((const double * RESTRICT)&rval)); // #else // double d_rval; // // memcpy( &d_rval, &rval, sizeof( double)); // return( d_rval); // #endif // }
12,775
C
.c
288
40.395833
88
0.66605
Bill-Gray/prngs
10
1
0
GPL-3.0
9/7/2024, 10:57:50 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
5,717,974
dummydrv.c
fxcoudert_xmgrace/src/dummydrv.c
/* * Grace - GRaphing, Advanced Computation and Exploration of data * * Home page: http://plasma-gate.weizmann.ac.il/Grace/ * * Copyright (c) 1991-95 Paul J Turner, Portland, OR * Copyright (c) 1996-99 Grace Development Team * * Maintained by Evgeny Stambulchik * * * All Rights Reserved * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * Dummy (Null) driver for Grace */ #include <stdio.h> #include <stdlib.h> #include "defines.h" #include "draw.h" #include "device.h" #include "devlist.h" #include "dummydrv.h" static Device_entry dev_dummy = {DEVICE_TERM, "Dummy", dummyinitgraphics, NULL, NULL, "", TRUE, FALSE, {DEFAULT_PAGE_WIDTH, DEFAULT_PAGE_HEIGHT, 72.0}, NULL }; int register_dummy_drv(void) { return register_device(dev_dummy); } int dummyinitgraphics(void) { /* device-dependent routines */ devupdatecmap = NULL; devdrawpixel = dummy_drawpixel; devdrawpolyline = dummy_drawpolyline; devfillpolygon = dummy_fillpolygon; devdrawarc = dummy_drawarc; devfillarc = dummy_fillarc; devputpixmap = dummy_putpixmap; devputtext = dummy_puttext; devleavegraphics = dummy_leavegraphics; return RETURN_SUCCESS; } void dummy_drawpixel(VPoint vp){} void dummy_drawpolyline(VPoint *vps, int n, int mode){} void dummy_fillpolygon(VPoint *vps, int nc){} void dummy_drawarc(VPoint vp1, VPoint vp2, int a1, int a2){} void dummy_fillarc(VPoint vp1, VPoint vp2, int a1, int a2, int mode){} void dummy_putpixmap(VPoint vp, int width, int height, char *databits, int pixmap_bpp, int bitmap_pad, int pixmap_type){} void dummy_puttext(VPoint vp, char *s, int len, int font, TextMatrix *tm, int underline, int overline, int kerning){} void dummy_leavegraphics(void){}
2,593
C
.c
76
30.302632
74
0.689227
fxcoudert/xmgrace
10
5
0
GPL-2.0
9/7/2024, 10:58:07 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
5,932,989
bldc_interface_uart.c
fadh3r_synchronized_lighting_for_vesc/lib/bldc_uart/bldc_interface_uart.c
/* Copyright 2015 Benjamin Vedder [email protected] This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * bldc_interface_uart.c * * Created on: 9 okt 2015 * Author: benjamin */ #include "bldc_interface_uart.h" // #include "ch.h" // #include "hal.h" #include "bldc_interface.h" // Settings #define PACKET_HANDLER 0 // Private functions static void process_packet(unsigned char *data, unsigned int len); static void send_packet_bldc_interface(unsigned char *data, unsigned int len); /** * Initialize the UART BLDC interface and provide a function to be used for * sending packets. * * @param func * Function provided for sending packets. */ void bldc_interface_uart_init(void(*func)(unsigned char *data, unsigned int len)) { // Initialize packet handler packet_init(func, process_packet, PACKET_HANDLER); // Initialize the bldc interface and provide a send function bldc_interface_init(send_packet_bldc_interface); } /** * Process one byte received on the UART. Once a full packet is received the * corresponding callback will be called by bldc_interface. * * @param b * The byte received on the UART to process. */ void bldc_interface_uart_process_byte(unsigned char b) { packet_process_byte(b, PACKET_HANDLER); } /** * Call this function at around 1 khz to reset the state of the packet * interface after a timeout in case data is lost. */ void bldc_interface_uart_run_timer(void) { packet_timerfunc(); } /** * Callback for the packet handled for when a whole packet is received, * assembled and checked. * * @param data * Data array pointer * @param len * Data array length */ static void process_packet(unsigned char *data, unsigned int len) { // Let bldc_interface process the packet. bldc_interface_process_packet(data, len); } /** * Callback that bldc_interface uses to send packets. * * @param data * Data array pointer * @param len * Data array length */ static void send_packet_bldc_interface(unsigned char *data, unsigned int len) { // Pass the packet to the packet handler to add checksum, length, start and stop bytes. packet_send_packet(data, len, PACKET_HANDLER); }
2,752
C
.c
83
30.951807
88
0.75113
fadh3r/synchronized_lighting_for_vesc
17
6
0
GPL-3.0
9/7/2024, 10:59:26 AM (Europe/Amsterdam)
false
false
false
true
true
true
false
false
5,963,239
reg52.h
jiacai-wang_piano-C51/reg52.h
/*-------------------------------------------------------------------------- REG52.H Header file for generic 80C52 and 80C32 microcontroller. Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc. All rights reserved. --------------------------------------------------------------------------*/ #ifndef __REG52_H__ #define __REG52_H__ /* BYTE Registers */ sfr P0 = 0x80; sfr P1 = 0x90; sfr P2 = 0xA0; sfr P3 = 0xB0; sfr PSW = 0xD0; sfr ACC = 0xE0; sfr B = 0xF0; sfr SP = 0x81; sfr DPL = 0x82; sfr DPH = 0x83; sfr PCON = 0x87; sfr TCON = 0x88; sfr TMOD = 0x89; sfr TL0 = 0x8A; sfr TL1 = 0x8B; sfr TH0 = 0x8C; sfr TH1 = 0x8D; sfr IE = 0xA8; sfr IP = 0xB8; sfr SCON = 0x98; sfr SBUF = 0x99; /* 8052 Extensions */ sfr T2CON = 0xC8; sfr RCAP2L = 0xCA; sfr RCAP2H = 0xCB; sfr TL2 = 0xCC; sfr TH2 = 0xCD; /* BIT Registers */ /* PSW */ sbit CY = PSW^7; sbit AC = PSW^6; sbit F0 = PSW^5; sbit RS1 = PSW^4; sbit RS0 = PSW^3; sbit OV = PSW^2; sbit P = PSW^0; //8052 only /* TCON */ sbit TF1 = TCON^7; sbit TR1 = TCON^6; sbit TF0 = TCON^5; sbit TR0 = TCON^4; sbit IE1 = TCON^3; sbit IT1 = TCON^2; sbit IE0 = TCON^1; sbit IT0 = TCON^0; /* IE */ sbit EA = IE^7; sbit ET2 = IE^5; //8052 only sbit ES = IE^4; sbit ET1 = IE^3; sbit EX1 = IE^2; sbit ET0 = IE^1; sbit EX0 = IE^0; /* IP */ sbit PT2 = IP^5; sbit PS = IP^4; sbit PT1 = IP^3; sbit PX1 = IP^2; sbit PT0 = IP^1; sbit PX0 = IP^0; /* P3 */ sbit RD = P3^7; sbit WR = P3^6; sbit T1 = P3^5; sbit T0 = P3^4; sbit INT1 = P3^3; sbit INT0 = P3^2; sbit TXD = P3^1; sbit RXD = P3^0; /* SCON */ sbit SM0 = SCON^7; sbit SM1 = SCON^6; sbit SM2 = SCON^5; sbit REN = SCON^4; sbit TB8 = SCON^3; sbit RB8 = SCON^2; sbit TI = SCON^1; sbit RI = SCON^0; /* P1 */ sbit T2EX = P1^1; // 8052 only sbit T2 = P1^0; // 8052 only /* T2CON */ sbit TF2 = T2CON^7; sbit EXF2 = T2CON^6; sbit RCLK = T2CON^5; sbit TCLK = T2CON^4; sbit EXEN2 = T2CON^3; sbit TR2 = T2CON^2; sbit C_T2 = T2CON^1; sbit CP_RL2 = T2CON^0; #endif
2,282
C
.h
100
20.41
77
0.518449
jiacai-wang/piano-C51
15
3
0
GPL-3.0
9/7/2024, 10:59:53 AM (Europe/Amsterdam)
true
false
false
true
true
true
false
false
5,981,188
rtl8192e_hal.h
nicshaca_rtl8814au/include/rtl8192e_hal.h
/* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database; /** * This exception is thrown when a CursorWindow couldn't be allocated, * most probably due to memory not being available. * * @hide */ public class CursorWindowAllocationException extends RuntimeException { public CursorWindowAllocationException(String description) { super(description); } }
13,291
C
.h
215
55.04186
3,134
0.470981
nicshaca/rtl8814au
12
2
4
GPL-2.0
9/7/2024, 10:59:53 AM (Europe/Amsterdam)
false
false
true
true
false
false
false
false
5,981,210
rtl8188e_xmit.h
nicshaca_rtl8814au/include/rtl8188e_xmit.h
<!DOCTYPE HTML> <html> <head> <style> .swipeable { overflow: scroll; height: 200px; width: 200px; } .left-right-item, .top-bottom-item { height: 100px; width: 100px; } .left-right-item { display: inline-block; } .red-bg { background-color: red; } .blue-bg { background-color: blue; } .tall-and-wide { background-color: grey; height: 5000px; width: 5000px; } </style> </head> <body> <div id="left-right" class="swipeable"> <div style="width: 1000px;"> <div class="left-right-item red-bg">Test</div> <div class="left-right-item blue-bg">Test</div> <div class="left-right-item red-bg">Test</div> <div class="left-right-item blue-bg">Test</div> </div> </div> <div id="top-bottom" class="swipeable"> <div class="top-bottom-item red-bg">Test</div> <div class="top-bottom-item blue-bg">Test</div> <div class="top-bottom-item red-bg">Test</div> <div class="top-bottom-item blue-bg">Test</div> </div> <div class="tall-and-wide"></div> <div id="off-screen"></div> </body> </html>
7,614
C
.h
146
46.267123
3,073
0.365707
nicshaca/rtl8814au
12
2
4
GPL-2.0
9/7/2024, 10:59:53 AM (Europe/Amsterdam)
false
false
true
true
false
false
false
false
6,023,733
cell.c
skyformat99_TinyTor/tinytor/cell.c
/* * This file is part of TinyTor. * Copyright (C) 2018 Marten4n6 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "cell.h"
741
C
.c
18
39.222222
72
0.753463
skyformat99/TinyTor
11
1
0
GPL-3.0
9/7/2024, 11:00:29 AM (Europe/Amsterdam)
false
false
false
true
false
true
false
false
6,134,547
Maths.h
Bitl_Black-Shades-Enhanced/blackshades/Source/Maths.h
#ifndef _MATHS_H_ #define _MATHS_H_ /**> HEADER FILES <**/ #include <cmath> double fast_sqrt (register double arg); #endif
128
C
.h
6
19.5
39
0.709402
Bitl/Black-Shades-Enhanced
10
5
3
GPL-3.0
9/7/2024, 11:00:46 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,184,236
stringpool.c
byebyebruce_goweblua/c/pbc/stringpool.c
#include "alloc.h" #include <stdlib.h> #include <string.h> #define PAGE_SIZE 256 struct _stringpool { char * buffer; size_t len; struct _stringpool *next; }; struct _stringpool * _pbcS_new(void) { struct _stringpool * ret = (struct _stringpool *)malloc(sizeof(struct _stringpool) + PAGE_SIZE); ret->buffer = (char *)(ret + 1); ret->len = 0; ret->next = NULL; return ret; } void _pbcS_delete(struct _stringpool *pool) { while(pool) { struct _stringpool *next = pool->next; free(pool); pool = next; } } const char * _pbcS_build(struct _stringpool *pool, const char * str , int sz) { size_t s = sz + 1; if (s < PAGE_SIZE - pool->len) { char * ret = pool->buffer + pool->len; memcpy(pool->buffer + pool->len, str, s); pool->len += s; return ret; } if (s > PAGE_SIZE) { struct _stringpool * next = (struct _stringpool *)malloc(sizeof(struct _stringpool) + s); next->buffer = (char *)(next + 1); memcpy(next->buffer, str, s); next->len = s; next->next = pool->next; pool->next = next; return next->buffer; } struct _stringpool *next = (struct _stringpool *)malloc(sizeof(struct _stringpool) + PAGE_SIZE); next->buffer = pool->buffer; next->next = pool->next; next->len = pool->len; pool->next = next; pool->buffer = (char *)(next + 1); memcpy(pool->buffer, str, s); pool->len = s; return pool->buffer; }
1,359
C
.c
53
23.490566
97
0.658199
byebyebruce/goweblua
13
7
0
GPL-3.0
9/7/2024, 11:01:13 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
6,225,409
novascon.c
kirxkirx_vast/src/heliocentric_correction/novascon.c
/* Naval Observatory Vector Astrometry Software (NOVAS) C Edition, Version 3.1 novascon.c: Constants for use with NOVAS U. S. Naval Observatory Astronomical Applications Dept. Washington, DC http://www.usno.navy.mil/USNO/astronomical-applications */ #ifndef _CONSTS_ #include "novascon.h" #endif /* TDB Julian date of epoch J2000.0. */ const double T0= 2451545.00000000; /* Speed of light in meters/second is a defining physical constant. */ const double C= 299792458.0; /* Light-time for one astronomical unit (AU) in seconds, from DE-405. */ const double AU_SEC= 499.0047838061; /* Speed of light in AU/day. Value is 86400 / AU_SEC. */ const double C_AUDAY= 173.1446326846693; /* Astronomical unit in meters. Value is AU_SEC * C. */ const double AU= 1.4959787069098932e+11; /* Astronomical Unit in kilometers. */ const double AU_KM= 1.4959787069098932e+8; /* Heliocentric gravitational constant in meters^3 / second^2, from DE-405. */ const double GS= 1.32712440017987e+20; /* Geocentric gravitational constant in meters^3 / second^2, from DE-405. */ const double GE= 3.98600433e+14; /* Radius of Earth in meters from IERS Conventions (2003). */ const double ERAD= 6378136.6; /* Earth ellipsoid flattening from IERS Conventions (2003). Value is 1 / 298.25642. */ const double F= 0.003352819697896; /* Rotational angular velocity of Earth in radians/sec from IERS Conventions (2003). */ const double ANGVEL= 7.2921150e-5; /* Reciprocal masses of solar system bodies, from DE-405 (Sun mass / body mass). MASS[0] = Earth/Moon barycenter, MASS[1] = Mercury, ..., MASS[9] = Pluto, MASS[10] = Sun, MASS[11] = Moon. */ const double RMASS[12]= {328900.561400, 6023600.0, 408523.71, 332946.050895, 3098708.0, 1047.3486, 3497.898, 22902.98, 19412.24, 135200000.0, 1.0, 27068700.387534}; /* Value of 2 * pi in radians. */ const double TWOPI= 6.283185307179586476925287; /* Number of arcseconds in 360 degrees. */ const double ASEC360= 1296000.0; /* Angle conversion constants. */ const double ASEC2RAD= 4.848136811095359935899141e-6; const double DEG2RAD= 0.017453292519943296; const double RAD2DEG= 57.295779513082321;
2,280
C
.c
83
24.457831
81
0.724792
kirxkirx/vast
13
3
3
GPL-3.0
9/7/2024, 11:01:22 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
6,225,414
eph_manager.c
kirxkirx_vast/src/heliocentric_correction/eph_manager.c
/* Naval Observatory Vector Astrometry Software (NOVAS) C Edition, Version 3.1 eph_manager.c: C version of JPL Ephemeris Manager for use with solsys1 U. S. Naval Observatory Astronomical Applications Dept. Washington, DC http://www.usno.navy.mil/USNO/astronomical-applications */ #ifndef _EPHMAN_ #include "eph_manager.h" #endif /* Define global variables */ short int KM; /* IPT and LPT defined as int to support 64 bit systems. */ int IPT[3][12], LPT[3]; long int NRL, NP, NV; long int RECORD_LENGTH; double SS[3], JPLAU, PC[18], VC[18], TWOT, EM_RATIO; double *BUFFER; FILE *EPHFILE= NULL; /********ephem_open */ short int ephem_open( char *ephem_name, double *jd_begin, double *jd_end, short int *de_number ) /* ------------------------------------------------------------------------ PURPOSE: This function opens a JPL planetary ephemeris file and sets initial values. This function must be called prior to calls to the other JPL ephemeris functions. REFERENCES: Standish, E.M. and Newhall, X X (1988). "The JPL Export Planetary Ephemeris"; JPL document dated 17 June 1988. INPUT ARGUMENTS: *ephem_name (char) Name of the direct-access ephemeris file. OUTPUT ARGUMENTS: *jd_begin (double) Beginning Julian date of the ephemeris file. *jd_end (double) Ending Julian date of the ephemeris file. *de_number (short int) DE number of the ephemeris file opened. RETURNED VALUE: (short int) 0 ...file exists and is opened correctly. 1 ...file does not exist/not found. 2-10...error reading from file header. 11 ...unable to set record length; ephemeris (DE number) not in look-up table. GLOBALS USED: SS eph_manager.h JPLAU eph_manager.h PC eph_manager.h VC eph_manager.h TWOT eph_manager.h EM_RATIO eph_manager.h BUFFER eph_manager.h IPT eph_manager.h LPT eph_manager.h NRL eph_manager.h KM eph_manager.h NP eph_manager.h NV eph_manager.h RECORD_LENGTH eph_manager.h EPHFILE eph_manager.h FUNCTIONS CALLED: fclose stdio.h free stdlib.h fopen stdio.h fread stdio.h calloc stdlib.h VER./DATE/ PROGRAMMER: V1.0/06-90/JAB (USNO/NA) V1.1/06-92/JAB (USNO/AA): Restructure and add initializations. V1.2/07-98/WTH (USNO/AA): Modified to open files for different ephemeris types. (200,403,404,405,406) V1.3/11-07/WKP (USNO/AA): Updated prolog. V1.4/09-10/WKP (USNO/AA): Changed ncon and denum variables and sizeof ipt array to type 'int' for 64-bit system compatibility. V1.5/09-10/WTH (USNO/AA): Added support for DE421, default case for switch, close file on error. V1.6/10-10/WKP (USNO/AA): Renamed function to lowercase to comply with coding standards. NOTES: KM...flag defining physical units of the output states. = 1, km and km/sec = 0, AU and AU/day Default value is 0 (KM determines time unit for nutations. Angle unit is always radians.) ------------------------------------------------------------------------ */ { char ttl[252], cnam[2400]; short int i, j; int ncon, denum; if ( EPHFILE ) { fclose( EPHFILE ); free( BUFFER ); } /* Open file ephem_name. */ if ( ( EPHFILE= fopen( ephem_name, "rb" ) ) == NULL ) { return 1; } else { /* File found. Set initializations and default values. */ KM= 0; NRL= 0; NP= 2; NV= 3; TWOT= 0.0; for ( i= 0; i < 18; i++ ) { PC[i]= 0.0; VC[i]= 0.0; } PC[0]= 1.0; VC[1]= 1.0; /* Read in values from the first record, aka the header. */ if ( fread( ttl, sizeof ttl, 1, EPHFILE ) != 1 ) { fclose( EPHFILE ); return 2; } if ( fread( cnam, sizeof cnam, 1, EPHFILE ) != 1 ) { fclose( EPHFILE ); return 3; } if ( fread( SS, sizeof SS, 1, EPHFILE ) != 1 ) { fclose( EPHFILE ); return 4; } if ( fread( &ncon, sizeof ncon, 1, EPHFILE ) != 1 ) { fclose( EPHFILE ); return 5; } if ( fread( &JPLAU, sizeof JPLAU, 1, EPHFILE ) != 1 ) { fclose( EPHFILE ); return 6; } if ( fread( &EM_RATIO, sizeof EM_RATIO, 1, EPHFILE ) != 1 ) { fclose( EPHFILE ); return 7; } for ( i= 0; i < 12; i++ ) for ( j= 0; j < 3; j++ ) if ( fread( &IPT[j][i], sizeof( int ), 1, EPHFILE ) != 1 ) { fclose( EPHFILE ); return 8; } if ( fread( &denum, sizeof denum, 1, EPHFILE ) != 1 ) { fclose( EPHFILE ); return 9; } if ( fread( LPT, sizeof LPT, 1, EPHFILE ) != 1 ) { fclose( EPHFILE ); return 10; } /* Set the value of the record length according to what JPL ephemeris is being opened. */ switch ( denum ) { case 200: RECORD_LENGTH= 6608; break; case 403: case 405: case 421: RECORD_LENGTH= 8144; break; case 404: case 406: RECORD_LENGTH= 5824; break; /* An unknown DE file was opened. Close the file and return an error code. */ default: *jd_begin= 0.0; *jd_end= 0.0; *de_number= 0; fclose( EPHFILE ); return 11; break; } BUFFER= (double *)calloc( RECORD_LENGTH / 8, sizeof( double ) ); *de_number= (short int)denum; *jd_begin= SS[0]; *jd_end= SS[1]; } return 0; } /********ephem_close */ short int ephem_close( void ) /* ------------------------------------------------------------------------ PURPOSE: This function closes a JPL planetary ephemeris file and frees the memory. REFERENCES: Standish, E.M. and Newhall, X X (1988). "The JPL Export Planetary Ephemeris"; JPL document dated 17 June 1988. INPUT ARGUMENTS: None. OUTPUT ARGUMENTS: None. RETURNED VALUE: (short int) 0 ...file was already closed or closed correctly. EOF...error closing file. GLOBALS USED: BUFFER eph_manager.h EPHFILE eph_manager.h FUNCTIONS CALLED: fclose stdio.h free stdlib.h VER./DATE/ PROGRAMMER: V1.0/11-07/WKP (USNO/AA) V1.1/09-10/WKP (USNO/AA): Explicitly cast fclose return value to type 'short int'. V1.2/10-10/WKP (USNO/AA): Renamed function to lowercase to comply with coding standards. NOTES: None. ------------------------------------------------------------------------ */ { short int error= 0; if ( EPHFILE ) { error= (short int)fclose( EPHFILE ); free( BUFFER ); } return error; } /********planet_ephemeris */ short int planet_ephemeris( double tjd[2], short int target, short int center, double *position, double *velocity ) /* ------------------------------------------------------------------------ PURPOSE: This function accesses the JPL planetary ephemeris to give the position and velocity of the target object with respect to the center object. REFERENCES: Standish, E.M. and Newhall, X X (1988). "The JPL Export Planetary Ephemeris"; JPL document dated 17 June 1988. INPUT ARGUMENTS: tjd[2] (double) Two-element array containing the Julian date, which may be split any way (although the first element is usually the "integer" part, and the second element is the "fractional" part). Julian date is in the TDB or "T_eph" time scale. target (short int) Number of 'target' point. center (short int) Number of 'center' (origin) point. The numbering convention for 'target' and'center' is: 0 = Mercury 7 = Neptune 1 = Venus 8 = Pluto 2 = Earth 9 = Moon 3 = Mars 10 = Sun 4 = Jupiter 11 = Solar system bary. 5 = Saturn 12 = Earth-Moon bary. 6 = Uranus 13 = Nutations (long int. and obliq.) (If nutations are desired, set 'target' = 13; 'center' will be ignored on that call.) OUTPUT ARGUMENTS: *position (double) Position vector array of target relative to center, measured in AU. *velocity (double) Velocity vector array of target relative to center, measured in AU/day. RETURNED VALUE: (short int) 0 ...everything OK. 1,2...error returned from State. GLOBALS USED: EM_RATIO eph_manager.h FUNCTIONS CALLED: state eph_manager.h VER./DATE/ PROGRAMMER: V1.0/03-93/WTH (USNO/AA): Convert FORTRAN to C. V1.1/07-93/WTH (USNO/AA): Update to C standards. V2.0/07-98/WTH (USNO/AA): Modified for ease of use and linearity. V3.0/11-06/JAB (USNO/AA): Allowed for use of input 'split' Julian date for higher precision. V3.1/11-07/WKP (USNO/AA): Updated prolog and error codes. V3.1/12-07/WKP (USNO/AA): Removed unreferenced variables. V3.2/10-10/WKP (USNO/AA): Renamed function to lowercase to comply with coding standards. NOTES: None. ------------------------------------------------------------------------ */ { short int i, error= 0, earth= 2, moon= 9; short int do_earth= 0, do_moon= 0; double jed[2]; double pos_moon[3]= {0.0, 0.0, 0.0}, vel_moon[3]= {0.0, 0.0, 0.0}, pos_earth[3]= {0.0, 0.0, 0.0}, vel_earth[3]= {0.0, 0.0, 0.0}; double target_pos[3]= {0.0, 0.0, 0.0}, target_vel[3]= {0.0, 0.0, 0.0}, center_pos[3]= {0.0, 0.0, 0.0}, center_vel[3]= {0.0, 0.0, 0.0}; /* Initialize 'jed' for 'state' and set up component count. */ jed[0]= tjd[0]; jed[1]= tjd[1]; /* Check for target point = center point. */ if ( target == center ) { for ( i= 0; i < 3; i++ ) { position[i]= 0.0; velocity[i]= 0.0; } return 0; } /* Check for instances of target or center being Earth or Moon, and for target or center being the Earth-Moon barycenter. */ if ( ( target == earth ) || ( center == earth ) ) do_moon= 1; if ( ( target == moon ) || ( center == moon ) ) do_earth= 1; if ( ( target == 12 ) || ( center == 12 ) ) do_earth= 1; if ( do_earth ) { error= state( jed, 2, pos_earth, vel_earth ); if ( error ) return error; } if ( do_moon ) { error= state( jed, 9, pos_moon, vel_moon ); if ( error ) return error; } /* Make call to State for target object. */ if ( target == 11 ) { for ( i= 0; i < 3; i++ ) { target_pos[i]= 0.0; target_vel[i]= 0.0; } } else if ( target == 12 ) { for ( i= 0; i < 3; i++ ) { target_pos[i]= pos_earth[i]; target_vel[i]= vel_earth[i]; } } else error= state( jed, target, target_pos, target_vel ); if ( error ) return error; /* Make call to State for center object. */ /* If the requested center is the Solar System barycenter, then don't bother with a second call to State. */ if ( center == 11 ) { for ( i= 0; i < 3; i++ ) { center_pos[i]= 0.0; center_vel[i]= 0.0; } } /* Center is Earth-Moon barycenter, which was already computed above. */ else if ( center == 12 ) { for ( i= 0; i < 3; i++ ) { center_pos[i]= pos_earth[i]; center_vel[i]= vel_earth[i]; } } else error= state( jed, center, center_pos, center_vel ); if ( error ) return error; /* Check for cases of Earth as target and Moon as center or vice versa. */ if ( ( target == earth ) && ( center == moon ) ) { for ( i= 0; i < 3; i++ ) { position[i]= -center_pos[i]; velocity[i]= -center_vel[i]; } return 0; } else if ( ( target == moon ) && ( center == earth ) ) { for ( i= 0; i < 3; i++ ) { position[i]= target_pos[i]; velocity[i]= target_vel[i]; } return 0; } /* Check for Earth as target, or as center. */ else if ( target == earth ) { for ( i= 0; i < 3; i++ ) { target_pos[i]= target_pos[i] - ( pos_moon[i] / ( 1.0 + EM_RATIO ) ); target_vel[i]= target_vel[i] - ( vel_moon[i] / ( 1.0 + EM_RATIO ) ); } } else if ( center == earth ) { for ( i= 0; i < 3; i++ ) { center_pos[i]= center_pos[i] - ( pos_moon[i] / ( 1.0 + EM_RATIO ) ); center_vel[i]= center_vel[i] - ( vel_moon[i] / ( 1.0 + EM_RATIO ) ); } } /* Check for Moon as target, or as center. */ else if ( target == moon ) { for ( i= 0; i < 3; i++ ) { target_pos[i]= ( pos_earth[i] - ( target_pos[i] / ( 1.0 + EM_RATIO ) ) ) + target_pos[i]; target_vel[i]= ( vel_earth[i] - ( target_vel[i] / ( 1.0 + EM_RATIO ) ) ) + target_vel[i]; } } else if ( center == moon ) { for ( i= 0; i < 3; i++ ) { center_pos[i]= ( pos_earth[i] - ( center_pos[i] / ( 1.0 + EM_RATIO ) ) ) + center_pos[i]; center_vel[i]= ( vel_earth[i] - ( center_vel[i] / ( 1.0 + EM_RATIO ) ) ) + center_vel[i]; } } /* Compute position and velocity vectors. */ for ( i= 0; i < 3; i++ ) { position[i]= target_pos[i] - center_pos[i]; velocity[i]= target_vel[i] - center_vel[i]; } return 0; } /********state */ short int state( double *jed, short int target, double *target_pos, double *target_vel ) /* ------------------------------------------------------------------------ PURPOSE: This function reads and interpolates the JPL planetary ephemeris file. REFERENCES: Standish, E.M. and Newhall, X X (1988). "The JPL Export Planetary Ephemeris"; JPL document dated 17 June 1988. INPUT ARGUMENTS: *jed (double) 2-element Julian date (TDB) at which interpolation is wanted. Any combination of jed[0]+jed[1] which falls within the time span on the file is a permissible epoch. See Note 1 below. target (short int) The requested body to get data for from the ephemeris file. The designation of the astronomical bodies is: 0 = Mercury 6 = Uranus 1 = Venus 7 = Neptune 2 = Earth-Moon barycenter 8 = Pluto 3 = Mars 9 = geocentric Moon 4 = Jupiter 10 = Sun 5 = Saturn OUTPUT ARGUMENTS: *target_pos (double) The barycentric position vector array of the requested object, in AU. (If target object is the Moon, then the vector is geocentric.) *target_vel (double) The barycentric velocity vector array of the requested object, in AU/Day. Both vectors are referenced to the Earth mean equator and equinox of epoch. RETURNED VALUE: (short int) 0...everything OK. 1...error reading ephemeris file. 2...epoch out of range. GLOBALS USED: KM eph_manager.h EPHFILE eph_manager.h IPT eph_manager.h BUFFER eph_manager.h NRL eph_manager.h RECORD_LENGTH eph_manager.h SS eph_manager.h JPLAU eph_manager.h FUNCTIONS CALLED: split eph_manager.h fseek stdio.h fread stdio.h interpolate eph_manager.h ephem_close eph_manager.h VER./DATE/ PROGRAMMER: V1.0/03-93/WTH (USNO/AA): Convert FORTRAN to C. V1.1/07-93/WTH (USNO/AA): Update to C standards. V2.0/07-98/WTH (USNO/AA): Modify to make position and velocity two distinct vector arrays. Routine set to compute one state per call. V2.1/11-07/WKP (USNO/AA): Updated prolog. V2.2/10-10/WKP (USNO/AA): Renamed function to lowercase to comply with coding standards. NOTES: 1. For ease in programming, the user may put the entire epoch in jed[0] and set jed[1] = 0. For maximum interpolation accuracy, set jed[0] = the most recent midnight at or before interpolation epoch, and set jed[1] = fractional part of a day elapsed between jed[0] and epoch. As an alternative, it may prove convenient to set jed[0] = some fixed epoch, such as start of the integration and jed[1] = elapsed interval between then and epoch. ------------------------------------------------------------------------ */ { short int i; long int nr, rec; double t[2], aufac= 1.0, jd[4], s; /* Set units based on value of the 'KM' flag. */ if ( KM ) t[1]= SS[2] * 86400.0; else { t[1]= SS[2]; aufac= 1.0 / JPLAU; } /* Check epoch. */ s= jed[0] - 0.5; split( s, &jd[0] ); split( jed[1], &jd[2] ); jd[0]+= jd[2] + 0.5; jd[1]+= jd[3]; split( jd[1], &jd[2] ); jd[0]+= jd[2]; /* Return error code if date is out of range. */ if ( ( jd[0] < SS[0] ) || ( ( jd[0] + jd[3] ) > SS[1] ) ) return 2; /* Calculate record number and relative time interval. */ nr= (long int)( ( jd[0] - SS[0] ) / SS[2] ) + 3; if ( jd[0] == SS[1] ) nr-= 2; t[0]= ( ( jd[0] - ( (double)( nr - 3 ) * SS[2] + SS[0] ) ) + jd[3] ) / SS[2]; /* Read correct record if it is not already in memory. */ if ( nr != NRL ) { NRL= nr; rec= ( nr - 1 ) * RECORD_LENGTH; fseek( EPHFILE, rec, SEEK_SET ); if ( !fread( BUFFER, RECORD_LENGTH, 1, EPHFILE ) ) { ephem_close(); return 1; } } /* Check and interpolate for requested body. */ interpolate( &BUFFER[IPT[0][target] - 1], t, IPT[1][target], IPT[2][target], target_pos, target_vel ); for ( i= 0; i < 3; i++ ) { target_pos[i]*= aufac; target_vel[i]*= aufac; } return 0; } /********interpolate */ void interpolate( double *buf, double *t, long int ncf, long int na, double *position, double *velocity ) /* ------------------------------------------------------------------------ PURPOSE: This function differentiates and interpolates a set of Chebyshev coefficients to give position and velocity. REFERENCES: Standish, E.M. and Newhall, X X (1988). "The JPL Export Planetary Ephemeris"; JPL document dated 17 June 1988. INPUT ARGUMENTS: *buf (double) Array of Chebyshev coefficients of position. *t (double) t[0] is fractional time interval covered by coefficients at which interpolation is desired (0 <= t[0] <= 1). t[1] is length of whole interval in input time units. ncf (long int) Number of coefficients per component. na (long int) Number of sets of coefficients in full array (i.e., number of sub-intervals in full interval). OUTPUT ARGUMENTS: *position (double) Position array of requested object. *velocity (double) Velocity array of requested object. RETURNED VALUE: None. GLOBALS USED: NP eph_manager.h NV eph_manager.h PC eph_manager.h VC eph_manager.h TWOT eph_manager.h FUNCTIONS CALLED: fmod math.h VER./DATE/ PROGRAMMER: V1.0/03-93/WTH (USNO/AA): Convert FORTRAN to C. V1.1/07-93/WTH (USNO/AA): Update to C standards. V1.2/07-98/WTH (USNO/AA): Modify to make position and velocity two distinct vector arrays. V1.3/11-07/WKP (USNO/AA): Updated prolog. V1.4/12-07/WKP (USNO/AA): Changed ncf and na arguments from short int to long int. V1.5/10-10/WKP (USNO/AA): Renamed function to lowercase to comply with coding standards. NOTES: None. ------------------------------------------------------------------------ */ { long int i, j, k, l; double dna, dt1, temp, tc, vfac; /* Get correct sub-interval number for this set of coefficients and then get normalized Chebyshev time within that subinterval. */ dna= (double)na; dt1= (double)( (long int)t[0] ); temp= dna * t[0]; l= (long int)( temp - dt1 ); /* 'tc' is the normalized Chebyshev time (-1 <= tc <= 1). */ tc= 2.0 * ( fmod( temp, 1.0 ) + dt1 ) - 1.0; /* Check to see whether Chebyshev time has changed, and compute new polynomial values if it has. (The element PC[1] is the value of t1[tc] and hence contains the value of 'tc' on the previous call.) */ if ( tc != PC[1] ) { NP= 2; NV= 3; PC[1]= tc; TWOT= tc + tc; } /* Be sure that at least 'ncf' polynomials have been evaluated and are stored in the array 'PC'. */ if ( NP < ncf ) { for ( i= NP; i < ncf; i++ ) PC[i]= TWOT * PC[i - 1] - PC[i - 2]; NP= ncf; } /* Interpolate to get position for each component. */ for ( i= 0; i < 3; i++ ) { position[i]= 0.0; for ( j= ncf - 1; j >= 0; j-- ) { k= j + ( i * ncf ) + ( l * ( 3 * ncf ) ); position[i]+= PC[j] * buf[k]; } } /* If velocity interpolation is desired, be sure enough derivative polynomials have been generated and stored. */ vfac= ( 2.0 * dna ) / t[1]; VC[2]= 2.0 * TWOT; if ( NV < ncf ) { for ( i= NV; i < ncf; i++ ) VC[i]= TWOT * VC[i - 1] + PC[i - 1] + PC[i - 1] - VC[i - 2]; NV= ncf; } /* Interpolate to get velocity for each component. */ for ( i= 0; i < 3; i++ ) { velocity[i]= 0.0; for ( j= ncf - 1; j > 0; j-- ) { k= j + ( i * ncf ) + ( l * ( 3 * ncf ) ); velocity[i]+= VC[j] * buf[k]; } velocity[i]*= vfac; } return; } /********split */ void split( double tt, double *fr ) /* ------------------------------------------------------------------------ PURPOSE: This function breaks up a double number into a double integer part and a fractional part. REFERENCES: Standish, E.M. and Newhall, X X (1988). "The JPL Export Planetary Ephemeris"; JPL document dated 17 June 1988. INPUT ARGUMENTS: tt (double) Input number. OUTPUT ARGUMENTS: *fr (double) 2-element output array; fr[0] contains integer part, fr[1] contains fractional part. For negative input numbers, fr[0] contains the next more negative integer; fr[1] contains a positive fraction. RETURNED VALUE: None. GLOBALS USED: None. FUNCTIONS CALLED: None. VER./DATE/ PROGRAMMER: V1.0/06-90/JAB (USNO/NA): CA coding standards V1.1/03-93/WTH (USNO/AA): Convert to C. V1.2/07-93/WTH (USNO/AA): Update to C standards. V1.3/10-10/WKP (USNO/AA): Renamed function to lowercase to comply with coding standards. NOTES: None. ------------------------------------------------------------------------ */ { /* Get integer and fractional parts. */ fr[0]= (double)( (long int)tt ); fr[1]= tt - fr[0]; /* Make adjustments for negative input number. */ if ( ( tt >= 0.0 ) || ( fr[1] == 0.0 ) ) return; else { fr[0]= fr[0] - 1.0; fr[1]= fr[1] + 1.0; } return; }
24,057
C
.c
802
24.127182
78
0.538385
kirxkirx/vast
13
3
3
GPL-3.0
9/7/2024, 11:01:22 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
6,225,416
novas.c
kirxkirx_vast/src/heliocentric_correction/novas.c
/* Naval Observatory Vector Astrometry Software (NOVAS) C Edition, Version 3.1 novas.c: Main library U. S. Naval Observatory Astronomical Applications Dept. Washington, DC http://www.usno.navy.mil/USNO/astronomical-applications */ #ifndef _NOVAS_ #include "novas.h" #endif #include <math.h> /* Global variables. 'PSI_COR' and 'EPS_COR' are celestial pole offsets for high- precision applications. See function 'cel_pole' for more details. */ static double PSI_COR= 0.0; static double EPS_COR= 0.0; /********app_star */ short int app_star( double jd_tt, cat_entry *star, short int accuracy, double *ra, double *dec ) /* ------------------------------------------------------------------------ PURPOSE: Computes the apparent place of a star at date 'jd_tt', given its catalog mean place, proper motion, parallax, and radial velocity. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for apparent place. *star (struct cat_entry) Pointer to catalog entry structure containing catalog data for the object in the ICRS (defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Apparent right ascension in hours, referred to true equator and equinox of date 'jd_tt'. *dec (double) Apparent declination in degrees, referred to true equator and equinox of date 'jd_tt'. RETURNED VALUE: (short int) = 0 ... Everything OK. > 10 ... Error code from function 'make_object'. > 20 ... Error code from function 'place'. GLOBALS USED: SIZE_OF_OBJ_NAME novas.h FUNCTIONS CALLED: make_object novas.c place novas.c strcpy string.h VER./DATE/ PROGRAMMER: V1.0/12-05/JAB (USNO/AA) V1.1/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.2/10-08/JAB (USNO/AA): Add 'accuracy' option to input. V1.3/05-10/JAB (USNO/AA): Fix bug in set-up of 'obj_name'. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'apstar'. 2. SIZE_OF_OBJ_NAME is defined in novas.h ------------------------------------------------------------------------ */ { char obj_name[SIZE_OF_OBJ_NAME]; short int error= 0; short int type, number, coord_sys; double delta_t= 0.0; object cel_obj; observer location; sky_pos output; /* Set 'obj_name' equal to 'starname' in the 'star' structure. Length will be checked in 'make_object'. */ strcpy( obj_name, star->starname ); /* Set up a structure of type 'object' containing the star data. */ type= 2; /* Object located outside the solar system */ number= 0; /* Set to zero */ if ( ( error= make_object( type, number, obj_name, star, &cel_obj ) ) != 0 ) { error+= 10; return ( error ); } /* Compute the apparent place with a call to function 'place'. */ location.where= 0; /* Geocenter */ coord_sys= 1; /* True equator and equinox of date */ if ( ( error= place( jd_tt, &cel_obj, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; error+= 20; } else { *ra= output.ra; *dec= output.dec; } return ( error ); } /********virtual_star */ short int virtual_star( double jd_tt, cat_entry *star, short int accuracy, double *ra, double *dec ) /* ------------------------------------------------------------------------ PURPOSE: Computes the virtual place of a star at date 'jd_tt', given its catalog mean place, proper motion, parallax, and radial velocity. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for virtual place. *star (struct cat_entry) Pointer to catalog entry structure containing catalog data for the object in the ICRS (defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Virtual right ascension in hours, referred to the GCRS. *dec (double) Virtual declination in degrees, referred to the GCRS. RETURNED VALUE: (short int) = 0 ... Everything OK. > 10 ... Error code from function 'make_object'. > 20 ... Error code from function 'place'. GLOBALS USED: SIZE_OF_OBJ_NAME novas.h FUNCTIONS CALLED: make_object novas.c place novas.c strcpy string.h VER./DATE/ PROGRAMMER: V1.0/12-05/JAB (USNO/AA) V1.1/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.2/10-08/JAB (USNO/AA): Add 'accuracy' option to input. V1.3/05-10/JAB (USNO/AA): Fix bug in set-up of 'obj_name'. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'vpstar'. 2. SIZE_OF_OBJ_NAME is defined in novas.h ------------------------------------------------------------------------ */ { char obj_name[SIZE_OF_OBJ_NAME]; short int error= 0; short int type, number, coord_sys; double delta_t= 0.0; object cel_obj; observer location; sky_pos output; /* Set 'obj_name' equal to 'starname' in the 'star' structure. Length will be checked in 'make_object'. */ strcpy( obj_name, star->starname ); /* Set up a structure of type 'object' containing the star data. */ type= 2; /* Object located outside the solar system */ number= 0; /* Set to zero */ if ( ( error= make_object( type, number, obj_name, star, &cel_obj ) ) != 0 ) { error+= 10; return ( error ); } /* Compute the virtual place with a call to function 'place'. */ location.where= 0; /* Geocenter */ coord_sys= 0; /* GCRS */ if ( ( error= place( jd_tt, &cel_obj, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; error+= 20; } else { *ra= output.ra; *dec= output.dec; } return ( error ); } /********astro_star */ short int astro_star( double jd_tt, cat_entry *star, short int accuracy, double *ra, double *dec ) /* ------------------------------------------------------------------------ PURPOSE: Computes the astrometric place of a star at date 'jd_tt', given its catalog mean place, proper motion, parallax, and radial velocity. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for astrometric place. *star (struct cat_entry) Pointer to catalog entry structure containing catalog data for the object in the ICRS (defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Astrometric right ascension in hours (referred to the ICRS, without light deflection or aberration). *dec (double) Astrometric declination in degrees (referred to the ICRS, without light deflection or aberration). RETURNED VALUE: (short int) = 0 ... Everything OK. > 10 ... Error code from function 'make_object'. > 20 ... Error code from function 'place'. GLOBALS USED: SIZE_OF_OBJ_NAME novas.h FUNCTIONS CALLED: make_object novas.c place novas.c strcpy string.h VER./DATE/ PROGRAMMER: V1.0/12-05/JAB (USNO/AA) V1.1/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.2/10-08/JAB (USNO/AA): Add 'accuracy' option to input. V1.3/05-10/JAB (USNO/AA): Fix bug in set-up of 'obj_name'. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'asstar'. 2. SIZE_OF_OBJ_NAME is defined in novas.h ------------------------------------------------------------------------ */ { char obj_name[SIZE_OF_OBJ_NAME]; short int error= 0; short int type, number, coord_sys; double delta_t= 0.0; object cel_obj; observer location; sky_pos output; /* Set 'obj_name' equal to 'starname' in the 'star' structure. Length will be checked in 'make_object'. */ strcpy( obj_name, star->starname ); /* Set up a structure of type 'object' containing the star data. */ type= 2; /* Object located outside the solar system */ number= 0; /* Set to zero */ if ( ( error= make_object( type, number, obj_name, star, &cel_obj ) ) != 0 ) { error+= 10; return ( error ); } /* Compute the astrometric place with a call to function 'place'. */ location.where= 0; /* Geocenter */ coord_sys= 3; /* ICRS astrometric coordinates */ if ( ( error= place( jd_tt, &cel_obj, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; error+= 20; } else { *ra= output.ra; *dec= output.dec; } return ( error ); } /********app_planet */ short int app_planet( double jd_tt, object *ss_body, short int accuracy, double *ra, double *dec, double *dis ) /* ------------------------------------------------------------------------ PURPOSE: Compute the apparent place of a solar system body. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for apparent place. *ss_body (struct object) Pointer to structure containing the body designation for the solar system body (defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Apparent right ascension in hours, referred to true equator and equinox of date. *dec (double) Apparent declination in degrees, referred to true equator and equinox of date. *dis (double) True distance from Earth to the body at 'jd_tt' in AU. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... Invalid value of 'type' in structure 'ss_body'. > 10 ... Error code from function 'place'. GLOBALS USED: None. FUNCTIONS CALLED: place novas.c VER./DATE/ PROGRAMMER: V1.0/12-05/JAB (USNO/AA) V1.1/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.2/10-08/JAB (USNO/AA): Add 'accuracy' option to input. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'applan'. ------------------------------------------------------------------------ */ { short int error= 0; short int coord_sys; double delta_t= 0.0; observer location; sky_pos output; /* Check for a valid value of 'type' in structure 'ss_body'. */ if ( ( ss_body->type < 0 ) || ( ss_body->type > 1 ) ) { error= 1; return ( error ); } /* Compute the apparent place with a call to function 'place'. */ location.where= 0; /* Geocenter */ coord_sys= 1; /* True equator and equinox of date */ if ( ( error= place( jd_tt, ss_body, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; *dis= 0.0; error+= 10; } else { *ra= output.ra; *dec= output.dec; *dis= output.dis; } return ( error ); } /********virtual_planet */ short int virtual_planet( double jd_tt, object *ss_body, short int accuracy, double *ra, double *dec, double *dis ) /* ------------------------------------------------------------------------ PURPOSE: Compute the virtual place of a solar system body. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for virtual place. *ss_body (struct object) Pointer to structure containing the body designation for the solar system body (defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Virtual right ascension in hours, referred to the GCRS. *dec (double) Virtual declination in degrees, referred to the GCRS. *dis (double) True distance from Earth to the body in AU. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... Invalid value of 'type' in structure 'ss_body'. > 10 ... Error code from function 'place'. GLOBALS USED: None. FUNCTIONS CALLED: place novas.c VER./DATE/ PROGRAMMER: V1.0/12-05/JAB (USNO/AA) V1.1/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.2/10-08/JAB (USNO/AA): Add 'accuracy' option to input. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'vpplan'. ------------------------------------------------------------------------ */ { short int error= 0; short int coord_sys; double delta_t= 0.0; observer location; sky_pos output; /* Check for a valid value of 'type' in structure 'ss_body'. */ if ( ( ss_body->type < 0 ) || ( ss_body->type > 1 ) ) { error= 1; return ( error ); } /* Compute the virtual place with a call to function 'place'. */ location.where= 0; /* Geocenter */ coord_sys= 0; /* GCRS */ if ( ( error= place( jd_tt, ss_body, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; *dis= 0.0; error+= 10; } else { *ra= output.ra; *dec= output.dec; *dis= output.dis; } return ( error ); } /********astro_planet */ short int astro_planet( double jd_tt, object *ss_body, short int accuracy, double *ra, double *dec, double *dis ) /* ------------------------------------------------------------------------ PURPOSE: Compute the astrometric place of a solar system body. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for astrometric place. *ss_body (struct object) Pointer to structure containing the body designation for the solar system body (defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Astrometric right ascension in hours (referred to the ICRS, without light deflection or aberration). *dec (double) Astrometric declination in degrees (referred to the ICRS, without light deflection or aberration). *dis (double) True distance from Earth to the body in AU. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... Invalid value of 'type' in structure 'ss_body'. > 10 ... Error code from function 'place'. GLOBALS USED: None. FUNCTIONS CALLED: place novas.c VER./DATE/ PROGRAMMER: V1.0/12-05/JAB (USNO/AA) V1.1/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.2/10-08/JAB (USNO/AA): Add 'accuracy' option to input. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'asplan'. ------------------------------------------------------------------------ */ { short int error= 0; short int coord_sys; double delta_t= 0.0; observer location; sky_pos output; /* Check for a valid value of 'type' in structure 'ss_body'. */ if ( ( ss_body->type < 0 ) || ( ss_body->type > 1 ) ) { error= 1; return ( error ); } /* Compute the astrometric place with a call to function 'place'. */ location.where= 0; /* Geocenter */ coord_sys= 3; /* ICRS astrometric coordinates */ if ( ( error= place( jd_tt, ss_body, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; *dis= 0.0; error+= 10; } else { *ra= output.ra; *dec= output.dec; *dis= output.dis; } return ( error ); } /********topo_star */ short int topo_star( double jd_tt, double delta_t, cat_entry *star, on_surface *position, short int accuracy, double *ra, double *dec ) /* ------------------------------------------------------------------------ PURPOSE: Computes the topocentric place of a star at date 'jd_tt', given its catalog mean place, proper motion, parallax, and radial velocity. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for topocentric place. delta_t (double) Difference TT-UT1 at 'jd_tt', in seconds of time. *star (struct cat_entry) Pointer to catalog entry structure containing catalog data for the object in the ICRS (defined in novas.h). *position (struct on_surface) Specifies the position of the observer (structure defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Topocentric right ascension in hours, referred to true equator and equinox of date 'jd_tt'. *dec (double) Topocentric declination in degrees, referred to true equator and equinox of date 'jd_tt'. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... Invalid value of 'where' in structure 'location'. > 10 ... Error code from function 'make_object'. > 20 ... Error code from function 'place'. GLOBALS USED: SIZE_OF_OBJ_NAME novas.h FUNCTIONS CALLED: make_observer novas.c make_object novas.c place novas.c strcpy string.h VER./DATE/ PROGRAMMER: V1.0/01-06/JAB (USNO/AA) V1.1/01-06/WKP (USNO/AA): Fixed minor syntax problem. V1.2/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.3/10-08/JAB (USNO/AA): Add 'accuracy' option to input. V1.4/05-10/JAB (USNO/AA): Fix bug in set-up of 'obj_name'. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'tpstar'. 2. SIZE_OF_OBJ_NAME is defined in novas.h ------------------------------------------------------------------------ */ { char obj_name[SIZE_OF_OBJ_NAME]; short int error= 0; short int type, number, coord_sys; in_space dummy; observer location; object cel_obj; sky_pos output; /* Initialize the 'dummy' structure. */ dummy.sc_pos[0]= dummy.sc_pos[1]= dummy.sc_pos[2]= 0.0; dummy.sc_vel[0]= dummy.sc_vel[1]= dummy.sc_vel[2]= 0.0; /* Set up a structure of type 'observer' containing the position of the observer. */ if ( ( error= make_observer( 1, position, &dummy, &location ) ) != 0 ) { error= 1; return ( error ); } /* Set 'obj_name' equal to 'starname' in the 'star' structure. Length will be checked in 'make_object'. */ strcpy( obj_name, star->starname ); /* Set up a structure of type 'object' containing the star data. */ type= 2; /* Object located outside the solar system */ number= 0; /* Set to zero */ if ( ( error= make_object( type, number, obj_name, star, &cel_obj ) ) != 0 ) { error+= 10; return ( error ); } /* Compute the topocentric place with a call to function 'place'. */ coord_sys= 1; /* True equator and equinox of date */ if ( ( error= place( jd_tt, &cel_obj, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; error+= 20; } else { *ra= output.ra; *dec= output.dec; } return ( error ); } /********local_star */ short int local_star( double jd_tt, double delta_t, cat_entry *star, on_surface *position, short int accuracy, double *ra, double *dec ) /* ------------------------------------------------------------------------ PURPOSE: Computes the local place of a star at date 'jd_tt', given its catalog mean place, proper motion, parallax, and radial velocity. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for local place. delta_t (double) Difference TT-UT1 at 'jd_tt', in seconds of time. *star (struct cat_entry) Pointer to catalog entry structure containing catalog data for the object in the ICRS (defined in novas.h). *position (struct on_surface) Specifies the position of the observer (structure defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Local right ascension in hours, referred to the 'local GCRS'. *dec (double) Local declination in degrees, referred to the 'local GCRS'. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... Invalid value of 'where' in structure 'location'. > 10 ... Error code from function 'make_object'. > 20 ... Error code from function 'place'. GLOBALS USED: SIZE_OF_OBJ_NAME novas.h FUNCTIONS CALLED: make_observer novas.c make_object novas.c place novas.c strcpy string.h VER./DATE/ PROGRAMMER: V1.0/01-06/JAB (USNO/AA) V1.1/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.2/10-08/JAB (USNO/AA): Add 'accuracy' option to input. V1.3/05-10/JAB (USNO/AA): Fix bug in set-up of 'obj_name'. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'lpstar'. 2. SIZE_OF_OBJ_NAME is defined in novas.h ------------------------------------------------------------------------ */ { char obj_name[SIZE_OF_OBJ_NAME]; short int error= 0; short int type, number, coord_sys; in_space dummy; observer location; object cel_obj; sky_pos output; /* Initialize the 'dummy' structure. */ dummy.sc_pos[0]= dummy.sc_pos[1]= dummy.sc_pos[2]= 0.0; dummy.sc_vel[0]= dummy.sc_vel[1]= dummy.sc_vel[2]= 0.0; /* Set up a structure of type 'observer' containing the position of the observer. */ if ( ( error= make_observer( 1, position, &dummy, &location ) ) != 0 ) { error= 1; return ( error ); } /* Set 'obj_name' equal to 'starname' in the 'star' structure. Length will be checked in 'make_object'. */ strcpy( obj_name, star->starname ); /* Set up a structure of type 'object' containing the star data. */ type= 2; /* Object located outside the solar system */ number= 0; /* Set to zero */ if ( ( error= make_object( type, number, obj_name, star, &cel_obj ) ) != 0 ) { error+= 10; return ( error ); } /* Compute the local place with a call to function 'place'. */ coord_sys= 0; /* "Local GCRS" */ if ( ( error= place( jd_tt, &cel_obj, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; error+= 20; } else { *ra= output.ra; *dec= output.dec; } return ( error ); } /********topo_planet */ short int topo_planet( double jd_tt, object *ss_body, double delta_t, on_surface *position, short int accuracy, double *ra, double *dec, double *dis ) /* ------------------------------------------------------------------------ PURPOSE: Computes the topocentric place of a solar system body. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for topocentric place. *ss_body (struct object) Pointer to structure containing the body designation for the solar system body (defined in novas.h). delta_t (double) Difference TT-UT1 at 'jd_tt', in seconds of time. *position (struct on_surface) Specifies the position of the observer (structure defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Topocentric right ascension in hours, referred to true equator and equinox of date. *dec (double) Topocentric declination in degrees, referred to true equator and equinox of date. *dis (double) True distance from Earth to the body at 'jd_tt' in AU. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... Invalid value of 'where' in structure 'location'. > 10 ... Error code from function 'place'. GLOBALS USED: None. FUNCTIONS CALLED: make_observer novas.c place novas.c VER./DATE/ PROGRAMMER: V1.0/01-06/JAB (USNO/AA) V1.1/01-06/WKP (USNO/AA): Fixed minor syntax problem. V1.2/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.3/10-08/JAB (USNO/AA): Add 'accuracy' option to input. V1.4/07-10/JLB (USNO/AA): Fixed minor documentation error in prolog NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'tpplan'. ------------------------------------------------------------------------ */ { short int error= 0; short int coord_sys; in_space dummy; observer location; sky_pos output; /* Initialize the 'dummy' structure. */ dummy.sc_pos[0]= dummy.sc_pos[1]= dummy.sc_pos[2]= 0.0; dummy.sc_vel[0]= dummy.sc_vel[1]= dummy.sc_vel[2]= 0.0; /* Set up a structure of type 'observer' containing the position of the observer. */ if ( ( error= make_observer( 1, position, &dummy, &location ) ) != 0 ) { error= 1; return ( error ); } /* Compute the topocentric place with a call to function 'place'. */ coord_sys= 1; /* True equator and equinox of date */ if ( ( error= place( jd_tt, ss_body, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; *dis= 0.0; error+= 10; } else { *ra= output.ra; *dec= output.dec; *dis= output.dis; } return ( error ); } /********local_planet */ short int local_planet( double jd_tt, object *ss_body, double delta_t, on_surface *position, short int accuracy, double *ra, double *dec, double *dis ) /* ------------------------------------------------------------------------ PURPOSE: Computes the local place of a solar system body. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date for local place. *ss_body (struct object) Pointer to structure containing the body designation for the solar system body (defined in novas.h). delta_t (double) Difference TT-UT1 at 'jd_tt', in seconds of time. *position (struct on_surface) Specifies the position of the observer (structure defined in novas.h). accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra (double) Local right ascension in hours, referred to the 'local GCRS'. *dec (double) Local declination in degrees, referred to the 'local GCRS'. *dis (double) True distance from Earth to the body in AU. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... Invalid value of 'where' in structure 'location'. > 10 ... Error code from function 'place'. GLOBALS USED: None. FUNCTIONS CALLED: make_observer novas.c place novas.c VER./DATE/ PROGRAMMER: V1.0/01-06/JAB (USNO/AA) V1.1/01-06/WKP (USNO/AA): Fixed minor syntax problem. V1.2/10-06/JAB (USNO/AA): Incorporate 'output' structure. V1.3/10-08/JAB (USNO/AA): Add 'accuracy' option to input. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'lpplan'. ------------------------------------------------------------------------ */ { short int error= 0; short int coord_sys; in_space dummy; observer location; sky_pos output; /* Initialize the 'dummy' structure. */ dummy.sc_pos[0]= dummy.sc_pos[1]= dummy.sc_pos[2]= 0.0; dummy.sc_vel[0]= dummy.sc_vel[1]= dummy.sc_vel[2]= 0.0; /* Set up a structure of type 'observer' containing the position of the observer. */ if ( ( error= make_observer( 1, position, &dummy, &location ) ) != 0 ) { error= 1; return ( error ); } /* Compute the local place with a call to function 'place'. */ coord_sys= 0; /* "Local GCRS" */ if ( ( error= place( jd_tt, ss_body, &location, delta_t, coord_sys, accuracy, &output ) ) != 0 ) { *ra= 0.0; *dec= 0.0; *dis= 0.0; error+= 10; } else { *ra= output.ra; *dec= output.dec; *dis= output.dis; } return ( error ); } /********mean_star */ short int mean_star( double jd_tt, double ra, double dec, short int accuracy, double *ira, double *idec ) /* ------------------------------------------------------------------------ PURPOSE: Computes the ICRS position of a star, given its apparent place at date 'jd_tt'. Proper motion, parallax and radial velocity are assumed to be zero. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Explanatory Supplement to the Astronomical Almanac (1992), Chapter 3. INPUT ARGUMENTS: jd_tt (double) TT Julian date of apparent place. ra (double) Apparent right ascension in hours, referred to true equator and equinox of date. dec (double) Apparent declination in degrees, referred to true equator and equinox of date. accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ira (double) ICRS right ascension in hours. *idec (double) ICRS declination in degrees. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... Iterative process did not converge after 30 iterations. = 2 ... length of dummy star name out of bounds. = 3 ... length of dummy catalog name out of bounds. > 10 ... Error from function 'vector2radec'. > 20 ... Error from function 'app_star'. GLOBALS USED: T0 novascon.c FUNCTIONS CALLED: make_cat_entry novas.c starvectors novas.c precession novas.c app_star novas.c vector2radec novas.c fabs math.h VER./DATE/ PROGRAMMER: V1.0/12-05/JAB (USNO/AA) V1.1/03-08/WKP (USNO/AA): Fixed subtle bug in exit condition of iteration and updated variable names. V1.2/10-08/JAB (USNO/AA): Add 'accuracy' option to input. V1.3/05-10/JAB (USNO/AA): Use 'make_cat_entry' to set up local structure 'tempstar'. NOTES: 1. This function is the "C" version of Fortran NOVAS routine 'mpstar'. ------------------------------------------------------------------------ */ { short int error= 0; short int iter= 0; double pos[3], dum[3], pos2[3], newira, newidec, oldira, oldidec, ra2, dec2, deltara, deltadec; cat_entry tempstar; /* Set up the 'tempstar' structure, then use it to create a position vector based on the apparent RA and declination of the star. */ if ( ( error= make_cat_entry( "dummy", "CAT", 0, ra, dec, 0.0, 0.0, 0.0, 0.0, &tempstar ) ) != 0 ) { return ( error + 1 ); } starvectors( &tempstar, pos, dum ); /* Get initial approximation by precessing star position at 'jd_tt' to its position at J2000.0. */ precession( jd_tt, pos, T0, pos2 ); if ( ( error= vector2radec( pos2, &newira, &newidec ) ) != 0 ) { return ( error + 10 ); } /* Iteratively find ICRS coordinates that produce input apparent place of star at date 'jd_tt'. */ do { oldira= newira; oldidec= newidec; tempstar.ra= oldira; tempstar.dec= oldidec; if ( ( error= app_star( jd_tt, &tempstar, accuracy, &ra2, &dec2 ) ) != 0 ) { *ira= 0.0; *idec= 0.0; return ( error + 20 ); } deltara= ra2 - oldira; deltadec= dec2 - oldidec; if ( deltara < -12.0 ) deltara+= 24.0; if ( deltara > 12.0 ) deltara-= 24.0; newira= ra - deltara; newidec= dec - deltadec; if ( iter >= 30 ) { *ira= 0.0; *idec= 0.0; return ( error= 1 ); } else { iter++; } } while ( !( fabs( newira - oldira ) <= 1.0e-12 ) || !( fabs( newidec - oldidec ) <= 1.0e-11 ) ); *ira= newira; *idec= newidec; if ( *ira < 0.0 ) *ira+= 24.0; if ( *ira >= 24.0 ) *ira-= 24.0; return ( error ); } /********place */ short int place( double jd_tt, object *cel_object, observer *location, double delta_t, short int coord_sys, short int accuracy, sky_pos *output ) /* ------------------------------------------------------------------------ PURPOSE: This function computes the apparent direction of a star or solar system body at a specified time and in a specified coordinate system. REFERENCES: Kaplan, G. et al. (1989), Astronomical Journal 97, 1197-1210. Klioner, S. (2003), Astronomical Journal 125, 1580-1597. INPUT ARGUMENTS: jd_tt (double) TT Julian date for place. *cel_object (struct object) Specifies the celestial object of interest (structure defined in novas.h). *location (struct observer) Specifies the location of the observer (structure defined in novas.h). delta_t (double) Difference TT-UT1 at 'jd_tt', in seconds of time. coord_sys (short int) Code specifying coordinate system of the output position. = 0 ... GCRS or "local GCRS" = 1 ... true equator and equinox of date = 2 ... true equator and CIO of date = 3 ... astrometric coordinates, i.e., without light deflection or aberration. accuracy (short int) Code specifying the relative accuracy of the output position. = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *output (struct sky_pos) Output data specifying object's place on the sky at time 'jd_tt', with respect to the specified output coordinate system (struct defined in novas.h). RETURNED VALUE: = 0 ... No problems. = 1 ... invalid value of 'coord_sys' = 2 ... invalid value of 'accuracy' = 3 ... Earth is the observed object, and the observer is either at the geocenter or on the Earth's surface (not permitted) > 10, < 40 ... 10 + error from function 'ephemeris' > 40, < 50 ... 40 + error from function 'geo_posvel' > 50, < 70 ... 50 + error from function 'light_time' > 70, < 80 ... 70 + error from function 'grav_def' > 80, < 90 ... 80 + error from function 'cio_location' > 90, < 100 ... 90 + error from function 'cio_basis' GLOBALS USED: T0, C_AUDAY novascon.c FUNCTIONS CALLED: make_cat_entry novas.c make_object novas.c tdb2tt novas.c ephemeris novas.c geo_posvel novas.c starvectors novas.c d_light novas.c proper_motion novas.c bary2obs novas.c light_time novas.c limb_angle novas.c grav_def novas.c aberration novas.c frame_tie novas.c precession novas.c nutation novas.c cio_location novas.c cio_basis novas.c rad_vel novas.c vector2radec novas.c fabs math.h sqrt math.h VER./DATE/ PROGRAMMER: V1.0/01-05/JAB (USNO/AA) V1.1/09-05/WKP (USNO/AA) Removed 'star' from the input argument list since it is nested in the 'object' structure. V1.2/01-06/WKP (USNO/AA) Updated error codes and replaced 'mode' with 'accuracy' where appropriate. V1.3/01-06/JAB (USNO/AA) Added more static variables. V1.4/07-06/JAB (USNO/AA) Implement 'cio_location' construct. V1.5/10-06/JAB (USNO/AA) Add radial velocity calculation and implement 'sky_pos' structure. V1.6/01-07/JAB (USNO/AA) Update to accommodate new radial velocity algorithm. V1.7/10-08/JAB (USNO/AA) Modify calls to 'ephemeris' to support two-part input Julian date. V1.8/07-10/JLB (USNO/AA) Corrected citation to Kaplan et al. NOTES: 1. Values of 'location->where' and 'coord_sys' dictate the various standard kinds of place: location->where = 0 and coord_sys = 1: apparent place location->where = 1 and coord_sys = 1: topocentric place location->where = 0 and coord_sys = 0: virtual place location->where = 1 and coord_sys = 0: local place location->where = 0 and coord_sys = 3: astrometric place location->where = 1 and coord_sys = 3: topocentric astrometric place 2. Input value of 'delta_t' is used only when 'location->where' equals 1 or 2 (observer is on surface of Earth or in a near-Earth satellite). ------------------------------------------------------------------------ */ { static short int first_time= 1; short int error= 0; short int loc, rs, i; static double tlast1= 0.0; static double tlast2= 0.0; static double jd_tdb, peb[3], veb[3], psb[3], vsb[3], px[3], py[3], pz[3]; double x, secdif, jd[2], pog[3], vog[3], pob[3], vob[3], pos1[3], vel1[3], dt, pos2[3], pos3[3], t_light, t_light0, pos4[3], frlimb, pos5[3], pos6[3], pos7[3], pos8[3], r_cio, d_obs_geo, d_obs_sun, d_obj_sun; cat_entry null_star; static object earth, sun; /* Check for invalid value of 'coord_sys' or 'accuracy'. */ if ( ( coord_sys < 0 ) || ( coord_sys > 3 ) ) return ( error= 1 ); if ( ( accuracy < 0 ) || ( accuracy > 1 ) ) return ( error= 2 ); /* Create a null star 'cat_entry' and Earth and Sun 'object's. */ if ( first_time ) { make_cat_entry( "NULL_STAR", " ", 0L, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &null_star ); make_object( 0, 3, "Earth", &null_star, &earth ); make_object( 0, 10, "Sun", &null_star, &sun ); first_time= 0; } /* --------------------------------------------------------------------- Check on Earth as an observed object. Earth can only be an observed object when 'location' is a near-Earth satellite. --------------------------------------------------------------------- */ if ( ( cel_object->type == 0 ) && ( cel_object->number == 3 ) && ( location->where != 2 ) ) return ( error= 3 ); /* --------------------------------------------------------------------- Get position and velocity of Earth (geocenter) and Sun. --------------------------------------------------------------------- */ if ( fabs( jd_tt - tlast1 ) > 1.0e-8 ) { /* Compute 'jd_tdb', the TDB Julian date corresponding to 'jd_tt'. */ jd_tdb= jd_tt; tdb2tt( jd_tdb, &x, &secdif ); jd_tdb= jd_tt + secdif / 86400.0; /* Get position and velocity of Earth wrt barycenter of solar system, in ICRS. */ jd[0]= jd_tdb; jd[1]= 0.0; if ( ( error= ephemeris( jd, &earth, 0, accuracy, peb, veb ) ) != 0 ) return ( error+= 10 ); /* Get position and velocity of Sun wrt barycenter of solar system, in ICRS. */ if ( ( error= ephemeris( jd, &sun, 0, accuracy, psb, vsb ) ) != 0 ) return ( error+= 10 ); tlast1= jd_tt; } /* --------------------------------------------------------------------- Get position and velocity of observer. --------------------------------------------------------------------- */ if ( ( location->where == 1 ) || ( location->where == 2 ) ) { /* For topocentric place, get geocentric position and velocity vectors of observer (observer is on surface of Earth or in a near-Earth satellite). */ if ( ( error= geo_posvel( jd_tt, delta_t, accuracy, location, pog, vog ) ) != 0 ) return ( error+= 40 ); loc= 1; } else { /* For geocentric place, there is nothing to do (observer is at geocenter). */ for ( i= 0; i < 3; i++ ) { pog[i]= 0.0; vog[i]= 0.0; } loc= 0; } /* Compute position and velocity of observer wrt barycenter of solar system (Galilean transformation). */ for ( i= 0; i < 3; i++ ) { pob[i]= peb[i] + pog[i]; vob[i]= veb[i] + vog[i]; } /* --------------------------------------------------------------------- Find geometric position of observed object. --------------------------------------------------------------------- */ if ( cel_object->type == 2 ) /* Observed object is star. */ { /* Get position of star updated for its space motion. */ starvectors( &cel_object->star, pos1, vel1 ); dt= d_light( pos1, pob ); proper_motion( T0, pos1, vel1, ( jd_tdb + dt ), pos2 ); /* Get position of star wrt observer (corrected for parallax). */ bary2obs( pos2, pob, pos3, &t_light ); output->dis= 0.0; } else /* Observed object is solar system body. */ { /* Get position of body wrt barycenter of solar system. */ jd[0]= jd_tdb; jd[1]= 0.0; if ( ( error= ephemeris( jd, cel_object, 0, accuracy, pos1, vel1 ) ) != 0 ) return ( error+= 10 ); /* Get position of body wrt observer, and true (Euclidian) distance. */ bary2obs( pos1, pob, pos2, &t_light0 ); output->dis= t_light0 * C_AUDAY; /* Get position of body wrt observer, antedated for light-time. */ if ( ( error= light_time( jd_tdb, cel_object, pob, t_light0, accuracy, pos3, &t_light ) ) != 0 ) return ( error+= 50 ); } /* --------------------------------------------------------------------- Apply gravitational deflection of light and aberration. --------------------------------------------------------------------- */ if ( coord_sys == 3 ) { /* These calculations are skipped for astrometric place. */ for ( i= 0; i < 3; i++ ) { pos5[i]= pos3[i]; } } else { /* Variable 'loc' determines whether Earth deflection is included. */ if ( loc == 1 ) { limb_angle( pos3, pog, &x, &frlimb ); if ( frlimb < 0.8 ) loc= 0; } /* Compute gravitational deflection and aberration. */ if ( ( error= grav_def( jd_tdb, loc, accuracy, pos3, pob, pos4 ) ) != 0 ) return ( error+= 70 ); aberration( pos4, vob, t_light, pos5 ); } /* --------------------------------------------------------------------- Transform, if necessary, to output coordinate system. --------------------------------------------------------------------- */ switch ( coord_sys ) { case ( 1 ): /* Transform to equator and equinox of date. */ frame_tie( pos5, 1, pos6 ); precession( T0, pos6, jd_tdb, pos7 ); nutation( jd_tdb, 0, accuracy, pos7, pos8 ); break; case ( 2 ): /* Transform to equator and CIO of date. */ if ( fabs( jd_tdb - tlast2 ) > 1.0e-8 ) { /* Obtain the basis vectors, in the GCRS, of the celestial intermediate system. */ if ( ( error= cio_location( jd_tdb, accuracy, &r_cio, &rs ) ) != 0 ) return ( error+= 80 ); if ( ( error= cio_basis( jd_tdb, r_cio, rs, accuracy, px, py, pz ) ) != 0 ) return ( error+= 90 ); tlast2= jd_tdb; } /* Transform position vector to celestial intermediate system. */ pos8[0]= px[0] * pos5[0] + px[1] * pos5[1] + px[2] * pos5[2]; pos8[1]= py[0] * pos5[0] + py[1] * pos5[1] + py[2] * pos5[2]; pos8[2]= pz[0] * pos5[0] + pz[1] * pos5[1] + pz[2] * pos5[2]; break; default: /* No transformation -- keep coordinates in GCRS, */ /* or ICRS for astrometric coordinates. */ for ( i= 0; i < 3; i++ ) { pos8[i]= pos5[i]; } } /* --------------------------------------------------------------------- Compute radial velocity. --------------------------------------------------------------------- */ /* Compute distances: observer-geocenter, observer-Sun, object-Sun. */ d_obs_geo= sqrt( ( pob[0] - peb[0] ) * ( pob[0] - peb[0] ) + ( pob[1] - peb[1] ) * ( pob[1] - peb[1] ) + ( pob[2] - peb[2] ) * ( pob[2] - peb[2] ) ); d_obs_sun= sqrt( ( pob[0] - psb[0] ) * ( pob[0] - psb[0] ) + ( pob[1] - psb[1] ) * ( pob[1] - psb[1] ) + ( pob[2] - psb[2] ) * ( pob[2] - psb[2] ) ); d_obj_sun= sqrt( ( pos1[0] - psb[0] ) * ( pos1[0] - psb[0] ) + ( pos1[1] - psb[1] ) * ( pos1[1] - psb[1] ) + ( pos1[2] - psb[2] ) * ( pos1[2] - psb[2] ) ); rad_vel( cel_object, pos3, vel1, vob, d_obs_geo, d_obs_sun, d_obj_sun, &output->rv ); /* --------------------------------------------------------------------- Finish up. --------------------------------------------------------------------- */ vector2radec( pos8, &output->ra, &output->dec ); x= sqrt( pos8[0] * pos8[0] + pos8[1] * pos8[1] + pos8[2] * pos8[2] ); for ( i= 0; i < 3; i++ ) { output->r_hat[i]= pos8[i] / x; } return ( error ); } /********equ2gal */ void equ2gal( double rai, double deci, double *glon, double *glat ) /* ------------------------------------------------------------------------ PURPOSE: To convert ICRS right ascension and declination to galactic longitude and latitude. REFERENCES: Hipparcos and Tycho Catalogues, Vol. 1, Section 1.5.3. INPUT ARGUMENTS: rai (double) ICRS right ascension in hours. deci (double) ICRS declination in degrees. OUTPUT ARGUMENTS: *glon (double) Galactic longitude in degrees. *glat (double) Galactic latitude in degrees. RETURNED VALUE: None. GLOBALS USED: DEG2RAD, RAD2DEG novascon.c FUNCTIONS CALLED: sin math.h cos math.h sqrt math.h atan2 math.h VER./DATE/ PROGRAMMER: V1.0/11-03/JAB (USNO/AA) V1.1/03-06/JAB (USNO/AA): Fixed initialization of 'ag'. V1.2/03-11/WKP (USNO/AA): Added braces to 2-D array initialization to quiet gcc warnings. NOTES: 1. This function uses the coordinate transformation specified in the reference. 2. This function is the C version of NOVAS Fortran routine 'eqgal'. ------------------------------------------------------------------------ */ { double r, d, pos1[3], pos2[3], xyproj, g; /* Rotation matrix A_g from Hipparcos documentation eq. 1.5.11. */ double ag[3][3]= { {-0.0548755604, +0.4941094279, -0.8676661490}, {-0.8734370902, -0.4448296300, -0.1980763734}, {-0.4838350155, +0.7469822445, +0.4559837762}}; /* Form position vector in equatorial system from input coordinates. */ r= rai * 15.0 * DEG2RAD; d= deci * DEG2RAD; pos1[0]= cos( d ) * cos( r ); pos1[1]= cos( d ) * sin( r ); pos1[2]= sin( d ); /* Rotate position vector to galactic system, using Hipparcos documentation eq. 1.5.13. */ pos2[0]= ag[0][0] * pos1[0] + ag[1][0] * pos1[1] + ag[2][0] * pos1[2]; pos2[1]= ag[0][1] * pos1[0] + ag[1][1] * pos1[1] + ag[2][1] * pos1[2]; pos2[2]= ag[0][2] * pos1[0] + ag[1][2] * pos1[1] + ag[2][2] * pos1[2]; /* Decompose galactic vector into longitude and latitude. */ xyproj= sqrt( pos2[0] * pos2[0] + pos2[1] * pos2[1] ); if ( xyproj > 0.0 ) g= atan2( pos2[1], pos2[0] ); else g= 0.0; *glon= g * RAD2DEG; if ( *glon < 0.0 ) *glon+= 360.0; g= atan2( pos2[2], xyproj ); *glat= g * RAD2DEG; return; } /********equ2ecl */ short int equ2ecl( double jd_tt, short int coord_sys, short int accuracy, double ra, double dec, double *elon, double *elat ) /* ------------------------------------------------------------------------ PURPOSE: To convert right ascension and declination to ecliptic longitude and latitude. REFERENCES: None. INPUT ARGUMENTS: jd_tt (double) TT Julian date of equator, equinox, and ecliptic used for coordinates. coord_sys (short int) Coordinate system selection. = 0 ... mean equator and equinox of date 'jd_tt' = 1 ... true equator and equinox of date 'jd_tt' = 2 ... ICRS (ecliptic is always the mean plane) accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy ra (double) Right ascension in hours, referred to specified equator and equinox of date. dec (double) Declination in degrees, referred to specified equator and equinox of date. OUTPUT ARGUMENTS: *elon (double) Ecliptic longitude in degrees, referred to specified ecliptic and equinox of date. *elat (double) Ecliptic latitude in degrees, referred to specified ecliptic and equinox of date. RETURNED VALUE: (short int) = 0 ... everything OK = 1 ... invalid value of 'coord_sys' GLOBALS USED: DEG2RAD, RAD2DEG novascon.c FUNCTIONS CALLED: equ2ecl_vec novas.c sin math.h cos math.h sqrt math.h atan2 math.h VER./DATE/ PROGRAMMER: V1.0/11-03/JAB (USNO/AA) V1.1/01-06/WKP (USNO/AA) Changed 'mode' to 'accuracy'. V1.2/05-06/JAB (USNO/AA) Use vector transformation function. V1.3/05-08/WKP (USNO/AA) Changed values of coord_sys to be more consistent with gcrs2equ. NOTES: 1. To convert ICRS RA and dec to ecliptic coordinates (mean ecliptic and equinox of J2000.0), set 'coord_sys' = 2; the value of 'jd_tt' can be set to anything, since J2000.0 is assumed. Except for the input to this case, all input coordinates are dynamical. 2. This function is the C version of NOVAS Fortran routine 'eqecl'. ------------------------------------------------------------------------ */ { short int error= 0; double r, d, pos1[3], pos2[3], xyproj, e; /* Form position vector in equatorial system from input coordinates. */ r= ra * 15.0 * DEG2RAD; d= dec * DEG2RAD; pos1[0]= cos( d ) * cos( r ); pos1[1]= cos( d ) * sin( r ); pos1[2]= sin( d ); /* Convert the vector from equatorial to ecliptic system. */ if ( ( error= equ2ecl_vec( jd_tt, coord_sys, accuracy, pos1, pos2 ) ) != 0 ) return ( error ); /* Decompose ecliptic vector into ecliptic longitude and latitude. */ xyproj= sqrt( pos2[0] * pos2[0] + pos2[1] * pos2[1] ); if ( xyproj > 0.0 ) e= atan2( pos2[1], pos2[0] ); else e= 0.0; *elon= e * RAD2DEG; if ( *elon < 0.0 ) *elon+= 360.0; e= atan2( pos2[2], xyproj ); *elat= e * RAD2DEG; return ( error ); } /********equ2ecl_vec */ short int equ2ecl_vec( double jd_tt, short int coord_sys, short int accuracy, double *pos1, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: Converts an equatorial position vector to an ecliptic position vector. REFERENCES: None. INPUT ARGUMENTS: jd_tt (double) TT Julian date of equator, equinox, and ecliptic used for coordinates. coord_sys (short int) Coordinate system selection. = 0 ... mean equator and equinox of date 'jd_tt' = 1 ... true equator and equinox of date 'jd_tt' = 2 ... ICRS (ecliptic is always the mean plane) accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy pos1[3] (double) Position vector, referred to specified equator and equinox of date. OUTPUT ARGUMENTS: pos2[3] (double) Position vector, referred to specified ecliptic and equinox of date. RETURNED VALUE: (short int) = 0 ... everything OK = 1 ... invalid value of 'coord_sys' GLOBALS USED: T0, DEG2RAD novascon.c FUNCTIONS CALLED: tdb2tt novas.c e_tilt novas.c frame_tie novas.c fabs math.h sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/05-06/JAB (USNO/AA) V1.1/05-08/WKP (USNO/AA) Changed values of coord_sys to be more consistent with gcrs2equ. NOTES: 1. To convert an ICRS vector to an ecliptic vector (mean ecliptic and equinox of J2000.0 only), set 'coord_sys' = 2; the value of 'jd_tt' can be set to anything, since J2000.0 is assumed. Except for the input to this case, all vectors are assumed to be with respect to a dynamical system. 2. This function is the C version of NOVAS Fortran routine 'eqec'. ------------------------------------------------------------------------ */ { short int error= 0; static double t_last= 0.0; static double ob2000= 0.0; static double oblm, oblt; double t, secdiff, jd_tdb, pos0[3], w, x, y, z, obl; /* 'jd_tdb' is the TDB Julian date corresponding to 'jd_tt'. */ tdb2tt( jd_tt, &t, &secdiff ); jd_tdb= jd_tt + secdiff / 86400.0; /* Get obliquity, depending upon the "system" of the input coordinates. */ switch ( coord_sys ) { case 0: /* Input: mean equator and equinox of date */ case 1: /* Input: true equator and equinox of date */ pos0[0]= pos1[0]; pos0[1]= pos1[1]; pos0[2]= pos1[2]; if ( fabs( jd_tt - t_last ) > 1.0e-8 ) { e_tilt( jd_tdb, accuracy, &oblm, &oblt, &x, &y, &z ); t_last= jd_tt; } switch ( coord_sys ) { case 0: /* Use mean obliquity of date */ obl= oblm * DEG2RAD; break; case 1: /* Use true obliquity of date */ obl= oblt * DEG2RAD; break; } break; case 2: /* Input: ICRS */ frame_tie( pos1, 1, pos0 ); if ( ob2000 == 0.0 ) { e_tilt( T0, accuracy, &oblm, &w, &x, &y, &z ); ob2000= oblm; } obl= ob2000 * DEG2RAD; break; default: return ( error= 1 ); } /* Rotate position vector to ecliptic system. */ pos2[0]= pos0[0]; pos2[1]= pos0[1] * cos( obl ) + pos0[2] * sin( obl ); pos2[2]= -pos0[1] * sin( obl ) + pos0[2] * cos( obl ); return ( error ); } /********ecl2equ_vec */ short int ecl2equ_vec( double jd_tt, short int coord_sys, short int accuracy, double *pos1, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: Converts an ecliptic position vector to an equatorial position vector. REFERENCES: None. INPUT ARGUMENTS: jd_tt (double) TT Julian date of equator, equinox, and ecliptic used for coordinates. coord_sys (short int) Coordinate system selection. = 0 ... mean equator and equinox of date = 1 ... true equator and equinox of date = 2 ... ICRS (ecliptic is always the mean plane) accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy pos1[3] (double) Position vector, referred to specified ecliptic and equinox of date. If 'coord_sys' = 2, 'pos1' must be on mean ecliptic and equinox of J2000.0; see Note 1 below. OUTPUT ARGUMENTS: POS2[3] (double) Position vector, referred to specified equator and equinox of date. RETURNED VALUE: (short int) = 0 ... everything OK = 1 ... invalid value of 'coord_sys' GLOBALS USED: T0, DEG2RAD novascon.c FUNCTIONS CALLED: tdb2tt novas.c e_tilt novas.c frame_tie novas.c fabs math.h sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/05-06/JAB (USNO/AA) V1.1/05-08/WKP (USNO/AA) Changed values of coord_sys to be more consistent with gcrs2equ. V1.2/09-10/WKP (USNO/AA) Initialized 'obl' variable to silence compiler warning. NOTES: 1. To convert an ecliptic vector (mean ecliptic and equinox of J2000.0 only) to an ICRS vector, set 'coord_sys' = 2; the value of 'jd_tt' can be set to anything, since J2000.0 is assumed. Except for the output from this case, all vectors are assumed to be with respect to a dynamical system. 2. This function is the C version of NOVAS Fortran routine 'eceq'. ------------------------------------------------------------------------ */ { short int error= 0; static double t_last= 0.0; static double ob2000= 0.0; static double oblm, oblt; double t, secdiff, jd_tdb, pos0[3], w, x, y, z, obl= 0.0; /* 'jd_tdb' is the TDB Julian date. */ tdb2tt( jd_tt, &t, &secdiff ); jd_tdb= jd_tt + secdiff / 86400.0; /* Get obliquity, depending upon the "system" of the input coordinates. */ switch ( coord_sys ) { case 0: /* Output: mean equator and equinox of date */ case 1: /* Output: true equator and equinox of date */ if ( fabs( jd_tt - t_last ) > 1.0e-8 ) { e_tilt( jd_tdb, accuracy, &oblm, &oblt, &x, &y, &z ); t_last= jd_tt; } switch ( coord_sys ) { case 0: /* Use mean obliquity of date */ obl= oblm * DEG2RAD; break; case 1: /* Use true obliquity of date */ obl= oblt * DEG2RAD; break; } break; case 2: /* Output: ICRS */ if ( ob2000 == 0.0 ) { e_tilt( T0, accuracy, &oblm, &w, &x, &y, &z ); ob2000= oblm; } obl= ob2000 * DEG2RAD; break; default: return ( error= 1 ); } /* Rotate position vector to ecliptic system. */ pos2[0]= pos1[0]; pos2[1]= pos1[1] * cos( obl ) - pos1[2] * sin( obl ); pos2[2]= pos1[1] * sin( obl ) + pos1[2] * cos( obl ); /* Case where output vector is to be in ICRS, rotate from dynamical system to ICRS. */ if ( coord_sys == 2 ) { pos0[0]= pos2[0]; pos0[1]= pos2[1]; pos0[2]= pos2[2]; frame_tie( pos0, -1, pos2 ); } return ( error ); } /********equ2hor */ void equ2hor( double jd_ut1, double delta_t, short int accuracy, double xp, double yp, on_surface *location, double ra, double dec, short int ref_option, double *zd, double *az, double *rar, double *decr ) /* ------------------------------------------------------------------------ PURPOSE: This function transforms topocentric right ascension and declination to zenith distance and azimuth. It uses a method that properly accounts for polar motion, which is significant at the sub-arcsecond level. This function can also adjust coordinates for atmospheric refraction. REFERENCES: Kaplan, G. (2008). USNO/AA Technical Note of 28 Apr 2008, "Refraction as a Vector." INPUT ARGUMENTS: jd_ut1 (double) UT1 Julian date. delta_t (double) Difference TT-UT1 at 'jd_ut1', in seconds. accuracy (short int) Selection for method and accuracy = 0 ... full accuracy = 1 ... reduced accuracy xp (double) Conventionally-defined x coordinate of celestial intermediate pole with respect to ITRS reference pole, in arcseconds. yp (double) Conventionally-defined y coordinate of celestial intermediate pole with respect to ITRS reference pole, in arcseconds. *location (struct on_surface) Pointer to structure containing observer's location (defined in novas.h). ra (double) Topocentric right ascension of object of interest, in hours, referred to true equator and equinox of date. dec (double) Topocentric declination of object of interest, in degrees, referred to true equator and equinox of date. ref_option (short int) = 0 ... no refraction = 1 ... include refraction, using 'standard' atmospheric conditions. = 2 ... include refraction, using atmospheric parameters input in the 'location' structure. OUTPUT ARGUMENTS: *zd (double) Topocentric zenith distance in degrees, affected by refraction if 'ref_option' is non-zero. *az (double) Topocentric azimuth (measured east from north) in degrees. *rar (double) Topocentric right ascension of object of interest, in hours, referred to true equator and equinox of date, affected by refraction if 'ref_option' is non-zero. *decr (double) Topocentric declination of object of interest, in degrees, referred to true equator and equinox of date, affected by refraction if 'ref_option' is non-zero. RETURNED VALUE: None. GLOBALS USED: DEG2RAD, RAD2DEG novascon.c FUNCTIONS CALLED: ter2cel novas.c refract novas.c sin math.h cos math.h sqrt math.h atan2 math.h fabs math.h VER./DATE/ PROGRAMMER: V1.0/06-98/JAB (USNO/AA) V2.0/01-06/JAB (USNO/AA) V2.1/01-06/WKP (USNO/AA): Changed 'mode' to 'accuracy'. V2.2/11-07/JAB (USNO/AA): Cosmetic changes. V2.2/05-08/WKP (USNO/AA): Updated the refraction algorithm. V2.3/06-08/WKP (USNO/AA): Tweaked convergence criteria. V2.4/03-09/JAB (USNO/AA): Conformed input variables to IERS conventions. NOTES: 1. 'xp' and 'yp' can be set to zero if sub-arcsecond accuracy is not needed. 'ra' and 'dec' can be obtained from functions 'tpstar' or 'tpplan'. 2. The directions 'zd'= 0 (zenith) and 'az'= 0 (north) are here considered fixed in the terrestrial system. Specifically, the zenith is along the geodetic normal, and north is toward the ITRS pole. 3. If 'ref_option'= 0, then 'rar'='ra' and 'decr'='dec'. 4. This function is the C version of NOVAS Fortran routine 'zdaz'. ------------------------------------------------------------------------ */ { short int j; double sinlat, coslat, sinlon, coslon, sindc, cosdc, sinra, cosra, uze[3], une[3], uwe[3], uz[3], un[3], uw[3], p[3], pz, pn, pw, proj, zd0, zd1, refr, sinzd, coszd, sinzd0, coszd0, pr[3]; /* Preliminaries. */ *rar= ra; *decr= dec; sinlat= sin( location->latitude * DEG2RAD ); coslat= cos( location->latitude * DEG2RAD ); sinlon= sin( location->longitude * DEG2RAD ); coslon= cos( location->longitude * DEG2RAD ); sindc= sin( dec * DEG2RAD ); cosdc= cos( dec * DEG2RAD ); sinra= sin( ra * 15.0 * DEG2RAD ); cosra= cos( ra * 15.0 * DEG2RAD ); /* Set up orthonormal basis vectors in local Earth-fixed system. Define vector toward local zenith in Earth-fixed system (z axis). */ uze[0]= coslat * coslon; uze[1]= coslat * sinlon; uze[2]= sinlat; /* Define vector toward local north in Earth-fixed system (x axis). */ une[0]= -sinlat * coslon; une[1]= -sinlat * sinlon; une[2]= coslat; /* Define vector toward local west in Earth-fixed system (y axis). */ uwe[0]= sinlon; uwe[1]= -coslon; uwe[2]= 0.0; /* Obtain vectors in celestial system. Rotate Earth-fixed orthonormal basis vectors to celestial system (wrt equator and equinox of date). */ ter2cel( jd_ut1, 0.0, delta_t, 1, accuracy, 1, xp, yp, uze, uz ); ter2cel( jd_ut1, 0.0, delta_t, 1, accuracy, 1, xp, yp, une, un ); ter2cel( jd_ut1, 0.0, delta_t, 1, accuracy, 1, xp, yp, uwe, uw ); /* Define unit vector 'p' toward object in celestial system (wrt equator and equinox of date). */ p[0]= cosdc * cosra; p[1]= cosdc * sinra; p[2]= sindc; /* Compute coordinates of object wrt orthonormal basis. Compute components of 'p' - projections of 'p' onto rotated Earth-fixed basis vectors. */ pz= p[0] * uz[0] + p[1] * uz[1] + p[2] * uz[2]; pn= p[0] * un[0] + p[1] * un[1] + p[2] * un[2]; pw= p[0] * uw[0] + p[1] * uw[1] + p[2] * uw[2]; /* Compute azimuth and zenith distance. */ proj= sqrt( pn * pn + pw * pw ); if ( proj > 0.0 ) *az= -atan2( pw, pn ) * RAD2DEG; if ( *az < 0.0 ) *az+= 360.0; if ( *az >= 360.0 ) *az-= 360.0; *zd= atan2( proj, pz ) * RAD2DEG; /* Apply atmospheric refraction if requested. */ if ( ref_option != 0 ) { /* Get refraction in zenith distance. Iterative process is required because refraction algorithms are always a function of observed (not computed) zenith distance. Require convergence to 0.1 arcsec (actual accuracy less). */ zd0= *zd; do { zd1= *zd; refr= refract( location, ref_option, *zd ); *zd= zd0 - refr; } while ( fabs( *zd - zd1 ) > 3.0e-5 ); /* Apply refraction to celestial coordinates of object. */ if ( ( refr > 0.0 ) && ( *zd > 3.0e-4 ) ) { /* Shift position vector of object in celestial system to account for refraction (see USNO/AA Technical Note 1998-09). */ sinzd= sin( *zd * DEG2RAD ); coszd= cos( *zd * DEG2RAD ); sinzd0= sin( zd0 * DEG2RAD ); coszd0= cos( zd0 * DEG2RAD ); /* Compute refracted position vector. */ for ( j= 0; j < 3; j++ ) pr[j]= ( ( p[j] - coszd0 * uz[j] ) / sinzd0 ) * sinzd + uz[j] * coszd; /* Compute refracted right ascension and declination. */ proj= sqrt( pr[0] * pr[0] + pr[1] * pr[1] ); if ( proj > 0.0 ) *rar= atan2( pr[1], pr[0] ) * RAD2DEG / 15.0; if ( *rar < 0.0 ) *rar+= 24.0; if ( *rar >= 24.0 ) *rar-= 24.0; *decr= atan2( pr[2], proj ) * RAD2DEG; } } return; } /********gcrs2equ */ short int gcrs2equ( double jd_tt, short int coord_sys, short int accuracy, double rag, double decg, double *ra, double *dec ) /* ------------------------------------------------------------------------ PURPOSE: This function converts GCRS right ascension and declination to coordinates with respect to the equator of date (mean or true). For coordinates with respect to the true equator of date, the origin of right ascension can be either the true equinox or the celestial intermediate origin (CIO). REFERENCES: None. INPUT ARGUMENTS: jd_tt (double) TT Julian date of equator to be used for output coordinates. coord_sys (short int) Coordinate system selection for output coordinates. = 0 ... mean equator and equinox of date = 1 ... true equator and equinox of date = 2 ... true equator and CIO of date accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy rag (double) GCRS right ascension in hours. decg (double) GCRS declination in degrees. OUTPUT ARGUMENTS: ra (double) Right ascension in hours, referred to specified equator and right ascension origin of date. dec (double) Declination in degrees, referred to specified equator of date. RETURNED VALUE: (short int) = 0 ... everything OK. < 0 ... error from function 'vector2radec' > 10 ... 10 + error from function 'cio_location' > 20 ... 20 + error from function 'cio_basis' GLOBALS USED: DEG2RAD, T0 novascon.c FUNCTIONS CALLED: tdb2tt novas.c frame_tie novas.c precession novas.c nutation novas.c cio_location novas.c cio_basis novas.c vector2radec novas.c sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/09-04/JAB (USNO/AA) V1.1/01-06/WKP (USNO/AA) Changed 'mode' to 'accuracy'. V1.2/07-06/JAB (USNO/AA) Implement 'cio_location' construct. V1.3/04-08/WKP (USNO/AA) Updated variable names. NOTES: 1. Set input value of 'accuracy' equal to any short int if 'coord_sys' equals 0 or 1. It is not used in these cases. 2. This function only supports the CIO-based method. 3. This function is the C version of NOVAS Fortran routine 'gcrseq'. ------------------------------------------------------------------------ */ { short int error= 0; short int rs; double t1, t, secdiff, r, d, pos1[3], pos2[3], pos3[3], pos4[3], r_cio, x[3], y[3], z[3]; /* 't1' is the TDB Julian date. */ tdb2tt( jd_tt, &t, &secdiff ); t1= jd_tt + secdiff / 86400.0; /* Form position vector in equatorial system from input coordinates. */ r= rag * 15.0 * DEG2RAD; d= decg * DEG2RAD; pos1[0]= cos( d ) * cos( r ); pos1[1]= cos( d ) * sin( r ); pos1[2]= sin( d ); /* Transform the position vector based on the value of 'coord_sys'. */ if ( coord_sys <= 1 ) { /* Transform the position vector from GCRS to mean equator and equinox of date. */ frame_tie( pos1, 1, pos2 ); precession( T0, pos2, t1, pos3 ); /* If requested, transform further to true equator and equinox of date. */ if ( coord_sys == 1 ) { nutation( t1, 0, accuracy, pos3, pos4 ); } else { pos4[0]= pos3[0]; pos4[1]= pos3[1]; pos4[2]= pos3[2]; } } else { /* Obtain the basis vectors, in the GCRS, of the celestial intermediate system. */ if ( ( error= cio_location( t1, accuracy, &r_cio, &rs ) ) != 0 ) return ( error+= 10 ); if ( ( error= cio_basis( t1, r_cio, rs, accuracy, x, y, z ) ) != 0 ) return ( error+= 20 ); /* Transform position vector to the celestial intermediate system (which has the CIO as its origin of right ascension). */ pos4[0]= x[0] * pos1[0] + x[1] * pos1[1] + x[2] * pos1[2]; pos4[1]= y[0] * pos1[0] + y[1] * pos1[1] + y[2] * pos1[2]; pos4[2]= z[0] * pos1[0] + z[1] * pos1[1] + z[2] * pos1[2]; } /* Convert the position vector to equatorial spherical coordinates. */ if ( ( error= vector2radec( pos4, ra, dec ) ) != 0 ) { *ra= 0.0; *dec= 0.0; return ( -1 * error ); } return ( error ); } /********sidereal_time */ short int sidereal_time( double jd_high, double jd_low, double delta_t, short int gst_type, short int method, short int accuracy, double *gst ) /* ------------------------------------------------------------------------ PURPOSE: Computes the Greenwich sidereal time, either mean or apparent, at Julian date 'jd_high' + 'jd_low'. REFERENCES: Kaplan, G. (2005), US Naval Observatory Circular 179. INPUT ARGUMENTS: jd_high (double) High-order part of UT1 Julian date. jd_low (double) Low-order part of UT1 Julian date. delta_t (double) Difference TT-UT1 at 'jd_high'+'jd_low', in seconds of time. gst_type (short int) = 0 ... compute Greenwich mean sidereal time = 1 ... compute Greenwich apparent sidereal time method (short int) Selection for method = 0 ... CIO-based method = 1 ... equinox-based method accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *gst (double) Greenwich (mean or apparent) sidereal time, in hours. RETURNED VALUE: (short int) = 0 ... everything OK = 1 ... invalid value of 'accuracy' = 2 ... invalid value of 'method' > 10, < 30 ... 10 + error from function 'cio_rai' GLOBALS USED: T0, RAD2DEG novascon.c FUNCTIONS CALLED: tdb2tt novas.c era novas.c e_tilt novas.c cio_location novas.c cio_basis novas.c nutation novas.c precession novas.c frame_tie novas.c fabs math.h atan2 math.h fmod math.h VER./DATE/ PROGRAMMER: V1.0/06-92/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Update to C programing standards. V1.2/03-98/JAB (USNO/AA) Expand documentation. V1.3/08-98/JAB (USNO/AA) Match flow of the Fortran counterpart. V2.0/09-03/JAB (USNO/AA) Incorporate the 2nd-reference changes. V2.1/08-04/JAB (USNO/AA) Incorporate the 1st-reference changes. V2.2/12-05/WKP (USNO/AA) Updated error handling. V2.3/01-06/WKP (USNO/AA) Changed 'mode' to 'method' and 'accuracy'. V2.4/04-06/JAB (USNO/AA) Use precession-in-RA terms in mean sidereal time from third reference. V2.5/07-06/JAB (USNO/AA) Implement 'cio_location' construct. V2.6/06-08/WKP (USNO/AA) Changed value of direction argument in call to 'nutation' from 1 to -1 for consistency. V2.7/03-11/WKP (USNO/AA) Updated prolog description to clarify this function computes either mean or apparent sidereal time, and removed Note 1 for consistency with Fortran. NOTES: 1. The Julian date may be split at any point, but for highest precision, set 'jd_high' to be the integral part of the Julian date, and set 'jd_low' to be the fractional part. 2. This function is the C version of NOVAS Fortran routine 'sidtim'. ------------------------------------------------------------------------ */ { short int error= 0; short int ref_sys; static double ee; static double jd_last= -99.0; double unitx[3]= {1.0, 0.0, 0.0}; double jd_ut, jd_tt, jd_tdb, tt_temp, t, theta, a, b, c, d, ra_cio, x[3], y[3], z[3], w1[3], w2[3], eq[3], ha_eq, st, secdiff, eqeq; /* Invalid value of 'accuracy'. */ if ( ( accuracy < 0 ) || ( accuracy > 1 ) ) return ( error= 1 ); /* Time argument for precession and nutation components of sidereal time is TDB. First approximation is TDB = TT, then refine. */ jd_ut= jd_high + jd_low; jd_tt= jd_ut + ( delta_t / 86400.0 ); jd_tdb= jd_tt; tdb2tt( jd_tdb, &tt_temp, &secdiff ); jd_tdb= jd_tt + ( secdiff / 86400.0 ); t= ( jd_tdb - T0 ) / 36525.0; /* Compute the Earth Rotation Angle. Time argument is UT1. */ theta= era( jd_high, jd_low ); /* Compute the equation of the equinoxes if needed, depending upon the input values of 'gst_type' and 'method'. If not needed, set to zero. */ if ( ( ( gst_type == 0 ) && ( method == 0 ) ) || /* GMST; CIO-TIO */ ( ( gst_type == 1 ) && ( method == 1 ) ) ) /* GAST; equinox */ { if ( fabs( jd_tdb - jd_last ) > 1.0e-8 ) { e_tilt( jd_tdb, accuracy, &a, &b, &ee, &c, &d ); jd_last= jd_tdb; } eqeq= ee * 15.0; } else { eqeq= 0.0; } /* Compute Greenwich sidereal time depending upon input values of 'method' and 'gst_type'. */ switch ( method ) { case ( 0 ): /* Use 'CIO-TIO-theta' method. See Circular 179, Section 6.5.4. */ /* Obtain the basis vectors, in the GCRS, of the celestial intermediate system. */ if ( ( error= cio_location( jd_tdb, accuracy, &ra_cio, &ref_sys ) ) != 0 ) { *gst= 99.0; return ( error+= 10 ); } cio_basis( jd_tdb, ra_cio, ref_sys, accuracy, x, y, z ); /* Compute the direction of the true equinox in the GCRS. */ nutation( jd_tdb, -1, accuracy, unitx, w1 ); precession( jd_tdb, w1, T0, w2 ); frame_tie( w2, -1, eq ); /* Compute the hour angle of the equinox wrt the TIO meridian (near Greenwich, but passes through the CIP and TIO). */ ha_eq= theta - atan2( ( eq[0] * y[0] + eq[1] * y[1] + eq[2] * y[2] ), ( eq[0] * x[0] + eq[1] * x[1] + eq[2] * x[2] ) ) * RAD2DEG; /* For mean sidereal time, subtract the equation of the equinoxes. */ ha_eq-= ( eqeq / 240.0 ); ha_eq= fmod( ha_eq, 360.0 ) / 15.0; if ( ha_eq < 0.0 ) ha_eq+= 24.0; *gst= ha_eq; break; case ( 1 ): /* Use equinox method. See Circular 179, Section 2.6.2. */ /* Precession-in-RA terms in mean sidereal time taken from third reference, eq. (42), with coefficients in arcseconds. */ st= eqeq + 0.014506 + ( ( ( ( -0.0000000368 * t - 0.000029956 ) * t - 0.00000044 ) * t + 1.3915817 ) * t + 4612.156534 ) * t; /* Form the Greenwich sidereal time. */ *gst= fmod( ( st / 3600.0 + theta ), 360.0 ) / 15.0; if ( *gst < 0.0 ) *gst+= 24.0; break; /* Invalid value of 'method'. */ default: *gst= 99.0; error= 2; break; } return ( error ); } /********era */ double era( double jd_high, double jd_low ) /* ------------------------------------------------------------------------ PURPOSE: This function returns the value of the Earth Rotation Angle (theta) for a given UT1 Julian date. The expression used is taken from the note to IAU Resolution B1.8 of 2000. REFERENCES: IAU Resolution B1.8, adopted at the 2000 IAU General Assembly, Manchester, UK. Kaplan, G. (2005), US Naval Observatory Circular 179. INPUT ARGUMENTS: jd_high (double) High-order part of UT1 Julian date. jd_low (double) Low-order part of UT1 Julian date. OUTPUT ARGUMENTS: None. RETURNED VALUE: (double) The Earth Rotation Angle (theta) in degrees. GLOBALS USED: T0 novascon.c FUNCTIONS CALLED: fmod math.h VER./DATE/ PROGRAMMER: V1.0/09-03/JAB (USNO/AA) NOTES: 1. The algorithm used here is equivalent to the canonical theta = 0.7790572732640 + 1.00273781191135448 * t, where t is the time in days from J2000 (t = jd_high + jd_low - T0), but it avoids many two-PI 'wraps' that decrease precision (adopted from SOFA Fortran routine iau_era00; see also expression at top of page 35 of IERS Conventions (1996)). 2. This function is the C version of NOVAS Fortran routine 'erot'. ------------------------------------------------------------------------ */ { double theta, thet1, thet2, thet3; thet1= 0.7790572732640 + 0.00273781191135448 * ( jd_high - T0 ); thet2= 0.00273781191135448 * jd_low; thet3= fmod( jd_high, 1.0 ) + fmod( jd_low, 1.0 ); theta= fmod( thet1 + thet2 + thet3, 1.0 ) * 360.0; if ( theta < 0.0 ) theta+= 360.0; return theta; } /********ter2cel */ short int ter2cel( double jd_ut_high, double jd_ut_low, double delta_t, short int method, short int accuracy, short int option, double xp, double yp, double *vec1, double *vec2 ) /* ------------------------------------------------------------------------ PURPOSE: This function rotates a vector from the terrestrial to the celestial system. Specifically, it transforms a vector in the ITRS (rotating earth-fixed system) to the GCRS (a local space- fixed system) by applying rotations for polar motion, Earth rotation, nutation, precession, and the dynamical-to-GCRS frame tie. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Kaplan, G. H. (2003), 'Another Look at Non-Rotating Origins', Proceedings of IAU XXV Joint Discussion 16. INPUT ARGUMENTS: jd_ut_high (double) High-order part of UT1 Julian date. jd_ut_low (double) Low-order part of UT1 Julian date. delta_t (double) Value of Delta T (= TT - UT1) at the input UT1 Julian date. method (short int) Selection for method = 0 ... CIO-based method = 1 ... equinox-based method accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy option (short int) = 0 ... The output vector is referred to GCRS axes. = 1 ... The output vector is produced with respect to the equator and equinox of date. See Note 2 below. xp (double) Conventionally-defined X coordinate of celestial intermediate pole with respect to ITRS pole, in arcseconds. yp (double) Conventionally-defined Y coordinate of celestial intermediate pole with respect to ITRS pole, in arcseconds. vec1[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to ITRS axes (terrestrial system) in the normal case where 'option' = 0. OUTPUT ARGUMENTS: vec2[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to GCRS axes (celestial system) or with respect to the equator and equinox of date, depending on 'option'. RETURNED VALUE: = 0 ... everything is ok. = 1 ... invalid value of 'accuracy' = 2 ... invalid value of 'method' > 10 ... 10 + error from function 'cio_location' > 20 ... 20 + error from function 'cio_basis' GLOBALS USED: T0 novascon.c FUNCTIONS CALLED: tdb2tt novas.c wobble novas.c cio_location novas.c cio_basis novas.c era novas.c spin novas.c sidereal_time novas.c nutation novas.c precession novas.c frame_tie novas.c VER./DATE/ PROGRAMMER: V1.0/08-93/WTH (USNO/AA) Translate Fortran. V2.0/10-03/JAB (USNO/AA) Formerly function 'pnsw.' Update for IAU 2000 resolutions. V2.1/01-05/JAB (USNO/AA) Update to include 'mode' flexibility. V2.2/12-05/WKP (USNO/AA) Check error codes. V2.3/01-06/WKP (USNO/AA) Changed 'mode' to 'method' and 'accuracy'. V2.4/07-06/JAB (USNO/AA) Implement 'cio_location' construct. V2.5/06-08/WKP (USNO/AA) Corrected sign of direction argument in 'frame_tie' call and changed value of direction argument in call to 'nutation' for consistency. V2.6/10-08/WKP (USNO/AA) Renamed input JD variables to include time system. V2.7/03-09/JAB (USNO/AA) Conformed input variables to IERS conventions. V2.8/12-10/JAB (USNO/AA) Cosmetic changes for consistency with Fortran. NOTES: 1. 'xp' = 'yp' = 0 means no polar motion transformation. 2. The 'option' flag only works for the equinox-based method. 3. This function is the C version of NOVAS Fortran routine 'tercel'. ------------------------------------------------------------------------ */ { short int error= 0; short int rs, j; double jd_ut1, jd_tt, dummy, secdiff, jd_tdb, gast, r_cio, theta, v1[3], v2[3], v3[3], v4[3], x[3], y[3], z[3]; /* Invalid value of 'accuracy'. */ if ( ( accuracy < 0 ) || ( accuracy > 1 ) ) return ( error= 1 ); /* Compute the TT Julian date corresponding to the input UT1 Julian date. */ jd_ut1= jd_ut_high + jd_ut_low; jd_tt= jd_ut1 + ( delta_t / 86400.0 ); /* Compute the TDB Julian date corresponding to the input UT1 Julian date. */ jd_tdb= jd_tt; tdb2tt( jd_tdb, &dummy, &secdiff ); jd_tdb= jd_tt + secdiff / 86400.0; switch ( method ) { case ( 0 ): /* 'CIO-TIO-THETA' method. See second reference, eq. (3) and (4). Apply polar motion, transforming the vector to the terrestrial intermediate system. */ if ( ( xp == 0.0 ) && ( yp == 0.0 ) ) { v1[0]= vec1[0]; v1[1]= vec1[1]; v1[2]= vec1[2]; } else wobble( jd_tdb, 0, xp, yp, vec1, v1 ); /* Obtain the basis vectors, in the GCRS, of the celestial intermediate system. */ if ( ( error= cio_location( jd_tdb, accuracy, &r_cio, &rs ) ) != 0 ) return ( error+= 10 ); if ( ( error= cio_basis( jd_tdb, r_cio, rs, accuracy, x, y, z ) ) != 0 ) return ( error+= 20 ); /* Compute and apply the Earth rotation angle, 'theta', transforming the vector to the celestial intermediate system. */ theta= era( jd_ut_high, jd_ut_low ); spin( -theta, v1, v2 ); /* Transform the vector from the celestial intermediate system to the GCRS. */ vec2[0]= x[0] * v2[0] + y[0] * v2[1] + z[0] * v2[2]; vec2[1]= x[1] * v2[0] + y[1] * v2[1] + z[1] * v2[2]; vec2[2]= x[2] * v2[0] + y[2] * v2[1] + z[2] * v2[2]; break; case ( 1 ): /* Equinox mode. Apply polar motion. */ if ( ( xp == 0.0 ) && ( yp == 0.0 ) ) { for ( j= 0; j < 3; j++ ) { v1[j]= vec1[j]; } } else wobble( jd_tdb, 0, xp, yp, vec1, v1 ); /* Apply Earth rotation. */ sidereal_time( jd_ut_high, jd_ut_low, delta_t, 1, 1, accuracy, &gast ); spin( -gast * 15.0, v1, v2 ); /* 'option' = 1 skips remaining transformations. */ if ( option == 1 ) { vec2[0]= v2[0]; vec2[1]= v2[1]; vec2[2]= v2[2]; } else { /* Apply precession, nutation, and frame tie. */ nutation( jd_tdb, -1, accuracy, v2, v3 ); precession( jd_tdb, v3, T0, v4 ); frame_tie( v4, -1, vec2 ); } break; /* Invalid value of 'method'. */ default: error= 2; break; } return ( error ); } /********cel2ter */ short int cel2ter( double jd_ut_high, double jd_ut_low, double delta_t, short int method, short int accuracy, short int option, double xp, double yp, double *vec1, double *vec2 ) /* ------------------------------------------------------------------------ PURPOSE: This function rotates a vector from the celestial to the terrestrial system. Specifically, it transforms a vector in the GCRS (a local space-fixed system) to the ITRS (a rotating earth- fixed system) by applying rotations for the GCRS-to-dynamical frame tie, precession, nutation, Earth rotation, and polar motion. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Kaplan, G. H. (2003), 'Another Look at Non-Rotating Origins', Proceedings of IAU XXV Joint Discussion 16. INPUT ARGUMENTS: jd_ut_high (double) High-order part of UT1 Julian date. jd_ut_low (double) Low-order part of UT1 Julian date. delta_t (double) Value of Delta T (= TT - UT1) at the input UT1 Julian date. method (short int) Selection for method = 0 ... CIO-based method = 1 ... equinox-based method accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy option (short int) = 0 ... The input vector is referred to GCRS axes. = 1 ... The input vector is produced with respect to the equator and equinox of date. See Note 2 below. xp (double) Conventionally-defined X coordinate of celestial intermediate pole with respect to ITRS pole, in arcseconds. yp (double) Conventionally-defined Y coordinate of celestial intermediate pole with respect to ITRS pole, in arcseconds. vec1[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to GCRS axes (celestial system) or with respect to the equator and equinox of date, depending on 'option'. OUTPUT ARGUMENTS: vec2[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to ITRS axes (terrestrial system). RETURNED VALUE: = 0 ... everything is ok. = 1 ... invalid value of 'accuracy' = 2 ... invalid value of 'method' > 10 ... 10 + error from function 'cio_location' > 20 ... 20 + error from function 'cio_basis' GLOBALS USED: T0 novascon.c FUNCTIONS CALLED: tdb2tt novas.c wobble novas.c cio_location novas.c cio_basis novas.c era novas.c spin novas.c sidereal_time novas.c nutation novas.c precession novas.c frame_tie novas.c VER./DATE/ PROGRAMMER: V1.0/03-09/JAB (USNO/AA) V1.1/12-10/JAB (USNO/AA) Fix confusion with input/output vectors; cosmetic changes to better match Fortran. NOTES: 1. 'xp' = 'yp' = 0 means no polar motion transformation. 2. 'option' = 1 only works for the equinox-based method ('method' = 1). 3. This function is the C version of NOVAS Fortran routine 'celter'. ------------------------------------------------------------------------ */ { short int error= 0; short int rs, j; double jd_ut1, jd_tt, dummy, secdiff, jd_tdb, gast, r_cio, theta, v1[3], v2[3], v3[3], v4[3], x[3], y[3], z[3]; /* Invalid value of 'accuracy'. */ if ( ( accuracy < 0 ) || ( accuracy > 1 ) ) return ( error= 1 ); /* Compute the TT Julian date corresponding to the input UT1 Julian date. */ jd_ut1= jd_ut_high + jd_ut_low; jd_tt= jd_ut1 + ( delta_t / 86400.0 ); /* Compute the TDB Julian date corresponding to the input UT1 Julian date. */ jd_tdb= jd_tt; tdb2tt( jd_tdb, &dummy, &secdiff ); jd_tdb= jd_tt + secdiff / 86400.0; switch ( method ) { case ( 0 ): /* 'CIO-TIO-THETA' method. See second reference, eq. (3) and (4). Obtain the basis vectors, in the GCRS, of the celestial intermediate system. */ if ( ( error= cio_location( jd_tdb, accuracy, &r_cio, &rs ) ) != 0 ) return ( error+= 10 ); if ( ( error= cio_basis( jd_tdb, r_cio, rs, accuracy, x, y, z ) ) != 0 ) return ( error+= 20 ); /* Transform the vector from the GCRS to the celestial intermediate system. */ v1[0]= x[0] * vec1[0] + x[1] * vec1[1] + x[2] * vec1[2]; v1[1]= y[0] * vec1[0] + y[1] * vec1[1] + y[2] * vec1[2]; v1[2]= z[0] * vec1[0] + z[1] * vec1[1] + z[2] * vec1[2]; /* Compute and apply the Earth rotation angle, 'theta', transforming the vector to the terrestrial intermediate system. */ theta= era( jd_ut_high, jd_ut_low ); spin( theta, v1, v2 ); /* Apply polar motion, transforming the vector to the ITRS. */ if ( ( xp == 0.0 ) && ( yp == 0.0 ) ) { vec2[0]= v2[0]; vec2[1]= v2[1]; vec2[2]= v2[2]; } else wobble( jd_tdb, 1, xp, yp, v2, vec2 ); break; case ( 1 ): /* Equinox mode. 'option' = 1 skips initial transformations. */ if ( option == 1 ) { v3[0]= vec1[0]; v3[1]= vec1[1]; v3[2]= vec1[2]; } else { /* Apply frame tie, nutation, and precession. */ frame_tie( vec1, 1, v1 ); precession( T0, v1, jd_tdb, v2 ); nutation( jd_tdb, 0, accuracy, v2, v3 ); } /* Apply Earth rotation. */ sidereal_time( jd_ut_high, jd_ut_low, delta_t, 1, 1, accuracy, &gast ); spin( gast * 15.0, v3, v4 ); /* Apply polar motion. */ if ( ( xp == 0.0 ) && ( yp == 0.0 ) ) { for ( j= 0; j < 3; j++ ) { vec2[j]= v4[j]; } } else wobble( jd_tdb, 1, xp, yp, v4, vec2 ); break; /* Invalid value of 'method'. */ default: error= 2; break; } return ( error ); } /********spin */ void spin( double angle, double *pos1, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: This function transforms a vector from one coordinate system to another with same origin and axes rotated about the z-axis. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. INPUT ARGUMENTS: angle (double) Angle of coordinate system rotation, positive counterclockwise when viewed from +z, in degrees. pos1[3] (double) Position vector. OUTPUT ARGUMENTS: pos2[3] (double) Position vector expressed in new coordinate system rotated about z by 'angle'. RETURNED VALUE: None. GLOBALS USED: DEG2RAD novascon.c FUNCTIONS CALLED: sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/08-93/WTH (USNO/AA) Translate Fortran. V2.0/10-03/JAB (USNO/AA) Update for IAU 2000 resolutions. V2.1/01-05/JAB (USNO/AA) Generalize the function. NOTES: 1. This function is the C version of NOVAS Fortran routine 'spin'. ------------------------------------------------------------------------ */ { static double ang_last= -999.0; static double xx, yx, zx, xy, yy, zy, xz, yz, zz; double angr, cosang, sinang; if ( fabs( angle - ang_last ) >= 1.0e-12 ) { angr= angle * DEG2RAD; cosang= cos( angr ); sinang= sin( angr ); /* Rotation matrix follows. */ xx= cosang; yx= sinang; zx= 0.0; xy= -sinang; yy= cosang; zy= 0.0; xz= 0.0; yz= 0.0; zz= 1.0; ang_last= angle; } /* Perform rotation. */ pos2[0]= xx * pos1[0] + yx * pos1[1] + zx * pos1[2]; pos2[1]= xy * pos1[0] + yy * pos1[1] + zy * pos1[2]; pos2[2]= xz * pos1[0] + yz * pos1[1] + zz * pos1[2]; return; } /********wobble */ void wobble( double tjd, short int direction, double xp, double yp, double *pos1, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: Corrects a vector in the ITRS (rotating Earth-fixed system) for polar motion, and also corrects the longitude origin (by a tiny amount) to the Terrestrial Intermediate Origin (TIO). The ITRS vector is thereby transformed to the terrestrial intermediate system, based on the true (rotational) equator and TIO. Because the true equator is the plane orthogonal to the direction of the Celestial Intermediate Pole (CIP), the components of the output vector are referred to z and x axes toward the CIP and TIO, respectively. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. Lambert & Bizouard (2002), Astronomy and Astrophysics 394, 317-321. INPUT ARGUMENTS: tjd (double) TT or UT1 Julian date. direction (short int) Flag determining 'direction' of transformation; direction = 0 transformation applied, ITRS to terrestrial intermediate system direction != 0 inverse transformation applied, terrestrial intermediate system to ITRS xp (double) Conventionally-defined X coordinate of Celestial Intermediate Pole with respect to ITRS pole, in arcseconds. yp (double) Conventionally-defined Y coordinate of Celestial Intermediate Pole with respect to ITRS pole, in arcseconds. pos1[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to ITRS axes. OUTPUT ARGUMENTS: pos2[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to true equator and TIO. RETURNED VALUE: None. GLOBALS USED: T0, ASEC2RAD novascon.c FUNCTIONS CALLED: sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/08-93/WTH (USNO/AA) Translate Fortran. V2.0/10-03/JAB (USNO/AA) Update for IAU 2000 resolutions. V2.1/01-05/JAB (USNO/AA) Include higher-order terms in the rotation. V2.2/06-05/JAB (USNO/AA) Corrected sign of first term in expression for 'yy' (should be -). V2.3/03-09/JAB (USNO/AA) Add 'direction' flag and inverse transformation; conformed input variables to IERS conventions. NOTES: 1. This function is the C version of NOVAS Fortran routine 'wobble'. ------------------------------------------------------------------------ */ { double xpole, ypole, t, sprime, tiolon, sinx, cosx, siny, cosy, sinl, cosl, xx, yx, zx, xy, yy, zy, xz, yz, zz; xpole= xp * ASEC2RAD; ypole= yp * ASEC2RAD; /* Compute approximate longitude of TIO, using eq. (10) of the second reference. Note that 'tiolon,' the longitude correction, is negligible for most astronomical purposes. */ t= ( tjd - T0 ) / 36525.0; sprime= -47.0e-6 * t; tiolon= -sprime * ASEC2RAD; /* Compute elements of rotation matrix. Equivalent to R3(-s')R2(x)R1(y) as per IERS Conventions (2003). */ sinx= sin( xpole ); cosx= cos( xpole ); siny= sin( ypole ); cosy= cos( ypole ); sinl= sin( tiolon ); cosl= cos( tiolon ); xx= cosx * cosl; yx= sinx * siny * cosl + cosy * sinl; zx= -sinx * cosy * cosl + siny * sinl; xy= -cosx * sinl; yy= -sinx * siny * sinl + cosy * cosl; zy= sinx * cosy * sinl + siny * cosl; xz= sinx; yz= -cosx * siny; zz= cosx * cosy; /* Perform rotation from ITRS to terrestrial intermediate system. */ if ( direction == 0 ) { pos2[0]= xx * pos1[0] + yx * pos1[1] + zx * pos1[2]; pos2[1]= xy * pos1[0] + yy * pos1[1] + zy * pos1[2]; pos2[2]= xz * pos1[0] + yz * pos1[1] + zz * pos1[2]; } else /* Perform rotation from terrestrial intermediate system to ITRS. */ { pos2[0]= xx * pos1[0] + xy * pos1[1] + xz * pos1[2]; pos2[1]= yx * pos1[0] + yy * pos1[1] + yz * pos1[2]; pos2[2]= zx * pos1[0] + zy * pos1[1] + zz * pos1[2]; } return; } /********terra */ void terra( on_surface *location, double st, double *pos, double *vel ) /* ------------------------------------------------------------------------ PURPOSE: Computes the position and velocity vectors of a terrestrial observer with respect to the center of the Earth. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. INPUT ARGUMENTS: *location (struct on_surface) Pointer to structure containing observer's location (defined in novas.h). st (double) Local apparent sidereal time at reference meridian in hours. OUTPUT ARGUMENTS: pos[3] (double) Position vector of observer with respect to center of Earth, equatorial rectangular coordinates, referred to true equator and equinox of date, components in AU. vel[3] (double) Velocity vector of observer with respect to center of Earth, equatorial rectangular coordinates, referred to true equator and equinox of date, components in AU/day. RETURNED VALUE: None. GLOBALS USED: AU_KM, ERAD, F novascon.c ANGVEL, DEG2RAD novascon.c FUNCTIONS CALLED: sin math.h cos math.h sqrt math.h VER./DATE/ PROGRAMMER: V1.0/04-93/WTH (USNO/AA): Translate Fortran. V1.1/06-98/JAB (USNO/AA): Move constants 'f' and 'omega' to file 'novascon.c'. V1.2/10-03/JAB (USNO/AA): Updates Notes; removed call to 'pow'. V1.3/12-04/JAB (USNO/AA): Update to use 'on_surface" structure. V1.4/09-09/WKP (USNO/AA): Moved ht_km calculation from first_entry block. NOTES: 1. If reference meridian is Greenwich and st=0, 'pos' is effectively referred to equator and Greenwich. 2. This function ignores polar motion, unless the observer's longitude and latitude have been corrected for it, and variation in the length of day (angular velocity of earth). 3. The true equator and equinox of date do not form an inertial system. Therefore, with respect to an inertial system, the very small velocity component (several meters/day) due to the precession and nutation of the Earth's axis is not accounted for here. 4. This function is the C version of NOVAS Fortran routine 'terra'. ------------------------------------------------------------------------ */ { static short int first_entry= 1; short int j; static double erad_km, ht_km; double df, df2, phi, sinphi, cosphi, c, s, ach, ash, stlocl, sinst, cosst; if ( first_entry ) { erad_km= ERAD / 1000.0; first_entry= 0; } /* Compute parameters relating to geodetic to geocentric conversion. */ df= 1.0 - F; df2= df * df; phi= location->latitude * DEG2RAD; sinphi= sin( phi ); cosphi= cos( phi ); c= 1.0 / sqrt( cosphi * cosphi + df2 * sinphi * sinphi ); s= df2 * c; ht_km= location->height / 1000.0; ach= erad_km * c + ht_km; ash= erad_km * s + ht_km; /* Compute local sidereal time factors at the observer's longitude. */ stlocl= ( st * 15.0 + location->longitude ) * DEG2RAD; sinst= sin( stlocl ); cosst= cos( stlocl ); /* Compute position vector components in kilometers. */ pos[0]= ach * cosphi * cosst; pos[1]= ach * cosphi * sinst; pos[2]= ash * sinphi; /* Compute velocity vector components in kilometers/sec. */ vel[0]= -ANGVEL * ach * cosphi * sinst; vel[1]= ANGVEL * ach * cosphi * cosst; vel[2]= 0.0; /* Convert position and velocity components to AU and AU/DAY. */ for ( j= 0; j < 3; j++ ) { pos[j]/= AU_KM; vel[j]/= AU_KM; vel[j]*= 86400.0; } return; } /********e_tilt */ void e_tilt( double jd_tdb, short int accuracy, double *mobl, double *tobl, double *ee, double *dpsi, double *deps ) /* ------------------------------------------------------------------------ PURPOSE: Computes quantities related to the orientation of the Earth's rotation axis at Julian date 'jd_tdb'. REFERENCES: None. INPUT ARGUMENTS: jd_tdb (double) TDB Julian Date. accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *mobl (double) Mean obliquity of the ecliptic in degrees at 'jd_tdb'. *tobl (double) True obliquity of the ecliptic in degrees at 'jd_tdb'. *ee (double) Equation of the equinoxes in seconds of time at 'jd_tdb'. *dpsi (double) Nutation in longitude in arcseconds at 'jd_tdb'. *deps (double) Nutation in obliquity in arcseconds at 'jd_tdb'. RETURNED VALUE: None. GLOBALS USED: PSI_COR, EPS_COR novas.c T0, ASEC2RAD novascon.c DEG2RAD novascon.c FUNCTIONS CALLED: nutation_angles novas.c ee_ct novas.c mean_obliq novas.c fabs math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/08-93/WTH (USNO/AA) Translate Fortran. V1.1/06-97/JAB (USNO/AA) Incorporate IAU (1994) and IERS (1996) adjustment to the "equation of the equinoxes". V1.2/10-97/JAB (USNO/AA) Implement function that computes arguments of the nutation series. V1.3/07-98/JAB (USNO/AA) Use global variables 'PSI_COR' and 'EPS_COR' to apply celestial pole offsets for high-precision applications. V2.0/10-03/JAB (USNO/AA) Update function for IAU 2000 resolutions. V2.1/12-04/JAB (USNO/AA) Add 'mode' argument. V2.2/01-06/WKP (USNO/AA) Changed 'mode' to 'accuracy'. NOTES: 1. Values of the celestial pole offsets 'PSI_COR' and 'EPS_COR' are set using function 'cel_pole', if desired. See the prolog of 'cel_pole' for details. 2. This function is the C version of NOVAS Fortran routine 'etilt'. ------------------------------------------------------------------------ */ { static short int accuracy_last= 0; short int acc_diff; static double jd_last= 0.0; static double dp, de, c_terms; double t, d_psi, d_eps, mean_ob, true_ob, eq_eq; /* Compute time in Julian centuries from epoch J2000.0. */ t= ( jd_tdb - T0 ) / 36525.0; /* Check for difference in accuracy mode from last call. */ acc_diff= accuracy - accuracy_last; /* Compute the nutation angles (arcseconds) if the input Julian date is significantly different from the last Julian date, or the accuracy mode has changed from the last call. */ if ( ( ( fabs( jd_tdb - jd_last ) ) > 1.0e-8 ) || ( acc_diff != 0 ) ) { nutation_angles( t, accuracy, &dp, &de ); /* Obtain complementary terms for equation of the equinoxes in arcseconds. */ c_terms= ee_ct( jd_tdb, 0.0, accuracy ) / ASEC2RAD; /* Reset the values of the last Julian date and last mode. */ jd_last= jd_tdb; accuracy_last= accuracy; } /* Apply observed celestial pole offsets. */ d_psi= dp + PSI_COR; d_eps= de + EPS_COR; /* Compute mean obliquity of the ecliptic in arcseconds. */ mean_ob= mean_obliq( jd_tdb ); /* Compute true obliquity of the ecliptic in arcseconds. */ true_ob= mean_ob + d_eps; /* Convert obliquity values to degrees. */ mean_ob/= 3600.0; true_ob/= 3600.0; /* Compute equation of the equinoxes in seconds of time. */ eq_eq= d_psi * cos( mean_ob * DEG2RAD ) + c_terms; eq_eq/= 15.0; /* Set output values. */ *dpsi= d_psi; *deps= d_eps; *ee= eq_eq; *mobl= mean_ob; *tobl= true_ob; return; } /********cel_pole */ short int cel_pole( double tjd, short int type, double dpole1, double dpole2 ) /* ------------------------------------------------------------------------ PURPOSE: This function allows for the specification of celestial pole offsets for high-precision applications. Each set of offsets is a correction to the modeled position of the pole for a specific date, derived from observations and published by the IERS. REFERENCES: Kaplan, G. (2005), US Naval Observatory Circular 179. Kaplan, G. (2003), USNO/AA Technical Note 2003-03. INPUT ARGUMENTS: tjd (double) TDB or TT Julian date for pole offsets. type (short int) Type of pole offset = 1 for corrections to angular coordinates of modeled pole referred to mean ecliptic of date, that is, delta-delta-psi and delta-delta-epsilon. = 2 for corrections to components of modeled pole unit vector referred to GCRS axes, that is, dx and dy. dpole1 (double) Value of celestial pole offset in first coordinate, (delta-delta-psi or dx) in milliarcseconds. dpole2 (double) Value of celestial pole offset in second coordinate, (delta-delta-epsilon or dy) in milliarcseconds. OUTPUT ARGUMENTS: None. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... Invalid value of 'type'. GLOBALS USED: PSI_COR, EPS_COR novas.c T0, ASEC2RAD novascon.c FUNCTIONS CALLED: frame_tie novas.c precession novas.c mean_obliq novas.c sin math.h VER./DATE/ PROGRAMMER: V1.0/12-04/JAB (USNO/AA) NOTES: 1. This function sets the values of global variables 'PSI_COR' and 'EPS_COR' declared at the top of file 'novas.c'. These global variables are used only in NOVAS function 'e_tilt'. 2. This function, if used, should be called before any other NOVAS functions for a given date. Values of the pole offsets specified via a call to this function will be used until explicitly changed. 3. 'tjd' is used only for 'type' = 2, to transform dx and dy to the equivalent delta-delta-psi and delta-delta-epsilon values. 4. For 'type' = 2, dx and dy are unit vector component corrections, but are expressed in milliarcseconds simply by multiplying by 206264806, the number of milliarcseconds in one radian. 5. This function is the C version of NOVAS Fortran routine 'celpol'. ------------------------------------------------------------------------ */ { short int error= 0; double dx, dy, t, mean_ob, sin_e, x, dz, dp1[3], dp2[3], dp3[3]; switch ( type ) { case ( 1 ): /* Angular coordinates of modeled pole referred to mean ecliptic of date, that is,delta-delta-psi and delta-delta-epsilon. */ PSI_COR= dpole1 * 1.0e-3; EPS_COR= dpole2 * 1.0e-3; break; case ( 2 ): /* Components of modeled pole unit vector referred to GCRS axes, that is, dx and dy. */ dx= dpole1; dy= dpole2; t= ( tjd - T0 ) / 36525.0; /* Compute sin_e of mean obliquity of date. */ mean_ob= mean_obliq( tjd ); sin_e= sin( mean_ob * ASEC2RAD ); /* The following algorithm, to transform dx and dy to delta-delta-psi and delta-delta-epsilon, is from eqs. (7)-(9) of the second reference. Trivial model of pole trajectory in GCRS allows computation of dz. */ x= ( 2004.190 * t ) * ASEC2RAD; dz= -( x + 0.5 * x * x * x ) * dx; /* Form pole offset vector (observed - modeled) in GCRS. */ dp1[0]= dx * 1.0e-3 * ASEC2RAD; dp1[1]= dy * 1.0e-3 * ASEC2RAD; dp1[2]= dz * 1.0e-3 * ASEC2RAD; /* Precess pole offset vector to mean equator and equinox of date. */ frame_tie( dp1, 1, dp2 ); precession( T0, dp2, tjd, dp3 ); /* Compute delta-delta-psi and delta-delta-epsilon in arcseconds. */ PSI_COR= ( dp3[0] / sin_e ) / ASEC2RAD; EPS_COR= dp3[1] / ASEC2RAD; break; default: /* Invalid value of 'type'. */ error= 1; break; } return ( error ); } /********ee_ct */ double ee_ct( double jd_high, double jd_low, short int accuracy ) /* ------------------------------------------------------------------------ PURPOSE: To compute the "complementary terms" of the equation of the equinoxes. REFERENCES: Capitaine, N., Wallace, P.T., and McCarthy, D.D. (2003). Astron. & Astrophys. 406, p. 1135-1149. Table 3. IERS Conventions (2010), Chapter 5, p. 60, Table 5.2e. (Table 5.2e presented in the printed publication is a truncated series. The full series, which is used in NOVAS, is available on the IERS Conventions Center website in file tab5.2e.txt.) ftp://tai.bipm.org/iers/conv2010/chapter5/ INPUT ARGUMENTS: jd_high (double) High-order part of TT Julian date. jd_low (double) Low-order part of TT Julian date. accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: None RETURNED VALUE: (double) Complementary terms, in radians. GLOBALS USED: T0, ASEC2RAD novascon.c TWOPI novascon.c FUNCTIONS CALLED: norm_ang novas.c fund_args novas.c fmod math.h sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/09-03/JAB (USNO/AA) V1.1/12-04/JAB (USNO/AA) Added low-accuracy formula. V1.2/01-06/WKP (USNO/AA) Changed 'mode' to 'accuracy'. V1.3/11-10/JAB (USNO/AA) Updated reference and notes. V1.4/03-11/WKP (USNO/AA) Added braces to 2-D array initialization to quiet gcc warnings. NOTES: 1. The series used in this function was derived from the first reference. This same series was also adopted for use in the IAU's Standards of Fundamental Astronomy (SOFA) software (i.e., subroutine eect00.for and function eect00.c). 2. The low-accuracy series used in this function is a simple implementation derived from the first reference, in which terms smaller than 2 microarcseconds have been omitted. 3. This function is based on NOVAS Fortran routine 'eect2000', with the low-accuracy formula taken from NOVAS Fortran routine 'etilt'. ------------------------------------------------------------------------ */ { short int i, j; double t, fa[14], fa2[5], s0, s1, a, c_terms; /* Argument coefficients for t^0. */ const short int ke0_t[33][14]= { {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 2, -2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 2, -2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 2, -2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* Sine and cosine coefficients for t^0. */ const double se0_t[33][2]= { {+2640.96e-6, -0.39e-6}, {+63.52e-6, -0.02e-6}, {+11.75e-6, +0.01e-6}, {+11.21e-6, +0.01e-6}, {-4.55e-6, +0.00e-6}, {+2.02e-6, +0.00e-6}, {+1.98e-6, +0.00e-6}, {-1.72e-6, +0.00e-6}, {-1.41e-6, -0.01e-6}, {-1.26e-6, -0.01e-6}, {-0.63e-6, +0.00e-6}, {-0.63e-6, +0.00e-6}, {+0.46e-6, +0.00e-6}, {+0.45e-6, +0.00e-6}, {+0.36e-6, +0.00e-6}, {-0.24e-6, -0.12e-6}, {+0.32e-6, +0.00e-6}, {+0.28e-6, +0.00e-6}, {+0.27e-6, +0.00e-6}, {+0.26e-6, +0.00e-6}, {-0.21e-6, +0.00e-6}, {+0.19e-6, +0.00e-6}, {+0.18e-6, +0.00e-6}, {-0.10e-6, +0.05e-6}, {+0.15e-6, +0.00e-6}, {-0.14e-6, +0.00e-6}, {+0.14e-6, +0.00e-6}, {-0.14e-6, +0.00e-6}, {+0.14e-6, +0.00e-6}, {+0.13e-6, +0.00e-6}, {-0.11e-6, +0.00e-6}, {+0.11e-6, +0.00e-6}, {+0.11e-6, +0.00e-6}}; /* Sine and cosine coefficients for t^1. */ const double se1[2]= {-0.87e-6, +0.00e-6}; /* Interval between fundamental epoch J2000.0 and current date. */ t= ( ( jd_high - T0 ) + jd_low ) / 36525.0; /* High accuracy mode. */ if ( accuracy == 0 ) { /* Fundamental Arguments. Mean Anomaly of the Moon. */ fa[0]= norm_ang( ( 485868.249036 + ( 715923.2178 + ( 31.8792 + ( 0.051635 + ( -0.00024470 ) * t ) * t ) * t ) * t ) * ASEC2RAD + fmod( 1325.0 * t, 1.0 ) * TWOPI ); /* Mean Anomaly of the Sun. */ fa[1]= norm_ang( ( 1287104.793048 + ( 1292581.0481 + ( -0.5532 + ( +0.000136 + ( -0.00001149 ) * t ) * t ) * t ) * t ) * ASEC2RAD + fmod( 99.0 * t, 1.0 ) * TWOPI ); /* Mean Longitude of the Moon minus Mean Longitude of the Ascending Node of the Moon. */ fa[2]= norm_ang( ( 335779.526232 + ( 295262.8478 + ( -12.7512 + ( -0.001037 + ( 0.00000417 ) * t ) * t ) * t ) * t ) * ASEC2RAD + fmod( 1342.0 * t, 1.0 ) * TWOPI ); /* Mean Elongation of the Moon from the Sun. */ fa[3]= norm_ang( ( 1072260.703692 + ( 1105601.2090 + ( -6.3706 + ( 0.006593 + ( -0.00003169 ) * t ) * t ) * t ) * t ) * ASEC2RAD + fmod( 1236.0 * t, 1.0 ) * TWOPI ); /* Mean Longitude of the Ascending Node of the Moon. */ fa[4]= norm_ang( ( 450160.398036 + ( -482890.5431 + ( 7.4722 + ( 0.007702 + ( -0.00005939 ) * t ) * t ) * t ) * t ) * ASEC2RAD + fmod( -5.0 * t, 1.0 ) * TWOPI ); fa[5]= norm_ang( 4.402608842 + 2608.7903141574 * t ); fa[6]= norm_ang( 3.176146697 + 1021.3285546211 * t ); fa[7]= norm_ang( 1.753470314 + 628.3075849991 * t ); fa[8]= norm_ang( 6.203480913 + 334.0612426700 * t ); fa[9]= norm_ang( 0.599546497 + 52.9690962641 * t ); fa[10]= norm_ang( 0.874016757 + 21.3299104960 * t ); fa[11]= norm_ang( 5.481293872 + 7.4781598567 * t ); fa[12]= norm_ang( 5.311886287 + 3.8133035638 * t ); fa[13]= ( 0.024381750 + 0.00000538691 * t ) * t; /* Evaluate the complementary terms. */ s0= 0.0; s1= 0.0; for ( i= 32; i >= 0; i-- ) { a= 0.0; for ( j= 0; j < 14; j++ ) { a+= (double)ke0_t[i][j] * fa[j]; } s0+= ( se0_t[i][0] * sin( a ) + se0_t[i][1] * cos( a ) ); } a= 0.0; for ( j= 0; j < 14; j++ ) { a+= (double)( ke1[j] ) * fa[j]; } s1+= ( se1[0] * sin( a ) + se1[1] * cos( a ) ); c_terms= ( s0 + s1 * t ); } else /* Low accuracy mode: Terms smaller than 2 microarcseconds omitted. */ { fund_args( t, fa2 ); c_terms= 2640.96e-6 * sin( fa2[4] ) + 63.52e-6 * sin( 2.0 * fa2[4] ) + 11.75e-6 * sin( 2.0 * fa2[2] - 2.0 * fa2[3] + 3.0 * fa2[4] ) + 11.21e-6 * sin( 2.0 * fa2[2] - 2.0 * fa2[3] + fa2[4] ) - 4.55e-6 * sin( 2.0 * fa2[2] - 2.0 * fa2[3] + 2.0 * fa2[4] ) + 2.02e-6 * sin( 2.0 * fa2[2] + 3.0 * fa2[4] ) + 1.98e-6 * sin( 2.0 * fa2[2] + fa2[4] ) - 1.72e-6 * sin( 3.0 * fa2[4] ) - 0.87e-6 * t * sin( fa2[4] ); } return ( c_terms*= ASEC2RAD ); } /********frame_tie */ void frame_tie( double *pos1, short int direction, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: To transform a vector from the dynamical reference system to the International Celestial Reference System (ICRS), or vice versa. The dynamical reference system is based on the dynamical mean equator and equinox of J2000.0. The ICRS is based on the space- fixed ICRS axes defined by the radio catalog positions of several hundred extragalactic objects. REFERENCES: Hilton, J. and Hohenkerk, C. (2004), Astronomy and Astrophysics 413, 765-770, eq. (6) and (8). IERS (2003) Conventions, Chapter 5. INPUT ARGUMENTS: pos1[3] (double) Position vector, equatorial rectangular coordinates. direction (short int) Set 'direction' < 0 for dynamical to ICRS transformation. Set 'direction' >= 0 for ICRS to dynamical transformation. OUTPUT ARGUMENTS: pos2[3] (double) Position vector, equatorial rectangular coordinates. RETURNED VALUE: None. GLOBALS USED: ASEC2RAD novascon.c FUNCTIONS CALLED: None. VER./DATE/ PROGRAMMER: V1.0/09-03/JAB (USNO/AA) V1.1/02-06/WKP (USNO/AA) Added second-order corrections to diagonal elements. NOTES: 1. For geocentric coordinates, the same transformation is used between the dynamical reference system and the GCRS. 2. This function is the C version of NOVAS Fortran routine 'frame'. ------------------------------------------------------------------------ */ { static short int compute_matrix= 1; /* 'xi0', 'eta0', and 'da0' are ICRS frame biases in arcseconds taken from IERS (2003) Conventions, Chapter 5. */ const double xi0= -0.0166170; const double eta0= -0.0068192; const double da0= -0.01460; static double xx, yx, zx, xy, yy, zy, xz, yz, zz; /* Compute elements of rotation matrix to first order the first time this function is called. Elements will be saved for future use and not recomputed. */ if ( compute_matrix == 1 ) { xx= 1.0; yx= -da0 * ASEC2RAD; zx= xi0 * ASEC2RAD; xy= da0 * ASEC2RAD; yy= 1.0; zy= eta0 * ASEC2RAD; xz= -xi0 * ASEC2RAD; yz= -eta0 * ASEC2RAD; zz= 1.0; /* Include second-order corrections to diagonal elements. */ xx= 1.0 - 0.5 * ( yx * yx + zx * zx ); yy= 1.0 - 0.5 * ( yx * yx + zy * zy ); zz= 1.0 - 0.5 * ( zy * zy + zx * zx ); compute_matrix= 0; } /* Perform the rotation in the sense specified by 'direction'. */ if ( direction < 0 ) { /* Perform rotation from dynamical system to ICRS. */ pos2[0]= xx * pos1[0] + yx * pos1[1] + zx * pos1[2]; pos2[1]= xy * pos1[0] + yy * pos1[1] + zy * pos1[2]; pos2[2]= xz * pos1[0] + yz * pos1[1] + zz * pos1[2]; } else { /* Perform rotation from ICRS to dynamical system. */ pos2[0]= xx * pos1[0] + xy * pos1[1] + xz * pos1[2]; pos2[1]= yx * pos1[0] + yy * pos1[1] + yz * pos1[2]; pos2[2]= zx * pos1[0] + zy * pos1[1] + zz * pos1[2]; } return; } /********proper_motion */ void proper_motion( double jd_tdb1, double *pos, double *vel, double jd_tdb2, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: Applies proper motion, including foreshortening effects, to a star's position. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. INPUT ARGUMENTS: jd_tdb1 (double) TDB Julian date of first epoch. pos[3] (double) Position vector at first epoch. vel[3] (double) Velocity vector at first epoch. jd_tdb2 (double) TDB Julian date of second epoch. OUTPUT ARGUMENTS: pos2[3] (double) Position vector at second epoch. RETURNED VALUE: None. GLOBALS USED: None. FUNCTIONS CALLED: None. VER./DATE/ PROGRAMMER: V1.0/01-93/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Updated to C programming standards. NOTES: 1. This function is the C version of NOVAS Fortran routine 'propmo'. ------------------------------------------------------------------------ */ { short int j; for ( j= 0; j < 3; j++ ) { pos2[j]= pos[j] + ( vel[j] * ( jd_tdb2 - jd_tdb1 ) ); } return; } /********bary2obs */ void bary2obs( double *pos, double *pos_obs, double *pos2, double *lighttime ) /* ------------------------------------------------------------------------ PURPOSE: This function moves the origin of coordinates from the barycenter of the solar system to the observer (or the geocenter); i.e., this function accounts for parallax (annual+geocentric or just annual). REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. INPUT ARGUMENTS: pos1[3] (double) Position vector, referred to origin at solar system barycenter, components in AU. pos_obs[3] (double) Position vector of observer (or the geocenter), with respect to origin at solar system barycenter, components in AU. OUTPUT ARGUMENTS: pos2[3] (double) Position vector, referred to origin at center of mass of the Earth, components in AU. *lighttime (double) Light time from object to Earth in days. RETURNED VALUE: None. GLOBALS USED: C_AUDAY novascon.c FUNCTIONS CALLED: sqrt math.h VER./DATE/ PROGRAMMER: V1.0/01-93/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Update to C Standards. V1.2/10-03/JAB (USNO/AA) Remove calls to 'pow'. V2.0/01-05/JAB (USNO/AA) Update documentation; change 'earthvector' to 'pos_obs'. NOTES: 1. This function is the C version of NOVAS Fortran routine 'geocen'. ------------------------------------------------------------------------ */ { short int j; /* Translate vector to geocentric coordinates. */ for ( j= 0; j < 3; j++ ) { pos2[j]= pos[j] - pos_obs[j]; } /* Calculate length of vector in terms of light time. */ *lighttime= sqrt( pos2[0] * pos2[0] + pos2[1] * pos2[1] + pos2[2] * pos2[2] ) / C_AUDAY; return; } /********geo_posvel */ short int geo_posvel( double jd_tt, double delta_t, short int accuracy, observer *obs, double *pos, double *vel ) /* ------------------------------------------------------------------------ PURPOSE: This function computes the geocentric position and velocity of an observer on the surface of the earth or on a near-earth spacecraft. The final vectors are expressed in the GCRS. REFERENCES: None. INPUT ARGUMENTS: jd_tt (double) TT Julian date. delta_t (double) Value of Delta T (= TT - UT1) at 'jd_tt'. accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy *obs (struct observer) Data specifying the location of the observer (struct defined in novas.h). OUTPUT ARGUMENTS: *pos (double) Position vector of observer, with respect to origin at geocenter, referred to GCRS axes, components in AU. *vel (double) Velocity vector of observer, with respect to origin at geocenter, referred to GCRS axes, components in AU/day. RETURNED VALUE: (short int) = 0 ... everything OK. = 1 ... invalid value of 'accuracy'. GLOBALS USED: AU_KM, T0 novascon.c FUNCTIONS CALLED: tdb2tt novas.c sidereal_time novas.c e_tilt novas.c terra novas.c nutation novas.c precession novas.c frame_tie novas.c fabs math.h VER./DATE/ PROGRAMMER: V1.0/12-04/JAB (USNO/AA) V2.2/12-05/WKP (USNO/AA) Updated error handling. V2.3/01-06/WKP (USNO/AA) Changed 'mode' to 'accuracy'. V2.4/02-06/WKP (USNO/AA) Changed time argument in sidereal_time call from 'jd_tt' to 'jd_ut1'. V2.5/04-06/WKP (USNO/AA) Corrected calculation of 'fac' and changed it to a static. V2.6/10-06/JAB (USNO/AA) Remove 'jd_tdb' input argument; TDB is approximated by TT. V2.7/02-07/JAB (USNO/AA) Compute 'jd_tdb' corresponding to input 'jd_tt'. NOTES: 1. This function is the C version of NOVAS Fortran routine 'geopos'. This C function differs from its Fortran counterpart in that it does not use the input TT time as a substitute for the TDB time. ------------------------------------------------------------------------ */ { static double t_last= 0; static double gast, fac; static short int first_time= 1; double x, secdif, gmst, x1, x2, x3, x4, eqeq, pos1[3], vel1[3], pos2[3], vel2[3], pos3[3], vel3[3], jd_tdb, jd_ut1; short int error= 0; /* Invalid value of 'accuracy'. */ if ( ( accuracy < 0 ) || ( accuracy > 1 ) ) return ( error= 1 ); /* Compute 'jd_tdb', the TDB Julian date corresponding to 'jd_tt'. */ jd_tdb= jd_tt; tdb2tt( jd_tdb, &x, &secdif ); jd_tdb= jd_tt + secdif / 86400.0; switch ( obs->where ) { /* Observer at geocenter. Trivial case. */ case ( 0 ): pos[0]= 0.0; pos[1]= 0.0; pos[2]= 0.0; vel[0]= 0.0; vel[1]= 0.0; vel[2]= 0.0; return ( error= 0 ); break; /* Other two cases: Get geocentric position and velocity vectors of observer wrt equator and equinox of date. Observer on surface of Earth. */ case ( 1 ): /* Compute UT1 and sidereal time. */ jd_ut1= jd_tt - ( delta_t / 86400.0 ); if ( fabs( jd_ut1 - t_last ) > 1.0e-8 ) { sidereal_time( jd_ut1, 0.0, delta_t, 0, 1, accuracy, &gmst ); e_tilt( jd_tdb, accuracy, &x1, &x2, &eqeq, &x3, &x4 ); gast= gmst + eqeq / 3600.0; t_last= jd_ut1; } /* Function 'terra' does the hard work, given sidereal time. */ terra( &obs->on_surf, gast, pos1, vel1 ); break; /* Observer on near-earth spacecraft. */ case ( 2 ): /* Convert units to AU and AU/day. */ if ( first_time ) { fac= AU_KM / 86400.0; first_time= 0; } pos1[0]= obs->near_earth.sc_pos[0] / AU_KM; pos1[1]= obs->near_earth.sc_pos[1] / AU_KM; pos1[2]= obs->near_earth.sc_pos[2] / AU_KM; vel1[0]= obs->near_earth.sc_vel[0] / fac; vel1[1]= obs->near_earth.sc_vel[1] / fac; vel1[2]= obs->near_earth.sc_vel[2] / fac; break; } /* Transform geocentric position vector of observer to GCRS. */ nutation( jd_tdb, -1, accuracy, pos1, pos2 ); precession( jd_tdb, pos2, T0, pos3 ); frame_tie( pos3, -1, pos ); /* Transform geocentric velocity vector of observer to GCRS. */ nutation( jd_tdb, -1, accuracy, vel1, vel2 ); precession( jd_tdb, vel2, T0, vel3 ); frame_tie( vel3, -1, vel ); return ( error= 0 ); } /********light_time */ short int light_time( double jd_tdb, object *ss_object, double pos_obs[3], double tlight0, short int accuracy, double pos[3], double *tlight ) /* ------------------------------------------------------------------------ PURPOSE: This function computes the geocentric position of a solar system body, as antedated for light-time. REFERENCES: None. INPUT ARGUMENTS: jd_tdb (double) TDB Julian date of observation. *ss_object (struct object) Pointer to structure containing the designation for the solar system body (defined in novas.h). pos_obs[3] (double) Position vector of observer (or the geocenter), with respect to origin at solar system barycenter, referred to ICRS axes, components in AU. tlight0 (double) First approximation to light-time, in days (can be set to 0.0 if unknown). accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: pos[3] (double) Position vector of body, with respect to origin at observer (or the geocenter), referred to ICRS axes, components in AU. tlight (double) Final light-time, in days. RETURNED VALUE: (short int) = 0 ... everything OK. = 1 ... algorithm failed to converge after 10 iterations. > 10 ... error is 10 + error from function 'solarsystem'. GLOBALS USED: None. FUNCTIONS CALLED: ephemeris novas.c bary2obs novas.c fabs math.h VER./DATE/ PROGRAMMER: V1.0/09-04/JAB (USNO/AA) V1.1/06-05/JAB (USNO/AA): Changed the convergence tolerance from 1.0e-8 to 1.0e-10 V1.2/04-06/JAB (USNO/AA): Changed the convergence tolerance from 1.0e-10 to 1.0e-9 V2.0/12-06/JAB (USNO/AA): Support use of split Julian date to improve accuracy when the full accuracy option is selected. V2.1/11-07/JAB (USNO/AA): Changed high-accuracy convergence tolerance from 1.0e-11 to 1.0e-12. V2.2/10-08/JAB (USNO/AA): Use function 'ephemeris' instead of direct calls to the solar system functions. V2.3/09-10/WKP (USNO/AA): Initialized 't3' variable to silence compiler warning. NOTES: 1. This function is the C version of NOVAS Fortran routine 'littim'. ------------------------------------------------------------------------ */ { short int error= 0; short int iter= 0; double tol, jd[2], t1, t2, t3= 0.0, pos1[3], vel1[3]; /* Set light-time convergence tolerance. If full-accuracy option has been selected, split the Julian date into whole days + fraction of day. */ if ( accuracy == 0 ) { tol= 1.0e-12; jd[0]= (double)( (long int)jd_tdb ); t1= jd_tdb - jd[0]; t2= t1 - tlight0; } else { tol= 1.0e-9; jd[0]= 0.0; jd[1]= 0.0; t1= jd_tdb; t2= jd_tdb - tlight0; } /* Iterate to obtain correct light-time (usually converges rapidly). */ do { if ( iter > 10 ) { error= 1; *tlight= 0.0; break; } if ( iter > 0 ) { t2= t3; } jd[1]= t2; error= ephemeris( jd, ss_object, 0, accuracy, pos1, vel1 ); if ( error != 0 ) { error+= 10; *tlight= 0.0; break; } bary2obs( pos1, pos_obs, pos, tlight ); t3= t1 - *tlight; iter++; } while ( fabs( t3 - t2 ) > tol ); return ( error ); } /********d_light */ double d_light( double *pos1, double *pos_obs ) /* ------------------------------------------------------------------------ PURPOSE: This function returns the difference in light-time, for a star, between the barycenter of the solar system and the observer (or the geocenter). REFERENCES: None. INPUT ARGUMENTS: pos1[3] (double) Position vector of star, with respect to origin at solar system barycenter. pos_obs[3] (double) Position vector of observer (or the geocenter), with respect to origin at solar system barycenter, components in AU. OUTPUT ARGUMENTS: None. RETURNED VALUE: (double) Difference in light time, in the sense star to barycenter minus star to earth, in days. GLOBALS USED: C_AUDAY novascon.c FUNCTIONS CALLED: sqrt math.h VER./DATE/ PROGRAMMER: V1.0/12-04/JAB (USNO/AA) NOTES: 1. Alternatively, this function returns the light-time from the observer (or the geocenter) to a point on a light ray that is closest to a specific solar system body. For this purpose, 'pos1' is the position vector toward observed object, with respect to origin at observer (or the geocenter); 'pos_obs' is the position vector of solar system body, with respect to origin at observer (or the geocenter), components in AU; and the returned value is the light time to point on line defined by 'pos1' that is closest to solar system body (positive if light passes body before hitting observer, i.e., if 'pos1' is within 90 degrees of 'pos_obs'). 2. This function is the C version of NOVAS Fortran routine 'dlight'. ------------------------------------------------------------------------ */ { double dis, u1[3], diflt; /* From 'pos1', form unit vector 'u1' in direction of star or light source. */ dis= sqrt( pos1[0] * pos1[0] + pos1[1] * pos1[1] + pos1[2] * pos1[2] ); u1[0]= pos1[0] / dis; u1[1]= pos1[1] / dis; u1[2]= pos1[2] / dis; /* Light-time returned is the projection of vector 'pos_obs' onto the unit vector 'u1' (formed from 'pos1'), divided by the speed of light. */ diflt= ( pos_obs[0] * u1[0] + pos_obs[1] * u1[1] + pos_obs[2] * u1[2] ) / C_AUDAY; return ( diflt ); } /********grav_def */ short int grav_def( double jd_tdb, short int loc_code, short int accuracy, double *pos1, double *pos_obs, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: This function computes the total gravitational deflection of light for the observed object due to the major gravitating bodies in the solar system. This function valid for an observed body within the solar system as well as for a star. REFERENCES: Klioner, S. (2003), Astronomical Journal 125, 1580-1597, Section 6. INPUT ARGUMENTS: jd_tdb (double) TDB Julian date of observation. loc_code (short int) Code for location of observer, determining whether the gravitational deflection due to the earth itself is applied. = 0 ... No earth deflection (normally means observer is at geocenter) = 1 ... Add in earth deflection (normally means observer is on or above surface of earth, including earth orbit) accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy *pos1 (double) Position vector of observed object, with respect to origin at observer (or the geocenter), referred to ICRS axes, components in AU. *pos_obs (double) Position vector of observer (or the geocenter), with respect to origin at solar system barycenter, referred to ICRS axes, components in AU. OUTPUT ARGUMENTS: *pos2 (double) Position vector of observed object, with respect to origin at observer (or the geocenter), referred to ICRS axes, corrected for gravitational deflection, components in AU. RETURNED VALUE: (short int) = 0 ... Everything OK. < 30 ... Error from function 'ephemeris'. > 30 ... Error from function 'make_object'. GLOBALS USED: C_AUDAY novascon.c RMASS[12] novascon.c FUNCTIONS CALLED: make_cat_entry novas.c make_object novas.c ephemeris novas.c bary2obs novas.c d_light novas.c grav_vec novas.c sqrt math.h VER./DATE/ PROGRAMMER: V1.0/01-05/JAB (USNO/AA) V1.1/04-06/WKP (USNO/AA): Added second note (superceded). V1.2/10-08/JAB (USNO/AA): Substituted calls to 'ephemeris' for calls to 'solarsystem'; added actions based on 'accuracy' input. NOTES: 1. This function is the C version of NOVAS Fortran routine 'grvdef'. 2. If 'accuracy' is set to zero (full accuracy), three bodies (Sun, Jupiter, and Saturn) are used in the calculation. If the reduced-accuracy option is set, only the Sun is used in the calculation. In both cases, if the observer is not at the geocenter, the deflection due to the Earth is included. 3. The number of bodies used at full and reduced accuracy can be set by making a change to the code in this function as indicated in the comments. ------------------------------------------------------------------------ */ { /* The following list of body numbers and corresponding names identifies which gravitating bodies (aside from the Earth) are potentially used -- list is taken from Klioner's table 1, the order based on area of sky affected (col 2). Order is Sun, Jupiter, Saturn, Moon, Venus, Uranus, Neptune. */ char body_name[7][8]= {"Sun", "Jupiter", "Saturn", "Moon", "Venus", "Uranus", "Neptune"}; const short int body_num[7]= {10, 5, 6, 11, 2, 7, 8}; static short int first_time= 1; static short int nbodies_last= 0; short int error= 0; short int nbodies, i; double jd[2], tlt, pbody[3], vbody[3], pbodyo[3], x, dlt, tclose; cat_entry dummy_star; static object body[7], earth; jd[1]= 0.0; /* Initialize output vector of observed object to equal input vector. */ for ( i= 0; i < 3; i++ ) { pos2[i]= pos1[i]; } /* Set the number of bodies -- and hence the bodies used -- based on the value of the 'accuracy' flag. Change value of 'nbodies' to include or exclude gravitating bodies ('nbodies' <= 0 means no deflection calculated, 'nbodies' = 1 means Sun only, 'nbodies' = 2 means Sun + Jupiter, etc.) Default is 'nbodies' = 3: Sun + Jupiter + Saturn. */ if ( accuracy == 0 ) { nbodies= 3; } else { nbodies= 1; } /* Set up the structures of type 'object' containing the body information. */ if ( ( first_time == 1 ) || ( nbodies != nbodies_last ) ) { for ( i= 0; i < nbodies; i++ ) { if ( i == 0 ) { make_cat_entry( "dummy", " ", 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &dummy_star ); make_object( 0, 3, "Earth", &dummy_star, &earth ); } if ( ( error= make_object( 0, body_num[i], body_name[i], &dummy_star, &body[i] ) ) != 0 ) { return ( error+= 30 ); } } first_time= 0; nbodies_last= nbodies; } /* Compute light-time to observed object. */ tlt= sqrt( pos1[0] * pos1[0] + pos1[1] * pos1[1] + pos1[2] * pos1[2] ) / C_AUDAY; /* Cycle through gravitating bodies. */ for ( i= 0; i < nbodies; i++ ) { /* Get position of gravitating body wrt ss barycenter at time 'jd_tdb'. */ jd[0]= jd_tdb; if ( ( error= ephemeris( jd, &body[i], 0, accuracy, pbody, vbody ) ) != 0 ) { return ( error ); } /* Get position of gravitating body wrt observer at time 'jd_tdb'. */ bary2obs( pbody, pos_obs, pbodyo, &x ); /* Compute light-time from point on incoming light ray that is closest to gravitating body. */ dlt= d_light( pos2, pbodyo ); /* Get position of gravitating body wrt ss barycenter at time when incoming photons were closest to it. */ tclose= jd_tdb; if ( dlt > 0.0 ) tclose= jd_tdb - dlt; if ( tlt < dlt ) tclose= jd_tdb - tlt; jd[0]= tclose; if ( ( error= ephemeris( jd, &body[i], 0, accuracy, pbody, vbody ) ) != 0 ) { return ( error ); } /* Compute deflection due to gravitating body. */ grav_vec( pos2, pos_obs, pbody, RMASS[body_num[i]], pos2 ); } /* If observer is not at geocenter, add in deflection due to Earth. */ if ( loc_code != 0 ) { /* Get position of Earth wrt solar system barycenter at time 'jd_tdb'. */ jd[0]= jd_tdb; if ( ( error= ephemeris( jd, &earth, 0, accuracy, pbody, vbody ) ) != 0 ) { return ( error ); } /* Compute deflection due to Earth. */ grav_vec( pos2, pos_obs, pbody, RMASS[3], pos2 ); } return ( error ); } /********grav_vec */ void grav_vec( double *pos1, double *pos_obs, double *pos_body, double rmass, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: This function corrects position vector for the deflection of light in the gravitational field of an arbitrary body. This function valid for an observed body within the solar system as well as for a star. REFERENCES: Murray, C.A. (1981) Mon. Notices Royal Ast. Society 195, 639-648. See also formulae in Section B of the Astronomical Almanac, or Kaplan, G. et al. (1989) Astronomical Journal 97, 1197-1210, section iii f. INPUT ARGUMENTS: pos1[3] (double) Position vector of observed object, with respect to origin at observer (or the geocenter), components in AU. pos_obs [3] (double) Position vector of observer (or the geocenter), with respect to origin at solar system barycenter, components in AU. pos_body[3] (double) Position vector of gravitating body, with respect to origin at solar system barycenter, components in AU. rmass (double) Reciprocal mass of gravitating body in solar mass units, that is, Sun mass / body mass. OUTPUT ARGUMENTS: pos2[3] (double) Position vector of observed object, with respect to origin at observer (or the geocenter), corrected for gravitational deflection, components in AU. RETURNED VALUE: None. GLOBALS USED: C, AU, GS novascon.c FUNCTIONS CALLED: sqrt math.h fabs math.h VER./DATE/ PROGRAMMER: V1.0/12-04/JAB (USNO/AA) NOTES: 1. This function is the C version of NOVAS Fortran routine 'grvd'. ------------------------------------------------------------------------ */ { short int i; double pq[3], pe[3], pmag, emag, qmag, phat[3], ehat[3], qhat[3], pdotq, edotp, qdote, fac1, fac2, p2i; /* Construct vector 'pq' from gravitating body to observed object and construct vector 'pe' from gravitating body to observer. */ for ( i= 0; i < 3; i++ ) { pq[i]= pos_obs[i] + pos1[i] - pos_body[i]; pe[i]= pos_obs[i] - pos_body[i]; } /* Compute vector magnitudes and unit vectors. */ pmag= sqrt( pos1[0] * pos1[0] + pos1[1] * pos1[1] + pos1[2] * pos1[2] ); emag= sqrt( pe[0] * pe[0] + pe[1] * pe[1] + pe[2] * pe[2] ); qmag= sqrt( pq[0] * pq[0] + pq[1] * pq[1] + pq[2] * pq[2] ); for ( i= 0; i < 3; i++ ) { phat[i]= pos1[i] / pmag; ehat[i]= pe[i] / emag; qhat[i]= pq[i] / qmag; } /* Compute dot products of vectors. */ pdotq= phat[0] * qhat[0] + phat[1] * qhat[1] + phat[2] * qhat[2]; edotp= ehat[0] * phat[0] + ehat[1] * phat[1] + ehat[2] * phat[2]; qdote= qhat[0] * ehat[0] + qhat[1] * ehat[1] + qhat[2] * ehat[2]; /* If gravitating body is observed object, or is on a straight line toward or away from observed object to within 1 arcsec, deflection is set to zero; set 'pos2' equal to 'pos1'. */ if ( fabs( edotp ) > 0.99999999999 ) { for ( i= 0; i < 3; i++ ) { pos2[i]= pos1[i]; } } else { /* Compute scalar factors. */ fac1= 2.0 * GS / ( C * C * emag * AU * rmass ); fac2= 1.0 + qdote; /* Construct corrected position vector 'pos2'. */ for ( i= 0; i < 3; i++ ) { p2i= phat[i] + fac1 * ( pdotq * ehat[i] - edotp * qhat[i] ) / fac2; pos2[i]= p2i * pmag; } } return; } /********aberration */ void aberration( double *pos, double *ve, double lighttime, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: Corrects position vector for aberration of light. Algorithm includes relativistic terms. REFERENCES: Murray, C. A. (1981) Mon. Notices Royal Ast. Society 195, 639-648. Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. INPUT ARGUMENTS: pos[3] (double) Position vector, referred to origin at center of mass of the Earth, components in AU. ve[3] (double) Velocity vector of center of mass of the Earth, referred to origin at solar system barycenter, components in AU/day. lighttime (double) Light time from object to Earth in days. OUTPUT ARGUMENTS: pos2[3] (double) Position vector, referred to origin at center of mass of the Earth, corrected for aberration, components in AU RETURNED VALUE: None. GLOBALS USED: C_AUDAY novascon.c FUNCTIONS CALLED: sqrt math.h VER./DATE/ PROGRAMMER: V1.0/01-93/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Update to C Standards. V1.2/12-02/JAB (USNO/AA) Improve efficiency by removing calls to 'pow' and replacing final 'for' loop with direct assignment. V1.3/11-03/JAB (USNO/AA) Remove returned value. V1.4/02-06/WKP (USNO/AA) Changed C to C_AUDAY. NOTES: 1. This function is the C version of NOVAS Fortran routine 'aberat'. 2. If 'lighttime' = 0 on input, this function will compute it. ------------------------------------------------------------------------ */ { double p1mag, vemag, beta, dot, cosd, gammai, p, q, r; if ( lighttime == 0.0 ) { p1mag= sqrt( pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2] ); lighttime= p1mag / C_AUDAY; } else p1mag= lighttime * C_AUDAY; vemag= sqrt( ve[0] * ve[0] + ve[1] * ve[1] + ve[2] * ve[2] ); beta= vemag / C_AUDAY; dot= pos[0] * ve[0] + pos[1] * ve[1] + pos[2] * ve[2]; cosd= dot / ( p1mag * vemag ); gammai= sqrt( 1.0 - beta * beta ); p= beta * cosd; q= ( 1.0 + p / ( 1.0 + gammai ) ) * lighttime; r= 1.0 + p; pos2[0]= ( gammai * pos[0] + q * ve[0] ) / r; pos2[1]= ( gammai * pos[1] + q * ve[1] ) / r; pos2[2]= ( gammai * pos[2] + q * ve[2] ) / r; return; } /********rad_vel */ void rad_vel( object *cel_object, double *pos, double *vel, double *vel_obs, double d_obs_geo, double d_obs_sun, double d_obj_sun, double *rv ) /* ------------------------------------------------------------------------ PURPOSE: Predicts the radial velocity of the observed object as it would be measured by spectroscopic means. Radial velocity is here defined as the radial velocity measure (z) times the speed of light. For a solar system body, it applies to a fictitious emitter at the center of the observed object, assumed massless (no gravitational red shift), and does not in general apply to reflected light. For stars, it includes all effects, such as gravitational red shift, contained in the catalog barycentric radial velocity measure, a scalar derived from spectroscopy. Nearby stars with a known kinematic velocity vector (obtained independently of spectroscopy) can be treated like solar system objects. REFERENCES: Lindegren & Dravins (2003), Astronomy & Astrophysics 401, 1185-1201. INPUT ARGUMENTS: *cel_object (struct object) Specifies the celestial object of interest (structure defined in novas.h). *pos (double) Geometric position vector of object with respect to observer, corrected for light-time, in AU. *vel (double) Velocity vector of object with respect to solar system barycenter, in AU/day. *vel_obs (double) Velocity vector of observer with respect to solar system barycenter, in AU/day. d_obs_geo (double) Distance from observer to geocenter, in AU. d_obs_sun (double) Distance from observer to Sun, in AU. d_obj_sun (double) Distance from object to Sun, in AU. OUTPUT ARGUMENTS: *rv (double) The observed radial velocity measure times the speed of light, in kilometers/second. RETURNED VALUE: None. GLOBALS USED: AU, C, GS, GE novascon.c DEG2RAD novascon.c FUNCTIONS CALLED: sqrt math.h sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/09-06/JAB (USNO/AA) V2.0/01-07/JAB (USNO/AA): Implement new algorithm NOTES: 1. All the input arguments are BCRS quantities, expressed with respect to the ICRS axes. 'vel' and 'vel_obs' are kinematic velocities - derived from geometry or dynamics, not spectroscopy. 2. If the object is outside the solar system, the algorithm used will be consistent with the IAU definition of stellar radial velocity, specifically, the barycentric radial velocity measure, which is derived from spectroscopy. In that case, the vector 'vel' can be very approximate -- or, for distant stars or galaxies, zero -- as it will be used only for a small geometric correction that is proportional to proper motion. 3. Any of the distances (last three input arguments) can be set to zero (0.0) if the corresponding general relativistic gravitational potential term is not to be evaluated. These terms generally are important only at the meter/second level. If 'd_obs_geo' and 'd_obs_sun' are both zero, an average value will be used for the relativistic term for the observer, appropriate for an observer on the surface of the Earth. 'd_obj_sun', if given, is used only for solar system objects. 4. This function is the C version of NOVAS Fortran routine 'radvl'. ------------------------------------------------------------------------ */ { static short int first_call= 1; short int i; static double c2, toms, toms2; double v[3], ra, dec, radvel, posmag, uk[3], v2, vo2, r, phigeo, phisun, rel, rar, dcr, cosdec, du[3], zc, kv, zb1, kvobs, zobs1; /* Set up local constants the first time this function is called. */ if ( first_call ) { c2= C * C; toms= AU / 86400.0; toms2= toms * toms; first_call= 0; } /* Initialize variables needed for radial velocity calculation. */ for ( i= 0; i < 3; i++ ) { v[i]= vel[i]; } switch ( cel_object->type ) { case 2: /* Data for objects outside the solar system. */ ra= cel_object->star.ra; dec= cel_object->star.dec; radvel= cel_object->star.radialvelocity; if ( cel_object->star.parallax <= 0.0 ) { for ( i= 0; i < 3; i++ ) { v[i]= 0.0; } } break; default: /* Data not used for solar system objects. */ ra= 0.0; dec= 0.0; radvel= 0.0; } /* Compute length of position vector = distance to object in AU. */ posmag= sqrt( pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2] ); /* Compute unit vector toward object. */ for ( i= 0; i < 3; i++ ) { uk[i]= pos[i] / posmag; } /* Compute velocity-squared factors. */ v2= ( v[0] * v[0] + v[1] * v[1] + v[2] * v[2] ) * toms2; vo2= ( vel_obs[0] * vel_obs[0] + vel_obs[1] * vel_obs[1] + vel_obs[2] * vel_obs[2] ) * toms2; /* Compute geopotential at observer, unless observer is geocentric. */ r= d_obs_geo * AU; if ( r > 1.0e6 ) { phigeo= GE / r; } else { phigeo= 0.0; } /* Compute solar potential at observer. */ r= d_obs_sun * AU; if ( r > 1.0e8 ) { phisun= GS / r; } else { phisun= 0.0; } /* Compute relativistic potential and velocity factor for observer. */ if ( ( d_obs_geo != 0.0 ) || ( d_obs_sun != 0.0 ) ) { /* Lindegren & Dravins eq. (41), second factor in parentheses. */ rel= 1.0 - ( phigeo + phisun ) / c2 - 0.5 * vo2 / c2; } else { /* Lindegren & Dravins eq. (42), inverse. */ rel= 1.0 - 1.550e-8; } /* Complete radial velocity calculation. */ switch ( cel_object->type ) { case 2: /* Objects outside the solar system. */ /* For stars, update barycentric radial velocity measure for change in view angle. */ rar= ra * 15.0 * DEG2RAD; dcr= dec * DEG2RAD; cosdec= cos( dcr ); du[0]= uk[0] - ( cosdec * cos( rar ) ); du[1]= uk[1] - ( cosdec * sin( rar ) ); du[2]= uk[2] - sin( dcr ); zc= radvel * 1.0e3 + ( v[0] * du[0] + v[1] * du[1] + v[2] * du[2] ) * toms; /* Compute observed radial velocity measure of a star (inverse of Lindegren & Dravins eq. (41)). */ zb1= 1.0 + zc / C; kvobs= ( uk[0] * vel_obs[0] + uk[1] * vel_obs[1] + uk[2] * vel_obs[2] ) * toms; zobs1= zb1 * rel / ( 1.0 + kvobs / C ); break; case 0: /* Objects in the solar system */ case 1: default: /* Compute solar potential at object, if within solar system. */ r= d_obj_sun * AU; if ( ( r > 1.0e8 ) && ( r < 1.0e16 ) ) { phisun= GS / r; } else { phisun= 0.0; } /* Compute observed radial velocity measure of a planet or other object -- including a nearby star -- where kinematic barycentric velocity vector is known and gravitational red shift is negligible (Lindegren & Dravins eq. (40), applied as per S. Klioner private communication (2006)). */ kv= ( uk[0] * vel[0] + uk[1] * vel[1] + uk[2] * vel[2] ) * toms; zb1= ( 1.0 + kv / C ) / ( 1.0 - phisun / c2 - 0.5 * v2 / c2 ); kvobs= ( uk[0] * vel_obs[0] + uk[1] * vel_obs[1] + uk[2] * vel_obs[2] ) * toms; zobs1= zb1 * rel / ( 1.0 + kvobs / C ); } /* Convert observed radial velocity measure to kilometers/second. */ *rv= ( zobs1 - 1.0 ) * C / 1000.0; return; } /********precession */ short int precession( double jd_tdb1, double *pos1, double jd_tdb2, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: Precesses equatorial rectangular coordinates from one epoch to another. One of the two epochs must be J2000.0. The coordinates are referred to the mean dynamical equator and equinox of the two respective epochs. REFERENCES: Explanatory Supplement To The Astronomical Almanac, pp. 103-104. Capitaine, N. et al. (2003), Astronomy And Astrophysics 412, pp. 567-586. Hilton, J. L. et al. (2006), IAU WG report, Celest. Mech., 94, pp. 351-367. INPUT ARGUMENTS: jd_tdb1 (double) TDB Julian date of first epoch. See Note 1 below. pos1[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to mean dynamical equator and equinox of first epoch. jd_tdb2 (double) TDB Julian date of second epoch. See Note 1 below. OUTPUT ARGUMENTS: pos2[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to mean dynamical equator and equinox of second epoch. RETURNED VALUE: (short int) = 0 ... everything OK. = 1 ... Precession not to or from J2000.0; 'jd_tdb1' or 'jd_tdb2' not 2451545.0. GLOBALS USED: T0, ASEC2RAD novascon.c FUNCTIONS CALLED: fabs math.h sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/01-93/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Update to C Standards. V1.2/03-98/JAB (USNO/AA) Change function type from 'short int' to 'void'. V1.3/12-99/JAB (USNO/AA) Precompute trig terms for greater efficiency. V2.0/10-03/JAB (USNO/AA) Update function for consistency with IERS (2000) Conventions. V2.1/01-05/JAB (USNO/AA) Update expressions for the precession angles (extra significant digits). V2.2/04-06/JAB (USNO/AA) Update model to 2006 IAU convention. This is model "P03" of second reference. V2.3/03-10/JAB (USNO/AA) Implement 'first-time' to fix bug when 'jd_tdb2' is 'T0' on first call to function. NOTES: 1. Either 'jd_tdb1' or 'jd_tdb2' must be 2451545.0 (J2000.0) TDB. 2. This function is the C version of NOVAS Fortran routine 'preces'. ------------------------------------------------------------------------ */ { static short int first_time= 1; short int error= 0; static double t_last= 0.0; static double xx, yx, zx, xy, yy, zy, xz, yz, zz; double eps0= 84381.406; double t, psia, omegaa, chia, sa, ca, sb, cb, sc, cc, sd, cd; /* Check to be sure that either 'jd_tdb1' or 'jd_tdb2' is equal to T0. */ if ( ( jd_tdb1 != T0 ) && ( jd_tdb2 != T0 ) ) return ( error= 1 ); /* 't' is time in TDB centuries between the two epochs. */ t= ( jd_tdb2 - jd_tdb1 ) / 36525.0; if ( jd_tdb2 == T0 ) t= -t; if ( ( fabs( t - t_last ) >= 1.0e-15 ) || ( first_time == 1 ) ) { /* Numerical coefficients of psi_a, omega_a, and chi_a, along with epsilon_0, the obliquity at J2000.0, are 4-angle formulation from Capitaine et al. (2003), eqs. (4), (37), & (39). */ psia= ( ( ( ( -0.0000000951 * t + 0.000132851 ) * t - 0.00114045 ) * t - 1.0790069 ) * t + 5038.481507 ) * t; omegaa= ( ( ( ( +0.0000003337 * t - 0.000000467 ) * t - 0.00772503 ) * t + 0.0512623 ) * t - 0.025754 ) * t + eps0; chia= ( ( ( ( -0.0000000560 * t + 0.000170663 ) * t - 0.00121197 ) * t - 2.3814292 ) * t + 10.556403 ) * t; eps0= eps0 * ASEC2RAD; psia= psia * ASEC2RAD; omegaa= omegaa * ASEC2RAD; chia= chia * ASEC2RAD; sa= sin( eps0 ); ca= cos( eps0 ); sb= sin( -psia ); cb= cos( -psia ); sc= sin( -omegaa ); cc= cos( -omegaa ); sd= sin( chia ); cd= cos( chia ); /* Compute elements of precession rotation matrix equivalent to R3(chi_a) R1(-omega_a) R3(-psi_a) R1(epsilon_0). */ xx= cd * cb - sb * sd * cc; yx= cd * sb * ca + sd * cc * cb * ca - sa * sd * sc; zx= cd * sb * sa + sd * cc * cb * sa + ca * sd * sc; xy= -sd * cb - sb * cd * cc; yy= -sd * sb * ca + cd * cc * cb * ca - sa * cd * sc; zy= -sd * sb * sa + cd * cc * cb * sa + ca * cd * sc; xz= sb * sc; yz= -sc * cb * ca - sa * cc; zz= -sc * cb * sa + cc * ca; t_last= t; first_time= 0; } if ( jd_tdb2 == T0 ) { /* Perform rotation from epoch to J2000.0. */ pos2[0]= xx * pos1[0] + xy * pos1[1] + xz * pos1[2]; pos2[1]= yx * pos1[0] + yy * pos1[1] + yz * pos1[2]; pos2[2]= zx * pos1[0] + zy * pos1[1] + zz * pos1[2]; } else { /* Perform rotation from J2000.0 to epoch. */ pos2[0]= xx * pos1[0] + yx * pos1[1] + zx * pos1[2]; pos2[1]= xy * pos1[0] + yy * pos1[1] + zy * pos1[2]; pos2[2]= xz * pos1[0] + yz * pos1[1] + zz * pos1[2]; } return ( error= 0 ); } /********nutation */ void nutation( double jd_tdb, short int direction, short int accuracy, double *pos, double *pos2 ) /* ------------------------------------------------------------------------ PURPOSE: Nutates equatorial rectangular coordinates from mean equator and equinox of epoch to true equator and equinox of epoch. Inverse transformation may be applied by setting flag 'direction'. REFERENCES: Explanatory Supplement To The Astronomical Almanac, pp. 114-115. INPUT ARGUMENTS: jd_tdb (double) TDB Julian date of epoch. direction (short int) Flag determining 'direction' of transformation; direction = 0 transformation applied, mean to true. direction != 0 inverse transformation applied, true to mean. accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy pos[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to mean equator and equinox of epoch. OUTPUT ARGUMENTS: pos2[3] (double) Position vector, geocentric equatorial rectangular coordinates, referred to true equator and equinox of epoch. RETURNED VALUE: None. GLOBALS USED: DEG2RAD, ASEC2RAD novascon.c FUNCTIONS CALLED: e_tilt novas.c cos math.h sin math.h VER./DATE/ PROGRAMMER: V1.0/01-93/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Update to C Standards. V1.2/11-03/JAB (USNO/AA) Remove returned value. V1.3/01-06/WKP (USNO/AA) Changed 'mode' to 'accuracy'. NOTES: 1. This function is the C version of NOVAS Fortran routine 'nutate'. ------------------------------------------------------------------------ */ { double cobm, sobm, cobt, sobt, cpsi, spsi, xx, yx, zx, xy, yy, zy, xz, yz, zz, oblm, oblt, eqeq, psi, eps; /* Call 'e_tilt' to get the obliquity and nutation angles. */ e_tilt( jd_tdb, accuracy, &oblm, &oblt, &eqeq, &psi, &eps ); cobm= cos( oblm * DEG2RAD ); sobm= sin( oblm * DEG2RAD ); cobt= cos( oblt * DEG2RAD ); sobt= sin( oblt * DEG2RAD ); cpsi= cos( psi * ASEC2RAD ); spsi= sin( psi * ASEC2RAD ); /* Nutation rotation matrix follows. */ xx= cpsi; yx= -spsi * cobm; zx= -spsi * sobm; xy= spsi * cobt; yy= cpsi * cobm * cobt + sobm * sobt; zy= cpsi * sobm * cobt - cobm * sobt; xz= spsi * sobt; yz= cpsi * cobm * sobt - sobm * cobt; zz= cpsi * sobm * sobt + cobm * cobt; if ( !direction ) { /* Perform rotation. */ pos2[0]= xx * pos[0] + yx * pos[1] + zx * pos[2]; pos2[1]= xy * pos[0] + yy * pos[1] + zy * pos[2]; pos2[2]= xz * pos[0] + yz * pos[1] + zz * pos[2]; } else { /* Perform inverse rotation. */ pos2[0]= xx * pos[0] + xy * pos[1] + xz * pos[2]; pos2[1]= yx * pos[0] + yy * pos[1] + yz * pos[2]; pos2[2]= zx * pos[0] + zy * pos[1] + zz * pos[2]; } return; } /********nutation_angles */ void nutation_angles( double t, short int accuracy, double *dpsi, double *deps ) /* ------------------------------------------------------------------------ PURPOSE: This function returns the values for nutation in longitude and nutation in obliquity for a given TDB Julian date. The nutation model selected depends upon the input value of 'accuracy'. See notes below for important details. REFERENCES: Kaplan, G. (2005), US Naval Observatory Circular 179. INPUT ARGUMENTS: t (double) TDB time in Julian centuries since J2000.0 accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: dpsi (double) Nutation in longitude in arcseconds. deps (double) Nutation in obliquity in arcseconds. RETURNED VALUE: None. GLOBALS USED: T0, ASEC2RAD novascon.c FUNCTIONS CALLED: iau2000a nutation.c iau2000b nutation.c nu2000k nutation.c VER./DATE/ PROGRAMMER: V1.0/12-04/JAB (USNO/AA) V1.1/01-06/WKP (USNO/AA): Changed 'mode' to 'accuracy'. V1.2/02-06/WKP (USNO/AA): Fixed units bug. V1.3/01-07/JAB (USNO/AA): Implemented 'low_acc_choice' construct. NOTES: 1. This function selects the nutation model depending first upon the input value of 'accuracy'. If 'accuracy' = 0 (full accuracy), the IAU 2000A nutation model is used. If 'accuracy' = 1 (reduced accuracy, the model used depends upon the value of local variable 'low_acc_choice', which is set below. 2. If local variable 'low_acc_choice' = 1 (the default), a specially truncated version of IAU 2000A, called 'NU2000K' is used. If 'low_acc_choice' = 2, the IAU 2000B nutation model is used. 3. See the prologs of the nutation functions in file 'nutation.c' for details concerning the models. 4. This function is the C version of NOVAS Fortran routine 'nod'. ------------------------------------------------------------------------ */ { /* Set the value of 'low_acc_choice' according to the rules explained under NOTES in the prolog. */ short int low_acc_choice= 1; double t1; t1= t * 36525.0; /* High accuracy mode -- use IAU 2000A. */ if ( accuracy == 0 ) { iau2000a( T0, t1, dpsi, deps ); } /* Low accuracy mode -- model depends upon value of 'low_acc_choice'. */ else { switch ( low_acc_choice ) { case 2: /* use IAU 2000B */ iau2000b( T0, t1, dpsi, deps ); break; case 1: /* use NU2000K */ default: nu2000k( T0, t1, dpsi, deps ); } } /* Convert output to arcseconds. */ *dpsi/= ASEC2RAD; *deps/= ASEC2RAD; return; } /********fund_args */ void fund_args( double t, double a[5] ) /* ------------------------------------------------------------------------ PURPOSE: To compute the fundamental arguments (mean elements) of the Sun and Moon. REFERENCES: Simon et al. (1994) Astronomy and Astrophysics 282, 663-683, esp. Sections 3.4-3.5. INPUT ARGUMENTS: t (double) TDB time in Julian centuries since J2000.0 OUTPUT ARGUMENTS: a[5] (double) Fundamental arguments, in radians: a[0] = l (mean anomaly of the Moon) a[1] = l' (mean anomaly of the Sun) a[2] = F (mean argument of the latitude of the Moon) a[3] = D (mean elongation of the Moon from the Sun) a[4] = Omega (mean longitude of the Moon's ascending node); from Simon section 3.4(b.3), precession = 5028.8200 arcsec/cy) RETURNED VALUE: None. GLOBALS USED: ASEC2RAD, ASEC360 novascon.c FUNCTIONS CALLED: fmod math.h VER./DATE/ PROGRAMMER: V1.0/10-97/JAB (USNO/AA) V1.1/07-98/JAB (USNO/AA): Place arguments in the range 0-TWOPI radians. V1.2/09-03/JAB (USNO/AA): Incorporate function 'norm_ang'. V1.3/11-03/JAB (USNO/AA): Update with Simon et al. expressions. V1.4/01-06/JAB (USNO/AA): Remove function 'norm_ang'; rewrite for consistency with Fortran. V1.5/02-11/WKP (USNO/AA): Clarified a[4] description in prolog. NOTES: 1. This function is the C version of NOVAS Fortran routine 'funarg'. ------------------------------------------------------------------------ */ { a[0]= fmod( 485868.249036 + t * ( 1717915923.2178 + t * ( 31.8792 + t * ( 0.051635 + t * ( -0.00024470 ) ) ) ), ASEC360 ) * ASEC2RAD; a[1]= fmod( 1287104.79305 + t * ( 129596581.0481 + t * ( -0.5532 + t * ( 0.000136 + t * ( -0.00001149 ) ) ) ), ASEC360 ) * ASEC2RAD; a[2]= fmod( 335779.526232 + t * ( 1739527262.8478 + t * ( -12.7512 + t * ( -0.001037 + t * ( 0.00000417 ) ) ) ), ASEC360 ) * ASEC2RAD; a[3]= fmod( 1072260.70369 + t * ( 1602961601.2090 + t * ( -6.3706 + t * ( 0.006593 + t * ( -0.00003169 ) ) ) ), ASEC360 ) * ASEC2RAD; a[4]= fmod( 450160.398036 + t * ( -6962890.5431 + t * ( 7.4722 + t * ( 0.007702 + t * ( -0.00005939 ) ) ) ), ASEC360 ) * ASEC2RAD; return; } /********mean_obliq */ double mean_obliq( double jd_tdb ) /* ------------------------------------------------------------------------ PURPOSE: To compute the mean obliquity of the ecliptic. REFERENCES: Capitaine et al. (2003), Astronomy and Astrophysics 412, 567-586. INPUT ARGUMENTS: jd_tdb (double) TDB Julian Date. OUTPUT ARGUMENTS: None. RETURNED VALUE: (double) Mean obliquity of the ecliptic in arcseconds. GLOBALS USED: T0 novascon.c FUNCTIONS CALLED: None. VER./DATE/ PROGRAMMER: V1.0/12-04/JAB (USNO/AA) V2.0/04-06/JAB (USNO/AA) Update the expression for mean obliquity using data from the reference. NOTES: None. ------------------------------------------------------------------------ */ { double t, epsilon; /* Compute time in Julian centuries from epoch J2000.0. */ t= ( jd_tdb - T0 ) / 36525.0; /* Compute the mean obliquity in arcseconds. Use expression from the reference's eq. (39) with obliquity at J2000.0 taken from eq. (37) or Table 8. */ epsilon= ( ( ( ( -0.0000000434 * t - 0.000000576 ) * t + 0.00200340 ) * t - 0.0001831 ) * t - 46.836769 ) * t + 84381.406; return ( epsilon ); } /********vector2radec */ short int vector2radec( double *pos, double *ra, double *dec ) /* ------------------------------------------------------------------------ PURPOSE: Converts an vector in equatorial rectangular coordinates to equatorial spherical coordinates. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. INPUT ARGUMENTS: pos[3] (double) Position vector, equatorial rectangular coordinates. OUTPUT ARGUMENTS: *rightascension (double) Right ascension in hours. *declination (double) Declination in degrees. RETURNED VALUE: (short int) = 0 ... Everything OK. = 1 ... All vector components are zero; 'ra' and 'dec' are indeterminate. = 2 ... Both pos[0] and pos[1] are zero, but pos[2] is nonzero; 'ra' is indeterminate. GLOBALS USED: ASEC2RAD novascon.c FUNCTIONS CALLED: sqrt math.h atan2 math.h VER./DATE/ PROGRAMMER: V1.0/01-93/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Update to C Standards. V1.2/01-04/JAB (USNO/AA) Remove calls to 'pow'. NOTES: 1. This function is the C version of NOVAS Fortran routine 'angles'. ------------------------------------------------------------------------ */ { double xyproj; xyproj= sqrt( pos[0] * pos[0] + pos[1] * pos[1] ); if ( ( xyproj == 0.0 ) && ( pos[2] == 0 ) ) { *ra= 0.0; *dec= 0.0; return 1; } else if ( xyproj == 0.0 ) { *ra= 0.0; if ( pos[2] < 0.0 ) *dec= -90.0; else *dec= 90.0; return 2; } else { *ra= atan2( pos[1], pos[0] ) / ASEC2RAD / 54000.0; *dec= atan2( pos[2], xyproj ) / ASEC2RAD / 3600.0; if ( *ra < 0.0 ) *ra+= 24.0; } return 0; } /********radec2vector */ void radec2vector( double ra, double dec, double dist, double *vector ) /* ------------------------------------------------------------------------ PURPOSE: Converts equatorial spherical coordinates to a vector (equatorial rectangular coordinates). REFERENCES: None. INPUT ARGUMENTS: ra (double) Right ascension (hours). dec (double) Declination (degrees). dist (double) Distance (AU) OUTPUT ARGUMENTS: vector[3] (double) Position vector, equatorial rectangular coordinates (AU). RETURNED VALUE: (short int) = 0 ... Everything OK. GLOBALS USED: DEG2RAD novascon.c FUNCTIONS CALLED: cos math.h sin math.h VER./DATE/ PROGRAMMER: V1.0/05-92/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Update to C Standards. V1.2/08-09/JLB (USNO/AA) Documented "dist" in prolog NOTES: None. ------------------------------------------------------------------------ */ { vector[0]= dist * cos( DEG2RAD * dec ) * cos( DEG2RAD * 15.0 * ra ); vector[1]= dist * cos( DEG2RAD * dec ) * sin( DEG2RAD * 15.0 * ra ); vector[2]= dist * sin( DEG2RAD * dec ); return; } /********starvectors */ void starvectors( cat_entry *star, double *pos, double *vel ) /* ------------------------------------------------------------------------ PURPOSE: Converts angular quantities for stars to vectors. REFERENCES: Kaplan, G. H. et. al. (1989). Astron. Journ. 97, 1197-1210. INPUT ARGUMENTS: *star (struct cat_entry) Pointer to catalog entry structure containing ICRS catalog data (defined in novas.h). OUTPUT ARGUMENTS: pos[3] (double) Position vector, equatorial rectangular coordinates, components in AU. vel[3] (double) Velocity vector, equatorial rectangular coordinates, components in AU/Day. RETURNED VALUE: None. GLOBALS USED: ASEC2RAD, DEG2RAD novascon.c AU_KM, C novascon.c FUNCTIONS CALLED: sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/01-93/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Updated to C programming standards. V1.2/11-03/JAB (USNO/AA) Update to account for parallax in units of milliarcseconds and proper motion in milliarcseconds/year. V1.3/01-06/WKP (USNO/AA) Changed 'a[3]' to 'd' and added Doppler factor. V1.4/02-06/WKP (USNO/AA) Corrected units of C to km/sec. NOTES: 1. This function is the C version of NOVAS Fortran routine 'vectrs'. ------------------------------------------------------------------------ */ { double paralx, dist, r, d, cra, sra, cdc, sdc, pmr, pmd, rvl, k; /* If parallax is unknown, undetermined, or zero, set it to 1e-6 milliarcsecond, corresponding to a distance of 1 gigaparsec. */ paralx= star->parallax; if ( star->parallax <= 0.0 ) paralx= 1.0e-6; /* Convert right ascension, declination, and parallax to position vector in equatorial system with units of AU. */ dist= 1.0 / sin( paralx * 1.0e-3 * ASEC2RAD ); r= ( star->ra ) * 15.0 * DEG2RAD; d= ( star->dec ) * DEG2RAD; cra= cos( r ); sra= sin( r ); cdc= cos( d ); sdc= sin( d ); pos[0]= dist * cdc * cra; pos[1]= dist * cdc * sra; pos[2]= dist * sdc; /* Compute Doppler factor, which accounts for change in light travel time to star. */ k= 1.0 / ( 1.0 - star->radialvelocity / C * 1000.0 ); /* Convert proper motion and radial velocity to orthogonal components of motion with units of AU/Day. */ pmr= star->promora / ( paralx * 365.25 ) * k; pmd= star->promodec / ( paralx * 365.25 ) * k; rvl= star->radialvelocity * 86400.0 / AU_KM * k; /* Transform motion vector to equatorial system. */ vel[0]= -pmr * sra - pmd * sdc * cra + rvl * cdc * cra; vel[1]= pmr * cra - pmd * sdc * sra + rvl * cdc * sra; vel[2]= pmd * cdc + rvl * sdc; return; } /********tdb2tt */ void tdb2tt( double tdb_jd, double *tt_jd, double *secdiff ) /* ------------------------------------------------------------------------ PURPOSE: Computes the Terrestrial Time (TT) or Terrestrial Dynamical Time (TDT) Julian date corresponding to a Barycentric Dynamical Time (TDB) Julian date. REFERENCES: Fairhead, L. & Bretagnon, P. (1990) Astron. & Astrophys. 229, 240. Kaplan, G. (2005), US Naval Observatory Circular 179. INPUT ARGUMENTS: tdb_jd (double) TDB Julian date. OUTPUT ARGUMENTS: *tt_jd (double) TT Julian date. *secdiff (double) Difference 'tdb_jd'-'tt_jd', in seconds. RETURNED VALUE: None. GLOBALS USED: T0 novascon.c FUNCTIONS CALLED: sin math.h VER./DATE/ PROGRAMMER: V1.0/07-92/TKB (USNO/NRL Optical Interfer.) Translate Fortran. V1.1/08-93/WTH (USNO/AA) Update to C Standards. V1.2/06-98/JAB (USNO/AA) Adopt new model (Explanatory Supplement to the Astronomical Almanac, pp. 42-44 and p. 316.) V1.3/11-03/JAB (USNO/AA) Changed variable names of the input Julian dates to make more descriptive. V1.4/01-07/JAB (USNO/AA) Adopt Fairhead & Bretagnon expression. NOTES: 1. Expression used in this function is a truncated form of a longer and more precise series given in the first reference. The result is good to about 10 microseconds. 2. This function is the C version of NOVAS Fortran routine 'times'. ------------------------------------------------------------------------ */ { double t; t= ( tdb_jd - T0 ) / 36525.0; /* Expression given in USNO Circular 179, eq. 2.6. */ *secdiff= 0.001657 * sin( 628.3076 * t + 6.2401 ) + 0.000022 * sin( 575.3385 * t + 4.2970 ) + 0.000014 * sin( 1256.6152 * t + 6.1969 ) + 0.000005 * sin( 606.9777 * t + 4.0212 ) + 0.000005 * sin( 52.9691 * t + 0.4444 ) + 0.000002 * sin( 21.3299 * t + 5.5431 ) + 0.000010 * t * sin( 628.3076 * t + 4.2490 ); *tt_jd= tdb_jd - *secdiff / 86400.0; return; } /********cio_ra */ short int cio_ra( double jd_tt, short int accuracy, double *ra_cio ) /* ------------------------------------------------------------------------ PURPOSE: This function computes the true right ascension of the celestial intermediate origin (CIO) at a given TT Julian date. This is -(equation of the origins). REFERENCES: Kaplan, G. (2005), US Naval Observatory Circular 179. INPUT ARGUMENTS: jd_tt (double) TT Julian date. accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra_cio (double) Right ascension of the CIO, with respect to the true equinox of date, in hours (+ or -). RETURNED VALUE: (short int) = 0 ... everything OK. = 1 ... invalid value of 'accuracy'. > 10 ... 10 + the error code from function 'cio_location'. > 20 ... 20 + the error code from function 'cio_basis'. GLOBALS USED: RAD2DEG, T0 novascon.c FUNCTIONS CALLED: tdb2tt novas.c cio_location novas.c cio_basis novas.c nutation novas.c precession novas.c frame_tie novas.c atan2 math.h VER./DATE/ PROGRAMMER: V1.0/01-05/JAB (USNO/AA) V1.1/12-05/WKP (USNO/AA) Corrected minor syntax problems. V1.2/01-06/WKP (USNO/AA) Changed 'mode' to 'accuracy'. V1.3/07-06/JAB (USNO/AA) Implement 'cio_location' construct. NOTES: 1. This function is the C version of NOVAS Fortran routine 'ciora'. ------------------------------------------------------------------------ */ { short int error= 0; short int rs; double unitx[3]= {1.0, 0.0, 0.0}; double jd_tdb, t, secdif, x[3], y[3], z[3], w1[3], w2[3], eq[3], az, r_cio; /* Check for valid value of 'accuracy'. */ if ( ( accuracy < 0 ) || ( accuracy > 1 ) ) return ( error= 1 ); /* 'jd_tdb' is the TDB Julian date. */ jd_tdb= jd_tt; tdb2tt( jd_tdb, &t, &secdif ); jd_tdb= jd_tt + secdif / 86400.0; /* Obtain the basis vectors, in the GCRS, for the celestial intermediate system defined by the CIP (in the z direction) and the CIO (in the x direction). */ if ( ( error= cio_location( jd_tdb, accuracy, &r_cio, &rs ) ) != 0 ) { *ra_cio= 0.0; return ( error+= 10 ); } if ( ( error= cio_basis( jd_tdb, r_cio, rs, accuracy, x, y, z ) ) != 0 ) { return ( error+= 20 ); } /* Compute the direction of the true equinox in the GCRS. */ nutation( jd_tdb, -1, accuracy, unitx, w1 ); precession( jd_tdb, w1, T0, w2 ); frame_tie( w2, -1, eq ); /* Compute the RA-like coordinate of the true equinox in the celestial intermediate system. */ az= atan2( eq[0] * y[0] + eq[1] * y[1] + eq[2] * y[2], eq[0] * x[0] + eq[1] * x[1] + eq[2] * x[2] ) * RAD2DEG; /* The RA of the CIO is minus this coordinate. */ *ra_cio= -az / 15.0; return ( error ); } /********cio_location */ short int cio_location( double jd_tdb, short int accuracy, double *ra_cio, short int *ref_sys ) /* ------------------------------------------------------------------------ PURPOSE: This function returns the location of the celestial intermediate origin (CIO) for a given Julian date, as a right ascension with respect to either the GCRS (geocentric ICRS) origin or the true equinox of date. The CIO is always located on the true equator (= intermediate equator) of date. REFERENCES: None. INPUT ARGUMENTS: jd_tdb (double) TDB Julian date. accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *ra_cio (double) Right ascension of the CIO, in hours. *ref_sys (short int) Reference system in which right ascension is given = 1 ... GCRS = 2 ... True equator and equinox of date. RETURNED VALUE: (short int) = 0 ... everything OK. = 1 ... unable to allocate memory for the 'cio' array. > 10 ... 10 + the error code from function 'cio_array'. GLOBALS USED: None. FUNCTIONS CALLED: cio_array novas.c ira_equinox novas.c fopen stdio.h fclose stdio.h fabs math.h calloc stdlib.h VER./DATE/ PROGRAMMER: V1.0/07-06/JAB (USNO/AA) NOTES: 1. If an external file of CIO right ascensions is available, it will be used and 'ref_sys' will be set to 1. Otherwise an internal computation will be used and 'ref_sys' will be set to 2. 2. The external binary file of CIO right ascensions is assumed to be named 'cio_ra.bin'. Utility program 'cio_file.c', provided with the NOVAS-C package, creates this file from a text file also provided with NOVAS-C. 3. This function is the C version of NOVAS Fortran routine 'cioloc'. ------------------------------------------------------------------------ */ { static short int first_call= 1; static short int ref_sys_last= 0; static short int use_file= 0; short int error= 0; long int n_pts= 6; long int i, j; static double t_last= 0.0; static double ra_last; double p, eq_origins; size_t cio_size; static ra_of_cio *cio; static FILE *cio_file; /* Check if the input external binary file exists and can be read. */ if ( first_call ) { if ( ( cio_file= fopen( "cio_ra.bin", "rb" ) ) == NULL ) { use_file= 0; } else { use_file= 1; fclose( cio_file ); } } /* Check if previously computed RA value can be used. */ if ( ( fabs( jd_tdb - t_last ) <= 1.0e-8 ) ) { *ra_cio= ra_last; *ref_sys= ref_sys_last; return ( error= 0 ); } /* Compute the RA of the CIO. */ switch ( use_file ) { /* ----------------------------- Interpolate values from file. ----------------------------- */ case 1: /* Allocate memory for the array 'cio'. This array contains the values to be interpolated, extracted from the CIO file. */ if ( first_call ) { cio_size= sizeof( ra_of_cio ); cio= (ra_of_cio *)calloc( (size_t)n_pts, cio_size ); if ( cio == NULL ) return ( error= 1 ); else first_call= 0; } /* Get array of values to interpolate. */ if ( ( error= cio_array( jd_tdb, n_pts, cio ) ) != 0 ) { *ra_cio= 0.0; return ( error+= 10 ); } /* Perform Lagrangian interpolation for the RA at 'tdb_jd'. */ *ra_cio= 0.0; for ( j= 0L; j < n_pts; j++ ) { p= 1.0; for ( i= 0L; i < n_pts; i++ ) { if ( i != j ) p*= ( ( jd_tdb - cio[i].jd_tdb ) / ( cio[j].jd_tdb - cio[i].jd_tdb ) ); } *ra_cio+= ( p * cio[j].ra_cio ); } *ra_cio/= 54000.0; *ref_sys= 1; break; /* ------------------------- Use internal computation. ------------------------- */ case 0: /* Compute equation of the origins. */ if ( first_call ) first_call= 0; eq_origins= ira_equinox( jd_tdb, 1, accuracy ); *ra_cio= -eq_origins; *ref_sys= 2; break; } t_last= jd_tdb; ra_last= *ra_cio; ref_sys_last= *ref_sys; return ( error ); } /********cio_basis */ short int cio_basis( double jd_tdb, double ra_cio, short int ref_sys, short int accuracy, double *x, double *y, double *z ) /* ------------------------------------------------------------------------ PURPOSE: To compute the orthonormal basis vectors, with respect to the GCRS (geocentric ICRS), of the celestial intermediate system defined by the celestial intermediate pole (CIP) (in the z direction) and the celestial intermediate origin (CIO) (in the x direction). A TDB Julian date and the right ascension of the CIO at that date is required as input. The right ascension of the CIO can be with respect to either the GCRS origin or the true equinox of date -- different algorithms are used in the two cases. REFERENCES: Kaplan, G. (2005), US Naval Observatory Circular 179. INPUT ARGUMENTS: jd_tdb (double) TDB Julian date of epoch. ra_cio (double) Right ascension of the CIO at epoch (hours). ref_sys (short int) Reference system in which right ascension is given (output from function 'cio_location') = 1 ... GCRS = 2 ... True equator and equinox of date. accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: *x (double) Unit vector toward the CIO, equatorial rectangular coordinates, referred to the GCRS. *y (double) Unit vector toward the y-direction, equatorial rectangular coordinates, referred to the GCRS. *z (double) Unit vector toward north celestial pole (CIP), equatorial rectangular coordinates, referred to the GCRS. RETURNED VALUE: (short int) = 0 ... everything OK. = 1 ... invalid value of input variable 'ref_sys'. GLOBALS USED: T0, DEG2RAD novascon.c FUNCTIONS CALLED: nutation novas.c precession novas.c frame_tie novas.c fabs math.h sin math.h cos math.h sqrt math.h VER./DATE/ PROGRAMMER: V1.0/08-04/JAB (USNO/AA) V1.1/01-06/WKP (USNO/AA) Changed 'mode' to 'accuracy'. V1.2/07-06/JAB (USNA/AA) Incorporate code to use 'ref_sys' input. V1.3/06-08/WKP (USNO/AA) Changed value of direction argument in calls to 'nutation' from 1 to -1 for consistency. NOTES: 1. This function effectively constructs the matrix C in eq. (3) of the reference. 2. This function is the C version of NOVAS Fortran routine 'ciobas'. ------------------------------------------------------------------------ */ { static short int ref_sys_last= 0; short int error= 0; short int i; static double t_last= 0.0; static double xx[3], yy[3], zz[3]; double z0[3]= {0.0, 0.0, 1.0}; double w0[3], w1[3], w2[3], sinra, cosra, xmag; /* Compute unit vector z toward celestial pole. */ if ( ( ( fabs( jd_tdb - t_last ) > 1.0e-8 ) ) || ( ref_sys != ref_sys_last ) ) { nutation( jd_tdb, -1, accuracy, z0, w1 ); precession( jd_tdb, w1, T0, w2 ); frame_tie( w2, -1, zz ); t_last= jd_tdb; ref_sys_last= ref_sys; } else { for ( i= 0; i < 3; i++ ) { x[i]= xx[i]; y[i]= yy[i]; z[i]= zz[i]; } return ( error ); } /* Now compute unit vectors x and y. Method used depends on the reference system in which right ascension of the CIO is given. */ switch ( ref_sys ) { /* ---------------------------- RA of CIO expressed in GCRS. ---------------------------- */ case 1: /* Compute vector x toward CIO in GCRS. */ sinra= sin( ra_cio * 15.0 * DEG2RAD ); cosra= cos( ra_cio * 15.0 * DEG2RAD ); xx[0]= zz[2] * cosra; xx[1]= zz[2] * sinra; xx[2]= -zz[0] * cosra - zz[1] * sinra; /* Normalize vector x. */ xmag= sqrt( xx[0] * xx[0] + xx[1] * xx[1] + xx[2] * xx[2] ); xx[0]/= xmag; xx[1]/= xmag; xx[2]/= xmag; /* Compute unit vector y orthogonal to x and z (y = z cross x). */ yy[0]= zz[1] * xx[2] - zz[2] * xx[1]; yy[1]= zz[2] * xx[0] - zz[0] * xx[2]; yy[2]= zz[0] * xx[1] - zz[1] * xx[0]; break; /* ---------------------------------------------------------- RA of CIO expressed in equator-and-equinox of date system. ---------------------------------------------------------- */ case 2: /* Construct unit vector toward CIO in equator-and-equinox-of-date system. */ w0[0]= cos( ra_cio * 15.0 * DEG2RAD ); w0[1]= sin( ra_cio * 15.0 * DEG2RAD ); w0[2]= 0.0; /* Rotate the vector into the GCRS to form unit vector x. */ nutation( jd_tdb, -1, accuracy, w0, w1 ); precession( jd_tdb, w1, T0, w2 ); frame_tie( w2, -1, xx ); /* Compute unit vector y orthogonal to x and z (y = z cross x). */ yy[0]= zz[1] * xx[2] - zz[2] * xx[1]; yy[1]= zz[2] * xx[0] - zz[0] * xx[2]; yy[2]= zz[0] * xx[1] - zz[1] * xx[0]; break; /* --------------------------- Invalid value of 'ref_sys'. --------------------------- */ default: for ( i= 0; i < 3; i++ ) { xx[i]= 0.0; yy[i]= 0.0; zz[i]= 0.0; } error= 1; break; } /* Load the x, y, and z arrays. */ for ( i= 0; i < 3; i++ ) { x[i]= xx[i]; y[i]= yy[i]; z[i]= zz[i]; } return ( error ); } /********cio_array */ short int cio_array( double jd_tdb, long int n_pts, ra_of_cio *cio ) /* ------------------------------------------------------------------------ PURPOSE: Given an input TDB Julian date and the number of data points desired, this function returns a set of Julian dates and corresponding values of the GCRS right ascension of the celestial intermediate origin (CIO). The range of dates is centered (at least approximately) on the requested date. The function obtains the data from an external data file. REFERENCES: None. INPUT ARGUMENTS: jd_tdb (double) TDB Julian date. n_pts (long int) Number of Julian dates and right ascension values requested (not less than 2 or more than 20). OUTPUT ARGUMENTS: *cio (struct ra_of_cio) An time series (array) of the right ascension of the Celestial Intermediate Origin (CIO) with respect to the GCRS (structure defined in novas.h). RETURNED VALUE: (short int) = 0 ... everything OK = 1 ... error opening the 'cio_ra.bin' file. = 2 ... 'jd_tdb' not in the range of the CIO file. = 3 ... 'n_pts' out of range. = 4 ... unable to allocate memory for the internal 't' array. = 5 ... unable to allocate memory for the internal 'ra' array. = 6 ... 'jd_tdb' is too close to either end of the CIO file; unable to put 'n_pts' data points into the output structure. GLOBALS USED: None. FUNCTIONS CALLED: fopen stdio.h fread stdio.h fclose stdio.h abs math.h free stdlib.h calloc stdlib.h fseek stdio.h VER./DATE/ PROGRAMMER: V1.0/09-04/JAB (USNO/AA) V1.1/12-05/WKP (USNO/AA) Changed struct type from 'cio_ra' to 'ra_of_cio' to avoid conflicts. V1.2/02-08/JAB (USNO/AA) Fix file-read strategy "Case 2" and improve documentation. NOTES: 1. This function assumes that binary, random-access file 'cio_ra.bin' has been created and is in the same directory as your executable. This file is created by program 'cio_file.c', included in the NOVAS-C package. On the first call to this function, file 'cio_ra.bin' is opened in read mode. ------------------------------------------------------------------------ */ { static short int first_call= 1; short int error= 0; static long int last_index_rec= -50L; static long int last_n_pts= 0L; static long int header_size, record_size, n_recs; long int min_pts= 2; long int max_pts= 20; long int del_n_pts, index_rec, half_int, lo_limit, hi_limit, del_index, abs_del_index, bytes_to_lo, n_swap, n_read, i, j; static double jd_beg, jd_end, t_int, *t, *ra; double t_temp, ra_temp; static size_t double_size, long_size; static FILE *cio_file; /* Set the sizes of the file header and data records, open the CIO file, and read the file header on the first call to this function. */ if ( first_call ) { double_size= sizeof( double ); long_size= sizeof( long int ); header_size= (long)( (size_t)3 * double_size + long_size ); record_size= (long)( (size_t)2 * double_size ); /* Open the input (binary, random-access) file. */ if ( ( cio_file= fopen( "cio_ra.bin", "rb" ) ) == NULL ) return ( error= 1 ); /* Read the file header. */ fread( &jd_beg, double_size, (size_t)1, cio_file ); fread( &jd_end, double_size, (size_t)1, cio_file ); fread( &t_int, double_size, (size_t)1, cio_file ); fread( &n_recs, long_size, (size_t)1, cio_file ); } /* Check the input data against limits. */ if ( ( jd_tdb < jd_beg ) || ( jd_tdb > jd_end ) ) return ( error= 2 ); if ( ( n_pts < min_pts ) || ( n_pts > max_pts ) ) return ( error= 3 ); /* Calculate the difference between the current value of 'n_pts' and the last value of 'n_pts'. */ del_n_pts= abs( n_pts - last_n_pts ); /* Allocate memory for the 't' and 'ra' arrays. */ if ( del_n_pts != 0L ) { if ( !first_call ) { free( t ); free( ra ); } t= (double *)calloc( (size_t)n_pts, double_size ); if ( t == NULL ) { fclose( cio_file ); return ( error= 4 ); } ra= (double *)calloc( (size_t)n_pts, double_size ); if ( ra == NULL ) { free( t ); fclose( cio_file ); return ( error= 5 ); } first_call= 0; } /* Calculate the record number of the record immediately preceding the date of interest: the "index record". */ index_rec= (long int)( ( jd_tdb - jd_beg ) / t_int ) + 1L; /* Test the range of 'n_pts' values centered on 'index_rec' to be sure the range of values requested falls within the file limits. */ half_int= ( n_pts / 2L ) - 1L; lo_limit= index_rec - half_int; hi_limit= index_rec + ( n_pts - half_int - 1L ); if ( ( lo_limit < 1L ) || ( hi_limit > n_recs ) ) return ( error= 6 ); /* Compute the number of bytes from the beginning of the file to the 'lo_limit'. */ bytes_to_lo= header_size + ( lo_limit - 1L ) * record_size; /* Compare the current index record with the previous index record. */ del_index= index_rec - last_index_rec; abs_del_index= abs( del_index ); /* Determine the file read strategy. */ /* Case 1: The input value of 'n_pts' changed since the last entry, or there are no data in the current arrays that can be re-used in the new arrays. In this case, read all new data points into the arrays. */ if ( ( abs_del_index > n_pts ) || ( del_n_pts != 0 ) ) { fseek( cio_file, bytes_to_lo, SEEK_SET ); for ( i= 0L; i < n_pts; i++ ) { fread( &t[i], double_size, (size_t)1, cio_file ); fread( &ra[i], double_size, (size_t)1, cio_file ); } } /* Case 2: The new index is close enough to the previous index that there are some data in the current arrays that can be re-used in the new arrays. The remaining data will be read from the CIO file. Note that if the new index is the same as the previous index (i.e., 'del_index' == 0), neither Case 2a nor 2b is satisfied, and the program flow goes directly to load the output arrays with the same values as in the current arrays. */ else if ( ( abs_del_index <= n_pts ) && ( del_n_pts == 0 ) ) { n_swap= abs( n_pts - abs_del_index ); n_read= abs_del_index; /* Case 2a: The new index is less than the previous one. Put the "old" data at the end of the new arrays, and read "new" data into the beginning of the new arrays. */ if ( del_index < 0L ) { for ( i= 0L; i < n_swap; i++ ) { t_temp= t[i]; ra_temp= ra[i]; j= i + abs_del_index; t[j]= t_temp; ra[j]= ra_temp; } fseek( cio_file, bytes_to_lo, SEEK_SET ); for ( i= 0L; i < n_read; i++ ) { fread( &t[i], double_size, (size_t)1, cio_file ); fread( &ra[i], double_size, (size_t)1, cio_file ); } } /* Case 2b: The new index is greater than the previous one. Put the "old" data at the beginning of the new arrays, and read "new" data into the end of the new arrays. */ else if ( del_index > 0L ) { for ( i= 0L; i < n_swap; i++ ) { j= i + abs_del_index; t_temp= t[j]; ra_temp= ra[j]; t[i]= t_temp; ra[i]= ra_temp; } fseek( cio_file, bytes_to_lo + ( n_swap * record_size ), SEEK_SET ); j= i++; for ( i= j; i < n_pts; i++ ) { fread( &t[i], double_size, (size_t)1, cio_file ); fread( &ra[i], double_size, (size_t)1, cio_file ); } } } /* Load the output 'cio' array with the values in the 't' and 'ra' arrays. Note that if the input value of 'n_pts' has not changed since the last entry, all data in the current arrays can be re-used in the new arrays. The if statements above are bypassed and the new arrays are the same as the current arrays. */ for ( i= 0L; i < n_pts; i++ ) { cio[i].jd_tdb= t[i]; cio[i].ra_cio= ra[i]; } /* Set values of 'last_index_rec' and 'last_n_pts'. */ last_index_rec= index_rec; last_n_pts= n_pts; return ( error ); } /********ira_equinox */ double ira_equinox( double jd_tdb, short int equinox, short int accuracy ) /* ------------------------------------------------------------------------ PURPOSE: To compute the intermediate right ascension of the equinox at the input Julian date, using an analytical expression for the accumulated precession in right ascension. For the true equinox, the result is the equation of the origins. REFERENCES: Capitaine, N. et al. (2003), Astronomy and Astrophysics 412, 567-586, eq. (42). INPUT ARGUMENTS: jd_tdb (double) TDB Julian date. equinox (short int) Equinox selection flag: = 0 ... mean equinox = 1 ... true equinox. accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: None. RETURNED VALUE: (double) Intermediate right ascension of the equinox, in hours (+ or -). If 'equinox' = 1 (i.e true equinox), then the returned value is the equation of the origins. GLOBALS USED: T0 novascon.c FUNCTIONS CALLED: e_tilt novas.c fabs math.h VER./DATE/ PROGRAMMER: V1.0/07-06/JAB (USNO/AA) NOTES: 1. This function is the C version of NOVAS Fortran routine 'eqxra'. ------------------------------------------------------------------------ */ { static short int acc_last= 99; static double t_last= 0.0; static double eq_eq= 0.0; double t, u, v, w, x, prec_ra, ra_eq; /* Compute time in Julian centuries. */ t= ( jd_tdb - T0 ) / 36525.0; /* For the true equinox, obtain the equation of the equinoxes in time seconds, which includes the 'complementary terms'. */ if ( equinox == 1 ) { if ( ( ( fabs( jd_tdb - t_last ) ) > 1.0e-8 ) || ( accuracy != acc_last ) ) { e_tilt( jd_tdb, accuracy, &u, &v, &eq_eq, &w, &x ); t_last= jd_tdb; acc_last= accuracy; } } else { eq_eq= 0.0; } /* Precession in RA in arcseconds taken from the reference. */ prec_ra= 0.014506 + ( ( ( ( -0.0000000368 * t - 0.000029956 ) * t - 0.00000044 ) * t + 1.3915817 ) * t + 4612.156534 ) * t; ra_eq= -( prec_ra / 15.0 + eq_eq ) / 3600.0; return ( ra_eq ); } /********ephemeris */ short int ephemeris( double jd[2], object *cel_obj, short int origin, short int accuracy, double *pos, double *vel ) /* ------------------------------------------------------------------------ PURPOSE: Retrieves the position and velocity of a solar system body from a fundamental ephemeris. REFERENCES: None. INPUT ARGUMENTS: jd[2] (double) TDB Julian date split into two parts, where the sum jd[0] + jd[1] is the TDB Julian date. *cel_obj (struct object) Pointer to structure containing the designation of the body of interest (defined in novas.h). origin (short int) Origin code = 0 ... solar system barycenter = 1 ... center of mass of the Sun accuracy (short int) Selection for accuracy = 0 ... full accuracy = 1 ... reduced accuracy OUTPUT ARGUMENTS: pos[3] (double) Position vector of the body at 'jd_tdb'; equatorial rectangular coordinates in AU referred to the ICRS. vel[3] (double) Velocity vector of the body at 'jd_tdb'; equatorial rectangular coordinates in AU/day referred to the ICRS. RETURNED VALUE: (short int) 0 ... Everything OK. 1 ... Invalid value of 'origin'. 2 ... Invalid value of 'type' in 'cel_obj'. 3 ... Unable to allocate memory. 10+n ... where n is the error code from 'solarsystem'. 20+n ... where n is the error code from 'readeph'. GLOBALS USED: None. FUNCTIONS CALLED: solarsystem novas.c solarsystem_hp novas.c readeph readeph.c strlen string.h strcpy string.h malloc stdlib.h free stdlib.h VER./DATE/ PROGRAMMER: V1.0/06-97/JAB (USNO/AA) V1.1/10-97/JAB (USNO/AA): Support error code from 'readeph'. V1.2/08-98/JAB (USNO/AA): Add computation of barycentric coordinates of a minor planet; support new 'readeph' argument list. V1.3/12-99/JAB (USNO/AA): Add error handling to call to 'solarsystem' (case 1). V1.4/12-02/JAB (USNO/AA): Fix memory leaks with 'posvel' (case 1). V1.5/10-08/JAB (USNO/AA): Incorporate higher-precision call to the solar system ephemeris, primarily to support light-time calculations. V1.6/02-11/JLB (USNO/AA): Reformatted description of origin for consistency with other documentation. NOTES: 1. It is recommended that the input structure 'cel_obj' be created using function 'make_object' in file novas.c. ------------------------------------------------------------------------ */ { char *mp_name; int err= 0; int mp_number; short int error= 0; short int ss_number, i; double jd_tdb, *posvel, *sun_pos, *sun_vel; size_t name_len; /* Check the value of 'origin'. */ if ( ( origin < 0 ) || ( origin > 1 ) ) return ( error= 1 ); /* Invoke the appropriate ephemeris access software depending upon the type of object. */ switch ( cel_obj->type ) { /* Get the position and velocity of a major planet, Pluto, Sun, or Moon. When high accuracy is specified, use function 'solarsystem_hp' rather than 'solarsystem'. */ case 0: ss_number= cel_obj->number; if ( accuracy == 0 ) { if ( ( error= solarsystem_hp( jd, ss_number, origin, pos, vel ) ) != 0 ) error+= 10; } else { jd_tdb= jd[0] + jd[1]; if ( ( error= solarsystem( jd_tdb, ss_number, origin, pos, vel ) ) != 0 ) error+= 10; } break; /* Get the position and velocity of a minor planet. */ case 1: mp_number= (int)cel_obj->number; name_len= ( strlen( cel_obj->name ) + 1L ) * sizeof( char ); mp_name= (char *)malloc( name_len ); if ( mp_name == NULL ) return ( error= 3 ); strcpy( mp_name, cel_obj->name ); /* The USNO minor planet software returns heliocentric positions and velocities. */ jd_tdb= jd[0] + jd[1]; posvel= readeph( mp_number, mp_name, jd_tdb, &err ); if ( posvel == NULL ) { free( mp_name ); return ( error= 3 ); } if ( err != 0 ) { free( mp_name ); free( posvel ); return ( (short int)( 20 + err ) ); } /* Barycentric coordinates of the minor planet, if desired, are computed via the barycentric coordinates of the Sun, obtained from the solar system ephemeris. */ if ( origin == 0 ) { sun_pos= (double *)malloc( 3L * sizeof( double ) ); if ( sun_pos == NULL ) { free( mp_name ); free( posvel ); return ( error= 3 ); } sun_vel= (double *)malloc( 3L * sizeof( double ) ); if ( sun_vel == NULL ) { free( mp_name ); free( posvel ); free( sun_pos ); return ( error= 3 ); } if ( ( error= solarsystem( jd_tdb, 10, 0, sun_pos, sun_vel ) ) != 0 ) { free( mp_name ); free( posvel ); free( sun_pos ); free( sun_vel ); return ( error+= 10 ); } for ( i= 0; i < 3; i++ ) { posvel[i]+= sun_pos[i]; posvel[i + 3]+= sun_vel[i]; } free( sun_pos ); free( sun_vel ); } /* Break up 'posvel' into separate position and velocity vectors. */ for ( i= 0; i < 3; i++ ) { pos[i]= posvel[i]; vel[i]= posvel[i + 3]; } free( mp_name ); free( posvel ); break; /* Invalid type of object. */ default: error= 2; break; } return ( error ); } /********transform_hip */ void transform_hip( cat_entry *hipparcos, cat_entry *hip_2000 ) /* ------------------------------------------------------------------------ PURPOSE: To convert Hipparcos catalog data at epoch J1991.25 to epoch J2000.0, for use within NOVAS. To be used only for Hipparcos or Tycho stars with linear space motion. Both input and output data is in the ICRS. REFERENCES: None. INPUT ARGUMENTS: *hipparcos (struct cat_entry) An entry from the Hipparcos catalog, at epoch J1991.25, with all members having Hipparcos catalog units. See Note 1 below (struct defined in novas.h). OUTPUT ARGUMENTS: *hip_2000 (struct cat_entry) The transformed input entry, at epoch J2000.0. See Note 2 below (struct defined in novas.h). RETURNED VALUE: None. GLOBALS USED: T0 novascon.c FUNCTIONS CALLED: transform_cat novas.c VER./DATE/ PROGRAMMER: V1.0/03-98/JAB (USNO/AA) V1.1/11-03/JAB (USNO/AA) Update for ICRS NOTES: 1. Input (Hipparcos catalog) epoch and units: Epoch: J1991.25 Right ascension (RA): degrees Declination (Dec): degrees Proper motion in RA: milliarcseconds per year Proper motion in Dec: milliarcseconds per year Parallax: milliarcseconds Radial velocity: kilometers per second (not in catalog) 2. Output (modified Hipparcos) epoch and units: Epoch: J2000.0 Right ascension: hours Declination: degrees Proper motion in RA: milliarcseconds per year Proper motion in Dec: milliarcseconds per year Parallax: milliarcseconds Radial velocity: kilometers per second 3. This function is the C version of NOVAS Fortran routine 'gethip'. ------------------------------------------------------------------------ */ { const double epoch_hip= 2448349.0625; cat_entry scratch; /* Set up a "scratch" catalog entry containing Hipparcos data in "NOVAS units." */ strcpy( scratch.starname, hipparcos->starname ); scratch.starnumber= hipparcos->starnumber; scratch.dec= hipparcos->dec; scratch.promora= hipparcos->promora; scratch.promodec= hipparcos->promodec; scratch.parallax= hipparcos->parallax; scratch.radialvelocity= hipparcos->radialvelocity; strcpy( scratch.catalog, "SCR" ); /* Convert right ascension from degrees to hours. */ scratch.ra= hipparcos->ra / 15.0; /* Change the epoch of the Hipparcos data from J1991.25 to J2000.0. */ transform_cat( 1, epoch_hip, &scratch, T0, "HP2", hip_2000 ); return; } /********transform_cat */ short int transform_cat( short int option, double date_incat, cat_entry *incat, double date_newcat, char newcat_id[SIZE_OF_CAT_NAME], cat_entry *newcat ) /* ------------------------------------------------------------------------ PURPOSE: To transform a star's catalog quantities for a change of epoch and/or equator and equinox. Also used to rotate catalog quantities on the dynamical equator and equinox of J2000.0 to the ICRS or vice versa. REFERENCES: None. INPUT ARGUMENTS: option (short int) Transformation option = 1 ... change epoch; same equator and equinox = 2 ... change equator and equinox; same epoch = 3 ... change equator and equinox and epoch = 4 ... change equator and equinox J2000.0 to ICRS = 5 ... change ICRS to equator and equinox of J2000.0 date_incat (double) TT Julian date, or year, of input catalog data. *incat (struct cat_entry) An entry from the input catalog, with units as given in the struct definition (struct defined in novas.h). date_newcat (double) TT Julian date, or year, of transformed catalog data. newcat_id[SIZE_OF_CAT_NAME] (char) Catalog identifier ((SIZE_OF_CAT_NAME - 1) characters maximum) e.g. HIP = Hipparcos, TY2 = Tycho-2. OUTPUT ARGUMENTS: *newcat (struct cat_entry) The transformed catalog entry, with units as given in the struct definition (struct defined in novas.h). RETURNED VALUE: = 0 ... Everything OK. = 1 ... Invalid value of an input date for option 2 or 3 (see Note 1 below). = 2 ... length of 'newcat_id' out of bounds. GLOBALS USED: SIZE_OF_CAT_NAME novas.h T0, ASEC2RAD novascon.c AU_KM, C novascon.c FUNCTIONS CALLED: precession novas.c frame_tie novas.c sin math.h cos math.h sqrt math.h atan2 math.h asin math.h strcpy string.h VER./DATE/ PROGRAMMER: V1.0/03-98/JAB (USNO/AA) V1.1/11-03/JAB (USNO/AA) Update for ICRS; add options 4 and 5. V1.2/06-08/WKP (USNO/AA) Changed 'a[3]' to 'd', added Doppler factor, and corrected 'frame_tie' direction. V1.3/06-08/JAB (USNO/AA) Error check on dates for options 2 and 3. V1.4/02-11/WKP (USNO/AA) Implement SIZE_OF_CAT_NAME. NOTES: 1. 'date_incat' and 'date_newcat' may be specified either as a Julian date (e.g., 2433282.5) or a Julian year and fraction (e.g., 1950.0). Values less than 10000 are assumed to be years. For 'option' = 2 or 'option' = 3, either 'date_incat' or 'date_newcat' must be 2451545.0 or 2000.0 (J2000.0). For 'option' = 4 and 'option' = 5, 'date_incat' and 'date_newcat' are ignored. 2. 'option' = 1 updates the star's data to account for the star's space motion between the first and second dates, within a fixed reference frame. 'option' = 2 applies a rotation of the reference frame corresponding to precession between the first and second dates, but leaves the star fixed in space. 'option' = 3 provides both transformations. 'option' = 4 and 'option' = 5 provide a a fixed rotation about very small angles (<0.1 arcsecond) to take data from the dynamical system of J2000.0 to the ICRS ('option' = 4) or vice versa ('option' = 5). 3. For 'option' = 1, input data can be in any fixed reference system. for 'option' = 2 or 'option' = 3, this function assumes the input data is in the dynamical system and produces output in the dynamical system. for 'option' = 4, the input data must be on the dynamical equator and equinox of J2000.0. for 'option' = 5, the input data must be in the ICRS. 4. This function cannot be properly used to bring data from old star catalogs into the modern system, because old catalogs were compiled using a set of constants that are incompatible with modern values. In particular, it should not be used for catalogs whose positions and proper motions were derived by assuming a precession constant significantly different from the value implicit in function 'precession'. 5. This function is the C version of NOVAS Fortran routine 'catran'. 6. SIZE_OF_CAT_NAME is defined in novas.h. ------------------------------------------------------------------------ */ { short int error= 0; short int j; double jd_incat, jd_newcat, paralx, dist, r, d, cra, sra, cdc, sdc, k, pos1[3], term1, pmr, pmd, rvl, vel1[3], pos2[3], vel2[3], xyproj; /* If necessary, compute Julian dates. This function uses TDB Julian dates internally, but no distinction between TDB and TT is necessary. */ if ( date_incat < 10000.0 ) jd_incat= T0 + ( date_incat - 2000.0 ) * 365.25; else jd_incat= date_incat; if ( date_newcat < 10000.0 ) jd_newcat= T0 + ( date_newcat - 2000.0 ) * 365.25; else jd_newcat= date_newcat; /* Convert input angular components to vectors If parallax is unknown, undetermined, or zero, set it to 1.0e-6 milliarcsecond, corresponding to a distance of 1 gigaparsec. */ paralx= incat->parallax; if ( paralx <= 0.0 ) paralx= 1.0e-6; /* Convert right ascension, declination, and parallax to position vector in equatorial system with units of AU. */ dist= 1.0 / sin( paralx * 1.0e-3 * ASEC2RAD ); r= incat->ra * 54000.0 * ASEC2RAD; d= incat->dec * 3600.0 * ASEC2RAD; cra= cos( r ); sra= sin( r ); cdc= cos( d ); sdc= sin( d ); pos1[0]= dist * cdc * cra; pos1[1]= dist * cdc * sra; pos1[2]= dist * sdc; /* Compute Doppler factor, which accounts for change in light travel time to star. */ k= 1.0 / ( 1.0 - incat->radialvelocity / C * 1000.0 ); /* Convert proper motion and radial velocity to orthogonal components of motion, in spherical polar system at star's original position, with units of AU/day. */ term1= paralx * 365.25; pmr= incat->promora / term1 * k; pmd= incat->promodec / term1 * k; rvl= incat->radialvelocity * 86400.0 / AU_KM * k; /* Transform motion vector to equatorial system. */ vel1[0]= -pmr * sra - pmd * sdc * cra + rvl * cdc * cra; vel1[1]= pmr * cra - pmd * sdc * sra + rvl * cdc * sra; vel1[2]= pmd * cdc + rvl * sdc; /* Update star's position vector for space motion (only if 'option' = 1 or 'option' = 3). */ if ( ( option == 1 ) || ( option == 3 ) ) { for ( j= 0; j < 3; j++ ) { pos2[j]= pos1[j] + vel1[j] * ( jd_newcat - jd_incat ); vel2[j]= vel1[j]; } } else { for ( j= 0; j < 3; j++ ) { pos2[j]= pos1[j]; vel2[j]= vel1[j]; } } /* Precess position and velocity vectors (only if 'option' = 2 or 'option' = 3). */ if ( ( option == 2 ) || ( option == 3 ) ) { for ( j= 0; j < 3; j++ ) { pos1[j]= pos2[j]; vel1[j]= vel2[j]; } if ( ( error= precession( jd_incat, pos1, jd_newcat, pos2 ) ) != 0 ) return ( error ); precession( jd_incat, vel1, jd_newcat, vel2 ); } /* Rotate dynamical J2000.0 position and velocity vectors to ICRS (only if 'option' = 4). */ if ( option == 4 ) { frame_tie( pos1, -1, pos2 ); frame_tie( vel1, -1, vel2 ); } /* Rotate ICRS position and velocity vectors to dynamical J2000.0 (only if 'option' = 5). */ if ( option == 5 ) { frame_tie( pos1, 1, pos2 ); frame_tie( vel1, 1, vel2 ); } /* Convert vectors back to angular components for output. From updated position vector, obtain star's new position expressed as angular quantities. */ xyproj= sqrt( pos2[0] * pos2[0] + pos2[1] * pos2[1] ); if ( xyproj > 0.0 ) r= atan2( pos2[1], pos2[0] ); else r= 0.0; newcat->ra= r / ASEC2RAD / 54000.0; if ( newcat->ra < 0.0 ) newcat->ra+= 24.0; if ( newcat->ra >= 24.0 ) newcat->ra-= 24.0; d= atan2( pos2[2], xyproj ); newcat->dec= d / ASEC2RAD / 3600.0; dist= sqrt( pos2[0] * pos2[0] + pos2[1] * pos2[1] + pos2[2] * pos2[2] ); paralx= asin( 1.0 / dist ) / ASEC2RAD * 1000.0; newcat->parallax= paralx; /* Transform motion vector back to spherical polar system at star's new position. */ cra= cos( r ); sra= sin( r ); cdc= cos( d ); sdc= sin( d ); pmr= -vel2[0] * sra + vel2[1] * cra; pmd= -vel2[0] * cra * sdc - vel2[1] * sra * sdc + vel2[2] * cdc; rvl= vel2[0] * cra * cdc + vel2[1] * sra * cdc + vel2[2] * sdc; /* Convert components of motion to from AU/day to normal catalog units. */ newcat->promora= pmr * paralx * 365.25 / k; newcat->promodec= pmd * paralx * 365.25 / k; newcat->radialvelocity= rvl * ( AU_KM / 86400.0 ) / k; /* Take care of zero-parallax case. */ if ( newcat->parallax <= 1.01e-6 ) { newcat->parallax= 0.0; newcat->radialvelocity= incat->radialvelocity; } /* Set the catalog identification code for the transformed catalog entry. */ if ( (short int)strlen( newcat_id ) > SIZE_OF_CAT_NAME - 1 ) return ( 2 ); else strcpy( newcat->catalog, newcat_id ); /* Copy unchanged quantities from the input catalog entry to the transformed catalog entry. */ strcpy( newcat->starname, incat->starname ); newcat->starnumber= incat->starnumber; return ( error ); } /********limb_angle */ void limb_angle( double pos_obj[3], double pos_obs[3], double *limb_ang, double *nadir_ang ) /* ------------------------------------------------------------------------ PURPOSE: This function determines the angle of an object above or below the Earth's limb (horizon). The geometric limb is computed, assuming the Earth to be an airless sphere (no refraction or oblateness is included). The observer can be on or above the Earth. For an observer on the surface of the Earth, this function returns the approximate unrefracted altitude. REFERENCES: None. INPUT ARGUMENTS: pos_obj[3] (double) Position vector of observed object, with respect to origin at geocenter, components in AU. pos_obs[3] (double) Position vector of observer, with respect to origin at geocenter, components in AU. OUTPUT ARGUMENTS: *limb_ang (double) Angle of observed object above (+) or below (-) limb in degrees. *nadir_ang (double) Nadir angle of observed object as a fraction of apparent radius of limb: < 1.0 ... below the limb = 1.0 ... on the limb > 1.0 ... above the limb RETURNED VALUE: None. GLOBALS USED: TWOPI, ERAD novascon.c AU, RAD2DEG novascon.c FUNCTIONS CALLED: sqrt math.h asin math.h acos math.h VER./DATE/ PROGRAMMER: V1.0/09-04/JAB (USNO/AA) NOTES: 1.This function is the C version of NOVAS Fortran routine 'limang'. ------------------------------------------------------------------------ */ { static short int first_entry= 1; static double pi, halfpi, rade; double disobj, disobs, aprad, zdlim, coszd, zdobj; if ( first_entry ) { pi= TWOPI / 2.0; halfpi= pi / 2.0; rade= ERAD / AU; first_entry= 0; } /* Compute the distance to the object and the distance to the observer. */ disobj= sqrt( pos_obj[0] * pos_obj[0] + pos_obj[1] * pos_obj[1] + pos_obj[2] * pos_obj[2] ); disobs= sqrt( pos_obs[0] * pos_obs[0] + pos_obs[1] * pos_obs[1] + pos_obs[2] * pos_obs[2] ); /* Compute apparent angular radius of Earth's limb. */ if ( disobs >= rade ) { aprad= asin( rade / disobs ); } else { aprad= halfpi; } /* Compute zenith distance of Earth's limb. */ zdlim= pi - aprad; /* Compute zenith distance of observed object. */ coszd= ( pos_obj[0] * pos_obs[0] + pos_obj[1] * pos_obs[1] + pos_obj[2] * pos_obs[2] ) / ( disobj * disobs ); if ( coszd <= -1.0 ) { zdobj= pi; } else if ( coszd >= 1.0 ) { zdobj= 0.0; } else { zdobj= acos( coszd ); } /* Angle of object wrt limb is difference in zenith distances. */ *limb_ang= ( zdlim - zdobj ) * RAD2DEG; /* Nadir angle of object as a fraction of angular radius of limb. */ *nadir_ang= ( pi - zdobj ) / aprad; return; } /********refract */ double refract( on_surface *location, short int ref_option, double zd_obs ) /* ------------------------------------------------------------------------ PURPOSE: This function computes atmospheric refraction in zenith distance. This version computes approximate refraction for optical wavelengths. REFERENCES: Explanatory Supplement to the Astronomical Almanac, p. 144. Bennett, G. (1982), Journal of Navigation (Royal Institute) 35, pp. 255-259. INPUT ARGUMENTS: *location (struct on_surface) Pointer to structure containing observer's location. This structure also contains weather data (optional) for the observer's location (defined in novas.h). ref_option (short int) = 1 ... Use 'standard' atmospheric conditions. = 2 ... Use atmospheric parameters input in the 'location' structure. zd_obs (double) Observed zenith distance, in degrees. OUTPUT ARGUMENTS: None. RETURNED VALUE: (double) Atmospheric refraction, in degrees. GLOBALS USED: DEG2RAD novascon.c FUNCTIONS CALLED: exp math.h tan math.h VER./DATE/ PROGRAMMER: V1.0/06-98/JAB (USNO/AA) NOTES: 1. This function can be used for planning observations or telescope pointing, but should not be used for the reduction of precise observations. 2. This function is the C version of NOVAS Fortran routine 'refrac'. ------------------------------------------------------------------------ */ { /* 's' is the approximate scale height of atmosphere in meters. */ const double s= 9.1e3; double refr, p, t, h, r; /* Compute refraction only for zenith distances between 0.1 and 91 degrees. */ if ( ( zd_obs < 0.1 ) || ( zd_obs > 91.0 ) ) refr= 0.0; else { /* If observed weather data are available, use them. Otherwise, use crude estimates of average conditions. */ if ( ref_option == 2 ) { p= location->pressure; t= location->temperature; } else { p= 1010.0 * exp( -location->height / s ); t= 10.0; } h= 90.0 - zd_obs; r= 0.016667 / tan( ( h + 7.31 / ( h + 4.4 ) ) * DEG2RAD ); refr= r * ( 0.28 * p / ( t + 273.0 ) ); } return ( refr ); } /********julian_date */ double julian_date( short int year, short int month, short int day, double hour ) /* ------------------------------------------------------------------------ PURPOSE: This function will compute the Julian date for a given calendar date (year, month, day, hour). REFERENCES: Fliegel, H. & Van Flandern, T. Comm. of the ACM, Vol. 11, No. 10, October 1968, p. 657. INPUT ARGUMENTS: year (short int) Year. month (short int) Month number. day (short int) Day-of-month. hour (double) Hour-of-day. OUTPUT ARGUMENTS: None. RETURNED VALUE: (double) Julian date. GLOBALS USED: None. FUNCTIONS CALLED: None. VER./DATE/ PROGRAMMER: V1.0/06-98/JAB (USNO/AA) V1.1/03-08/WKP (USNO/AA) Updated prolog. NOTES: 1. This function is the C version of NOVAS Fortran routine 'juldat'. 2. This function makes no checks for a valid input calendar date. 3. Input calendar date must be Gregorian. 4. Input time value can be based on any UT-like time scale (UTC, UT1, TT, etc.) - output Julian date will have the same basis. ------------------------------------------------------------------------ */ { long int jd12h; double tjd; jd12h= (long)day - 32075L + 1461L * ( (long)year + 4800L + ( (long)month - 14L ) / 12L ) / 4L + 367L * ( (long)month - 2L - ( (long)month - 14L ) / 12L * 12L ) / 12L - 3L * ( ( (long)year + 4900L + ( (long)month - 14L ) / 12L ) / 100L ) / 4L; tjd= (double)jd12h - 0.5 + hour / 24.0; return ( tjd ); } /********cal_date */ void cal_date( double tjd, short int *year, short int *month, short int *day, double *hour ) /* ------------------------------------------------------------------------ PURPOSE: This function will compute a date on the Gregorian calendar given the Julian date. REFERENCES: Fliegel, H. & Van Flandern, T. Comm. of the ACM, Vol. 11, No. 10, October 1968, p. 657. INPUT ARGUMENTS: tjd (double) Julian date. OUTPUT ARGUMENTS: *year (short int) Year. *month (short int) Month number. *day (short int) Day-of-month. *hour (double) Hour-of-day. RETURNED VALUE: None. GLOBALS USED: None. FUNCTIONS CALLED: fmod math.h VER./DATE/ PROGRAMMER: V1.0/06-98/JAB (USNO/AA) NOTES: 1. This routine valid for any 'jd' greater than zero. 2. Input Julian date can be based on any UT-like time scale (UTC, UT1, TT, etc.) - output time value will have same basis. 3. This function is the C version of NOVAS Fortran routine 'caldat'. ------------------------------------------------------------------------ */ { long int jd, k, m, n; double djd; djd= tjd + 0.5; jd= (long int)djd; *hour= fmod( djd, 1.0 ) * 24.0; k= jd + 68569L; n= 4L * k / 146097L; k= k - ( 146097L * n + 3L ) / 4L; m= 4000L * ( k + 1L ) / 1461001L; k= k - 1461L * m / 4L + 31L; *month= (short int)( 80L * k / 2447L ); *day= (short int)( k - 2447L * (long int)*month / 80L ); k= (long int)*month / 11L; *month= (short int)( (long int)*month + 2L - 12L * k ); *year= (short int)( 100L * ( n - 49L ) + m + k ); return; } /********norm_ang */ double norm_ang( double angle ) /* ------------------------------------------------------------------------ PURPOSE: Normalize angle into the range 0 <= angle < (2 * pi). REFERENCES: None. INPUT ARGUMENTS: angle (double) Input angle (radians). OUTPUT ARGUMENTS: None. RETURNED VALUE: (double) The input angle, normalized as described above (radians). GLOBALS USED: TWOPI novascon.c FUNCTIONS CALLED: fmod math.h VER./DATE/ PROGRAMMER: V1.0/09-03/JAB (USNO/AA) NOTES: None. ------------------------------------------------------------------------ */ { double a; a= fmod( angle, TWOPI ); if ( a < 0.0 ) a+= TWOPI; return ( a ); } /********make_cat_entry */ short int make_cat_entry( char star_name[SIZE_OF_OBJ_NAME], char catalog[SIZE_OF_CAT_NAME], long int star_num, double ra, double dec, double pm_ra, double pm_dec, double parallax, double rad_vel, cat_entry *star ) /* ------------------------------------------------------------------------ PURPOSE: To create a structure of type 'cat_entry' containing catalog data for a star or "star-like" object. REFERENCES: None. INPUT ARGUMENTS: star_name[SIZE_OF_OBJ_NAME] (char) Object name ((SIZE_OF_OBJ_NAME - 1) characters maximum). catalog[SIZE_OF_CAT_NAME] (char) Catalog identifier ((SIZE_OF_CAT_NAME - 1) characters maximum) e.g. HIP = Hipparcos, TY2 = Tycho-2. star_num (long int) Object number in the catalog. ra (double) Right ascension of the object (hours). dec (double) Declination of the object (degrees). pm_ra (double) Proper motion in right ascension (milliarcseconds/year). pm_dec (double) Proper motion in declination (milliarcseconds/year). parallax (double) Parallax (milliarcseconds). rad_vel (double) Radial velocity (kilometers/second). OUTPUT ARGUMENTS: *star (struct cat_entry) Structure containing the input data (structure defined in novas.h). RETURNED VALUE: (short int) = 0 ... no problems. = 1 ... length of 'star_name' out of bounds. = 2 ... length of 'catalog' out of bounds. GLOBALS USED: SIZE_OF_OBJ_NAME novas.h SIZE_OF_CAT_NAME novas.h FUNCTIONS CALLED: strlen string.h strcpy string.h VER./DATE/ PROGRAMMER: V1.0/03-98/JAB (USNO/AA) V1.1/08-04/JAB (USNO/AA) V1.3/05-10/JAB (USNO/AA): Fix bugs in set-up of 'star->starname' and 'star->catalog'. NOTES: 1. This utility function creates a single data structure encapsulating the input data. 2. SIZE_OF_OBJ_NAME and SIZE_OF_CAT_NAME are defined in novas.h. ------------------------------------------------------------------------ */ { /* Set up the 'star' structure. */ if ( (short int)strlen( star_name ) > SIZE_OF_OBJ_NAME - 1 ) return ( 1 ); else strcpy( star->starname, star_name ); if ( (short int)strlen( catalog ) > SIZE_OF_CAT_NAME - 1 ) return ( 2 ); else strcpy( star->catalog, catalog ); star->starnumber= star_num; star->ra= ra; star->dec= dec; star->promora= pm_ra; star->promodec= pm_dec; star->parallax= parallax; star->radialvelocity= rad_vel; return ( 0 ); } /********make_object */ short int make_object( short int type, short int number, char name[SIZE_OF_OBJ_NAME], cat_entry *star_data, object *cel_obj ) /* ------------------------------------------------------------------------ PURPOSE: Makes a structure of type 'object' - specifying a celestial object - based on the input parameters. REFERENCES: None. INPUT ARGUMENTS: type (short int) Type of object = 0 ... major planet, Pluto, Sun, or Moon = 1 ... minor planet = 2 ... object located outside the solar system (e.g. star, galaxy, nebula, etc.) number (short int) Body number For 'type' = 0: Mercury = 1,...,Pluto = 9, Sun = 10, Moon = 11 For 'type' = 1: minor planet number For 'type' = 2: set to 0 (zero) name[SIZE_OF_OBJ_NAME] (char) Name of the object ((SIZE_OF_OBJ_NAME - 1) characters maximum). *star_data (struct cat_entry) Structure containing basic astrometric data for any celestial object located outside the solar system; the catalog data for a star (defined in novas.h). OUTPUT ARGUMENTS: struct object *cel_obj Structure containing the object definition (defined in novas.h). RETURNED VALUE: (short int) = 0 ... everything OK = 1 ... invalid value of 'type' = 2 ... 'number' out of range = 3 ... Initialization of 'cel_obj' failed (object name). = 4 ... Initialization of 'cel_obj' failed (catalog name). = 5 ... 'name' is out of string bounds. GLOBALS USED: SIZE_OF_OBJ_NAME novas.h SIZE_OF_CAT_NAME novas.h FUNCTIONS CALLED: strlen string.h strcpy string.h toupper ctype.h VER./DATE/ PROGRAMMER: V1.0/06-97/JAB (USNO/AA) V1.1/10-98/JAB (USNO/AA): Change object name to mixed case. V1.2/12-02/JAB (USNO/AA): Fix bug by adding brackets in the "Set the object number" 'if' block. V1.3/07-04/JAB (USNO/AA): Change name from 'set_body'; expand to include objects outside solar system. V1.4/05-10/JAB (USNO/AA): Implement SIZE_OF_OBJ_NAME and SIZE_OF_CAT_NAME; check length of 'name'. V1.5/09-10/WKP (USNO/AA): Explicitly cast 'toupper' return value to type 'char' to silence compiler. NOTES: 1. SIZE_OF_OBJ_NAME and SIZE_OF_CAT_NAME are defined in novas.h. ------------------------------------------------------------------------ */ { short int error= 0; short int i; /* Initialize the structure. */ cel_obj->type= 0; cel_obj->number= 0; strcpy( cel_obj->name, " " ); if ( (short int)strlen( " " ) > SIZE_OF_OBJ_NAME - 1 ) return ( error= 3 ); else { strcpy( cel_obj->name, " " ); strcpy( cel_obj->star.starname, " " ); } if ( (short int)strlen( " " ) > SIZE_OF_CAT_NAME - 1 ) return ( error= 4 ); else strcpy( cel_obj->star.catalog, " " ); cel_obj->star.starnumber= 0L; cel_obj->star.ra= 0.0; cel_obj->star.dec= 0.0; cel_obj->star.promora= 0.0; cel_obj->star.promodec= 0.0; cel_obj->star.parallax= 0.0; cel_obj->star.radialvelocity= 0.0; /* Set the object type. */ if ( ( type < 0 ) || ( type > 2 ) ) return ( error= 1 ); else cel_obj->type= type; /* Set the object number. */ if ( type == 0 ) { if ( ( number <= 0 ) || ( number > 11 ) ) return ( error= 2 ); } else if ( type == 1 ) { if ( number <= 0 ) return ( error= 2 ); } else { number= 0; } cel_obj->number= number; /* Check length of 'name'. Set the object name in upper case. */ if ( (short int)strlen( name ) > SIZE_OF_OBJ_NAME - 1 ) return ( error= 5 ); for ( i= 0; i < SIZE_OF_OBJ_NAME - 1; i++ ) { cel_obj->name[i]= (char)toupper( name[i] ); if ( name[i] == '\0' ) break; } cel_obj->name[i]= '\0'; /* Populate the astrometric-data structure if the object is 'type' = 2. */ if ( type == 2 ) { strcpy( cel_obj->star.starname, star_data->starname ); strcpy( cel_obj->star.catalog, star_data->catalog ); cel_obj->star.starnumber= star_data->starnumber; cel_obj->star.ra= star_data->ra; cel_obj->star.dec= star_data->dec; cel_obj->star.promora= star_data->promora; cel_obj->star.promodec= star_data->promodec; cel_obj->star.parallax= star_data->parallax; cel_obj->star.radialvelocity= star_data->radialvelocity; } return ( error ); } /********make_observer */ short int make_observer( short int where, on_surface *obs_surface, in_space *obs_space, observer *obs ) /* ------------------------------------------------------------------------ PURPOSE: Makes a structure of type 'observer' - specifying the location of the observer. REFERENCES: None. INPUT ARGUMENTS: where (short int) Integer code specifying location of observer. = 0: observer at geocenter = 1: observer on surface of earth = 2: observer on near-earth spacecraft *obs_surface (struct on_surface) Structure containing data for an observer's location on the surface of the Earth; used when 'where' = 1 (defined in novas.h). *obs_space (struct in_space) Data for an observer's location on a near-Earth spacecraft; used when 'where' = 2 (defined in novas.h). OUTPUT ARGUMENTS: struct observer *obs Structure specifying the location of the observer (defined in novas.h). RETURNED VALUE: (short int) = 0 ... everything OK. = 1 ... input value of 'where' is out-of-range. GLOBALS USED: None. FUNCTIONS CALLED: None. VER./DATE/ PROGRAMMER: V1.0/08-04/JAB (USNO/AA) NOTES: None. ------------------------------------------------------------------------ */ { short int error= 0; /* Initialize the output structure. */ obs->where= where; obs->on_surf.latitude= 0.0; obs->on_surf.longitude= 0.0; obs->on_surf.height= 0.0; obs->on_surf.temperature= 0.0; obs->on_surf.pressure= 0.0; obs->near_earth.sc_pos[0]= 0.0; obs->near_earth.sc_pos[1]= 0.0; obs->near_earth.sc_pos[2]= 0.0; obs->near_earth.sc_vel[0]= 0.0; obs->near_earth.sc_vel[1]= 0.0; obs->near_earth.sc_vel[2]= 0.0; /* Populate the output structure based on the value of 'where'. */ switch ( where ) { case ( 0 ): /* Geocentric */ break; case ( 1 ): /* On surface of Earth */ obs->on_surf.latitude= obs_surface->latitude; obs->on_surf.longitude= obs_surface->longitude; obs->on_surf.height= obs_surface->height; obs->on_surf.temperature= obs_surface->temperature; obs->on_surf.pressure= obs_surface->pressure; break; case ( 2 ): /* In near-Earth spacecraft */ obs->near_earth.sc_pos[0]= obs_space->sc_pos[0]; obs->near_earth.sc_pos[1]= obs_space->sc_pos[1]; obs->near_earth.sc_pos[2]= obs_space->sc_pos[2]; obs->near_earth.sc_vel[0]= obs_space->sc_vel[0]; obs->near_earth.sc_vel[1]= obs_space->sc_vel[1]; obs->near_earth.sc_vel[2]= obs_space->sc_vel[2]; break; default: error= 1; break; } return ( error ); } /********make_observer_at_geocenter */ void make_observer_at_geocenter( observer *obs_at_geocenter ) /* ------------------------------------------------------------------------ PURPOSE: Makes a structure of type 'observer' specifying an observer at the geocenter. REFERENCES: None. INPUT ARGUMENTS: None. OUTPUT ARGUMENTS: struct observer *obs_at_geocenter Structure specifying the location of the observer at the geocenter (defined in novas.h). RETURNED VALUE: None. GLOBALS USED: None. FUNCTIONS CALLED: make_in_space novas.c make_on_surface novas.c VER./DATE/ PROGRAMMER: V1.0/03-07/JAB (USNO/AA) NOTES: 1. The output data structure is one of the inputs to NOVAS-C function 'place'. ------------------------------------------------------------------------ */ { double latitude= 0.0; double longitude= 0.0; double height= 0.0; double temperature= 0.0; double pressure= 0.0; double sat_pos[3]= {0.0, 0.0, 0.0}; double sat_vel[3]= {0.0, 0.0, 0.0}; in_space sat_state; on_surface surface_loc; make_in_space( sat_pos, sat_vel, &sat_state ); make_on_surface( latitude, longitude, height, temperature, pressure, &surface_loc ); obs_at_geocenter->where= 0; obs_at_geocenter->on_surf= surface_loc; obs_at_geocenter->near_earth= sat_state; } /********make_observer_on_surface */ void make_observer_on_surface( double latitude, double longitude, double height, double temperature, double pressure, observer *obs_on_surface ) /* ------------------------------------------------------------------------ PURPOSE: Makes a structure of type 'observer' specifying the location of and weather for an observer on the surface of the Earth. REFERENCES: None. INPUT ARGUMENTS: latitude (double) Geodetic (ITRS) latitude in degrees; north positive. longitude (double) Geodetic (ITRS) longitude in degrees; east positive. height (double) Height of the observer (meters). temperature (double) Temperature (degrees Celsius). pressure (double) Atmospheric pressure (millibars). OUTPUT ARGUMENTS: struct observer *obs_on_surface Structure containing the location of and weather for an observer on the surface of the Earth (defined in novas.h). RETURNED VALUE: None. GLOBALS USED: None. FUNCTIONS CALLED: make_in_space novas.c make_on_surface novas.c VER./DATE/ PROGRAMMER: V1.0/03-07/JAB (USNO/AA) NOTES: 1. The output data structure is one of the inputs to NOVAS-C function 'place'. ------------------------------------------------------------------------ */ { double sat_pos[3]= {0.0, 0.0, 0.0}; double sat_vel[3]= {0.0, 0.0, 0.0}; in_space sat_state; on_surface surface_loc; make_in_space( sat_pos, sat_vel, &sat_state ); make_on_surface( latitude, longitude, height, temperature, pressure, &surface_loc ); obs_on_surface->where= 1; obs_on_surface->on_surf= surface_loc; obs_on_surface->near_earth= sat_state; } /********make_observer_in_space */ void make_observer_in_space( double sc_pos[3], double sc_vel[3], observer *obs_in_space ) /* ------------------------------------------------------------------------ PURPOSE: Makes a structure of type 'observer' specifying the position and velocity of an observer situated on a near-Earth spacecraft. REFERENCES: None. INPUT ARGUMENTS: sc_pos[3] (double) Geocentric position vector (x, y, z) in km. sc_vel[3] (double) Geocentric velocity vector (x_dot, y_dot, z_dot) in km/s. OUTPUT ARGUMENTS: struct observer *obs_in_space Structure containing the position and velocity of an observer situated on a near-Earth spacecraft (defined in novas.h). RETURNED VALUE: None. GLOBALS USED: None. FUNCTIONS CALLED: make_in_space novas.c make_on_surface novas.c VER./DATE/ PROGRAMMER: V1.0/03-07/JAB (USNO/AA) NOTES: 1. Both input vectors are with respect to true equator and equinox of date. 2. The output data structure is one of the inputs to NOVAS-C function 'place'. ------------------------------------------------------------------------ */ { const double latitude= 0.0; const double longitude= 0.0; const double height= 0.0; const double temperature= 0.0; const double pressure= 0.0; in_space sat_state; on_surface surface_loc; make_in_space( sc_pos, sc_vel, &sat_state ); make_on_surface( latitude, longitude, height, temperature, pressure, &surface_loc ); obs_in_space->where= 2; obs_in_space->on_surf= surface_loc; obs_in_space->near_earth= sat_state; } /********make_on_surface */ void make_on_surface( double latitude, double longitude, double height, double temperature, double pressure, on_surface *obs_surface ) /* ------------------------------------------------------------------------ PURPOSE: Makes a structure of type 'on_surface' - specifying the location of and weather for an observer on the surface of the Earth. REFERENCES: None. INPUT ARGUMENTS: latitude (double) Geodetic (ITRS) latitude in degrees; north positive. longitude (double) Geodetic (ITRS) longitude in degrees; east positive. height (double) Height of the observer (meters). temperature (double) Temperature (degrees Celsius). pressure (double) Atmospheric pressure (millibars). OUTPUT ARGUMENTS: struct on_surface *obs_surface Structure containing the location of and weather for an observer on the surface of the Earth (defined in novas.h). RETURNED VALUE: None. GLOBALS USED: None. FUNCTIONS CALLED: None. VER./DATE/ PROGRAMMER: V1.0/08-04/JAB (USNO/AA) NOTES: None. ------------------------------------------------------------------------ */ { obs_surface->latitude= latitude; obs_surface->longitude= longitude; obs_surface->height= height; obs_surface->temperature= temperature; obs_surface->pressure= pressure; } /********make_in_space */ void make_in_space( double sc_pos[3], double sc_vel[3], in_space *obs_space ) /* ------------------------------------------------------------------------ PURPOSE: Makes a structure of type 'in_space' - specifying the position and velocity of an observer situated on a near-Earth spacecraft. REFERENCES: None. INPUT ARGUMENTS: sc_pos[3] (double) Geocentric position vector (x, y, z) in km. sc_vel[3] (double) Geocentric velocity vector (x_dot, y_dot, z_dot) in km/s. OUTPUT ARGUMENTS: struct in_space *obs_space Structure containing the position and velocity of an observer situated on a near-Earth spacecraft (defined in novas.h). RETURNED VALUE: None. GLOBALS USED: None. FUNCTIONS CALLED: None. VER./DATE/ PROGRAMMER: V1.0/08-04/JAB (USNO/AA) NOTES: 1. Both vectors with respect to true equator and equinox of date. ------------------------------------------------------------------------ */ { obs_space->sc_pos[0]= sc_pos[0]; obs_space->sc_pos[1]= sc_pos[1]; obs_space->sc_pos[2]= sc_pos[2]; obs_space->sc_vel[0]= sc_vel[0]; obs_space->sc_vel[1]= sc_vel[1]; obs_space->sc_vel[2]= sc_vel[2]; }
254,122
C
.c
7,881
26.525314
398
0.567833
kirxkirx/vast
13
3
3
GPL-3.0
9/7/2024, 11:01:22 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
6,225,417
nutation.c
kirxkirx_vast/src/heliocentric_correction/nutation.c
/* Naval Observatory Vector Astrometry Software (NOVAS) C Edition, Version 3.1 nutation.c: Nutation models U. S. Naval Observatory Astronomical Applications Dept. Washington, DC http://www.usno.navy.mil/USNO/astronomical-applications */ #ifndef _NOVAS_ #include "novas.h" #endif /********iau2000a */ void iau2000a( double jd_high, double jd_low, double *dpsi, double *deps ) /* ------------------------------------------------------------------------ PURPOSE: To compute the forced nutation of the non-rigid Earth based on the IAU 2000A nutation model. REFERENCES: IERS Conventions (2003), Chapter 5. Simon et al. (1994) Astronomy and Astrophysics 282, 663-683, esp. Sections 3.4-3.5. INPUT ARGUMENTS: jd_high (double) High-order part of TT Julian date. jd_low (double) Low-order part of TT Julian date. OUTPUT ARGUMENTS: *dpsi (double) Nutation (luni-solar + planetary) in longitude, in radians. *deps (double) Nutation (luni-solar + planetary) in obliquity, in radians. RETURNED VALUE: None. GLOBALS USED: T0, ASEC2RAD, TWOPI FUNCTIONS CALLED: fund_args novas.c fmod math.h sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/03-04/JAB (USNO/AA) V1.1/12-10/JAB (USNO/AA): Implement static storage class for const arrays. V1.2/03-11/WKP (USNO/AA): Added braces to 2-D array initialization to quiet gcc warnings. NOTES: 1. The IAU 2000A nutation model is MHB_2000 without the free core nutation and without the corrections to Lieske precession. 2. This function is the "C" version of NOVAS Fortran routine 'nu2000a'. ------------------------------------------------------------------------ */ { short int i; double t, a[5], dp, de, arg, sarg, carg, factor, dpsils, depsls, al, alsu, af, ad, aom, alme, alve, alea, alma, alju, alsa, alur, alne, apa, dpsipl, depspl; /* Luni-Solar argument multipliers: L L' F D Om */ static const short int nals_t[678][5]= { {0, 0, 0, 0, 1}, {0, 0, 2, -2, 2}, {0, 0, 2, 0, 2}, {0, 0, 0, 0, 2}, {0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2, -2, 2}, {2, 0, 0, -2, 2}, {0, 2, 0, 0, 1}, {1, 0, 0, -4, 1}, {0, 2, 2, -2, 1}, {-3, 0, 0, 4, 0}, {-1, 1, 2, 0, 1}, {-1, -1, 0, 4, 0}, {-1, -2, 2, 2, 2}, {-2, -1, 2, 4, 2}, {1, -1, 2, 2, 1}, {-2, 1, 0, 2, 0}, {-2, 1, 2, 0, 1}, {2, 1, 0, -2, 1}, {-3, 0, 2, 0, 1}, {-2, 0, 2, -2, 1}, {-1, 1, 0, 2, 2}, {0, -1, 2, -1, 2}, {-1, 0, 4, -2, 2}, {0, -2, 2, 0, 2}, {-1, 0, 2, 1, 2}, {2, 0, 0, 0, 2}, {0, 0, 2, 0, 3}, {-2, 0, 4, 0, 2}, {-1, 0, -2, 0, 1}, {-1, 1, 2, 2, 1}, {3, 0, 0, 0, 1}, {-1, 0, 2, 3, 2}, {2, -1, 2, 0, 1}, {0, 1, 2, 2, 1}, {0, -1, 2, 4, 2}, {2, -1, 2, 2, 2}, {0, 2, -2, 2, 0}, {-1, -1, 2, -1, 1}, {0, -2, 0, 0, 1}, {1, 0, 2, -4, 2}, {1, -1, 0, -2, 1}, {-1, -1, 2, 0, 1}, {1, -1, 2, -2, 2}, {-2, -1, 0, 4, 0}, {-1, 0, 0, 3, 0}, {-2, -1, 2, 2, 2}, {0, 2, 2, 0, 2}, {1, 1, 0, 2, 0}, {2, 0, 2, -1, 2}, {1, 0, 2, 1, 1}, {4, 0, 0, 0, 0}, {2, 1, 2, 0, 1}, {3, -1, 2, 0, 2}, {-2, 2, 0, 2, 1}, {1, 0, 2, -3, 1}, {1, 1, 2, -4, 1}, {-1, -1, 2, -2, 1}, {0, -1, 0, -1, 1}, {0, -1, 0, -2, 1}, {-2, 0, 0, 0, 2}, {-2, 0, -2, 2, 0}, {-1, 0, -2, 4, 0}, {1, -2, 0, 0, 0}, {0, 1, 0, 1, 1}, {-1, 2, 0, 2, 0}, {1, -1, 2, -2, 1}, {1, 2, 2, -2,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, 4, 2}, {1, 1, -2, 1, 0}, {-3, 1, 2, 1, 2}, {2, 0, -2, 0, 2}, {-1, 0, 0, 1, 2}, {-4, 0, 2, 2, 1}, {-1, -1, 0, 1, 0}, {0, 0, -2, 2, 2}, {1, 0, 0, -1, 2}, {0, -1, 2, -2, 3}, {-2, 1, 2, 0, 0}, {0, 0, 2, -2, 4}, {-2, -2, 0, 2, 0}, {-2, 0, -2, 4, 0}, {0, -2, -2, 2, 0}, {1, 2, 0, -2, 1}, {3, 0, 0, -4, 1}, {-1, 1, 2, -2, 2}, {1, -1, 2, -4, 1}, {1, 1, 0, -2, 2}, {-3, 0, 2, 0, 0}, {-3, 0, 2, 0, 2}, {-2, 0, 0, 1, 0}, {0, 0, -2, 1, 0}, {-3, 0, 0, 2, 1}, {-1, -1, -2, 2, 0}, {0, 1, 2, -4, 1}, {2, 1, 0, -4, 1}, {0, 2, 0, -2, 1}, {1, 0, 0, -3, 1}, {-2, 0, 2, -2, 2}, {-2, -1, 0, 0, 1}, {-4, 0, 0, 2, 0}, {1, 1, 0, -4, 1}, {-1, 0, 2, -4, 1}, {0, 0, 4, -4, 1}, {0, 3, 2, -2, 2}, {-3, -1, 0, 4, 0}, {-3, 0, 0, 4, 1}, {1, -1, -2, 2, 0}, {-1, -1, 0, 2, 2}, {1, -2, 0, 0, 1}, {1, -1, 0, 0, 2}, {0, 0, 0, 1, 2}, {-1, -1, 2, 0, 0}, {1, -2, 2, -2, 2}, {0, -1, 2, -1, 1}, {-1, 0, 2, 0, 3}, {1, 1, 0, 0, 2}, {-1, 1, 2, 0, 0}, {1, 2, 0, 0, 0}, {-1, 2, 2, 0, 2}, {-1, 0, 4, -2, 1}, {3, 0, 2, -4, 2}, {1, 2, 2, -2, 1}, {1, 0, 4, -4, 2}, {-2, -1, 0, 4, 1}, {0, -1, 0, 2, 2}, {-2, 1, 0, 4, 0}, {-2, -1, 2, 2, 1}, {2, 0, -2, 2, 0}, {1, 0, 0, 1, 1}, {0, 1, 0, 2,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 6, 2}, {4, 0, 2, 2, 2}, {0, -1, 1, -1, 1}, {-1, 0, 1, 0, 3}, {0, -2, 2, -2, 3}, {1, 0, -1, 0, 1}, {2, -2, 0, -2, 1}, {-1, 0, 1, 0, 2}, {-1, 0, 1, 0, 1}, {-1, -1, 2, -1, 2}, {-2, 2, 0, 2, 2}, {-1, 0, 1, 0, 0}, {-4, 1, 2, 2, 2}, {-3, 0, 2, 1, 1}, {-2, -1, 2, 0, 2}, {1, 0, -2, 1, 1}, {2, -1, -2, 0, 1}, {-4, 0, 2, 2, 0}, {-3, 1, 0, 3, 0}, {-1, 0, -1, 2, 0}, {0, -2, 0, 0, 2}, {0, -2, 0, 0, 2}, {-3, 0, 0, 3, 0}, {-2, -1, 0, 2, 2}, {-1, 0, -2, 3, 0}, {-4, 0, 0, 4, 0}, {2, 1, -2, 0, 1}, {2, -1, 0, -2, 2}, {0, 0, 1, -1, 0}, {-1, 2, 0, 1, 0}, {-2, 1, 2, 0, 2}, {1, 1, 0, -1, 1}, {1, 0, 1, -2, 1}, {0, 2, 0, 0, 2}, {1, -1, 2, -3, 1}, {-1, 1, 2, -1, 1}, {-2, 0, 4, -2, 2}, {-2, 0, 4, -2, 1}, {-2, -2, 0, 2, 1}, {-2, 0, -2, 4, 0}, {1, 2, 2, -4, 1}, {1, 1, 2, -4, 2}, {-1, 2, 2, -2, 1}, {2, 0, 0, -3, 1}, {-1, 2, 0, 0, 1}, {0, 0, 0, -2, 0}, {-1, -1, 2, -2, 2}, {-1, 1, 0, 0, 2}, {0, 0, 0, -1, 2}, {-2, 1, 0, 1, 0}, {1, -2, 0, -2, 1}, {1, 0, -2, 0, 2}, {-3, 1, 0, 2, 0}, {-1, 1, -2, 2, 0}, {-1, -1, 0, 0, 2}, {-3, 0, 0, 2, 0}, {-3, -1, 0, 2, 0}, {2, 0, 2, -6, 1}, {0, 1, 2, -4, 2}, {2, 0, 0, -4, 2}, {-2, 1, 2, -2, 1}, {0, -1, 2, -4, 1}, {0, 1, 0, -2, 2}, {-1, 0, 0, -2, 0}, {2, 0, -2, -2, 1}, {-4, 0, 2, 0, 1}, {-1, -1, 0, -1, 1}, {0, 0, -2, 0, 2}, {-3, 0, 0, 1, 0}, {-1, 0, -2, 1, 0}, {-2, 0, -2, 2, 1}, {0, 0, -4, 2, 0}, {-2, -1, -2, 2, 0}, {1, 0, 2, -6, 1}, {-1, 0, 2, -4, 2}, {1, 0, 0, -4, 2}, {2, 1, 2, -4, 2}, {2, 1, 2, -4, 1}, {0, 1, 4, -4, 4}, {0, 1, 4, -4, 2}, {-1, -1, -2, 4, 0}, {-1, -3, 0, 2, 0}, {-1, 0, -2, 4, 1}, {-2, -1, 0, 3, 0}, {0, 0, -2, 3, 0}, {-2, 0, 0, 3, 1}, {0, -1, 0, 1, 0}, {-3, 0, 2, 2, 0}, {1, 1, -2, 2, 0}, {-1, 1, 0, 2, 2}, {1, -2, 2, -2, 1}, {0, 0, 1, 0, 2}, {0, 0, 1, 0, 1}, {0, 0, 1, 0, 0}, {-1, 2, 0, 2, 1}, {0, 0, 2, 0, 2}, {-2, 0, 2, 0, 2}, {2, 0, 0, -1, 1}, {3, 0, 0, -2, 1}, {1, 0, 2, -2, 3}, {1, 2, 0, 0, 1}, {2, 0, 2, -3, 2}, {-1, 1, 4, -2, 2}, {-2, -2, 0, 4, 0}, {0, -3, 0, 2, 0}, {0, 0, -2, 4, 0}, {-1, -1, 0, 3, 0}, {-2, 0, 0, 4, 2}, {-1, 0, 0, 3, 1}, {2, -2, 0, 0, 0}, {1, -1, 0, 1, 0}, {-1, 0, 0, 2, 0}, {0, -2, 2, 0, 1}, {-1, 0, 1, 2, 1}, {-1, 1, 0, 3, 0}, {-1, -1, 2, 1, 2}, {0, -1, 2, 0, 0}, {-2, 1, 2, 2, 1}, {2, -2, 2, -2, 2}, {1, 1, 0, 1, 1}, {1, 0, 1, 0, 1}, {1, 0, 1, 0, 0}, {0, 2, 0, 2, 0}, {2, -1, 2, -2, 1}, {0, -1, 4, -2,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1, 2, 1, 1}, {0, 2, 2, 2, 2}, {2, 1, 2, 0, 0}, {2, 0, 4, -2, 1}, {4, 1, 2, -2, 2}, {-1, -1, 0, 6, 0}, {-3, -1, 2, 6, 2}, {-1, 0, 0, 6, 1}, {-3, 0, 2, 6, 1}, {1, -1, 0, 4, 1}, {1, -1, 0, 4, 0}, {-2, 0, 2, 5, 2}, {1, -2, 2, 2, 1}, {3, -1, 0, 2, 0}, {1, -1, 2, 2, 0}, {0, 0, 2, 3, 1}, {-1, 1, 2, 4, 1}, {0, 1, 2, 3, 2}, {-1, 0, 4, 2, 1}, {2, 0, 2, 1, 1}, {5, 0, 0, 0, 0}, {2, 1, 2, 1, 2}, {1, 0, 4, 0, 1}, {3, 1, 2, 0, 1}, {3, 0, 4, -2, 2}, {-2, -1, 2, 6, 2}, {0, 0, 0, 6, 0}, {0, -2, 2, 4, 2}, {-2, 0, 2, 6, 1}, {2, 0, 0, 4, 1}, {2, 0, 0, 4, 0}, {2, -2, 2, 2, 2}, {0, 0, 2, 4, 0}, {1, 0, 2, 3, 2}, {4, 0, 0, 2, 0}, {2, 0, 2, 2, 0}, {0, 0, 4, 2, 2}, {4, -1, 2, 0, 2}, {3, 0, 2, 1, 2}, {2, 1, 2, 2, 1}, {4, 1, 2, 0, 2}, {-1, -1, 2, 6, 2}, {-1, 0, 2, 6, 1}, {1, -1, 2, 4, 1}, {1, 1, 2, 4, 2}, {3, 1, 2, 2, 2}, {5, 0, 2, 0, 1}, {2, -1, 2, 4, 2}, {2, 0, 2, 4, 1}}; /* Luni-Solar nutation coefficients, unit 1e-7 arcsec: longitude (sin, t*sin, cos), obliquity (cos, t*cos, sin) Each row of coefficients in 'cls_t' belongs with the corresponding row of fundamental-argument multipliers in 'nals_t'. */ static const double cls_t[678][6]= { {-172064161.0, -174666.0, 33386.0, 92052331.0, 9086.0, 15377.0}, {-13170906.0, -1675.0, -13696.0, 5730336.0, -3015.0, -4587.0}, {-2276413.0, -234.0, 2796.0, 978459.0, -485.0, 1374.0}, {2074554.0, 207.0, -698.0, -897492.0, 470.0, -291.0}, {1475877.0, -3633.0, 11817.0, 73871.0, -184.0, -1924.0}, {-516821.0, 1226.0, -524.0, 224386.0, -677.0, -174.0}, {711159.0, 73.0, -872.0, -6750.0, 0.0, 358.0}, {-387298.0, -367.0, 380.0, 200728.0, 18.0, 318.0}, {-301461.0, -36.0, 816.0, 129025.0, -63.0, 367.0}, {215829.0, -494.0, 111.0, -95929.0, 299.0, 132.0}, {128227.0, 137.0, 181.0, -68982.0, -9.0, 39.0}, {123457.0, 11.0, 19.0, -53311.0, 32.0, -4.0}, {156994.0, 10.0, -168.0, -1235.0, 0.0, 82.0}, {63110.0, 63.0, 27.0, -33228.0, 0.0, -9.0}, {-57976.0, -63.0, -189.0, 31429.0, 0.0, -75.0}, {-59641.0, -11.0, 149.0, 25543.0, -11.0, 66.0}, {-51613.0, -42.0, 129.0, 26366.0, 0.0, 78.0}, {45893.0, 50.0, 31.0, -24236.0, -10.0, 20.0}, {63384.0, 11.0, -150.0, -1220.0, 0.0, 29.0}, {-38571.0, -1.0, 158.0, 16452.0, -11.0, 68.0}, {32481.0, 0.0, 0.0, -13870.0, 0.0, 0.0}, {-47722.0, 0.0, -18.0, 477.0, 0.0, -25.0}, {-31046.0, -1.0, 131.0, 13238.0, -11.0, 59.0}, {28593.0, 0.0, -1.0, -12338.0, 10.0, -3.0}, {20441.0, 21.0, 10.0, -10758.0, 0.0, -3.0}, {29243.0, 0.0, -74.0, -609.0, 0.0, 13.0}, {25887.0, 0.0, -66.0, -550.0, 0.0, 11.0}, {-14053.0, -25.0, 79.0, 8551.0, -2.0, -45.0}, {15164.0, 10.0, 11.0, -8001.0, 0.0, -1.0}, {-15794.0, 72.0, -16.0, 6850.0, -42.0, -5.0}, {21783.0, 0.0, 13.0, -167.0, 0.0, 13.0}, {-12873.0, -10.0, -37.0, 6953.0, 0.0, -14.0}, {-12654.0, 11.0, 63.0, 6415.0, 0.0, 26.0}, {-10204.0, 0.0, 25.0, 5222.0, 0.0, 15.0}, {16707.0, -85.0, -10.0, 168.0, -1.0, 10.0}, {-7691.0, 0.0, 44.0, 3268.0, 0.0, 19.0}, {-11024.0, 0.0, -14.0, 104.0, 0.0, 2.0}, {7566.0, -21.0, -11.0, -3250.0, 0.0, -5.0}, {-6637.0, -11.0, 25.0, 3353.0, 0.0, 14.0}, {-7141.0, 21.0, 8.0, 3070.0, 0.0, 4.0}, {-6302.0, -11.0, 2.0, 3272.0, 0.0, 4.0}, {5800.0, 10.0, 2.0, -3045.0, 0.0, -1.0}, {6443.0, 0.0, -7.0, -2768.0, 0.0, -4.0}, {-5774.0, -11.0, -15.0, 3041.0, 0.0, -5.0}, {-5350.0, 0.0, 21.0, 2695.0, 0.0, 12.0}, {-4752.0, -11.0, -3.0, 2719.0, 0.0, -3.0}, {-4940.0, -11.0, -21.0, 2720.0, 0.0, -9.0}, {7350.0, 0.0, -8.0, -51.0, 0.0, 4.0}, {4065.0, 0.0, 6.0, -2206.0, 0.0, 1.0}, {6579.0, 0.0, -24.0, -199.0, 0.0, 2.0}, {3579.0, 0.0, 5.0, -1900.0, 0.0, 1.0}, {4725.0, 0.0, -6.0, -41.0, 0.0, 3.0}, {-3075.0, 0.0, -2.0, 1313.0, 0.0, -1.0}, {-2904.0, 0.0, 15.0, 1233.0, 0.0, 7.0}, {4348.0, 0.0, -10.0, -81.0, 0.0, 2.0}, {-2878.0, 0.0, 8.0, 1232.0, 0.0, 4.0}, {-4230.0, 0.0, 5.0, -20.0, 0.0, -2.0}, {-2819.0, 0.0, 7.0, 1207.0, 0.0, 3.0}, {-4056.0, 0.0, 5.0, 40.0, 0.0, -2.0}, {-2647.0, 0.0, 11.0, 1129.0, 0.0, 5.0}, {-2294.0, 0.0, -10.0, 1266.0, 0.0, -4.0}, {2481.0, 0.0, -7.0, -1062.0, 0.0, -3.0}, {2179.0, 0.0, -2.0, -1129.0, 0.0, -2.0}, {3276.0, 0.0, 1.0, -9.0, 0.0, 0.0}, {-3389.0, 0.0, 5.0, 35.0, 0.0, -2.0}, {3339.0, 0.0, -13.0, -107.0, 0.0, 1.0}, {-1987.0, 0.0, -6.0, 1073.0, 0.0, -2.0}, {-1981.0, 0.0, 0.0, 854.0, 0.0, 0.0}, {4026.0, 0.0, -353.0, -553.0, 0.0, -139.0}, {1660.0, 0.0, -5.0, -710.0, 0.0, -2.0}, {-1521.0, 0.0, 9.0, 647.0, 0.0, 4.0}, {1314.0, 0.0, 0.0, -700.0, 0.0, 0.0}, {-1283.0, 0.0, 0.0, 672.0, 0.0, 0.0}, {-1331.0, 0.0, 8.0, 663.0, 0.0, 4.0}, {1383.0, 0.0, -2.0, -594.0, 0.0, -2.0}, {1405.0, 0.0, 4.0, -610.0, 0.0, 2.0}, {1290.0, 0.0, 0.0, -556.0, 0.0, 0.0}, {-1214.0, 0.0, 5.0, 518.0, 0.0, 2.0}, {1146.0, 0.0, -3.0, -490.0, 0.0, -1.0}, {1019.0, 0.0, -1.0, -527.0, 0.0, -1.0}, {-1100.0, 0.0, 9.0, 465.0, 0.0, 4.0}, {-970.0, 0.0, 2.0, 496.0, 0.0, 1.0}, {1575.0, 0.0, -6.0, -50.0, 0.0, 0.0}, {934.0, 0.0, -3.0, -399.0, 0.0, -1.0}, {922.0, 0.0, -1.0, -395.0, 0.0, -1.0}, {815.0, 0.0, -1.0, -422.0, 0.0, -1.0}, {834.0, 0.0, 2.0, -440.0, 0.0, 1.0}, {1248.0, 0.0, 0.0, -170.0, 0.0, 1.0}, {1338.0, 0.0, -5.0, -39.0, 0.0, 0.0}, {716.0, 0.0, -2.0, -389.0, 0.0, -1.0}, {1282.0, 0.0, -3.0, -23.0, 0.0, 1.0}, {742.0, 0.0, 1.0, -391.0, 0.0, 0.0}, {1020.0, 0.0, -25.0, -495.0, 0.0, -10.0}, {715.0, 0.0, -4.0, -326.0, 0.0, 2.0}, {-666.0, 0.0, -3.0, 369.0, 0.0, -1.0}, {-667.0, 0.0, 1.0, 346.0, 0.0, 1.0}, {-704.0, 0.0, 0.0, 304.0, 0.0, 0.0}, {-694.0, 0.0, 5.0, 294.0, 0.0, 2.0}, {-1014.0, 0.0, -1.0, 4.0, 0.0, -1.0}, {-585.0, 0.0, -2.0, 316.0, 0.0, -1.0}, {-949.0, 0.0, 1.0, 8.0, 0.0, -1.0}, {-595.0, 0.0, 0.0, 258.0, 0.0, 0.0}, {528.0, 0.0, 0.0, -279.0, 0.0, 0.0}, {-590.0, 0.0, 4.0, 252.0, 0.0, 2.0}, {570.0, 0.0, -2.0, -244.0, 0.0, -1.0}, {-502.0, 0.0, 3.0, 250.0, 0.0, 2.0}, {-875.0, 0.0, 1.0, 29.0, 0.0, 0.0}, {-492.0, 0.0, -3.0, 275.0, 0.0, -1.0}, {535.0, 0.0, -2.0, -228.0, 0.0, -1.0}, {-467.0, 0.0, 1.0, 240.0, 0.0, 1.0}, {591.0, 0.0, 0.0, -253.0, 0.0, 0.0}, {-453.0, 0.0, -1.0, 244.0, 0.0, -1.0}, {766.0, 0.0, 1.0, 9.0, 0.0, 0.0}, {-446.0, 0.0, 2.0, 225.0, 0.0, 1.0}, {-488.0, 0.0, 2.0, 207.0, 0.0, 1.0}, {-468.0, 0.0, 0.0, 201.0, 0.0, 0.0}, {-421.0, 0.0, 1.0, 216.0, 0.0, 1.0}, {463.0, 0.0, 0.0, -200.0, 0.0, 0.0}, {-673.0, 0.0, 2.0, 14.0, 0.0, 0.0}, {658.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-438.0, 0.0, 0.0, 188.0, 0.0, 0.0}, {-390.0, 0.0, 0.0, 205.0, 0.0, 0.0}, {639.0, -11.0, -2.0, -19.0, 0.0, 0.0}, {412.0, 0.0, -2.0, -176.0, 0.0, -1.0}, {-361.0, 0.0, 0.0, 189.0, 0.0, 0.0}, {360.0, 0.0, -1.0, -185.0, 0.0, -1.0}, {588.0, 0.0, -3.0, -24.0, 0.0, 0.0}, {-578.0, 0.0, 1.0, 5.0, 0.0, 0.0}, {-396.0, 0.0, 0.0, 171.0, 0.0, 0.0}, {565.0, 0.0, -1.0, -6.0, 0.0, 0.0}, {-335.0, 0.0, -1.0, 184.0, 0.0, -1.0}, {357.0, 0.0, 1.0, -154.0, 0.0, 0.0}, {321.0, 0.0, 1.0, -174.0, 0.0, 0.0}, {-301.0, 0.0, -1.0, 162.0, 0.0, 0.0}, {-334.0, 0.0, 0.0, 144.0, 0.0, 0.0}, {493.0, 0.0, -2.0, -15.0, 0.0, 0.0}, {494.0, 0.0, -2.0, -19.0, 0.0, 0.0}, {337.0, 0.0, -1.0, -143.0, 0.0, -1.0}, {280.0, 0.0, -1.0, -144.0, 0.0, 0.0}, {309.0, 0.0, 1.0, -134.0, 0.0, 0.0}, {-263.0, 0.0, 2.0, 131.0, 0.0, 1.0}, {253.0, 0.0, 1.0, -138.0, 0.0, 0.0}, {245.0, 0.0, 0.0, -128.0, 0.0, 0.0}, {416.0, 0.0, -2.0, -17.0, 0.0, 0.0}, {-229.0, 0.0, 0.0, 128.0, 0.0, 0.0}, {231.0, 0.0, 0.0, -120.0, 0.0, 0.0}, {-259.0, 0.0, 2.0, 109.0, 0.0, 1.0}, {375.0, 0.0, -1.0, -8.0, 0.0, 0.0}, {252.0, 0.0, 0.0, -108.0, 0.0, 0.0}, {-245.0, 0.0, 1.0, 104.0, 0.0, 0.0}, {243.0, 0.0, -1.0, -104.0, 0.0, 0.0}, {208.0, 0.0, 1.0, -112.0, 0.0, 0.0}, {199.0, 0.0, 0.0, -102.0, 0.0, 0.0}, {-208.0, 0.0, 1.0, 105.0, 0.0, 0.0}, {335.0, 0.0, -2.0, -14.0, 0.0, 0.0}, {-325.0, 0.0, 1.0, 7.0, 0.0, 0.0}, {-187.0, 0.0, 0.0, 96.0, 0.0, 0.0}, {197.0, 0.0, -1.0, -100.0, 0.0, 0.0}, {-192.0, 0.0, 2.0, 94.0, 0.0, 1.0}, {-188.0, 0.0, 0.0, 83.0, 0.0, 0.0}, {276.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-286.0, 0.0, 1.0, 6.0, 0.0, 0.0}, {186.0, 0.0, -1.0, -79.0, 0.0, 0.0}, {-219.0, 0.0, 0.0, 43.0, 0.0, 0.0}, {276.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {-153.0, 0.0, -1.0, 84.0, 0.0, 0.0}, {-156.0, 0.0, 0.0, 81.0, 0.0, 0.0}, {-154.0, 0.0, 1.0, 78.0, 0.0, 0.0}, {-174.0, 0.0, 1.0, 75.0, 0.0, 0.0}, {-163.0, 0.0, 2.0, 69.0, 0.0, 1.0}, {-228.0, 0.0, 0.0, 1.0, 0.0, 0.0}, {91.0, 0.0, -4.0, -54.0, 0.0, -2.0}, {175.0, 0.0, 0.0, -75.0, 0.0, 0.0}, {-159.0, 0.0, 0.0, 69.0, 0.0, 0.0}, {141.0, 0.0, 0.0, -72.0, 0.0, 0.0}, {147.0, 0.0, 0.0, -75.0, 0.0, 0.0}, {-132.0, 0.0, 0.0, 69.0, 0.0, 0.0}, {159.0, 0.0, -28.0, -54.0, 0.0, 11.0}, {213.0, 0.0, 0.0, -4.0, 0.0, 0.0}, {123.0, 0.0, 0.0, -64.0, 0.0, 0.0}, {-118.0, 0.0, -1.0, 66.0, 0.0, 0.0}, {144.0, 0.0, -1.0, -61.0, 0.0, 0.0}, {-121.0, 0.0, 1.0, 60.0, 0.0, 0.0}, {-134.0, 0.0, 1.0, 56.0, 0.0, 1.0}, {-105.0, 0.0, 0.0, 57.0, 0.0, 0.0}, {-102.0, 0.0, 0.0, 56.0, 0.0, 0.0}, {120.0, 0.0, 0.0, -52.0, 0.0, 0.0}, {101.0, 0.0, 0.0, -54.0, 0.0, 0.0}, {-113.0, 0.0, 0.0, 59.0, 0.0, 0.0}, {-106.0, 0.0, 0.0, 61.0, 0.0, 0.0}, {-129.0, 0.0, 1.0, 55.0, 0.0, 0.0}, {-114.0, 0.0, 0.0, 57.0, 0.0, 0.0}, {113.0, 0.0, -1.0, -49.0, 0.0, 0.0}, {-102.0, 0.0, 0.0, 44.0, 0.0, 0.0}, {-94.0, 0.0, 0.0, 51.0, 0.0, 0.0}, {-100.0, 0.0, -1.0, 56.0, 0.0, 0.0}, {87.0, 0.0, 0.0, -47.0, 0.0, 0.0}, {161.0, 0.0, 0.0, -1.0, 0.0, 0.0}, {96.0, 0.0, 0.0, -50.0, 0.0, 0.0}, {151.0, 0.0, -1.0, -5.0, 0.0, 0.0}, {-104.0, 0.0, 0.0, 44.0, 0.0, 0.0}, {-110.0, 0.0, 0.0, 48.0, 0.0, 0.0}, {-100.0, 0.0, 1.0, 50.0, 0.0, 0.0}, {92.0, 0.0, -5.0, 12.0, 0.0, -2.0}, {82.0, 0.0, 0.0, -45.0, 0.0, 0.0}, {82.0, 0.0, 0.0, -45.0, 0.0, 0.0}, {-78.0, 0.0, 0.0, 41.0, 0.0, 0.0}, {-77.0, 0.0, 0.0, 43.0, 0.0, 0.0}, {2.0, 0.0, 0.0, 54.0, 0.0, 0.0}, {94.0, 0.0, 0.0, -40.0, 0.0, 0.0}, {-93.0, 0.0, 0.0, 40.0, 0.0, 0.0}, {-83.0, 0.0, 10.0, 40.0, 0.0, -2.0}, {83.0, 0.0, 0.0, -36.0, 0.0, 0.0}, {-91.0, 0.0, 0.0, 39.0, 0.0, 0.0}, {128.0, 0.0, 0.0, -1.0, 0.0, 0.0}, {-79.0, 0.0, 0.0, 34.0, 0.0, 0.0}, {-83.0, 0.0, 0.0, 47.0, 0.0, 0.0}, {84.0, 0.0, 0.0, -44.0, 0.0, 0.0}, {83.0, 0.0, 0.0, -43.0, 0.0, 0.0}, {91.0, 0.0, 0.0, -39.0, 0.0, 0.0}, {-77.0, 0.0, 0.0, 39.0, 0.0, 0.0}, {84.0, 0.0, 0.0, -43.0, 0.0, 0.0}, {-92.0, 0.0, 1.0, 39.0, 0.0, 0.0}, {-92.0, 0.0, 1.0, 39.0, 0.0, 0.0}, {-94.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {68.0, 0.0, 0.0, -36.0, 0.0, 0.0}, {-61.0, 0.0, 0.0, 32.0, 0.0, 0.0}, {71.0, 0.0, 0.0, -31.0, 0.0, 0.0}, {62.0, 0.0, 0.0, -34.0, 0.0, 0.0}, {-63.0, 0.0, 0.0, 33.0, 0.0, 0.0}, {-73.0, 0.0, 0.0, 32.0, 0.0, 0.0}, {115.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-103.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {63.0, 0.0, 0.0, -28.0, 0.0, 0.0}, {74.0, 0.0, 0.0, -32.0, 0.0, 0.0}, {-103.0, 0.0, -3.0, 3.0, 0.0, -1.0}, {-69.0, 0.0, 0.0, 30.0, 0.0, 0.0}, {57.0, 0.0, 0.0, -29.0, 0.0, 0.0}, {94.0, 0.0, 0.0, -4.0, 0.0, 0.0}, {64.0, 0.0, 0.0, -33.0, 0.0, 0.0}, {-63.0, 0.0, 0.0, 26.0, 0.0, 0.0}, {-38.0, 0.0, 0.0, 20.0, 0.0, 0.0}, {-43.0, 0.0, 0.0, 24.0, 0.0, 0.0}, {-45.0, 0.0, 0.0, 23.0, 0.0, 0.0}, {47.0, 0.0, 0.0, -24.0, 0.0, 0.0}, {-48.0, 0.0, 0.0, 25.0, 0.0, 0.0}, {45.0, 0.0, 0.0, -26.0, 0.0, 0.0}, {56.0, 0.0, 0.0, -25.0, 0.0, 0.0}, {88.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {-75.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {85.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {49.0, 0.0, 0.0, -26.0, 0.0, 0.0}, {-74.0, 0.0, -3.0, -1.0, 0.0, -1.0}, {-39.0, 0.0, 0.0, 21.0, 0.0, 0.0}, {45.0, 0.0, 0.0, -20.0, 0.0, 0.0}, {51.0, 0.0, 0.0, -22.0, 0.0, 0.0}, {-40.0, 0.0, 0.0, 21.0, 0.0, 0.0}, {41.0, 0.0, 0.0, -21.0, 0.0, 0.0}, {-42.0, 0.0, 0.0, 24.0, 0.0, 0.0}, {-51.0, 0.0, 0.0, 22.0, 0.0, 0.0}, {-42.0, 0.0, 0.0, 22.0, 0.0, 0.0}, {39.0, 0.0, 0.0, -21.0, 0.0, 0.0}, {46.0, 0.0, 0.0, -18.0, 0.0, 0.0}, {-53.0, 0.0, 0.0, 22.0, 0.0, 0.0}, {82.0, 0.0, 0.0, -4.0, 0.0, 0.0}, {81.0, 0.0, -1.0, -4.0, 0.0, 0.0}, {47.0, 0.0, 0.0, -19.0, 0.0, 0.0}, {53.0, 0.0, 0.0, -23.0, 0.0, 0.0}, {-45.0, 0.0, 0.0, 22.0, 0.0, 0.0}, {-44.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-33.0, 0.0, 0.0, 16.0, 0.0, 0.0}, {-61.0, 0.0, 0.0, 1.0, 0.0, 0.0}, {28.0, 0.0, 0.0, -15.0, 0.0, 0.0}, {-38.0, 0.0, 0.0, 19.0, 0.0, 0.0}, {-33.0, 0.0, 0.0, 21.0, 0.0, 0.0}, {-60.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {48.0, 0.0, 0.0, -10.0, 0.0, 0.0}, {27.0, 0.0, 0.0, -14.0, 0.0, 0.0}, {38.0, 0.0, 0.0, -20.0, 0.0, 0.0}, {31.0, 0.0, 0.0, -13.0, 0.0, 0.0}, {-29.0, 0.0, 0.0, 15.0, 0.0, 0.0}, {28.0, 0.0, 0.0, -15.0, 0.0, 0.0}, {-32.0, 0.0, 0.0, 15.0, 0.0, 0.0}, {45.0, 0.0, 0.0, -8.0, 0.0, 0.0}, {-44.0, 0.0, 0.0, 19.0, 0.0, 0.0}, {28.0, 0.0, 0.0, -15.0, 0.0, 0.0}, {-51.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-36.0, 0.0, 0.0, 20.0, 0.0, 0.0}, {44.0, 0.0, 0.0, -19.0, 0.0, 0.0}, {26.0, 0.0, 0.0, -14.0, 0.0, 0.0}, {-60.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {35.0, 0.0, 0.0, -18.0, 0.0, 0.0}, {-27.0, 0.0, 0.0, 11.0, 0.0, 0.0}, {47.0, 0.0, 0.0, -1.0, 0.0, 0.0}, {36.0, 0.0, 0.0, -15.0, 0.0, 0.0}, {-36.0, 0.0, 0.0, 20.0, 0.0, 0.0}, {-35.0, 0.0, 0.0, 19.0, 0.0, 0.0}, {-37.0, 0.0, 0.0, 19.0, 0.0, 0.0}, {32.0, 0.0, 0.0, -16.0, 0.0, 0.0}, {35.0, 0.0, 0.0, -14.0, 0.0, 0.0}, {32.0, 0.0, 0.0, -13.0, 0.0, 0.0}, {65.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {47.0, 0.0, 0.0, -1.0, 0.0, 0.0}, {32.0, 0.0, 0.0, -16.0, 0.0, 0.0}, {37.0, 0.0, 0.0, -16.0, 0.0, 0.0}, {-30.0, 0.0, 0.0, 15.0, 0.0, 0.0}, {-32.0, 0.0, 0.0, 16.0, 0.0, 0.0}, {-31.0, 0.0, 0.0, 13.0, 0.0, 0.0}, {37.0, 0.0, 0.0, -16.0, 0.0, 0.0}, {31.0, 0.0, 0.0, -13.0, 0.0, 0.0}, {49.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {32.0, 0.0, 0.0, -13.0, 0.0, 0.0}, {23.0, 0.0, 0.0, -12.0, 0.0, 0.0}, {-43.0, 0.0, 0.0, 18.0, 0.0, 0.0}, {26.0, 0.0, 0.0, -11.0, 0.0, 0.0}, {-32.0, 0.0, 0.0, 14.0, 0.0, 0.0}, {-29.0, 0.0, 0.0, 14.0, 0.0, 0.0}, {-27.0, 0.0, 0.0, 12.0, 0.0, 0.0}, {30.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-11.0, 0.0, 0.0, 5.0, 0.0, 0.0}, {-21.0, 0.0, 0.0, 10.0, 0.0, 0.0}, {-34.0, 0.0, 0.0, 15.0, 0.0, 0.0}, {-10.0, 0.0, 0.0, 6.0, 0.0, 0.0}, {-36.0, 0.0, 0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0.0, 0.0}, {6.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-6.0, 0.0, 0.0, 3.0, 0.0, 0.0}, {3.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {7.0, 0.0, 0.0, -4.0, 0.0, 0.0}, {4.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-5.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {5.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-6.0, 0.0, 0.0, 3.0, 0.0, 0.0}, {-6.0, 0.0, 0.0, 3.0, 0.0, 0.0}, {-4.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {10.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-4.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {7.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {7.0, 0.0, 0.0, -3.0, 0.0, 0.0}, {4.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {11.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {5.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-6.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {4.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {3.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {5.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-4.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {-4.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {4.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {3.0, 0.0, 0.0, -1.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 1.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 1.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 2.0, 0.0, 0.0}}; /* Planetary argument multipliers: L L' F D Om Me Ve E Ma Ju Sa Ur Ne pre */ static const short int napl_t[687][14]= { {0, 0, 0, 0, 0, 0, 0, 8, -16, 4, 5, 0, 0, 0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, 1, 0, 0, -2, 0, 3, 0, 0, 0, 0}, {0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {-1, 0, 2, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {-2, 0, 2, 2, 2, 0, 0, 2, 0, -2, 0, 0, 0, 0}, {0, 0, 2, 0, 2, 0, 2, -3, 0, 0, 0, 0, 0, 0}, {0, 0, 2, 0, 2, 0, 1, -1, 0, 0, 0, 0, 0, 0}, {0, 0, 2, 0, 2, 0, 0, 1, 0, -1, 0, 0, 0, 0}, {0, 0, 2, 0, 2, 0, 2, -2, 0, 0, 0, 0, 0, 0}, {-1, 0, 2, 2, 2, 0, 0, -1, 0, 1, 0, 0, 0, 0}, {1, 0, 2, 0, 2, 0, -1, 1, 0, 0, 0, 0, 0, 0}, {-1, 0, 2, 2, 2, 0, 0, 2, 0, -3, 0, 0, 0, 0}, {2, 0, 2, 0, 2, 0, 0, 2, 0, -3, 0, 0, 0, 0}, {1, 0, 2, 0, 2, 0, 0, -4, 8, -3, 0, 0, 0, 0}, {1, 0, 2, 0, 2, 0, 0, 4, -8, 3, 0, 0, 0, 0}, {1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 2, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {2, 0, 2, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {-1, 0, 2, 2, 2, 0, 0, 2, 0, -2, 0, 0, 0, 0}, {-1, 0, 2, 2, 2, 0, 3, -3, 0, 0, 0, 0, 0, 0}, {1, 0, 2, 0, 2, 0, 1, -1, 0, 0, 0, 0, 0, 0}, {0, 0, 2, 2, 2, 0, 0, 2, 0, -2, 0, 0, 0, 0}}; /* Planetary nutation coefficients, unit 1e-7 arcsec: longitude (sin, cos), obliquity (sin, cos) Each row of coefficients in 'cpl_t' belongs with the corresponding row of fundamental-argument multipliers in 'napl_t'. */ static const double cpl_t[687][4]= { {1440.0, 0.0, 0.0, 0.0}, {56.0, -117.0, -42.0, -40.0}, {125.0, -43.0, 0.0, -54.0}, {0.0, 5.0, 0.0, 0.0}, {3.0, -7.0, -3.0, 0.0}, {3.0, 0.0, 0.0, -2.0}, {-114.0, 0.0, 0.0, 61.0}, {-219.0, 89.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 0.0}, {-462.0, 1604.0, 0.0, 0.0}, {99.0, 0.0, 0.0, -53.0}, {-3.0, 0.0, 0.0, 2.0}, {0.0, 6.0, 2.0, 0.0}, {3.0, 0.0, 0.0, 0.0}, {-12.0, 0.0, 0.0, 0.0}, {14.0, -218.0, 117.0, 8.0}, {31.0, -481.0, -257.0, -17.0}, {-491.0, 128.0, 0.0, 0.0}, {-3084.0, 5123.0, 2735.0, 1647.0}, {-1444.0, 2409.0, -1286.0, -771.0}, {11.0, -24.0, -11.0, -9.0}, {26.0, -9.0, 0.0, 0.0}, {103.0, -60.0, 0.0, 0.0}, {0.0, -13.0, -7.0, 0.0}, {-26.0, -29.0, -16.0, 14.0}, {9.0, -27.0, -14.0, -5.0}, {12.0, 0.0, 0.0, -6.0}, {-7.0, 0.0, 0.0, 0.0}, {0.0, 24.0, 0.0, 0.0}, {284.0, 0.0, 0.0, -151.0}, {226.0, 101.0, 0.0, 0.0}, {0.0, -8.0, -2.0, 0.0}, {0.0, -6.0, -3.0, 0.0}, {5.0, 0.0, 0.0, -3.0}, {-41.0, 175.0, 76.0, 17.0}, {0.0, 15.0, 6.0, 0.0}, {425.0, 212.0, -133.0, 269.0}, {1200.0, 598.0, 319.0, -641.0}, {235.0, 334.0, 0.0, 0.0}, {11.0, -12.0, -7.0, -6.0}, {5.0, -6.0, 3.0, 3.0}, {-5.0, 0.0, 0.0, 3.0}, {6.0, 0.0, 0.0, -3.0}, {15.0, 0.0, 0.0, 0.0}, {13.0, 0.0, 0.0, -7.0}, {-6.0, -9.0, 0.0, 0.0}, {266.0, -78.0, 0.0, 0.0}, {-460.0, -435.0, -232.0, 246.0}, {0.0, 15.0, 7.0, 0.0}, {-3.0, 0.0, 0.0, 2.0}, {0.0, 131.0, 0.0, 0.0}, {4.0, 0.0, 0.0, 0.0}, {0.0, 3.0, 0.0, 0.0}, {0.0, 4.0, 2.0, 0.0}, {0.0, 3.0, 0.0, 0.0}, {-17.0, -19.0, -10.0, 9.0}, {-9.0, -11.0, 6.0, -5.0}, {-6.0, 0.0, 0.0, 3.0}, {-16.0, 8.0, 0.0, 0.0}, {0.0, 3.0, 0.0, 0.0}, {11.0, 24.0, 11.0, -5.0}, {-3.0, -4.0, -2.0, 1.0}, {3.0, 0.0, 0.0, -1.0}, {0.0, -8.0, -4.0, 0.0}, {0.0, 3.0, 0.0, 0.0}, {0.0, 5.0, 0.0, 0.0}, {0.0, 3.0, 2.0, 0.0}, {-6.0, 4.0, 2.0, 3.0}, {-3.0, -5.0, 0.0, 0.0}, {-5.0, 0.0, 0.0, 2.0}, {4.0, 24.0, 13.0, -2.0}, {-42.0, 20.0, 0.0, 0.0}, {-10.0, 233.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 1.0}, {78.0, -18.0, 0.0, 0.0}, {0.0, 3.0, 1.0, 0.0}, {0.0, -3.0, -1.0, 0.0}, {0.0, -4.0, -2.0, 1.0}, {0.0, -8.0, -4.0, -1.0}, {0.0, -5.0, 3.0, 0.0}, {-7.0, 0.0, 0.0, 3.0}, {-14.0, 8.0, 3.0, 6.0}, {0.0, 8.0, -4.0, 0.0}, {0.0, 19.0, 10.0, 0.0}, {45.0, -22.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 0.0}, {0.0, -3.0, 0.0, 0.0}, {0.0, 3.0, 0.0, 0.0}, {3.0, 5.0, 3.0, -2.0}, {89.0, -16.0, -9.0, -48.0}, {0.0, 3.0, 0.0, 0.0}, {-3.0, 7.0, 4.0, 2.0}, {-349.0, -62.0, 0.0, 0.0}, {-15.0, 22.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 0.0}, {-53.0, 0.0, 0.0, 0.0}, {5.0, 0.0, 0.0, -3.0}, {0.0, -8.0, 0.0, 0.0}, {15.0, -7.0, -4.0, -8.0}, {-3.0, 0.0, 0.0, 1.0}, {-21.0, -78.0, 0.0, 0.0}, {20.0, -70.0, -37.0, -11.0}, {0.0, 6.0, 3.0, 0.0}, {5.0, 3.0, 2.0, -2.0}, {-17.0, -4.0, -2.0, 9.0}, {0.0, 6.0, 3.0, 0.0}, {32.0, 15.0, -8.0, 17.0}, {174.0, 84.0, 45.0, -93.0}, {11.0, 56.0, 0.0, 0.0}, {-66.0, -12.0, -6.0, 35.0}, {47.0, 8.0, 4.0, -25.0}, {0.0, 8.0, 4.0, 0.0}, {10.0, -22.0, -12.0, -5.0}, {-3.0, 0.0, 0.0, 2.0}, {-24.0, 12.0, 0.0, 0.0}, {5.0, -6.0, 0.0, 0.0}, {3.0, 0.0, 0.0, -2.0}, {4.0, 3.0, 1.0, -2.0}, {0.0, 29.0, 15.0, 0.0}, {-5.0, -4.0, -2.0, 2.0}, {8.0, -3.0, -1.0, -5.0}, {0.0, -3.0, 0.0, 0.0}, {10.0, 0.0, 0.0, 0.0}, {3.0, 0.0, 0.0, -2.0}, {-5.0, 0.0, 0.0, 3.0}, {46.0, 66.0, 35.0, -25.0}, {-14.0, 7.0, 0.0, 0.0}, {0.0, 3.0, 2.0, 0.0}, {-5.0, 0.0, 0.0, 0.0}, {-68.0, -34.0, -18.0, 36.0}, {0.0, 14.0, 7.0, 0.0}, {10.0, -6.0, -3.0, -5.0}, {-5.0, -4.0, -2.0, 3.0}, {-3.0, 5.0, 2.0, 1.0}, {76.0, 17.0, 9.0, -41.0}, {84.0, 298.0, 159.0, -45.0}, {3.0, 0.0, 0.0, -1.0}, {-3.0, 0.0, 0.0, 2.0}, {-3.0, 0.0, 0.0, 1.0}, {-82.0, 292.0, 156.0, 44.0}, {-73.0, 17.0, 9.0, 39.0}, {-9.0, -16.0, 0.0, 0.0}, {3.0, 0.0, -1.0, -2.0}, {-3.0, 0.0, 0.0, 0.0}, {-9.0, -5.0, -3.0, 5.0}, {-439.0, 0.0, 0.0, 0.0}, {57.0, -28.0, -15.0, -30.0}, {0.0, -6.0, -3.0, 0.0}, {-4.0, 0.0, 0.0, 2.0}, {-40.0, 57.0, 30.0, 21.0}, {23.0, 7.0, 3.0, -13.0}, {273.0, 80.0, 43.0, -146.0}, {-449.0, 430.0, 0.0, 0.0}, {-8.0, -47.0, -25.0, 4.0}, {6.0, 47.0, 25.0, -3.0}, {0.0, 23.0, 13.0, 0.0}, {-3.0, 0.0, 0.0, 2.0}, {3.0, -4.0, -2.0, -2.0}, {-48.0, -110.0, -59.0, 26.0}, {51.0, 114.0, 61.0, -27.0}, {-133.0, 0.0, 0.0, 57.0}, {0.0, 4.0, 0.0, 0.0}, {-21.0, -6.0, -3.0, 11.0}, {0.0, -3.0, -1.0, 0.0}, {-11.0, -21.0, -11.0, 6.0}, {-18.0, -436.0, -233.0, 9.0}, {35.0, -7.0, 0.0, 0.0}, {0.0, 5.0, 3.0, 0.0}, {11.0, -3.0, -1.0, -6.0}, {-5.0, -3.0, -1.0, 3.0}, {-53.0, -9.0, -5.0, 28.0}, {0.0, 3.0, 2.0, 1.0}, {4.0, 0.0, 0.0, -2.0}, {0.0, -4.0, 0.0, 0.0}, {-50.0, 194.0, 103.0, 27.0}, {-13.0, 52.0, 28.0, 7.0}, {-91.0, 248.0, 0.0, 0.0}, {6.0, 49.0, 26.0, -3.0}, {-6.0, -47.0, -25.0, 3.0}, {0.0, 5.0, 3.0, 0.0}, {52.0, 23.0, 10.0, -23.0}, {-3.0, 0.0, 0.0, 1.0}, {0.0, 5.0, 3.0, 0.0}, {-4.0, 0.0, 0.0, 0.0}, {-4.0, 8.0, 3.0, 2.0}, {10.0, 0.0, 0.0, 0.0}, {3.0, 0.0, 0.0, -2.0}, {0.0, 8.0, 4.0, 0.0}, {0.0, 8.0, 4.0, 1.0}, {-4.0, 0.0, 0.0, 0.0}, {-4.0, 0.0, 0.0, 0.0}, {-8.0, 4.0, 2.0, 4.0}, {8.0, -4.0, -2.0, -4.0}, {0.0, 15.0, 7.0, 0.0}, {-138.0, 0.0, 0.0, 0.0}, {0.0, -7.0, -3.0, 0.0}, {0.0, -7.0, -3.0, 0.0}, {54.0, 0.0, 0.0, -29.0}, {0.0, 10.0, 4.0, 0.0}, {-7.0, 0.0, 0.0, 3.0}, {-37.0, 35.0, 19.0, 20.0}, {0.0, 4.0, 0.0, 0.0}, {-4.0, 9.0, 0.0, 0.0}, {8.0, 0.0, 0.0, -4.0}, {-9.0, -14.0, -8.0, 5.0}, {-3.0, -9.0, -5.0, 3.0}, {-145.0, 47.0, 0.0, 0.0}, {-10.0, 40.0, 21.0, 5.0}, {11.0, -49.0, -26.0, -7.0}, {-2150.0, 0.0, 0.0, 932.0}, {-12.0, 0.0, 0.0, 5.0}, {85.0, 0.0, 0.0, -37.0}, {4.0, 0.0, 0.0, -2.0}, {3.0, 0.0, 0.0, -2.0}, {-86.0, 153.0, 0.0, 0.0}, {-6.0, 9.0, 5.0, 3.0}, {9.0, -13.0, -7.0, -5.0}, {-8.0, 12.0, 6.0, 4.0}, {-51.0, 0.0, 0.0, 22.0}, {-11.0, -268.0, -116.0, 5.0}, {0.0, 12.0, 5.0, 0.0}, {0.0, 7.0, 3.0, 0.0}, {31.0, 6.0, 3.0, -17.0}, {140.0, 27.0, 14.0, -75.0}, {57.0, 11.0, 6.0, -30.0}, {-14.0, -39.0, 0.0, 0.0}, {0.0, -6.0, -2.0, 0.0}, {4.0, 15.0, 8.0, -2.0}, {0.0, 4.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 1.0}, {0.0, 11.0, 5.0, 0.0}, {9.0, 6.0, 0.0, 0.0}, {-4.0, 10.0, 4.0, 2.0}, {5.0, 3.0, 0.0, 0.0}, {16.0, 0.0, 0.0, -9.0}, {-3.0, 0.0, 0.0, 0.0}, {0.0, 3.0, 2.0, -1.0}, {7.0, 0.0, 0.0, -3.0}, {-25.0, 22.0, 0.0, 0.0}, {42.0, 223.0, 119.0, -22.0}, {-27.0, -143.0, -77.0, 14.0}, {9.0, 49.0, 26.0, -5.0}, {-1166.0, 0.0, 0.0, 505.0}, {-5.0, 0.0, 0.0, 2.0}, {-6.0, 0.0, 0.0, 3.0}, {-8.0, 0.0, 1.0, 4.0}, {0.0, -4.0, 0.0, 0.0}, {117.0, 0.0, 0.0, -63.0}, {-4.0, 8.0, 4.0, 2.0}, {3.0, 0.0, 0.0, -2.0}, {-5.0, 0.0, 0.0, 2.0}, {0.0, 31.0, 0.0, 0.0}, {-5.0, 0.0, 1.0, 3.0}, {4.0, 0.0, 0.0, -2.0}, {-4.0, 0.0, 0.0, 2.0}, {-24.0, -13.0, -6.0, 10.0}, {3.0, 0.0, 0.0, 0.0}, {0.0, -32.0, -17.0, 0.0}, {8.0, 12.0, 5.0, -3.0}, {3.0, 0.0, 0.0, -1.0}, {7.0, 13.0, 0.0, 0.0}, {-3.0, 16.0, 0.0, 0.0}, {50.0, 0.0, 0.0, -27.0}, {0.0, -5.0, -3.0, 0.0}, {13.0, 0.0, 0.0, 0.0}, {0.0, 5.0, 3.0, 1.0}, {24.0, 5.0, 2.0, -11.0}, {5.0, -11.0, -5.0, -2.0}, {30.0, -3.0, -2.0, -16.0}, {18.0, 0.0, 0.0, -9.0}, {8.0, 614.0, 0.0, 0.0}, {3.0, -3.0, -1.0, -2.0}, {6.0, 17.0, 9.0, -3.0}, {-3.0, -9.0, -5.0, 2.0}, {0.0, 6.0, 3.0, -1.0}, {-127.0, 21.0, 9.0, 55.0}, {3.0, 5.0, 0.0, 0.0}, {-6.0, -10.0, -4.0, 3.0}, {5.0, 0.0, 0.0, 0.0}, {16.0, 9.0, 4.0, -7.0}, {3.0, 0.0, 0.0, -2.0}, {0.0, 22.0, 0.0, 0.0}, {0.0, 19.0, 10.0, 0.0}, {7.0, 0.0, 0.0, -4.0}, {0.0, -5.0, -2.0, 0.0}, {0.0, 3.0, 1.0, 0.0}, {-9.0, 3.0, 1.0, 4.0}, {17.0, 0.0, 0.0, -7.0}, {0.0, -3.0, -2.0, -1.0}, {-20.0, 34.0, 0.0, 0.0}, {-10.0, 0.0, 1.0, 5.0}, {-4.0, 0.0, 0.0, 2.0}, {22.0, -87.0, 0.0, 0.0}, {-4.0, 0.0, 0.0, 2.0}, {-3.0, -6.0, -2.0, 1.0}, {-16.0, -3.0, -1.0, 7.0}, {0.0, -3.0, -2.0, 0.0}, {4.0, 0.0, 0.0, 0.0}, {-68.0, 39.0, 0.0, 0.0}, {27.0, 0.0, 0.0, -14.0}, {0.0, -4.0, 0.0, 0.0}, {-25.0, 0.0, 0.0, 0.0}, {-12.0, -3.0, -2.0, 6.0}, {3.0, 0.0, 0.0, -1.0}, {3.0, 66.0, 29.0, -1.0}, {490.0, 0.0, 0.0, -213.0}, {-22.0, 93.0, 49.0, 12.0}, {-7.0, 28.0, 15.0, 4.0}, {-3.0, 13.0, 7.0, 2.0}, {-46.0, 14.0, 0.0, 0.0}, {-5.0, 0.0, 0.0, 0.0}, {2.0, 1.0, 0.0, 0.0}, {0.0, -3.0, 0.0, 0.0}, {-28.0, 0.0, 0.0, 15.0}, {5.0, 0.0, 0.0, -2.0}, {0.0, 3.0, 0.0, 0.0}, {-11.0, 0.0, 0.0, 5.0}, {0.0, 3.0, 1.0, 0.0}, {-3.0, 0.0, 0.0, 1.0}, {25.0, 106.0, 57.0, -13.0}, {5.0, 21.0, 11.0, -3.0}, {1485.0, 0.0, 0.0, 0.0}, {-7.0, -32.0, -17.0, 4.0}, {0.0, 5.0, 3.0, 0.0}, {-6.0, -3.0, -2.0, 3.0}, {30.0, -6.0, -2.0, -13.0}, {-4.0, 4.0, 0.0, 0.0}, {-19.0, 0.0, 0.0, 10.0}, {0.0, 4.0, 2.0, -1.0}, {0.0, 3.0, 0.0, 0.0}, {4.0, 0.0, 0.0, -2.0}, {0.0, -3.0, -1.0, 0.0}, {-3.0, 0.0, 0.0, 0.0}, {5.0, 3.0, 1.0, -2.0}, {0.0, 11.0, 0.0, 0.0}, {118.0, 0.0, 0.0, -52.0}, {0.0, -5.0, -3.0, 0.0}, {-28.0, 36.0, 0.0, 0.0}, {5.0, -5.0, 0.0, 0.0}, {14.0, -59.0, -31.0, -8.0}, {0.0, 9.0, 5.0, 1.0}, {-458.0, 0.0, 0.0, 198.0}, {0.0, -45.0, -20.0, 0.0}, {9.0, 0.0, 0.0, -5.0}, {0.0, -3.0, 0.0, 0.0}, {0.0, -4.0, -2.0, -1.0}, {11.0, 0.0, 0.0, -6.0}, {6.0, 0.0, 0.0, -2.0}, {-16.0, 23.0, 0.0, 0.0}, {0.0, -4.0, -2.0, 0.0}, {-5.0, 0.0, 0.0, 2.0}, {-166.0, 269.0, 0.0, 0.0}, {15.0, 0.0, 0.0, -8.0}, {10.0, 0.0, 0.0, -4.0}, {-78.0, 45.0, 0.0, 0.0}, {0.0, -5.0, -2.0, 0.0}, {7.0, 0.0, 0.0, -4.0}, {-5.0, 328.0, 0.0, 0.0}, {3.0, 0.0, 0.0, -2.0}, {5.0, 0.0, 0.0, -2.0}, {0.0, 3.0, 1.0, 0.0}, {-3.0, 0.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 0.0}, {0.0, -4.0, -2.0, 0.0}, {-1223.0, -26.0, 0.0, 0.0}, {0.0, 7.0, 3.0, 0.0}, {3.0, 0.0, 0.0, 0.0}, {0.0, 3.0, 2.0, 0.0}, {-6.0, 20.0, 0.0, 0.0}, {-368.0, 0.0, 0.0, 0.0}, {-75.0, 0.0, 0.0, 0.0}, {11.0, 0.0, 0.0, -6.0}, {3.0, 0.0, 0.0, -2.0}, {-3.0, 0.0, 0.0, 1.0}, {-13.0, -30.0, 0.0, 0.0}, {21.0, 3.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 1.0}, {-4.0, 0.0, 0.0, 2.0}, {8.0, -27.0, 0.0, 0.0}, {-19.0, -11.0, 0.0, 0.0}, {-4.0, 0.0, 0.0, 2.0}, {0.0, 5.0, 2.0, 0.0}, {-6.0, 0.0, 0.0, 2.0}, {-8.0, 0.0, 0.0, 0.0}, {-1.0, 0.0, 0.0, 0.0}, {-14.0, 0.0, 0.0, 6.0}, {6.0, 0.0, 0.0, 0.0}, {-74.0, 0.0, 0.0, 32.0}, {0.0, -3.0, -1.0, 0.0}, {4.0, 0.0, 0.0, -2.0}, {8.0, 11.0, 0.0, 0.0}, {0.0, 3.0, 2.0, 0.0}, {-262.0, 0.0, 0.0, 114.0}, {0.0, -4.0, 0.0, 0.0}, {-7.0, 0.0, 0.0, 4.0}, {0.0, -27.0, -12.0, 0.0}, {-19.0, -8.0, -4.0, 8.0}, {202.0, 0.0, 0.0, -87.0}, {-8.0, 35.0, 19.0, 5.0}, {0.0, 4.0, 2.0, 0.0}, {16.0, -5.0, 0.0, 0.0}, {5.0, 0.0, 0.0, -3.0}, {0.0, -3.0, 0.0, 0.0}, {1.0, 0.0, 0.0, 0.0}, {-35.0, -48.0, -21.0, 15.0}, {-3.0, -5.0, -2.0, 1.0}, {6.0, 0.0, 0.0, -3.0}, {3.0, 0.0, 0.0, -1.0}, {0.0, -5.0, 0.0, 0.0}, {12.0, 55.0, 29.0, -6.0}, {0.0, 5.0, 3.0, 0.0}, {-598.0, 0.0, 0.0, 0.0}, {-3.0, -13.0, -7.0, 1.0}, {-5.0, -7.0, -3.0, 2.0}, {3.0, 0.0, 0.0, -1.0}, {5.0, -7.0, 0.0, 0.0}, {4.0, 0.0, 0.0, -2.0}, {16.0, -6.0, 0.0, 0.0}, {8.0, -3.0, 0.0, 0.0}, {8.0, -31.0, -16.0, -4.0}, {0.0, 3.0, 1.0, 0.0}, {113.0, 0.0, 0.0, -49.0}, {0.0, -24.0, -10.0, 0.0}, {4.0, 0.0, 0.0, -2.0}, {27.0, 0.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 1.0}, {0.0, -4.0, -2.0, 0.0}, {5.0, 0.0, 0.0, -2.0}, {0.0, -3.0, 0.0, 0.0}, {-13.0, 0.0, 0.0, 6.0}, {5.0, 0.0, 0.0, -2.0}, {-18.0, -10.0, -4.0, 8.0}, {-4.0, -28.0, 0.0, 0.0}, {-5.0, 6.0, 3.0, 2.0}, {-3.0, 0.0, 0.0, 1.0}, {-5.0, -9.0, -4.0, 2.0}, {17.0, 0.0, 0.0, -7.0}, {11.0, 4.0, 0.0, 0.0}, {0.0, -6.0, -2.0, 0.0}, {83.0, 15.0, 0.0, 0.0}, {-4.0, 0.0, 0.0, 2.0}, {0.0, -114.0, -49.0, 0.0}, {117.0, 0.0, 0.0, -51.0}, {-5.0, 19.0, 10.0, 2.0}, {-3.0, 0.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 2.0}, {0.0, -3.0, -1.0, 0.0}, {3.0, 0.0, 0.0, 0.0}, {0.0, -6.0, -2.0, 0.0}, {393.0, 3.0, 0.0, 0.0}, {-4.0, 21.0, 11.0, 2.0}, {-6.0, 0.0, -1.0, 3.0}, {-3.0, 8.0, 4.0, 1.0}, {8.0, 0.0, 0.0, 0.0}, {18.0, -29.0, -13.0, -8.0}, {8.0, 34.0, 18.0, -4.0}, {89.0, 0.0, 0.0, 0.0}, {3.0, 12.0, 6.0, -1.0}, {54.0, -15.0, -7.0, -24.0}, {0.0, 3.0, 0.0, 0.0}, {3.0, 0.0, 0.0, -1.0}, {0.0, 35.0, 0.0, 0.0}, {-154.0, -30.0, -13.0, 67.0}, {15.0, 0.0, 0.0, 0.0}, {0.0, 4.0, 2.0, 0.0}, {0.0, 9.0, 0.0, 0.0}, {80.0, -71.0, -31.0, -35.0}, {0.0, -20.0, -9.0, 0.0}, {11.0, 5.0, 2.0, -5.0}, {61.0, -96.0, -42.0, -27.0}, {14.0, 9.0, 4.0, -6.0}, {-11.0, -6.0, -3.0, 5.0}, {0.0, -3.0, -1.0, 0.0}, {123.0, -415.0, -180.0, -53.0}, {0.0, 0.0, 0.0, -35.0}, {-5.0, 0.0, 0.0, 0.0}, {7.0, -32.0, -17.0, -4.0}, {0.0, -9.0, -5.0, 0.0}, {0.0, -4.0, 2.0, 0.0}, {-89.0, 0.0, 0.0, 38.0}, {0.0, -86.0, -19.0, -6.0}, {0.0, 0.0, -19.0, 6.0}, {-123.0, -416.0, -180.0, 53.0}, {0.0, -3.0, -1.0, 0.0}, {12.0, -6.0, -3.0, -5.0}, {-13.0, 9.0, 4.0, 6.0}, {0.0, -15.0, -7.0, 0.0}, {3.0, 0.0, 0.0, -1.0}, {-62.0, -97.0, -42.0, 27.0}, {-11.0, 5.0, 2.0, 5.0}, {0.0, -19.0, -8.0, 0.0}, {-3.0, 0.0, 0.0, 1.0}, {0.0, 4.0, 2.0, 0.0}, {0.0, 3.0, 0.0, 0.0}, {0.0, 4.0, 2.0, 0.0}, {-85.0, -70.0, -31.0, 37.0}, {163.0, -12.0, -5.0, -72.0}, {-63.0, -16.0, -7.0, 28.0}, {-21.0, -32.0, -14.0, 9.0}, {0.0, -3.0, -1.0, 0.0}, {3.0, 0.0, 0.0, -2.0}, {0.0, 8.0, 0.0, 0.0}, {3.0, 10.0, 4.0, -1.0}, {3.0, 0.0, 0.0, -1.0}, {0.0, -7.0, -3.0, 0.0}, {0.0, -4.0, -2.0, 0.0}, {6.0, 19.0, 0.0, 0.0}, {5.0, -173.0, -75.0, -2.0}, {0.0, -7.0, -3.0, 0.0}, {7.0, -12.0, -5.0, -3.0}, {-3.0, 0.0, 0.0, 2.0}, {3.0, -4.0, -2.0, -1.0}, {74.0, 0.0, 0.0, -32.0}, {-3.0, 12.0, 6.0, 2.0}, {26.0, -14.0, -6.0, -11.0}, {19.0, 0.0, 0.0, -8.0}, {6.0, 24.0, 13.0, -3.0}, {83.0, 0.0, 0.0, 0.0}, {0.0, -10.0, -5.0, 0.0}, {11.0, -3.0, -1.0, -5.0}, {3.0, 0.0, 1.0, -1.0}, {3.0, 0.0, 0.0, -1.0}, {-4.0, 0.0, 0.0, 0.0}, {5.0, -23.0, -12.0, -3.0}, {-339.0, 0.0, 0.0, 147.0}, {0.0, -10.0, -5.0, 0.0}, {5.0, 0.0, 0.0, 0.0}, {3.0, 0.0, 0.0, -1.0}, {0.0, -4.0, -2.0, 0.0}, {18.0, -3.0, 0.0, 0.0}, {9.0, -11.0, -5.0, -4.0}, {-8.0, 0.0, 0.0, 4.0}, {3.0, 0.0, 0.0, -1.0}, {0.0, 9.0, 0.0, 0.0}, {6.0, -9.0, -4.0, -2.0}, {-4.0, -12.0, 0.0, 0.0}, {67.0, -91.0, -39.0, -29.0}, {30.0, -18.0, -8.0, -13.0}, {0.0, 0.0, 0.0, 0.0}, {0.0, -114.0, -50.0, 0.0}, {0.0, 0.0, 0.0, 23.0}, {517.0, 16.0, 7.0, -224.0}, {0.0, -7.0, -3.0, 0.0}, {143.0, -3.0, -1.0, -62.0}, {29.0, 0.0, 0.0, -13.0}, {-4.0, 0.0, 0.0, 2.0}, {-6.0, 0.0, 0.0, 3.0}, {5.0, 12.0, 5.0, -2.0}, {-25.0, 0.0, 0.0, 11.0}, {-3.0, 0.0, 0.0, 1.0}, {0.0, 4.0, 2.0, 0.0}, {-22.0, 12.0, 5.0, 10.0}, {50.0, 0.0, 0.0, -22.0}, {0.0, 7.0, 4.0, 0.0}, {0.0, 3.0, 1.0, 0.0}, {-4.0, 4.0, 2.0, 2.0}, {-5.0, -11.0, -5.0, 2.0}, {0.0, 4.0, 2.0, 0.0}, {4.0, 17.0, 9.0, -2.0}, {59.0, 0.0, 0.0, 0.0}, {0.0, -4.0, -2.0, 0.0}, {-8.0, 0.0, 0.0, 4.0}, {-3.0, 0.0, 0.0, 0.0}, {4.0, -15.0, -8.0, -2.0}, {370.0, -8.0, 0.0, -160.0}, {0.0, 0.0, -3.0, 0.0}, {0.0, 3.0, 1.0, 0.0}, {-6.0, 3.0, 1.0, 3.0}, {0.0, 6.0, 0.0, 0.0}, {-10.0, 0.0, 0.0, 4.0}, {0.0, 9.0, 4.0, 0.0}, {4.0, 17.0, 7.0, -2.0}, {34.0, 0.0, 0.0, -15.0}, {0.0, 5.0, 3.0, 0.0}, {-5.0, 0.0, 0.0, 2.0}, {-37.0, -7.0, -3.0, 16.0}, {3.0, 13.0, 7.0, -2.0}, {40.0, 0.0, 0.0, 0.0}, {0.0, -3.0, -2.0, 0.0}, {-184.0, -3.0, -1.0, 80.0}, {-3.0, 0.0, 0.0, 1.0}, {-3.0, 0.0, 0.0, 0.0}, {0.0, -10.0, -6.0, -1.0}, {31.0, -6.0, 0.0, -13.0}, {-3.0, -32.0, -14.0, 1.0}, {-7.0, 0.0, 0.0, 3.0}, {0.0, -8.0, -4.0, 0.0}, {3.0, -4.0, 0.0, 0.0}, {0.0, 4.0, 0.0, 0.0}, {0.0, 3.0, 1.0, 0.0}, {19.0, -23.0, -10.0, 2.0}, {0.0, 0.0, 0.0, -10.0}, {0.0, 3.0, 2.0, 0.0}, {0.0, 9.0, 5.0, -1.0}, {28.0, 0.0, 0.0, 0.0}, {0.0, -7.0, -4.0, 0.0}, {8.0, -4.0, 0.0, -4.0}, {0.0, 0.0, -2.0, 0.0}, {0.0, 3.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 1.0}, {-9.0, 0.0, 1.0, 4.0}, {3.0, 12.0, 5.0, -1.0}, {17.0, -3.0, -1.0, 0.0}, {0.0, 7.0, 4.0, 0.0}, {19.0, 0.0, 0.0, 0.0}, {0.0, -5.0, -3.0, 0.0}, {14.0, -3.0, 0.0, -1.0}, {0.0, 0.0, -1.0, 0.0}, {0.0, 0.0, 0.0, -5.0}, {0.0, 5.0, 3.0, 0.0}, {13.0, 0.0, 0.0, 0.0}, {0.0, -3.0, -2.0, 0.0}, {2.0, 9.0, 4.0, 3.0}, {0.0, 0.0, 0.0, -4.0}, {8.0, 0.0, 0.0, 0.0}, {0.0, 4.0, 2.0, 0.0}, {6.0, 0.0, 0.0, -3.0}, {6.0, 0.0, 0.0, 0.0}, {0.0, 3.0, 1.0, 0.0}, {5.0, 0.0, 0.0, -2.0}, {3.0, 0.0, 0.0, -1.0}, {-3.0, 0.0, 0.0, 0.0}, {6.0, 0.0, 0.0, 0.0}, {7.0, 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0.0, 0.0, -4.0}, {-6.0, 0.0, 0.0, 3.0}, {-3.0, 0.0, 0.0, 1.0}, {3.0, 0.0, 0.0, -1.0}, {-3.0, 0.0, 0.0, 1.0}, {-5.0, 0.0, 0.0, 2.0}, {24.0, -12.0, -5.0, -11.0}, {0.0, 3.0, 1.0, 0.0}, {0.0, 3.0, 1.0, 0.0}, {0.0, 3.0, 2.0, 0.0}, {-24.0, -12.0, -5.0, 10.0}, {4.0, 0.0, -1.0, -2.0}, {13.0, 0.0, 0.0, -6.0}, {7.0, 0.0, 0.0, -3.0}, {3.0, 0.0, 0.0, -1.0}, {3.0, 0.0, 0.0, -1.0}}; /* Interval between fundamental epoch J2000.0 and given date. */ t= ( ( jd_high - T0 ) + jd_low ) / 36525.0; /* Compute fundamental arguments from Simon et al. (1994), in radians. */ fund_args( t, a ); /* ** Luni-solar nutation. ** */ /* Initialize the nutation values. */ dp= 0.0; de= 0.0; /* Summation of luni-solar nutation series (in reverse order). */ for ( i= 677; i >= 0; i-- ) { /* Argument and functions. */ arg= fmod( (double)nals_t[i][0] * a[0] + (double)nals_t[i][1] * a[1] + (double)nals_t[i][2] * a[2] + (double)nals_t[i][3] * a[3] + (double)nals_t[i][4] * a[4], TWOPI ); sarg= sin( arg ); carg= cos( arg ); /* Term. */ dp+= ( cls_t[i][0] + cls_t[i][1] * t ) * sarg + cls_t[i][2] * carg; de+= ( cls_t[i][3] + cls_t[i][4] * t ) * carg + cls_t[i][5] * sarg; } /* Convert from 0.1 microarcsec units to radians. */ factor= 1.0e-7 * ASEC2RAD; dpsils= dp * factor; depsls= de * factor; /* ** Planetary nutation. ** */ /* Mean anomaly of the Moon. */ al= fmod( 2.35555598 + 8328.6914269554 * t, TWOPI ); /* Mean anomaly of the Sun. */ alsu= fmod( 6.24006013 + 628.301955 * t, TWOPI ); /* Mean argument of the latitude of the Moon. */ af= fmod( 1.627905234 + 8433.466158131 * t, TWOPI ); /* Mean elongation of the Moon from the Sun. */ ad= fmod( 5.198466741 + 7771.3771468121 * t, TWOPI ); /* Mean longitude of the ascending node of the Moon. */ aom= fmod( 2.18243920 - 33.757045 * t, TWOPI ); /* General accumulated precession in longitude. */ apa= ( 0.02438175 + 0.00000538691 * t ) * t; /* Planetary longitudes, Mercury through Neptune (Souchay et al. 1999). */ alme= fmod( 4.402608842 + 2608.7903141574 * t, TWOPI ); alve= fmod( 3.176146697 + 1021.3285546211 * t, TWOPI ); alea= fmod( 1.753470314 + 628.3075849991 * t, TWOPI ); alma= fmod( 6.203480913 + 334.0612426700 * t, TWOPI ); alju= fmod( 0.599546497 + 52.9690962641 * t, TWOPI ); alsa= fmod( 0.874016757 + 21.3299104960 * t, TWOPI ); alur= fmod( 5.481293871 + 7.4781598567 * t, TWOPI ); alne= fmod( 5.321159000 + 3.8127774000 * t, TWOPI ); /* Initialize the nutation values. */ dp= 0.0; de= 0.0; /* Summation of planetary nutation series (in reverse order). */ for ( i= 686; i >= 0; i-- ) { /* Argument and functions. */ arg= fmod( (double)napl_t[i][0] * al + (double)napl_t[i][1] * alsu + (double)napl_t[i][2] * af + (double)napl_t[i][3] * ad + (double)napl_t[i][4] * aom + (double)napl_t[i][5] * alme + (double)napl_t[i][6] * alve + (double)napl_t[i][7] * alea + (double)napl_t[i][8] * alma + (double)napl_t[i][9] * alju + (double)napl_t[i][10] * alsa + (double)napl_t[i][11] * alur + (double)napl_t[i][12] * alne + (double)napl_t[i][13] * apa, TWOPI ); sarg= sin( arg ); carg= cos( arg ); /* Term. */ dp+= cpl_t[i][0] * sarg + cpl_t[i][1] * carg; de+= cpl_t[i][2] * sarg + cpl_t[i][3] * carg; } dpsipl= dp * factor; depspl= de * factor; /* Total: Add planetary and luni-solar components. */ *dpsi= dpsipl + dpsils; *deps= depspl + depsls; return; } /********iau2000b */ void iau2000b( double jd_high, double jd_low, double *dpsi, double *deps ) /* ------------------------------------------------------------------------ PURPOSE: To compute the forced nutation of the non-rigid Earth based on the IAU 2000B precession/nutation model. REFERENCES: McCarthy, D. and Luzum, B. (2003). "An Abridged Model of the Precession & Nutation of the Celestial Pole," Celestial Mechanics and Dynamical Astronomy, Volume 85, Issue 1, Jan. 2003, p. 37. (IAU 2000B) IERS Conventions (2003), Chapter 5. INPUT ARGUMENTS: jd_high (double) High-order part of TT Julian date. jd_low (double) Low-order part of TT Julian date. OUTPUT ARGUMENTS: *dpsi (double) Nutation (luni-solar + planetary) in longitude, in radians. *deps (double) Nutation (luni-solar + planetary) in obliquity, in radians. RETURNED VALUE: None. GLOBALS USED: T0, ASEC2RAD, TWOPI FUNCTIONS CALLED: fmod math.h sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/09-03/JAB (USNO/AA) V1.1/12-10/JAB (USNO/AA): Implement static storage class for const arrays. V1.2/03-11/WKP (USNO/AA): Added braces to 2-D array initialization to quiet gcc warnings. NOTES: 1. IAU 2000B reproduces the IAU 2000A model to a precision of 1 milliarcsecond in the interval 1995-2020. ------------------------------------------------------------------------ */ { short int i; /* Planetary nutation (arcsec). These fixed terms account for the omission of the long-period planetary terms in the truncated model. */ double dpplan= -0.000135; double deplan= 0.000388; double t, el, elp, f, d, om, arg, dp, de, sarg, carg, factor, dpsils, depsls, dpsipl, depspl; /* Luni-Solar argument multipliers: L L' F D Om */ static const short int nals_t[77][5]= { {0, 0, 0, 0, 1}, {0, 0, 2, -2, 2}, {0, 0, 2, 0, 2}, {0, 0, 0, 0, 2}, {0, 1, 0, 0, 0}, {0, 1, 2, -2, 2}, {1, 0, 0, 0, 0}, {0, 0, 2, 0, 1}, {1, 0, 2, 0, 2}, {0, -1, 2, -2, 2}, {0, 0, 2, -2, 1}, {-1, 0, 2, 0, 2}, {-1, 0, 0, 2, 0}, {1, 0, 0, 0, 1}, {-1, 0, 0, 0, 1}, {-1, 0, 2, 2, 2}, {1, 0, 2, 0, 1}, {-2, 0, 2, 0, 1}, {0, 0, 0, 2, 0}, {0, 0, 2, 2, 2}, {0, -2, 2, -2, 2}, {-2, 0, 0, 2, 0}, {2, 0, 2, 0, 2}, {1, 0, 2, -2, 2}, {-1, 0, 2, 0, 1}, {2, 0, 0, 0, 0}, {0, 0, 2, 0, 0}, {0, 1, 0, 0, 1}, {-1, 0, 0, 2, 1}, {0, 2, 2, -2, 2}, {0, 0, -2, 2, 0}, {1, 0, 0, -2, 1}, {0, -1, 0, 0, 1}, {-1, 0, 2, 2, 1}, {0, 2, 0, 0, 0}, {1, 0, 2, 2, 2}, {-2, 0, 2, 0, 0}, {0, 1, 2, 0, 2}, {0, 0, 2, 2, 1}, {0, -1, 2, 0, 2}, {0, 0, 0, 2, 1}, {1, 0, 2, -2, 1}, {2, 0, 2, -2, 2}, {-2, 0, 0, 2, 1}, {2, 0, 2, 0, 1}, {0, -1, 2, -2, 1}, {0, 0, 0, -2, 1}, {-1, -1, 0, 2, 0}, {2, 0, 0, -2, 1}, {1, 0, 0, 2, 0}, {0, 1, 2, -2, 1}, {1, -1, 0, 0, 0}, {-2, 0, 2, 0, 2}, {3, 0, 2, 0, 2}, {0, -1, 0, 2, 0}, {1, -1, 2, 0, 2}, {0, 0, 0, 1, 0}, {-1, -1, 2, 2, 2}, {-1, 0, 2, 0, 0}, {0, -1, 2, 2, 2}, {-2, 0, 0, 0, 1}, {1, 1, 2, 0, 2}, {2, 0, 0, 0, 1}, {-1, 1, 0, 1, 0}, {1, 1, 0, 0, 0}, {1, 0, 2, 0, 0}, {-1, 0, 2, -2, 1}, {1, 0, 0, 0, 2}, {-1, 0, 0, 1, 0}, {0, 0, 2, 1, 2}, {-1, 0, 2, 4, 2}, {-1, 1, 0, 1, 1}, {0, -2, 2, -2, 1}, {1, 0, 2, 2, 1}, {-2, 0, 2, 2, 2}, {-1, 0, 0, 0, 2}, {1, 1, 2, -2, 2}}; /* Luni-Solar nutation coefficients, unit 1e-7 arcsec: longitude (sin, t*sin, cos), obliquity (cos, t*cos, sin) Each row of coefficients in 'cls_t' belongs with the corresponding row of fundamental-argument multipliers in 'nals_t'. */ static const double cls_t[77][6]= { {-172064161.0, -174666.0, 33386.0, 92052331.0, 9086.0, 15377.0}, {-13170906.0, -1675.0, -13696.0, 5730336.0, -3015.0, -4587.0}, {-2276413.0, -234.0, 2796.0, 978459.0, -485.0, 1374.0}, {2074554.0, 207.0, -698.0, -897492.0, 470.0, -291.0}, {1475877.0, -3633.0, 11817.0, 73871.0, -184.0, -1924.0}, {-516821.0, 1226.0, -524.0, 224386.0, -677.0, -174.0}, {711159.0, 73.0, -872.0, -6750.0, 0.0, 358.0}, {-387298.0, -367.0, 380.0, 200728.0, 18.0, 318.0}, {-301461.0, -36.0, 816.0, 129025.0, -63.0, 367.0}, {215829.0, -494.0, 111.0, -95929.0, 299.0, 132.0}, {128227.0, 137.0, 181.0, -68982.0, -9.0, 39.0}, {123457.0, 11.0, 19.0, -53311.0, 32.0, -4.0}, {156994.0, 10.0, -168.0, -1235.0, 0.0, 82.0}, {63110.0, 63.0, 27.0, -33228.0, 0.0, -9.0}, {-57976.0, -63.0, -189.0, 31429.0, 0.0, -75.0}, {-59641.0, -11.0, 149.0, 25543.0, -11.0, 66.0}, {-51613.0, -42.0, 129.0, 26366.0, 0.0, 78.0}, {45893.0, 50.0, 31.0, -24236.0, -10.0, 20.0}, {63384.0, 11.0, -150.0, -1220.0, 0.0, 29.0}, {-38571.0, -1.0, 158.0, 16452.0, -11.0, 68.0}, {32481.0, 0.0, 0.0, -13870.0, 0.0, 0.0}, {-47722.0, 0.0, -18.0, 477.0, 0.0, -25.0}, {-31046.0, -1.0, 131.0, 13238.0, -11.0, 59.0}, {28593.0, 0.0, -1.0, -12338.0, 10.0, -3.0}, {20441.0, 21.0, 10.0, -10758.0, 0.0, -3.0}, {29243.0, 0.0, -74.0, -609.0, 0.0, 13.0}, {25887.0, 0.0, -66.0, -550.0, 0.0, 11.0}, {-14053.0, -25.0, 79.0, 8551.0, -2.0, -45.0}, {15164.0, 10.0, 11.0, -8001.0, 0.0, -1.0}, {-15794.0, 72.0, -16.0, 6850.0, -42.0, -5.0}, {21783.0, 0.0, 13.0, -167.0, 0.0, 13.0}, {-12873.0, -10.0, -37.0, 6953.0, 0.0, -14.0}, {-12654.0, 11.0, 63.0, 6415.0, 0.0, 26.0}, {-10204.0, 0.0, 25.0, 5222.0, 0.0, 15.0}, {16707.0, -85.0, -10.0, 168.0, -1.0, 10.0}, {-7691.0, 0.0, 44.0, 3268.0, 0.0, 19.0}, {-11024.0, 0.0, -14.0, 104.0, 0.0, 2.0}, {7566.0, -21.0, -11.0, -3250.0, 0.0, -5.0}, {-6637.0, -11.0, 25.0, 3353.0, 0.0, 14.0}, {-7141.0, 21.0, 8.0, 3070.0, 0.0, 4.0}, {-6302.0, -11.0, 2.0, 3272.0, 0.0, 4.0}, {5800.0, 10.0, 2.0, -3045.0, 0.0, -1.0}, {6443.0, 0.0, -7.0, -2768.0, 0.0, -4.0}, {-5774.0, -11.0, -15.0, 3041.0, 0.0, -5.0}, {-5350.0, 0.0, 21.0, 2695.0, 0.0, 12.0}, {-4752.0, -11.0, -3.0, 2719.0, 0.0, -3.0}, {-4940.0, -11.0, -21.0, 2720.0, 0.0, -9.0}, {7350.0, 0.0, -8.0, -51.0, 0.0, 4.0}, {4065.0, 0.0, 6.0, -2206.0, 0.0, 1.0}, {6579.0, 0.0, -24.0, -199.0, 0.0, 2.0}, {3579.0, 0.0, 5.0, -1900.0, 0.0, 1.0}, {4725.0, 0.0, -6.0, -41.0, 0.0, 3.0}, {-3075.0, 0.0, -2.0, 1313.0, 0.0, -1.0}, {-2904.0, 0.0, 15.0, 1233.0, 0.0, 7.0}, {4348.0, 0.0, -10.0, -81.0, 0.0, 2.0}, {-2878.0, 0.0, 8.0, 1232.0, 0.0, 4.0}, {-4230.0, 0.0, 5.0, -20.0, 0.0, -2.0}, {-2819.0, 0.0, 7.0, 1207.0, 0.0, 3.0}, {-4056.0, 0.0, 5.0, 40.0, 0.0, -2.0}, {-2647.0, 0.0, 11.0, 1129.0, 0.0, 5.0}, {-2294.0, 0.0, -10.0, 1266.0, 0.0, -4.0}, {2481.0, 0.0, -7.0, -1062.0, 0.0, -3.0}, {2179.0, 0.0, -2.0, -1129.0, 0.0, -2.0}, {3276.0, 0.0, 1.0, -9.0, 0.0, 0.0}, {-3389.0, 0.0, 5.0, 35.0, 0.0, -2.0}, {3339.0, 0.0, -13.0, -107.0, 0.0, 1.0}, {-1987.0, 0.0, -6.0, 1073.0, 0.0, -2.0}, {-1981.0, 0.0, 0.0, 854.0, 0.0, 0.0}, {4026.0, 0.0, -353.0, -553.0, 0.0, -139.0}, {1660.0, 0.0, -5.0, -710.0, 0.0, -2.0}, {-1521.0, 0.0, 9.0, 647.0, 0.0, 4.0}, {1314.0, 0.0, 0.0, -700.0, 0.0, 0.0}, {-1283.0, 0.0, 0.0, 672.0, 0.0, 0.0}, {-1331.0, 0.0, 8.0, 663.0, 0.0, 4.0}, {1383.0, 0.0, -2.0, -594.0, 0.0, -2.0}, {1405.0, 0.0, 4.0, -610.0, 0.0, 2.0}, {1290.0, 0.0, 0.0, -556.0, 0.0, 0.0}}; /* Interval between fundamental epoch J2000.0 and given date. */ t= ( ( jd_high - T0 ) + jd_low ) / 36525.0; /* ** Luni-solar nutation. ** Fundamental (Delaunay) arguments from Simon et al. (1994), in radians. */ /* Mean anomaly of the Moon. */ el= fmod( 485868.249036 + t * 1717915923.2178, ASEC360 ) * ASEC2RAD; /* Mean anomaly of the Sun. */ elp= fmod( 1287104.79305 + t * 129596581.0481, ASEC360 ) * ASEC2RAD; /* Mean argument of the latitude of the Moon. */ f= fmod( 335779.526232 + t * 1739527262.8478, ASEC360 ) * ASEC2RAD; /* Mean elongation of the Moon from the Sun. */ d= fmod( 1072260.70369 + t * 1602961601.2090, ASEC360 ) * ASEC2RAD; /* Mean longitude of the ascending node of the Moon. */ om= fmod( 450160.398036 - t * 6962890.5431, ASEC360 ) * ASEC2RAD; /* Initialize the nutation values. */ dp= 0.0; de= 0.0; /* Summation of luni-solar nutation series (in reverse order). */ for ( i= 76; i >= 0; i-- ) { /* Argument and functions. */ arg= fmod( (double)nals_t[i][0] * el + (double)nals_t[i][1] * elp + (double)nals_t[i][2] * f + (double)nals_t[i][3] * d + (double)nals_t[i][4] * om, TWOPI ); sarg= sin( arg ); carg= cos( arg ); /* Term. */ dp+= ( cls_t[i][0] + cls_t[i][1] * t ) * sarg + cls_t[i][2] * carg; de+= ( cls_t[i][3] + cls_t[i][4] * t ) * carg + cls_t[i][5] * sarg; } /* Convert from 0.1 microarcsec units to radians. */ factor= 1.0e-7 * ASEC2RAD; dpsils= dp * factor; depsls= de * factor; /* ** Planetary nutation. ** Fixed terms to allow for long-period nutation, in radians. */ dpsipl= dpplan * ASEC2RAD; depspl= deplan * ASEC2RAD; /* Total: Add planetary and luni-solar components. */ *dpsi= dpsipl + dpsils; *deps= depspl + depsls; return; } /********nu2000k */ void nu2000k( double jd_high, double jd_low, double *dpsi, double *deps ) /* ------------------------------------------------------------------------ PURPOSE: To compute the forced nutation of the non-rigid Earth: Model NU2000K. This model is a modified version of IAU 2000A, which has been truncated for speed of execution, and uses Simon et al. (1994) fundamental arguments throughout. NU2000K agrees with IAU 2000A at the 0.1 milliarcsecond level from 1700 to 2300. REFERENCES: IERS Conventions (2003), Chapter 5. Simon et al. (1994) Astronomy and Astrophysics 282, 663-683, esp. Sections 3.4-3.5. INPUT ARGUMENTS: jd_high (double) High-order part of TT Julian date. jd_low (double) Low-order part of TT Julian date. OUTPUT ARGUMENTS: *dpsi (double) Nutation (luni-solar + planetary) in longitude, in radians. *deps (double) Nutation (luni-solar + planetary) in obliquity, in radians. RETURNED VALUE: None. GLOBALS USED: T0, ASEC2RAD, TWOPI FUNCTIONS CALLED: fund_args novas.c fmod math.h sin math.h cos math.h VER./DATE/ PROGRAMMER: V1.0/03-04/JAB (USNO/AA) V1.1/12-10/JAB (USNO/AA): Implement static storage class for const arrays. V1.2/03-11/WKP (USNO/AA): Added braces to 2-D array initialization to quiet gcc warnings. NOTES: 1. NU2000K was compared to IAU 2000A over six centuries (1700- 2300). The average error in dpsi is 20 microarcseconds, with 98% of the errors < 60 microarcseconds; the average error in deleps is 8 microarcseconds, with 100% of the errors < 60 microarcseconds. 2. NU2000K was developed by G. Kaplan (USNO) in March 2004. 3. This function is the "C" version of NOVAS Fortran routine 'nu2000k'. ------------------------------------------------------------------------ */ { short int i; double t, a[5], dp, de, arg, sarg, carg, factor, dpsils, depsls, alme, alve, alea, alma, alju, alsa, alur, alne, apa, dpsipl, depspl; /* Luni-Solar argument multipliers: L L' F D Om */ static const short int nals_t[323][5]= { {0, 0, 0, 0, 1}, {0, 0, 2, -2, 2}, {0, 0, 2, 0, 2}, {0, 0, 0, 0, 2}, {0, 1, 0, 0, 0}, {0, 1, 2, -2, 2}, {1, 0, 0, 0, 0}, {0, 0, 2, 0, 1}, {1, 0, 2, 0, 2}, {0, -1, 2, -2, 2}, {0, 0, 2, -2, 1}, {-1, 0, 2, 0, 2}, {-1, 0, 0, 2, 0}, {1, 0, 0, 0, 1}, {-1, 0, 0, 0, 1}, {-1, 0, 2, 2, 2}, {1, 0, 2, 0, 1}, {-2, 0, 2, 0, 1}, {0, 0, 0, 2, 0}, {0, 0, 2, 2, 2}, {0, -2, 2, -2, 2}, {-2, 0, 0, 2, 0}, {2, 0, 2, 0, 2}, {1, 0, 2, -2, 2}, {-1, 0, 2, 0, 1}, {2, 0, 0, 0, 0}, {0, 0, 2, 0, 0}, {0, 1, 0, 0, 1}, {-1, 0, 0, 2, 1}, {0, 2, 2, -2, 2}, {0, 0, -2, 2, 0}, {1, 0, 0, -2, 1}, {0, -1, 0, 0, 1}, {-1, 0, 2, 2, 1}, {0, 2, 0, 0, 0}, {1, 0, 2, 2, 2}, {-2, 0, 2, 0, 0}, {0, 1, 2, 0, 2}, {0, 0, 2, 2, 1}, {0, -1, 2, 0, 2}, {0, 0, 0, 2, 1}, {1, 0, 2, -2, 1}, {2, 0, 2, -2, 2}, {-2, 0, 0, 2, 1}, {2, 0, 2, 0, 1}, {0, -1, 2, -2, 1}, {0, 0, 0, -2, 1}, {-1, -1, 0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, {-1, -1, 2, 0, 2}, {0, 0, 4, -2, 1}, {3, 0, 2, -2, 1}, {-2, -1, 0, 2, 1}, {1, 0, 0, -1, 1}, {0, -2, 0, 2, 0}, {-2, 0, 0, 4, 1}, {-3, 0, 0, 0, 1}, {1, 1, 2, 2, 2}, {0, 0, 2, 4, 1}, {3, 0, 2, 2, 2}, {-1, 1, 2, -2, 1}, {2, 0, 0, -4, 1}, {0, 0, 0, -2, 2}, {2, 0, 2, -4, 1}, {-1, 1, 0, 2, 1}, {0, 0, 2, -1, 1}, {0, -2, 2, 2, 2}, {2, 0, 0, 2, 1}, {4, 0, 2, -2, 2}, {2, 0, 0, -2, 2}, {0, 2, 0, 0, 1}, {1, 0, 0, -4, 1}, {0, 2, 2, -2, 1}, {-3, 0, 0, 4, 0}, {-1, 1, 2, 0, 1}, {-1, -1, 0, 4, 0}, {-1, -2, 2, 2, 2}, {-2, -1, 2, 4, 2}, {1, -1, 2, 2, 1}, {-2, 1, 0, 2, 0}, {-2, 1, 2, 0, 1}, {2, 1, 0, -2, 1}, {-3, 0, 2, 0, 1}, {-2, 0, 2, -2, 1}, {-1, 1, 0, 2, 2}, {0, -1, 2, -1, 2}, {-1, 0, 4, -2, 2}, {0, -2, 2, 0, 2}, {-1, 0, 2, 1, 2}, {2, 0, 0, 0, 2}, {0, 0, 2, 0, 3}, {-2, 0, 4, 0, 2}, {-1, 0, -2, 0, 1}, {-1, 1, 2, 2, 1}, {3, 0, 0, 0, 1}, {-1, 0, 2, 3, 2}, {2, -1, 2, 0, 1}, {0, 1, 2, 2, 1}, {0, -1, 2, 4, 2}, {2, -1, 2, 2, 2}, {0, 2, -2, 2, 0}, {-1, -1, 2, -1, 1}, {0, -2, 0, 0, 1}, {1, 0, 2, -4, 2}, {1, -1, 0, -2, 1}, {-1, -1, 2, 0, 1}, {1, -1, 2, -2, 2}, {-2, -1, 0, 4, 0}, {-1, 0, 0, 3, 0}, {-2, -1, 2, 2, 2}, {0, 2, 2, 0, 2}, {1, 1, 0, 2, 0}, {2, 0, 2, -1, 2}, {1, 0, 2, 1, 1}, {4, 0, 0, 0, 0}, {2, 1, 2, 0, 1}, {3, -1, 2, 0, 2}, {-2, 2, 0, 2, 1}, {1, 0, 2, -3, 1}, {1, 1, 2, -4, 1}, {-1, -1, 2, -2, 1}, {0, -1, 0, -1, 1}, {0, -1, 0, -2, 1}, {-2, 0, 0, 0, 2}, {-2, 0, -2, 2, 0}, {-1, 0, -2, 4, 0}, {1, -2, 0, 0, 0}, {0, 1, 0, 1, 1}, {-1, 2, 0, 2, 0}, {1, -1, 2, -2, 1}, {1, 2, 2, -2, 2}, {2, -1, 2, -2, 2}, {1, 0, 2, -1, 1}, {2, 1, 2, -2, 1}, {-2, 0, 0, -2, 1}, {1, -2, 2, 0, 2}, {0, 1, 2, 1, 1}, {1, 0, 4, -2, 1}, {-2, 0, 4, 2, 2}, {1, 1, 2, 1, 2}, {1, 0, 0, 4, 0}, {1, 0, 2, 2, 0}, {2, 0, 2, 1, 2}, {3, 1, 2, 0, 2}, {4, 0, 2, 0, 1}, {-2, -1, 2, 0, 0}, {0, 1, -2, 2, 1}, {1, 0, -2, 1, 0}, {2, -1, 0, -2, 1}, {-1, 0, 2, -1, 2}, {1, 0, 2, -3, 2}, {0, 1, 2, -2, 3}, {-1, 0, -2, 2, 1}, {0, 0, 2, -4, 2}, {2, 0, 2, -4, 2}, {0, 0, 4, -4, 4}, {0, 0, 4, -4, 2}, {-2, 0, 0, 3, 0}, {1, 0, -2, 2, 1}, {-3, 0, 2, 2, 2}, {-2, 0, 2, 2, 0}, {2, -1, 0, 0, 1}, {1, 1, 0, 1, 0}, {0, 1, 4, -2, 2}, {-1, 1, 0, -2, 1}, {0, 0, 0, -4, 1}, {1, -1, 0, 2, 1}, {1, 1, 0, 2, 1}, {-1, 2, 2, 2, 2}, {3, 1, 2, -2, 2}, {0, -1, 0, 4, 0}, {2, -1, 0, 2, 0}, {0, 0, 4, 0, 1}, {2, 0, 4, -2, 2}, {-1, -1, 2, 4, 1}, {1, 0, 0, 4, 1}, {1, -2, 2, 2, 2}, {0, 0, 2, 3, 2}, {-1, 1, 2, 4, 2}, {3, 0, 0, 2, 0}, {-1, 0, 4, 2, 2}, {-2, 0, 2, 6, 2}, {-1, 0, 2, 6, 2}, {1, 1, -2, 1, 0}, {-1, 0, 0, 1, 2}, {-1, -1, 0, 1, 0}, {-2, 0, 0, 1, 0}, {0, 0, -2, 1, 0}, {1, -1, -2, 2, 0}, {1, 2, 0, 0, 0}, {3, 0, 2, 0, 0}, {0, -1, 1, -1, 1}, {-1, 0, 1, 0, 3}, {-1, 0, 1, 0, 2}, {-1, 0, 1, 0, 1}, {-1, 0, 1, 0, 0}, {0, 0, 1, 0, 2}, {0, 0, 1, 0, 1}, {0, 0, 1, 0, 0}}; /* Luni-Solar nutation coefficients, unit 1e-7 arcsec: longitude (sin, t*sin, cos), obliquity (cos, t*cos, sin) Each row of coefficients in 'cls_t' belongs with the corresponding row of fundamental-argument multipliers in 'nals_t'. */ static const double cls_t[323][6]= { {-172064161.0, -174666.0, 33386.0, 92052331.0, 9086.0, 15377.0}, {-13170906.0, -1675.0, -13696.0, 5730336.0, -3015.0, -4587.0}, {-2276413.0, -234.0, 2796.0, 978459.0, -485.0, 1374.0}, {2074554.0, 207.0, -698.0, -897492.0, 470.0, -291.0}, {1475877.0, -3633.0, 11817.0, 73871.0, -184.0, -1924.0}, {-516821.0, 1226.0, -524.0, 224386.0, -677.0, -174.0}, {711159.0, 73.0, -872.0, -6750.0, 0.0, 358.0}, {-387298.0, -367.0, 380.0, 200728.0, 18.0, 318.0}, {-301461.0, -36.0, 816.0, 129025.0, -63.0, 367.0}, {215829.0, -494.0, 111.0, -95929.0, 299.0, 132.0}, {128227.0, 137.0, 181.0, -68982.0, -9.0, 39.0}, {123457.0, 11.0, 19.0, -53311.0, 32.0, -4.0}, {156994.0, 10.0, -168.0, -1235.0, 0.0, 82.0}, {63110.0, 63.0, 27.0, -33228.0, 0.0, -9.0}, {-57976.0, -63.0, -189.0, 31429.0, 0.0, -75.0}, {-59641.0, -11.0, 149.0, 25543.0, -11.0, 66.0}, {-51613.0, -42.0, 129.0, 26366.0, 0.0, 78.0}, {45893.0, 50.0, 31.0, -24236.0, -10.0, 20.0}, {63384.0, 11.0, -150.0, -1220.0, 0.0, 29.0}, {-38571.0, -1.0, 158.0, 16452.0, -11.0, 68.0}, {32481.0, 0.0, 0.0, -13870.0, 0.0, 0.0}, {-47722.0, 0.0, -18.0, 477.0, 0.0, -25.0}, {-31046.0, -1.0, 131.0, 13238.0, -11.0, 59.0}, {28593.0, 0.0, -1.0, -12338.0, 10.0, -3.0}, {20441.0, 21.0, 10.0, -10758.0, 0.0, -3.0}, {29243.0, 0.0, -74.0, -609.0, 0.0, 13.0}, {25887.0, 0.0, -66.0, -550.0, 0.0, 11.0}, {-14053.0, -25.0, 79.0, 8551.0, -2.0, -45.0}, {15164.0, 10.0, 11.0, -8001.0, 0.0, -1.0}, {-15794.0, 72.0, -16.0, 6850.0, -42.0, -5.0}, {21783.0, 0.0, 13.0, -167.0, 0.0, 13.0}, {-12873.0, -10.0, -37.0, 6953.0, 0.0, -14.0}, {-12654.0, 11.0, 63.0, 6415.0, 0.0, 26.0}, {-10204.0, 0.0, 25.0, 5222.0, 0.0, 15.0}, {16707.0, -85.0, -10.0, 168.0, -1.0, 10.0}, {-7691.0, 0.0, 44.0, 3268.0, 0.0, 19.0}, {-11024.0, 0.0, -14.0, 104.0, 0.0, 2.0}, {7566.0, -21.0, -11.0, -3250.0, 0.0, -5.0}, {-6637.0, -11.0, 25.0, 3353.0, 0.0, 14.0}, {-7141.0, 21.0, 8.0, 3070.0, 0.0, 4.0}, {-6302.0, -11.0, 2.0, 3272.0, 0.0, 4.0}, {5800.0, 10.0, 2.0, -3045.0, 0.0, -1.0}, {6443.0, 0.0, -7.0, -2768.0, 0.0, -4.0}, {-5774.0, -11.0, -15.0, 3041.0, 0.0, -5.0}, {-5350.0, 0.0, 21.0, 2695.0, 0.0, 12.0}, {-4752.0, -11.0, -3.0, 2719.0, 0.0, -3.0}, {-4940.0, -11.0, -21.0, 2720.0, 0.0, -9.0}, {7350.0, 0.0, -8.0, -51.0, 0.0, 4.0}, {4065.0, 0.0, 6.0, -2206.0, 0.0, 1.0}, {6579.0, 0.0, -24.0, -199.0, 0.0, 2.0}, {3579.0, 0.0, 5.0, -1900.0, 0.0, 1.0}, {4725.0, 0.0, -6.0, -41.0, 0.0, 3.0}, {-3075.0, 0.0, -2.0, 1313.0, 0.0, -1.0}, {-2904.0, 0.0, 15.0, 1233.0, 0.0, 7.0}, {4348.0, 0.0, -10.0, -81.0, 0.0, 2.0}, {-2878.0, 0.0, 8.0, 1232.0, 0.0, 4.0}, {-4230.0, 0.0, 5.0, -20.0, 0.0, -2.0}, {-2819.0, 0.0, 7.0, 1207.0, 0.0, 3.0}, {-4056.0, 0.0, 5.0, 40.0, 0.0, -2.0}, {-2647.0, 0.0, 11.0, 1129.0, 0.0, 5.0}, {-2294.0, 0.0, -10.0, 1266.0, 0.0, -4.0}, {2481.0, 0.0, -7.0, -1062.0, 0.0, -3.0}, {2179.0, 0.0, -2.0, -1129.0, 0.0, -2.0}, {3276.0, 0.0, 1.0, -9.0, 0.0, 0.0}, {-3389.0, 0.0, 5.0, 35.0, 0.0, -2.0}, {3339.0, 0.0, -13.0, -107.0, 0.0, 1.0}, {-1987.0, 0.0, -6.0, 1073.0, 0.0, -2.0}, {-1981.0, 0.0, 0.0, 854.0, 0.0, 0.0}, {4026.0, 0.0, -353.0, -553.0, 0.0, -139.0}, {1660.0, 0.0, -5.0, -710.0, 0.0, -2.0}, {-1521.0, 0.0, 9.0, 647.0, 0.0, 4.0}, {1314.0, 0.0, 0.0, -700.0, 0.0, 0.0}, {-1283.0, 0.0, 0.0, 672.0, 0.0, 0.0}, {-1331.0, 0.0, 8.0, 663.0, 0.0, 4.0}, {1383.0, 0.0, -2.0, -594.0, 0.0, -2.0}, {1405.0, 0.0, 4.0, -610.0, 0.0, 2.0}, {1290.0, 0.0, 0.0, -556.0, 0.0, 0.0}, {-1214.0, 0.0, 5.0, 518.0, 0.0, 2.0}, {1146.0, 0.0, -3.0, -490.0, 0.0, -1.0}, {1019.0, 0.0, -1.0, -527.0, 0.0, -1.0}, {-1100.0, 0.0, 9.0, 465.0, 0.0, 4.0}, {-970.0, 0.0, 2.0, 496.0, 0.0, 1.0}, {1575.0, 0.0, -6.0, -50.0, 0.0, 0.0}, {934.0, 0.0, -3.0, -399.0, 0.0, -1.0}, {922.0, 0.0, -1.0, -395.0, 0.0, -1.0}, {815.0, 0.0, -1.0, -422.0, 0.0, -1.0}, {834.0, 0.0, 2.0, -440.0, 0.0, 1.0}, {1248.0, 0.0, 0.0, -170.0, 0.0, 1.0}, {1338.0, 0.0, -5.0, -39.0, 0.0, 0.0}, {716.0, 0.0, -2.0, -389.0, 0.0, -1.0}, {1282.0, 0.0, -3.0, -23.0, 0.0, 1.0}, {742.0, 0.0, 1.0, -391.0, 0.0, 0.0}, {1020.0, 0.0, -25.0, -495.0, 0.0, -10.0}, {715.0, 0.0, -4.0, -326.0, 0.0, 2.0}, {-666.0, 0.0, -3.0, 369.0, 0.0, -1.0}, {-667.0, 0.0, 1.0, 346.0, 0.0, 1.0}, {-704.0, 0.0, 0.0, 304.0, 0.0, 0.0}, {-694.0, 0.0, 5.0, 294.0, 0.0, 2.0}, {-1014.0, 0.0, -1.0, 4.0, 0.0, -1.0}, {-585.0, 0.0, -2.0, 316.0, 0.0, -1.0}, {-949.0, 0.0, 1.0, 8.0, 0.0, -1.0}, {-595.0, 0.0, 0.0, 258.0, 0.0, 0.0}, {528.0, 0.0, 0.0, -279.0, 0.0, 0.0}, {-590.0, 0.0, 4.0, 252.0, 0.0, 2.0}, {570.0, 0.0, -2.0, -244.0, 0.0, -1.0}, {-502.0, 0.0, 3.0, 250.0, 0.0, 2.0}, {-875.0, 0.0, 1.0, 29.0, 0.0, 0.0}, {-492.0, 0.0, -3.0, 275.0, 0.0, -1.0}, {535.0, 0.0, -2.0, -228.0, 0.0, -1.0}, {-467.0, 0.0, 1.0, 240.0, 0.0, 1.0}, {591.0, 0.0, 0.0, -253.0, 0.0, 0.0}, {-453.0, 0.0, -1.0, 244.0, 0.0, -1.0}, {766.0, 0.0, 1.0, 9.0, 0.0, 0.0}, {-446.0, 0.0, 2.0, 225.0, 0.0, 1.0}, {-488.0, 0.0, 2.0, 207.0, 0.0, 1.0}, {-468.0, 0.0, 0.0, 201.0, 0.0, 0.0}, {-421.0, 0.0, 1.0, 216.0, 0.0, 1.0}, {463.0, 0.0, 0.0, -200.0, 0.0, 0.0}, {-673.0, 0.0, 2.0, 14.0, 0.0, 0.0}, {658.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-438.0, 0.0, 0.0, 188.0, 0.0, 0.0}, {-390.0, 0.0, 0.0, 205.0, 0.0, 0.0}, {639.0, -11.0, -2.0, -19.0, 0.0, 0.0}, {412.0, 0.0, -2.0, -176.0, 0.0, -1.0}, {-361.0, 0.0, 0.0, 189.0, 0.0, 0.0}, {360.0, 0.0, -1.0, -185.0, 0.0, -1.0}, {588.0, 0.0, -3.0, -24.0, 0.0, 0.0}, {-578.0, 0.0, 1.0, 5.0, 0.0, 0.0}, {-396.0, 0.0, 0.0, 171.0, 0.0, 0.0}, {565.0, 0.0, -1.0, -6.0, 0.0, 0.0}, {-335.0, 0.0, -1.0, 184.0, 0.0, -1.0}, {357.0, 0.0, 1.0, -154.0, 0.0, 0.0}, {321.0, 0.0, 1.0, -174.0, 0.0, 0.0}, {-301.0, 0.0, -1.0, 162.0, 0.0, 0.0}, {-334.0, 0.0, 0.0, 144.0, 0.0, 0.0}, {493.0, 0.0, -2.0, -15.0, 0.0, 0.0}, {494.0, 0.0, -2.0, -19.0, 0.0, 0.0}, {337.0, 0.0, -1.0, -143.0, 0.0, -1.0}, {280.0, 0.0, -1.0, -144.0, 0.0, 0.0}, {309.0, 0.0, 1.0, -134.0, 0.0, 0.0}, {-263.0, 0.0, 2.0, 131.0, 0.0, 1.0}, {253.0, 0.0, 1.0, -138.0, 0.0, 0.0}, {245.0, 0.0, 0.0, -128.0, 0.0, 0.0}, {416.0, 0.0, -2.0, -17.0, 0.0, 0.0}, {-229.0, 0.0, 0.0, 128.0, 0.0, 0.0}, {231.0, 0.0, 0.0, -120.0, 0.0, 0.0}, {-259.0, 0.0, 2.0, 109.0, 0.0, 1.0}, {375.0, 0.0, -1.0, -8.0, 0.0, 0.0}, {252.0, 0.0, 0.0, -108.0, 0.0, 0.0}, {-245.0, 0.0, 1.0, 104.0, 0.0, 0.0}, {243.0, 0.0, -1.0, -104.0, 0.0, 0.0}, {208.0, 0.0, 1.0, -112.0, 0.0, 0.0}, {199.0, 0.0, 0.0, -102.0, 0.0, 0.0}, {-208.0, 0.0, 1.0, 105.0, 0.0, 0.0}, {335.0, 0.0, -2.0, -14.0, 0.0, 0.0}, {-325.0, 0.0, 1.0, 7.0, 0.0, 0.0}, {-187.0, 0.0, 0.0, 96.0, 0.0, 0.0}, {197.0, 0.0, -1.0, -100.0, 0.0, 0.0}, {-192.0, 0.0, 2.0, 94.0, 0.0, 1.0}, {-188.0, 0.0, 0.0, 83.0, 0.0, 0.0}, {276.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-286.0, 0.0, 1.0, 6.0, 0.0, 0.0}, {186.0, 0.0, -1.0, -79.0, 0.0, 0.0}, {-219.0, 0.0, 0.0, 43.0, 0.0, 0.0}, {276.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {-153.0, 0.0, -1.0, 84.0, 0.0, 0.0}, {-156.0, 0.0, 0.0, 81.0, 0.0, 0.0}, {-154.0, 0.0, 1.0, 78.0, 0.0, 0.0}, {-174.0, 0.0, 1.0, 75.0, 0.0, 0.0}, {-163.0, 0.0, 2.0, 69.0, 0.0, 1.0}, {-228.0, 0.0, 0.0, 1.0, 0.0, 0.0}, {91.0, 0.0, -4.0, -54.0, 0.0, -2.0}, {175.0, 0.0, 0.0, -75.0, 0.0, 0.0}, {-159.0, 0.0, 0.0, 69.0, 0.0, 0.0}, {141.0, 0.0, 0.0, -72.0, 0.0, 0.0}, {147.0, 0.0, 0.0, -75.0, 0.0, 0.0}, {-132.0, 0.0, 0.0, 69.0, 0.0, 0.0}, {159.0, 0.0, -28.0, -54.0, 0.0, 11.0}, {213.0, 0.0, 0.0, -4.0, 0.0, 0.0}, {123.0, 0.0, 0.0, -64.0, 0.0, 0.0}, {-118.0, 0.0, -1.0, 66.0, 0.0, 0.0}, {144.0, 0.0, -1.0, -61.0, 0.0, 0.0}, {-121.0, 0.0, 1.0, 60.0, 0.0, 0.0}, {-134.0, 0.0, 1.0, 56.0, 0.0, 1.0}, {-105.0, 0.0, 0.0, 57.0, 0.0, 0.0}, {-102.0, 0.0, 0.0, 56.0, 0.0, 0.0}, {120.0, 0.0, 0.0, -52.0, 0.0, 0.0}, {101.0, 0.0, 0.0, -54.0, 0.0, 0.0}, {-113.0, 0.0, 0.0, 59.0, 0.0, 0.0}, {-106.0, 0.0, 0.0, 61.0, 0.0, 0.0}, {-129.0, 0.0, 1.0, 55.0, 0.0, 0.0}, {-114.0, 0.0, 0.0, 57.0, 0.0, 0.0}, {113.0, 0.0, -1.0, -49.0, 0.0, 0.0}, {-102.0, 0.0, 0.0, 44.0, 0.0, 0.0}, {-94.0, 0.0, 0.0, 51.0, 0.0, 0.0}, {-100.0, 0.0, -1.0, 56.0, 0.0, 0.0}, {87.0, 0.0, 0.0, -47.0, 0.0, 0.0}, {161.0, 0.0, 0.0, -1.0, 0.0, 0.0}, {96.0, 0.0, 0.0, -50.0, 0.0, 0.0}, {151.0, 0.0, -1.0, -5.0, 0.0, 0.0}, {-104.0, 0.0, 0.0, 44.0, 0.0, 0.0}, {-110.0, 0.0, 0.0, 48.0, 0.0, 0.0}, {-100.0, 0.0, 1.0, 50.0, 0.0, 0.0}, {92.0, 0.0, -5.0, 12.0, 0.0, -2.0}, {82.0, 0.0, 0.0, -45.0, 0.0, 0.0}, {82.0, 0.0, 0.0, -45.0, 0.0, 0.0}, {-78.0, 0.0, 0.0, 41.0, 0.0, 0.0}, {-77.0, 0.0, 0.0, 43.0, 0.0, 0.0}, {2.0, 0.0, 0.0, 54.0, 0.0, 0.0}, {94.0, 0.0, 0.0, -40.0, 0.0, 0.0}, {-93.0, 0.0, 0.0, 40.0, 0.0, 0.0}, {-83.0, 0.0, 10.0, 40.0, 0.0, -2.0}, {83.0, 0.0, 0.0, -36.0, 0.0, 0.0}, {-91.0, 0.0, 0.0, 39.0, 0.0, 0.0}, {128.0, 0.0, 0.0, -1.0, 0.0, 0.0}, {-79.0, 0.0, 0.0, 34.0, 0.0, 0.0}, {-83.0, 0.0, 0.0, 47.0, 0.0, 0.0}, {84.0, 0.0, 0.0, -44.0, 0.0, 0.0}, {83.0, 0.0, 0.0, -43.0, 0.0, 0.0}, {91.0, 0.0, 0.0, -39.0, 0.0, 0.0}, {-77.0, 0.0, 0.0, 39.0, 0.0, 0.0}, {84.0, 0.0, 0.0, -43.0, 0.0, 0.0}, {-92.0, 0.0, 1.0, 39.0, 0.0, 0.0}, {-92.0, 0.0, 1.0, 39.0, 0.0, 0.0}, {-94.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {68.0, 0.0, 0.0, -36.0, 0.0, 0.0}, {-61.0, 0.0, 0.0, 32.0, 0.0, 0.0}, {71.0, 0.0, 0.0, -31.0, 0.0, 0.0}, {62.0, 0.0, 0.0, -34.0, 0.0, 0.0}, {-63.0, 0.0, 0.0, 33.0, 0.0, 0.0}, {-73.0, 0.0, 0.0, 32.0, 0.0, 0.0}, {115.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-103.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {63.0, 0.0, 0.0, -28.0, 0.0, 0.0}, {74.0, 0.0, 0.0, -32.0, 0.0, 0.0}, {-103.0, 0.0, -3.0, 3.0, 0.0, -1.0}, {-69.0, 0.0, 0.0, 30.0, 0.0, 0.0}, {57.0, 0.0, 0.0, -29.0, 0.0, 0.0}, {94.0, 0.0, 0.0, -4.0, 0.0, 0.0}, {64.0, 0.0, 0.0, -33.0, 0.0, 0.0}, {-63.0, 0.0, 0.0, 26.0, 0.0, 0.0}, {-38.0, 0.0, 0.0, 20.0, 0.0, 0.0}, {-43.0, 0.0, 0.0, 24.0, 0.0, 0.0}, {-45.0, 0.0, 0.0, 23.0, 0.0, 0.0}, {47.0, 0.0, 0.0, -24.0, 0.0, 0.0}, {-48.0, 0.0, 0.0, 25.0, 0.0, 0.0}, {45.0, 0.0, 0.0, -26.0, 0.0, 0.0}, {56.0, 0.0, 0.0, -25.0, 0.0, 0.0}, {88.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {-75.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {85.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {49.0, 0.0, 0.0, -26.0, 0.0, 0.0}, {-74.0, 0.0, -3.0, -1.0, 0.0, -1.0}, {-39.0, 0.0, 0.0, 21.0, 0.0, 0.0}, {45.0, 0.0, 0.0, -20.0, 0.0, 0.0}, {51.0, 0.0, 0.0, -22.0, 0.0, 0.0}, {-40.0, 0.0, 0.0, 21.0, 0.0, 0.0}, {41.0, 0.0, 0.0, -21.0, 0.0, 0.0}, {-42.0, 0.0, 0.0, 24.0, 0.0, 0.0}, {-51.0, 0.0, 0.0, 22.0, 0.0, 0.0}, {-42.0, 0.0, 0.0, 22.0, 0.0, 0.0}, {39.0, 0.0, 0.0, -21.0, 0.0, 0.0}, {46.0, 0.0, 0.0, -18.0, 0.0, 0.0}, {-53.0, 0.0, 0.0, 22.0, 0.0, 0.0}, {82.0, 0.0, 0.0, -4.0, 0.0, 0.0}, {81.0, 0.0, -1.0, -4.0, 0.0, 0.0}, {47.0, 0.0, 0.0, -19.0, 0.0, 0.0}, {53.0, 0.0, 0.0, -23.0, 0.0, 0.0}, {-45.0, 0.0, 0.0, 22.0, 0.0, 0.0}, {-44.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {-33.0, 0.0, 0.0, 16.0, 0.0, 0.0}, {-61.0, 0.0, 0.0, 1.0, 0.0, 0.0}, {-38.0, 0.0, 0.0, 19.0, 0.0, 0.0}, {-33.0, 0.0, 0.0, 21.0, 0.0, 0.0}, {-60.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {48.0, 0.0, 0.0, -10.0, 0.0, 0.0}, {38.0, 0.0, 0.0, -20.0, 0.0, 0.0}, {31.0, 0.0, 0.0, -13.0, 0.0, 0.0}, {-32.0, 0.0, 0.0, 15.0, 0.0, 0.0}, {45.0, 0.0, 0.0, -8.0, 0.0, 0.0}, {-44.0, 0.0, 0.0, 19.0, 0.0, 0.0}, {-51.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-36.0, 0.0, 0.0, 20.0, 0.0, 0.0}, {44.0, 0.0, 0.0, -19.0, 0.0, 0.0}, {-60.0, 0.0, 0.0, 2.0, 0.0, 0.0}, {35.0, 0.0, 0.0, -18.0, 0.0, 0.0}, {47.0, 0.0, 0.0, -1.0, 0.0, 0.0}, {36.0, 0.0, 0.0, -15.0, 0.0, 0.0}, {-36.0, 0.0, 0.0, 20.0, 0.0, 0.0}, {-35.0, 0.0, 0.0, 19.0, 0.0, 0.0}, {-37.0, 0.0, 0.0, 19.0, 0.0, 0.0}, {32.0, 0.0, 0.0, -16.0, 0.0, 0.0}, {35.0, 0.0, 0.0, -14.0, 0.0, 0.0}, {32.0, 0.0, 0.0, -13.0, 0.0, 0.0}, {65.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {47.0, 0.0, 0.0, -1.0, 0.0, 0.0}, {32.0, 0.0, 0.0, -16.0, 0.0, 0.0}, {37.0, 0.0, 0.0, -16.0, 0.0, 0.0}, {-30.0, 0.0, 0.0, 15.0, 0.0, 0.0}, {-32.0, 0.0, 0.0, 16.0, 0.0, 0.0}, {-31.0, 0.0, 0.0, 13.0, 0.0, 0.0}, {37.0, 0.0, 0.0, -16.0, 0.0, 0.0}, {31.0, 0.0, 0.0, -13.0, 0.0, 0.0}, {49.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {32.0, 0.0, 0.0, -13.0, 0.0, 0.0}, {-43.0, 0.0, 0.0, 18.0, 0.0, 0.0}, {-32.0, 0.0, 0.0, 14.0, 0.0, 0.0}, {30.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-34.0, 0.0, 0.0, 15.0, 0.0, 0.0}, {-36.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-38.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-31.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-34.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-35.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {30.0, 0.0, 0.0, -2.0, 0.0, 0.0}, {0.0, 0.0, -1988.0, 0.0, 0.0, -1679.0}, {0.0, 0.0, -63.0, 0.0, 0.0, -27.0}, {0.0, 0.0, 364.0, 0.0, 0.0, 176.0}, {0.0, 0.0, -1044.0, 0.0, 0.0, -891.0}, {0.0, 0.0, 330.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 30.0, 0.0, 0.0, 14.0}, {0.0, 0.0, -162.0, 0.0, 0.0, -138.0}, {0.0, 0.0, 75.0, 0.0, 0.0, 0.0}}; /* Planetary argument multipliers: L L' F D Om Me Ve E Ma Ju Sa Ur Ne pre */ static const short int napl_t[165][14]= { {0, 0, 0, 0, 0, 0, 0, 8, -16, 4, 5, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, -8, 16, -4, -5, 0, 0, 2}, {0, 0, 0, 0, 0, 0, 0, 8, -16, 4, 5, 0, 0, 2}, {0, 0, 1, -1, 1, 0, 0, 3, -8, 3, 0, 0, 0, 0}, {-1, 0, 0, 0, 0, 0, 10, -3, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 4, -8, 3, 0, 0, 0, 0}, {0, 0, 1, -1, 1, 0, 0, -5, 8, -3, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -5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, 3, -2, 0, 0, 0, 0, 0, 2}, {0, 0, 0, 0, 0, 0, 0, 3, 0, -1, 0, 0, 0, 2}, {0, 0, 0, 0, 0, 0, 0, 4, -2, 0, 0, 0, 0, 2}, {0, 0, 0, 0, 0, 0, -8, 10, 0, 0, 0, 0, 0, 2}, {0, 0, 0, 0, 0, 0, 5, -5, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2}, {0, 0, 0, 0, 0, 0, -9, 11, 0, 0, 0, 0, 0, 2}, {0, 0, 0, 0, 0, 0, 0, 4, 0, -3, 0, 0, 0, 2}, {0, 0, 0, 0, 0, 0, 6, -6, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 4, 0, -2, 0, 0, 0, 2}, {0, 0, 0, 0, 0, 0, 3, -1, 0, 0, 0, 0, 0, 2}, {0, 0, 0, 0, 0, 0, 0, 4, 0, -1, 0, 0, 0, 2}, {-1, 0, 0, 2, 0, 0, 0, 2, 0, -2, 0, 0, 0, 0}, {1, 0, 2, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {-1, 0, 2, 0, 2, 0, 0, -4, 8, -3, 0, 0, 0, 0}}; /* Planetary nutation coefficients, unit 1e-7 arcsec: longitude (sin, cos), obliquity (sin, cos) Each row of coefficients in 'cpl_t' belongs with the corresponding row of fundamental-argument multipliers in 'napl_t'. */ static const double cpl_t[165][4]= { {1440.0, 0.0, 0.0, 0.0}, {56.0, -117.0, -42.0, -40.0}, {125.0, -43.0, 0.0, -54.0}, {-114.0, 0.0, 0.0, 61.0}, {-219.0, 89.0, 0.0, 0.0}, {-462.0, 1604.0, 0.0, 0.0}, {99.0, 0.0, 0.0, -53.0}, {14.0, -218.0, 117.0, 8.0}, {31.0, -481.0, -257.0, -17.0}, {-491.0, 128.0, 0.0, 0.0}, {-3084.0, 5123.0, 2735.0, 1647.0}, {-1444.0, 2409.0, -1286.0, -771.0}, {103.0, -60.0, 0.0, 0.0}, {-26.0, -29.0, -16.0, 14.0}, {284.0, 0.0, 0.0, -151.0}, {226.0, 101.0, 0.0, 0.0}, {-41.0, 175.0, 76.0, 17.0}, {425.0, 212.0, -133.0, 269.0}, {1200.0, 598.0, 319.0, -641.0}, {235.0, 334.0, 0.0, 0.0}, {266.0, -78.0, 0.0, 0.0}, {-460.0, -435.0, -232.0, 246.0}, {0.0, 131.0, 0.0, 0.0}, {-42.0, 20.0, 0.0, 0.0}, {-10.0, 233.0, 0.0, 0.0}, {78.0, -18.0, 0.0, 0.0}, {45.0, -22.0, 0.0, 0.0}, {89.0, -16.0, -9.0, -48.0}, {-349.0, -62.0, 0.0, 0.0}, {-53.0, 0.0, 0.0, 0.0}, {-21.0, -78.0, 0.0, 0.0}, {20.0, -70.0, -37.0, -11.0}, {32.0, 15.0, -8.0, 17.0}, {174.0, 84.0, 45.0, -93.0}, {11.0, 56.0, 0.0, 0.0}, {-66.0, -12.0, -6.0, 35.0}, {47.0, 8.0, 4.0, -25.0}, {46.0, 66.0, 35.0, -25.0}, {-68.0, -34.0, -18.0, 36.0}, {76.0, 17.0, 9.0, -41.0}, {84.0, 298.0, 159.0, -45.0}, {-82.0, 292.0, 156.0, 44.0}, {-73.0, 17.0, 9.0, 39.0}, {-439.0, 0.0, 0.0, 0.0}, {57.0, -28.0, -15.0, -30.0}, {-40.0, 57.0, 30.0, 21.0}, {273.0, 80.0, 43.0, -146.0}, {-449.0, 430.0, 0.0, 0.0}, {-8.0, -47.0, -25.0, 4.0}, {6.0, 47.0, 25.0, -3.0}, {-48.0, -110.0, -59.0, 26.0}, {51.0, 114.0, 61.0, -27.0}, {-133.0, 0.0, 0.0, 57.0}, {-18.0, -436.0, -233.0, 9.0}, {35.0, -7.0, 0.0, 0.0}, {-53.0, -9.0, -5.0, 28.0}, {-50.0, 194.0, 103.0, 27.0}, {-13.0, 52.0, 28.0, 7.0}, {-91.0, 248.0, 0.0, 0.0}, {6.0, 49.0, 26.0, -3.0}, {-6.0, -47.0, -25.0, 3.0}, {52.0, 23.0, 10.0, -23.0}, {-138.0, 0.0, 0.0, 0.0}, {54.0, 0.0, 0.0, -29.0}, {-37.0, 35.0, 19.0, 20.0}, {-145.0, 47.0, 0.0, 0.0}, {-10.0, 40.0, 21.0, 5.0}, {11.0, -49.0, -26.0, -7.0}, {-2150.0, 0.0, 0.0, 932.0}, {85.0, 0.0, 0.0, -37.0}, {-86.0, 153.0, 0.0, 0.0}, {-51.0, 0.0, 0.0, 22.0}, {-11.0, -268.0, -116.0, 5.0}, {31.0, 6.0, 3.0, -17.0}, {140.0, 27.0, 14.0, -75.0}, {57.0, 11.0, 6.0, -30.0}, {-14.0, -39.0, 0.0, 0.0}, {-25.0, 22.0, 0.0, 0.0}, {42.0, 223.0, 119.0, -22.0}, {-27.0, -143.0, -77.0, 14.0}, {9.0, 49.0, 26.0, -5.0}, {-1166.0, 0.0, 0.0, 505.0}, {117.0, 0.0, 0.0, -63.0}, {0.0, 31.0, 0.0, 0.0}, {0.0, -32.0, -17.0, 0.0}, {50.0, 0.0, 0.0, -27.0}, {30.0, -3.0, -2.0, -16.0}, {8.0, 614.0, 0.0, 0.0}, {-127.0, 21.0, 9.0, 55.0}, {-20.0, 34.0, 0.0, 0.0}, {22.0, -87.0, 0.0, 0.0}, {-68.0, 39.0, 0.0, 0.0}, {3.0, 66.0, 29.0, -1.0}, {490.0, 0.0, 0.0, -213.0}, {-22.0, 93.0, 49.0, 12.0}, {-46.0, 14.0, 0.0, 0.0}, {25.0, 106.0, 57.0, -13.0}, {1485.0, 0.0, 0.0, 0.0}, {-7.0, -32.0, -17.0, 4.0}, {30.0, -6.0, -2.0, -13.0}, {118.0, 0.0, 0.0, -52.0}, {-28.0, 36.0, 0.0, 0.0}, {14.0, -59.0, -31.0, -8.0}, {-458.0, 0.0, 0.0, 198.0}, {0.0, -45.0, -20.0, 0.0}, {-166.0, 269.0, 0.0, 0.0}, {-78.0, 45.0, 0.0, 0.0}, {-5.0, 328.0, 0.0, 0.0}, {-1223.0, -26.0, 0.0, 0.0}, {-368.0, 0.0, 0.0, 0.0}, {-75.0, 0.0, 0.0, 0.0}, {-13.0, -30.0, 0.0, 0.0}, {-74.0, 0.0, 0.0, 32.0}, {-262.0, 0.0, 0.0, 114.0}, {202.0, 0.0, 0.0, -87.0}, {-8.0, 35.0, 19.0, 5.0}, {-35.0, -48.0, -21.0, 15.0}, {12.0, 55.0, 29.0, -6.0}, {-598.0, 0.0, 0.0, 0.0}, {8.0, -31.0, -16.0, -4.0}, {113.0, 0.0, 0.0, -49.0}, {83.0, 15.0, 0.0, 0.0}, {0.0, -114.0, -49.0, 0.0}, {117.0, 0.0, 0.0, -51.0}, {393.0, 3.0, 0.0, 0.0}, {18.0, -29.0, -13.0, -8.0}, {8.0, 34.0, 18.0, -4.0}, {89.0, 0.0, 0.0, 0.0}, {54.0, -15.0, -7.0, -24.0}, {0.0, 35.0, 0.0, 0.0}, {-154.0, -30.0, -13.0, 67.0}, {80.0, -71.0, -31.0, -35.0}, {61.0, -96.0, -42.0, -27.0}, {123.0, -415.0, -180.0, -53.0}, {0.0, 0.0, 0.0, -35.0}, {7.0, -32.0, -17.0, -4.0}, {-89.0, 0.0, 0.0, 38.0}, {0.0, -86.0, -19.0, -6.0}, {-123.0, -416.0, -180.0, 53.0}, {-62.0, -97.0, -42.0, 27.0}, {-85.0, -70.0, -31.0, 37.0}, {163.0, -12.0, -5.0, -72.0}, {-63.0, -16.0, -7.0, 28.0}, {-21.0, -32.0, -14.0, 9.0}, {5.0, -173.0, -75.0, -2.0}, {74.0, 0.0, 0.0, -32.0}, {83.0, 0.0, 0.0, 0.0}, {-339.0, 0.0, 0.0, 147.0}, {67.0, -91.0, -39.0, -29.0}, {30.0, -18.0, -8.0, -13.0}, {0.0, -114.0, -50.0, 0.0}, {517.0, 16.0, 7.0, -224.0}, {143.0, -3.0, -1.0, -62.0}, {50.0, 0.0, 0.0, -22.0}, {59.0, 0.0, 0.0, 0.0}, {370.0, -8.0, 0.0, -160.0}, {34.0, 0.0, 0.0, -15.0}, {-37.0, -7.0, -3.0, 16.0}, {40.0, 0.0, 0.0, 0.0}, {-184.0, -3.0, -1.0, 80.0}, {31.0, -6.0, 0.0, -13.0}, {-3.0, -32.0, -14.0, 1.0}, {-34.0, 0.0, 0.0, 0.0}, {126.0, -63.0, -27.0, -55.0}, {-126.0, -63.0, -27.0, 55.0}}; /* Interval between fundamental epoch J2000.0 and given date. */ t= ( ( jd_high - T0 ) + jd_low ) / 36525.0; /* Compute fundamental arguments from Simon et al. (1994), in radians. */ fund_args( t, a ); /* ** Luni-solar nutation. ** */ /* Initialize the nutation values. */ dp= 0.0; de= 0.0; /* Summation of luni-solar nutation series (in reverse order). */ for ( i= 322; i >= 0; i-- ) { /* Argument and functions. */ arg= fmod( (double)nals_t[i][0] * a[0] + (double)nals_t[i][1] * a[1] + (double)nals_t[i][2] * a[2] + (double)nals_t[i][3] * a[3] + (double)nals_t[i][4] * a[4], TWOPI ); sarg= sin( arg ); carg= cos( arg ); /* Term. */ dp+= ( cls_t[i][0] + cls_t[i][1] * t ) * sarg + cls_t[i][2] * carg; de+= ( cls_t[i][3] + cls_t[i][4] * t ) * carg + cls_t[i][5] * sarg; } /* Convert from 0.1 microarcsec units to radians. */ factor= 1.0e-7 * ASEC2RAD; dpsils= dp * factor; depsls= de * factor; /* ** Planetary nutation. ** */ /* Planetary longitudes, Mercury through Neptune, wrt mean dynamical ecliptic and equinox of J2000, with high order terms omitted (Simon et al. 1994, 5.8.1-5.8.8). */ alme= fmod( 4.402608842461 + 2608.790314157421 * t, TWOPI ); alve= fmod( 3.176146696956 + 1021.328554621099 * t, TWOPI ); alea= fmod( 1.753470459496 + 628.307584999142 * t, TWOPI ); alma= fmod( 6.203476112911 + 334.061242669982 * t, TWOPI ); alju= fmod( 0.599547105074 + 52.969096264064 * t, TWOPI ); alsa= fmod( 0.874016284019 + 21.329910496032 * t, TWOPI ); alur= fmod( 5.481293871537 + 7.478159856729 * t, TWOPI ); alne= fmod( 5.311886286677 + 3.813303563778 * t, TWOPI ); /* General precession in longitude (Simon et al. 1994), equivalent to 5028.8200 arcsec/cy at J2000. */ apa= ( 0.024380407358 + 0.000005391235 * t ) * t; /* Initialize the nutation values. */ dp= 0.0; de= 0.0; /* Summation of planetary nutation series (in reverse order). */ for ( i= 164; i >= 0; i-- ) { /* Argument and functions. */ arg= fmod( (double)napl_t[i][0] * a[0] + (double)napl_t[i][1] * a[1] + (double)napl_t[i][2] * a[2] + (double)napl_t[i][3] * a[3] + (double)napl_t[i][4] * a[4] + (double)napl_t[i][5] * alme + (double)napl_t[i][6] * alve + (double)napl_t[i][7] * alea + (double)napl_t[i][8] * alma + (double)napl_t[i][9] * alju + (double)napl_t[i][10] * alsa + (double)napl_t[i][11] * alur + (double)napl_t[i][12] * alne + (double)napl_t[i][13] * apa, TWOPI ); sarg= sin( arg ); carg= cos( arg ); /* Term. */ dp+= cpl_t[i][0] * sarg + cpl_t[i][1] * carg; de+= cpl_t[i][2] * sarg + cpl_t[i][3] * carg; } dpsipl= dp * factor; depspl= de * factor; /* Total: Add planetary and luni-solar components. */ *dpsi= dpsipl + dpsils; *deps= depspl + depsls; return; }
154,960
C
.c
4,432
29.040839
72
0.342634
kirxkirx/vast
13
3
3
GPL-3.0
9/7/2024, 11:01:22 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
6,345,989
template.c
sezero_hhexen/base/template.c
//************************************************************************** //** //** TEMPLATE.C //** //************************************************************************** // HEADER FILES ------------------------------------------------------------ // MACROS ------------------------------------------------------------------ // TYPES ------------------------------------------------------------------- // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // EXTERNAL DATA DECLARATIONS ---------------------------------------------- // PUBLIC DATA DEFINITIONS ------------------------------------------------- // PRIVATE DATA DEFINITIONS ------------------------------------------------ // CODE -------------------------------------------------------------------- //========================================================================== // // // //==========================================================================
1,125
C
.c
20
54.65
76
0.16194
sezero/hhexen
11
4
1
GPL-2.0
9/7/2024, 11:02:14 AM (Europe/Amsterdam)
false
true
false
true
false
true
false
false
6,366,299
lcs.c
FireFeathers06_Basic-C-Programming/Algorithms/lcs.c
#include<stdio.h> #include<string.h> int i,j,m,n,c[20][20]; char x[20],y[20],b[20][20]; void print(int i,int j) { if(i==0 || j==0) return; if(b[i][j]=='c') { print(i-1,j-1); printf("%c",x[i-1]); } else if(b[i][j]=='u') print(i-1,j); else print(i,j-1); } void lcs() { m=strlen(x); n=strlen(y); for(i=0;i<=m;i++) c[i][0]=0; for(i=0;i<=n;i++) c[0][i]=0; //c, u and l denotes cross, upward and downward directions respectively for(i=1;i<=m;i++) for(j=1;j<=n;j++) { if(x[i-1]==y[j-1]) { c[i][j]=c[i-1][j-1]+1; b[i][j]='c'; } else if(c[i-1][j]>=c[i][j-1]) { c[i][j]=c[i-1][j]; b[i][j]='u'; } else { c[i][j]=c[i][j-1]; b[i][j]='l'; } } } int main() { printf("Enter 1st sequence:"); scanf("%s",x); printf("Enter 2nd sequence:"); scanf("%s",y); printf("\nThe Longest Common Subsequence is "); lcs(); print(m,n); return 0; }
1,290
C
.c
58
13.051724
75
0.363259
FireFeathers06/Basic-C-Programming
16
62
7
GPL-3.0
9/7/2024, 11:02:32 AM (Europe/Amsterdam)
true
true
false
true
true
true
false
false
6,899,560
zextest.c
novintic_FlukeEmu-FluCom/flukeEmuWx/Z80/zextest.c
/* zextest.c * Example program using z80emu to run the zexall and zexdoc tests. This will * check if the Z80 is correctly emulated. * * Copyright (c) 2012, 2016 Lin Ke-Fong * Copyright (c) 2012 Chris Pressey * * This code is free, do whatever you want with it. */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include "zextest.h" #include "z80emu.h" #define Z80_CPU_SPEED 4000000 /* In Hz. */ #define CYCLES_PER_STEP (Z80_CPU_SPEED / 50) #define MAXIMUM_STRING_LENGTH 100 static void emulate (char *filename); int main (void) { time_t start, stop; start = time(NULL); emulate("testfiles/zexdoc.com"); emulate("testfiles/zexall.com"); stop = time(NULL); printf("Emulating zexdoc and zexall took a total of %d second(s).\n", (int) (stop - start)); return EXIT_SUCCESS; } /* Emulate "zexdoc.com" or "zexall.com". */ static void emulate (char *filename) { FILE *file; long l; ZEXTEST context; double total; printf("Testing \"%s\"...\n", filename); if ((file = fopen(filename, "rb")) == NULL) { fprintf(stderr, "Can't open file!\n"); exit(EXIT_FAILURE); } fseek(file, 0, SEEK_END); l = ftell(file); fseek(file, 0, SEEK_SET); fread(context.memory + 0x100, 1, l, file); fclose(file); /* Patch the memory of the program. Reset at 0x0000 is trapped by an * OUT which will stop emulation. CP/M bdos call 5 is trapped by an IN. * See Z80_INPUT_BYTE() and Z80_OUTPUT_BYTE() definitions in z80user.h. */ context.memory[0] = 0xd3; /* OUT N, A */ context.memory[1] = 0x00; context.memory[5] = 0xdb; /* IN A, N */ context.memory[6] = 0x00; context.memory[7] = 0xc9; /* RET */ context.is_done = 0; /* Emulate. */ Z80Reset(&context.state); context.state.pc = 0x100; total = 0.0; do total += Z80Emulate(&context.state, CYCLES_PER_STEP, &context); while (!context.is_done); printf("\n%.0f cycle(s) emulated.\n" "For a Z80 running at %.2fMHz, " "that would be %d second(s) or %.2f hour(s).\n", total, Z80_CPU_SPEED / 1000000.0, (int) (total / Z80_CPU_SPEED), total / ((double) 3600 * Z80_CPU_SPEED)); } /* Emulate CP/M bdos call 5 functions 2 (output character on screen) and 9 * (output $-terminated string to screen). */ void SystemCall (ZEXTEST *zextest) { if (zextest->state.registers.byte[Z80_C] == 2) printf("%c", zextest->state.registers.byte[Z80_E]); else if (zextest->state.registers.byte[Z80_C] == 9) { int i, c; for (i = zextest->state.registers.word[Z80_DE], c = 0; zextest->memory[i] != '$'; i++) { printf("%c", zextest->memory[i & 0xffff]); if (c++ > MAXIMUM_STRING_LENGTH) { fprintf(stderr, "String to print is too long!\n"); exit(EXIT_FAILURE); } } } }
3,350
C
.c
92
27.380435
79
0.536578
novintic/FlukeEmu-FluCom
18
2
0
GPL-2.0
9/7/2024, 11:06:55 AM (Europe/Amsterdam)
true
false
false
true
true
false
false
false
6,903,498
77.c
proninyaroslav_nesoid/app/jni/neslib/mappers/77.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" /* Original code provided by LULU */ static DECLFW(Mapper77_write) { mapbyte1[0]=V; ROM_BANK32(V&0x7); VROM_BANK2(0x0000, (V&0xf0)>>4); } static void Mapper77_StateRestore(int version) { int x; if(version>=7200) { ROM_BANK32(mapbyte1[0]&0x7); VROM_BANK2(0x0000, (mapbyte1[0]&0xf0)>>4); } for(x=2;x<8;x++) VRAM_BANK1(x*0x400,x); } void Mapper77_init(void) { int x; ROM_BANK32(0); for(x=2;x<8;x++) VRAM_BANK1(x*0x400,x); SetWriteHandler(0x6000,0xffff,Mapper77_write); MapStateRestore=Mapper77_StateRestore; }
1,382
C
.c
47
27.404255
76
0.742276
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,500
203.c
proninyaroslav_nesoid/app/jni/neslib/mappers/203.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2003 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static DECLFW(Mapper203_write) { ROM_BANK16(0x8000,(V>>2)&3); ROM_BANK16(0xc000,(V>>2)&3); VROM_BANK8(V&3); } void Mapper203_init(void) { ROM_BANK16(0x8000,0); ROM_BANK16(0xc000,0); VROM_BANK8(0); SetWriteHandler(0x8000,0xFFFF,Mapper203_write); }
1,103
C
.c
33
31.575758
76
0.752577
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,501
72.c
proninyaroslav_nesoid/app/jni/neslib/mappers/72.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" DECLFW(Mapper72_write) { mapbyte1[0]=V; if(V&0x80) ROM_BANK16(0x8000,V&0xF); if(V&0x40) VROM_BANK8(V&0xF); } void Mapper72_init(void) { SetWriteHandler(0x6000,0xffff,Mapper72_write); }
1,044
C
.c
32
30.65625
76
0.75571
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,502
151.c
proninyaroslav_nesoid/app/jni/neslib/mappers/151.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" DECLFW(Mapper151_write) { switch(A&0xF000) { case 0x8000:ROM_BANK8(0x8000,V);break; case 0xA000:ROM_BANK8(0xA000,V);break; case 0xC000:ROM_BANK8(0xC000,V);break; case 0xe000:VROM_BANK4(0x0000,V);break; case 0xf000:VROM_BANK4(0x1000,V);break; } } void Mapper151_init(void) { SetWriteHandler(0x8000,0xffff,Mapper151_write); }
1,191
C
.c
35
31.914286
76
0.75913
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,503
86.c
proninyaroslav_nesoid/app/jni/neslib/mappers/86.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" DECLFW(Mapper86_write) { if(A>=0x6000 && A<=0x6fFF) { VROM_BANK8((V&3)|((V>>4)&4)); ROM_BANK32((V>>4)&3); } //else //if(A!=0x6000) // printf("$%04x:$%02x\n",A,V); } void Mapper86_init(void) { SetWriteHandler(0x6000,0x6fff,Mapper86_write); SetWriteHandler(0x4020,0xffff,Mapper86_write); }
1,148
C
.c
36
30
76
0.734234
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,505
92.c
proninyaroslav_nesoid/app/jni/neslib/mappers/92.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" /* Original code provided by LULU */ static DECLFW(Mapper92_write) { uint8 reg=(A&0xF0)>>4; uint8 bank=A&0xF; if(A>=0x9000) { if(reg==0xD) ROM_BANK16(0xc000,bank); else if(reg==0xE) VROM_BANK8(bank); } else { if(reg==0xB) ROM_BANK16(0xc000,bank); else if(reg==0x7) VROM_BANK8(bank); } } void Mapper92_init(void) { SetWriteHandler(0x8000,0xFFFF,Mapper92_write); }
1,231
C
.c
40
28.775
76
0.742833
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,507
225.c
proninyaroslav_nesoid/app/jni/neslib/mappers/225.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define reg1 mapbyte1[0] #define reg2 mapbyte1[1] #define reg3 mapbyte1[2] #define reg4 mapbyte1[3] DECLFR(A110in1read) { switch(A&0x3) { case 0:return reg1;break; case 1:return reg2;break; case 2:return reg3;break; case 3:return reg4;break; } return 0xF; } DECLFW(A110in1regwr) { switch(A&0x3) { case 0:reg1=V&0xF;break; case 1:reg2=V&0xF;break; case 2:reg3=V&0xF;break; case 3:reg4=V&0xF;break; } } DECLFW(Mapper225_write) { int banks=0; MIRROR_SET((A>>13)&1); if(A&0x4000) banks=1; else banks=0; VROM_BANK8(((A&0x003f)+(banks<<6))); if(A&0x1000) { if(A&0x40) { ROM_BANK16(0x8000,((((((A>>7)&0x1F)+(banks<<5)))<<1)+1)); ROM_BANK16(0xC000,((((((A>>7)&0x1F)+(banks<<5)))<<1)+1)); } else { ROM_BANK16(0x8000,(((((A>>7)&0x1F)+(banks<<5)))<<1)); ROM_BANK16(0xC000,(((((A>>7)&0x1F)+(banks<<5)))<<1)); } } else { ROM_BANK32(((((A>>7)&0x1F)+(banks<<5)))); } } void Mapper225_init(void) { SetWriteHandler(0x8000,0xffff,Mapper225_write); SetReadHandler(0x5800,0x5fff,A110in1read); SetWriteHandler(0x5800,0x5fff,A110in1regwr); }
1,969
C
.c
78
22.692308
76
0.69288
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,509
241.c
proninyaroslav_nesoid/app/jni/neslib/mappers/241.c
#include "mapinc.h" static DECLFW(M241wr) { // FCEU_printf("Wr: $%04x:$%02x, $%04x\n",A,V,X.PC); if(A<0x8000) { // printf("$%04x:$%02x, $%04x\n",A,V,X.PC); } else ROM_BANK32(V); } static DECLFR(M241rd) { //DumpMem("out",0x8000,0xffff); //printf("Rd: $%04x, $%04x\n",A,X.PC); return(0x50); } void Mapper241_init(void) { ROM_BANK32(0); SetWriteHandler(0x5000,0x5fff,M241wr); SetWriteHandler(0x8000,0xFFFF,M241wr); SetReadHandler(0x4020,0x5fff,M241rd); }
469
C
.c
24
17.875
53
0.680995
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,511
214.c
proninyaroslav_nesoid/app/jni/neslib/mappers/214.c
#include "mapinc.h" static DECLFW(Mapper214_write) { // FCEU_printf("%02x:%02x\n",A,V); ROM_BANK16(0x8000,(A>>2)&3); ROM_BANK16(0xC000,(A>>2)&3); VROM_BANK8(A&3); } void Mapper214_init(void) { ROM_BANK16(0x8000,0); ROM_BANK16(0xC000,0); VROM_BANK8(0); SetWriteHandler(0x8000,0xFFFF,Mapper214_write); }
311
C
.c
15
19.133333
48
0.714286
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,512
244.c
proninyaroslav_nesoid/app/jni/neslib/mappers/244.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2003 CaH4e3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static DECLFW(Mapper244_write_1) { ROM_BANK32((A-0x8065)&0x03); } static DECLFW(Mapper244_write_2) { VROM_BANK8((A-0x80A5)&0x07); } void Mapper244_init(void) { ROM_BANK32(0); SetWriteHandler(0x8065,0x80a4,Mapper244_write_1); SetWriteHandler(0x80a5,0x80e4,Mapper244_write_2); }
1,135
C
.c
34
31.441176
76
0.759344
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,524
234.c
proninyaroslav_nesoid/app/jni/neslib/mappers/234.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define r1 mapbyte1[0] #define r2 mapbyte1[1] static void DoBS(void) { if(r1&0x40) { ROM_BANK32((r1&0xE)|(r2&1)); VROM_BANK8( ((r1&0xE)<<2) | ((r2>>4)&7) ); } else { ROM_BANK32(r1&0xF); VROM_BANK8( ((r1&0xF)<<2) | ((r2>>4)&3) ); } } static void R1Set(uint8 V) { if(r1) return; r1=V; MIRROR_SET(V>>7); DoBS(); } static void R2Set(uint8 V) { r2=V; DoBS(); } DECLFW(R1W) { R1Set(V); } DECLFR(R1R) { uint8 r=CartBR(A); R1Set(r); return r; } DECLFW(R2W) { R2Set(V); } DECLFR(R2R) { uint8 r=CartBR(A); R2Set(r); return r; } static void M15Restore(int version) { DoBS(); MIRROR_SET(r1>>7); } static void M15Reset(void) { r1=r2=0; DoBS(); MIRROR_SET(0); } void Mapper234_init(void) { SetWriteHandler(0xff80,0xff9f,R1W); SetReadHandler(0xff80,0xff9f,R1R); SetWriteHandler(0xffe8,0xfff7,R2W); SetReadHandler(0xffe8,0xfff7,R2R); SetReadHandler(0x6000,0x7FFF,0); SetWriteHandler(0x6000,0x7FFF,0); M15Reset(); GameStateRestore=M15Restore; MapperReset=M15Reset; }
1,918
C
.c
90
18.755556
76
0.70127
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,525
41.c
proninyaroslav_nesoid/app/jni/neslib/mappers/41.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define calreg mapbyte1[0] #define calchr mapbyte1[1] DECLFW(Mapper41_write) { if(A<0x8000) { ROM_BANK32(A&7); MIRROR_SET((A>>5)&1); calreg=A; calchr&=0x3; calchr|=(A>>1)&0xC; VROM_BANK8(calchr); } else if(calreg&0x4) { calchr&=0xC; calchr|=A&3; VROM_BANK8(calchr); } } static void M41Reset(void) { calreg=calchr=0; } void Mapper41_init(void) { MapperReset=M41Reset; ROM_BANK32(0); SetWriteHandler(0x8000,0xffff,Mapper41_write); SetWriteHandler(0x6000,0x67ff,Mapper41_write); }
1,359
C
.c
51
24.607843
76
0.746544
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,526
8.c
proninyaroslav_nesoid/app/jni/neslib/mappers/8.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static DECLFW(Mapper8_write) { ROM_BANK16(0x8000,V>>3); VROM_BANK8(V&7); } void Mapper8_init(void) { ROM_BANK32(0); SetWriteHandler(0x8000,0xFFFF,Mapper8_write); }
1,046
C
.c
30
32.066667
76
0.737154
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,527
82.c
proninyaroslav_nesoid/app/jni/neslib/mappers/82.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define ctrl mapbyte1[6] static void DoCHR(void) { int x; for(x=0;x<2;x++) VROM_BANK2((x<<11)|((ctrl&2)<<11),mapbyte1[x]>>1); for(x=0;x<4;x++) VROM_BANK1((x<<10) | (((ctrl&2)^2)<<11),mapbyte1[2+x]); } static DECLFW(Mapper82_write) { if(A<=0x7EF5) { mapbyte1[A&7]=V; DoCHR(); } else switch(A) { case 0x7ef6:ctrl=V&3; MIRROR_SET2(V&1); DoCHR(); break; case 0x7efa:V>>=2;mapbyte2[0]=V;ROM_BANK8(0x8000,V);break; case 0x7efb:V>>=2;mapbyte2[1]=V;ROM_BANK8(0xa000,V);break; case 0x7efc:V>>=2;mapbyte2[2]=V;ROM_BANK8(0xc000,V);break; } } void Mapper82_init(void) { ROM_BANK8(0xE000,~0); /* external WRAM might end at $73FF */ SetWriteHandler(0x7ef0,0x7efc,Mapper82_write); }
1,613
C
.c
54
26.833333
76
0.689233
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,529
89.c
proninyaroslav_nesoid/app/jni/neslib/mappers/89.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" DECLFW(Mapper89_write) { VROM_BANK8((V&7)|((V>>4)&8)); ROM_BANK16(0x8000,(V>>4)&7); onemir((V>>3)&1); } void Mapper89_init(void) { Mirroring=0; SetWriteHandler(0x8000,0xffff,Mapper89_write); }
1,047
C
.c
31
31.935484
76
0.746298
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,531
91.c
proninyaroslav_nesoid/app/jni/neslib/mappers/91.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static DECLFW(Mapper91_write) { //if(A>=0x7001) //printf("$%04x:$%02x, %d\n",A,V,scanline); A&=0xF007; if(A>=0x6000 && A<=0x6003) VROM_BANK2((A&3)*2048,V); else switch(A&0xF003) { case 0x7000: case 0x7001:ROM_BANK8(0x8000+(A&1)*8192,V);break; case 0x7002:IRQa=IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);break; case 0x7003:IRQa=1;X6502_IRQEnd(FCEU_IQEXT);break; // default: printf("Iyee: $%04x:$%02x\n",A,V);break; } //if(A>=0x7000) // printf("$%04x:$%02x, %d\n",A,V,scanline); } static void Mapper91_hb(void) { if(IRQCount<8 && IRQa) { IRQCount++; if(IRQCount>=8) { X6502_IRQBegin(FCEU_IQEXT); } } } void Mapper91_init(void) { SetWriteHandler(0x4020,0xFFFF,Mapper91_write); GameHBIRQHook=Mapper91_hb; }
1,589
C
.c
53
27.773585
76
0.719608
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,532
232.c
proninyaroslav_nesoid/app/jni/neslib/mappers/232.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static void DoIt(void) { ROM_BANK16(0x8000,(mapbyte1[1]&3) | ((mapbyte1[0]&0x18)>>1)); ROM_BANK16(0xc000,3|(((mapbyte1[0])&0x18)>>1)); } DECLFW(Mapper232_write) { if(A<=0x9FFF) mapbyte1[0]=V; else mapbyte1[1]=V; DoIt(); } static void QuattroReset(void) { mapbyte1[0]=0x18; DoIt(); } void Mapper232_init(void) { SetWriteHandler(0x6000,0xffff,Mapper232_write); MapperReset=QuattroReset; QuattroReset(); }
1,306
C
.c
44
26.977273
76
0.724522
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,533
97.c
proninyaroslav_nesoid/app/jni/neslib/mappers/97.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" DECLFW(Mapper97_write) { ROM_BANK16(0xC000,V&15); switch(V>>6) { case 0:break; case 1:MIRROR_SET2(0);break; case 2:MIRROR_SET2(1);break; case 3:break; } } void Mapper97_init(void) { ROM_BANK16(0x8000,~0); SetWriteHandler(0x8000,0xffff,Mapper97_write); }
1,116
C
.c
36
29.055556
76
0.753259
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,534
202.c
proninyaroslav_nesoid/app/jni/neslib/mappers/202.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2003 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static DECLFW(Mapper202_write) { int tmp=(A>>1)&0x7; MIRROR_SET(A&1); ROM_BANK16(0x8000,tmp); ROM_BANK16(0xc000,tmp+(((tmp&0x6)==0x6)?1:0)); VROM_BANK8(tmp); } void Mapper202_init(void) { ROM_BANK16(0x8000,0); ROM_BANK16(0xc000,0); VROM_BANK8(0); SetWriteHandler(0x8000,0xFFFF,Mapper202_write); }
1,156
C
.c
35
31.142857
76
0.749329
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,535
46.c
proninyaroslav_nesoid/app/jni/neslib/mappers/46.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define A64reg mapbyte1[0] #define A64wr mapbyte1[1] DECLFW(Mapper46_writel) { A64reg=V; ROM_BANK32((A64wr&1)+((A64reg&0xF)<<1)); VROM_BANK8(((A64wr>>4)&7)+((A64reg&0xF0)>>1)); } DECLFW(Mapper46_write) { A64wr=V; ROM_BANK32((V&1)+((A64reg&0xF)<<1)); VROM_BANK8(((V>>4)&7)+((A64reg&0xF0)>>1)); } void Mapper46_init(void) { MIRROR_SET(0); ROM_BANK32(0); SetWriteHandler(0x8000,0xffff,Mapper46_write); SetWriteHandler(0x6000,0x7fff,Mapper46_writel); }
1,321
C
.c
41
30.219512
76
0.735271
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,536
255.c
proninyaroslav_nesoid/app/jni/neslib/mappers/255.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static DECLFW(Mapper255_write) { uint32 pbank=(A>>7)&0x1F; uint32 cbank=A&0x3F; uint32 rbank=(A>>14)&1; // printf("$%04x:$%02x\n",A,V); // printf("%2x:%2x:%2x,%2x\n",pbank,cbank,rbank,(A&0x40)>>6); if(A&0x1000) { ROM_BANK16(0x8000,((pbank|(rbank<<5))<<1)|((A&0x40)>>6)); ROM_BANK16(0xc000,((pbank|(rbank<<5))<<1)|((A&0x40)>>6)); } else { ROM_BANK32(pbank|(rbank<<5)); } MIRROR_SET((A>>13)&1); VROM_BANK8((rbank<<6)|cbank); } static DECLFW(Mapper255_wl) { // printf("Wr: $%04x:$%02x\n",A,V); mapbyte1[A&3]=V&0xF; } static DECLFR(Mapper255_read) { //printf("Rd: $%04x\n",A); return(mapbyte1[A&3]); //|(X.DB&0xF0)); } void Mapper255_init(void) { mapbyte1[0]=mapbyte1[1]=0xF; ROM_BANK32(0); VROM_BANK8(0); SetWriteHandler(0x5800,0x5FF0,Mapper255_wl); SetWriteHandler(0x8000,0xffff,Mapper255_write); SetReadHandler(0x5800,0x5FFF,Mapper255_read); }
1,724
C
.c
58
27.810345
76
0.710923
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,537
32.c
proninyaroslav_nesoid/app/jni/neslib/mappers/32.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define IREMCon mapbyte1[0] static DECLFW(Mapper32_write) { switch(A>>12) { case 0x8: mapbyte1[1]=V; if(IREMCon) {ROM_BANK8(0xc000,V);ROM_BANK8(0x8000,~1);} else {ROM_BANK8(0x8000,V);ROM_BANK8(0xc000,~1);} break; case 0x9:IREMCon=(V>>1)&1; if(IREMCon) {ROM_BANK8(0xc000,mapbyte1[1]);ROM_BANK8(0x8000,~1);} else {ROM_BANK8(0x8000,mapbyte1[1]); ROM_BANK8(0xc000,~1);} MIRROR_SET(V&1); break; case 0xa:ROM_BANK8(0xA000,V); break; } if((A&0xF000)==0xb000) VROM_BANK1((A&0x7)<<10,V); } void Mapper32_init(void) { ROM_BANK16(0x8000,0); ROM_BANK16(0xc000,~0); SetWriteHandler(0x8000,0xffff,Mapper32_write); }
1,571
C
.c
47
29.425532
76
0.691041
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,540
230.c
proninyaroslav_nesoid/app/jni/neslib/mappers/230.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2003 CaH4e3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define rom_sw mapbyte1[0] void Mapper230_Reset(void) { rom_sw ^= 1; //1 - rom_sw; if( rom_sw ) { ROM_BANK16(0x8000,0); ROM_BANK16(0xc000,7); } else { ROM_BANK16(0x8000,8); ROM_BANK16(0xc000,39); } MIRROR_SET2(1); } static DECLFW(Mapper230_write) { if( rom_sw ) { ROM_BANK16( 0x8000, V&0x07 ); } else { if( V & 0x20 ) { ROM_BANK16( 0x8000, (V&0x1F)+8 ); ROM_BANK16( 0xc000, (V&0x1F)+8 ); } else { ROM_BANK32( ((V&0x1E) >> 1) + 4 ); } MIRROR_SET2( ((V & 0x40) >> 6) ); } } void Mapper230_init(void) { ROM_BANK16(0x8000,0); ROM_BANK16(0xc000,7); SetWriteHandler(0x8000, 0xffff, Mapper230_write); MapperReset = Mapper230_Reset; rom_sw = 1; }
1,810
C
.c
55
25.636364
76
0.590389
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,542
75.c
proninyaroslav_nesoid/app/jni/neslib/mappers/75.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define map75sel mapbyte1[0] #define map75ar mapbyte2 DECLFW(Mapper75_write) { switch(A&0xF000) { case 0x8000:ROM_BANK8(0x8000,V);break; case 0x9000: VROM_BANK4(0x0000,map75ar[0]|((V&2)<<3)); VROM_BANK4(0x1000,map75ar[1]|((V&4)<<2)); map75sel=V;MIRROR_SET(V&1);break; case 0xa000:ROM_BANK8(0xa000,V);break; case 0xc000:ROM_BANK8(0xc000,V);break; case 0xe000:V&=0xF;map75ar[0]=V;V|=(map75sel&2)<<3;VROM_BANK4(0x0000,V);break; case 0xf000:V&=0xF;map75ar[1]=V;V|=(map75sel&4)<<2;VROM_BANK4(0x1000,V);break; } } void Mapper75_init(void) { SetWriteHandler(0x8000,0xffff,Mapper75_write); }
1,484
C
.c
41
33.463415
79
0.729993
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,545
22.c
proninyaroslav_nesoid/app/jni/neslib/mappers/22.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define K4buf mapbyte2 DECLFW(Mapper22_write) { if(A<=0xAFFF) { switch(A&0xF000) { case 0x8000:ROM_BANK8(0x8000,V);break; case 0xa000:ROM_BANK8(0xA000,V);break; case 0x9000:switch(V&3) { case 0x00:MIRROR_SET2(1);break; case 0x01:MIRROR_SET2(0);break; case 0x02:onemir(0);break; case 0x03:onemir(1);break; } break; } } else { A&=0xF003; if(A>=0xb000 && A<=0xe003) { int x=(A&1)|((A-0xB000)>>11); K4buf[x]&=(0xF0)>>((A&2)<<1); K4buf[x]|=(V&0xF)<<((A&2)<<1); VROM_BANK1(x<<10,K4buf[x]>>1); } } } void Mapper22_init(void) { SetWriteHandler(0x8000,0xffff,Mapper22_write); }
1,783
C
.c
55
24.4
76
0.583721
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,547
246.c
proninyaroslav_nesoid/app/jni/neslib/mappers/246.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" DECLFW(Mapper246_write) { switch(A&0xF007) { case 0x6000:ROM_BANK8(0x8000,V);break; case 0x6001:ROM_BANK8(0xA000,V);break; case 0x6002:ROM_BANK8(0xC000,V);break; case 0x6003:ROM_BANK8(0xE000,V);break; case 0x6004:VROM_BANK2(0x0000,V);break; case 0x6005:VROM_BANK2(0x0800,V);break; case 0x6006:VROM_BANK2(0x1000,V);break; case 0x6007:VROM_BANK2(0x1800,V);break; } } void Mapper246_init(void) { SetWriteHandler(0x4020,0x67ff,Mapper246_write); SetWriteHandler(0x8000,0xffff,Mapper246_write); }
1,357
C
.c
39
32.820513
76
0.766184
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,548
71.c
proninyaroslav_nesoid/app/jni/neslib/mappers/71.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" DECLFW(Mapper71_write) { switch(A&0xF000) { case 0xF000: case 0xE000: case 0xD000: case 0xC000:ROM_BANK16(0x8000,V);break; case 0x9000:onemir((V>>3)&2);break; } } void Mapper71_init(void) { SetWriteHandler(0x4020,0xffff,Mapper71_write); }
1,098
C
.c
35
29.485714
76
0.759697
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,549
204.c
proninyaroslav_nesoid/app/jni/neslib/mappers/204.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2003 CaH4e3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static DECLFW(Mapper204_write) { int tmp2=A&0x6; int tmp1=tmp2+((tmp2==0x6)?0:(A&1)); MIRROR_SET((A>>4)&1); ROM_BANK16(0x8000,tmp1); ROM_BANK16(0xc000,tmp2+((tmp2==0x6)?1:(A&1))); VROM_BANK8(tmp1); } void Mapper204_init(void) { ROM_BANK32(~0); VROM_BANK8(~0); SetWriteHandler(0x8000,0xFFFF,Mapper204_write); }
1,166
C
.c
35
31.457143
76
0.742021
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,550
79.c
proninyaroslav_nesoid/app/jni/neslib/mappers/79.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" DECLFW(Mapper79_write) { if(A<0x8000 && ((A^0x4100)==0)) { ROM_BANK32((V>>3)&1); } VROM_BANK8(V); } void Mapper79_init(void) { ROM_BANK32(~0); SetWriteHandler(0x8000,0xffff,Mapper79_write); SetWriteHandler(0x4020,0x5fff,Mapper79_write); }
1,100
C
.c
34
30.382353
76
0.749057
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,552
229.c
proninyaroslav_nesoid/app/jni/neslib/mappers/229.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" DECLFW(Mapper229_write) { if(A>=0x8000) { MIRROR_SET((A>>5)&1); if(!(A&0x1e)) { ROM_BANK32(0); } else { ROM_BANK16(0x8000,A&0x1f); ROM_BANK16(0xC000,A&0x1f); } VROM_BANK8(A); } } void Mapper229_init(void) { SetWriteHandler(0x8000,0xffff,Mapper229_write); }
1,120
C
.c
41
25.463415
76
0.746269
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,553
62.c
proninyaroslav_nesoid/app/jni/neslib/mappers/62.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2003 CaH4e3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static DECLFW(Mapper62_write) { VROM_BANK8(((A&0x1F)<<2)|(V&0x03)); if(A&0x20) { ROM_BANK16(0x8000,(A&0x40)|((A>>8)&0x3F)); ROM_BANK16(0xc000,(A&0x40)|((A>>8)&0x3F)); } else ROM_BANK32(((A&0x40)|((A>>8)&0x3F))>>1); MIRROR_SET((A&0x80)>>7); } void Mapper62_init(void) { SetWriteHandler(0x8000,0xffff, Mapper62_write); ROM_BANK32(0); }
1,224
C
.c
36
31.222222
76
0.708369
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,555
51.c
proninyaroslav_nesoid/app/jni/neslib/mappers/51.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #define mode mapbyte1[0] #define page mapbyte1[1] static uint32 Get8K(uint32 A) { uint32 bank; bank=(page<<2)|((A>>13)&1); if(A&0x4000 && !(mode&1)) bank|=0xC; if(!(A&0x8000)) bank|=0x20; if(mode==2) bank|=2; else bank|=(A>>13)&2; return(bank); } static void Synco(void) { uint32 x; if(mapbyte1[0]<=2) MIRROR_SET2(1); else MIRROR_SET2(0); for(x=0x6000;x<0x10000;x+=8192) ROM_BANK8(x,Get8K(x)); } static DECLFW(Write) { if(A&0x8000) mapbyte1[1]=V&0xF; else mapbyte1[0]=(mapbyte1[0]&2)|((V>>1)&1); if(A&0x4000) mapbyte1[0]=(mapbyte1[0]&1)|((V>>3)&2); Synco(); } void Mapper51_init(void) { SetWriteHandler(0x6000,0xFFFF,Write); SetReadHandler(0x6000,0xFFFF,CartBR); mapbyte1[0]=1; mapbyte1[1]=0; Synco(); }
1,586
C
.c
57
25.877193
76
0.720869
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false
6,903,556
59.c
proninyaroslav_nesoid/app/jni/neslib/mappers/59.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static int ay; static DECLFW(Mapper59_write) { //printf("$%04x:$%02x\n",A,V); setprg32(0x8000,(A&0x70)>>4); setchr8(A&0x7); //if(A&0x100) // setprg32r(0x10,0x8000,0); ay=A; MIRROR_SET2((A&0x8)>>3); } static DECLFR(m59rd) { if(ay&0x100) return(0); else return(CartBR(A)); } void Mapper59_init(void) { setprg32(0x8000,0); SetReadHandler(0x8000,0xffff,m59rd); SetWriteHandler(0x8000,0xffff,Mapper59_write); }
1,270
C
.c
43
27.697674
76
0.744072
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,557
76.c
proninyaroslav_nesoid/app/jni/neslib/mappers/76.c
/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static uint8 MMC3_cmd; static DECLFW(Mapper76_write) { switch(A&0xE001){ case 0x8000: MMC3_cmd = V; break; case 0x8001: switch(MMC3_cmd&0x07){ case 2: VROM_BANK2(0x000,V);break; case 3: VROM_BANK2(0x800,V);break; case 4: VROM_BANK2(0x1000,V);break; case 5: VROM_BANK2(0x1800,V);break; case 6: if(MMC3_cmd&0x40) ROM_BANK8(0xC000,V); else ROM_BANK8(0x8000,V); break; case 7: ROM_BANK8(0xA000,V); break; } break; case 0xA000: MIRROR_SET(V&1); break; } } void Mapper76_init(void) { SetWriteHandler(0x8000,0xffff,Mapper76_write); }
1,682
C
.c
50
26.1
76
0.61855
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,560
213.c
proninyaroslav_nesoid/app/jni/neslib/mappers/213.c
#include "mapinc.h" static DECLFW(Mapper213_write) { ROM_BANK32((A>>1)&3); VROM_BANK8((A>>3)&7); } void Mapper213_init(void) { ROM_BANK32(0); VROM_BANK8(0); SetWriteHandler(0x8000,0xFFFF,Mapper213_write); }
214
C
.c
12
16.25
48
0.73
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
true
false
false
false
6,903,562
193.c
proninyaroslav_nesoid/app/jni/neslib/mappers/193.c
#include "mapinc.h" static DECLFW(m193w) { //printf("$%04x:$%02x\n",A,V); switch(A&3) { case 0:VROM_BANK4(0x0000,V>>2);break; case 1:VROM_BANK2(0x1000,V>>1);break; case 2:VROM_BANK2(0x1800,V>>1);break; case 3:ROM_BANK8(0x8000,V);break; } } void Mapper193_init(void) { ROM_BANK32(~0); SetWriteHandler(0x4018,0x7fff,m193w); SetReadHandler(0x4018,0x7fff,0); }
375
C
.c
18
18.833333
39
0.704225
proninyaroslav/nesoid
19
6
1
GPL-2.0
9/7/2024, 11:07:04 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
false