MISR Toolkit  1.5.1
misrfor.c
Go to the documentation of this file.
1 #include "misrproj.h" /* Prototype for this function */
2 #include "errormacros.h" /* Error macros */
3 #include <math.h> /* Prototype for floor */
4 
5 extern int nb;
6 extern int nl_var;
7 extern int ns;
8 extern float absOffset[NBLOCK];
9 extern double ulc[2];
10 extern double lrc[2];
11 extern double sx;
12 extern double sy;
13 extern double xc;
14 extern double yc;
15 
16 #define FUNC_NAMEm "misrfor"
17 
18 int misrfor(
19 const double x, /* Output SOM X coordinate */
20 const double y, /* Output SOM Y coordinate */
21 int* block, /* Input block */
22 float* line, /* Input line */
23 float* sample /* Input sample */
24 )
25 {
26  float i; /* Intermediate X coordinate */
27  float j; /* Intermediate Y coordinate */
28  int b; /* Intermediate block */
29  float l; /* Intermediate line */
30  float s; /* Intermediate sample */
31  char msg[STRLEN]; /* Warning message */
32 
33 /* Compute intermediate coordinates */
34 
35  i = (float)((x - xc) / sx);
36  j = (float)((y - yc) / sy);
37 
38 /* Check for very small numbers in i and j and assume they are zero */
39 
40  i = (fabs(i) < 1E-5 ? 0.0 : i);
41  j = (fabs(j) < 1E-5 ? 0.0 : j);
42 
43 /* Compute block and check range */
44 
45  b = (int)(floor((i + 0.5) / nl_var)) + 1;
46  if (b < 1 || b > nb) {
47  sprintf(msg, "block is out of range (1 < %d < %d)", b, nb);
48  WRN_LOG_JUMP(msg);
49  }
50 
51 /* Compute line and check range */
52 
53  l = (float)(i - ((b - 1) * nl_var));
54  if (l < -0.5 || l > nl_var - 0.5) {
55  sprintf(msg, "line is out of range (0 < %e < %d)", l, nl_var);
56  WRN_LOG_JUMP(msg);
57  }
58 
59 /* Compute sample and check range */
60 
61  s = (float)(j - absOffset[b-1]);
62  if (s < -0.5 || s > ns - 0.5) {
63  sprintf(msg, "sample is out of range (0 < %e < %d)", s, ns);
64  WRN_LOG_JUMP(msg);
65  }
66 
67 /* Set return values */
68 
69  *block = b;
70  *line = l;
71  *sample = s;
72 
73  return(0);
74 
75  ERROR_HANDLE:
76 
77  *block = -1;
78  *line = -1.0;
79  *sample = -1.0;
80  return(1);
81 }
int nl_var
Definition: misr_init.c:5
#define STRLEN
Definition: misrproj.h:6
double sy
Definition: misr_init.c:12
long b
Definition: jpegint.h:371
int ns
Definition: misr_init.c:6
float absOffset[NBLOCK]
Definition: misr_init.c:7
double xc
Definition: misr_init.c:13
int misrfor(const double x, const double y, int *block, float *line, float *sample)
Definition: misrfor.c:18
#define WRN_LOG_JUMP(msg)
Definition: errormacros.h:32
int nb
Definition: misr_init.c:4
#define NBLOCK
Definition: MisrProjParam.h:51
double yc
Definition: misr_init.c:14
double lrc[2]
Definition: misr_init.c:10
double ulc[2]
Definition: misr_init.c:9
double sx
Definition: misr_init.c:11

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51