OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
pqueue.c
Go to the documentation of this file.
1 
2 #include <pqueue.h>
3 
4 #include <check.h>
5 #include <stdarg.h>
6 #include <stdbool.h>
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12 
13 void print_double(void *item){
14  printf("%.2f", *(double*)item);
15 }
16 bool confirm_order(pqueue *pq, int n, ...){
17  va_list args;
18  va_start(args, n);
19  void *item;
20  int i;
21  for (i=0;i<n;i++){
22  item = pqueue_pull(pq);
23  if (item == NULL || *(double*)item != va_arg(args, double)){
24  va_end(args);
25  return false;
26  }
27  }
28  va_end(args);
29  return true;
30 }
31 void pqueue_push_multiple(pqueue *pq, int n, ...){
32  va_list args;
33  va_start(args, n);
34  int i;
35  for (i=0;i<n;i++){
36  double priority = va_arg(args, double);
37  double *item = va_arg(args, double*);
38  pqueue_push(pq, priority, item);
39  }
40  va_end(args);
41 }
42 
43 START_TEST(push_multiple){
44  pqueue *pq = pqueue_create(0);
45  double a = 9, b = 5, c = 3;
46  double one = 1, three = 3, five = 5;
47  pqueue_push_multiple(pq, 3, one, &a, five, &b, three, &c);
48  ck_assert(confirm_order(pq, 3, a, c, b));
49  pqueue_destroy(pq);
50 }
51 END_TEST
52 
53 START_TEST(push_to_start){
54  pqueue *pq = pqueue_create(0);
55  double a = 9, b = 5, c = 3;
56  double one = 1, three = 3, five = 5;
57  pqueue_push_multiple(pq, 3, three, &a, five, &b, one, &c);
58  ck_assert(confirm_order(pq, 3, c, a, b));
59  pqueue_destroy(pq);
60 }
61 END_TEST
62 
63 START_TEST(move_middle){
64  pqueue *pq = pqueue_create(0);
65  double a = 9, b = 5, c = 3;
66  double one = 1, three = 3, five = 5;
67  pqueue_push_multiple(pq, 3, one, &a, five, &b, three, &c);
68  pqueue_repush(pq, 6, &c);
69  ck_assert(confirm_order(pq, 3, a, b, c));
70  pqueue_destroy(pq);
71 }
72 END_TEST
73 
74 START_TEST(move_last){
75  pqueue *pq = pqueue_create(0);
76  double a = 9, b = 5, c = 3;
77  double one = 1, three = 3, five = 5;
78  pqueue_push_multiple(pq, 3, one, &a, five, &b, three, &c);
79  pqueue_repush(pq, 6, &b);
80  ck_assert(confirm_order(pq, 3, a, c, b));
81  pqueue_destroy(pq);
82 }
83 END_TEST
84 
85 START_TEST(move_first){
86  pqueue *pq = pqueue_create(0);
87  double a = 9, b = 5, c = 3;
88  double one = 1, three = 3, five = 5;
89  pqueue_push_multiple(pq, 3, one, &a, five, &b, three, &c);
90  pqueue_repush(pq, 6, &a);
91  ck_assert(confirm_order(pq, 3, c, b, a));
92  pqueue_destroy(pq);
93 }
94 END_TEST
95 
96 Suite* stub_suite(void){
97  Suite *s = suite_create("Stub");
98 
99  TCase *tc_core = tcase_create("Core");
100  tcase_add_test(tc_core, push_multiple);
101  tcase_add_test(tc_core, push_to_start);
102  tcase_add_test(tc_core, move_middle);
103  tcase_add_test(tc_core, move_last);
104  tcase_add_test(tc_core, move_first);
105  suite_add_tcase(s, tc_core);
106 
107  return s;
108 }
109 
110 int main(int argc, char **argv){
111  int number_failed;
112 
113  Suite *s = stub_suite();
114  SRunner *sr = srunner_create(s);
115 
116  srunner_run_all(sr, CK_VERBOSE);
117  number_failed = srunner_ntests_failed(sr);
118  srunner_free(sr);
119  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
120 }
#define EXIT_SUCCESS
Definition: GEO_basic.h:72
void pqueue_push(pqueue *pq, double priority, void *item)
Definition: pqueue-ll.c:34
#define NULL
Definition: decode_rs.h:63
END_TEST Suite * stub_suite(void)
Definition: pqueue.c:96
void pqueue_destroy(pqueue *pq)
Definition: pqueue-ll.c:24
void pqueue_push_multiple(pqueue *pq, int n,...)
Definition: pqueue.c:31
void pqueue_repush(pqueue *pq, double priority, void *item)
Definition: pqueue-ll.c:54
bool confirm_order(pqueue *pq, int n,...)
Definition: pqueue.c:16
data_t b[NROOTS+1]
Definition: decode_rs.h:77
void print_double(void *item)
Definition: pqueue.c:13
data_t s[NROOTS]
Definition: decode_rs.h:75
int main(int argc, char **argv)
Definition: pqueue.c:110
pqueue * pqueue_create()
Definition: pqueue-ll.c:18
void * pqueue_pull(pqueue *pq)
Definition: pqueue-ll.c:94
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed as required for compatibility with version of the SDP toolkit Corrected test output file names to end in per delivery and then split off a new MYD_PR03 pcf file for Aqua Added AssociatedPlatformInstrumentSensor to the inventory metadata in MOD01 mcf and MOD03 mcf Created new versions named MYD01 mcf and MYD03 where AssociatedPlatformShortName is rather than Terra The program itself has been changed to read the Satellite Instrument validate it against the input L1A and LUT and to use it determine the correct files to retrieve the ephemeris and attitude data from Changed to produce a LocalGranuleID starting with MYD03 if run on Aqua data Added the Scan Type file attribute to the Geolocation copied from the L1A and attitude_angels to radians rather than degrees The accumulation of Cumulated gflags was moved from GEO_validate_earth_location c to GEO_locate_one_scan c
Definition: HISTORY.txt:464
START_TEST(push_multiple)
Definition: pqueue.c:43
int i
Definition: decode_rs.h:71
PGE01 indicating that PGE02 PGE01 V6 for and PGE01 V2 for MOD03 were used to produce the granule By convention adopted in all MODIS Terra PGE02 code versions are The fourth digit of the PGE02 version denotes the LUT version used to produce the granule The source of the metadata environment variable ProcessingCenter was changed from a QA LUT value to the Process Configuration A sign used in error in the second order term was changed to a
Definition: HISTORY.txt:424