Back to index

radiance  4R0+20100331
gcomp.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: gcomp.c,v 1.3 2003/11/15 02:13:37 schorsch Exp $";
00003 #endif
00004 /*
00005  *  gcomp.c - program to calculate things from graph files.
00006  *
00007  *     7/7/86
00008  *
00009  *     Greg Ward Larson
00010  */
00011 
00012 #include  <stdlib.h>
00013 #include  <stdio.h>
00014 
00015 #include "rterror.h"
00016 #include "meta.h"
00017 #include "mgvars.h"
00018 
00019 #define  istyp(s)    (s[0] == '-')
00020 
00021 #define  isvar(s)    (s[0] == '+')
00022 
00023 char  *progname;
00024 
00025 char  *libpath[4];
00026 
00027 static void dofile(int  optc, char  *optv[], char  *file);
00028 
00029 int
00030 main(
00031        int  argc,
00032        char  *argv[]
00033 )
00034 {
00035        char  *getenv();
00036        int  i, file0;
00037 
00038        progname = argv[0];
00039        libpath[0] = "./";
00040        if ((libpath[i=1] = getenv("MDIR")) != NULL)
00041               i++;
00042        libpath[i++] = MDIR;
00043        libpath[i] = NULL;
00044 
00045        for (file0 = 1; file0 < argc; )
00046               if (istyp(argv[file0]))
00047                      file0++;
00048               else if (isvar(argv[file0]) && file0 < argc-1)
00049                      file0 += 2;
00050               else
00051                      break;
00052 
00053        if (file0 >= argc)
00054               dofile(argc-1, argv+1, NULL);
00055        else
00056               for (i = file0; i < argc; i++)
00057                      dofile(file0-1, argv+1, argv[i]);
00058 
00059        quit(0);
00060        return 0; /* pro forma return */
00061 }
00062 
00063 
00064 void
00065 dofile(              /* plot a file */
00066        int  optc,
00067        char  *optv[],
00068        char  *file
00069 )
00070 {
00071        char  types[16], stmp[256], *strcat();
00072        int  i;
00073 
00074        mgclearall();
00075 
00076        mgload(file);
00077 
00078        types[0] = '\0';
00079        for (i = 0; i < optc; i++)
00080               if (istyp(optv[i]))
00081                      strcat(types, optv[i]+1);
00082               else {
00083                      sprintf(stmp, "%s=%s", optv[i]+1, optv[i+1]);
00084                      setmgvar("command line", stdin, stmp);
00085                      i++;
00086               }
00087 
00088        gcalc(types);
00089 }
00090 
00091 
00092 void
00093 eputs(                      /* print error message */
00094        char  *msg
00095 )
00096 {
00097        fputs(msg, stderr);
00098 }
00099 
00100 
00101 void
00102 quit(                       /* quit program */
00103        int  code
00104 )
00105 {
00106        exit(code);
00107 }