[GRASS-SVN] r33697 - grass/trunk/imagery/i.qc.modis

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 6 09:39:01 EDT 2008


Author: ychemin
Date: 2008-10-06 09:39:01 -0400 (Mon, 06 Oct 2008)
New Revision: 33697

Modified:
   grass/trunk/imagery/i.qc.modis/i.qc.modis.html
   grass/trunk/imagery/i.qc.modis/main.c
   grass/trunk/imagery/i.qc.modis/qc250a.c
   grass/trunk/imagery/i.qc.modis/qc250b.c
   grass/trunk/imagery/i.qc.modis/qc250c.c
   grass/trunk/imagery/i.qc.modis/qc250d.c
   grass/trunk/imagery/i.qc.modis/qc250e.c
   grass/trunk/imagery/i.qc.modis/qc250f.c
   grass/trunk/imagery/i.qc.modis/qc500a.c
   grass/trunk/imagery/i.qc.modis/qc500c.c
   grass/trunk/imagery/i.qc.modis/qc500d.c
   grass/trunk/imagery/i.qc.modis/qc500e.c
Log:
rewrite of module

Modified: grass/trunk/imagery/i.qc.modis/i.qc.modis.html
===================================================================
--- grass/trunk/imagery/i.qc.modis/i.qc.modis.html	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/i.qc.modis.html	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,55 +1,89 @@
 <H2>DESCRIPTION</H2>
 
-<EM>i.qc.modis</EM> Extracts Requested Quality Assessment flags from Modis 09 A and Q products.
+<EM>i.qc.modis</EM> Extracts Requested Quality Assessment flags from Modis 09 A and Q products 
+(Surface_reflectance_250/500m_quality_control_flags).
+This does not yet include QA_state_500m layer (see Notes and TODO).
 
+<pre>
 <EM>MODLAND QA Bits 250m/500m bits[0-1]</EM>
-[00]= class 1: Corrected product produced at ideal quality -- all bands
-[01]= class 2: Corrected product produced at less than idel quality -- some or all bands
-[10]= class 3: Corrected product NOT produced due to cloud effect -- all bands
-[11]= class 4: Corrected product NOT produced due to other reasons -- some or all bands maybe be fill value (Note that a value of [11] overrides a value of [01])
+</pre>
+<ul>
+ <li>[00]= class 0: Corrected product produced at ideal quality -- all bands</li>
+ <li>[01]= class 1: Corrected product produced at less than ideal quality -- some or all bands</li>
+ <li>[10]= class 2: Corrected product NOT produced due to cloud effect -- all bands</li>
+ <li>[11]= class 3: Corrected product NOT produced due to other reasons -- some or all bands maybe be fill value (Note that a value of [11] overrides a value of [01])</li>
+</ul>
 
-<EM> Cloud State 250m Unsigned Int bits[2-3] </EM>
-[00]= class 1: Clear -- No clouds
-[01]= class 2: Cloudy
-[10]= class 3: Mixed
-[11]= class 4: Not Set ; Assumed Clear
+<pre>
+<EM>Cloud State 250m Unsigned Int bits[2-3] </EM>
+</pre>
+<ul>
+ <li>[00]= class 0: Clear -- No clouds</li>
+ <li>[01]= class 1: Cloudy</li>
+ <li>[10]= class 2: Mixed</li>
+ <li>[11]= class 3: Not Set ; Assumed Clear</li>
+</ul>
 
-<EM> Band-wise Data Quality 250m Unsigned Int bits[4-7][8-11]</EM>
-<EM> Band-wise Data Quality 500m long Int bits[2-5][6-9][10-13][14-17][18-21][22-25][26-29]</EM>
-[0000]= class 1: highest quality
-[0111]= class 2: noisy detector
-[1000]= class 3: dead detector; data interpolated in L1B
-[1001]= class 4: solar zenith ge 86 degrees
-[1010]= class 5: solar zenith ge 85 and lt 86 degrees
-[1011]= class 6: missing input
-[1100] class 7: internal constant used in place of climatological data for at least one atmospheric constant
-[1101]= class 8: correction out of bounds, pixel constrained to extreme allowable value
-[1110]= class 9: L1B data faulty
-[1111]= class 10: not processed due to deep ocean or cloud
-Class 11: Combination of bits unused
+<pre>
+<EM>Band-wise Data Quality 250m Unsigned Int bits[4-7][8-11]</EM>
+<EM>Band-wise Data Quality 500m long Int bits[2-5][6-9][10-13][14-17][18-21][22-25][26-29]</EM>
+</pre>
+<ul>
+ <li>[0000]= class 0: highest quality</li>
+ <li>[0111]= class 1: noisy detector</li>
+ <li>[1000]= class 2: dead detector; data interpolated in L1B</li>
+ <li>[1001]= class 3: solar zenith ge 86 degrees</li>
+ <li>[1010]= class 4: solar zenith ge 85 and lt 86 degrees</li>
+ <li>[1011]= class 5: missing input</li>
+ <li>[1100]= class 6: internal constant used in place of climatological data for at least one atmospheric constant</li>
+ <li>[1101]= class 7: correction out of bounds, pixel constrained to extreme allowable value</li>
+ <li>[1110]= class 8: L1B data faulty</li>
+ <li>[1111]= class 9: not processed due to deep ocean or cloud</li>
+ <li>Class 10-15: Combination of bits unused</li>
+</ul>
 
+<pre>
 <EM>Atmospheric correction 250m/500m bit[12]/[30]</EM>
-[00]= class 1: Not Corrected product
-[01]= class 2: Corrected product
+</pre>
+<ul>
+ <li>[0]= class 0: Not Corrected product</li>
+ <li>[1]= class 1: Corrected product</li>
+</ul>
 
+<pre>
 <EM>Adjacency correction 250m/500m bit[13][31]</EM>
-[00]= class 1: Not Corrected product
-[01]= class 2: Corrected product
+</pre>
+<ul>
+ <li>[0]= class 0: Not Corrected product</li>
+ <li>[1]= class 1: Corrected product</li>
+</ul>
 
+<pre>
 <EM>Different orbit from 500m product, 250m Unsigned Int bit[14]</EM>
-[00]= class 1: same orbit as 500m
-[01]= class 2: different orbit from 500m
+</pre>
+<ul>
+ <li>[0]= class 0: same orbit as 500m</li>
+ <li>[1]= class 1: different orbit from 500m</li>
+</ul>
 
 
-
 <H2>NOTES</H2>
+It seems that cloud related info is not filled properly since version 3.
+State-QA 500m images should be used (see Vermote et al., 2008).
 
-
 <H2>TODO</H2>
-Testing is required.
+STATE-QA500m flag Processing should be included for detailed cloud status. 
+More testing is required.
 
 <H2>SEE ALSO</H2>
 
+Vermote E.F., Kotchenova S.Y., Ray J.P.
+MODIS Surface Reflectance User's Guide.
+Version 1.2. June 2008.
+MODIS Land Surface Reflectance Science Computing Facility.
+<A HREF="http://modis-sr.ltdri.org">Homepage</A><br>
+
+
 <em>
 <A HREF="i.vi.html">i.vi</A><br>
 </em>

Modified: grass/trunk/imagery/i.qc.modis/main.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/main.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/main.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -23,19 +23,19 @@
 #include <grass/glocale.h>
 
     /* 250m Products (MOD09Q) */ 
-int qc250a(unsigned int pixel);
-int qc250b(unsigned int pixel);
-int qc250c(unsigned int pixel, int bandno);
-int qc250d(unsigned int pixel);
-int qc250e(unsigned int pixel);
-int qc250f(unsigned int pixel);
+CELL qc250a(CELL pixel);
+CELL qc250b(CELL pixel);
+CELL qc250c(CELL pixel, int bandno);
+CELL qc250d(CELL pixel);
+CELL qc250e(CELL pixel);
+CELL qc250f(CELL pixel);
 
 
     /* 500m Products (MOD09A) */ 
-int qc500a(long int pixel);
-int qc500c(long int pixel, int bandno);
-int qc500d(long int pixel);
-int qc500e(long int pixel);
+CELL qc500a(CELL pixel);
+CELL qc500c(CELL pixel, int bandno);
+CELL qc500d(CELL pixel);
+CELL qc500e(CELL pixel);
 
 int main(int argc, char *argv[]) 
 {
@@ -55,7 +55,6 @@
     /* FMEO Declarations**************** */ 
     char *result;		/*output raster name */
 
-
     /*File Descriptors */ 
     int infd;
     int outfd;
@@ -65,7 +64,6 @@
     CELL *outrast;
     RASTER_MAP_TYPE data_type_output = CELL_TYPE;
 
-
     /************************************/ 
     G_gisinit(argv[0]);
     module = G_define_module();
@@ -106,7 +104,6 @@
     flag1->description =
 	_("QC for MOD09A product @ 500m instead of default MOD09Q at 250m");
 
-
     /********************/ 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -150,7 +147,7 @@
     for (row = 0; row < nrows; row++)
     {
 	CELL c;
-	unsigned int qc250chan;
+	CELL qc250chan;
 	CELL qc500chan;
 	G_percent(row, nrows, 2);
 	if (G_get_c_raster_row(infd, inrast, row) < 0)
@@ -166,7 +163,7 @@
 		qc500chan = c;
 	    else
 		/* This is a MOD09A at 250m product, QC layer is 16-bit */ 
-		qc250chan = (unsigned int) c;
+		qc250chan =  c;
 
 	    if (G_is_c_null_value(&c))
 		G_set_c_null_value(&outrast[col], 1);

Modified: grass/trunk/imagery/i.qc.modis/qc250a.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc250a.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc250a.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,39 +1,17 @@
 /* MODLAND QA Bits 250m Unsigned Int bits[0-1]
- * 00 -> class 1: Corrected product produced at ideal quality -- all bands
- * 01 -> class 2: Corrected product produced at less than idel quality -- some or all bands
- * 10 -> class 3: Corrected product NOT produced due to cloud effect -- all bands
- * 11 -> class 4: Corrected product NOT produced due to other reasons -- some or all bands mayb be fill value (Note that a value of [11] overrides a value of [01])
+ * 00 -> class 0: Corrected product produced at ideal quality -- all bands
+ * 01 -> class 1: Corrected product produced at less than idel quality -- some or all bands
+ * 10 -> class 2: Corrected product NOT produced due to cloud effect -- all bands
+ * 11 -> class 3: Corrected product NOT produced due to other reasons -- some or all bands mayb be fill value (Note that a value of [11] overrides a value of [01])
  */  
-int qc250a(unsigned int pixel) 
-{
-    unsigned int swabfrom, swabto, qctemp;
+#include "grass/gis.h"
 
-    int class;
-
-    swabfrom = pixel;
-    swab(&swabfrom, &swabto, 4);
-    qctemp = swabto;
-    if (qctemp & 0x02) {
-	
-	    /* Non-Corrected product */ 
-	    if (qctemp & 0x01) {
-	    class = 4;		/*other reasons */
-	}
-	else {
-	    class = 3;		/*because of clouds */
-	}
-    }
-    else {
-	
-	    /* Corrected product */ 
-	    if (qctemp & 0x01) {
-	    class = 2;		/*less than ideal quality */
-	}
-	else {
-	    class = 1;		/*ideal quality */
-	}
-    }
-    return class;
+CELL qc250a (CELL pixel) 
+{
+    CELL qctemp;
+    qctemp = pixel & 0x03;
+    
+    return qctemp;
 }
 
 

Modified: grass/trunk/imagery/i.qc.modis/qc250b.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc250b.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc250b.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,36 +1,20 @@
 /* Cloud State 250m Unsigned Int bits[2-3]
- * 00 -> class 1: Clear -- No clouds
- * 01 -> class 2: Cloudy
- * 10 -> class 3: Mixed
- * 11 -> class 4: Not Set ; Assumed Clear
+ * 00 -> class 0: Clear -- No clouds
+ * 01 -> class 1: Cloudy
+ * 10 -> class 2: Mixed
+ * 11 -> class 3: Not Set ; Assumed Clear
  */  
-int qc250b(unsigned int pixel) 
-{
-    unsigned int swabfrom, swabto, qctemp;
 
-    int class;
+#include "grass/gis.h"
 
-    swabfrom = pixel;
-    swabfrom >> 2;		/*bits [2-3] become [0-1] */
-    swab(&swabfrom, &swabto, 4);
-    qctemp = swabto;
-    if (qctemp & 0x02) {	/* 1 ? */
-	if (qctemp & 0x01) {
-	    class = 4;		/*Not Set ; Assumed Clear */
-	}
-	else {
-	    class = 3;		/*Mixed clouds */
-	}
-    }
-    else {			/* 0 ? */
-	if (qctemp & 0x01) {
-	    class = 2;		/*Cloudy */
-	}
-	else {
-	    class = 1;		/*Clear -- No Clouds */
-	}
-    }
-    return class;
+CELL qc250b(CELL pixel) 
+{
+    CELL qctemp;
+
+    qctemp >> 2;		/*bits [2-3] become [0-1] */
+    qctemp = pixel & 0x03;
+    
+    return qctemp;
 }
 
 

Modified: grass/trunk/imagery/i.qc.modis/qc250c.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc250c.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc250c.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,103 +1,26 @@
 /* Band-wise Data Quality 250m Unsigned Int bits[0-1]
- * 0000 -> class 1: highest quality
- * 0111 -> class 2: noisy detector
- * 1000 -> class 3: dead detector; data interpolated in L1B
- * 1001 -> class 4: solar zenith >= 86 degrees
- * 1010 -> class 5: solar zenith >= 85 and < 86 degrees
- * 1011 -> class 6: missing input
- * 1100 -> class 7: internal constant used in place of climatological data for at least one atmospheric constant
- * 1101 -> class 8: correction out of bounds, pixel constrained to extreme allowable value
- * 1110 -> class 9: L1B data faulty
- * 1111 -> class 10: not processed due to deep ocean or cloud
- * Class 11: Combination of bits unused
- */  
-int qc250c(unsigned int pixel, int bandno) 
+ * 0000 -> class 0: highest quality
+ * 0111 -> class 1: noisy detector
+ * 1000 -> class 2: dead detector; data interpolated in L1B
+ * 1001 -> class 3: solar zenith >= 86 degrees
+ * 1010 -> class 4: solar zenith >= 85 and < 86 degrees
+ * 1011 -> class 5: missing input
+ * 1100 -> class 6: internal constant used in place of climatological data for at least one atmospheric constant
+ * 1101 -> class 7: correction out of bounds, pixel constrained to extreme allowable value
+ * 1110 -> class 8: L1B data faulty
+ * 1111 -> class 9: not processed due to deep ocean or cloud
+ * Class 11-15: Combination of bits unused
+ */
+#include "grass/gis.h"
+  
+CELL qc250c(CELL pixel, int bandno) 
 {
-    unsigned int swabfrom, swabto, qctemp;
+    CELL qctemp;
 
-    int class;
+    qctemp >> 4 + (4 * (bandno - 1));	/* bitshift [4-7] or [8-11] to [0-3] */
+    qctemp = pixel & 0x0F;
 
-    swabfrom = pixel;
-    swabfrom >> 4 * bandno;	/* bitshift [4-7] or [8-11] to [0-3] */
-    swab(&swabfrom, &swabto, 4);
-    qctemp = swabto;
-    if (qctemp & 0x08) {	/* 1??? */
-	if (qctemp & 0x04) {	/* 11?? */
-	    if (qctemp & 0x02) {	/* 111? */
-		if (qctemp & 0x01) {	/* 1111 */
-		    class = 10;	/*Not proc.ocean/cloud */
-		}
-		else {		/* 1110 */
-		    class = 9;	/*L1B faulty data */
-		}
-	    }
-	    else {		/* 110? */
-		if (qctemp & 0x01) {	/* 1101 */
-		    class = 8;	/*corr. out of bounds */
-		}
-		else {		/* 1100 */
-		    class = 7;	/*internal constant used */
-		}
-	    }
-	}
-	else {
-	    if (qctemp & 0x02) {	/* 101? */
-		if (qctemp & 0x01) {	/* 1011 */
-		    class = 6;	/*missing input */
-		}
-		else {		/* 1010 */
-		    class = 5;	/*solarzen>=85&&<86 */
-		}
-	    }
-	    else {		/* 100? */
-		if (qctemp & 0x01) {	/* 1001 */
-		    class = 4;	/*solar zenith angle>=86 */
-		}
-		else {		/* 1000 */
-		    class = 3;	/*Dead detector */
-		}
-	    }
-	}
-    }
-    else {			/* 0??? */
-	if (qctemp & 0x04) {	/* 01?? */
-	    if (qctemp & 0x02) {	/* 011? */
-		if (qctemp & 0x01) {	/* 0111 */
-		    class = 2;	/*Noisy detector */
-		}
-		else {		/* 0110 */
-		    class = 11;	/*Unused */
-		}
-	    }
-	    else {		/* 010? */
-		if (qctemp & 0x01) {	/* 0101 */
-		    class = 11;	/*Unused */
-		}
-		else {		/* 0100 */
-		    class = 11;	/*Unused */
-		}
-	    }
-	}
-	else {			/* 00?? */
-	    if (qctemp & 0x02) {	/* 001? */
-		if (qctemp & 0x01) {	/* 0011 */
-		    class = 11;	/*Unused */
-		}
-		else {		/* 0010 */
-		    class = 11;	/*Unused */
-		}
-	    }
-	    else {		/* 000? */
-		if (qctemp & 0x01) {	/* 0001 */
-		    class = 11;	/*Unused */
-		}
-		else {		/* 0000 */
-		    class = 1;	/*Highest quality */
-		}
-	    }
-	}
-    }
-    return class;
+    return qctemp;
 }
 
 

Modified: grass/trunk/imagery/i.qc.modis/qc250d.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc250d.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc250d.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,24 +1,17 @@
 /* Atmospheric correction 250m Unsigned Int bit[12]
- * 00 -> class 1: Not Corrected product
- * 01 -> class 2: Corrected product
+ * 0 -> class 0: Not Corrected product
+ * 1 -> class 1: Corrected product
  */  
-int qc250d(unsigned int pixel) 
-{
-    unsigned int swabfrom, swabto, qctemp;
 
-    int class;
+#include "grass/gis.h"
 
-    swabfrom = pixel;
-    swabfrom >> 12;		/* bit no 12 becomes 0 */
-    swab(&swabfrom, &swabto, 4);
-    qctemp = swabto;
-    if (qctemp & 0x01) {
-	class = 2;		/*Corrected */
-    }
-    else {
-	class = 1;		/*Not corrected */
-    }
-    return class;
+CELL qc250d(CELL pixel) 
+{
+    CELL qctemp;
+
+    qctemp >> 12;		/* bit no 12 becomes 0 */
+    qctemp = pixel & 0x01;
+    
+    return qctemp;
 }
 
-

Modified: grass/trunk/imagery/i.qc.modis/qc250e.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc250e.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc250e.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,24 +1,18 @@
 /* Adjacency correction 250m Unsigned Int bit[13]
- * 00 -> class 1: Not Corrected product
- * 01 -> class 2: Corrected product
+ * 0 -> class 0: Not Corrected product
+ * 1 -> class 1: Corrected product
  */  
-int qc250e(unsigned int pixel) 
-{
-    unsigned int swabfrom, swabto, qctemp;
 
-    int class;
+#include "grass/gis.h"
 
-    swabfrom = pixel;
-    swabfrom >> 13;		/* bit no 13 becomes 0 */
-    swab(&swabfrom, &swabto, 4);
-    qctemp = swabto;
-    if (qctemp & 0x01) {
-	class = 2;		/*Corrected */
-    }
-    else {
-	class = 1;		/*Not corrected */
-    }
-    return class;
+CELL qc250e(CELL pixel) 
+{
+    CELL qctemp;
+
+    qctemp >> 13;		/* bit no 13 becomes 0 */
+    qctemp = pixel & 0x01;
+    
+    return qctemp;
 }
 
 

Modified: grass/trunk/imagery/i.qc.modis/qc250f.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc250f.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc250f.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,24 +1,18 @@
 /* Different orbit from 500m product, 250m Unsigned Int bit[14]
- * 00 -> class 1: same orbit as 500m
- * 01 -> class 2: different orbit from 500m
+ * 0 -> class 0: same orbit as 500m
+ * 1 -> class 1: different orbit from 500m
  */  
-int qc250f(unsigned int pixel) 
-{
-    unsigned int swabfrom, swabto, qctemp;
 
-    int class;
+#include "grass/gis.h"
 
-    swabfrom = pixel;
-    swabfrom >> 14;		/* bit no 14 becomes 0 */
-    swab(&swabfrom, &swabto, 4);
-    qctemp = swabto;
-    if (qctemp & 0x01) {
-	class = 2;		/*different orbit */
-    }
-    else {
-	class = 1;		/*same orbit */
-    }
-    return class;
+CELL qc250f(CELL pixel) 
+{
+    CELL qctemp;
+
+    qctemp >> 14;		/* bit no 14 becomes 0 */
+    qctemp = pixel & 0x01;
+    
+    return qctemp;
 }
 
 

Modified: grass/trunk/imagery/i.qc.modis/qc500a.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc500a.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc500a.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,39 +1,22 @@
 /* MODLAND QA Bits 500m long int bits[0-1]
- * 00 -> class 1: Corrected product produced at ideal quality -- all bands
- * 01 -> class 2: Corrected product produced at less than idel quality -- some or all bands
- * 10 -> class 3: Corrected product NOT produced due to cloud effect -- all bands
- * 11 -> class 4: Corrected product NOT produced due to other reasons -- some or all bands mayb be fill value (Note that a value of [11] overrides a value of [01])
+ * 00 -> class 0: Corrected product produced at ideal quality -- all bands
+ * 01 -> class 1: Corrected product produced at less than idel quality -- some or all bands
+ * 10 -> class 2: Corrected product NOT produced due to cloud effect -- all bands
+ * 11 -> class 3: Corrected product NOT produced due to other reasons -- some or all bands mayb be fill value (Note that a value of [11] overrides a value of [01])
  */  
-int qc500a(long int pixel) 
+
+#include "grass/gis.h"
+
+CELL qc500a(CELL pixel) 
 {
-    long int swabfrom, swabto, qctemp;
+    CELL qctemp;
 
-    int class;
+    /* Select bit 0 and 1 (right-side).
+     * hexadecimal "0x03" => binary "11" 
+     * this will set all other bits to null */
+    qctemp = pixel & 0x03;
 
-    swabfrom = pixel;
-    swab(&swabfrom, &swabto, 4);
-    qctemp = swabto;
-    if (qctemp & 0x02) {
-	
-	    /* Non-Corrected product */ 
-	    if (qctemp & 0x01) {
-	    class = 4;		/*other reasons */
-	}
-	else {
-	    class = 3;		/*because of clouds */
-	}
-    }
-    else {
-	
-	    /* Corrected product */ 
-	    if (qctemp & 0x01) {
-	    class = 2;		/*less than ideal quality */
-	}
-	else {
-	    class = 1;		/*ideal quality */
-	}
-    }
-    return class;
+    return qctemp;
 }
 
 

Modified: grass/trunk/imagery/i.qc.modis/qc500c.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc500c.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc500c.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,104 +1,28 @@
 /* Band-wise Data Quality 500m long Int 
  * bits[2-5][6-9][10-13][14-17][18-21][22-25][26-29]
- * 0000 -> class 1: highest quality
- * 0111 -> class 2: noisy detector
- * 1000 -> class 3: dead detector; data interpolated in L1B
- * 1001 -> class 4: solar zenith >= 86 degrees
- * 1010 -> class 5: solar zenith >= 85 and < 86 degrees
- * 1011 -> class 6: missing input
- * 1100 -> class 7: internal constant used in place of climatological data for at least one atmospheric constant
- * 1101 -> class 8: correction out of bounds, pixel constrained to extreme allowable value
- * 1110 -> class 9: L1B data faulty
- * 1111 -> class 10: not processed due to deep ocean or cloud
- * Class 11: Combination of bits unused
+ * 0000 -> class 0: highest quality
+ * 0111 -> class 1: noisy detector
+ * 1000 -> class 2: dead detector; data interpolated in L1B
+ * 1001 -> class 3: solar zenith >= 86 degrees
+ * 1010 -> class 4: solar zenith >= 85 and < 86 degrees
+ * 1011 -> class 5: missing input
+ * 1100 -> class 6: internal constant used in place of climatological data for at least one atmospheric constant
+ * 1101 -> class 7: correction out of bounds, pixel constrained to extreme allowable value
+ * 1110 -> class 8: L1B data faulty
+ * 1111 -> class 9: not processed due to deep ocean or cloud
+ * Class 10-15: Combination of bits unused
  */  
-int qc500c(long int pixel, int bandno) 
-{
-    long int swabfrom, swabto, qctemp;
 
-    int class;
+#include "grass/gis.h"
 
-    swabfrom = pixel;
-    swabfrom >> 2 + (4 * bandno - 1);	/* bitshift [] to [0-3] etc. */
-    swab(&swabfrom, &swabto, 4);
-    qctemp = swabto;
-    if (qctemp & 0x08) {	/* 1??? */
-	if (qctemp & 0x04) {	/* 11?? */
-	    if (qctemp & 0x02) {	/* 111? */
-		if (qctemp & 0x01) {	/* 1111 */
-		    class = 10;	/*Not proc.ocean/cloud */
-		}
-		else {		/* 1110 */
-		    class = 9;	/*L1B faulty data */
-		}
-	    }
-	    else {		/* 110? */
-		if (qctemp & 0x01) {	/* 1101 */
-		    class = 8;	/*corr. out of bounds */
-		}
-		else {		/* 1100 */
-		    class = 7;	/*internal constant used */
-		}
-	    }
-	}
-	else {
-	    if (qctemp & 0x02) {	/* 101? */
-		if (qctemp & 0x01) {	/* 1011 */
-		    class = 6;	/*missing input */
-		}
-		else {		/* 1010 */
-		    class = 5;	/*solarzen>=85&&<86 */
-		}
-	    }
-	    else {		/* 100? */
-		if (qctemp & 0x01) {	/* 1001 */
-		    class = 4;	/*solar zenith angle>=86 */
-		}
-		else {		/* 1000 */
-		    class = 3;	/*Dead detector */
-		}
-	    }
-	}
-    }
-    else {			/* 0??? */
-	if (qctemp & 0x04) {	/* 01?? */
-	    if (qctemp & 0x02) {	/* 011? */
-		if (qctemp & 0x01) {	/* 0111 */
-		    class = 2;	/*Noisy detector */
-		}
-		else {		/* 0110 */
-		    class = 11;	/*Unused */
-		}
-	    }
-	    else {		/* 010? */
-		if (qctemp & 0x01) {	/* 0101 */
-		    class = 11;	/*Unused */
-		}
-		else {		/* 0100 */
-		    class = 11;	/*Unused */
-		}
-	    }
-	}
-	else {			/* 00?? */
-	    if (qctemp & 0x02) {	/* 001? */
-		if (qctemp & 0x01) {	/* 0011 */
-		    class = 11;	/*Unused */
-		}
-		else {		/* 0010 */
-		    class = 11;	/*Unused */
-		}
-	    }
-	    else {		/* 000? */
-		if (qctemp & 0x01) {	/* 0001 */
-		    class = 11;	/*Unused */
-		}
-		else {		/* 0000 */
-		    class = 1;	/*Highest quality */
-		}
-	    }
-	}
-    }
-    return class;
+CELL qc500c(CELL pixel, int bandno) 
+{
+    CELL qctemp;
+
+    pixel >> 2 + (4 * (bandno - 1));	/* bitshift [] to [0-3] etc. */
+    qctemp = pixel & 0x0F;    
+    
+    return qctemp;
 }
 
 

Modified: grass/trunk/imagery/i.qc.modis/qc500d.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc500d.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc500d.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,24 +1,18 @@
 /* Atmospheric correction 500m long Int bit[30]
- * 00 -> class 1: Not Corrected product
- * 01 -> class 2: Corrected product
+ * 0 -> class 0: Not Corrected product
+ * 1 -> class 1: Corrected product
  */  
-int qc500d(long int pixel) 
+
+#include "grass/gis.h"
+
+CELL qc500d(CELL pixel) 
 {
-    long int swabfrom, swabto, qctemp;
+    CELL qctemp;
 
-    int class;
+    pixel >> 30;		/* bit no 30 becomes 0 */
+    qctemp = pixel & 0x01;    
 
-    swabfrom = pixel;
-    swabfrom >> 30;		/* bit no 30 becomes 0 */
-    swab(&swabfrom, &swabto, 1);
-    qctemp = swabto;
-    if (qctemp & 0x01) {
-	class = 2;		/*Corrected */
-    }
-    else {
-	class = 1;		/*Not corrected */
-    }
-    return class;
+    return qctemp;
 }
 
 

Modified: grass/trunk/imagery/i.qc.modis/qc500e.c
===================================================================
--- grass/trunk/imagery/i.qc.modis/qc500e.c	2008-10-06 10:11:16 UTC (rev 33696)
+++ grass/trunk/imagery/i.qc.modis/qc500e.c	2008-10-06 13:39:01 UTC (rev 33697)
@@ -1,24 +1,18 @@
 /* Adjacency correction 500m long Int bit[31]
- * 00 -> class 1: Not Corrected product
- * 01 -> class 2: Corrected product
+ * 0 -> class 0: Not Corrected product
+ * 1 -> class 1: Corrected product
  */  
-int qc500e(long int pixel) 
-{
-    long int swabfrom, swabto, qctemp;
 
-    int class;
+#include "grass/gis.h"
 
-    swabfrom = pixel;
-    swabfrom >> 31;		/* bit no 31 becomes 0 */
-    swab(&swabfrom, &swabto, 1);
-    qctemp = swabto;
-    if (qctemp & 0x01) {
-	class = 2;		/*Corrected */
-    }
-    else {
-	class = 1;		/*Not corrected */
-    }
-    return class;
+CELL qc500e(CELL pixel) 
+{
+    CELL qctemp;
+
+    pixel >> 31;		/* bit no 31 becomes 0 */
+    qctemp = pixel & 0x01; 
+    
+    return qctemp;
 }
 
 



More information about the grass-commit mailing list