[Swift-commit] r6288 - in SwiftApps/modis: bin data/modis/2002
davidk at ci.uchicago.edu
davidk at ci.uchicago.edu
Mon Feb 18 09:28:03 CST 2013
Author: davidk
Date: 2013-02-18 09:28:01 -0600 (Mon, 18 Feb 2013)
New Revision: 6288
Modified:
SwiftApps/modis/bin/getlanduse.pl
SwiftApps/modis/data/modis/2002/README.data
Log:
Change getlanduse.pl to use rgb files
Modified: SwiftApps/modis/bin/getlanduse.pl
===================================================================
--- SwiftApps/modis/bin/getlanduse.pl 2013-02-18 01:22:58 UTC (rev 6287)
+++ SwiftApps/modis/bin/getlanduse.pl 2013-02-18 15:28:01 UTC (rev 6288)
@@ -1,32 +1,23 @@
#!/usr/bin/perl -w
-# Input to this program should be a gzipped PGM file
-# Usage: getlanduse.pl myfile.pgm.gz
+# Input to this program should be a raw, greyscale RGB file
+# Usage: getlanduse.pl myfile.rgb
-my $pgm_filename = shift;
-open(PGMFILE, "gunzip -c $pgm_filename |") || die "Unable to open $pgm_filename!\n";
+my $image_filename = shift;
+open(IMAGEFILE, "$image_filename") || die "Unable to open $image_filename!\n";
+binmode IMAGEFILE;
-# Header
-my $magic = <PGMFILE>;
-my $resolution = <PGMFILE>;
-my $maxvalue = <PGMFILE>;
-
-# Use arrays to count frequencies
my @pixelcount;
-foreach my $count(0..$maxvalue) {
- $pixelcount[$count] = 0;
-}
+foreach my $count (0..255) { $pixelcount[$count] = 0; }
-# Read values
-foreach(<PGMFILE>) {
- foreach $word(split) {
- $pixelcount[$word]++;
- }
+# Read values, three bytes at a time
+$/ = \3;
+foreach(<IMAGEFILE>) {
+ $pixelcount[unpack('C', $_)]++;
}
-close(PGMFILE);
+close(IMAGEFILE);
-foreach my $count(0..$maxvalue) {
- if($pixelcount[$count] == 0){ next; }
+foreach my $count (0..255) {
+ if($pixelcount[$count] == 0) { next; }
printf("%d %d %02x\n", $pixelcount[$count], $count, $count);
}
-
Modified: SwiftApps/modis/data/modis/2002/README.data
===================================================================
--- SwiftApps/modis/data/modis/2002/README.data 2013-02-18 01:22:58 UTC (rev 6287)
+++ SwiftApps/modis/data/modis/2002/README.data 2013-02-18 15:28:01 UTC (rev 6288)
@@ -1 +1 @@
-Download and extract modis data from http://www.ci.uchicago.edu/swift/modis/modis-2002.tar. It's approximately 140MB.
+Download and extract modis data from http://www.ci.uchicago.edu/swift/modis/modis-2002.tar.gz. It's approximately 130MB.
More information about the Swift-commit
mailing list