OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
pdsinfo.c
Go to the documentation of this file.
1 /********************************************************************
2  * *
3  * Copyright (C) 2007, 2008, 2009 *
4  * Charles Darwin University, Darwin, Australia *
5  * *
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public License as *
8  * published by the Free Software Foundation; either version 2 of *
9  * the License, or (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be *
12  * useful, but WITHOUT ANY WARRANTY; without even the implied *
13  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *
14  * PURPOSE. See the GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public *
17  * License along with this program; if not, write to the Free *
18  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
19  * MA 02111-1307 USA *
20  * *
21  ********************************************************************
22  * *
23  * provide info about contents of a PDS file *
24  * *
25  * 05/12/2007 S W Maier start of work *
26  * 12/12/2007 S W Maier initial version *
27  * 14/12/2007 S W Maier added count of missing packets *
28  * 03/06/2008 S W Maier added count of missing seconds *
29  * 14/08/2008 S W Maier fix bug in missing seconds calcula- *
30  * tion when covering two days *
31  * 10/10/2008 S W Maier increased data buffer and test for *
32  * packet size before reading *
33  * 09/12/2008 S W Maier test if we have found any valid pkts *
34  * 14/02/2009 S W Maier output number of day, night and eng. *
35  * pkts *
36  * 24/03/2009 S W Maier proper handling of corrupted files *
37  * *
38  ********************************************************************
39  * *
40  * usage: pdsinfo <input> *
41  * *
42  ********************************************************************
43  * *
44  * to do: *
45  * - support other sensors *
46  * *
47  ********************************************************************
48  * *
49  * build: cc pdsinfo.c -lm -o pdsinfo *
50  * *
51  ********************************************************************/
52 
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <math.h>
56 
57 
58 /********************************************************************
59  * *
60  * defines *
61  * *
62  ********************************************************************/
63 /* name */
64 #define NAME "pdsinfo"
65 /* version */
66 #define VERSION 1
67 /* revision */
68 #define REVISION 6
69 /* primary header size */
70 #define PRI_HDR_SIZE 6
71 /* MODIS secondary header size */
72 #define MODIS_HDR_SIZE 12
73 /* Julian Day of MODIS reference date (01/01/1958)*/
74 #define MODIS_REF_DATE 2436205.0
75 /* data buffer size */
76 #define DATA_SIZE 100000
77 
78 
79 /********************************************************************
80  * *
81  * structure definitions *
82  * *
83  ********************************************************************/
84 
85 /* primary header */
86 struct pri_hdr {
87  int version;
88  int type;
89  int sec_hdr_flag;
90  int apid;
91  int seq_flags;
92  int pkt_count;
94 };
95 
96 /* APID info */
97 struct apid_info {
98  int apid;
99  long int count;
100  long int invalid;
101  long int missing;
102  long int last_pkt_count;
103  struct apid_info *next;
104 };
105 
106 /* MODIS header */
107 struct modis_hdr {
108  int days;
109  unsigned long int millisec;
110  int microsec;
111  int ql;
112  int pkt_type;
115  int src1;
116  int src2;
117  int conf;
120  int checksum;
121 };
122 
123 
124 /********************************************************************
125  * *
126  * function declarations *
127  * *
128  ********************************************************************/
129 int ReadPriHdr(FILE *f, unsigned char *buf);
130 int DecodePriHdr(unsigned char *buf, struct pri_hdr *hdr);
131 int DecodeMODISHdr(unsigned char *buf, int len,
132  struct modis_hdr *hdr);
133 struct apid_info *AllocAPIDInfo(int apid);
134 void AddAPIDInfo(struct apid_info **list, struct apid_info *ai);
135 void FreeAPIDInfoList(struct apid_info *list);
136 struct apid_info *FindAPIDInfo(struct apid_info *list, int apid);
137 void caldat(int *minute, int *hour, int *day, int *month, int *year,
138  double jul);
139 int CalcChecksum12(unsigned char *buf, int n);
140 
141 /********************************************************************
142  * *
143  * main function *
144  * *
145  ********************************************************************/
146 int main(int argc, char *argv[]) {
147  /* file pointer */
148  FILE *fin;
149  /* primary header structure */
150  struct pri_hdr hdr;
151  /* MODIS header structure */
152  struct modis_hdr mhdr;
153  /* header buffer */
154  unsigned char buf_hdr[PRI_HDR_SIZE];
155  /* data buffer */
156  unsigned char *buf_data;
157  /* pointer to APID Info list */
158  struct apid_info *apidlist = NULL;
159  /* pointer to current APID Info object */
160  struct apid_info *apidinfo = NULL;
161  /* first packet date/time */
162  long int firstday = 1.E6, firstms = 1.E6, firstmics = 1.E6;
163  /* last packet date/time */
164  long int lastday = 0, lastms = 0, lastmics = 0;
165  /* previous packet date/time */
166  long int prevday = 0, prevms = 0;
167  /* date buffer */
168  int second, minute, hour, day, month, year;
169  long int ms;
170  double jul;
171  /* checksum */
172  int chksum;
173  /* error code */
174  int error;
175  /* number of missing packets */
176  long int missing;
177  /* number of missing seconds */
178  long int missingsecs = 0;
179  /* millisecs difference between packets */
180  long int diffms;
181  /* */
182  int lastdays, lastmicrosec, lastsrc;
183  unsigned long int lastmillisec;
184  /* number of day packets */
185  long int daypkts1 = 0, daypkts2 = 0;
186  /* number of night packets */
187  long int nightpkts1 = 0, nightpkts2 = 0;
188  /* number of engineering packets */
189  long int engpkts1 = 0, engpkts2 = 0;
190  /* return value */
191  int retvalue = 0;
192 
193 
194  /* print version information */
195  fprintf(stderr, "%s V%d.%d ("__DATE__")\n",
196  NAME, VERSION, REVISION);
197 
198  /* check number of arguments */
199  if (argc != 2) {
200  fprintf(stderr, "USAGE: %s <input>\n", argv[0]);
201  return (20);
202  }
203 
204  /* allocate memory */
205  if (!(buf_data = malloc(sizeof (unsigned char) * DATA_SIZE))) {
206  fprintf(stderr, "not enough memory\n");
207  return (10);
208  }
209 
210  /* open input file */
211  if (!(fin = fopen(argv[1], "rb"))) {
212  fprintf(stderr, "can't open input file (%s)\n", argv[1]);
213  return (10);
214  }
215 
216  /* main loop */
217  for (;;) {
218  /* read primary header */
219  if (ReadPriHdr(fin, buf_hdr)) {
220  /* end of file? */
221  if (feof(fin))
222  break;
223  else {
224  fprintf(stderr,
225  "error 1 reading input file (%s): "
226  "file might be corrupted\n",
227  argv[1]);
228  retvalue = 5;
229  break;
230  }
231  }
232 
233  /* decode primary header */
234  switch (error = DecodePriHdr(buf_hdr, &hdr)) {
235  case 0:
236  break;
237  case -1:
238  fprintf(stderr,
239  "unsupported packet version (%d): "
240  "file might be corrupted, trying to resyncronise\n",
241  hdr.version);
242 
243  /* read data block */
244  if (fread(buf_data, hdr.pkt_length + 1, 1, fin) != 1) {
245  fprintf(stderr,
246  "error 2 reading input file (%s): "
247  "file might be corrupted\n",
248  argv[1]);
249  retvalue = 5;
250  break;
251  }
252  continue;
253  default:
254  fprintf(stderr,
255  "unknown error (%d) while decoding primary header\n",
256  error);
257  return (5);
258  }
259 
260  /* do we have a current APID Info object? */
261  if (apidinfo != NULL) {
262  /* APID different as of current APID Info object? */
263  if (apidinfo->apid != hdr.apid) {
264  /* find APID Info object */
265  if (!(apidinfo = FindAPIDInfo(apidlist, hdr.apid))) {
266  /* allocate an APID Info object */
267  if (!(apidinfo = AllocAPIDInfo(hdr.apid))) {
268  fprintf(stderr, "can't allocate memory\n");
269  return (5);
270  }
271 
272  /* add APID Info object to list */
273  AddAPIDInfo(&apidlist, apidinfo);
274  }
275  }
276  } else {
277  /* allocate an APID Info object */
278  if (!(apidinfo = AllocAPIDInfo(hdr.apid))) {
279  fprintf(stderr, "can't allocate memory\n");
280  return (5);
281  }
282 
283  /* add APID Info object to list */
284  AddAPIDInfo(&apidlist, apidinfo);
285  }
286 
287  /* increase packet counter */
288  apidinfo->count = apidinfo->count + 1;
289 
290  /* check if there are missing packets */
291  /* first packet with this APID? */
292  if (apidinfo->last_pkt_count != -1) {
293  /* calculate number of missing packets */
294  missing =
295  (hdr.pkt_count > apidinfo->last_pkt_count) ?
296  (hdr.pkt_count - apidinfo->last_pkt_count - 1) :
297  (hdr.pkt_count - apidinfo->last_pkt_count + 16383);
298 
299  /* duplicated packet? */
300  if (missing == 16383)
301  fprintf(stderr, "duplicated packet!!!\n");
302 
303  /* add to counter for missing packets */
304  apidinfo->missing += missing;
305  }
306 
307  /* store packet count */
308  apidinfo->last_pkt_count = hdr.pkt_count;
309 
310  /* read data block */
311  if (hdr.pkt_length + 1 > DATA_SIZE) {
312  fprintf(stderr,
313  "buffer overflow (%d), "
314  "please contact developer\n",
315  hdr.pkt_length);
316  return (20);
317  }
318  if (fread(buf_data, hdr.pkt_length + 1, 1, fin) != 1) {
319  fprintf(stderr,
320  "error 3 reading input file (%s): "
321  "file might be corrupted\n",
322  argv[1]);
323  retvalue = 5;
324  break;
325  }
326 
327  /* is it a MODIS packet? */
328  if ((hdr.apid >= 64) && (hdr.apid <= 127)) {
329  /* decode MODIS header */
330  DecodeMODISHdr(buf_data, hdr.pkt_length + 1, &mhdr);
331 
332  /* duplicated packet? */
333  if (missing == 16383) {
334  fprintf(stderr, "duplicated MODIS packet: %d/%d %ld/%ld %d/%d %d/%d\n",
335  mhdr.days, lastdays,
336  mhdr.millisec, lastmillisec,
337  mhdr.microsec, lastmicrosec,
338  mhdr.src2, lastsrc);
339  }
340  lastdays = mhdr.days;
341  lastmillisec = mhdr.millisec;
342  lastmicrosec = mhdr.microsec;
343  lastsrc = mhdr.src2;
344 
345  /* calculate checksum */
346  chksum = CalcChecksum12(&(buf_data[MODIS_HDR_SIZE]),
347  (hdr.pkt_length + 1 - MODIS_HDR_SIZE) /
348  1.5 - 1);
349 
350  /* valid packet? */
351  if (chksum != mhdr.checksum) {
352  /* increase invalid packet counter */
353  apidinfo->invalid = apidinfo->invalid + 1;
354  }
355 
356  /* determine first and last packet date/time */
357  if (mhdr.days < firstday) {
358  firstday = mhdr.days;
359  firstms = mhdr.millisec;
360  firstmics = mhdr.microsec;
361  } else {
362  if (mhdr.days == firstday) {
363  if (mhdr.millisec < firstms) {
364  firstday = mhdr.days;
365  firstms = mhdr.millisec;
366  firstmics = mhdr.microsec;
367  } else {
368  if (mhdr.millisec == firstms) {
369  if (mhdr.microsec < firstmics) {
370  firstday = mhdr.days;
371  firstms = mhdr.millisec;
372  firstmics = mhdr.microsec;
373  }
374  }
375  }
376  }
377  }
378  if (mhdr.days > lastday) {
379  lastday = mhdr.days;
380  lastms = mhdr.millisec;
381  lastmics = mhdr.microsec;
382  } else {
383  if (mhdr.days == lastday) {
384  if (mhdr.millisec > lastms) {
385  lastday = mhdr.days;
386  lastms = mhdr.millisec;
387  lastmics = mhdr.microsec;
388  } else {
389  if (mhdr.millisec == lastms) {
390  if (mhdr.microsec > lastmics) {
391  lastday = mhdr.days;
392  lastms = mhdr.millisec;
393  lastmics = mhdr.microsec;
394  }
395  }
396  }
397  }
398  }
399 
400  /* check if there are missing seconds */
401  if (prevday != 0) {
402  diffms =
403  mhdr.millisec - prevms +
404  (mhdr.days - prevday) * 86400000;
405  missingsecs += diffms / 1000;
406  }
407  prevday = mhdr.days;
408  prevms = mhdr.millisec;
409 
410  /* earth view packet? */
411  if (mhdr.src1 == 0) {
412  /* increase packet type counters? */
413  switch (mhdr.pkt_type) {
414  case 0:
415  daypkts1++;
416  break;
417  case 1:
418  nightpkts1++;
419  break;
420  case 2:
421  case 4:
422  engpkts1++;
423  break;
424  }
425  } else {
426  /* increase packet type counters? */
427  switch (mhdr.pkt_type) {
428  case 0:
429  daypkts2++;
430  break;
431  case 1:
432  nightpkts2++;
433  break;
434  case 2:
435  case 4:
436  engpkts2++;
437  break;
438  }
439  }
440  }
441  }
442 
443  /* have we read any valid packets? */
444  if (apidinfo == NULL) {
445  fprintf(stderr, "no valid packets found\n");
446  return (5);
447  }
448 
449  /* print APID statistics */
450  for (apidinfo = apidlist;
451  apidinfo != NULL;
452  apidinfo = apidinfo->next) {
453  printf("APID %d: count %ld invalid %ld missing %ld\n",
454  apidinfo->apid,
455  apidinfo->count,
456  apidinfo->invalid,
457  apidinfo->missing);
458  }
459 
460  /* print first and last packet date/time */
461  jul = firstday + MODIS_REF_DATE;
462  caldat(&minute, &hour, &day, &month, &year, jul);
463  hour = firstms / (1000L * 60L * 60L);
464  ms = firstms - hour * 1000L * 60L * 60L;
465  minute = ms / (1000L * 60L);
466  ms = ms - minute * 1000L * 60L;
467  second = ms / 1000L;
468  ms = ms - second * 1000L;
469  printf("first packet: %04d/%02d/%02d %02d:%02d:%d.%03ld%03ld\n",
470  year, month, day, hour, minute, second, ms, firstmics);
471  jul = lastday + MODIS_REF_DATE;
472  caldat(&minute, &hour, &day, &month, &year, jul);
473  hour = lastms / (1000L * 60L * 60L);
474  ms = lastms - hour * 1000L * 60L * 60L;
475  minute = ms / (1000L * 60L);
476  ms = ms - minute * 1000L * 60L;
477  second = ms / 1000L;
478  ms = ms - second * 1000L;
479  printf("last packet: %04d/%02d/%02d %02d:%02d:%d.%03ld%03ld\n",
480  year, month, day, hour, minute, second, ms, lastmics);
481 
482  /* print number of missing secs */
483  printf("missing seconds: %ld\n", missingsecs);
484 
485  /* print number of day packets */
486  printf("day packets: %ld/%ld\n", daypkts1, daypkts2);
487 
488  /* print number of night packets */
489  printf("night packets: %ld/%ld\n", nightpkts1, nightpkts2);
490 
491  /* print number of engineering packets */
492  printf("engineering packets: %ld/%ld\n", engpkts1, engpkts2);
493 
494  /* free APID Info list */
495  FreeAPIDInfoList(apidlist);
496 
497  /* close input file */
498  fclose(fin);
499 
500  /* free memory */
501  free(buf_data);
502 
503  /* Ja das war's. Der Pop-Shop ist zu Ende */
504  return (retvalue);
505 }
506 
507 /********************************************************************
508  * *
509  * read primary header from file *
510  * *
511  * f: file pointer *
512  * buf: pointer to buffer *
513  * *
514  * result: 0 - ok *
515  * -1 - read error *
516  * *
517  ********************************************************************/
518 int ReadPriHdr(FILE *f, unsigned char *buf) {
519  /* read header */
520  if (fread(buf, PRI_HDR_SIZE, 1, f) != 1)
521  return (-1);
522 
523  /* ois rodger */
524  return (0);
525 }
526 
527 /********************************************************************
528  * *
529  * decode primary header *
530  * *
531  * buf: pointer to buffer *
532  * hdr: pointer to header structure *
533  * *
534  * result: 0 - ok *
535  * -1 - decode error (version not supported) *
536  * *
537  ********************************************************************/
538 int DecodePriHdr(unsigned char *buf, struct pri_hdr *hdr) {
539  /* version */
540  hdr->version = (buf[0] & 0xE0) >> 5;
541 
542  /* version supported? */
543  if (hdr->version != 0)
544  return (-1);
545 
546  /* type */
547  hdr->type = (buf[0] & 0x10) >> 4;
548 
549  /* secondary header flag */
550  hdr->sec_hdr_flag = (buf[0] & 0x08) >> 3;
551 
552  /* APID */
553  hdr->apid = (((int) (buf[0] & 0x07)) << 8) + buf[1];
554 
555  /* sequence flags */
556  hdr->seq_flags = (buf[2] & 0xC0) >> 6;
557 
558  /* packet count per APID */
559  hdr->pkt_count = (((int) (buf[2] & 0x3F)) << 8) + buf[3];
560 
561  /* packet length (length - 1) */
562  hdr->pkt_length = (((int) buf[4]) << 8) + buf[5];
563 
564  /* okeydokey */
565  return (0);
566 }
567 
568 /********************************************************************
569  * *
570  * allocate and initialise APID Info object *
571  * *
572  * apid: APID *
573  * *
574  * result: pointer to APID Info object *
575  * 0 - error *
576  * *
577  ********************************************************************/
579  /* pointer to APID Info object */
580  struct apid_info *ai;
581 
582 
583  /* allocate memory for object */
584  if (!(ai = malloc(sizeof (struct apid_info))))
585  return (0);
586 
587  /* store APID */
588  ai->apid = apid;
589 
590  /* initialise packet counter */
591  ai->count = 0;
592 
593  /* initialise invalid packet counter */
594  ai->invalid = 0;
595 
596  /* initialise missing packet counter */
597  ai->missing = 0;
598 
599  /* initialise last packet count value */
600  ai->last_pkt_count = -1;
601 
602  /* initialise pointer to next object */
603  ai->next = NULL;
604 
605  /* all done */
606  return (ai);
607 }
608 
609 /********************************************************************
610  * *
611  * add APID Info object to list *
612  * *
613  * list: pointer to pointer to first object in list *
614  * ai: pointer to APID Info object to be added *
615  * *
616  * result: none *
617  * *
618  ********************************************************************/
619 void AddAPIDInfo(struct apid_info **list, struct apid_info *ai) {
620  /* pointer to APID Info object */
621  struct apid_info *p;
622 
623 
624  /* empty list? */
625  if (*list == NULL) {
626  /* add object as first in list */
627  *list = ai;
628 
629  /* ciao */
630  return;
631  }
632 
633  /* first object? */
634  if ((*list)->apid > ai->apid) {
635  /* add object as first in list */
636  ai->next = *list;
637  *list = ai;
638 
639  /* Tschuess */
640  return;
641  }
642 
643  /* find right place in list */
644  for (p = *list; p->next != NULL; p = p->next) {
645  /* reached right position */
646  if (p->next->apid > ai->apid) {
647  /* add object to list */
648  ai->next = p->next;
649  p->next = ai;
650 
651  /* all good */
652  return;
653  }
654  }
655 
656  /* add object as last in list */
657  p->next = ai;
658 
659  /* hasta la vista*/
660  return;
661 }
662 
663 /********************************************************************
664  * *
665  * free memory in APID list *
666  * *
667  * list: pointer to first object in list *
668  * *
669  * result: none *
670  * *
671  ********************************************************************/
673  /* pointers to APID Info objects */
674  struct apid_info *p1, *p2;
675 
676 
677  /* go through list */
678  for (p1 = list; p1 != NULL; p1 = p2) {
679  /* get pointer to next object */
680  p2 = p1->next;
681 
682  /* free memory of current object */
683  free(p1);
684  }
685 }
686 
687 /********************************************************************
688  * *
689  * find APID Info object *
690  * *
691  * list: pointer to first object in list *
692  * apid: APID *
693  * *
694  * result: pointer to APID Info object *
695  * 0 - APID Info object not found *
696  * *
697  ********************************************************************/
698 struct apid_info *FindAPIDInfo(struct apid_info *list, int apid) {
699  /* pointer to APID Info object */
700  struct apid_info *p;
701 
702 
703  /* go through list */
704  for (p = list; p != NULL; p = p->next) {
705  /* right APID? */
706  if (p->apid == apid)
707  /* return object address */
708  return (p);
709  }
710 
711  /* couldn't find object */
712  return (NULL);
713 }
714 
715 /********************************************************************
716  * *
717  * decode MODIS header *
718  * *
719  * buf: pointer to buffer *
720  * len: data lengh *
721  * hdr: pointer to header structure *
722  * *
723  * result: 0 - ok *
724  * -1 - decode error *
725  * -2 - decode error *
726  * *
727  ********************************************************************/
728 int DecodeMODISHdr(unsigned char *buf, int len,
729  struct modis_hdr *hdr) {
730  /* days since 01/01/1958 */
731  hdr->days =
732  (((int) buf[0]) << 8) +
733  (((int) buf[1]));
734 
735  /* milliseconds of day */
736  hdr->millisec =
737  (((unsigned long int) buf[2]) << 24) +
738  (((unsigned long int) buf[3]) << 16) +
739  (((unsigned long int) buf[4]) << 8) +
740  (((unsigned long int) buf[5]));
741 
742  /* microseconds of milliseconds */
743  hdr->microsec =
744  (((int) buf[6]) << 8) +
745  (((int) buf[7]));
746 
747  /* quicklook flag */
748  hdr->ql = (buf[8] & 0x80) >> 7;
749 
750  /* packet type (000 = day, 001 = night, 010 = eng1, 100 = eng2 */
751  hdr->pkt_type = (buf[8] & 0x70) >> 4;
752 
753  /* scan count */
754  hdr->scan_count = (buf[8] & 0x0E) >> 1;
755 
756  /* mirror side */
757  hdr->mirror_side = (buf[8] & 1);
758 
759  /* source identification (0 = earth, 1 = calibration) */
760  hdr->src1 = (buf[9] & 0x80) >> 7;
761 
762  /* source identification (0 = eng., 1 to 1354 = sample count) */
763  hdr->src2 =
764  (((int) buf[9] & 0x7F) << 4) +
765  (((int) buf[10] & 0xF0) >> 4);
766 
767  /* FPA/AEM config */
768  hdr->conf =
769  (((int) buf[10] & 0x0F) << 6) +
770  (((int) buf[11] & 0xFC) >> 2);
771 
772  /* sci state */
773  hdr->sci_state = (((int) buf[11] & 0x02) >> 1);
774 
775  /* sci abnorm */
776  hdr->sci_abnorm = (((int) buf[11] & 0x01));
777 
778  /* check sum */
779  hdr->checksum =
780  (((int) buf[len - 2] & 0x0F) << 8) +
781  (((int) buf[len - 1]));
782 
783  return 0;
784 }
785 
786 /********************************************************************
787  * *
788  * convert julian day to calendar date *
789  * *
790  * minute: pointer to store minute *
791  * hour: pointer to store hour *
792  * day: pointer to store day *
793  * month: pointer to store month *
794  * year: pointer to store year *
795  * jul: julian day *
796  * *
797  * result: none *
798  * *
799  ********************************************************************/
800 void caldat(int *minute, int *hour, int *day, int *month, int *year,
801  double jul) {
802  /* julian day as long */
803  long ljul;
804  /* helping variables */
805  long ja, jalpha, jb, jc, jd, je;
806 
807 
808  ljul = (long) floor(jul);
809  jul -= (double) ljul;
810  *hour = (int) (floor(jul * 24.0));
811  jul -= (double) *hour / 24.0;
812  *minute = (int) (floor(jul * 1440.0));
813 
814  if (ljul >= 2299161) {
815  jalpha = (long) (((float) (ljul - 1867216) - 0.25) / 36524.25);
816  ja = ljul + 1 + jalpha - (long) (0.25 * jalpha);
817  } else
818  ja = ljul;
819  jb = ja + 1524;
820  jc = (long) (6680.0 + ((float) (jb - 2439870) - 122.1) / 365.25);
821  jd = (long) (365 * jc + (0.25 * jc));
822  je = (long) ((jb - jd) / 30.6001);
823  *day = jb - jd - (long) (30.6001 * je);
824  *month = je - 1;
825  if (*month > 12)
826  *month -= 12;
827  *year = jc - 4715;
828  if (*month > 2)
829  --(*year);
830  if (*year <= 0)
831  --(*year);
832 }
833 
834 /********************************************************************
835  * *
836  * calculate 12bit checksum *
837  * *
838  * buf: pointer to data buffer *
839  * n: number of bytes in buffer *
840  * *
841  * result: checksum *
842  * *
843  ********************************************************************/
844 int CalcChecksum12(unsigned char *buf, int n) {
845  /* counter */
846  int i;
847  /* data value */
848  unsigned long x;
849  /* checksum */
850  unsigned long s = 0;
851 
852 
853  /* main loop */
854  for (i = 0; i < n; i++) {
855  /* get 1. value */
856  x =
857  (((unsigned long) buf[(int) (1.5 * i)]) << 4) +
858  (((unsigned long) buf[(int) (1.5 * i) + 1] & 0xF0) >> 4);
859 
860  /* add to checksum */
861  s = s + x;
862 
863  /* increase counter */
864  i++;
865 
866  /* do we have a second value */
867  if (i >= n)
868  break;
869 
870  /* get 2. value */
871  x =
872  (((unsigned long) buf[(int) (1.5 * (i - 1)) + 1] & 0x0F) << 8) +
873  (((unsigned long) buf[(int) (1.5 * (i - 1)) + 2]));
874 
875  /* add to checksum */
876  s = s + x;
877  }
878 
879 
880  s = s >> 4;
881  s = s & 0xFFF;
882 
883  /* return checksum */
884  return (s);
885 }
unsigned long int millisec
Definition: pdsinfo.c:109
int apid
Definition: pdsinfo.c:94
int version
Definition: pdsinfo.c:91
long int last_pkt_count
Definition: pdsinfo.c:102
int src2
Definition: pdsinfo.c:116
int32_t day
#define DATA_SIZE
Definition: pdsinfo.c:76
#define L(lambda, T)
Definition: PreprocessP.h:185
int sci_abnorm
Definition: pdsinfo.c:119
list(APPEND LIBS ${PGSTK_LIBRARIES}) add_executable(atteph_info_modis atteph_info_modis.c) target_link_libraries(atteph_info_modis $
Definition: CMakeLists.txt:7
int sci_state
Definition: pdsinfo.c:118
function jd(i, j, k)
Definition: jd.f:2
int DecodePriHdr(unsigned char *buf, struct pri_hdr *hdr)
Definition: pdsinfo.c:538
void caldat(int *minute, int *hour, int *day, int *month, int *year, double jul)
Definition: pdsinfo.c:800
struct apid_info * FindAPIDInfo(struct apid_info *list, int apid)
Definition: pdsinfo.c:698
void FreeAPIDInfoList(struct apid_info *list)
Definition: pdsinfo.c:672
#define NULL
Definition: decode_rs.h:63
int microsec
Definition: pdsinfo.c:110
int ReadPriHdr(FILE *f, unsigned char *buf)
Definition: pdsinfo.c:518
int ql
Definition: pdsinfo.c:111
#define MODIS_HDR_SIZE
Definition: pdsinfo.c:72
int sec_hdr_flag
Definition: pdsinfo.c:93
struct apid_info * AllocAPIDInfo(int apid)
Definition: pdsinfo.c:578
int type
Definition: pdsinfo.c:92
int jb
Definition: atrem_corl1.h:227
int CalcChecksum12(unsigned char *buf, int n)
Definition: pdsinfo.c:844
#define NAME
Definition: pdsinfo.c:64
int pkt_count
Definition: pdsinfo.c:96
a context in which it is NOT documented to do so subscript error
Definition: HISTORY.txt:53
double precision function f(R1)
Definition: tmd.lp.f:1454
#define MODIS_REF_DATE
Definition: pdsinfo.c:74
int apid
Definition: pdsinfo.c:98
int main(int argc, char *argv[])
Definition: pdsinfo.c:146
void AddAPIDInfo(struct apid_info **list, struct apid_info *ai)
Definition: pdsinfo.c:619
int conf
Definition: pdsinfo.c:117
Definition: jd.py:1
int checksum
Definition: pdsinfo.c:120
int DecodeMODISHdr(unsigned char *buf, int len, struct modis_hdr *hdr)
Definition: pdsinfo.c:728
long int missing
Definition: pdsinfo.c:101
float ja
Definition: atrem_cor.h:114
integer, parameter double
int days
Definition: pdsinfo.c:108
#define VERSION
Definition: pdsinfo.c:66
int src1
Definition: pdsinfo.c:115
int pkt_length
Definition: pdsinfo.c:97
#define PRI_HDR_SIZE
Definition: pdsinfo.c:70
long int count
Definition: pdsinfo.c:99
struct apid_info * next
Definition: pdsinfo.c:103
data_t s[NROOTS]
Definition: decode_rs.h:75
long int invalid
Definition: pdsinfo.c:100
#define REVISION
Definition: pdsinfo.c:68
int seq_flags
Definition: pdsinfo.c:95
int i
Definition: decode_rs.h:71
int mirror_side
Definition: pdsinfo.c:114
float p[MODELMAX]
Definition: atrem_corl1.h:131
int scan_count
Definition: pdsinfo.c:113
int pkt_type
Definition: pdsinfo.c:112