/* strek_prune_db.f -- translated by f2c (version of 19 December 1990  16:50:21).
   You must link the resulting object file with the libraries:
	-lF77 -lI77 -lm -lc   (in that order)
*/

#include "f2c.h"

/* Table of constant values */

static integer c__1 = 1;

/* Main program */ MAIN__()
{
    /* System generated locals */
    integer i__1;
    olist o__1;
    cllist cl__1;

    /* Builtin functions */
    integer f_open(), s_rdue(), do_uio(), e_rdue(), s_cmp(), s_wdue(), e_wdue(
	    ), f_clos();
    /* Subroutine */ int s_stop();

    /* Local variables */
    static real year;
    static char key_file__[256*1000];
    static integer num_kept__, ship_retired__[1000], i, j;
    static real check;
    static shortint clock[6];
    static char nick_name__[10*1000], capt_name__[10*1000], ship_name__[30*
	    1000];
    static integer month;
    static char user_name__[10*1000];
    static integer cum_score__[1000], num_lines__, ship_avail__[3000]	/* 
	    was [1000][3] */;
    extern /* Subroutine */ int caldecodelocaltime_();
    static integer last_score__[1000];

    /* Fortran I/O blocks */
    static cilist io___2 = { 0, 1, 0, 0, 1 };
    static cilist io___5 = { 0, 1, 0, 0, 0 };
    static cilist io___20 = { 0, 1, 0, 0, 0 };
    static cilist io___21 = { 0, 1, 0, 0, 0 };
    static cilist io___22 = { 0, 1, 0, 0, 1 };



/*    ******************************************************************* 
*/
/*    *****                                                         ***** 
*/
/*    *****                STAR TREK VERSION 3.0                    ***** 
*/
/*    *****                                                         ***** 
*/
/*    *****                     written by                          ***** 
*/
/*    *****                                                         ***** 
*/
/*    *****                Justin S. Revenaugh                      ***** 
*/
/*    *****                                                         ***** 
*/
/*    *****                       7/87                              ***** 
*/
/*    *****                                                         ***** 
*/
/*    *****        Massachussetts Institute of Technology           ***** 
*/
/*    *****  Department of Earth, Atmospheric and Planetary Science ***** 
*/
/*    *****                                                         ***** 
*/
/*    ******************************************************************* 
*/

/*    STREK_PRUNE_INFO helps weed out retired or unused ships from the */
/*    ship's registry (STREK_INFO). Used occasionally it should prevent */

/*    this file from growing too huge. */

/*    version 1 */
/*                                           -jsr 8/85 */


/*    get local date */

    caldecodelocaltime_(clock);

/*    open up file and read num_lines */

    o__1.oerr = 0;
    o__1.ounit = 1;
    o__1.ofnmlen = 30;
    o__1.ofnm = "/usr/lib/X11/xstrek/strek_info";
    o__1.orl = 1000;
    o__1.osta = 0;
    o__1.oacc = "direct";
    o__1.ofm = "unformatted";
    o__1.oblnk = 0;
    f_open(&o__1);
    s_rdue(&io___2);
    do_uio(&c__1, (char *)&num_lines__, (ftnlen)sizeof(integer));
    e_rdue();
    i__1 = num_lines__;
    for (j = 1; j <= i__1; ++j) {
	io___5.cirec = j + 1;
	s_rdue(&io___5);
	do_uio(&c__1, ship_name__ + (j - 1) * 30, 30L);
	do_uio(&c__1, user_name__ + (j - 1) * 10, 10L);
	do_uio(&c__1, capt_name__ + (j - 1) * 10, 10L);
	do_uio(&c__1, nick_name__ + (j - 1) * 10, 10L);
	do_uio(&c__1, key_file__ + (j - 1 << 8), 256L);
	for (i = 1; i <= 3; ++i) {
	    do_uio(&c__1, (char *)&ship_avail__[j + i * 1000 - 1001], (ftnlen)
		    sizeof(integer));
	}
	do_uio(&c__1, (char *)&last_score__[j - 1], (ftnlen)sizeof(integer));
	do_uio(&c__1, (char *)&cum_score__[j - 1], (ftnlen)sizeof(integer));
	do_uio(&c__1, (char *)&ship_retired__[j - 1], (ftnlen)sizeof(integer))
		;
	e_rdue();
/* L10: */
    }
    num_kept__ = 0;
    i__1 = num_lines__;
    for (j = 1; j <= i__1; ++j) {
	if (ship_retired__[j - 1] != 1) {
	    check = (real) (clock[1] - 2);
	    year = (real) (clock[0] - 1);
	    month = clock[1] - 10;
	    if (ship_avail__[j - 1] >= clock[0] && (real) ship_avail__[j + 
		    999] > check || (real) ship_avail__[j - 1] == year && 
		    month > 0) {
		if (s_cmp(ship_name__ + (j - 1) * 30, " ", 30L, 1L) != 0) {
		    ++num_kept__;
		    io___20.cirec = num_kept__ + 1;
		    s_wdue(&io___20);
		    do_uio(&c__1, ship_name__ + (j - 1) * 30, 30L);
		    do_uio(&c__1, user_name__ + (j - 1) * 10, 10L);
		    do_uio(&c__1, capt_name__ + (j - 1) * 10, 10L);
		    do_uio(&c__1, nick_name__ + (j - 1) * 10, 10L);
		    do_uio(&c__1, key_file__ + (j - 1 << 8), 256L);
		    for (i = 1; i <= 3; ++i) {
			do_uio(&c__1, (char *)&ship_avail__[j + i * 1000 - 
				1001], (ftnlen)sizeof(integer));
		    }
		    do_uio(&c__1, (char *)&last_score__[j - 1], (ftnlen)
			    sizeof(integer));
		    do_uio(&c__1, (char *)&cum_score__[j - 1], (ftnlen)sizeof(
			    integer));
		    do_uio(&c__1, (char *)&ship_retired__[j - 1], (ftnlen)
			    sizeof(integer));
		    e_wdue();
		}
	    }
	}
/* L20: */
    }

/*    erase all former ships */

    i__1 = num_lines__ + 1;
    for (j = num_kept__ + 2; j <= i__1; ++j) {
	io___21.cirec = j;
	s_wdue(&io___21);
	e_wdue();
/* L30: */
    }

/*    rewrite the number of ships in the registry */

    s_wdue(&io___22);
    do_uio(&c__1, (char *)&num_kept__, (ftnlen)sizeof(integer));
    e_wdue();
    cl__1.cerr = 0;
    cl__1.cunit = 1;
    cl__1.csta = 0;
    f_clos(&cl__1);
    s_stop("", 0L);
} /* MAIN__ */

/* Main program alias */ int strek_prune_info__ () { MAIN__ (); }
