From b18347ffc9db9641e215995edea1c04c363b2bdf Mon Sep 17 00:00:00 2001 From: Angelo Rossi Date: Wed, 21 Jun 2023 12:04:16 +0000 Subject: Initial commit. --- sources/main.cpp | 387 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 sources/main.cpp (limited to 'sources/main.cpp') diff --git a/sources/main.cpp b/sources/main.cpp new file mode 100644 index 0000000..2d52703 --- /dev/null +++ b/sources/main.cpp @@ -0,0 +1,387 @@ +//-*- mode: c++; indent-tabs-mode: t; coding: utf-8; show-trailing-whitespace: t -*- + +// file main.cpp + +#include "main.hpp" + +//********************************************************************** +// * +// --------------- Electromagnetic Transients Program ------------ * +// methods development branch, route eogb * +// division of system engineering * +// Bonneville Power Administration * +// P. O. Box 3621 * +// Portland, Oregon 97208 * +// U.S.A. phone: (503) 230-4404 * +// * +// The fortran comment-card text now being read represents a * +// summary introduction and explanation which applies to a very * +// large program development referred to by the title of * +// 'electromagnetic transients program' (abbreviated 'EMTP' , * +// or 't.p.' in the older notation). * +// * +// In general terms, the purpose of this work is to simulate * +// transient phenomena in power system networks, taking into * +// account traveling waves (electromagnetic transients) on * +// transmission lines, saturation of transformers, nonlinearities * +// of surge arresters, etc. While not so restricted in theory, * +// the most common program application is for the simulation of * +// switching surges which propagate on power network transmission * +// lines. for a more detailed explantion of the modeling * +// techniques which are used, the reader is referred to the * +// manual for this program (840 pages for the version dated * +// march, 1983). ). while older issues were titled * +// "EMTP user's manual", beginning in september of 1980 * +// this work is now called the "EMTP rule book" . * +// * +// The utpf is a large 80-column bcd card-image file, to be used * +// as input to e/t programs. E/t programs machine translate this * +// utpf code into legal fortran for most computer systems of * +// interest (ibm, cdc, univac, honeywell, dec pdp-10, dec vax-11, * +// prime, sel, apollo, hitachi, facom, harris, etc.). * +// * +// In conformity with long-standing bpa policy, as well as the * +// more recent (february 19, 1975) federal freedom of information * +// act, dissemination of these program materials is freely made * +// to any and all interested parties. a fee to cover reproduction,* +// handling, and mailing costs may be assessed against the * +// organization receiving the material, however. No claim or * +// warranty as to the usefulness, accuracy, fidelity, or * +// completeness of these materials is (or ever has been) in any * +// way expressed or implied. * +// * +//********************************************************************** +// +// The present module main00 is always in memory. It is the +// highest level module of a program which has two levels of +// overlaying. It calls primary level overlays only (directly), +// based on the value of variable 'nchain' . The following +// legitimate values, and the meaning of the associated overlay +// calls, exist ..... +// 1-20. For overlays 1, 2, ..., 20, which are secondary-level +// overlays, a call must be first made to the controlling +// primary-level overlay. Thus for such 'nchain' values, +// control is transfered first to module main10 . This +// is the only case where calls to overlays are not made +// directly. +// +// 29. Completion of statistics (Monte Carlo) study, where variable +// maxima of the different case solutions are read off the +// disk, and are processed statistically to produce +// cumulative distribution functions, etc. +// +// 31. Plot routine, for graphical output of transients. +// The program also terminates execution here, usually, +// after writing an end-of-information mark on the +// plot tape (whether or not the user has plotted anything). +// +// 39. Supporting routine which generates EMTP branch +// cards for the frequency-dependent representation of +// an untransposed transmission line. this is the +// "marti setup" code, named after dr. jose marti of +// vancouver and caracas (see 1981 ieee pica paper). +// +// 41. Supporting routine which calculates transformer matrices (R) +// and (L) from short-circuit and open-circuit data. +// +// 42. Supporting routine which converts an rms voltage vs. current +// saturation characteristic into an instantaneous flux vs. +// current characteristic. +// +// 43. Supporting routine which calculates weighting functions +// a1(t) and a2(2) for the zero-sequence mode of a +// distributed line which has frequency-dependent line +// constants r and l . +// +// 44. Supporting routine which calculates line constants for +// overhead transmission lines by means of carson's formula. +// this is a modified version of what was originally (until +// january 1975) the completely-separate bpa line-constants +// program. +// +// 45. Supporting routine of 'Semlyen setup' code. the output +// is a group of punched cards, as are required for the EMTP +// simulation of a transmission circuit using semlyen +// recursive convolution modeling. +// +// 47. Supporting routine of 'cable constants' code. the +// primary function is to calculate (r), (l), % (c) +// matrices for a multi-phase system of single-core coaxial +// cables. +// +// 51. Printing of introductory paragraph of error-message +// termination ('you lose, fella, ... '), plus error-message +// texts for 'kill' codes numbered 1 through 50 . +// the exiting linkage is to the last error overlay. +// +// 52. Error message texts for 'kill' codes numbered 51 +// the exiting linkage is to the last error overlay. +// +// 53. Error message texts for 'kill' codes numbered 91 +// through 150. the exiting linkage is to the last +// error overlay. +// +// 54. Error message texts for 'kill' codes numbered 151 +// through 200. the exiting linkage is to the +// last error overlay. +// +// 55. Final error overlay. Messages for kill = 201 +// onward are contained, as well as summary statistics +// --- table sizes and timing figures for the run. +// The exiting linkage is generally to module over1 (to read +// a new data case), but may be to module over31 (for final +// case termination). +//********************************************************************** + +int main(int argc, char *argv[]) +{ + char c; + char optopt; + int n1; + long int nReturnValue = EXIT_FAILURE; + static struct option long_options[] = { + { "dimensioning-file", optional_argument, nullptr, 'd' }, + { "case-file", optional_argument, nullptr, 'f' }, + { "help", optional_argument, nullptr, 'h' }, + { "output-file", optional_argument, nullptr, 'o' }, + { "verbose", optional_argument, nullptr, 'v' }, + { "version", optional_argument, nullptr, 'V' }, + { nullptr, 0, nullptr, 0 } + }; + struct winsize sWindow; + // + auto a2010 = [&](void) + { + if(blkcom::nM4Plot == 1) + ;//emtspy(); + switch(blkcom::nChain) { + case 29: +#ifdef WITH_OVER29 + over29(); +#else + emtp::dummy(); +#endif + break; + + case 31: +#ifdef WITH_OVER31 + over31(); +#else + emtp::dummy(); +#endif + break; + + case 39: +#ifdef WITH_OVER39 + over39(); +#else + emtp::dummy(); +#endif + break; + + case 41: +#ifdef WITH_OVER41 + over41(); +#else + emtp::dummy(); +#endif + break; + + case 42: +#ifdef WITH_OVER42 + over42(); +#else + emtp::dummy(); +#endif + break; + + case 44: +#ifdef WITH_OVER44 + over44(); +#else + emtp::dummy(); +#endif + break; + + case 45: +#ifdef WITH_OVER45 + over45(); +#else + emtp::dummy(); +#endif + break; + + case 47: +#ifdef WITH_OVER47 + over47(); +#else + emtp::dummy(); +#endif + break; + + case 51: +#ifdef WITH_OVER51 + over51::over51(); +#else + emtp::dummy(); +#endif + break; + + case 52: +#ifdef WITH_OVER52 + over52(); +#else + emtp::dummy(); +#endif + break; + + case 53: +#ifdef WITH_OVER53 + over53(); +#else + emtp::dummy(); +#endif + break; + + case 54: +#ifdef WITH_OVER54 + over54(); +#else + emtp::dummy(); +#endif + break; + + case 55: +#ifdef WITH_OVER55 + over55(); +#else + emtp::dummy(); +#endif + break; + + default: + (*reinterpret_cast (blkcom::pLFiles[ 5 ])) << std::endl << " Illegal NCHAIN in MAIN00." << blkcom::nChain << std::endl << std::flush; + break; + } + }; + auto a2001 = [&](void) + { + // + n1 = blkcom::nChain; + if(n1 > 30) + n1 -= 30; + if(n1 <= 0) + n1 = 1; + if(blkcom::nIprsUp == 0) + blkcom::nIprsUp = blkcom::pIprsOV[ n1 - 1 ]; + if(blkcom::nChain > 20) + a2010(); + else { + if((blkcom::nChain == 12) || (blkcom::nChain == 2)) + emtp::main10(); + else { + if(blkcom::nChain == -1) + ;//movecopy::move0(&blkcom::pIprsOv[ 0 ], nLL34); + emtp::vardim(emtp::sSizesFileName, blkcom::sLStat); + emtp::erexit(); + blkcom::nChain = 0; + if (blkcom::nChain <= 20) + emtp::main10(); + } + } + }; + // + opterr = 0; + optind = 0; + blkcom::nLLBuff = -3333; + blkcom::nChain = -1; + blkcom::nLastOV = 0; + blkcom::nKill = 0; + blkcom::pLFiles[ 0 ] = reinterpret_cast(&std::cerr); + blkcom::pLFiles[ 4 ] = reinterpret_cast(&std::cin); + blkcom::pLFiles[ 5 ] = reinterpret_cast(&std::cout); + sWindow = utilities::getTerminalSize(); + if(sWindow.ws_col >= 132) + blkcom::nKol132 = 132; + else if(sWindow.ws_col >= 80) + blkcom::nKol132 = 80; + else + blkcom::nKol132 = sWindow.ws_col; + while((c = getopt_long(argc, argv, "d:f:ho:vV", long_options, &optind)) != -1) { + switch(c) { + case 0: + // If this option set a flag, do nothing else now. + if(long_options[ optind ].flag != 0) + break; + std::cout << "Option " << long_options[ optind ].name; + if(optarg) + std::cout << " with arg " << optarg; + std::cout << std::endl; + break; + + case 'd': + { + std::stringstream sTemp(optarg); + if(sTemp.str().empty()) { + blkcom::nChain = 51; + blkcom::nKill = 100; + emtp::sSizesFileName = ""; + } else { + emtp::sSizesFileName = sTemp.str(); + } + } + break; + + case 'f': + // To do. + break; + + case 'h': + std::cout << "Usage: gemtp++ [-d|--dimensioning-file dimfile] [-f|--case-file infile] [-h|--help] [-o|--output-file outfile] [-v|--verbose] [-V|--Version] [< infile]" << std::endl; + emtp::stoptp(); + exit(EXIT_SUCCESS); + break; + + case 'o': + // To do. + break; + + case 'v': + ++blkcom::nIprsUp; + break; + + case 'V': + // To do. + break; + } + } + FOREVER { + switch(blkcom::nKill) { + case 0: + case 9999: + a2001(); + break; + + case 7733: + (*reinterpret_cast(blkcom::pLFiles[ 5 ])) << " \"main\" intercept of \"begin\" request." << std::endl << std::flush; + blkcom::nKill = 0; + blkcom::nNumDCD = 0; + blkcom::nChain = 1; + emtp::main10(); + break; + + default: + if(blkcom::nChain > 51) + a2001(); + else { + blkcom::nChain = 51; + a2001(); + } + break; + } + } + ;; + return nReturnValue; +} + +// end of file main.cpp -- cgit v1.2.3