Index: trunk/ippScripts/scripts/register_exp.pl
===================================================================
--- trunk/ippScripts/scripts/register_exp.pl	(revision 19779)
+++ trunk/ippScripts/scripts/register_exp.pl	(revision 20101)
@@ -19,5 +19,4 @@
 use IPC::Cmd 0.36 qw( can_run run );
 use PS::IPP::Metadata::Config;
-use PS::IPP::Metadata::Stats;
 use PS::IPP::Config 1.01 qw( :standard );
 
@@ -51,61 +50,4 @@
 my $DETREND_FLAG = "-end_stage reg"; # Flag to use to mark detrend exposure
 
-# values to extract from output metadata and the stats to calculate
-my $STATS =
-   [   #          register imfile
-       #          label             STATISTIC          CHIPTOOL FLAG
-       { name => "exp_name",        type => "constant",   flag => "-exp_name",        dtype => "string" }, # File level
-       { name => "telescope",       type => "constant",   flag => "-telescope",       dtype => "string" }, # File level
-       { name => "camera",          type => "constant",   flag => "-inst",            dtype => "string" }, # File level
-       { name => "filelevel",       type => "constant",   flag => "-filelevel",       dtype => "string" }, # File level
-       { name => "object",          type => "constant",   flag => "-object",          dtype => "string" },
-       { name => "exp_type",        type => "constant",   flag => "-exp_type",        dtype => "string" }, # File level
-       { name => "filter",          type => "constant",   flag => "-filter",          dtype => "string" }, # File level
-       { name => "comment",         type => "constant",   flag => "-comment",         dtype => "string" }, # ObsComment
-       { name => "dateobs",         type => "constant",   flag => "-dateobs",         dtype => "string" }, # File level
-       { name => "ccd_temp",        type => "mean",       flag => "-ccd_temp",        dtype => "float"  }, # CCD temperature
-       { name => "exp_time",        type => "mean",       flag => "-exp_time",        dtype => "float"  }, # Exposure time
-       { name => "sat_pixel_frac",  type => "mean",       flag => "-sat_pixel_frac",  dtype => "float"  }, # Fraction of saturated pixels
-       { name => "airmass",         type => "mean",       flag => "-airmass",         dtype => "float"  }, # Airmass
-       { name => "ra",              type => "mean",       flag => "-ra",              dtype => "float"  }, # Right ascension
-       { name => "decl",            type => "mean",       flag => "-decl",            dtype => "float"  }, # Declination
-       { name => "posang",          type => "mean",       flag => "-posang",          dtype => "float"  }, # Position angle
-       { name => "alt",             type => "mean",       flag => "-alt",             dtype => "float"  }, # Altitude
-       { name => "az",              type => "mean",       flag => "-az",              dtype => "float"  }, # Azimuth
-       { name => "m1_x",            type => "constant",   flag => "-m1_x",            dtype => "float"  }, # M1X
-       { name => "m1_y",            type => "constant",   flag => "-m1_y",            dtype => "float"  }, # M1Y
-       { name => "m1_z",            type => "constant",   flag => "-m1_z",            dtype => "float"  }, # M1Z
-       { name => "m1_tip",          type => "constant",   flag => "-m1_tip",          dtype => "float"  }, # M1TIP
-       { name => "m1_tilt",         type => "constant",   flag => "-m1_tilt",         dtype => "float"  }, # M1TILT
-       { name => "m2_x",            type => "constant",   flag => "-m2_x",            dtype => "float"  }, # M2X
-       { name => "m2_y",            type => "constant",   flag => "-m2_y",            dtype => "float"  }, # M2Y
-       { name => "m2_z",            type => "constant",   flag => "-m2_z",            dtype => "float"  }, # M2Z
-       { name => "m2_tip",          type => "constant",   flag => "-m2_tip",          dtype => "float"  }, # M2TIP
-       { name => "m2_tilt",         type => "constant",   flag => "-m2_tilt",         dtype => "float"  }, # M2TILT
-       { name => "env_temperature", type => "constant",   flag => "-env_temperature", dtype => "float"  }, # external temp
-       { name => "env_humidity",    type => "constant",   flag => "-env_humidity",    dtype => "float"  }, # external humidity
-       { name => "env_wind_speed",  type => "constant",   flag => "-env_wind_speed",  dtype => "float"  }, # external wind speed
-       { name => "env_wind_dir",    type => "constant",   flag => "-env_wind_dir",    dtype => "float"  }, # external wind direction
-
-       { name => "teltemp_m1",      type => "constant",   flag => "-teltemp_m1",      dtype => "float"  }, # Primary mirror temps (C)
-       { name => "teltemp_m1cell",  type => "constant",   flag => "-teltemp_m1cell",  dtype => "float"  }, # Primary mirror support temps (C)
-       { name => "teltemp_m2",      type => "constant",   flag => "-teltemp_m2",      dtype => "float"  }, # Secondary mirror temps (C
-       { name => "teltemp_spider",  type => "constant",   flag => "-teltemp_spider",  dtype => "float"  }, # Spider temperatures (C)
-       { name => "teltemp_truss",   type => "constant",   flag => "-teltemp_truss",   dtype => "float"  }, # Mid truss temperatures (C
-       { name => "teltemp_extra",   type => "constant",   flag => "-teltemp_extra",   dtype => "float"  }, # Miscellaneous temperatures (C)
-
-       { name => "sun_angle",       type => "constant",   flag => "-sun_angle",       dtype => "float"  }, # Angle to sun
-       { name => "sun_alt",         type => "constant",   flag => "-sun_alt",         dtype => "float"  }, # Altitude of sun
-       { name => "moon_angle",      type => "constant",   flag => "-moon_angle",      dtype => "float"  }, # Angle to moon
-       { name => "moon_alt",        type => "constant",   flag => "-moon_alt",        dtype => "float"  }, # Altitude of moon
-       { name => "moon_phase",      type => "constant",   flag => "-moon_phase",      dtype => "float"  }, # Phase of moon
-
-       { name => "pon_time",        type => "mean",       flag => "-pon_time",        dtype => "float"  }, # time since last power on
-       { name => "bg",              type => "mean",       flag => "-bg",              dtype => "float"  }, # background
-       { name => "bg",              type => "stdev",      flag => "-bg_mean_stdev",   dtype => "float"  }, # Azimuth
-       { name => "bg_stdev",        type => "rms",        flag => "-bg_stdev",        dtype => "float"  }, # Azimuth
-       ];
-my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
-
 # Look for commands we need
 my $missing_tools;
@@ -136,23 +78,35 @@
     }
 
-    # Parse the output
-    my $mdcParser = PS::IPP::Metadata::Config->new;        # Parser for metadata config files
-    my $metadata = $mdcParser->parse(join "", @$stdout_buf);
-    unless ($metadata) {
-        &my_die ("Unable to parse metadata config doc", $exp_id, $PS_EXIT_PROG_ERROR);
+    # since I can't figure out how to do input and output within PERL, I'm writing to a temp file
+    my ($statFile, $statName) = tempfile( "/tmp/$exp_id.register.XXXX", UNLINK => !$save_temps );
+    print "saving stats to $statName\n";
+    foreach my $line (@$stdout_buf) {
+        print $statFile $line;
+    }
+    close $statFile;
+
+    # parse the stats in the metadata file
+    $command = "$ppStatsFromMetadata $statName - REGISTER_EXP";
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform ppStatsFromMetadata: $error_code\n");
+        exit($error_code);
     }
 
-    # extract the stats from the metadata
-    unless ($stats->parse($metadata)) {
-        &my_die ("Unable to find all values", $exp_id, $PS_EXIT_CONFIG_ERROR);
+    foreach my $line (@$stdout_buf) {
+        $cmdflags .= " $line";
     }
 }
 
-# we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_type
-if (uc($stats->value_for_flag ("-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
-if (uc($stats->value_for_flag ("-inst"))      eq "NULL") { &my_die ("inst      not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
-if (uc($stats->value_for_flag ("-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
-if (uc($stats->value_for_flag ("-exp_type"))  eq "NULL") { &my_die ("exp_type  not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
-if (uc($stats->value_for_flag ("-exp_name"))  eq "NULL") { &my_die ("exp_name  not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
+# we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_name, -exp_type
+if (uc(&value_for_flag ($cmdflags, "-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
+if (uc(&value_for_flag ($cmdflags, "-inst"))      eq "NULL") { &my_die ("inst      not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
+if (uc(&value_for_flag ($cmdflags, "-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
+if (uc(&value_for_flag ($cmdflags, "-exp_name"))  eq "NULL") { &my_die ("exp_name  not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
+
+my $exp_type = &value_for_flag ("-exp_type");
+if (uc($exp_type) eq "NULL") { &my_die ("exp_type  not found", $exp_id, $PS_EXIT_CONFIG_ERROR); }
 
 my $command = "$regtool -addprocessedexp";
@@ -161,7 +115,5 @@
 $command .= " -hostname $host" if defined $host;
 $command .= " -dbname $dbname" if defined $dbname;
-$command .= $stats->cmdflags();
-
-my $exp_type = $stats->value_for_flag ("-exp_type");
+$command .= " $cmdflags";
 
 # Add the detrend flag, if needed
@@ -206,4 +158,16 @@
 }
 
+sub value_for_flag
+{
+    my $cmdflags = shift;
+    my $flag = shift;
+
+    my $value = 0.0;
+    if ($cmdflags =~ m|$flag|) {
+        ($value) = $cmdflags =~ m|$flag\s+(\S+)|;
+    }
+    $value;
+}
+
 sub my_die
 {
