OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
read_mask.c
Go to the documentation of this file.
1 /*
2  Modification history:
3  Programmer Organization Date Description of change
4  -------------- ------------ -------- ---------------------
5  Joel Gales Futuretech 058/06/01 Original Development
6 
7  */
8 
9 
10 #include <stdio.h>
11 #include <math.h>
12 #include "hdf.h"
13 
14 unsigned char read_mask(double lon, double lat, int16 close) {
15 
16  int16 nrec;
17  int16 header[1024];
18  int16 ptr_arr[1024 * 64];
19  static int16 cmpz[8 * 128];
20  int32 offset = -1;
21 
22  int32 ilon, ilat, i, j;
23 
24  unsigned char mask[128 * 128];
25  unsigned char zero = 0;
26  unsigned char one = 1;
27  unsigned char mask_lonlat = 0;
28 
29  static int32 first = 1;
30  static unsigned int pow2[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256,
31  512, 1024, 2048, 4096, 8192, 16384, 32768};
32  static FILE *maskfile;
33 
34  if (close == 1) {
35  fclose(maskfile);
36  return -one;
37  }
38 
39  if (first == 1) {
40  maskfile = fopen("/home/simbiosd/data/common/landmask_modland.dat", "r");
41  fread(header, sizeof (int16), 1024, maskfile);
42  nrec = header[1];
43 
44  fseek(maskfile, sizeof (header), SEEK_SET);
45  fread(ptr_arr, sizeof (int16), 1024 * 64, maskfile);
46  first = 0;
47  }
48 
49  ilon = floor(lon) + 180;
50  ilat = floor(lat) + 90;
51 
52  if (ptr_arr[360 * ilat + ilon] == 1) mask_lonlat = one;
53 
54  if (ptr_arr[360 * ilat + ilon] > 65) {
55  if (sizeof (int16)*1024 * ptr_arr[360 * ilat + ilon] != offset) {
56  offset = sizeof (int16)*1024 * ptr_arr[360 * ilat + ilon];
57 
58  fseek(maskfile, offset, SEEK_SET);
59  fread(cmpz, sizeof (int16), 8 * 128, maskfile);
60  }
61 
62  i = (lon - (ilon - 180)) * 128;
63  j = (lat - (ilat - 90)) * 128;
64 
65  if (i < 0) i = 128 + i;
66  if (j < 0) j = 128 + j;
67 
68  if ((cmpz[j * 8 + (i / 16)] & pow2[15 - (i % 16)]) != 0) mask_lonlat = one;
69  else mask_lonlat = zero;
70  }
71 
72  return mask_lonlat;
73 }
74 
75 #if 1
76 
77 /*
78 cc -o read_mask read_mask.c -g -I/systems04/home/simbiosd/lib/hdf/include -lm
79 
80  */
81 
82 main() {
83  int i, j;
84  double inlon, inlat;
85  unsigned char mask_lonlat, map[180 * 360];
86 
87  FILE *fp;
88 
89  /*
90 
91  for (i=-90; i<90; i++) {
92  for (j=-180; j<180; j++) {
93 
94  mask_lonlat=read_mask((double) (j*0.02+10), (double) (i*0.02-2), (int16) 0);
95  map[(i+90) * 360 + (j+180)] = mask_lonlat;
96  }
97  }
98  */
99 
100 loop:
101 
102  printf("Input lon lat: ");
103  scanf("%lf %lf", &inlon, &inlat);
104  if (inlon >= -180) {
105  mask_lonlat = read_mask(inlon, inlat, (int16) 0);
106  printf("%lf %lf %d\n", inlon, inlat, mask_lonlat);
107  goto loop;
108  }
109 
110  read_mask(inlon, inlat, (int16) 1);
111 
112  fp = fopen("map.dat", "wb");
113  fwrite(map, 1, 180 * 360, fp);
114  close(fp);
115 
116  /* map=bytarr(360,180)&openr,1,'map.dat'&readu,1,map&close,1&tv,bytscl(map,min=0,max=1) */
117 
118 }
119 
120 
121 #endif
122 
integer, parameter int16
Definition: cubeio.f90:3
int j
Definition: decode_rs.h:73
unsigned char read_mask(double lon, double lat, int16 close)
Definition: read_mask.c:14
float * lat
main()
Definition: read_mask.c:82
a context in which it is NOT documented to do so subscript which cannot be easily calculated when extracting TONS attitude data from the Terra L0 files Corrected several defects in extraction of entrained ephemeris and and as HDF file for both the L1A and Geolocation enabling retrieval of South Polar DEM data Resolved Bug by changing to opent the geolocation file only after a successful read of the L1A and also by checking for fatal errors from not restoring C5 and to report how many of those high resolution values were water in the new WaterPresent SDS Added valid_range attribute to Land SeaMask Changed to bilinearly interpolate the geoid_height to remove artifacts at one degree lines Made corrections to const qualification of pointers allowed by new version of M API library Removed casts that are no longer for same not the geoid Corrected off by one error in calculation of high resolution offsets Corrected parsing of maneuver list configuration parameter Corrected to set Height SDS to fill values when geolocation when for elevation and land water mask
Definition: HISTORY.txt:114
float * lon
l2prod offset
int i
Definition: decode_rs.h:71