Index: /trunk/ippScripts/scripts/skycalibration.pl
===================================================================
--- /trunk/ippScripts/scripts/skycalibration.pl	(revision 34736)
+++ /trunk/ippScripts/scripts/skycalibration.pl	(revision 34737)
@@ -33,4 +33,5 @@
 my $psastro = can_run('psastro') or (warn "Can't find psastro" and $missing_tools = 1);
 my $fhead = can_run('fhead') or (warn "Can't find fhead" and $missing_tools = 1);
+my $fields = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);
 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
@@ -191,4 +192,37 @@
 }
 
+my $resolved = $ipprc->file_resolve($file);
+if (!$resolved) {
+    &my_die("Unable to find input file: $file", $skycal_id, $PS_EXIT_SYS_ERROR);
+}
+
+# read the input header to find the number of detections and the number of detections
+# with extended model
+my $n_detections = 0;
+my $n_extended = 0;
+{
+    my $command = "echo $resolved | $fields -n SkyChip.psf NAXIS2";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => 0);
+        # fields does not return 0 on success
+    (undef, $n_detections)  = split " ", join "", @$stdout_buf;
+    chomp $n_detections;
+    &my_die("Unable to find number of detections from $file: ", $skycal_id, $PS_EXIT_SYS_ERROR)
+        unless defined $n_detections;
+
+
+if (0) {
+    # use ppStatsFromMetadata for this
+    $command = "echo $resolved | $fields -n SkyChip.hdr NDET_EXT";
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => 0);
+    (undef, $n_extended)  = split " ", join "", @$stdout_buf;
+    chomp $n_extended;
+    &my_die("Unable to find number of extended objects from $file: ", $skycal_id, $PS_EXIT_SYS_ERROR)
+        unless defined $n_extended;
+}
+}
+
+
 # Perform psastro analysis
 my $output_sources_filerule =  'PSASTRO.OUTPUT.CMF';
@@ -246,4 +280,6 @@
 {
     my $command = "$staticskytool -skycal_id $skycal_id";
+    $command .= " -n_detections $n_detections";
+    $command .= " -n_extended $n_extended";
     $command .= " -addskycalresult -path_base $outroot";
     $command .= " $cmdflags";
