OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
convert_diary.c
Go to the documentation of this file.
1 // procedure to convert spacecraft diary data into time-tagged
2 // orbit and attitude data
3 
4 // Arguments
5 //
6 // Name Type I/O Description
7 // ---- ---- --- -----------
8 // npkts int I Number of SC diary packets
9 // dstore byte I 71 x npkts array of SC diary packets
10 // otime double O Time tags of orbit (seconds of day)
11 // orb double O 6 x npkts array of orbit vectors
12 // atime double O Time tags of attitude (seconds of day)
13 // quat double O 4 x npkts array of quaternions
14 
15 // Liang Hong, Jan 14, 2016, Ported from IDL
16 // V0.1, Feb 1, 2016
17 
18 #include <timeutils.h>
19 
20 int convert_diary(int npkts, uint8_t dstore[], double otime[], double orb[], double atime[], double quat[]) {
21  // Set up output arrays
22  int i, j, m, ioff;
23  int32_t jd0, ccsds_iy, idy, jd;
24  int16_t iy;
25  double secd;
26  uint8_t cctime[8];
27 
28  // initialize output arrays
29  for (i = 0; i < npkts; i++) {
30  otime[i] = 0;
31  atime[i] = 0;
32  for (j = 0; j < 6; j++) orb[j + i * 6] = 0;
33  for (j = 0; j < 4; j++) quat[j + i * 4] = 0;
34  }
35 
36  // Get start year and day
37  //jd0 = swap_endian(fix(dstore(6:7,0),0)) + 2436205 ;Days since 1/1/1958
38  jd0 = (dstore[0 * 71 + 6] << 8) + dstore[0 * 71 + 7] + 2436205;
39 
40  // Loop through packets
41  for (i = 0; i < npkts; i++) {
42  // Get orbit time
43  //ccsds_to_yds,dstore(15:22,i),iy,idy,sec
44  for (m = 0; m < 8; m++) cctime[m] = dstore[i * 71 + m + 15];
45  ccsds_to_yds(cctime, &ccsds_iy, &idy, &secd);
46  iy = (int16_t) ccsds_iy;
47  jd = jday(iy, 1, idy);
48  otime[i] = secd + (jd - jd0)*86400.0;
49 
50  // Convert orbit vectors to doubles
51  ioff = 23;
52  for (j = 0; j < 6; j++) {
53  float tmpa;
54  *((uint8_t*) (&tmpa) + 0) = dstore[i * 71 + ioff + 3];
55  *((uint8_t*) (&tmpa) + 1) = dstore[i * 71 + ioff + 2];
56  *((uint8_t*) (&tmpa) + 2) = dstore[i * 71 + ioff + 1];
57  *((uint8_t*) (&tmpa) + 3) = dstore[i * 71 + ioff];
58  orb[j + i * 6] = (double) tmpa;
59  ioff += 4;
60  }
61 
62  // Get attitude time
63  //ccsds_to_yds,dstore(47:54,i),iy,idy,sec
64  for (m = 0; m < 8; m++) cctime[m] = dstore[i * 71 + m + 47];
65  ccsds_to_yds(cctime, &ccsds_iy, &idy, &secd);
66  iy = (int16_t) ccsds_iy;
67  jd = jday(iy, 1, idy);
68  atime[i] = secd + (jd - jd0)*86400.0;
69 
70  // Convert attitude quaternion to doubles
71  ioff = 55;
72  for (j = 0; j < 4; j++) {
73  float tmpa;
74  *((uint8_t*) (&tmpa) + 0) = dstore[i * 71 + ioff + 3];
75  *((uint8_t*) (&tmpa) + 1) = dstore[i * 71 + ioff + 2];
76  *((uint8_t*) (&tmpa) + 2) = dstore[i * 71 + ioff + 1];
77  *((uint8_t*) (&tmpa) + 3) = dstore[i * 71 + ioff];
78  quat[j + i * 4] = (double) tmpa;
79  ioff += 4;
80  }
81  }
82  return 0;
83 }
int j
Definition: decode_rs.h:73
function jd(i, j, k)
Definition: jd.f:2
int32_t jday(int16_t i, int16_t j, int16_t k)
Definition: jday.c:4
int ccsds_to_yds(uint8_t *cctime, int32_t *iyear, int32_t *iday, double *sec)
Definition: ccsds_to_yds.c:5
int convert_diary(int npkts, uint8_t dstore[], double otime[], double orb[], double atime[], double quat[])
Definition: convert_diary.c:20
Definition: jd.py:1
int32 ioff
integer, parameter double
int32_t idy
Definition: atrem_corl1.h:161
int i
Definition: decode_rs.h:71