ftp.nice.ch/pub/next/science/physics/gck.2.01.s.tar.gz#/gckc.2.0.1/gck_main.c

This is gck_main.c in view mode; [Download] [Up]

/* ******************************************************************** */
/* *                           GCK                                    * */
/* *               A Circuit Simulation Program                       * */
/* *                    by Tanju Cataltepe                            * */
/* *                    (c) Copyright 1989                            * */
/* ******************************************************************** */
/* (c) Copyright 1989, Tanju Cataltepe */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>

#ifdef Macintosh
#include <console.h>
#include <Files.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif

#include <math.h>
#include <float.h>
#include "gck.h"
#define GLOBAL
#include "gck_vars.h"
#include "gck_protos.h"
#include "gck_errors.h"


void main(argc, argv)
int argc;
char *argv[];
{
long 	i;
long 	j;
boolean	is_symbol;
boolean have_read_filename;
aWord 	temp;

#ifdef Macintosh
  argc = ccommand(&argv);
#endif  

  timing.start = clock();
  
  if (argc < 2)
    errorReport(ERROR_ARGUMENT_USAGE, progName, ERR_VOID, 0);
  initializeGlobals();
  
  /* deal with command line */
  have_read_filename = FALSE;
  for (i = 1; i < argc; i++) {
    is_symbol = FALSE;
	strcpy(temp,argv[i]);
	if (temp[0] == '-')
	  parseCommandLineOptions(temp);
	else {
	  for (j = 0; j < (long) strlen(temp); j++) {
	    if (temp[j] == '=') {
	      is_symbol = TRUE;
	      break;
	      }
	    }  
	  if (is_symbol == TRUE)
	    parseCommandLineSymbol(temp);
	  if (is_symbol == FALSE) {
	    if (have_read_filename == FALSE) {
  	      have_read_filename = TRUE;
	      strcpy(rfile.filename,temp);
	      }
	    else
	      errorReport(ERROR_MULTIPLE_INPUT_FILES,0,ERR_VOID,0);
	    }
	  }
    } 

  if (PRINT_NORMAL) {
    fprintf(stderr,"GCKC, Version %s.",GCK_VERSION_RELEASE);
    fprintf(stderr,"  \"A Circuit Simulation Program.\"\n");
    fprintf(stderr,"(c) Copyright 1989, Tanju Cataltepe, University of California, Los Angeles\n");
    fprintf(stderr,"(c) Copyright 1992, Roger Hayward, Oregon State University\n");
    }

  if ((rfile.filePtr[rfile.depth] = fopen(rfile.filename,"r")) == NULL)
    errorReport(ERROR_INPUT_NOT_FOUND,rfile.filename,ERR_VOID,0);

/* some conditioning required */

  readInputFile();
  
  timing.read_file = clock();
  
  if (PRINT_HIGHLIGHTS) {
    fprintf(stderr,"Input Parser Complete.        Time : %8lu Seconds.\n",
      (clock_t) ((timing.read_file - timing.start) / CLOCKS_PER_SEC));
    }
  
  updateSymbols();		/* Update Command Line Symbols */
  SetUpCircuit();
  InitializeSystem();
  CreateSourceList(); /* RdH */
  MakeNonlinList();
  MakeDigitalList();
  MakeLogicalList();
  SetUpVariables();
  SetUpSources();
  SetUpNodes();
  SetUpNonlins();
  SetUpDigital();
  SetUpPrint();
  SetUpFFT();
  SetUpStubSample();

  timing.setup = clock();

  if (PRINT_HIGHLIGHTS) {
    fprintf(stderr,"Circuit Setup Complete.       Time : %8lu Seconds.\n",
      (clock_t) ((timing.setup - timing.read_file) / CLOCKS_PER_SEC));
    }

  if ((PRINT_HIGHLIGHTS)
    && (up_to_date == FALSE)
    && (flag_compiler == COMPILER_QUICK_MODE)) {
    fprintf(stderr,"*GCKC Warning:  Unable to Quick Compile -- System Not Up-to-date.\n");
    }

  if ((up_to_date == FALSE)
    || (flag_compiler == COMPILER_FORCE_COMPILATION)
    || (flag_compiler == COMPILER_COMPILE_AND_QUIT))
    BuildSystem();
  else
    BuildQuickSystem();
  
  timing.solve = clock();

  if (PRINT_HIGHLIGHTS) {
    fprintf(stderr,"Circuit Solution Complete.    Time : %8lu Seconds.\n",
      (clock_t) ((timing.solve - timing.setup) / CLOCKS_PER_SEC));
    }

  if (flag_compiler == COMPILER_COMPILE_AND_QUIT) {
    if (PRINT_NORMAL) {
      fprintf(stderr,"*Simulation Suspended.\n");
      fprintf(stderr,"GCKC Program Complete.        Time : %8lu Seconds.\n",
      (clock_t) ((timing.solve - timing.start) / CLOCKS_PER_SEC));
      }
    exit_now();
    }

  fastTick = 0;
  RunSources();
  while ((((The_Time) < lastTime) && !terminate_on_eof)
    || (terminate_on_eof && !terminate)){ /* RdH */
    presentTick = fastTick % NoOfTicks + 1;
    GetFromSystem(&presentSys, presentTick);
    RunSystem(&presentSys);
    RunNonlins();
    RunNodes();
    RunDigital();
    RunLogical();
    The_Time += deltaT;
    if (GetValue(sampleTicks->value, presentTick) != 0) {
      RunPrint();
      RunFFT();			/* doesn't really FFT anything */
      }
    RunSources();
    fastTick++;
  }

  timing.simulate = clock();

  if (PRINT_HIGHLIGHTS) {
    fprintf(stderr,"Circuit Simulation Complete.  Time : %8lu Seconds.\n",
      (clock_t) ((timing.simulate - timing.solve) / CLOCKS_PER_SEC));
    }

  /* post process */
  /* perform_fft's_here() */
  process_fft();
  print_fft();

  timing.post_process = clock();

  if (PRINT_HIGHLIGHTS) {
    fprintf(stderr,"Post Processing Complete.     Time : %8lu Seconds.\n",
      (clock_t) ((timing.post_process - timing.simulate) / CLOCKS_PER_SEC));
    }

  if (PRINT_NORMAL) {
    fprintf(stderr,"GCKC Program Complete.        Time : %8lu Seconds.\n",
      (clock_t) ((timing.post_process - timing.start) / CLOCKS_PER_SEC));
    }

  exit_now();
}


/* End. */





These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.