MISR Toolkit  1.5.1
biz.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = biz =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2005, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrToolkit.h"
18 #include "MisrError.h"
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <math.h>
22 
23 
24 
25 int biz( ) {
26 
27  MTKt_status status; /* For routine calls */
28  MTKt_status status_code; /* For error handler */
29  char *err_msg[] = MTK_ERR_DESC; /* Error message descriptions */
30 
31  double lat_dd = 32.2, lon_dd = -114.5;
32  double lat, lon;
33  double lat_extent = 200, lon_extent = 100;
34  double somx, somy;
35  int path, res;
36  float line, sample;
37  int block;
38  float blk_line, blk_sample;
39  int l, s;
40  int latdeg, londeg, latmin, lonmin;
41  double latsec, lonsec;
44  char datetime[MTKd_DATETIME_LEN];
45  char testroot[200];
46  char filename[200];
47  char gridname[200];
48  char fieldname[200];
50  MTKt_MapInfo brf_mapinfo = MTKT_MAPINFO_INIT;
52  MTKt_MapInfo hdrf_mapinfo = MTKT_MAPINFO_INIT;
53 
54  /* ---------------------------------------------------------- */
55  /* Set a file root from prompt or environment variable */
56  /* ---------------------------------------------------------- */
57  if( getenv("MTKHOME") ) {
58  strcpy(testroot, getenv("MTKHOME"));
59  strcat(testroot, "/../Mtk_testdata");
60  } else {
61  printf("MTKHOME environment variable not found.\n" \
62  "Please enter the path to Mtk_testdata directory" \
63  "(e.g. C:\\Mtk_testdata or /tmp/Mtk_testdata ):");
64  scanf("%s",testroot);
65  }
66 
67  /* ---------------------------------------------------------- */
68  /* Set a region given center latitude/longitude and an extent */
69  /* ---------------------------------------------------------- */
70 
71  status = MtkSetRegionByLatLonExtent(lat_dd, lon_dd,
72  lat_extent, lon_extent, "km", &region);
73  MTK_ERR_COND_JUMP(status);
74 
75  printf("region center lat/lon (dd) = (%f, %f)\n",
76  region.geo.ctr.lat, region.geo.ctr.lon);
77  printf(" region extent (m) = (%f, %f)\n",
78  region.hextent.xlat * 2.0, region.hextent.ylon * 2.0);
79 
80  /* --------------------------------------------------------- */
81  /* Read data in the region from filename/gridname/fieldname, */
82  /* do some coordinate conversions, query data buffer and */
83  /* get pixel time */
84  /* --------------------------------------------------------- */
85 
86  strcpy(filename,testroot);
87  strcat(filename, "/in/");
88  strcat(filename, "MISR_AM1_GRP_ELLIPSOID_GM_P037_O029058_AA_F03_0024.hdf");
89  strcpy(gridname, "RedBand");
90  strcpy(fieldname, "Red Brf");
91 
92  status = MtkReadData(filename, gridname, fieldname, region,
93  &brf_databuf, &brf_mapinfo);
94  MTK_ERR_COND_JUMP(status);
95 
96  status = MtkLatLonToLS(brf_mapinfo, lat_dd, lon_dd, &line, &sample);
97  MTK_ERR_COND_JUMP(status);
98 
99  l = (int)round(line);
100  s = (int)round(sample);
101 
102  status = MtkFileToPath(filename, &path);
103  MTK_ERR_COND_JUMP(status);
104 
105  status = MtkFileGridToResolution(filename, gridname, &res);
106  MTK_ERR_COND_JUMP(status);
107 
108  status = MtkLatLonToBls(path, res, lat_dd, lon_dd,
109  &block, &blk_line, &blk_sample);
110  MTK_ERR_COND_JUMP(status);
111 
112  status = MtkLSToLatLon(brf_mapinfo, line, sample, &lat, &lon);
113  MTK_ERR_COND_JUMP(status);
114 
115  status = MtkDdToDegMinSec(lat, &latdeg, &latmin, &latsec);
116  MTK_ERR_COND_JUMP(status);
117 
118  status = MtkDdToDegMinSec(lon, &londeg, &lonmin, &lonsec);
119  MTK_ERR_COND_JUMP(status);
120 
121  status = MtkLSToSomXY(brf_mapinfo, line, sample, &somx, &somy);
122  MTK_ERR_COND_JUMP(status);
123 
124  status = MtkTimeMetaRead(filename, &timemeta);
125  MTK_ERR_COND_JUMP(status);
126 
127  status = MtkPixelTime(timemeta, somx, somy, datetime);
128  MTK_ERR_COND_JUMP(status);
129 
130  printf("\n Reading file = %s\n",filename);
131  printf(" Reading grid = %s\n",gridname);
132  printf(" Reading field = %s\n",fieldname);
133  printf(" number of lines/samples = (%d, %d)\n",
134  brf_mapinfo.nline, brf_mapinfo.nsample);
135  printf(" input lat/lon (dd) = (%f, %f)\n", lat_dd, lon_dd);
136  printf(" line/sample = (%f, %f)\n", line, sample);
137  printf(" Brf[%d][%d] = %f\n", l, s, brf_databuf.data.f[l][s]),
138  printf(" block/line/sample = (%d, %f, %f)\n",
139  block, blk_line, blk_sample);
140  printf(" lat/lon (dd) = (%f, %f)\n", lat, lon);
141  printf(" lat/lon (dms) = (%d:%d:%f, %d:%d:%f)\n",
142  latdeg, latmin, latsec, londeg, lonmin, lonsec);
143  printf(" SOM x/y = (%f, %f)\n", somx, somy);
144  printf(" pixel time[%d][%d] = %s\n", l, s, datetime);
145 
146  MtkDataBufferFree(&brf_databuf);
147 
148  /* --------------------------------------------------------- */
149  /* Read data in the region from filename/gridname/fieldname */
150  /* with extra dimensions, do some coordinate conversions and */
151  /* query data buffer */
152  /* --------------------------------------------------------- */
153 
154  strcpy(filename,testroot);
155  strcat(filename, "/in/");
156  strcat(filename, "MISR_AM1_AS_LAND_P037_O029058_F06_0017.hdf");
157  strcpy(gridname, "SubregParamsLnd");
158  strcpy(fieldname, "LandHDRF[3][4]");
159 
160  status = MtkReadData(filename, gridname, fieldname, region,
161  &hdrf_databuf, &hdrf_mapinfo);
162  MTK_ERR_COND_JUMP(status);
163 
164  status = MtkLatLonToLS(hdrf_mapinfo, lat_dd, lon_dd, &line, &sample);
165  MTK_ERR_COND_JUMP(status);
166 
167  l = (int)round(line);
168  s = (int)round(sample);
169 
170  status = MtkFileToPath(filename, &path);
171  MTK_ERR_COND_JUMP(status);
172 
173  status = MtkFileGridToResolution(filename, gridname, &res);
174  MTK_ERR_COND_JUMP(status);
175 
176  status = MtkLatLonToBls(path, res, lat_dd, lon_dd,
177  &block, &blk_line, &blk_sample);
178  MTK_ERR_COND_JUMP(status);
179 
180  status = MtkLSToLatLon(hdrf_mapinfo, line, sample, &lat, &lon);
181  MTK_ERR_COND_JUMP(status);
182 
183  status = MtkDdToDegMinSec(lat, &latdeg, &latmin, &latsec);
184  MTK_ERR_COND_JUMP(status);
185 
186  status = MtkDdToDegMinSec(lon, &londeg, &lonmin, &lonsec);
187  MTK_ERR_COND_JUMP(status);
188 
189  status = MtkLatLonToSomXY(path, lat_dd, lon_dd, &somx, &somy);
190  MTK_ERR_COND_JUMP(status);
191 
192  printf("\n Reading file = %s\n",filename);
193  printf(" Reading grid = %s\n",gridname);
194  printf(" Reading field = %s\n",fieldname);
195  printf(" number of lines/samples = (%d, %d)\n",
196  hdrf_mapinfo.nline, hdrf_mapinfo.nsample);
197  printf(" input lat/lon (dd) = (%f, %f)\n", lat_dd, lon_dd);
198  printf(" line/sample = (%f, %f)\n", line, sample);
199  printf(" HDRF[%d][%d] = %f\n", l, s, hdrf_databuf.data.f[l][s]),
200  printf(" block/line/sample = (%d, %f, %f)\n",
201  block, blk_line, blk_sample);
202  printf(" lat/lon (dd) = (%f, %f)\n", lat, lon);
203  printf(" lat/lon (dms) = (%d:%d:%f, %d:%d:%f)\n",
204  latdeg, latmin, latsec, londeg, lonmin, lonsec);
205  printf(" SOM x/y = (%f, %f)\n", somx, somy);
206 
207  MtkDataBufferFree(&hdrf_databuf);
208 
209  return MTK_SUCCESS;
210  ERROR_HANDLE:
211  printf("Error: %s\n",err_msg[status_code]);
212  MtkDataBufferFree(&hdrf_databuf);
213  return status_code;
214 }
MTKt_status MtkLatLonToBls(int path, int resolution_meters, double lat_dd, double lon_dd, int *block, float *line, float *sample)
Convert decimal degrees latitude and longitude to block, line, sample.
#define MTKT_TIME_METADATA_INIT
Definition: MisrFileQuery.h:91
char * filename
Definition: cdjpeg.h:133
MTKt_DataBufferType data
Definition: MisrUtil.h:104
#define MTKT_MAPINFO_INIT
Definition: MisrMapQuery.h:79
MTKt_status MtkLSToLatLon(MTKt_MapInfo mapinfo, float line, float sample, double *lat_dd, double *lon_dd)
Convert line, sample to decimal degrees latitude and longitude.
Definition: MtkLSToLatLon.c:33
MTKt_GeoCenter geo
Definition: MisrSetRegion.h:42
#define MTKT_REGION_INIT
Definition: MisrSetRegion.h:46
MTKt_status MtkLSToSomXY(MTKt_MapInfo mapinfo, float line, float sample, double *som_x, double *som_y)
Convert line, sample to SOM X, SOM Y.
Definition: MtkLSToSomXY.c:33
MTKt_status MtkLatLonToLS(MTKt_MapInfo mapinfo, double lat_dd, double lon_dd, float *line, float *sample)
Convert decimal degrees latitude and longitude to line, sample.
Definition: MtkLatLonToLS.c:33
Map Information.
Definition: MisrMapQuery.h:65
int biz()
Definition: biz.c:25
2-dimensional Data Buffer
Definition: MisrUtil.h:98
MTKt_float ** f
Definition: MisrUtil.h:93
MTKt_GeoCoord ctr
Definition: MisrSetRegion.h:27
#define MTKT_DATABUFFER_INIT
Definition: MisrUtil.h:109
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
#define MTK_ERR_DESC
Definition: MisrError.h:91
MTKt_Extent hextent
Definition: MisrSetRegion.h:43
MTKt_status MtkReadData(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Reads any grid/field from any MISR product file and performs unpacking or unscaling. It also reads any MISR conventional product file.
Definition: MtkReadData.c:62
MTKt_status MtkSetRegionByLatLonExtent(double ctr_lat_dd, double ctr_lon_dd, double lat_extent, double lon_extent, const char *extent_units, MTKt_Region *region)
Select region by latitude, longitude in decimal degrees, and extent in specified units of degrees...
MTKt_status MtkTimeMetaRead(const char *filename, MTKt_TimeMetaData *time_metadata)
Read time metadata from L1B2 Ellipsoid product file.
Time Metadata.
Definition: MisrFileQuery.h:77
MTKt_status MtkPixelTime(MTKt_TimeMetaData time_metadata, double som_x, double som_y, char pixel_time[MTKd_DATETIME_LEN])
Given SOM Coordinates compute pixel time.
Definition: MtkPixelTime.c:41
MTKt_status MtkDdToDegMinSec(double dd, int *deg, int *min, double *sec)
Convert decimal degrees to unpacked degrees, minutes, seconds.
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
Region of interest.
Definition: MisrSetRegion.h:41
MTKt_status MtkFileToPath(const char *filename, int *path)
Read path number from file.
Definition: MtkFileToPath.c:35
#define MTKd_DATETIME_LEN
Definition: MisrUtil.h:149
MTKt_status MtkLatLonToSomXY(int path, double lat_dd, double lon_dd, double *som_x, double *som_y)
Convert decimal degrees latitude and longitude to SOM X, SOM Y.
MTKt_status MtkFileGridToResolution(const char *filename, const char *gridname, int *resolution)
Get resolution of a particular grid.

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