The whole structure of WebEarth is very straightforward - of course, it's on its third revision, so it's dramatically more simple than its original incarnation, which was quite a process-bound hack.
To make WebEarth run on your server, you'll need the following components:
We are assuming that this server is connected to the Internet.
WebEarth runs best when run from directories that are accessible to the Web server. On hyperreal.org, I have the following directory structure setup:
$HOME - my home directory /home/mpesce on webearth.org
update.cgi - the update cron script
update.pl - the update perl script
/var/www/html/ - my Web directory for http://www.webearth.org/we/ - my WebEarth directory
div.pl - PERL script to create mosaic from current.gif
current.gif - latest composite satellite image (generated)
current.pnm - PNM version of current.gif (generated)
welarge.wrl - VRML file which creates WebEarth (Gzipped)
images/ - directory containing Earth mosaic images
Webearth.org runs LUNIX (RedHat 7.0.2). Inside UNIX each user account has access to the cron process, which allows you to estabish processes that run at regular intervals. (See the UNIX man pages on cron and crontab for more information about this.) To keep WebEarth updating hourly, we establish a cron process. My crontab file on hyperreal.org looks like this:
# use /bin/sh to run commands, no matter what /etc/passwd says SHELL=/bin/sh # mail any output to `mpesce', no matter whose crontab this is MAILTO=mpesce # run thirty-seven minutes after the hour, every day, forever. 23 * * * * /home/mpesce/update.cgi
When you run the crontab command with this file as input, it will execute update.cgi (from my home directory on webearth.org) every 23 minutes.
All of the work happens inside the update scripts. The first of these is the shell script update.cgi:
#!/bin/sh /usr/bin/lynx -source http://www.fourmilab.ch/earthview/Current-clouds.gif > /var/www/html/current.gif # # At this point we MUST run some error checking or things will be bad. # Any suggestions? # Here is a very simple PERL script to do some error checking... # $HOME/update.pl
This script uses LYNX in its source mode to get the current Earth composite satellite image from John Walker's Web site, and then saves it to the file current.gif in the WebEarth subdirectory. Once, that's done, the script invokes the first PERL script, update.pl:
#!/usr/bin/perl
#
$this = system ("/usr/bin/giftopnm /var/www/html/current.gif > /dev/null");
if ( $this ) {
# We got an error and should try again later.
print "Will try again later.\n";
} else {
system("/usr/bin/giftopnm /var/www/html/current.gif > /var/www/html/current.ppm");
system("/var/www/html/divw.pl 12");
}
This PERL script runs the PNM tool giftopnm twice. On the first pass, the output is channeled to /dev/null, while errors - if there are any - are channeled to the script. If the script executes without error, we can be assured that the current.gif image retrieved from fourmilab.ch is valid. (On many occasions, it won't be valid, and this is a very necessary error check.) If the image is invalid, the if statement block is executed, which quits the script with a message that will be mailed back to you from the cron process daemon. Thus, if the script ever fails, you'll get a message which will help you figure out what went wrong.
If the image is valid, the else statement block is executed, and the real processing begins. First, the image file current.gif is converted to a portable network graphics (PNG) image with the giftopnm command. This creates the file current.pnm in the WebEarth subdirectory. Next, this PERL script invokes the PERL script divw.pl, which resides in the WebEarth subdirectory:
#!/usr/bin/perl
#
# The div PERL script divides a texture map
# Temporarily of known dimensions
# Into a number of smaller areas
# Suitable for being shipped around as texture maps
#
$filename = "/var/www/html/current.ppm"; # Absolute paths
$width = 640; # It is
$height = 320; # Half as long as it is wide
$parts = @ARGV[0]; # Number of parts to be cut into (incl poles)
if ($parts < 1) {
$parts = 6;
}
#
# Now we need to do some fancy footwork.
# First we subtract the top and bottom parts because they're poles.
#
$eheight = $height / $parts;
$ewidth = $width / $parts;
#
# The outside loop does the banding lengthwise
# The inside loop does the banding vertically.
for ($y = 1; $y < ($parts-1); $y++) {
for ( $x = 0; $x < $parts; $x++ ) {
$theCmd = sprintf("/usr/bin/pnmcut %d %d %d %d %s | /usr/bin/ppmtogif 2> /dev/null > /var/www/html/images/mp%02d%02d%02d.gif",
($x * $ewidth), ($y * $eheight), $ewidth, $eheight, $filename, $parts, $y, ($x + 1));
system($theCmd); # And go do it.
}
}
This script creates a mosaic from the composite image; it repeatedly invokes the PNM tool pnmcut with a range of values which "dice" the image into a number of different sections. That number is determined by the number passed on the command line with the divw.pl command, which in this case is twelve - meaning that the image will be divided into twelve sections latitudinally, and ten sections longitudially. Please note that this tool (in an classic example of poor programming practices) uses absolute paths, filenames and hard-coding for the image width (which is 640 x 320 pixels, total).
The image files created by the tool are placed into the images/ subdirectory. The WebEarth VRML model welarge.wrl (the VRML file is compressed and consumes only 5K) explicitly points to the files in the image subdirectory, so the VRML file does not need to be regenerated at any time - only the mosaic of images need to be kept fresh.
OK, that's it. You should have everything you need. If you have any questions, don't hesitate to drop me a note.