Index: trunk/DataStoreServer/web/doc/smfs/getsmf.html
===================================================================
--- trunk/DataStoreServer/web/doc/smfs/getsmf.html	(revision 39660)
+++ trunk/DataStoreServer/web/doc/smfs/getsmf.html	(revision 39660)
@@ -0,0 +1,117 @@
+<html>
+<head>
+<title>IPP SMF Access Tools</title>
+</head>
+
+<body>
+<H1>
+Access to IPP smf files
+</H1>
+
+<a href=index.html>Go back up.</a><br>
+
+<h2>
+getsmf</h2>
+
+IPP smf files contain the results of camera stage processing. 
+They are FITS format files containg tables with the photometric and
+astronometric measurements for the
+sources detected in a single exposure.
+<br>
+<br>
+getsmf.php is a tool that may be used to retrieve an IPP smf file
+given certain parameters. 
+<br><br>The url of the tool is
+<pre>    http://misc.ipp.ifa.hawaii.edu/getsmf.php</pre>
+
+When this page is accessed without parameters it simply displays an 
+error message. 
+With valid parameters the tool returns the contents of the selected
+smf file. 
+<br> <br>
+Note: Obviously displaying the contents of a FITS file in a web browser is
+not very useful.
+getsmf.php is intended to be accessed directly using HTTP. 
+It is easy to write scripts that use the command line tools curl or wget
+to retrieve smf files using this tool.
+<br><br>
+For example, the following two equivalent unix commands copy the contents of 
+the smf containing the results from the cameraRun with cam_id=1780283) 
+to a local files:
+<pre>
+    curl 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=1780283' -o 1780283.smf
+
+    wget 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=1780283' -O 1780283-wget.smf
+</pre>
+
+The previous method allows the user to control the name of the local copy.
+If one would like to use the original file name supplied by the server
+the commands may be changed to:
+<pre>
+    curl 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=1780283' -O --remote-header-name
+
+    wget 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=1780283' --content-disposition
+
+</pre>
+In this example the name of the downloaded file is "o7616g0008o.1131492.cm.1780283.smf".
+<br><br>
+<b>Note:</b> The quote characters in these commands are needed to prevent
+the '?' characters from being interpreted by user's shell.
+
+<h3>parameters</h3>
+There are a few parameters that may be used to select specific smf files.
+Parameters are supplied by appending them to the base url following
+a '?' character. 
+<br><br>
+If multiple parameters are needed
+they should be separated by a '&' character.
+<br><br>
+<h4>cam_id=value</h4>
+The examples above demonstrated selection by cam_id. When a
+cam_id is supplied any other parameters supplied are ignored.
+
+<h4>exp_name=value</h4>
+Selects an smf file for an exposure with the given name. <br><br>
+For example supplying the parameter: <pre>exp_name=o7616g0008o</pre>
+gets the same result as the examples listed above. (As of the time
+of this writing).
+<br>
+Note that exposures may be processed multiple times. If no other selection
+parameters are found, the smf for the most recent processing is selected.
+<h4>release=value</h4>
+When used with exp_name, the release parameter specifies the 
+ipp release (processing version) for the smf file.<br>
+For example: <pre>exp_name=o5275g0401o&release=3PI.PV3</pre> retrieves the
+smf processed for exposure o5275g0401o in 3PI.PV3.
+If the release were changed to 3PI.nightly
+the smf from the original nightly procecessing would be retrieved. 
+(At the time of this writing, if the release parameter were omitted
+the 3PI.PV3 version would also be retrieved since it is currently
+the latest processing.)
+<h4>data_group=value</h4>
+This is a rarely used parameter.
+With exp_name, chooses smfs from camRuns processed as part of 
+the supplied data group. 
+
+<h3>Errors and Exceptions</h3>
+If an smf matching the supplied parameters is not found in the IPP, a message
+is included in the response. The http request succeeds.
+<br>
+After a user retrieves a file in this manner it should be checked 
+to insure that it
+is actually a FITS format file. 
+
+For example the following getsmf request asks for a non-existent smf:
+<pre>
+    curl 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=99999999999' -o test.smf
+</pre>
+After this command succeeds, the file test.smf is not a FITS file.
+Instead it contains text. This fact and its contents may be found 
+with the following 
+commands.
+<pre>
+    $ file test.smf
+    test.smf: ASCII text
+    $ cat test.smf
+    Could not find smf for cam_id: 99999999999.
+</pre>
Index: trunk/DataStoreServer/web/doc/smfs/index.html
===================================================================
--- trunk/DataStoreServer/web/doc/smfs/index.html	(revision 39660)
+++ trunk/DataStoreServer/web/doc/smfs/index.html	(revision 39660)
@@ -0,0 +1,29 @@
+<html>
+<head>
+<title>IPP-Misc: SMF Access</title>
+</head>
+
+<body>
+<H1>
+IPP-Misc: SMF Access
+</H1>
+<p>
+This page contains links to information about accessing
+IPP <b>SMF</b> files
+which contain the results of IPP camera stage processing.
+<p>
+These files are FITS format files containing multiple binary table extension 
+sections. These which contain the photometric and astronometric measurements 
+for the sources detected in a single Pan-STARRS exposure.
+<p>
+These files are the inital inputs to the PS calibration process.
+<p>
+The following  links describe how to use the IPP-MISC SMF Access tools
+to discover and retrive SMF files.
+<ul>
+<li><a href=listsmfs.html>Get a list of SMF files.</a>
+<li><a href=getsmf.html>Get individual SMF files.</a>
+<li><a href=scripting.html>Scripting: Putting it together.</a>
+</ul>
+
+
Index: trunk/DataStoreServer/web/doc/smfs/listsmfs.html
===================================================================
--- trunk/DataStoreServer/web/doc/smfs/listsmfs.html	(revision 39660)
+++ trunk/DataStoreServer/web/doc/smfs/listsmfs.html	(revision 39660)
@@ -0,0 +1,141 @@
+<html>
+<head>
+<title>
+listsmf
+</title>
+</head>
+
+<body>
+<H1>
+listsmfs
+</H1>
+
+<a href=index.html>Go back up.</a><br>
+<p>
+listsmf.php is a tool that may be used to retrieve certain information
+about SMF files from the IPP database.
+<br>The url of the tool is
+<a href=http://misc.ipp.ifa.hawaii.edu/listsmfs.php>http://misc.ipp.ifa.hawaii.edu/listsmfs.php</a>
+
+<p>
+The list returned is controlled by parameters supplied 
+as part of the http request used to access the page.
+
+By default listsmfs displays the list of
+smfs corresponding to the PS1 science exposures collected on
+the current date (UTC). The output may be fine tuned using parameters.
+The use of parameters is discussed <A HREF=#parameters>below</a>.
+<p>
+Here is some sample output.
+<pre>
+#cam_id smf_name                           quality state   exp_name    label                release        filter      obs_date   obs_time  comment
+1783121 o7622g0062o.1134677.cm.1783121.smf       0 full    o7622g0062o OSS.nightlyscience   SSS.nightly    i.00000     2016-08-22 07:43:12  'OSSR.R19S6.16.Q.i ps1_32_2599 visit 1'
+1783120 o7622g0061o.1134678.cm.1783120.smf       0 full    o7622g0061o OSS.nightlyscience   SSS.nightly    i.00000     2016-08-22 07:42:16  'OSSR.R19S6.16.Q.i ps1_32_2493 visit 1'
+1783122 o7622g0063o.1134679.cm.1783122.smf       0 full    o7622g0063o OSS.nightlyscience   SSS.nightly    i.00000     2016-08-22 07:44:08  'OSSR.R19S6.16.Q.i ps1_32_2614 visit 1'
+... and so on.
+</pre>
+
+<p>
+The first line, which begins with the "comment" character '#', is a
+header line. This line lists the names of the columns shown
+in the subsequent lines. 
+<p>
+If no exposures are found that match the supplied parameters (and their
+defaults) only the header line is displayed.
+<p>The first 4 columns are the most important. They are very useful 
+for constructing requests to retrieve individual SMFs using 
+<a href=getsmf.html>getsmf.php</a>.
+
+<h2>List of Columns</h2>
+
+<h3>cam_id</h3>
+The IPP camera run identifier.
+<h3>smf_name</h3>
+The base name of the SMF file for the exposure (if any).
+<h3>quality</h3>
+The quality value for the camera processing. A non-zero value indicates
+a problem with the processing. For example: unsuccessful astrometric
+solution. In the event of a run with non zero quality
+no SMF file will be available.
+<h3>state</h3>
+The current state of the camera run. 
+Runs that have completed processing will have
+the state "full". SMF files will not be available for runs with any 
+state other than full. Runs with state "new" may finish processing 
+at a later time.
+<h3>exp_name</h3>
+The exposure name of the source exposure. (Also known as "Frame Name"
+in PSPS and other contexts.)
+<h3>label</h3>
+The processing label for the camRun.
+<h3>release</h3>
+The Release that contains the exposures. Examples might be
+3PI.nightly or SSS.nightly.
+If the exposure has not been assigned to a release this column will have
+the value "none".
+<h3>filter</h3>
+The filter used by the camera for the exposure.
+<h3>obs_date</h3>
+Date of the observation (UTC).
+<h3>obs_time</h3>
+Time of the observation (UTC).
+<h3>comment</h3>
+The comment string for the exposure. Note that single quote characters
+have been added around the comment string as delimiters to 
+facilitate parsing.
+
+<A NAME="parameters">
+<h2>Parameters</h2>
+</a>
+As mentioned above, listsmfs gives a list of the
+exposures for the current (UTC) day by default.
+Parameters may be used to
+control the selection. Parameters are provided by appending
+an HTML query string to the request URL.
+<p>
+For example the sample output shown above was generated by a request
+with the parameter string '?release=SSS.nightly' appended to the URL 
+(on the date that this page was written of course).
+<p>
+If multiple parameters are to be supplied they should be separated
+by a '&' character. For example '?release=SSS.nightly&filter=r'
+would list exposures with the named release in the r band filter..
+<p>
+Here is the list of the parameters.
+
+
+<h3>date_min and date_max</h3>
+The date/time limits for observations to be included by the listing. 
+The format for the datetime is 
+
+<pre>    YYYY-MM-DDTHH:MM:SS</pre> 
+where the '-', 'T', and ':' characters are literal and the other characters are
+numeric values for year, month, day, hours, minutes, and seconds.
+<p>
+For example 'date_min=2016-08-22T08:00:00&date_max=2016-08-22T09:00:00'
+would select exposures observed between 0800 UTC and before 0900 UTC
+on Augst 22.
+<p>
+<b>Notes on date limits.</b><p>
+The time portion may be omitted. For example the parameter pair 
+'date_min=2016-08-21&date_max=2016-08-22' will cause all exposures observed
+on 2016-08-21 or 2016-08-22 to be listed.
+<p>
+If date_min is not supplied, any date_max value supplied is silently ignored.
+Instead page uses the defaults for the date parameter: exposures for the current date are listed (if any).
+
+<h3>filter</h3>
+Only exposures with the corresponding filter are listed. If a single 
+character value is supplied for filter, exposures from all filters that 
+begin with that letter are listed.
+
+<h3>label</h3>
+The list is restricted to camRuns with the supplied label.
+
+<h3>release</h3>
+The list is restrictred to exposures with supplied release name. 
+
+<h3>data_group</h3>
+The list is restrictred to camRuns with the supplied data group.
+Note: This parameter is expected to be rarely used.
+
Index: trunk/DataStoreServer/web/doc/smfs/scripting.html
===================================================================
--- trunk/DataStoreServer/web/doc/smfs/scripting.html	(revision 39660)
+++ trunk/DataStoreServer/web/doc/smfs/scripting.html	(revision 39660)
@@ -0,0 +1,151 @@
+<html>
+<head>
+<title>Scripting IPP SMF Access</title>
+</head>
+
+<body>
+<H1>
+Scripting IPP SMF Access
+</H1>
+
+<a href=index.html>Go back up.</a><br>
+
+<p>
+The process of retrieving SMF files is straightforward.
+<ul>
+<li>Discover the list of files of interest.
+<li>Build valid commands to retrieve them from the IPP to local storage.
+<li>Check the results for validity.
+<li>Start working on your science :).
+</ul>
+
+<p>
+This page is primarily concerned with the first two items on this list.
+
+<p> 
+The two pages listsmfs.php and getsmf.php have a relatively straightforward
+interface. UNIX command line tools such as curl or wget may be used to
+access the interface.
+
+<h2>Sample PERL script</h2>
+<p>
+The perl script below gives an example of how to use curl to get
+a list of the current day's smf files from listsmf.php and print curl
+commands that may be used to download the files.
+
+<pre>
+        #!/usr/bin/env perl
+
+        use strict;
+        use warnings;
+
+        my $verbose = 0;
+
+        my $misc_url = 'http://misc.ipp.ifa.hawaii.edu';
+        my $list_url = "$misc_url/listsmfs.php";
+        my $get_url = "$misc_url/getsmf.php";
+
+        my $silent = ' --silent';
+        if ($verbose) {
+            $silent = '';
+        }
+
+        my $list_cmd = "curl $silent http://misc.ipp.ifa.hawaii.edu/listsmfs.php";
+
+        my $output = `$list_cmd`;
+
+        if ($? != 0) {
+            my $rc = $?;
+            print STDERR "Ooops something went wrong with the command $list_cmd\n";
+            print STDERR "command returned $rc\n";
+            exit $rc >> 8;
+        }
+
+        my @lines = split "\n", $output;
+
+        foreach my $line (@lines) {
+            # skip the header line and any others that begin with '#'
+            next if $line =~ '#';
+
+            # split the line at the single quote character that preceeds the
+            # comment string
+            my ($left, $right) = split "'", $line;
+            
+            # the right side of this split is the comment string ...
+            my $comment = $right;
+            
+            # ... and the left side of this split contains a string
+            # with the other parameters.
+            # The other parameters are separated by whitespace
+
+            # NOTE: One might have thought we could parse the header string 
+            # and find the column names but that implies more than the
+            # listsmf "interface" commits to at this time.
+
+            my ($cam_id, $smf_name, $quality, $state, $exp_name, $label, $release, $filter, $obs_date, $obs_time) = split " ", $left;
+
+            if ($quality != 0) {
+                print STDERR "camRun $cam_id had bad quality $quality\n";
+                next;
+            }
+
+            if ($state ne 'full') {
+                print STDERR "camRun is in state $state\n";
+                next;
+            }
+
+            # generate and print out a curl command that could be used to
+            # download the smf file to the current directory
+            my $this_cmd = "curl $silent '$get_url?cam_id=$cam_id' --output $smf_name";
+
+            print "$this_cmd\n";
+        }
+        # all done
+
+</pre>
+When executed the resulting output will look something like this:
+<pre>
+        # 1783100 o7622g0010o.1134626.cm.1783100.smf 0 ICECUBE-160731A.01 i band dither 1 visit 1
+        curl  --silent 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=1783100' --output o7622g0010o.1134626.cm.1783100.smf
+        # 1783101 o7622g0011o.1134627.cm.1783101.smf 0 ICECUBE-160731A.01 i band dither 2 visit 1
+        curl  --silent 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=1783101' --output o7622g0011o.1134627.cm.1783101.smf
+        # 1783102 o7622g0012o.1134628.cm.1783102.smf 0 ICECUBE-160731A.01 i band dither 3 visit 1
+        curl  --silent 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=1783102' --output o7622g0012o.1134628.cm.1783102.smf
+        # 1783103 o7622g0013o.1134629.cm.1783103.smf 0 ICECUBE-160731A.01 i band dither 4 visit 1
+        curl  --silent 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=1783103' --output o7622g0013o.1134629.cm.1783103.smf
+        # 1783104 o7622g0014o.1134630.cm.1783104.smf 0 ICECUBE-160731A.01 i band dither 5 visit 1
+        curl  --silent 'http://misc.ipp.ifa.hawaii.edu/getsmf.php?cam_id=1783104' --output o7622g0014o.1134630.cm.1783104.smf
+</pre>
+
+<p>
+There are two lines for each exposure. The first (which begins with
+ a '#' character) lists prints selected metadata
+for the smf and its source exposure. The second line gives
+a curl command that would copy the file to the user's current directory.
+<p> Note, while not suggested, one could take the output of listsmfs.php
+and source it into a UNIX shell to execute the commands.
+<p>
+This script demonstrates how to
+<ul>
+<li>Use curl to get a list of the smfs for the current day's exposures
+<li>Split the lines of the output into its columns (including the comment string)
+<li>Examining the state and quality values to determine whether or not an SMF exists for the exposure
+<li>Printing a curl command line which when exectuted with copy the SMF to the current directory
+</ul>
+<p>
+This simple script shows the most important steps necessary for successful
+smf retrieval.
+
+<h2>What about errors?</h2>
+<p>
+For the sake of speed we chose to not include any information that
+might be useful for detecting errors in the download process. The database
+does contain anything (a checksum for example)
+which could be used to gain confidence that a file was transmitted
+successfully.
+
+<p>
+In practice so far this has not shown to be an issue. getsmf.php has been
+used to download hundreds of thousands of smf files. When users have
+detected problem files, simply trying the download again seems to correct
+the problem.
