
/* This file was automatically generated by pclu.*/

#include "pclu_err.h"
#include "pclu_sys.h"


extern struct dbg_info* dbg_info_f_form;
#undef MY_TRACE_FLAG
#define MY_TRACE_FLAG f_form_TRACE
int f_form_TRACE;
extern struct OPS *int_ops;
static Vlist1 owns_f_form = {0, 1,{ {0, 2, "_init", &int_ops}
}
};
extern errcode intOPlt();
extern errcode intOPequal();
extern errcode _unparse_real();
extern errcode boolOPnot();
extern errcode realOPequal();
extern errcode _round_real();
extern errcode intOPadd();
extern errcode intOPgt();
extern errcode _bytevecOPcreate();
extern errcode _bytevecOPstore();
extern errcode intOPge();
extern errcode intOPle();
extern errcode _bytevecOPfetch();
extern errcode intOPsub();
extern errcode _cvt();
extern OWN_req int_ownreqs;
static int f_form_own_init = 0;

/**** BEGIN PROCEDURE f_form ****/

errcode f_form(x, i, f, ret_1)
CLUREF x;
CLUREF i;
CLUREF f;
CLUREF *ret_1;
    {
    struct {
        struct dbg_info *DBG_INFO;
        int DBG_LINE;
        errcode err;
        errcode ecode2;
        CLUREF minus;
        CLUREF digits;
        CLUREF expon;
        CLUREF ndigs;
        CLUREF n;
        CLUREF res;
        CLUREF j;
        CLUREF c;
        CLUREF x;
        CLUREF i;
        CLUREF f;
        } locals;
    locals.minus.num = UNINIT;
    locals.digits.num = UNINIT;
    locals.expon.num = UNINIT;
    locals.ndigs.num = UNINIT;
    locals.n.num = UNINIT;
    locals.res.num = UNINIT;
    locals.j.num = UNINIT;
    locals.c.num = UNINIT;
    locals.x.num = UNINIT;
    locals.i.num = UNINIT;
    locals.f.num = UNINIT;
    locals.DBG_INFO = dbg_info_f_form;
    locals.x = x;
    locals.i = i;
    locals.f = f;
        if (f_form_own_init == 0) {
        f_form_own_init = 1;
    }
    enter_proc(3);

  LINE(6);
    {
    CLUREF T_1_1;
    CLUREF T_1_2;
    CLUREF T_1_3;
    CLUREF T_1_4;
    CLUREF T_1_5;
    CLUREF T_1_6;
    CLUREF T_1_7;
    T_1_3.num = (locals.i.num < 0)? true : false;
    T_1_2.num = T_1_3.num;
    if (!T_1_3.num) {
        T_1_4.num = (locals.f.num < 0)? true : false;
        T_1_2.num = T_1_4.num;
    }
    T_1_1.num = T_1_2.num;
    if (!T_1_2.num) {
        T_1_6.num = (locals.i.num == 0)? true : false;
        T_1_5.num = T_1_6.num;
        if (T_1_6.num) {
            T_1_7.num = (locals.f.num == 0)? true : false;
            T_1_5.num = T_1_7.num;
        }
        T_1_1.num = T_1_5.num;
    }
    if (T_1_1.num == true) {

  LINE(7);
        {
        {signal (ERR_illegal_field_width);}}
        }
        }/* end if */

  LINE(8);
    {
        {CLUREF T_1_1;
        CLUREF T_1_2;
        CLUREF T_1_3;
        locals.err = _unparse_real(locals.x, &T_1_1, &T_1_2, &T_1_3);
        if (locals.err != ERR_ok) goto ex_0;
        locals.minus.num = T_1_1.num;
        locals.digits.num = T_1_2.num;
        locals.expon.num = T_1_3.num;
        }
        }

  LINE(9);
    {
        {locals.ndigs.num = 0;
        }
        }

  LINE(10);
    locals.n.num = UNINIT;

  LINE(11);
    {
    CLUREF T_1_1;
    CLUREF T_1_2;
    CLUREF T_1_3;
    T_1_1.real = 0.000000e+00;
    locals.err = realOPequal(locals.x, T_1_1, &T_1_2);
    if (locals.err != ERR_ok) goto ex_0;
    T_1_3.num = T_1_2.num ^ 1;
    if (T_1_3.num == true) {

  LINE(12);
        {
        CLUREF T_2_1;
        CLUREF T_2_2;
        CLUREF T_2_3;
        locals.err = intOPadd(locals.expon, locals.f, &T_2_1);
        if (locals.err != ERR_ok) goto ex_0;
        locals.err = _round_real(locals.digits, T_2_1, &T_2_2, &T_2_3);
        if (locals.err != ERR_ok) goto ex_0;
        locals.n.num = T_2_2.num;
        locals.ndigs.num = T_2_3.num;
        }

  LINE(13);
        {
        CLUREF T_2_1;
        locals.err = intOPadd(locals.expon, locals.n, &T_2_1);
        if (locals.err != ERR_ok) goto ex_0;
        locals.expon.num = T_2_1.num;
        }

  LINE(14);
        {
        CLUREF T_2_1;
        T_2_1.num = (locals.expon.num > locals.i.num)? true : false;
        if (T_2_1.num == true) {

  LINE(15);
            {
            {signal (ERR_insufficient_field_width);}}
            }
            }/* end if */
        }
        }/* end if */

  LINE(17);
    {
    CLUREF T_1_1;
    locals.err = intOPadd(locals.f, CLU_1, &T_1_1);
    if (locals.err != ERR_ok) goto ex_0;
    locals.n.num = T_1_1.num;
    }

  LINE(18);
    {
    CLUREF T_1_1;
    T_1_1.num = (locals.i.num > 0)? true : false;
    if (T_1_1.num == true) {

  LINE(19);
        {
        CLUREF T_2_1;
        T_2_1.num = (locals.expon.num > 0)? true : false;
        if (T_2_1.num == true) {

  LINE(20);
            {
            CLUREF T_3_1;
            locals.err = intOPadd(locals.n, locals.expon, &T_3_1);
            if (locals.err != ERR_ok) goto ex_0;
            locals.n.num = T_3_1.num;
            }

  LINE(21);
            {
            CLUREF T_3_1;
            T_3_1.num = (locals.i.num > locals.expon.num)? true : false;
            if (T_3_1.num == true) {

  LINE(22);
                {
                locals.i.num = locals.expon.num;
                }
                }
                }/* end if */
            }
        else {

  LINE(23);
            {
            CLUREF T_3_1;
            locals.err = intOPadd(locals.n, CLU_1, &T_3_1);
            if (locals.err != ERR_ok) goto ex_0;
            locals.n.num = T_3_1.num;
            }

  LINE(24);
            {
            CLUREF T_3_1;
            T_3_1.num = (locals.i.num > 1)? true : false;
            if (T_3_1.num == true) {

  LINE(25);
                {
                locals.i.num = 1;
                }
                }
                }/* end if */
            }}/* end if */
        }
        }/* end if */

  LINE(28);
    {
    if (locals.minus.num == true) {

  LINE(29);
        {
        CLUREF T_2_1;
        locals.err = intOPadd(locals.n, CLU_1, &T_2_1);
        if (locals.err != ERR_ok) goto ex_0;
        locals.n.num = T_2_1.num;
        }
        }
        }/* end if */

  LINE(30);
    {
        {CLUREF T_1_1;
        locals.err = _bytevecOPcreate(locals.n, &T_1_1);
        if (locals.err != ERR_ok) goto ex_0;
        locals.res.num = T_1_1.num;
        }
        }

  LINE(31);
    {
    locals.n.num = 1;
    }

  LINE(32);
    {
    if (locals.minus.num == true) {

  LINE(33);
        {
        CLUREF T_2_1;
        T_2_1.ch = '-';
        locals.err = _bytevecOPstore(locals.res, CLU_1, T_2_1);
        if (locals.err != ERR_ok) goto ex_0;
        }

  LINE(34);
        {
        locals.n.num = 2;
        }
        }
        }/* end if */

  LINE(36);
    {
        {locals.j.num = 1;
        }
        }

  LINE(37);
    for (;;) {
        if (true != true) { break; }

  LINE(38);
        {
        CLUREF T_2_1;
        T_2_1.num = (locals.i.num == 0)? true : false;
        if (T_2_1.num == true) {

  LINE(39);
            {
            CLUREF T_3_1;
            T_3_1.ch = '.';
            locals.err = _bytevecOPstore(locals.res, locals.n, T_3_1);
            if (locals.err != ERR_ok) goto ex_0;
            }

  LINE(40);
            {
            CLUREF T_3_1;
            locals.err = intOPadd(locals.n, CLU_1, &T_3_1);
            if (locals.err != ERR_ok) goto ex_0;
            locals.n.num = T_3_1.num;
            }

  LINE(41);
            {
            CLUREF T_3_1;
            T_3_1.num = (locals.f.num == 0)? true : false;
            if (T_3_1.num == true) {

  LINE(42);
                goto end_while_1;
                }
                }/* end if */
            }
            }/* end if */

  LINE(44);
        {
            {CLUREF T_2_1;
            T_2_1.ch = '0';
            locals.c.num = T_2_1.num;
            }
            }

  LINE(45);
        {
        CLUREF T_2_1;
        CLUREF T_2_2;
        CLUREF T_2_3;
        T_2_2.num = (locals.expon.num >= locals.i.num)? true : false;
        T_2_1.num = T_2_2.num;
        if (T_2_2.num) {
            T_2_3.num = (locals.j.num <= locals.ndigs.num)? true : false;
            T_2_1.num = T_2_3.num;
        }
        if (T_2_1.num == true) {

  LINE(46);
            {
            CLUREF T_3_1;
            locals.err = _bytevecOPfetch(locals.digits, locals.j, &T_3_1);
            if (locals.err != ERR_ok) goto ex_0;
            locals.c.num = T_3_1.num;
            }

  LINE(47);
            {
            CLUREF T_3_1;
            locals.err = intOPadd(locals.j, CLU_1, &T_3_1);
            if (locals.err != ERR_ok) goto ex_0;
            locals.j.num = T_3_1.num;
            }
            }
            }/* end if */

  LINE(49);
        {
        locals.err = _bytevecOPstore(locals.res, locals.n, locals.c);
        if (locals.err != ERR_ok) goto ex_0;
        }

  LINE(50);
        {
        CLUREF T_2_1;
        locals.err = intOPadd(locals.n, CLU_1, &T_2_1);
        if (locals.err != ERR_ok) goto ex_0;
        locals.n.num = T_2_1.num;
        }

  LINE(51);
        {
        CLUREF T_2_1;
        locals.err = intOPsub(locals.i, CLU_1, &T_2_1);
        if (locals.err != ERR_ok) goto ex_0;
        locals.i.num = T_2_1.num;
        }

  LINE(52);
        {
        CLUREF T_2_1;
        T_2_1.num = (locals.i.num >= 0)? true : false;
        if (T_2_1.num == true) {

  LINE(53);
            continue;
            }
            }/* end if */

  LINE(54);
        {
        CLUREF T_2_1;
        locals.err = intOPsub(locals.f, CLU_1, &T_2_1);
        if (locals.err != ERR_ok) goto ex_0;
        locals.f.num = T_2_1.num;
        }

  LINE(55);
        {
        CLUREF T_2_1;
        T_2_1.num = (locals.f.num <= 0)? true : false;
        if (T_2_1.num == true) {

  LINE(56);
            goto end_while_1;
            }
            }/* end if */
        }
        end_while_1:;

  LINE(58);
    {
    {
    CLUREF T_1_1;
    T_1_1.num = locals.res.num;
    ret_1->num = T_1_1.num;
    }
    {signal (ERR_ok);}}
    goto end_0;
    ex_0:
        {
            if (locals.err == ERR_failure) {signal(ERR_failure);}
            elist[0] = _pclu_erstr(locals.err);
            {signal(ERR_failure);}
        }
    end_0: elist[0].str = no_return_values_STRING;
        {signal(ERR_failure);}
    }

/**** END PROCEDURE f_form ****/

extern struct OPS *string_ops;
extern struct OPS *bool_ops;
extern struct OPS *_bytevec_ops;
extern struct OPS *char_ops;
extern struct OPS *real_ops;
typedef struct {
    int hdr;
    int count;
    char *name;
    char *fname;
    bool is_iter;
    int is_parmd;
    int addr;
    int nargs;
    Vlist1 *vals;
    siglist2 *sigs;
    Vlist13 *locals;
    Vlist1 *owns;
    Vlist0 *ptowns;
    Vlist0 *popowns;
    Slist0 *type_formals;
    Slist0 *op_formals;
    } dbg_info_f_form_actual;
static Vlist1 vals_f_form = {0, 1, { {0, 2, "", &string_ops}}
};
static sig_desc0 sig_f_form_1 = {0, 3, "illegal_field_width", {0, 0
}};
static sig_desc0 sig_f_form_2 = {0, 3, "insufficient_field_width", {0, 0
}};
static siglist2 sigs_f_form = {0, 2, (sig_desc*)&sig_f_form_1, (sig_desc*)&sig_f_form_2};
static Vlist13 locals_f_form = {0, 13,{ {0, 2, "err", &int_ops},  {0, 2, "ecode2", &int_ops},  {0, 2, "minus", &bool_ops},  {0, 2, "digits", &_bytevec_ops},  {0, 2, "expon", &int_ops},  {0, 2, "ndigs", &int_ops},  {0, 2, "n", &int_ops},  {0, 2, "res", &_bytevec_ops},  {0, 2, "j", &int_ops},  {0, 2, "c", &char_ops},  {0, 2, "x", &real_ops},  {0, 2, "i", &int_ops},  {0, 2, "f", &int_ops}}
};
static Vlist0 popowns_f_form = {0, 0};
Slist0 tformals_f_form = {0, 0};
Slist0 opformals_f_form = {0, 0};
dbg_info_f_form_actual dbg_info_f_form_data = {0, 12, 
    "f_form", "/common/pub/dcurtis-temp/pclu/sys/clu/f_form", 0, 0, (int)f_form, 3, 
    &vals_f_form, &sigs_f_form, &locals_f_form, &owns_f_form, &NO_VALS, &NO_VALS, &NO_PARMS, &NO_PARMS};
    struct dbg_info *dbg_info_f_form = (struct dbg_info*)&dbg_info_f_form_data;
