#!/usr/local/bin/perl #Includes /home/deutsch/cgi-bin/cgi-lib file; if /home/deutsch/cgi-bin/cgi-lib doesn't exist, returns malformed #header error do "/home/deutsch/cgi-bin/cgi-lib.pl" || die "Fatal Error: Can't load cgi library"; #calls the subroutine in the cgi-lib.pl library #to read in the variables from the form and set them up #as key=value pairs in the array @in require '/home/deutsch/cgi-bin/MO/MOGlobals.pl'; # written by Freeman Deutsch, December 11, 1996 # # ImageDirectory.pl # # Displays the image in the image directory. # Gives multiple view options, username, filename, file size, object name, telescope name and date. # # ------------------------------------------------------------------- @theMonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ); # if there are no parameters view by fileDate if ($ENV{'QUERY_STRING'} ne "") { $viewBy = GetParameters(); } else { $viewBy = "fileDate"; } chdir($gImageFTPDir); # must change to image directory to get size and date information on the files # get directory information opendir(DIR, $gImageFTPDir); @files = readdir(DIR); closedir(DIR); # chop off .,.. from the start of the files i.e. the directory info shift(@files); shift(@files); # sort the files in the directory by the desired view if ($viewBy eq "userName") { @sortedFiles = sort UserNameCompare @files; } elsif ($viewBy eq "fileName") { @sortedFiles = sort FileNameCompare @files; } elsif ($viewBy eq "fileSize") { @sortedFiles = sort SizeCompare @files; } elsif ($viewBy eq "objectName") { @sortedFiles = sort ObjectNameCompare @files; } elsif ($viewBy eq "telescopeName") { @sortedFiles = sort TelescopeNameCompare @files; } else { @sortedFiles = sort DateCompare @files; } #tells http server incoming data is text html print "Content-type: text/html\n\n"; print ""; print "Index of Latest Images"; print ""; WriteWebTextHeader(); print "
"; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; if ($viewBy eq "userName") { print "
"; } elsif ($viewBy eq "fileName") { print "
"; } elsif ($viewBy eq "fileSize") { print "
"; } elsif ($viewBy eq "objectName") { print "
"; } elsif ($viewBy eq "telescopeName") { print "
"; } else { print "
"; } print "
";

		
# used for making GIF file print " Username   Filename                        Size  Date             Info  Object	             Telescope\r\r";


# make a list of links to the image files


foreach $file (@sortedFiles)
{
	if ($file ne "ImageInfo")
	{
		$fullFileName = "$gImageURLDir/$file";
		
		# Get path to ImageInfo for this file
				
		$imageInfoFileName = GetImageInfoFileName($file);
				
		$size = int (((stat($file))[7] + 999) / 1000); # do not use directory path here

		$lastModified = (stat($file))[9];  # do not use directory path here

		($sec, $min, $hour, $day,  $month, $year, $dayOfWeek, $dayOfYear, $isItDaylightSavings) = localtime($lastModified);
		
		
		($userName, $object, $telescopeName) = GetImageInfoFields($imageInfoFileName);
				
		
		# ------------- Format the Data ----------------
		
		$formatedDate = sprintf("%02d-%03s-%02d  %02d:%02d", $day, $theMonths[$month], $year, $hour, $min);
		
		$formatedFileSize = sprintf("%03s K", $size);
		
		$formatedFileName = sprintf("%-31s", $file);
		
		$formatedUserName = sprintf("%-12s", $userName);
		
		$formatedObject = sprintf("%-20s", $object);

		$formatedTelescopeName = sprintf("%-10s", $telescopeName);
	
		print "$formatedUserName$formatedFileName $formatedFileSize $formatedDate Info $formatedObject$formatedTelescopeName\r\r";
	}
}


print"
"; print"

"; print" F.S.D."; print"

"; print"

Last updated 02/26/97
"; print ""; # ------------------------------------------------------------------- sub FileNameCompare { return(lc($a) cmp lc($b)); } # ------------------------------------------------------------------- # # This will sort the dates going back in time, New to Old date # sub DateCompare { return((stat($b))[9] cmp (stat($a))[9]); } # ------------------------------------------------------------------- # # This will sort the by size, small to big in order # sub SizeCompare { return((stat($a))[7] > (stat($b))[7]); } # ------------------------------------------------------------------- # # This will sort the by userName # sub UserNameCompare { local($infoFileA, $userNameA, $objectA, $telescopeNameA); local($infoFileB, $userNameB, $objectB, $telescopeNameB); if (($a ne "ImageInfo") && ($b ne "ImageInfo")) { $infoFileA = GetImageInfoFileName($a); $infoFileB = GetImageInfoFileName($b); ($userNameA, $objectA, $telescopeNameA) = GetImageInfoFields($infoFileA); ($userNameB, $objectB, $telescopeNameB) = GetImageInfoFields($infoFileB); return(lc($userNameA) cmp lc($userNameB)); } } # ------------------------------------------------------------------- # # This will sort the by Object Name # sub ObjectNameCompare { local($infoFileA, $userNameA, $objectA, $telescopeNameA); local($infoFileB, $userNameB, $objectB, $telescopeNameB); if (($a ne "ImageInfo") && ($b ne "ImageInfo")) { $infoFileA = GetImageInfoFileName($a); $infoFileB = GetImageInfoFileName($b); ($userNameA, $objectA, $telescopeNameA) = GetImageInfoFields($infoFileA); ($userNameB, $objectB, $telescopeNameB) = GetImageInfoFields($infoFileB); return(lc($objectA) cmp lc($objectB)); } } # ------------------------------------------------------------------- # # This will sort the by Telescope Name # sub TelescopeNameCompare { local($infoFileA, $userNameA, $objectA, $telescopeNameA); local($infoFileB, $userNameB, $objectB, $telescopeNameB); if (($a ne "ImageInfo") && ($b ne "ImageInfo")) { $infoFileA = GetImageInfoFileName($a); $infoFileB = GetImageInfoFileName($b); ($userNameA, $objectA, $telescopeNameA) = GetImageInfoFields($infoFileA); ($userNameB, $objectB, $telescopeNameB) = GetImageInfoFields($infoFileB); return(lc($telescopeNameA) cmp lc($telescopeNameB)); } } # ------------------------------------------------------------------- sub GetParameters() { my($parameters, @setttings, $set, $name, $value, $viewBy); $parameters = $ENV{'QUERY_STRING'}; # First split into "A=B" parts: @setttings = split('&', $parameters); foreach $set (@setttings) { ($name, $value) = split('=', $set); if ($name eq "viewBy") { $viewBy = $value; } } return ($viewBy); } # ------------------------------------------------------------------- sub WriteWebTextHeader() { print "
"; print "

Latest MicroObservatory Images

"; print "

"; print "
"; print "To retrieve your image:

"; print "

  • Image files are listed by date and time. (If you wish to list files "; print "alphabetically by username, click on the heading, \"UserName,\" at the top of "; print "the list.)

    "; print "

  • To view an image file ending in .GIF, click on the filename.
    To "; print "view or process an image in the original FITS format (which contains more "; print "visual information than GIF format) save the file and open with software "; print "that can view FITS files. See \"Get Software\" elsewhere in this Web "; print "site.

    "; print "

  • To save files to your desktop: Click and HOLD on the filename; when "; print "the menu appears, choose \"Save As\". Then select \"Source\" (not \"Text\") for "; print "the Format. (If you have \"drag and drop,\" simply drag the file to your "; print "desktop.)

    "; print "

  • Please note: To conserve space, images will be held for one week and "; print "then deleted.

    "; print "

  • "; print "

    "; } # ------------------------------------------------------------------- sub GetImageInfoFields() # Note return values have a space in front of string { my($imageInfoFile) = @_; my($userName, $object, $telescopeName); my(@data); my($count); $count = 0; if (!open(IMAGE_INFO_FILE,"$imageInfoFile")) { return (" ???", " ???", " ???"); } while() { chop; @data = split(':', $_); if ($data[0] eq "Observer's Username") { $userName = $data[1]; $count++; } if ($data[0] eq "Object") { $object = $data[1]; $count++; } if ($data[0] eq "Telescope's Name") { $telescopeName = $data[1]; $count++; } if ($count == 3) { close IMAGE_INFO_FILE; return ($userName, $object, $telescopeName); } } close IMAGE_INFO_FILE; return ($userName, $object, $telescopeName); } # ------------------------------------------------------------------- sub GetImageInfoFileName() { my($file) = @_; my($where); my($prefixString); my($infoFileName); # Get path to ImageInfo for this file $where = index($file, ".GIF"); if ($where != -1) { $prefixString = substr($file, 0, $where); } $where = index($file, ".FITS"); if ($where != -1) { $prefixString = substr($file, 0, $where); } $infoFileName = "$gImageFTPDir/ImageInfo/$prefixString.INFO"; return($infoFileName); }