/* ** conversion.c ** ** ** This program reads in the parameters of the NICMOS Units Conversion ** FORM and uses them to run the FORTRAN program (written by Chris Skinner ** and modified by Daniela Calzetti) ** "conversion2.f". ** ** The output is then sent back to the Mosaic screen. ** ** ** Doris Daou. 25 Apr 1996. ** Modified: Daniela Calzetti 01 July 1996. ** */ #include #include #include #include "util.h" #define MAX_ENTRIES 10000 typedef struct { char *name; char *val; } entry; 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); conpar(entry *entries, char *datadir, int m, char *parfile, char *sfile, char *prog) { /* entries -- the array of parameters and values from the FORM m -- the number of parameters in the array datadir -- the output directory parfile -- file that keeps the FORMs specifications. It is the input file for the "conversion.f" program. sfile -- file that keeps the results on screen. prog -- THe fortran program that we link to. */ FILE *fp; FILE *fs; char srepfile[256]; char inputfile[256]; char command[256]; char string[256]; register int x; int l; char *s; /* set up the temporary parameter file based on the full conmain.par */ sprintf(inputfile, "%s/%s%d", datadir, parfile, (int)getpid()); /* set up the name of the temporary screen report file */ sprintf(srepfile, "%s/%s%d", datadir, sfile, (int)getpid()); fp=fopen(inputfile,"w"); /* write the paramters from the FORM into the temporary file : */ /* "inputfile" */ if (fp != NULL) { /* determine the parameters. */ fprintf(fp,"conmain.inputunits = %s\n",entries[1].val); fprintf(fp,"conmain.outputunits = %s\n",entries[3].val); fprintf(fp,"conmain.fluxvalue = %s\n",entries[4].val); fprintf(fp,"conmain.ilambda = %s\n",entries[5].val); fprintf(fp,"conmain.olambda = %s\n",entries[6].val); /* determine which type of spectrum is selected */ if(!strcmp(entries[7].name,"spectrum")) { fprintf(fp,"conmain.spec = %s\n",entries[7].val); fprintf(fp,"conmain.temp = %s\n",entries[8].val); } else if(!strcmp(entries[8].name,"spectrum")) { fprintf(fp,"conmain.spec = %s\n",entries[8].val); fprintf(fp,"conmain.ind1 = %s\n",entries[9].val); } else { fprintf(fp,"conmain.spec = %s\n",entries[9].val); fprintf(fp,"conmain.ind2 = %s\n",entries[10].val); } } fclose(fp); /* Send the command to run program. */ /* using the input parameters of 'inputfile'. */ fs = fopen(srepfile,"w"); sprintf(command, "%s < %s > %s",prog,inputfile,srepfile); system(command); fclose(fs); fs = fopen(srepfile,"r"); printf("

"); for(l=0;fgets(string,sizeof(string),fs) != '\0'; l++) printf("%s",string); fclose(fs); printf("

"); } main(int argc,char *argv[]){ entry entries[MAX_ENTRIES]; register int x,m=0; int cl; char *datadir, *parfile, *sfile, *prog; char *ename; printf("Content-type: text/html%c%c",10,10); printf("NICMOS Units Conversion Tool Results%c",10); printf("

NICMOS Units Conversion Tool Results

%c",10); printf("
%c",10); printf("
%c",10);

    cl = atoi(getenv("CONTENT_LENGTH"));
/*    datadir = "/data/picard3/NICMOS/web/tmp/NICMOS"; */
    datadir = "/var/tmp/NICMOS";

    for(x=0;cl && (!feof(stdin));x++) {
        m=x;
        entries[x].val = fmakeword(stdin,'&',&cl);
        plustospace(entries[x].val);
        unescape_url(entries[x].val);
        entries[x].name = makeword(entries[x].val,'=');
    }


    parfile = "conpar";
    sfile = "consrep";
/*    prog = "/data/picard3/NICMOS/web/cgi-bin/convertf2"; */
    prog = "/opt/www/cgi-bin/convertf2";
    conpar(entries, datadir, m, parfile, sfile, prog);

    printf("
%c",10); printf("This page was created by Doris Daou%c",10); }