OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
main_lonlat2pixline.c
Go to the documentation of this file.
1 /* ========================================================================
2  * MSscanpixlimits - Determines bounding scans and pixels for given lon/lat box
3  *
4  * Synopsis:
5  *
6  * MSscanpixlimits input-filename [geo file] SW-lon SW-lat NE-lon NE-lat
7  *
8  * Description:
9  *
10  * Modification history:
11  *
12  * Programmer Organization Date Description of change
13  * -------------- ------------ -------- ---------------------
14  * Joel M. Gales Futuretech 20 Sept 1999 Original Development
15  * Joel M. Gales Futuretech 29 Sept 2000 Perform single pixel
16  * search within initial
17  * scan loop.
18  * Joel M. Gales Futuretech 03 Oct 2000 Change uv, uvpix, maxcos
19  * and dot to float64
20  *
21  * Joel M. Gales Futuretech 08 Nov 2006 Processes both MODIS &
22  * non-MODIS L1 & L2 granules
23  * (OCTS, CZCS, SEAWIFS)
24  *
25  * Joel M. Gales Futuretech 08 Feb 2007 Remove obsolete argc=3,5
26  * cases.
27  * Update usage statement
28  * Set ver# to 6.00
29  *
30  * Joel M. Gales Futuretech 12 Feb 2007 Put back argc=3,5
31  * cases.
32  * Update usage statement
33  * Set ver# to 6.01
34  *
35  * Joel M. Gales Futuretech 22 Feb 2007 Subtract extract pixel
36  * offset if present
37  * Set ver# to 6.03
38  *
39  * Joel M. Gales Futuretech 13 Mar 2007 Subtract extract pixel
40  * offset for pixsrch also
41  * Set ver# to 6.04
42  *
43  * Joel M. Gales Futuretech 15 Mar 2007 Move executable code to
44  * after declaration statements
45  *
46  * Joel M. Gales Futuretech 16 May 2007 Reset min scan & pix to -1
47  * if region not found
48  *
49  * Joel M. Gales Futuretech 15 Oct 2007 Add support for box
50  * extraction
51  * * ======================================================================== */
52 
53 #include <stdio.h>
54 #include <string.h>
55 #include <math.h>
56 #include <unistd.h>
57 
58 #include "lonlat2pixline.h"
59 
60 #define CMD_ARGS "+x:y:r:o:Fv" /* Valid commandline options */
61 #define VERSION_SPL "6.5.2"
62 
63 void usage(const char *prog) {
64  printf("%s %s (%s %s)\n",
65  "lonlat2pixline", VERSION_SPL, __DATE__, __TIME__);
66  printf("Usage (box): %s [-x box-halfwidth] [-y box-halfheight] [-r res]\n", prog);
67  printf(" [-v] infile [geofile] SWlon SWlat NElon NElat\n");
68  printf("Usage (pix): %s [-x box-halfwidth] [-y box-halfheight] [-r res]\n", prog);
69  printf(" [-v] [-F] infile [geofile] lon lat\n");
70  printf("where:\n");
71  printf(" infile is either a L1B, L2, or GEO filename\n");
72  printf(" geofile is the GEO filename used for MODIS L1B or VIIRS L1 files\n");
73  printf(" -r res resolution for MODIS Files (1000,500,250)\n");
74  printf(" -x val min number of pixels on either side of location to include\n");
75  printf(" -y val min number of scan lines on top and bottom of location to include\n");
76  printf(" -F return 110 if full-box can't be extracted and\n");
77  printf(" 120 if full file would be extracted\n");
78  printf(" -v print more verbose messages\n");
79  printf(" -o file output to file instead of stdout\n");
80  printf(" return 0 everything OK\n");
81  printf(" 100 location not found in scene\n");
82  printf(" 110 full box not extracted using the -F option\n");
83  printf(" 120 the whole file is inside the given coordinates, using -F\n");
84  printf(" other error number\n\n");
85 
86  exit(FATAL_ERROR);
87 }
88 
89 /* -------------------------------------------------------------------- *
90  * main *
91  * -------------------------------------------------------------------- */
92 int main(int argc, char *argv[]) {
93  int result;
94  int32_t want_FAIL = 0;
95  char* ofileName = NULL;
96  FILE* ofile = stdout;
97 
98  lonlat2pixline_t params;
99 
100  /* Parameters for getopt() */
101  extern int opterr;
102  extern int optind;
103  extern char *optarg;
104  int c;
105 
106  cdata_();
107 
108  // set some normal defaults
109  params.want_pixbox = 0;
110  params.pix_srch = 0;
111  params.resolution = -1;
112  params.xbox = 0;
113  params.ybox = 0;
114  params.geo_filename[0] = 0;
115 
116  want_verbose = 0;
117 
118  while ((c = getopt(argc, argv, CMD_ARGS)) != EOF) {
119  switch (c) {
120  case 'x':
121  params.xbox = atoi(optarg);
122  if (params.xbox != 0 && params.ybox == 0)
123  params.ybox = params.xbox;
124  params.want_pixbox = 1;
125  break;
126  case 'y':
127  params.ybox = atoi(optarg);
128  if (params.xbox == 0 && params.ybox != 0)
129  params.xbox = params.ybox;
130  params.want_pixbox = 1;
131  break;
132  case 'r':
133  params.resolution = atoi(optarg);
134  break;
135  case 'F':
136  want_FAIL = 1;
137  break;
138  case 'v':
139  want_verbose = 1;
140  break;
141  case 'o':
142  ofileName = optarg;
143  break;
144  default:
145  usage(argv[0]);
146  break;
147  }
148  }
149 
150  if (ofileName != NULL) {
151  ofile = fopen(ofileName, "w");
152  if (ofile == NULL) {
153  printf("-E- Can not open %s as output file\n", ofileName);
154  exit(EXIT_FAILURE);
155  }
156  }
157 
158  /* */
159  /* Process required command-line arguments */
160  /* */
161  switch (argc - optind + 1) {
162  case 4:
163  strcpy(params.input_filename, argv[1 + optind - 1]);
164  params.SWlon = atof(argv[2 + optind - 1]);
165  params.SWlat = atof(argv[3 + optind - 1]);
166  params.pix_srch = 1;
167  break;
168  case 5:
169  strcpy(params.input_filename, argv[1 + optind - 1]);
170  strcpy(params.geo_filename, argv[2 + optind - 1]);
171  params.SWlon = atof(argv[3 + optind - 1]);
172  params.SWlat = atof(argv[4 + optind - 1]);
173  params.pix_srch = 1;
174  break;
175  case 6:
176  strcpy(params.input_filename, argv[1 + optind - 1]);
177  params.SWlon = atof(argv[2 + optind - 1]);
178  params.SWlat = atof(argv[3 + optind - 1]);
179  params.NElon = atof(argv[4 + optind - 1]);
180  params.NElat = atof(argv[5 + optind - 1]);
181  if ((params.SWlon == params.NElon) && (params.SWlat == params.NElat)) {
182  params.pix_srch = 1;
183  } else {
184  params.pix_srch = 0;
185  }
186  break;
187  case 7:
188  strcpy(params.input_filename, argv[1 + optind - 1]);
189  strcpy(params.geo_filename, argv[2 + optind - 1]);
190  params.SWlon = atof(argv[3 + optind - 1]);
191  params.SWlat = atof(argv[4 + optind - 1]);
192  params.NElon = atof(argv[5 + optind - 1]);
193  params.NElat = atof(argv[6 + optind - 1]);
194  if ((params.SWlon == params.NElon) && (params.SWlat == params.NElat)) {
195  params.pix_srch = 1;
196  } else {
197  params.pix_srch = 0;
198  }
199  break;
200  default:
201  usage(argv[0]);
202  break;
203  }
204 
206 
207  if ((result == 110 || result == 120) && !want_FAIL) {
208  result = 0;
209  }
210 
211  if (result && (result != 110) && (result != 120)) {
212  exit(result);
213  }
214 
215  if (params.pix_srch) {
216  fprintf(ofile, "#Lon=%f\n", params.pixLon);
217  fprintf(ofile, "#Lat=%f\n", params.pixLat);
218  } else {
219  fprintf(ofile, "# %d %d %d %d\n", params.spixl, params.epixl,
220  params.sline, params.eline);
221  }
222 
223  fprintf(ofile, "sline=%d\n", params.sline);
224  fprintf(ofile, "eline=%d\n", params.eline);
225  fprintf(ofile, "spixl=%d\n", params.spixl);
226  fprintf(ofile, "epixl=%d\n", params.epixl);
227  if (ofileName != NULL) {
228  fprintf(ofile, "status=%d\n", result);
229  fclose(ofile);
230  }
231 
232  exit(result);
233 }
#define NULL
Definition: decode_rs.h:63
void usage(const char *prog)
#define VERSION_SPL
#define CMD_ARGS
void cdata_()
#define FATAL_ERROR
Definition: swl0_parms.h:5
int want_verbose
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
int lonlat2pixline(lonlat2pixline_t *params)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int main(int argc, char *argv[])