/* clrmem.f -- translated by f2c (version of 3 February 1990  3:36:42).
   You must link the resulting object file with the libraries:
	-lF77 -lI77 -lm -lc   (in that order)
*/

#include "f2c.h"

/* Common Block Declarations */

struct {
    doublereal cpyknt;
    integer istack[1], lorg, icore, maxcor, maxuse, memavl, ldval, numblk, 
	    loctab, ltab, ifwa, nwoff, ntab, maxmem, memerr, nwd4, nwd8, 
	    nwd16;
} memmgr_;

#define memmgr_1 memmgr_

/* Table of constant values */

static integer c__1 = 1;

/*<       subroutine clrmem(ipntr) >*/
/* Subroutine */ int clrmem_(ipntr)
integer *ipntr;
{
    static integer muse, msiz, ltab1;
    extern /* Subroutine */ int copy4_(), memadj_(), errmem_();
    extern logical memptr_();
    static integer nwords;
    extern integer nxtevn_();

    /* Parameter adjustments */
    --ipntr;

    /* Function Body */
/*<       implicit double precision (a-h,o-z) >*/
/*<       dimension ipntr(1) >*/
/* spice version 2g.6  sccsid=memmgr 3/15/83 */
/*<       common /memmgr/ cpyknt,istack(1),lorg,icore,maxcor,maxuse,memavl, >*/
/*<      1   ldval,numblk,loctab,ltab,ifwa,nwoff,ntab,maxmem,memerr,nwd4, >*/
/*<      2   nwd8,nwd16 >*/
/*<       logical memptr >*/

/* ***  clrmem - release block */


/* ...  check that pointer is valid */
/*<       if (memptr(ipntr(1))) go to 10 >*/
    if (memptr_(&ipntr[1])) {
	goto L10;
    }
/*<       memerr=5 >*/
    memmgr_1.memerr = 5;
/*<       call errmem(1,memerr,ipntr(1)) >*/
    errmem_(&c__1, &memmgr_1.memerr, &ipntr[1]);
/*<    10 msiz=istack(ltab+2) >*/
L10:
    msiz = memmgr_1.istack[memmgr_1.ltab + 1];
/*<       muse=istack(ltab+3) >*/
    muse = memmgr_1.istack[memmgr_1.ltab + 2];
/*<       memavl=memavl+nxtevn(muse)+istack(ltab+6) >*/
    memmgr_1.memavl = memmgr_1.memavl + nxtevn_(&muse) + memmgr_1.istack[
	    memmgr_1.ltab + 5];
/* ...  assumption:  first allocated block is never cleared. */
/*<       ltab1=ltab-ntab >*/
    ltab1 = memmgr_1.ltab - memmgr_1.ntab;
/*<       istack(ltab1+2)=istack(ltab1+2)+msiz >*/
    memmgr_1.istack[ltab1 + 1] += msiz;
/* ...  reposition the block table */
/*<       nwords=ltab-loctab >*/
    nwords = memmgr_1.ltab - memmgr_1.loctab;
/*<       cpyknt=cpyknt+dble(nwords) >*/
    memmgr_1.cpyknt += (doublereal) nwords;
/*<       call copy4(istack(loctab+1),istack(loctab+ntab+1),nwords) >*/
    copy4_(&memmgr_1.istack[memmgr_1.loctab], &memmgr_1.istack[
	    memmgr_1.loctab + memmgr_1.ntab], &nwords);
/*<       numblk=numblk-1 >*/
    --memmgr_1.numblk;
/*<       loctab=loctab+ntab >*/
    memmgr_1.loctab += memmgr_1.ntab;
/*<       memavl=memavl+ntab >*/
    memmgr_1.memavl += memmgr_1.ntab;
/*<       ltab1=ldval-ntab >*/
    ltab1 = memmgr_1.ldval - memmgr_1.ntab;
/*<       istack(ltab1+2)=istack(ltab1+2)+ntab >*/
    memmgr_1.istack[ltab1 + 1] += memmgr_1.ntab;
/*<       ipntr(1)=2**30-1 >*/
    ipntr[1] = 1073741823;
/*<       call memadj >*/
    memadj_();
/*<       return >*/
    return 0;
/*<       end >*/
} /* clrmem_ */

