IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 13, 2008, 11:43:12 AM (18 years ago)
Author:
bills
Message:

If listing or getting images don't require an roi or user tag.
When a job completes look for a parse_error file and if found list
it contents.
Keep track of last command mode across requests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/web/request.php

    r16960 r16977  
    3232$list_checked = "";
    3333$pstamp_checked = "";
     34$get_checked = "";
    3435
    3536$command_line = "";
     
    3738$command_status = "";
    3839
     40$outFileset = "";
    3941
    4042// Initialize the request variables that we depend upon
     
    6163
    6264$rvar_cmd_mode = "";
     65$rvar_last_cmd_mode = "";
    6366$rvar_request_id = 0;
    6467$rvar_last_request_id = 0;
     
    9598
    9699// is the center is specified in Pixels or sky coordinates
    97 if ($rvar_center_type == "Pixels") {
     100if ($rvar_center_type == "Sky") {
     101    $sky_checked="checked";
     102    $pix_checked="";
     103} else {
    98104    $sky_checked="";
    99105    $pix_checked="checked";
    100 } else {
    101     $sky_checked="checked";
    102     $pix_checked="";
    103106}
    104107
    105108// is the range is specified in Pixels or sky coordinates
    106 if ($rvar_range_type == "Pixels") {
    107     $rsky_checked="";
    108     $rpix_checked="checked";
    109 } else {
     109if ($rvar_range_type == "Sky") {
    110110    $rsky_checked="checked";
    111111    $rpix_checked="";
     112} else {
     113    $rpix_checked="checked";
     114    $rsky_checked="";
    112115}
    113116
     
    117120$last_request_id = $rvar_last_request_id;
    118121
    119 
    120 // default to list mode, unless we are waiting for a request to finish
    121 if (($rvar_cmd_mode == "Make Stamps") || ($request_id != 0)) {
     122// during request the page doesn't have cmd_mode set. So we remember the lat real value
     123// and use that
     124if (!$rvar_cmd_mode) {
     125    $rvar_cmd_mode = "$rvar_last_cmd_mode";
     126}
     127
     128if ($rvar_cmd_mode == "Make Stamps") {
    122129    $pstamp_checked = "checked";
    123130    $list_checked = "";
     131    $get_checked = "";
     132} else if ($rvar_cmd_mode == "Get Images") {
     133    $get_checked = "checked";
     134    $list_checked = "";
     135    $pstamp_checked = "";
    124136} else {
    125137    $list_checked = "checked";
     138    $get_checked = "";
    126139    $pstamp_checked = "";
    127140}
     
    138151if ($rvar_img_type) {
    139152
     153    $jobFinished = 0;
    140154    if ($request_id == 0) {
    141155        try {
    142             $command_line = build_command_line();
     156            $command_line = build_request_cmd();
    143157            $error_line = "";
    144158            run_command($command_line);
     
    155169                $jobRunning = getRequestStatus();
    156170                if (!$jobRunning) {
     171                    $jobFinished = 1;
    157172                    $request_id = 0;
    158173                }
     
    169184
    170185            if (!$jobRunning) {
     186                $jobFinished = 1;
    171187                $request_id = 0;
    172188            }
    173189
    174190        } catch (Exception $e) {
     191            echo "Got Exception $request_id $e\n";
    175192            $error_line = $e->getMessage();
    176193        }
    177194    }
    178     listJobs($last_request_id);
    179 }
    180 
    181 function build_command_line()
     195    if ($last_request_id) {
     196        // This doesn't work for get_image
     197        listJobs($last_request_id, $jobFinished);
     198    }
     199}
     200
     201function build_request_cmd()
    182202{
    183203    global $rvar_project, $rvar_user_tag;
    184204    global $sky_checked, $rsky_checked;
    185205    global $list_checked;
     206    global $get_checked;
    186207    global $rvar_RA, $rvar_DEC;
    187208    global $rvar_dRA, $rvar_dDEC;
     
    194215
    195216    $cmd = "pstamp_runcommand.sh pstamp_webrequest.pl";
     217
     218    $making_stamps = 1;
    196219   
    197220    if ($list_checked) {
    198221        $cmd .= " -list";
     222        $making_stamps = 0;
     223    } else if ($get_checked) {
     224        $making_stamps = 0;
     225        $cmd .= " -get_image";
    199226    }
    200227
     
    203230    }
    204231    $cmd .= " -project $rvar_project";
    205     if (! $rvar_user_tag ) {
    206         throw new Exception('Stamp Name must be specified.');
    207     }
    208     $cmd .= " -user_tag $rvar_user_tag";
    209 
    210     // Set up the ROI parameters
    211     if ($sky_checked) {
    212         if (! $rvar_RA || ! $rvar_DEC) {
    213             throw new Exception('RA and DEC must be specified.');
    214         }
    215         $cmd .= " -skycenter $rvar_RA $rvar_DEC";
    216     } else {
    217         if (! $rvar_X || ! $rvar_Y) {
    218             throw new Exception('X and Y must be specified.');
    219         }
    220         $cmd .= " -pixcenter $rvar_X $rvar_Y";
    221     }
    222 
    223     if ($rsky_checked) {
    224         if (! $rvar_dRA || ! $rvar_dDEC) {
    225             throw new Exception('dRA and dDEC must be specified.');
    226         }
    227         $cmd .= " -arcrange $rvar_dRA $rvar_dDEC";
    228     } else {
    229         if (! $rvar_W || ! $rvar_H) {
    230             throw new Exception('width and height must be specified.');
    231         }
    232         $cmd .= " -pixrange $rvar_W $rvar_H";
    233     }
    234 
    235 
    236     // Note: in the following block we assume that image type has been
    237     // which is true since it comes from the menu
     232
     233    if ($making_stamps) {
     234        if (!$rvar_user_tag) {
     235            throw new Exception('Stamp Name must be specified.');
     236        }
     237        $cmd .= " -user_tag $rvar_user_tag";
     238    }
     239
     240    if ($making_stamps || $coord_checked) {
     241        // Set up the ROI parameters
     242        if ($sky_checked) {
     243            if (! $rvar_RA || ! $rvar_DEC) {
     244                throw new Exception('RA and DEC must be specified.');
     245            }
     246            $cmd .= " -skycenter $rvar_RA $rvar_DEC";
     247        } else {
     248            if (! $rvar_X || ! $rvar_Y) {
     249                throw new Exception('X and Y must be specified.');
     250            }
     251            $cmd .= " -pixcenter $rvar_X $rvar_Y";
     252        }
     253
     254        if ($rsky_checked) {
     255            if (! $rvar_dRA || ! $rvar_dDEC) {
     256                throw new Exception('dRA and dDEC must be specified.');
     257            }
     258            $cmd .= " -arcrange $rvar_dRA $rvar_dDEC";
     259        } else {
     260            if (! $rvar_W || ! $rvar_H) {
     261                throw new Exception('width and height must be specified.');
     262            }
     263            $cmd .= " -pixrange $rvar_W $rvar_H";
     264        }
     265    }
     266
     267
     268    if (! $rvar_img_type) {
     269        // this actually can't happen
     270        throw new Exception('Must set image type.');
     271    }
     272
    238273    if ($exp_checked) {
    239274        if (! $rvar_id ) {
     
    243278    } else if ($file_checked) {
    244279        if (! $rvar_id ) {
    245             throw new Exception('Must set ID specified.');
     280            throw new Exception('Must set ID.');
    246281        }
    247282        $cmd .= " -byid $rvar_img_type $rvar_id";
     
    270305    global $COMMAND_DIR;
    271306
     307    // echo "running $command_line\n";
    272308
    273309    exec ("$COMMAND_DIR/$command_line", $output_array, $command_status);
     
    349385}
    350386
    351 function listJobs($request_id)
     387function listJobs($request_id, $jobFinished)
    352388{
     389
    353390    $command_line = "pstamp_runcommand.sh pstamp_listjobs.pl $request_id";
    354391    run_command($command_line);
     392    if ($jobFinished) {
     393        global $outFileset;
     394        $parse_error = "/var/www/html/ds/dsroot/$outFileset/parse_error";
     395        #echo "reading $parse_error\n";
     396        // readfile( $parse_error );
     397        $fhandle = fopen($parse_error, "r");
     398        if ($fhandle) {
     399            $contents = fread($fhandle, 1024);
     400            if ($contents) {
     401                global $last_request_id;
     402                global $error_line;
     403                $error_line = "Request $last_request_id: $contents\n";
     404            }
     405        }
     406    }
    355407}
    356408
     
    360412    global $command_status;
    361413    global $output_array;
     414    global $outFileset;
    362415
    363416    $command_line = "pstamp_runcommand.sh pstamptool -listreq -req_id $request_id -simple";
     
    368421        for ($i = 0; $i < $size; $i++) {
    369422            $elements = explode(" ", $output_array[$i]);
    370             if (count($elements) >= 3) {
     423            if (count($elements) >= 4) {
    371424                $state = $elements[2];
     425                $outFileset = $elements[4];
    372426                if ($state != "stop") {
    373427                    $runningReq++;
     
    601655    <td><b>Mode:</b>&nbsp;&nbsp;
    602656    <input type=radio name="cmd_mode" value="Make Stamps"<?php echo $pstamp_checked; ?> >Make Stamps
     657    <input type=radio name="cmd_mode" value="Get Images" <?php echo $get_checked; ?> >Get Images
    603658    <input type=radio name="cmd_mode" value="List Images" <?php echo $list_checked; ?> >List Images
    604659    </td>
     
    686741    <input type="hidden" name="last_request_id" value=<?php echo $last_request_id ?> >
    687742</td>
     743<td>
     744    <input type="hidden" name="last_cmd_mode" value=<?php echo "\"$rvar_cmd_mode\"" ?> >
     745</td>
    688746</tr>
    689747</table>
Note: See TracChangeset for help on using the changeset viewer.