/**********************************************************************
 *  COCOMO II Risk Model
 *
 *  NOTE: block comments were included with source code as delivered,
 *        and my commented code was marked by me - ews.
 *
 *  08/10/1999
 **********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

/*
#ifdef random
#undef random
#endif
*/

#include <time.h>

#define MAX_ENTRIES 100
#define DEGREES 4

//to run in command-line mode, set RANDOMIZED to 0
//RANDOM_SIZE controls the size of the random sample
#define COMMAND_LINE 2
#define RANDOMIZED   1
#define DEFAULT 		0


int runmode;
int rand_size;

//int random(){return 1;}

typedef struct {
    char name[50];
    char val[10];
} entry;

/*
 * from util.c
 */
char *makeword(char *line, char stop){};
char *fmakeword(FILE *f, char stop, int *len){};
char x2c(char *what);
void unescape_url(char *url){};
void plustospace(char *str){};

main(int argc, char *argv[]){
   int i;

   runmode = RANDOMIZED;

   if(argc >= 3 && strlen(argv[1]) >= 2 && strncmp(argv[1], "-r", 2)==0){

     	rand_size = atoi(argv[2]);
      runmode = RANDOMIZED;

   	for(i=0; i < rand_size; i++)
   		main2(argc, argv);

   }else
   	main2(argc, argv);

}

main2(int argc, char* argv[])
{
    entry entries[MAX_ENTRIES];
    register int x, m=0;
    int content_length=0;
    char buf[256];
    FILE *out;
    double EAF = 1.0, rely=0, data=0, cplx=0, time=0, stor=0, VIRT=0, TURN=0;
    double acap=0, aexp=0, pcap=0, VEXP=0, LEXP=0, ltex=0, MODP=0, tool=0, sced=0;
    double  pmat=0;
    double multiplier = 1.0;
    double MODE=0, CONSTANT=0, PM=0, exponent=0, TDEV=0, TDEVEXP=0;
    int SIZE=0;
    int i, j, k, param_num=0;

    int sced_index=0,rely_index=0,pvol_index=0,tool_index=0,acap_index=0,aexp_index=0;
    int pcap_index=0,data_index=0,cplx_index=0,time_index=0,stor_index=0;
    int ltex_index=0,ruse_index=0,docu_index=0,pcon_index=0,pexp_index,site_index=0;
    int prec_index=0,flex_index=0,arch_index=0,team_index=0,pmat_index=0;

    double total_risk_normalized=0,product_risk_normalized=0;
    double schedule_risk_normalized=0;
    double personnel_risk_normalized=0,process_risk_normalized=0;
    double platform_risk_normalized=0,reuse_risk_normalized=0;


    double prec_scale[6] = { 4.05, 3.24,2.43,1.62,0.81,  0.};
    double flex_scale[6] = { 6.07, 4.86,3.64,2.43,1.21,  0.};
    double arch_scale[6] = { 4.22, 3.38,2.53,1.69,0.84,  0.};
    double team_scale[6] = { 4.94, 3.95,2.97,1.98,0.99,  0.};
    double pmat_scale[6] = { 4.54, 3.64,2.73,1.82,0.91,  0.};

    double rely_mult[6] = { 0.75, 0.88,1.00,1.15,1.40,  0.};
    double data_mult[6] = {  0.,.94,1.00,1.08,1.16,  0.};
    double cplx_mult[6] = {0.75,0.88,1.00,1.15,1.30,1.65};
    double ruse_mult[6] = {  0.,.89,1.00,1.16,1.34,1.56};
    double docu_mult[6] = {0.85,0.93,1.00,1.08,1.17,  0.};
    double time_mult[6] = {  0.,  0.,1.00,1.11,1.30,1.66};
    double stor_mult[6] = {  0.,  0.,1.00,1.06,1.21,1.56};
    double pvol_mult[6] = {  0.,0.87,1.00,1.15,1.30,  0.};
    double acap_mult[6] = {1.50,1.22,1.00,0.83,0.67,  0.};
    double pcap_mult[6] = {1.37,1.16,1.00,0.87,0.74,  0.};
    double pcon_mult[6] = {1.26,1.11,1.00,0.91,0.83,  0.};
    double aexp_mult[6] = {1.23,1.10,1.00,0.88,0.80,  0.};
    double pexp_mult[6] = {1.26,1.12,1.00,0.88,0.80,  0.};
    double ltex_mult[6] = {1.24,1.11,1.00,0.90,0.82,  0.};
    double tool_mult[6] = {1.20,1.10,1.00,0.88,0.75,  0.};
    double site_mult[6] = {1.24,1.10,1.00,0.92,0.85, 0.79};
    double sced_mult[6] = {1.23,1.08,1.00,1.04,1.10,  0.};

    double prec_mult[6],flex_mult[6],arch_mult[6],team_mult[6],pmat_mult[6];

    double total_risk=0,schedule_risk=0,product_risk=0,personnel_risk=0;
    double process_risk=0,platform_risk=0,reuse_risk=0.0;

/*	schedule risks	*/
    double sced_rely_risk=0,sced_time_risk=0,sced_pvol_risk=0,sced_tool_risk=0;
    double sced_cplx_risk=0;
    double sced_acap_risk=0,sced_aexp_risk=0,sced_pcap_risk=0,sced_pexp_risk=0;
    double sced_ltex_risk=0,sced_pmat_risk=0;

/*	product risks	*/
    double rely_acap_risk=0,rely_pcap_risk=0,cplx_acap_risk=0,cplx_pcap_risk=0;
    double cplx_tool_risk=0,rely_pmat_risk=0,size_pcap_risk=0;

/*	personnel risks	*/
    double pmat_acap_risk=0,stor_acap_risk=0,time_acap_risk=0,tool_acap_risk=0;
    double ruse_aexp_risk=0,ruse_ltex_risk=0;
    double pmat_pcap_risk=0,stor_pcap_risk=0,time_pcap_risk=0,ltex_pcap_risk=0;
    double pvol_pexp_risk=0,tool_pcap_risk=0;

/*	process risks	*/
    double tool_pmat_risk=0,time_tool_risk=0;
    double team_aexp_risk=0,team_sced_risk=0,team_site_risk=0;

/*	platform risks	*/


/*          VL    L     N   H  VH  EH	factor2
VL
 L
 N factor1
 H
VH
EH	*/

/*	schedule	*/
    double sced_rely_risklevel[6][6]={
      {0.  ,0.  , 0.  ,1.  ,2.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,1.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_cplx_risklevel[6][6]={
      {0.  ,0.  , 0.  ,1.  ,2.  ,4.},
      {0.  ,0.  , 0.  ,0.  ,1.  ,2.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,1.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_time_risklevel[6][6]={
      {-99.  ,-99.  , 0.  ,1.  ,2.  ,4.},
      {-99.  ,-99.  , 0.  ,0.  ,1.  ,2.},
      {-99.  ,-99.  , 0.  ,0.  ,0.  ,1.},
      {-99.  ,-99.  , 0.  ,0.  ,0.  ,0.},
      {-99.  ,-99.  , 0.  ,0.  ,0.  ,0.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_pvol_risklevel[6][6]={
      {0.  ,0.  , 0.  ,1.  ,2.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,1.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_tool_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_pexp_risklevel[6][6]={
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_pcap_risklevel[6][6]={
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_aexp_risklevel[6][6]={
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_acap_risklevel[6][6]={
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_ltex_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double sced_pmat_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};


/*	product	*/
    double rely_acap_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double rely_pcap_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};


    double cplx_acap_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.}};

    double cplx_pcap_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.}};

    double cplx_tool_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.}};

    double rely_pmat_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,0.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,0.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

/*	personnel	*/

    double pmat_acap_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.}};

    double stor_acap_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.}};

    double time_acap_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.}};

    double tool_acap_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double tool_pcap_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double ruse_aexp_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.}};

    double ruse_ltex_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.}};

    double pmat_pcap_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.}};

    double stor_pcap_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.}};

    double time_pcap_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.}};

    double ltex_pcap_risklevel[6][6]={
      {4.  ,2.  , 1.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};

    double pvol_pexp_risklevel[6][6]={
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.},
      {-99.,-99., -99.,-99.,-99.,-99.}};


/*	process	*/

    double tool_pmat_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,0.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {-99.  ,-99.  , -99.  ,-99.  ,-99.  ,-99.}};

    double time_tool_risklevel[6][6]={
      {-99.  ,-99.  , -99.  ,-99.  ,-99.  ,-99.},
      {-99.  ,-99.  , -99.  ,-99.  ,-99.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,-99.},
      {2.  ,1.  , 0.  ,0.  ,0.  ,-99.}};

    double team_aexp_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,0.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.}};

    double team_sced_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,0.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.}};

    double team_site_risklevel[6][6]={
      {2.  ,1.  , 0.  ,0.  ,0.  ,0.},
      {1.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.},
      {0.  ,0.  , 0.  ,0.  ,0.  ,0.}};


/* added 8/26/1999 - ews */
const char *names[] = {"size", "prec", "flex", "resl", "team", "team", "pmat",
   "rely", "data", "cplx", "ruse", "docu", "time", "stor", "pval",
   "acap", "pcap", "pcon", "aexp", "pexp", "ltex", "tool", "site", "sced"};



/* ews - 08/10/1999

    printf(out, out, "Content-type: text/html%c%c",10,10);
    if(strcmp(getenv("REQUEST_METHOD"),"POST"))
      {
        printf(out, out, "This script should be referenced with a METHOD of POST.\n");
        printf(out, "If you don't understand this, see this ");
        printf(out, "<A HREF=\"http://www.ncsa.uiuc.edu/SDG/Software/Mosaic");
        printf(out, "/Docs/fill-out-forms/overview.html\">forms overview</A>.%c",10);
        exit(1);
      }
    if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded"))
      {
        printf(out, "This script can only be used to decode form results. \n");
        exit(1);
      }


    content_length = atoi(getenv("CONTENT_LENGTH"));


    for(x=0; content_length && (!feof(stdin)); x++){

        m=x;
        entries[x].val = fmakeword(stdin,'&',&content_length);
        plustospace(entries[x].val);
        unescape_url(entries[x].val);
        entries[x].name = makeword(entries[x].val,'=');
*/

/*** replacement code - ews ***/

   if(runmode != RANDOMIZED) out=fopen("cocomo.html", "w");
   else            out=fopen("cocomo.txt", "a+");

	if(!out){
   	perror("output file");
      exit(1);
   }

   x=0;



	if(runmode == RANDOMIZED){
       for(i=0; i < 23; i++)  strcpy(entries[i].name, names[i]);

       // due to individual domains for the values, this must be
       //   done individually, and cannot be handled in one loop
       srandom((unsigned int) 0);


       // size range: 50,000 - 10,000,000 LOC, 100 buckets
       sprintf(entries[0].val, "%d", 50000 + (int)((random()%100)*100505.05));
       sprintf(entries[1].val, "%d", random()%6);
       sprintf(entries[2].val, "%d", random()%6);
       sprintf(entries[3].val, "%d", random()%6);
       sprintf(entries[4].val, "%d",  random()%6);
       sprintf(entries[5].val, "%d",  random()%6);
       sprintf(entries[6].val, "%d",  random()%5);
       sprintf(entries[7].val, "%d",  random()%4 + 1);
       sprintf(entries[8].val, "%d",  random()%6);
       sprintf(entries[9].val, "%d",  random()%5 + 1);
       sprintf(entries[10].val, "%d", random()%5);
       sprintf(entries[11].val, "%d", random()%4 + 2);
       sprintf(entries[12].val, "%d", random()%4 + 2);
       sprintf(entries[13].val, "%d", random()%4 + 1);
       sprintf(entries[14].val, "%d", random()%5);
       sprintf(entries[15].val, "%d", random()%5);
       sprintf(entries[16].val, "%d", random()%5);
       sprintf(entries[17].val, "%d", random()%5);
       sprintf(entries[18].val, "%d", random()%5);
       sprintf(entries[19].val, "%d", random()%5);
       sprintf(entries[20].val, "%d", random()%5);
       sprintf(entries[21].val, "%d", random()%6);
       sprintf(entries[22].val, "%d", random()%5);
	}



	for(k=1; k< argc; k++){
      if(strlen(argv[k]) == 2 && strncmp(argv[k], "-s", 2)==0){
         	k++;
			SIZE = atoi(argv[k]);
			strcpy(entries[0].val, argv[k]);
			if(SIZE == 0){
          	perror("Invalid size argument.");
            exit(1);
         }

      }else if(strlen(argv[k])== 2 && strncmp(argv[k], "-r", 2)==0){
     	  	k++;

      }else if(strlen(argv[k]) > 4 && (k+6) < argc){
      	if (strncmp(argv[k], "-prec", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				prec_scale[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-flex", 5)==0){
            for(j=0;j<6;j++){
             	k++;
   				flex_scale[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-arch", 5)==0 ||
		   strncmp(argv[k], "-resl", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				arch_scale[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-team", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				team_scale[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-pmat", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				pmat_scale[j] = atof(argv[k]);
            }


         }else if (strncmp(argv[k], "-rely", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				rely_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-data", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				data_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-cplx", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				cplx_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-ruse", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				ruse_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-docu", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				docu_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-time", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				time_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-stor", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				stor_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-pvol", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				pvol_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-acap", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				acap_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-pcap", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				pcap_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-pcon", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				pcon_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-aexp", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				aexp_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-pexp", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				pexp_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-ltex", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				ltex_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-tool", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				tool_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-site", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				site_mult[j] = atof(argv[k]);
            }

         }else if (strncmp(argv[k], "-sced", 5)==0){
            for(j=0;j<6;j++){
            	k++;
   				sced_mult[j] = atof(argv[k]);
            }
         }else{
         	printf("Unknown option: %s - skipped.\n\r",argv[k]);
            k = k+6;
         }

     /* assume any option without a leading "-" option is an input value */
     }else{
     		param_num++;
         if(strncmp(argv[k], "9", 1)!=0)
         	sprintf(entries[param_num].val, "%d", atoi(argv[k]));

     }
  	}






   do{
   		/* are we accepting command line input? */
        if(runmode == COMMAND_LINE){
           scanf("%s", entries[x].name);

           if(strncmp(entries[x].name, "quit", 4) == 0) break;

           scanf("%s", entries[x].val);

           m = x;
        }
/*** end replacement code ***/

        if ( !strcmp(entries[x].name, "size") ){
	            SIZE = atoi( entries[x].val );

        }else if ( !strcmp(entries[x].name, "mode") ){
	            MODE = strtod( entries[x].val, NULL );

		         if ( MODE == 1.05 ) {
		               CONSTANT = 3.2;
			            TDEVEXP = 0.38;
		         }else if ( MODE == 1.12 ) {
		               CONSTANT = 3.0;
			            TDEVEXP = 0.35;
               }else {
		               CONSTANT = 2.8;
			            TDEVEXP = 0.32;
		         }
        }else{
	            /* gather multipliers */
              multiplier = strtod( entries[x].val, NULL );
		        EAF = EAF * multiplier;
           }
        x++;
      }while( x < 23);





    /*  commented by author - ews
     * Check SIZE field for a valid number
     if (SIZE < 2000 || SIZE > 2000000)
     {
     fprintf(out, "<title>Request Rejected</title>");
     fprintf(out, "<h1>Request Rejected</h1><p>");
     fprintf(out, "You <em>must</em> enter a size between 2,000 and 2,000,000.<p>");
     fprintf(out, "Please back up one page and try again.");
     return 0;
     }
     */

/*  commented by author - ews  
    fprintf(out, "<h3>You submitted the following name / value pairs:</h3>");
    fprintf(out, "<ul>%c",10);
    for(x=0; x <= m; x++)
        fprintf(out, "<li> <code>%s = %s</code>%c\n",entries[x].name,
               entries[x].val,10);
    fprintf(out, "</ul>%c",10);

    fprintf(out, "<hr>");		*/


    /*	hardwire the indices	*/
    x=1;
    prec_index=atoi(entries[x].val);
    x=2;
    flex_index=atoi(entries[x].val);
    x=3;
    arch_index=atoi(entries[x].val);
    x=4;
    team_index=atoi(entries[x].val);
    x=5;
    pmat_index=atoi(entries[x].val);

    x=6;
    rely_index=atoi(entries[x].val);
    x=7;
    data_index=atoi(entries[x].val);
    x=8;
    cplx_index=atoi(entries[x].val);
    x=9;
    ruse_index=atoi(entries[x].val);
    x=10;
    docu_index=atoi(entries[x].val);
    x=11;
    time_index=atoi(entries[x].val);
    x=12;
    stor_index=atoi(entries[x].val);
    x=13;
    pvol_index=atoi(entries[x].val);
    x=14;
    acap_index=atoi(entries[x].val);
    x=15;
    pcap_index=atoi(entries[x].val);
    x=16;
    pcon_index=atoi(entries[x].val);
    x=17;
    aexp_index=atoi(entries[x].val);
    x=18;
    pexp_index=atoi(entries[x].val);
    x=19;
    ltex_index=atoi(entries[x].val);
    x=20;
    tool_index=atoi(entries[x].val);
    x=21;
    site_index=atoi(entries[x].val);
    x=22;
    sced_index=atoi(entries[x].val);

/*	effort and schedule calculations	*/
    EAF =
rely_mult[rely_index]*data_mult[data_index]*cplx_mult[cplx_index]*
ruse_mult[ruse_index]*docu_mult[docu_index]*time_mult[time_index]*
stor_mult[stor_index]*pvol_mult[pvol_index]*acap_mult[acap_index]*
pcap_mult[pcap_index]*pcon_mult[pcon_index]*aexp_mult[aexp_index]*
pexp_mult[pexp_index]*ltex_mult[ltex_index]*tool_mult[tool_index]*
site_mult[site_index]*sced_mult[sced_index];

    CONSTANT = 2.5;

    exponent = 1.01+.01*(prec_scale[prec_index]+flex_scale[flex_index]+
	arch_scale[arch_index]+team_scale[team_index]+pmat_scale[pmat_index]);

    PM = CONSTANT * EAF * pow((SIZE/1000), exponent);
    TDEVEXP = .33+.2*(exponent-1.01);
    TDEV = 3.0 * pow(PM/sced_mult[sced_index], TDEVEXP);

/*	schedule adjustment	*/
        	if ( sced_index== 0 )
	  {
	            	            TDEV = TDEV*.75;
	  }
	else if ( sced_index== 1 )
	  {
	            	            TDEV = TDEV*.85;

	  }
	else if ( sced_index== 3 )
	  {
	            	            TDEV = TDEV*1.3;

	  }
	else if ( sced_index== 4 )
	  {
	            	            TDEV = TDEV*1.6;

	  }

if(runmode != RANDOMIZED){
    fprintf(out, "<title>COCOMO II Results</title>");
    fprintf(out, "<body bgcolor=\"#FFFFFF\">");
    fprintf(out, "<h2>COCOMO II Results</h2>");

/*  commented by author - ews  
    fprintf(out, "<h3>Effort = %6.2f eaf</h3>\n", EAF);
    fprintf(out, "<h3>Effort = %6.2f exponent</h3>", exponent);	*/
    fprintf(out, "<h3>Effort = %6.2f Person-months</h3>\n", PM);
    fprintf(out, "<h3>Schedule = %6.2f Months</h3>", TDEV);

    fprintf(out, "<hr>");
}
    /*	calculate effective effort multipliers for scale drivers	*/

   prec_mult[0] = pow((SIZE/1000.),.02);
    prec_mult[1] = pow((SIZE/1000.),.01);
    flex_mult[0] = pow((SIZE/1000.),.02);
    flex_mult[1] = pow((SIZE/1000.),.01);
    arch_mult[0] = pow((SIZE/1000.),.02);
    arch_mult[1] = pow((SIZE/1000.),.01);
    team_mult[0] = pow((SIZE/1000.),.02);
    team_mult[1] = pow((SIZE/1000.),.01);
    pmat_mult[0] = pow((SIZE/1000.),.02);
    pmat_mult[1] = pow((SIZE/1000.),.01);
    pmat_mult[2] = pow((SIZE/1000.),.00);

/*	The lists below are only the (arbitrary) "home" risks per category.
Overlap is accounted for in the category summary equations.	*/

     /*	schedule risks	*/

sced_cplx_risk=sced_mult[sced_index]*cplx_mult[rely_index]*
sced_cplx_risklevel[sced_index][cplx_index];

sced_rely_risk=sced_mult[sced_index]*rely_mult[rely_index]*
sced_rely_risklevel[sced_index][rely_index];

sced_time_risk=sced_mult[sced_index]*time_mult[time_index]*
sced_time_risklevel[sced_index][time_index];
    
sced_pvol_risk=sced_mult[sced_index]*pvol_mult[pvol_index]*
sced_pvol_risklevel[sced_index][pvol_index];
    
sced_tool_risk=sced_mult[sced_index]*tool_mult[tool_index]*
sced_tool_risklevel[sced_index][tool_index];

sced_acap_risk=sced_mult[sced_index]*acap_mult[pvol_index]*
sced_acap_risklevel[sced_index][acap_index];

sced_aexp_risk=sced_mult[sced_index]*aexp_mult[aexp_index]*
sced_aexp_risklevel[sced_index][aexp_index];

sced_pcap_risk=sced_mult[sced_index]*pcap_mult[pcap_index]*
sced_pcap_risklevel[sced_index][pcap_index];

sced_pexp_risk=sced_mult[sced_index]*pexp_mult[pexp_index]*
sced_pexp_risklevel[sced_index][pexp_index];

sced_ltex_risk=sced_mult[sced_index]*ltex_mult[ltex_index]*
sced_ltex_risklevel[sced_index][ltex_index];

sced_pmat_risk=sced_mult[sced_index]*pmat_mult[pmat_index]*
sced_pmat_risklevel[sced_index][pmat_index];

/*	product risks	*/


rely_acap_risk=rely_mult[rely_index]*acap_mult[acap_index]*
rely_acap_risklevel[rely_index][acap_index];


rely_pcap_risk=rely_mult[rely_index]*pcap_mult[pcap_index]*
rely_pcap_risklevel[rely_index][pcap_index];

cplx_acap_risk=cplx_mult[cplx_index]*acap_mult[acap_index]*
cplx_acap_risklevel[cplx_index][acap_index];

cplx_pcap_risk=cplx_mult[cplx_index]*pcap_mult[pcap_index]*
cplx_pcap_risklevel[cplx_index][pcap_index];

cplx_tool_risk=cplx_mult[cplx_index]*tool_mult[tool_index]*
cplx_tool_risklevel[cplx_index][tool_index];

rely_pmat_risk=rely_mult[rely_index]*pmat_mult[pmat_index]*
rely_pmat_risklevel[rely_index][pmat_index];

/*	personnel risks	*/


pmat_acap_risk=pmat_mult[pmat_index]*acap_mult[acap_index]*
pmat_acap_risklevel[pmat_index][acap_index];

stor_acap_risk=stor_mult[stor_index]*acap_mult[acap_index]*
stor_acap_risklevel[stor_index][acap_index];

time_acap_risk=time_mult[time_index]*acap_mult[acap_index]*
time_acap_risklevel[time_index][acap_index];

tool_acap_risk=tool_mult[tool_index]*acap_mult[acap_index]*
tool_acap_risklevel[tool_index][acap_index];

tool_pcap_risk=tool_mult[tool_index]*pcap_mult[pcap_index]*
tool_pcap_risklevel[tool_index][pcap_index];

ruse_aexp_risk=ruse_mult[ruse_index]*aexp_mult[aexp_index]*
ruse_aexp_risklevel[ruse_index][aexp_index];

ruse_ltex_risk=ruse_mult[ruse_index]*ltex_mult[ltex_index]*
ruse_ltex_risklevel[ruse_index][ltex_index];

pmat_pcap_risk=pmat_mult[pmat_index]*pcap_mult[pcap_index]*
pmat_pcap_risklevel[pmat_index][pcap_index];

stor_pcap_risk=stor_mult[stor_index]*pcap_mult[pcap_index]*
stor_pcap_risklevel[stor_index][pcap_index];

time_pcap_risk=time_mult[time_index]*pcap_mult[pcap_index]*
time_pcap_risklevel[time_index][pcap_index];

ltex_pcap_risk=ltex_mult[ltex_index]*pcap_mult[pcap_index]*
ltex_pcap_risklevel[ltex_index][pcap_index];

pvol_pexp_risk=pvol_mult[pvol_index]*pexp_mult[pexp_index]*
pvol_pexp_risklevel[pvol_index][pexp_index];

/*	process risks	*/


tool_pmat_risk=tool_mult[tool_index]*pmat_mult[pmat_index]*
tool_pmat_risklevel[tool_index][pmat_index];

time_tool_risk=time_mult[time_index]*tool_mult[tool_index]*
time_tool_risklevel[time_index][tool_index];

team_aexp_risk=team_mult[team_index]*aexp_mult[aexp_index]*
team_aexp_risklevel[team_index][aexp_index];

team_sced_risk=team_mult[team_index]*sced_mult[sced_index]*
team_sced_risklevel[team_index][sced_index];

team_site_risk=team_mult[team_index]*site_mult[site_index]*
team_site_risklevel[team_index][site_index];

/*	summary category risks - overlaps are in the second adding equations	*/

schedule_risk=sced_rely_risk+sced_time_risk+sced_pvol_risk+sced_tool_risk+
sced_acap_risk+sced_aexp_risk+sced_pcap_risk+sced_pexp_risk+sced_ltex_risk+
sced_pmat_risk;


product_risk=rely_acap_risk+rely_pcap_risk+cplx_acap_risk+cplx_pcap_risk+
cplx_tool_risk+rely_pmat_risk;

product_risk=product_risk+sced_cplx_risk+sced_rely_risk+sced_time_risk+
ruse_aexp_risk+ruse_ltex_risk;


personnel_risk=pmat_acap_risk+stor_acap_risk+time_acap_risk+tool_acap_risk+
tool_pcap_risk+ruse_aexp_risk+ruse_ltex_risk+pmat_pcap_risk+stor_pcap_risk+
time_pcap_risk+ltex_pcap_risk+pvol_pexp_risk;

personnel_risk=personnel_risk+sced_acap_risk+sced_aexp_risk+sced_pcap_risk+
sced_pexp_risk+sced_ltex_risk+rely_acap_risk+rely_pcap_risk+cplx_acap_risk+
cplx_pcap_risk+team_aexp_risk;


process_risk=tool_pmat_risk+time_tool_risk+tool_pmat_risk+team_aexp_risk+
team_sced_risk+team_site_risk;

process_risk=process_risk+sced_tool_risk+sced_pmat_risk+cplx_tool_risk+
pmat_acap_risk+tool_acap_risk+tool_pcap_risk+pmat_pcap_risk;

/*	all platform risks are home in other categories	*/

platform_risk=sced_time_risk+sced_pvol_risk+stor_acap_risk+time_acap_risk+
stor_pcap_risk+pvol_pexp_risk+time_tool_risk;

    reuse_risk=reuse_risk+ruse_aexp_risk+ruse_ltex_risk;


total_risk=schedule_risk+product_risk+personnel_risk+process_risk+
platform_risk+reuse_risk;



/*   commented by author - ews 
    fprintf(out, "Total Project =%6.2f<br>",total_risk);
    fprintf(out, "Total Project  <IMG ALIGN=bottom
     SRC=http://sunset.usc.edu/COCOMOII/expert_cocomo/%2.0f.gif>",total_risk);	*/

    total_risk_normalized=total_risk/373.*100.;
    schedule_risk_normalized=schedule_risk/45.8*100.;
    product_risk_normalized=product_risk/82.5*100.;
    personnel_risk_normalized=personnel_risk/138.7*100.;
    process_risk_normalized=process_risk/44.1*100.;
    platform_risk_normalized=platform_risk/46.5*100.;
    reuse_risk_normalized=reuse_risk/100.*100.;


/* added if check - ews */
if(runmode != RANDOMIZED){
    fprintf(out, "<h2>Risk Assessment Summary  (0-100) </h2>");
    fprintf(out, "<TABLE COLSPAN=3 COLSPEC=L60 L40 L40  >");


    fprintf(out, "<TR ALIGN=left><TH><h3>   </h3></TH><TH>\n<IMG SRC=http://sunset"
 ".usc.edu/COCOMOII/expert_cocomo/scale.gif> </TH><TH><h3></h3></TH></TR>\n");

    fprintf(out, "<TR ALIGN=left>");
    fprintf(out, "<TH><h3>Total Project Risk  </h3></TH>");

        	if ( total_risk_normalized< 10.0 )
	  {
        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
              "/expert_cocomo/%1.0f.gif></TH>\n",total_risk_normalized);
	  }
	else if ( total_risk_normalized>= 10.0 && total_risk_normalized < 100.0 )
	  {
       fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII/"
                "expert_cocomo/%2.0f.gif></TH>\n",total_risk_normalized);
	  }
	else if ( total_risk_normalized== 100.0 )
	  {
        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
                 "/expert_cocomo/%3.0f.gif></TH>\n",total_risk_normalized);
	  }

    fprintf(out, "<TH>%5.1f</TH></TR>",total_risk_normalized);

    fprintf(out, "<TR ALIGN=left>");
    fprintf(out, "<TH><h4>Schedule Risk</h4></TH>\n");
        	if ( schedule_risk_normalized< 10.0 )
	  {
          fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII/"
            "expert_cocomo/%1.0f.gif></TH>\n",schedule_risk_normalized);
	  }
	else if ( schedule_risk_normalized>= 10.0 && schedule_risk_normalized<100.0 )
	  {
	     fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
              "/expert_cocomo/%2.0f.gif></TH>\n",schedule_risk_normalized);
	  }
	else if ( schedule_risk_normalized== 100.0 )
	  {
        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
             "/expert_cocomo/%3.0f.gif></TH>\n",schedule_risk_normalized);
	  }
    fprintf(out, "<TH>%5.1f</TH></TR>",schedule_risk_normalized);

    fprintf(out, "<TR ALIGN=left>");
    fprintf(out, "<TH><h4>Product Risk</h4></TH>\n");
        	if ( product_risk_normalized< 10.0 )
	  {
	     fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII/"
            "expert_cocomo/%1.0f.gif></TH>\n",product_risk_normalized);
	  }
	else if ( product_risk_normalized>= 10.0 && product_risk_normalized< 100.0 )
	  {
	      fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
         "/expert_cocomo/%2.0f.gif></TH>\n",product_risk_normalized);
	  }
	else if ( product_risk_normalized== 100.0 )
	  {
	     fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
             "/expert_cocomo/%3.0f.gif></TH>\n",product_risk_normalized);
	  }
    fprintf(out, "<TH>%5.1f</TH></TR>",product_risk_normalized);

    fprintf(out, "<TR ALIGN=left>");
    fprintf(out, "<TH><h4>Platform Risk</h4></TH>\n");
        	if ( platform_risk_normalized< 10.0 )
	  {
	        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII/"
"expert_cocomo/%1.0f.gif></TH>",platform_risk_normalized);
	  }
	else if ( platform_risk_normalized>= 10.0 && platform_risk_normalized<100.0 )
	  {
	        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
"/expert_cocomo/%2.0f.gif></TH>",platform_risk_normalized);
	  }
	else if ( platform_risk_normalized== 100.0 )
	  {
	        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
              "/expert_cocomo/%3.0f.gif></TH>",platform_risk_normalized);
	  }

    fprintf(out, "\n<TH>%5.1f</TH></TR>",platform_risk_normalized);

    fprintf(out, "<TR ALIGN=left>");
    fprintf(out, "<TH><h4>Personnel Risk</h4></TH>\n");
        	if ( personnel_risk_normalized< 10.0 )
	  {
	        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
            "/expert_cocomo/%1.0f.gif></TH>",personnel_risk_normalized);
	  }
	else if (personnel_risk_normalized>= 10.0 && personnel_risk_normalized<100.0)
	  {
	        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII/"
           "expert_cocomo/%2.0f.gif></TH>",personnel_risk_normalized);
	  }
	else if ( personnel_risk_normalized== 100.0 )
	  {
	     fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
              "/expert_cocomo/%3.0f.gif></TH>",personnel_risk_normalized);
	  }

    fprintf(out, "\n<TH>%5.1f</TH></TR>",personnel_risk_normalized);

    fprintf(out, "<TR ALIGN=left>");
    fprintf(out, "<TH><h4>Process Risk</h4></TH>\n");
        	if ( process_risk_normalized< 10.0 )
	  {
	         fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII/"
            "expert_cocomo/%1.0f.gif></TH>",process_risk_normalized);
	  }
	else if ( process_risk_normalized>= 10.0 && process_risk_normalized< 100.0 )
	  {
	        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII/"
              "expert_cocomo/%2.0f.gif></TH>",process_risk_normalized);
	  }
	else if ( process_risk_normalized== 100.0 )
	  {
	         fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
             "/expert_cocomo/%3.0f.gif></TH>",process_risk_normalized);
	  }
    fprintf(out, "\n<TH>%5.1f</TH></TR>",process_risk_normalized);

    fprintf(out, "<TR ALIGN=left>");
    fprintf(out, "<TH><h4>Reuse Risk</h4></TH>\n");
        	if ( reuse_risk_normalized< 10.0 )
	  {
	        fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
             "/expert_cocomo/%1.0f.gif></TH>",reuse_risk_normalized);
	  }
	else if ( reuse_risk_normalized>= 10.0 && reuse_risk_normalized< 100.0 )
	  {
	          fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
              "/expert_cocomo/%2.0f.gif></TH>",reuse_risk_normalized);
	  }
	else if ( reuse_risk_normalized== 100.0 )
	  {
	           fprintf(out, "<TH><IMG ALIGN=bottom SRC=http://sunset.usc.edu/COCOMOII"
             "/expert_cocomo/%3.0f.gif></TH>",reuse_risk_normalized);
	  }

    fprintf(out, "\n<TH>%5.1f</TH></TR>",reuse_risk_normalized);

    fprintf(out, "</TABLE>\n");

/* print summary and recommendations based on risk level*/

    	if ( total_risk_normalized< 5.0 )
	  {
	         fprintf(out, "<h3>*** This project is a low risk.  Try"
" to mitigate the top individual risk items. ***</h3>");
	  }
	else if ( total_risk_normalized> 5.0 && total_risk_normalized < 15.0 )
	  {
	        fprintf(out, "<h3>*** This project is a medium risk.  Try to"
" mitigate the top individual risk items. ***</h3>");
	  }
	else if ( total_risk_normalized> 15.0 && total_risk_normalized < 50.0 )
	  {
	         fprintf(out, "<h3>*** This project is a high risk.  Try to mitigate"
" the top individual risk items. ***</h3>");
	  }
	else if ( total_risk_normalized> 50.0 )
	  {
	         fprintf(out, "<h3>*** This project is a very high risk.  Try to"
" mitigate the top individual risk items. ***</h3>");
	  }

/*	individual risk items	*/
    fprintf(out, "<h2>Individual Risk Items (non-normalized)</h2>");

    fprintf(out, "sced_cplx_risk=%6.2f<br>\n",sced_cplx_risk);
    fprintf(out, "sced_rely_risk=%6.2f<br>\n",sced_rely_risk);
    fprintf(out, "sced_time_risk=%6.2f<br>\n",sced_time_risk);
    fprintf(out, "sced_pvol_risk=%6.2f<br>\n",sced_pvol_risk);
    fprintf(out, "sced_tool_risk=%6.2f<br>\n",sced_tool_risk);
    fprintf(out, "sced_pexp_risk=%6.2f<br>\n",sced_pexp_risk);
    fprintf(out, "sced_pcap_risk=%6.2f<br>\n",sced_pcap_risk);
    fprintf(out, "sced_aexp_risk=%6.2f<br>\n",sced_aexp_risk);
    fprintf(out, "sced_acap_risk=%6.2f<br>\n",sced_acap_risk);
    fprintf(out, "sced_ltex_risk=%6.2f<br>\n",sced_ltex_risk);
    fprintf(out, "sced_pmat_risk=%6.2f<br>\n",sced_pmat_risk);

    fprintf(out, "rely_acap_risk=%6.2f<br>\n",rely_acap_risk);
    fprintf(out, "rely_pcap_risk=%6.2f<br>\n",rely_pcap_risk);
    fprintf(out, "cplx_acap_risk=%6.2f<br>\n",cplx_acap_risk);
    fprintf(out, "cplx_pcap_risk=%6.2f<br>\n",cplx_pcap_risk);
    fprintf(out, "cplx_tool_risk=%6.2f<br>\n",cplx_tool_risk);
    fprintf(out, "rely_pmat_risk=%6.2f<br>\n",rely_pmat_risk);

    fprintf(out, "pmat_acap_risk=%6.2f<br>\n",pmat_acap_risk);
    fprintf(out, "stor_acap_risk=%6.2f<br>\n",stor_acap_risk);
    fprintf(out, "time_acap_risk=%6.2f<br>\n",time_acap_risk);
    fprintf(out, "tool_acap_risk=%6.2f<br>\n",tool_acap_risk);
    fprintf(out, "tool_pcap_risk=%6.2f<br>\n",tool_pcap_risk);
    fprintf(out, "ruse_aexp_risk=%6.2f<br>\n",ruse_aexp_risk);
    fprintf(out, "ruse_ltex_risk=%6.2f<br>\n",ruse_ltex_risk);
    fprintf(out, "pmat_pcap_risk=%6.2f<br>\n",pmat_pcap_risk);
    fprintf(out, "stor_pcap_risk=%6.2f<br>\n",stor_pcap_risk);
    fprintf(out, "time_pcap_risk=%6.2f<br>\n",time_pcap_risk);
    fprintf(out, "ltex_pcap_risk=%6.2f<br>\n",ltex_pcap_risk);
    fprintf(out, "pvol_pexp_risk=%6.2f<br>\n",pvol_pexp_risk);

    fprintf(out, "tool_pmat_risk=%6.2f<br>\n",tool_pmat_risk);
    fprintf(out, "time_tool_risk=%6.2f<br>\n",time_tool_risk);

    fprintf(out, "team_aexp_risk=%6.2f<br>\n",team_aexp_risk);
    fprintf(out, "team_sced_risk=%6.2f<br>\n",team_sced_risk);
    fprintf(out, "team_site_risk=%6.2f<br>\n",team_site_risk);

    fprintf(out, "<br>");

}else{
   /* we're in the randomized version
   output takes the format : size, d1, d2, d3, ... d22, r1, r2, ... r6, total
   d=driver, r=risk, total=total risk.  In all cases risk increases with value
   */
   strcpy(buf, "\0");
  
	sprintf(buf, "%d, ", SIZE);
   for(i=1; i < 23; i++)
      sprintf(buf, "%s%d, ", buf, atoi(entries[i].val)); 

   
/*    sprintf(buf, "%s%6.2f, %6.2f, %6.2f, %6.2f, %6.2f, %6.2f, %6.2f\n", buf, 
      schedule_risk_normalized=schedule_risk/45.8*100.,
      product_risk_normalized=product_risk/82.5*100.,
      personnel_risk_normalized=personnel_risk/138.7*100.,
      process_risk_normalized=process_risk/44.1*100.,
      platform_risk_normalized=platform_risk/46.5*100.,
      reuse_risk_normalized=reuse_risk/100.*100.,
      total_risk_normalized=total_risk/373.*100.);
*/

	sprintf(buf, "%s %6.2f, %7.3f\n", buf, total_risk_normalized, PM);

    fprintf(out, "%s", buf);
    fflush(out);

   
}//RANDOMIZED 


    fclose(out);

    /*  commented by author - ews      
    printf(out, "<h3>Thank you for your interest in this model.</h3>");

    printf(out, "<img align=bottom src=""../../graphics/back.gif"">");
    printf(out, "<A HREF=""../Cocomo.html"">Back to the COCOMO Homepage</A>");
    */
}


