#!/usr/freeware/bin/perl

use Time::JulianDay;

$rootDir    = "/Net/data/qscat/data/glob_L2B_1d";
$urlBase    = "http://www.coaps.fsu.edu/cgi-bin/dods/nph-nc/dods_data";
$dataRoot   = "QuikSCAT_WINDS_1d";
$name       = "QuikSCAT_WINDS_1d";
$fileBase   = "gcv_QSCAT_";
$fileSuffix = ".nc";


chdir("$rootDir");

open (DAT, ">$rootDir/catalog2.dat");

$urlLength = 0;
open (YEARS, "ls -1 . |");
while (<YEARS>) {
    chomp();
    $year = $_;

    #print "$dataRoot/$year\n";

    if (-d "$year/mon") {

	for ($jmon = 1; $jmon <= 12; $jmon++) {

	    $jmonstring = sprintf("%.2d", $jmon);

	    $file = "$year/mon/$fileBase".$year.$jmonstring.$fileSuffix;

	    #print "$file\n";

	    if (-e $file) {

		    $date = sprintf("%.4d/%.2d ",
				    $year, $jmon);
		    print DAT "$date";

		    $url = "$urlBase/$dataRoot/$file";
		    $blah = length("$url");

		    if ($blah > $urlLength) {
			$urlLength = $blah;
		    }
		    print DAT "$url\n";
		
	    }
	}
    }
}
close YEARS;
close DAT;

$urlLength += 9 - 1;

open(FMT, ">$rootDir/catalog2.fmt");
print FMT <<DONE;
ASCII_input_data "$name"
year         1  4   int32 0
month        6  7   int32 0
DODS_URL     9  $urlLength  text  0
DONE
close FMT;
