char rcsid[] =" @(#)$Header: Work:User/src/E12/RCS/main.c 2.3 1997/11/03 22:45:33 cts Exp $";
#define PROGVERSION  "1.4"
#define PROGDATE     "03.11.97"
#define y2k_DATE     "03.11.1997"
#define PROGNAME     "E12"
/*
#define DEBUG_main
 */
/*+ "RCS info" */
/*
 * $Revision: 2.3 $
 * $State: Exp $
 * $Author: cts $
 * $Locker:  $
 * $Date: 1997/11/03 22:45:33 $
 *
 * $Log: main.c $
 * Revision 2.3  1997/11/03  22:45:33  cts
 * first release version
 *
 * Revision 2.2  1997/10/18  02:23:27  cts
 * fixed some scale bugs. 2s working.
 *
 * Revision 2.1  1997/10/18  01:36:27  cts
 * resistor arithmetics. r2 series works!
 *
 * Revision 2.0  1997/10/13 00:42:33  cts
 * create struct for resistor: value, scale, index
 *
 * Revision 1.7  1997/10/12  22:34:42  cts
 * ident info
 *
 * Revision 1.6  1997/10/10  00:34:06  cts
 * usage included again
 *
 * Revision 1.5  1997/10/09  23:56:29  cts
 * 05101997
 *
 * Revision 1.4  1997/10/05 14:41:32  cts
 * nicer output
 *
 * Revision 1.3  1997/10/05 03:07:51  cts
 * 1 resistor ok
 *
 * Revision 1.2  1997/10/05  01:40:41  cts
 * E6..E24 values
 *
 * Revision 1.1  1997/10/02  00:27:01  cts
 * define E12 values
 *
 */
/*- */
/*+ "defines and includes" */
#include "main.h"

const char Version[] = "$VER: " PROGNAME " " PROGVERSION " (" PROGDATE ")"
" © 1997 Christian T. Steigies";

/*- */
/*+ "int main( int argc, char *argv[] )" */
int main( int argc, char *argv[] )
{
	double r;
	struct resistor r0, r1, r2, r3, r4, r5;

/*        puts ("BUG!!! call: E12 1.2, 28, 280, ...???\n"); fixed! */
	if ( argc == 1) {
/*+ "copyright" */
		printf ("%s\n",Version+6);
		printf ("This is free software; see the source for copying conditions.\n");
		printf ("There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\nPARTICULAR PURPOSE.\n\n");
#ifdef DEBUG
		printf ("compiled by GCC %s on %s at %s\n\n",__VERSION__,__DATE__,__TIME__);
#endif
		printf ("usage: "PROGNAME" <value>\n");
/*- */
	}
	else { /* argc >1 */
		if ( ( argc == 2 ) ) {
			r0 = res_set( atof(argv[1]) );
#ifdef DEBUG_main
			printf("R= %f\n", res_val(r0));
#endif
			if ( res_val(r0) < 0. ) {
				printf("Go, build an active circuit...\n");
				exit(EXIT_SUCCESS);
			}
			else if ( res_val(r0) == 0. ) {
				printf("You need a resistor for that?\n");
				exit(EXIT_SUCCESS);
			}
			printf("fit %.3f Ohm with resistors from the E12 series:\n", res_val(r0));
			r1 = E12_1(r0);
#ifdef DEBUG_main
			printf("E12_R  1: %8.3f ~= %8.3f                       |index  %4i\n", res_val(r0), res_val(r1), r1.index);
#endif
			printf("one resistor:              %.3f\n", res_val(r1));
			if (res_val(r0) != res_val(r1)) {
				r2.value = 1.; r2.scale = 1.; r2.index = 1;
				r3.value = 1.; r3.scale = 1.; r3.index = 1;
				r = E12_2s(r0, &r2, &r3);
				printf("two resistors in series  : %.3f +  %.3f = %.3f\n", res_val(r2), res_val(r3), r);
#ifdef DEBUG_main
				printf("E12_R 2s a: value:%8.3f | index : %4i\n", res_val(r2), r2.index );
				printf("E12_R 2s b: value:%8.3f | index : %4i\n", res_val(r3), r3.index );
				printf("E12_R 2s: %8.3f ~= %8.3f = %8.3f + %8.3f |index1 %4i index2 %4i\n", res_val(r0), r, res_val(r2), res_val(r3), r2.index, r3.index);
#endif
				r = E12_2p(r0, &r4, &r5);
				if (res_val(r5) != 0.) {
					printf("two resistors in parallel: %.3f || %.3f = %.3f\n", res_val(r4), res_val(r5), r);
				}
#ifdef DEBUG_main
				printf("E12_R 2p: %8.3f ~= %8.3f = %8.3f p %8.3f |index1 %4i index2 %4i\n", res_val(r0), r, res_val(r4), res_val(r4), r4.index, r5.index);
#endif
			}
		} /* argc = 2 */
		else {
		} /* nothing else... */
		puts("\nReady.");
	} /*argc >1 */
}
/*- */

