OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
getorbdata.c
Go to the documentation of this file.
1 /* -------------------------------------------------------------------- */
2 /* getorbdata() - loads telemetry structure with raw GPS data */
3 /* -------------------------------------------------------------------- */
4 
5 #include <stdio.h>
6 #include "swl0_proto.h"
7 #include <timeutils.h>
8 
9 INT32 getorbdata(swl0indx *indx, input_sType gps[]) {
10  BYTE mnf[L0LEN];
11  INT32 irec;
12  FILE *fp;
13  INT32 ngps = 0;
14  INT16 ttag[4];
15  FLOAT64 secs;
16  int endian = 0;
17 
18  if (endianess() == 1)
19  endian = 1;
20 
21  /* */
22  /* Open file for reading */
23  /* */
24  if ((fp = fopen(indx->l0file, "r")) == NULL) {
25  fprintf(stderr,
26  "-E- %s line %d: unable to open %s for reading\n",
27  __FILE__, __LINE__, indx->l0file);
28  return (1);
29  }
30 
31 
32  /* */
33  /* Loop through L0 index, find frames with valid GPS data, and load */
34  /* the gps data structure with converted telemetry. We'll take any */
35  /* frame with a valid time for the first frame, as we need that */
36  /* start-time to buffer the orbit vectors. */
37  /* */
38  for (irec = 0; irec < indx->nrecs; irec++) {
39 
40  /*
41  * GPS data is only stored in minor frame 1
42  */
43  if (
44  ((ngps == 0) &&
45  !(indx->rec[irec].tRanError ||
46  indx->rec[irec].tSeqError ||
47  indx->rec[irec].tDifError)) ||
48 
49  ((indx->rec[irec].mnfnum == 1) &&
50  !(indx->rec[irec].scidError ||
51  indx->rec[irec].sgaError ||
52  indx->rec[irec].tRanError ||
53  indx->rec[irec].tSeqError ||
54  indx->rec[irec].tDifError ||
55  indx->rec[irec].bitError))) {
56 
57  if (fseek(fp, sizeof (swl0hdr) + irec * (L0LEN), SEEK_SET) != 0) {
58  fprintf(stderr,
59  "-E- %s line %d: error reading %s\n",
60  __FILE__, __LINE__, indx->l0file);
61  return (1);
62  }
63  if (fread(mnf, L0LEN, 1, fp) != 1) {
64  fprintf(stderr,
65  "-E- %s line %d: error reading %s\n",
66  __FILE__, __LINE__, indx->l0file);
67  return (1);
68  }
69 
70  gps[ngps].flag = 0;
71  memcpy(gps[ngps].sc_id, &mnf[O_SCID], 4);
72  if (endian)
73  swapc_bytes((char *) gps[ngps].sc_id, 2, 2);
74  memcpy(ttag, &mnf[O_TIME], 8);
75  if (endian)
76  swapc_bytes((char *) ttag, 2, 4);
77  ttag2ydmsec(ttag,
78  &gps[ngps].iyear, &gps[ngps].iday, (INT32 *) & gps[ngps].msec);
79  conv_soh_(&mnf[O_SOH], gps[ngps].sc_ana, gps[ngps].sc_dis);
80 
81  ngps++;
82 
83  if (ngps >= MAXFRAMES - 1) {
84  fprintf(stderr,
85  "-W- %s line %d: limit on MAXFRAMES exceeded\n",
86  __FILE__, __LINE__);
87  break;
88  }
89 
90  }
91 
92  }
93 
94  /* add dummy record with time chosen to span data period */
95  unix2yds(indx->timeLast, &gps[ngps].iyear, &gps[ngps].iday, &secs);
96  gps[ngps].msec = (INT32) secs * 1000;
97  memset(gps[ngps].sc_ana, 0, sizeof (gps[ngps].sc_ana));
98  memset(gps[ngps].sc_dis, 0, sizeof (gps[ngps].sc_dis));
99  ngps++;
100 
101  fclose(fp);
102 
103  return (ngps);
104 
105 }
106 
107 
108 
109 
double FLOAT64
Definition: elements.h:8
int conv_soh_(BYTE *soh, FLOAT32 *scana, BYTE *scdis)
#define INT32
Definition: l1_imgscale.c:3
#define NULL
Definition: decode_rs.h:63
#define O_TIME
Definition: swl0_parms.h:33
void ttag2ydmsec(INT16 ttag[], INT16 *year, INT16 *day, INT32 *msec)
Definition: swl0_utils.c:71
int32_t INT32
Definition: elements.h:6
#define MAXFRAMES
Definition: swl0_parms.h:9
int32 * msec
Definition: l1_czcs_hdf.c:31
int endianess(void)
determine endianess
Definition: endianess.c:10
int swapc_bytes(char *in, int nbyte, int ntime)
Definition: swapc_bytes.c:4
unsigned char BYTE
Definition: elements.h:4
short int INT16
Definition: elements.h:5
void unix2yds(double usec, short *year, short *day, double *secs)
#define L0LEN
Definition: swl0_parms.h:8
#define O_SCID
Definition: swl0_parms.h:32
#define O_SOH
Definition: swl0_parms.h:34
INT32 getorbdata(swl0indx *indx, input_sType gps[])
Definition: getorbdata.c:9