main.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /****************************************************************************
  2. *
  3. * MODULE: i.modis.qc
  4. * AUTHOR(S): Yann Chemin - yann.chemin@gmail.com
  5. * PURPOSE: Converts Quality Control indicators into human readable classes
  6. * for Modis surface reflectance products 250m/500m
  7. * (MOD09Q/MOD09A), Modis LST (MOD11A1, MOD11A2), Modis Vegetation
  8. * (MOD13A2)
  9. *
  10. * COPYRIGHT: (C) 2008 -2011 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. * CHANGELOG: Added support MOD11A1 (Markus, December 2010)
  17. * Added support MOD13A2, MCD43B2 (Yann, January 2011)
  18. *
  19. *****************************************************************************/
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <grass/gis.h>
  24. #include <grass/raster.h>
  25. #include <grass/glocale.h>
  26. /* MOD09Q1 Products (250m, 8-Days) */
  27. CELL mod09Q1a(CELL pixel);
  28. CELL mod09Q1b(CELL pixel);
  29. CELL mod09Q1c(CELL pixel, int bandno);
  30. CELL mod09Q1d(CELL pixel);
  31. CELL mod09Q1e(CELL pixel);
  32. CELL mod09Q1f(CELL pixel);
  33. /* MOD09A1 Products (500m, 8-Days) */
  34. CELL mod09A1a(CELL pixel);
  35. CELL mod09A1c(CELL pixel, int bandno);
  36. CELL mod09A1d(CELL pixel);
  37. CELL mod09A1e(CELL pixel);
  38. /* MOD09A1 Products (500m, 8-Days, State QA) */
  39. CELL mod09A1sa(CELL pixel);
  40. CELL mod09A1sb(CELL pixel);
  41. CELL mod09A1sc(CELL pixel);
  42. CELL mod09A1sd(CELL pixel);
  43. CELL mod09A1se(CELL pixel);
  44. CELL mod09A1sf(CELL pixel);
  45. CELL mod09A1sg(CELL pixel);
  46. CELL mod09A1sh(CELL pixel);
  47. CELL mod09A1si(CELL pixel);
  48. CELL mod09A1sj(CELL pixel);
  49. CELL mod09A1sk(CELL pixel);
  50. /* MOD11A1 Products (1Km, daily) */
  51. CELL mod11A1a(CELL pixel);
  52. CELL mod11A1b(CELL pixel);
  53. CELL mod11A1c(CELL pixel);
  54. CELL mod11A1d(CELL pixel);
  55. /* MOD11A2 Products (1Km, 8-Days) */
  56. CELL mod11A2a(CELL pixel);
  57. CELL mod11A2b(CELL pixel);
  58. CELL mod11A2c(CELL pixel);
  59. CELL mod11A2d(CELL pixel);
  60. /* MOD13A2 Products (1Km, 16-Days) */
  61. CELL mod13A2a (CELL pixel);
  62. CELL mod13A2b (CELL pixel);
  63. CELL mod13A2c (CELL pixel);
  64. CELL mod13A2d (CELL pixel);
  65. CELL mod13A2e (CELL pixel);
  66. CELL mod13A2f (CELL pixel);
  67. CELL mod13A2g (CELL pixel);
  68. CELL mod13A2h (CELL pixel);
  69. CELL mod13A2i (CELL pixel);
  70. /* MCD43B2 Products (1Km, 8-Days)*/
  71. /* SDS: BRDF_Albedo_Ancilliary */
  72. CELL mcd43B2a(CELL pixel);
  73. CELL mcd43B2b(CELL pixel);
  74. CELL mcd43B2c(CELL pixel);
  75. /* SDS: BRDF_Albedo_Band_Quality */
  76. CELL mcd43B2qa(CELL pixel, int bandno);
  77. int main(int argc, char *argv[])
  78. {
  79. struct Cell_head cellhd; /*region+header info */
  80. int nrows, ncols;
  81. int row, col;
  82. char *qcflag; /*Switch for particular index */
  83. struct GModule *module;
  84. struct Option *productname, *qcname, *input, *input_band, *output;
  85. struct History history; /*metadata */
  86. struct Colors colors; /*Color rules */
  87. char *desc_productname, *desc_qcname, *desc_input_band;
  88. char *result; /*output raster name */
  89. /*File Descriptors */
  90. int infd;
  91. int outfd;
  92. char *product;
  93. char *qcchan;
  94. int bandno;
  95. CELL *inrast;
  96. CELL *outrast;
  97. RASTER_MAP_TYPE data_type_output = CELL_TYPE;
  98. CELL val1, val2;
  99. /************************************/
  100. G_gisinit(argv[0]);
  101. module = G_define_module();
  102. G_add_keyword(_("imagery"));
  103. G_add_keyword(_("imagery quality assessment"));
  104. G_add_keyword(_("reflectance"));
  105. G_add_keyword(_("land surface temperature"));
  106. G_add_keyword(_("vegetation"));
  107. G_add_keyword(_("MODIS"));
  108. module->description =
  109. _("Extracts quality control parameters from Modis QC layers.");
  110. /* Define the different options */
  111. input = G_define_standard_option(G_OPT_R_INPUT);
  112. input->description =
  113. _("Name of input surface reflectance QC layer [bit array]");
  114. output = G_define_standard_option(G_OPT_R_OUTPUT);
  115. output->key = "output";
  116. output->description =
  117. _("Name for output QC type classification layer");
  118. productname = G_define_option();
  119. productname->key = "productname";
  120. productname->type = TYPE_STRING;
  121. productname->required = YES;
  122. productname->description = _("Name of MODIS product type");
  123. desc_productname = NULL;
  124. G_asprintf(&desc_productname,
  125. "mod09Q1;%s;"
  126. "mod09A1;%s;"
  127. "mod09A1s;%s;"
  128. "mod11A1;%s;"
  129. "mod11A2;%s;"
  130. "mod13A2;%s;"
  131. "mcd43B2;%s;"
  132. "mcd43B2q;%s",
  133. _("surf. refl. 250m 8-days"),
  134. _("surf. refl. 500m 8-days"),
  135. _("surf. refl. 500m 8-days, State QA"),
  136. _("LST 1Km daily (Day/Night)"),
  137. _("LST 1Km 8-days (Day/Night)"),
  138. _("VI 1Km 16-days"),
  139. _("Brdf-Albedo Quality (Ancillary SDS) 1Km 8-days"),
  140. _("Brdf-Albedo Quality (BRDF SDS) 1Km 8-days"));
  141. productname->descriptions = desc_productname;
  142. productname->options = "mod09Q1,mod09A1,mod09A1s,mod11A1,mod11A2,mod13A2,mcd43B2,mcd43B2q";
  143. productname->answer = "mod13A2";
  144. qcname = G_define_option();
  145. qcname->key = "qcname";
  146. qcname->type = TYPE_STRING;
  147. qcname->required = YES;
  148. qcname->description = _("Name of QC type to extract");
  149. desc_qcname = NULL;
  150. G_asprintf(&desc_qcname,
  151. "adjcorr;%s;"
  152. "atcorr;%s;"
  153. "cloud;%s;"
  154. "data_quality;%s;"
  155. "diff_orbit_from_500m;%s;"
  156. "modland_qa;%s;"
  157. "mandatory_qa_11A1;%s;"
  158. "data_quality_flag_11A1;%s;"
  159. "emis_error_11A1;%s;"
  160. "lst_error_11A1;%s;"
  161. "data_quality_flag_11A2;%s;"
  162. "emis_error_11A2;%s;"
  163. "mandatory_qa_11A2;%s;"
  164. "lst_error_11A2;%s;"
  165. "aerosol_quantity;%s;"
  166. "brdf_correction_performed;%s;"
  167. "cirrus_detected;%s;"
  168. "cloud_shadow;%s;"
  169. "cloud_state;%s;"
  170. "internal_cloud_algorithm;%s;"
  171. "internal_fire_algorithm;%s;"
  172. "internal_snow_mask;%s;"
  173. "land_water;%s;"
  174. "mod35_snow_ice;%s;"
  175. "pixel_adjacent_to_cloud;%s;"
  176. "modland_qa;%s;"
  177. "vi_usefulness;%s;"
  178. "aerosol_quantity;%s;"
  179. "pixel_adjacent_to_cloud;%s;"
  180. "brdf_correction_performed;%s;"
  181. "mixed_clouds;%s;"
  182. "land_water;%s;"
  183. "possible_snow_ice;%s;"
  184. "possible_shadow;%s;"
  185. "platform;%s;"
  186. "land_water;%s;"
  187. "sun_z_angle_at_local_noon;%s;"
  188. "brdf_correction_performed;%s",
  189. _("mod09: Adjacency Correction"),
  190. _("mod09: Atmospheric Correction"),
  191. _("mod09: Cloud State"),
  192. _("mod09: Band-Wise Data Quality Flag"),
  193. _("mod09: 250m Band is at Different Orbit than 500m"),
  194. _("mod09: MODIS Land General Quality Assessment"),
  195. _("mod11A1: MODIS Land General Quality Assessment"),
  196. _("mod11A1: Detailed Quality Indications"),
  197. _("mod11A1: Average Emissivity Error Classes"),
  198. _("mod11A1: Average LST Error Classes"),
  199. _("mod11A2: Detailed Quality Indications"),
  200. _("mod11A2: Average Emissivity Error Classes"),
  201. _("mod11A2: MODIS Land General Quality Assessment"),
  202. _("mod11A2: Average LST Error Classes"),
  203. _("mod09A1s: StateQA Internal Snow Mask"),
  204. _("mod09A1s: StateQA Internal Snow Mask"),
  205. _("mod09A1s: StateQA Internal Snow Mask"),
  206. _("mod09A1s: StateQA Internal Snow Mask"),
  207. _("mod09A1s: StateQA Internal Snow Mask"),
  208. _("mod09A1s: StateQA Internal Snow Mask"),
  209. _("mod09A1s: StateQA Internal Snow Mask"),
  210. _("mod09A1s: StateQA Internal Snow Mask"),
  211. _("mod09A1s: StateQA Internal Snow Mask"),
  212. _("mod09A1s: StateQA Internal Snow Mask"),
  213. _("mod09A1s: StateQA Internal Snow Mask"),
  214. _("mod13A2: MODIS Land General Quality Assessment"),
  215. _("mod13A2: Quality estimation of the pixel"),
  216. _("mod13A2: Quantity range of Aerosol"),
  217. _("mod13A2: if pixel is a cloud neighbour"),
  218. _("mod13A2: if BRDF correction performed"),
  219. _("mod13A2: if pixel mixed with clouds"),
  220. _("mod13A2: separate land from various water objects"),
  221. _("mod13A2: if snow/ice present in pixel"),
  222. _("mod13A2: if shadow is present in pixel"),
  223. _("mcd43B2: Quality of BRDF correction performed"),
  224. _("mcd43B2: Quality of BRDF correction performed"),
  225. _("mcd43B2: Quality of BRDF correction performed"),
  226. _("mcd43B2q: Quality of BRDF correction performed"));
  227. qcname->descriptions = desc_qcname;
  228. qcname->options = "adjcorr,atcorr,cloud,data_quality,diff_orbit_from_500m,modland_qa,mandatory_qa_11A1,data_quality_flag_11A1,emis_error_11A1,lst_error_11A1,data_quality_flag_11A2,emis_error_11A2,mandatory_qa_11A2,lst_error_11A2,aerosol_quantity,brdf_correction_performed,cirrus_detected,cloud_shadow,cloud_state,internal_cloud_algorithm,internal_fire_algorithm,internal_snow_mask,land_water,mod35_snow_ice,pixel_adjacent_to_cloud,modland_qa,vi_usefulness,aerosol_quantity,pixel_adjacent_to_cloud,brdf_correction_performed,mixed_clouds,land_water,possible_snow_ice,possible_shadow,platform,land_water,sun_z_angle_at_local_noon,brdf_correction_performed";
  229. qcname->answer = "modland_qa";
  230. input_band = G_define_option();
  231. input_band->key = "band";
  232. input_band->type = TYPE_STRING;
  233. input_band->required = NO;
  234. input_band->description =
  235. _("Band number of Modis product (mod09Q1=[1,2],mod09A1=[1-7], mcd43B2q=[1-7])");
  236. desc_input_band = NULL;
  237. G_asprintf(&desc_input_band,
  238. "1;%s;2;%s;3;%s;4;%s;5;%s;6;%s;7;%s",
  239. _("Band 1: Red"),
  240. _("Band 2: NIR"),
  241. _("Band 3: Blue"),
  242. _("Band 4: Green"),
  243. _("Band 5: SWIR 1"),
  244. _("Band 6: SWIR 2"),
  245. _("Band 7: SWIR 3"));
  246. input_band->descriptions = desc_input_band;
  247. input_band->options = "1,2,3,4,5,6,7";
  248. /********************/
  249. if (G_parser(argc, argv))
  250. exit(EXIT_FAILURE);
  251. product = productname->answer;
  252. qcflag = qcname->answer;
  253. qcchan = input->answer;
  254. if (input_band->answer)
  255. bandno = atoi(input_band->answer);
  256. result = output->answer;
  257. /*mod09Q1*/
  258. if ((strcmp(qcflag, "cloud") && !(strcmp(product, "mod09Q1"))) ||
  259. (strcmp(qcflag, "diff_orbit_from_500m") && !(strcmp(product, "mod09Q1"))))
  260. G_fatal_error(_("This flag is only available for MOD09Q1 @ 250m products"));
  261. if (!strcmp(qcflag, "data_quality")) {
  262. if (bandno < 1 || bandno > 7)
  263. G_fatal_error(_("Band number out of allowed range [1-7]"));
  264. if (!strcmp(product, "mod09Q1") && bandno > 2)
  265. G_fatal_error(_("mod09Q1 product only has 2 bands"));
  266. }
  267. /*mod09A1*/
  268. if ((strcmp(qcflag, "cirrus_detected") && !(strcmp(product, "mod09A1s"))) ||
  269. (strcmp(qcflag, "cloud_shadow") && !(strcmp(product, "mod09A1s"))) ||
  270. (strcmp(qcflag, "cloud_state") && !(strcmp(product, "mod09A1s"))) ||
  271. (strcmp(qcflag, "internal_cloud_algorithm") && !(strcmp(product, "mod09A1s"))) ||
  272. (strcmp(qcflag, "internal_fire_algorithm") && !(strcmp(product, "mod09A1s"))) ||
  273. (strcmp(qcflag, "internal_snow_mask") && !(strcmp(product, "mod09A1s"))) ||
  274. (strcmp(qcflag, "mod35_snow_ice") && !(strcmp(product, "mod09A1s"))))
  275. G_fatal_error(_("This flag is only available for MOD09A1s @ 500m products"));
  276. /*mod13A2*/
  277. if ((strcmp(qcflag, "vi_usefulness") && !(strcmp(product, "mod13A2"))) ||
  278. (strcmp(qcflag, "mixed_clouds") && !(strcmp(product, "mod13A2"))) ||
  279. (strcmp(qcflag, "possible_snow_ice") && !(strcmp(product, "mod13A2"))) ||
  280. (strcmp(qcflag, "possible_shadow") && !(strcmp(product, "mod13A2"))))
  281. G_fatal_error(_("This flag is only available for MOD13A2 @ 1Km products"));
  282. /*mcd43B2*/
  283. if ((strcmp(qcflag, "platform") && !(strcmp(product, "mcd43B2"))) ||
  284. (strcmp(qcflag, "land_water") && !(strcmp(product, "mcd43B2"))) ||
  285. (strcmp(qcflag, "sun_z_angle_at_local_noon") && !(strcmp(product, "mcd43B2"))))
  286. G_fatal_error(_("This flag is only available for MCD43B2 @ 1Km products"));
  287. /*mcd43B2q*/
  288. if (strcmp(product, "mcd43B2q") && (bandno < 1 || bandno > 7))
  289. G_fatal_error(_("Band number out of allowed range [1-7]"));
  290. infd = Rast_open_old(qcchan, "");
  291. Rast_get_cellhd(qcchan, "", &cellhd);
  292. inrast = Rast_allocate_c_buf();
  293. G_debug(3, "number of rows %d", cellhd.rows);
  294. nrows = Rast_window_rows();
  295. ncols = Rast_window_cols();
  296. outrast = Rast_allocate_c_buf();
  297. /* Create New raster files */
  298. outfd = Rast_open_new(result, data_type_output);
  299. /* Process pixels */
  300. for (row = 0; row < nrows; row++)
  301. {
  302. CELL c;
  303. G_percent(row, nrows, 2);
  304. Rast_get_c_row(infd, inrast, row);
  305. /*process the data */
  306. for (col = 0; col < ncols; col++)
  307. {
  308. c = inrast[col];
  309. if (Rast_is_c_null_value(&c))
  310. Rast_set_c_null_value(&outrast[col], 1);
  311. else if (!strcmp(product, "mod09A1"))
  312. {
  313. if (!strcmp(qcflag, "modland_qa"))
  314. /*calculate modland QA bits extraction */
  315. c = mod09A1a(c);
  316. if (!strcmp(qcflag, "data_quality"))
  317. /*calculate modland QA bits extraction */
  318. c = mod09A1c(c, bandno);
  319. if (!strcmp(qcflag, "atcorr"))
  320. /*calculate atmospheric correction flag */
  321. c = mod09A1d(c);
  322. if (!strcmp(qcflag, "adjcorr"))
  323. /*calculate adjacency correction flag */
  324. c = mod09A1e(c);
  325. }
  326. else if (!strcmp(product, "mod09Q1"))
  327. {
  328. if (!strcmp(qcflag, "modland_qa"))
  329. /*calculate modland QA bits extraction */
  330. c = mod09Q1a(c);
  331. if (!strcmp(qcflag, "cloud"))
  332. /*calculate cloud state */
  333. /* ONLY 250m product! */
  334. c = mod09Q1b(c);
  335. if (!strcmp(qcflag, "data_quality"))
  336. /*calculate modland QA bits extraction */
  337. c = mod09Q1c(c, bandno);
  338. if (!strcmp(qcflag, "atcorr"))
  339. /*calculate atmospheric correction flag */
  340. c = mod09Q1d(c);
  341. if (!strcmp(qcflag, "adjcorr"))
  342. /*calculate adjacency correction flag */
  343. c = mod09Q1e(c);
  344. if (!strcmp(qcflag, "diff_orbit_from_500m"))
  345. /*calculate different orbit from 500m flag */
  346. c = mod09Q1f(c);
  347. }
  348. else if (!strcmp(product, "mod11A1"))
  349. {
  350. if (!strcmp(qcflag, "mandatory_qa"))
  351. /*calculate mod11A1 mandatory qa flags */
  352. c = mod11A1a(c);
  353. if (!strcmp(qcflag, "data_quality_flag"))
  354. /*calculate mod11A1 data quality flag */
  355. c = mod11A1b(c);
  356. if (!strcmp(qcflag, "emis_error"))
  357. /*calculate mod11A1 emissivity error flag */
  358. c = mod11A1c(c);
  359. if (!strcmp(qcflag, "lst_error"))
  360. /*calculate mod11A1 lst error flag */
  361. c = mod11A1d(c);
  362. }
  363. else if (!strcmp(product, "mod11A2"))
  364. {
  365. if (!strcmp(qcflag, "mandatory_qa"))
  366. /*calculate mod11A2 mandatory qa flags */
  367. c = mod11A2a(c);
  368. if (!strcmp(qcflag, "data_quality_flag"))
  369. /*calculate mod11A2 data quality flag */
  370. c = mod11A2b(c);
  371. if (!strcmp(qcflag, "emis_error"))
  372. /*calculate mod11A2 emissivity error flag */
  373. c = mod11A2c(c);
  374. if (!strcmp(qcflag, "lst_error"))
  375. /*calculate mod11A2 lst error flag */
  376. c = mod11A2d(c);
  377. }
  378. else if (!strcmp(product, "mod09A1s"))
  379. {
  380. if (!strcmp(qcflag, "cloud_state"))
  381. /*calculate mod09A1s cloud state flag */
  382. c = mod09A1sa(c);
  383. if (!strcmp(qcflag, "cloud_shadow"))
  384. /*calculate mod09A1s cloud shadow flag */
  385. c = mod09A1sb(c);
  386. if (!strcmp(qcflag, "land_water"))
  387. /*calculate mod09A1s land/water flag */
  388. c = mod09A1sc(c);
  389. if (!strcmp(qcflag, "aerosol_quantity"))
  390. /*calculate mod09A1s aerosol quantity flag */
  391. c = mod09A1sd(c);
  392. if (!strcmp(qcflag, "cirrus_detected"))
  393. /*calculate mod09A1s cirrus detected flag */
  394. c = mod09A1se(c);
  395. if (!strcmp(qcflag, "internal_cloud_algorithm"))
  396. /*calculate mod09A1s internal cloud algorithm flag */
  397. c = mod09A1sf(c);
  398. if (!strcmp(qcflag, "internal_fire_algorithm"))
  399. /*calculate mod09A1s internal fire algorithm flag */
  400. c = mod09A1sg(c);
  401. if (!strcmp(qcflag, "mod35_snow_ice"))
  402. /*calculate mod09A1s MOD35 snow/ice flag */
  403. c = mod09A1sh(c);
  404. if (!strcmp(qcflag, "pixel_adjacent_to_cloud"))
  405. /*calculate mod09A1s pixel adjacent to cloud flag */
  406. c = mod09A1si(c);
  407. if (!strcmp(qcflag, "brdf_correction_performed"))
  408. /*calculate mod09A1s BRDF correction performed flag */
  409. c = mod09A1sj(c);
  410. if (!strcmp(qcflag, "internal_snow_mask"))
  411. /*calculate mod09A1s internal snow mask flag */
  412. c = mod09A1sk(c);
  413. }
  414. else if (!strcmp(product, "mod13A2"))
  415. {
  416. if (!strcmp(qcflag, "modland_qa"))
  417. /*calculate mod11A2 MODIS Land Quality flags */
  418. c = mod13A2a(c);
  419. if (!strcmp(qcflag, "vi_usefulness"))
  420. /*calculate mod13A2 estimate of vi usefulness flag */
  421. c = mod13A2b(c);
  422. if (!strcmp(qcflag, "aerosol_quantity"))
  423. /*calculate mod13A2 aerosol quantity range flag */
  424. c = mod13A2c(c);
  425. if (!strcmp(qcflag, "pixel_adjacent_to_cloud"))
  426. /*calculate mod13A2 adjacent cloud detected flag */
  427. c = mod13A2d(c);
  428. if (!strcmp(qcflag, "brdf_correction_performed"))
  429. /*calculate mod13A2 BRDF correction performed flag */
  430. c = mod13A2e(c);
  431. if (!strcmp(qcflag, "mixed_clouds"))
  432. /*calculate mod13A2 pixel has clouds flag */
  433. c = mod13A2f(c);
  434. if (!strcmp(qcflag, "land_water"))
  435. /*calculate mod13A2 land and water types screening flag */
  436. c = mod13A2g(c);
  437. if (!strcmp(qcflag, "possible_snow_ice"))
  438. /*calculate mod13A2 possible presence of snow or ice flag */
  439. c = mod13A2h(c);
  440. if (!strcmp(qcflag, "possible_shadow"))
  441. /*calculate mod13A2 possible presence of shadow flag */
  442. c = mod13A2i(c);
  443. }
  444. else if (!strcmp(product, "mcd43B2"))
  445. {
  446. if (!strcmp(qcflag, "platform"))
  447. /*calculate mcd43B2: SDS: BRDF_Albedo_Ancillary */
  448. /* Satellite platform identification flag */
  449. c = mcd43B2a(c);
  450. if (!strcmp(qcflag, "land_water"))
  451. /*calculate mcd43B2: SDS: BRDF_Albedo_Ancillary */
  452. /* Land Water types in pixel flag */
  453. c = mcd43B2b(c);
  454. if (!strcmp(qcflag, "sun_z_angle_at_local_noon"))
  455. /*calculate mcd43B2: SDS: BRDF_Albedo_Ancillary */
  456. /* Sun Zenith Angle at Local Solar Noon flag */
  457. c = mcd43B2c(c);
  458. }
  459. else if (!strcmp(product, "mcd43B2q"))
  460. {
  461. if (!strcmp(qcflag, "brdf_correction_performed"))
  462. /*calculate mcd43B2: SDS: BRDF_Albedo_Band_Quality */
  463. /* BRDF correction performed Quality flag */
  464. c = mcd43B2qa(c, bandno);
  465. }
  466. else
  467. G_fatal_error(_("Unknown names and/or combination, please check spelling"));
  468. outrast[col] = c;
  469. }
  470. Rast_put_c_row(outfd, outrast);
  471. }
  472. G_free(inrast);
  473. Rast_close(infd);
  474. G_free(outrast);
  475. Rast_close(outfd);
  476. /* Color from 0 to 10 in grey */
  477. Rast_init_colors(&colors);
  478. val1 = 0;
  479. val2 = 10;
  480. Rast_add_c_color_rule(&val1, 0, 0, 0, &val2, 255, 255, 255, &colors);
  481. Rast_short_history(result, "raster", &history);
  482. Rast_command_history(&history);
  483. Rast_write_history(result, &history);
  484. exit(EXIT_SUCCESS);
  485. }