Scripts: further sanity checks
@@ -89,13 +89,6 @@ my $CFVARNAME_FILENAME = "cfVarName.def";
my $tm = localtime;
my $today_date = sprintf("%04d-%02d-%02d", $tm->year+1900, ($tm->mon)+1, $tm->mday);
-if ($WRITE_TO_FILES) {
- create_or_append(\*OUT_PARAMID, "$PARAMID_FILENAME");
- create_or_append(\*OUT_SHORTNAME, "$SHORTNAME_FILENAME");
- create_or_append(\*OUT_NAME, "$NAME_FILENAME");
- create_or_append(\*OUT_UNITS, "$UNITS_FILENAME");
- create_or_append(\*OUT_CFVARNAME, "$CFVARNAME_FILENAME");
-}
if ($WRITE_TO_PARAMDB || $SANITY_CHECK) {
print "Connecting to database ...\n";
$dbh = DBI->connect("dbi:mysql(RaiseError=>1):database=$db;host=$host",$user,$pass) or die $DBI::errstr;
@@ -105,6 +98,8 @@ my $first = 1;
my $lcount = 0;
if ($SANITY_CHECK) {
+ my %map_sn = (); # map of shortNames
+ my %map_pid = (); # map of paramIds
print "Checking sanity: uniqueness of paramId and shortName keys ...\n";
while (<>) {
chomp;
@@ -115,15 +110,33 @@ if ($SANITY_CHECK) {
}
$lcount++;
($paramId, $shortName) = split(/\t/);
+
+ die "Error: shortName=$shortName is duplicated (line ", $lcount+1, ")\n" if (exists $map_sn{$shortName});
+ $map_sn{$shortName}++; # increment count in shortName map
+
+ die "Error: paramId=$paramId is duplicated (line ", $lcount+1, ")\n" if (exists $map_pid{$paramId});
+ $map_pid{$paramId}++; # increment count in paramId map
+
+ die "Error: paramId=$paramId is not an integer (line ", $lcount+1, ")\n" if (!is_integer($paramId));
+
my $x = $dbh->selectrow_array("select * from param.param where id = ?",undef,$paramId);
die "Error: paramId=$x already exists (line ", $lcount+1, ")\n" if (defined $x);
$x = $dbh->selectrow_array("select shortName from param.param where shortName = ?",undef,$shortName);
die "Error: shortName=$x already exists (line ", $lcount+1, ")\n" if (defined $x);
}
- print "Sanity checking completed. $lcount rows checked. No errors. Exiting.\n";
+ print "\nSanity checking completed. $lcount rows checked. No errors.\nExiting.\n";
exit 0;
}
+if ($WRITE_TO_FILES) {
+ create_or_append(\*OUT_PARAMID, "$PARAMID_FILENAME");
+ create_or_append(\*OUT_SHORTNAME, "$SHORTNAME_FILENAME");
+ create_or_append(\*OUT_NAME, "$NAME_FILENAME");
+ create_or_append(\*OUT_UNITS, "$UNITS_FILENAME");
+ create_or_append(\*OUT_CFVARNAME, "$CFVARNAME_FILENAME");
+}
+
+
while (<>) {
chomp;
s/\r//g; # Remove DOS carriage returns
