#!/cis/bin/perl # # generate event files from raw Applanix data if($#ARGV < 0) { print "Usage: perl genevents.pl [directory]\n"; print "Encapsulate the directory location with double quotes if there is space.\n"; exit 0; } my($directory) = $ARGV[0]; if( ! -d $directory ) { print "$directory is NOT a valid directory.\n"; exit 0; } opendir(DIR, $directory); my(@dir_list) = readdir(DIR); closedir(DIR); my $element; foreach (@dir_list) { # ignore . and .. filenames next if($_ eq "." || $_ eq ".." || $_ eq "applanix" || $_ eq "products"|| $_ eq "applanix-proc" | $_ eq "vnir-proc"); $element = $directory . "\\" . $_; # print "Test: $element \n"; if( opendir(DIR, $element) ) { my(@sub_list) = readdir(DIR); closedir(DIR); $size = scalar @sub_list; if( $size > 6 ) { print "Processing: $element \n"; chdir($element); $is_big_endian = unpack( "h*", pack( "s", 1 )) =~ /01/; open APLX, ">LWIRevents.txt" or die "cannot open LWIRevents for writing"; open MWIR, ">>MWIRevents.txt" or die "cannot open MWIRevents for writing"; open SWIR, ">>SWIRevents.txt" or die "cannot open SWIRevents for writing"; open VNIR, ">>VNIRevents.txt" or die "cannot open VNIRevents for writing"; while( sysread( APLX, $header, 8 ) == 8 ) { my( $hdr, $grp, $len ) = unpack( "a4vv", $header ); sysread( APLX, $body, $len ); # print "hdr is $hdr\ngrp is $grp\nlen is $len\n"; if( $hdr eq "\$GRP" ) { print "."; # print "Found a group $grp record.\n"; if( $grp == 206 || $grp == 207 ) { my( $time1, $time2, $dist, $ttypes, $dtype, $event ) = unpack( "a8a8a8ccV", $body ); $time1 = reverse( $time1 ) if( $is_big_endian ); ( $time1 ) = unpack( "d", $time1 ); if( $grp == 206 ) { printf LWIR "%f\tLWIR%03u.img\n", $time1, $event; printf MWIR "%f\tMWIR%03u.img\n", $time1, $event; printf SWIR "%f\tSWIR%03u.img\n", $time1, $event; } else { printf VNIR "%f\tVNIR%03u.img\n", $time1, $event; } # if ... else } } } # while } else { print "IGNORED: $element"; }# if (size > 5) ... else print "\n# DONE!\n"; close APLX; close VNIR; close SWIR; close MWIR; close LWIR; } else { print ">> $element is NOT a directory \n"; }# if (directory == true) ... else } # for loop exit 0;