OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_del_limit_check.c
Go to the documentation of this file.
1 /* file: GEO_del_limit_check.c */
2 
3 #include "PGS_MODIS_35251.h"
4 #include "smfio.h"
5 #include "GEO_validation.h"
6 
8  double data_samples[],
9  int const number_of_samples,
10  double const delta_limit,
11  int sample_flags[]
12  )
13 /*
14 !C****************************************************************************
15 
16 !Description:
17  Routine in Input group of the Level-1A geolocation software to validate
18  a set of data samples by comparing differences between successive
19  samples against a limit. Previously flagged values are not checked.
20  Flags set to BAD_DATA for all samples not within limits.
21 
22 !Input Parameters:
23  data_samples array of input data samples
24  number_of_samples number of samples to check
25  delta_limit difference limit
26 
27 !Output Parameters:
28 
29 !Input/Output Parameters:
30  sample_flags array of validation flags with previously
31  invalidated samples flagged
32 
33 Return Values:
34  SUCCESS - if it can find at least one valid pair of values.
35  FAIL - otherwise
36 
37 Externally Defined:
38  BAD_DATA "GEO_validation.h"
39  FAIL "GEO_basic.h"
40  MODIS_E_BAD_INPUT_ARG "PGS_MODIS_35251.h"
41  MODIS_E_ONE_UNFLAG "PGS_MODIS_35251.h"
42  SUCCESS "GEO_basic.h"
43 
44 Called by:
45  GEO_prepare_mirr_data
46  GEO_validate_attit_data
47 
48 Routines Called:
49  GEO_find_next_flag
50  modsmf
51 
52 !Revision History:
53 $Log: GEO_del_limit_check.c,v $
54 Revision 4.2 2003/08/28 16:01:45 kuyper
55 Corrected prolog.
56 
57 Revision 4.1 2003/02/21 22:53:21 kuyper
58 Corrected to use void* pointers with %p format code.
59 
60 Revision 3.2 2001/03/16 20:55:05 kuyper
61 Changed to not return FAIL for number_of_samples = 0
62 
63 Revision 3.1 2001/03/07 19:33:25 kuyper
64 Major rewrite, to mark both sides of a sudden jump as bad.
65 
66 James.R.Kuyper.1@gsfc.nasa.gov
67 
68 Requirements:
69  PR03-F-2.4-1
70  PR03-F-2.4-2
71  PR03-F-2.5-1
72  PR03-F-2.5-2
73  PR03-F-2.5-3
74  PR03-I-1
75  PR03-I-2
76  PR03-S-1
77 
78 !Team-unique Header:
79  This software is developed by the MODIS Science Data Support
80  Team for the National Aeronautics and Space Administration,
81  Goddard Space Flight Center, under contract NAS5-32373.
82 
83 References and Credits
84 
85 Design Notes
86 
87 !END*************************************************************************
88  */
89 {
90 
91  /* Local variable declarations */
92 
93  double del = 0.0; /* absolute value of difference */
94  double limit = 0.0; /* limit value */
95  int num_valid = 0; /* number of valid data samples found */
96  int f1 = -1; /* array index */
97  int f2 = -1; /* array index */
98  char msgbuf[64];
99 
100  if(data_samples==NULL || sample_flags==NULL)
101  {
102  sprintf(msgbuf, "data_samples:%p sample_flags:%p",
103  (void*)data_samples, (void*)sample_flags);
104  modsmf(MODIS_E_BAD_INPUT_ARG, msgbuf, __FILE__ ", GEO_del_limit_check");
105 
106  return FAIL;
107  }
108  /* Begin program logic */
109  while( (f2=GEO_find_next_flag(sample_flags,number_of_samples,f2+1))>=0)
110  {
111  if(f1 < 0) /* First time */
112  num_valid++;
113  else
114  {
115  del = fabs(data_samples[f2] - data_samples[f1]);
116  limit = delta_limit * (double)(f2 - f1);
117  if (del > limit) {
118  if(sample_flags[f1] != BAD_DATA)
119  {
120  num_valid--; /* We counted it as valid earlier.*/
121  sample_flags[f1] = BAD_DATA;
122  }
123 
124  sample_flags[f2] = BAD_DATA;
125  }
126  else
127  num_valid++;
128  }
129 
130  f1 = f2;
131  }
132 
133  if (num_valid ==0 && number_of_samples > 0)
134  return FAIL;
135 
136  if (num_valid == 1)
137  modsmf(MODIS_E_ONE_UNFLAG, "", __FILE__ ", GEO_del_limit_check");
138 
139  return SUCCESS;
140 }
141 
#define SUCCESS
Definition: ObpgReadGrid.h:15
#define MODIS_E_ONE_UNFLAG
float f1(float x)
#define FAIL
Definition: ObpgReadGrid.h:18
int GEO_del_limit_check(double data_samples[], int const number_of_samples, double const delta_limit, int sample_flags[])
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_BAD_INPUT_ARG
const int BAD_DATA
float f2(float y)
integer, parameter double
#define fabs(a)
Definition: misc.h:93
int GEO_find_next_flag(int sample_flags[], int const number_of_samples, int const start_sample)