summaryrefslogtreecommitdiffstats
path: root/sources/emtp.cpp
diff options
context:
space:
mode:
authorAngelo Rossi <angelo.rossi.homelab@gmail.com>2023-06-21 12:04:16 +0000
committerAngelo Rossi <angelo.rossi.homelab@gmail.com>2023-06-21 12:04:16 +0000
commitb18347ffc9db9641e215995edea1c04c363b2bdf (patch)
treef3908dc911399f1a21e17d950355ee56dc0919ee /sources/emtp.cpp
Initial commit.
Diffstat (limited to 'sources/emtp.cpp')
-rw-r--r--sources/emtp.cpp1130
1 files changed, 1130 insertions, 0 deletions
diff --git a/sources/emtp.cpp b/sources/emtp.cpp
new file mode 100644
index 0000000..5364890
--- /dev/null
+++ b/sources/emtp.cpp
@@ -0,0 +1,1130 @@
+//-*- mode: c++; indent-tabs-mode: t; coding: utf-8; show-trailing-whitespace: t -*-
+
+// file emtp.cpp
+
+#include "emtp.hpp"
+
+// The EMTP solution process proper consists of numerous secondary-
+// level overlays, each called from module main10 using
+// module number 'nchain' as the indicator of where control is to
+// pass next. The following is a tabulation of valid 'nchain'
+// values, along with the function of the corresponding code. With
+// the possible exception of the time-step loop, 'nchain' is the
+// utpf overlay number of the code to which control is to be
+// transfered next. The overlay number of the time-step loop
+// is given by 'nchain' corresponding to the first quarter of
+// the time-step-loop segmentation, on machines not using ecs
+// overlaying.
+//
+// 1. Input of miscellaneous data cards.
+// 2. Input branch data.
+// 3. Code associated with the cascading of pi-circuits for
+// steady-state phasor solutions only.
+// 4. Input and processing of frequency-dependence data for
+// distributed-parameter line mode.
+// 5. Input of switch and source data cards.
+// 6. Network connectivity output. Setup of transient-network
+// renumbering tables.
+// 7. Network node renumbering routine (John Walker's old
+// subroutine number).
+// 8. Convert tables to new node numbers. Find steady-state
+// phasor equivalents for distributed branches.
+// 9. Set up steady-state phasor network renumbering tables.
+// 10. Form the steady-state admittance matrix (y). Solve for
+// steady-state phasor voltages.
+// 11. Output steady-state phasor solution (if requested).
+// 12. Branch-table and switch-table processing, as preparation
+// for the integration in time-step loop.
+// 13. Setup initial conditions on lumped elements, and past
+// history for distributed lines.
+// 14. Form (Y) for the transients network. Triangularize the
+// first partition (nonswitch/source nodes).
+// 15. Final setup operations before time-step loop.
+// 16. First quarter of time-step loop (checking for changes of
+// switches and pseudo-nonlinear elements, retriangularization
+// of Ybb and calculation of thevenin impedance vectors).
+// 17. Second quarter of time-step loop (branch-table history
+// updating, addition of branch contributions to nodal
+// injected current vector i ).
+// 18. Third quarter of time-step loop (source update, repeat
+// solution of (Y)v = i for node voltage vector v ).
+// 19. Fourth quarter of time-step loop (solution of 3-phase
+// nonlinearities and compensation-based rotating
+// machinery [type-50 s.m., u.m.], superposition to
+// give the total solution including compensation).
+// 20. Punch and print terminal conditions (if requested).
+// Catalog plot-data points on the disk as a permanent file, if
+// misc. data parameter 'icat' is positive.
+
+namespace emtp {
+
+ const long int nLL34 = 34;
+ std::string sSizesFileName;
+ tWords pWords[ 24 ] = {
+ { "a", "attach", 1 },
+ { "p", "punch", 2 },
+ { "out", "output", 3 },
+ { "s", "save", 4 },
+ { "spy", "spydata", 5 },
+ { "d", "disable", 7 },
+ { "r", "return", 10 },
+ { "n", "newfile", 11 },
+ { "ne", "new epsln", 13 },
+ { "de", "delete", 15 },
+ { "m", "monitor", 16 },
+ { "lf", "listoff", 18 },
+ { "ln", "liston", 20 },
+ { "v", "vintage", 21 },
+ { "old", "oldfile", 23 },
+ { "st", "stop", 25 },
+ { "w", "watch5", 26 },
+ { "com", "comment", 27 },
+ { "wi", "width", 29 },
+ { "u", "units", 30 },
+ { "", "", 31 },
+ { "", "", 0 }
+ };
+
+ // subroutine ioerr.
+ void ioerr(const long int &nAddr)
+ {
+ ;
+ }
+
+ // subroutine caterr.
+ void caterr(const long int &nAddr, const long int &nKodErr)
+ {
+ ;
+ }
+
+ void stoptp(void)
+ {
+ // Temporary stop statements of EMTP have been converted to
+ // "CALL STOPTP", allowing installation-dependent clean up.
+ blkcom::sTexCol = blkcom::sABuff.str().substr(0, 80);
+ if((blkcom::nChain == 31) && (blkcom::nLastOV == 1) && (blkcom::nKill == 9999))
+ exit(EXIT_FAILURE);
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Temporary error stop in \"stoptp\"., nchain, lastov =";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << blkcom::nChain << blkcom::nLastOV;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Last-read card image ABUFF follows ...." << std::endl;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << blkcom::sABuff.str() << std::endl << std::flush;
+ exit(EXIT_FAILURE);
+ }
+
+ // subroutine nextcard.
+ void nextcard(void)
+ {
+ long int n7;
+ // This entry is used only for interactive EMTP. It gets
+ // next card image from memory rather than unit 5.
+ n7 = blkcom::nNumDCD + 1;
+
+ a1472:
+ if(spycom::nIprSpy < 5)
+ goto a1486;
+ (*reinterpret_cast<std::stringstream *>(spycom::pMFiles[ 5 ])) << " in \"nextcard\":";
+ (*reinterpret_cast<std::stringstream *>(spycom::pMFiles[ 5 ])) << std::setfill(' ') << std::setw(5) << std::dec << n7;
+ (*reinterpret_cast<std::stringstream *>(spycom::pMFiles[ 5 ])) << " ";
+ (*reinterpret_cast<std::stringstream *>(spycom::pMFiles[ 5 ])) << std::setfill(' ') << std::setw(80) << spyf77::sFile6[ n7 - 1 ] << std::endl;
+ utilities::window(*reinterpret_cast<std::ostream*>(blkcom::pLFiles[ 5 ]), \
+ *reinterpret_cast<std::stringstream *>(spycom::pMFiles[ 5 ]));
+
+ a1486:
+ if(n7 <= spycom::nNumCRD)
+ goto a1488;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " **** **** Data crisis. Last card has been read. numcrd =";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setfill(' ') << std::setw(6) << std::dec << spycom::nNumCRD << std::endl;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Use \"data\" command of spy to read in next block of data." << std::endl;
+ if(blkcom::nM4Plot != 1)
+ goto a9000;
+ over20::emtspy();
+ goto a1472;
+
+ a1488:
+ blkcom::sABuff.str(spyf77::sFile6[ n7 - 1 ]);
+ goto a9200;
+
+ a9000:
+ blkcom::nKill = 7654;
+
+ a9200:
+ return;
+ }
+
+ // subroutine cimage.
+ void cimage(void)
+ {
+ // VAX-11 installation-dependent EMTP module which serves
+ // to return the next input card. All systems will substitute.
+ //
+ //char pBuff10[ 80 ];
+ //
+ long int i;
+ long int j;
+ long int k;
+ long int l;
+ long int n1, n2, n3, n8 = 0, n11 = 0, n12 = 99999, n13 = 99999;
+ //
+ double d1;
+ double d11 = 0.0;
+ //
+ std::string sBuff10;
+ std::string sFileName;
+ std::string sText1;
+ std::string sText2;
+ std::string sText4("9");
+ std::string sText5("blank");
+ std::string sCharC("c");
+ std::string sChTACS("tacs");
+ //
+ std::fstream *pTempFile1 = nullptr, *pTempFile2 = nullptr, *pTempFile7 = nullptr;
+ //
+ auto a4209 = [ & ](void)
+ {
+ //
+ blkcom::nNFrFld = 1;
+ free((void *) &d11);
+
+ a4225:
+ if(d11 < 0.0)
+ pTempFile1 = pTempFile2;
+ else
+ pTempFile1 = reinterpret_cast<std::fstream *>(blkcom::pLFiles[ (int) d11 ]);
+ if(n8 == 8) {
+ utilities::closeFile(reinterpret_cast<std::fstream *>(pTempFile1));
+ if(blkcom::nNOutPR == 0)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+Close file on unit 0x" << std::setfill('0') << std::setw(8) << std::hex << pTempFile1 << " ." << std::endl;
+ if(pTempFile1 == blkcom::pLFiles[ 4 ])
+ blkcom::nNOutPR = 1;
+ } else {
+ if(blkcom::nNOutPR == 0) {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+Copy file";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "0x" << std::setfill('0') << std::setw(8) << std::hex << pTempFile1;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " to" << sText1 << " ." << std::endl;
+ }
+ utilities::copyFile(pTempFile1, \
+ pTempFile7, \
+ sFileName);
+ }
+ };
+ auto a4206 = [ & ](void)
+ {
+ pTempFile2 = reinterpret_cast<std::fstream *>(blkcom::pLFiles[ 6 ]);
+ a4209();
+ };
+ auto a4506 = [ & ](void)
+ {
+ long int i;
+ long int k;
+ long int n4;
+ //
+ std::fstream *pTempFile6 = nullptr;
+ std::fstream *pTempFile7 = nullptr;
+ //
+ n4 = 0;
+ sFileName = std::string(25, ' ');
+ for(k = blkcom::nKolBeg; k <= 80; k++) {
+ if(blkcom::sTexCol[ k - 1 ] != ' ') {
+ if((blkcom::sTexCol[ k - 1 ] == blkcom::cCSepar) || \
+ (blkcom::sTexCol[ k - 1 ] == '('))
+ goto a4536;
+ ++n4;
+ sFileName[ n4 - 1 ] = blkcom::sTexCol[ k - 1 ];
+ }
+ }
+ k = 80;
+
+ a4536:
+ blkcom::nKolBeg = k + 1;
+ blkcom::nNFrFld = 1;
+ free((void *) &d11);
+ pTempFile7 = reinterpret_cast<std::fstream *>(blkcom::pLFiles[ (int) d11 - 1 ]);
+ if(n8 == 4) {
+ free((void *) &d11);
+ pTempFile6 = reinterpret_cast<std::fstream *>(blkcom::pLFiles[ (int) d11 - 1 ]);
+ } else {
+ if(!pTempFile6)
+ pTempFile6 = reinterpret_cast<std::fstream *>(blkcom::pLFiles[ 6 ]);
+ if(n8 == 5)
+ pTempFile7 = reinterpret_cast<std::fstream *>(spycom::pMFiles[ 4 ]);
+ if(!pTempFile7) {
+ for(k = 1; k <= 15; k++)
+ if(blkcom::pLFilesSave[ k - 1 ] == nullptr)
+ goto a4568;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::endl;
+ for(i = 1; i <= 10; i++)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Error, ";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::endl;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::string(5, ' ') << " All I/O channels occupied. Kill run at s.n. 4566 of \"cimage\" ." << std::endl;
+ for(i = 1; i <= 20; i++)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setfill(' ') << std::setw(5) << std::dec << blkcom::pLFilesSave[ i - 1 ];
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::endl;
+ stoptp();
+
+ a4568:
+ pTempFile7 = reinterpret_cast<std::fstream *>(blkcom::pLFiles[ k - 1 ]);
+ } else {
+ if(blkcom::nNOutPR == 0)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+" << sText1.substr(0, 6) << " file:" << sFileName.substr(0, 25) << " unit = 0x" << std::setfill('0') << std::setw(8) << std::hex << pTempFile7 << std::endl;
+ switch(n8) {
+ case 4:
+ utilities::copyFile(pTempFile6, pTempFile7, sFileName); // label 4423
+ break;
+
+ case 9:
+ utilities::openFile(pTempFile7, sFileName, std::ios::out); // label 4907
+ break;
+
+ case 11:
+ utilities::deleteFile(sFileName); // label 5106
+ break;
+
+ case 16:
+ utilities::closeFile(pTempFile7); // label 5608
+ utilities::openFile(pTempFile7, sFileName, std::ios::out);
+ break;
+
+ default:
+ utilities::closeFile(pTempFile7);
+ utilities::openFile(pTempFile7, sFileName, std::ios::out);
+ pTempFile7 -> seekp(0, std::ios::beg);
+ if(n8 == 5)
+ over20::spying();
+ break;
+ }
+ }
+ }
+ };
+ auto cattach = [ & ](void)
+ {
+ sText1 = "attach";
+ a4506();
+ };
+ auto cpunch = [ & ](void)
+ {
+ long int n1;
+ //
+ sText1 = "punch";
+ a4206();
+ };
+ auto coutput = [ & ](void)
+ {
+ sText1 = "output";
+ a4206();
+ };
+ auto csave = [ & ](void)
+ {
+ sText1 = "saved";
+ a4506();
+ };
+ auto cspydata = [ & ](void)
+ {
+ sText1 = "spying";
+ blkcom::pMFilesSave[ 1 ] = nullptr; // remember $spy for eof time in "spying (2288)"
+ blkcom::pMFilesSave[ 0 ] = spycom::pMFiles[ 4 ]; // remember spy input channel till now
+ spycom::pMFiles[ 4 ] = blkcom::pLFiles[ 16 ]; // special I/O unit used for $spy connection
+ spycom::nKFile5 = 1; // flag so "spying" knows munit5 opened to disk
+ a4506();
+ };
+ auto cdisable = [ & ](void)
+ {
+ if(blkcom::nNOutPR == 0)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+Begin data to be ignored." << std::endl;
+ };
+ auto cenable = [ & ](void)
+ {
+ if(blkcom::nNOutPR == 0)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+End of data to be ignored." << std::endl;
+ };
+ auto creturn = [ & ](void)
+ {
+ pTempFile2 = reinterpret_cast<std::fstream *>(blkcom::pLFiles[ 3 ]);
+ a4209();
+ };
+ auto cnewfile = [ & ](void)
+ {
+ sText1 = "newfil";
+ pTempFile2 = reinterpret_cast<std::fstream *>(blkcom::pLFiles[ 3 ]);
+ a4506();
+ };
+ auto cnew_epsilon = [ & ](void)
+ {
+ double d1;
+ //
+ blkcom::nNFrFld = 1;
+ d1 = blkcom::nEpsilon;
+ freedom::freeOne(blkcom::nEpsilon);
+ if(blkcom::nNOutPR == 0)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+ Epsiln change. old, new =" << std::setfill(' ') << std::setw(13) << d1 << blkcom::nEpsilon << std::endl;
+ };
+ auto cdelete = [ & ](void)
+ {
+ sText1 = "delete";
+ a4506();
+ utilities::deleteFile(sFileName);
+ };
+ auto cmonitor = [ & ](void)
+ {
+ if(blkcom::nNOutPR != 0) {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << sBuff10 << std::endl;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+CRT Monitor. Card number = " << std::setfill(' ') << std::setw(5) << std::dec << blkcom::nNumDCD << std::endl;
+ }
+ };
+ auto clistoff = [ & ](void)
+ {
+ if(blkcom::nNOutPR == 0) {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+Turn off input listing at card" << std::setfill(' ') << std::setw(5) << std::dec << blkcom::nNumDCD << std::endl;
+ blkcom::nNOutPR = 1;
+ }
+ };
+ auto cliston = [ & ](void)
+ {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::string(51, ' ') << "|$liston"<< std::endl;
+ blkcom::nNOutPR = 0;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+Turn on input listing at card" << std::setfill(' ') << std::setw(5) << std::dec << blkcom::nNumDCD << std::endl;
+ };
+ auto cvintage = [ & ](void)
+ {
+ ;
+ };
+ auto coldfile = [ & ](void)
+ {
+ ;
+ };
+ auto cstop = [ & ](void)
+ {
+ ;
+ };
+ auto cwatch5 = [ & ](void)
+ {
+ ;
+ };
+ auto ccomment = [ & ](void)
+ {
+ ;
+ };
+ auto cwidth = [ & ](void)
+ {
+ ;
+ };
+ auto cunits = [ & ](void)
+ {
+ ;
+ };
+ tRequest pRequests[] = {
+ { "a", "attach", 1, cattach },
+ { "p", "punch", 2, cpunch },
+ { "out", "output", 3, coutput },
+ { "s", "save", 4, csave },
+ { "spy", "spydata", 5, cspydata },
+ { "d", "disable", 7, cdisable },
+ { "e", "enable", 9, cenable },
+ { "r", "return", 10, creturn },
+ { "n", "newfile", 11, cnewfile },
+ { "ne", "new epsiln", 13, cnew_epsilon },
+ { "de", "delete", 15, cdelete },
+ { "m", "monitor", 16, cmonitor },
+ { "lf", "listoff", 18, clistoff },
+ { "ln", "liston", 20, cliston },
+ { "v", "vintage", 21, cvintage },
+ { "old", "oldfile", 23, coldfile },
+ { "st", "stop", 25, cstop },
+ { "w", "watch5", 26, cwatch5 },
+ { "com", "comment", 27, ccomment },
+ { "wi", "width", 29, cwidth },
+ { "u", "units", 30, cunits }
+ };
+ std::list<tRequest> sRequests(pRequests, pRequests + sizeof(pRequests) / sizeof(tRequest));
+ auto cecho = [ & ](void)
+ {
+ if(blkcom::nChain <= 15)
+ ++blkcom::pIpnTV[ 10 ] + 1;
+ reinterpret_cast<std::fstream *>(blkcom::pInEcho) -> write(blkcom::sABuff.str().c_str(), 80);
+ };
+ auto ibrinc = [ & ](void)
+ {
+ ++blkcom::nIBr;
+ labcom::sXOptBR[ blkcom::nIBr - 1 ] = blkcom::nXOpt;
+ labcom::sCOptBR[ blkcom::nIBr - 1 ] = blkcom::nCOpt;
+ };
+ //
+ // The main body of cimage subroutine.
+ //
+ if(blkcom::nIprsUp >= 10) {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Begin cimage. lunit5, lunit6, noutpr, numdcd =";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "0x" << std::setfill('0') << std::setw(8) << std::hex << blkcom::pLFiles[ 4 ];
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "0x" << std::setfill('0') << std::setw(8) << std::hex << blkcom::pLFiles[ 5 ];
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setfill(' ') << std::setw(5) << std::dec << blkcom::nNOutPR;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setfill(' ') << std::setw(5) << std::dec << blkcom::nNumDCD << std::endl << std::flush;
+ }
+
+ a1000:
+ if(blkcom::nM4Plot == 1)
+ over20::emtspy();
+ if(blkcom::pLFiles[ 4 ] != nullptr) {
+ if(reinterpret_cast<std::ifstream *>(blkcom::pLFiles[ 4 ]) -> is_open()) {
+ std::getline(*reinterpret_cast<std::istream *>(blkcom::pLFiles[ 4 ]), sBuff10, '\n');
+ if(reinterpret_cast<std::ifstream *>(blkcom::pLFiles[ 4 ]) -> eof())
+ goto a4000;
+ }
+ }
+ if(blkcom::pLFiles[ 4 ]) {
+ if(!reinterpret_cast<std::ifstream *>(blkcom::pLFiles[ 4 ]) -> is_open())
+ nextcard();
+ } else
+ nextcard();
+ if(blkcom::nKill > 0)
+ goto a4000;
+ if(!blkcom::pLFilesSave[ 4 ])
+ ++blkcom::nNumDCD;
+ sBuff10 = blkcom::sABuff.str();
+ sText1 = sBuff10[ 0 ];
+ sText2 = sBuff10[ 1 ];
+ if(sText1 != CHARC)
+ goto a3034;
+ if(sText2 != BLANK)
+ goto a3034;
+
+ a1036:
+ if(blkcom::nNOutPR != 0)
+ goto a1000;
+ if(n11 != 0)
+ goto a1000;
+ if(blkcom::nKol132 == 132)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Comment card. " << std::string(37, ' ') << "|" << sBuff10.substr(0, 80) << std::endl;
+ else
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Comment card. " << std::string(37, ' ') << "|" << sBuff10.substr(0, 29) << std::endl;
+ goto a1000;
+
+ a3034:
+ if(blkcom::nNOutPR != 0)
+ goto a3035;
+ if(blkcom::nKol132 == 132)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::string(52, ' ') << "|" << sBuff10.substr(0, 80) << std::endl;
+ else
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::string(52, ' ') << "|" << sBuff10.substr(0, 29) << std::endl;
+
+ a3035:
+ if(n13 > 0)
+ goto a3011;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " " << std::setfill(' ') << std::setw(5) << std::dec << blkcom::nNumDCD << " :" << blkcom::sABuff.str().substr(0, 72) << std::endl;
+ n13 = n12;
+
+ a3011:
+ --n13;
+ blkcom::sABuff >> sText2;
+ if(strcom::toLower(sText2) != sText5)
+ goto a3040;
+ if(n8 == 6)
+ goto a3044;
+
+ a3039:
+ blkcom::sABuff.str("");
+ goto a3233;
+
+ a3040:
+ if(blkcom::sChCont == strcom::toLower(sText4))
+ goto a3233;
+ blkcom::sTexCol = blkcom::sABuff.str().substr(0, 80);
+ if((strcom::toLower(blkcom::sABuff.str()) != "$listoff") && \
+ (strcom::toLower(blkcom::sABuff.str()) != "$liston"))
+ goto a3042;
+ goto a3246;
+
+ a3042:
+ if(blkcom::sChCont == sChTACS)
+ goto a3233;
+ if(blkcom::sTexCol == blkcom::sChCont)
+ goto a3246;
+ if(n8 != 6)
+ goto a1144;
+
+ a3044:
+ if(blkcom::nNOutPR == 0)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "+Comment card (impicit)." << std::endl;
+ goto a1000;
+
+ a1144:
+ for(k = 1; k <= 80; k++) {
+ if(blkcom::sTexCol[ k - 1 ] == blkcom::cCSepar)
+ goto a3237;
+ if(blkcom::sTexCol.substr(k - 1, blkcom::sChCont.size()) == blkcom::sChCont)
+ goto a3237;
+ }
+
+ a3233:
+ blkcom::nKolBeg = -std::numeric_limits<long int>::infinity();
+ goto a7014;
+
+ a3237:
+ blkcom::nKolBeg = 1;
+ goto a7014;
+
+ a3246:
+ blkcom::nKolBeg = 2;
+
+ a3251:
+ blkcom::nNRight = -2;
+ freedom::freeOne(d1);
+ if(blkcom::nIprsUp >= 1)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::endl << " nfrfld = " << std::setfill(' ') << std::setw(8) << blkcom::nNFrFld << std::string(5, ' ') << "texta6 = " << blkcom::pTextA6[ 0 ].substr(0, 7) << blkcom::pTextA6[ 1 ].substr(0, 7) << std::endl;
+ blkcom::nNRight = 0;
+ for(i = 1; i <= 200; i++) {
+ n1 = pRequests[ i - 1 ].m_nPointer;
+ n2 = pRequests[ i ].m_nPointer - 1;
+ if(n2 < 0)
+ goto a3319;
+ if(blkcom::nIprsUp >= 35) {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Special-request word" << std::setfill(' ') << std::setw(4) << i << " .";
+ for(j = n1; j <= n2; j++)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << pRequests[ j - 1 ].m_sLongName;
+ }
+ if(strcom::toLower(pRequests[ n1 - 1 ].m_sLongName) == BLANK)
+ goto a3306;
+ l = 0;
+ n2 = n2 - n1 + 1;
+ if(n3 != blkcom::nNFrFld)
+ goto a3306;
+ for(j = n1; j <= n2; j++) {
+ ++l;
+ if(strcom::toLower(blkcom::pTextA6[ l - 1 ]) != pRequests[ j - 1 ].m_sLongName)
+ goto a3306;
+ }
+ if(blkcom::nIprsUp >= 2) {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::endl << " key-word found. i, n8 =" << std::setfill(' ') << std::setw(5) << i << n8;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::string(5, ' ') << "texta6, textay = " << blkcom::pTextA6[ 0 ] << pRequests[ i - 1 ].m_sLongName << std::endl;
+ }
+
+ a3294:
+ if(n8 != 6)
+ goto a3301;
+ if(i != 7)
+ goto a1036;
+
+ a3301:
+ n8 = i;
+ switch(n8) {
+ case 1: // ***** Request no. 1. "$attach" *****
+ cattach();
+ break;
+
+ case 2: // ***** Request no. 2. "$punch" *****
+ cpunch();
+ break;
+
+ case 3: // ***** Request no. 3. "$output" *****
+ coutput();
+ break;
+
+ case 4: // ***** Request no. 4. "$save" *****
+ csave();
+ break;
+
+ case 5: // ***** Request no. 5. "$spy" *****
+ cspydata();
+ break;
+
+ case 6: // ***** Request no. 6. "$disable" *****
+ cdisable();
+ break;
+
+ case 7: // ***** Request no. 7. "$enable" *****
+ cenable();
+ break;
+
+ case 8: // ***** Request no. 8. "$return" *****
+ creturn();
+ break;
+
+ case 9: // ***** Request no. 9. "$newfile" *****
+ cnewfile();
+ break;
+
+ case 10: // ***** Request no. 10. "new epsiln" *****
+ cnew_epsilon();
+ break;
+
+ case 11: // ***** Request no. 11. "delete" *****
+ cdelete();
+ break;
+
+ case 12: // ***** Request no. 12. "monitor" *****
+ cmonitor();
+ break;
+
+ case 13: // ***** Request no. 13. "listoff" *****
+ clistoff();
+ break;
+
+ case 14: // ***** Request no. 14. "liston" *****
+ cliston();
+ break;
+
+ case 15: // ***** Request no. 15. "vintage" *****
+ cvintage();
+ break;
+
+ case 16: // ***** Request no. 16. "oldfile" *****
+ coldfile();
+ break;
+
+ case 17: // ***** Request no. 17. "stop" *****
+ cstop();
+ break;
+
+ case 18: // ***** Request no. 18. "watch5" *****
+ cwatch5();
+ break;
+
+ case 19: // ***** Request no. 19. "comment" *****
+ ccomment();
+ break;
+
+ case 21: // ***** Request no. 21. "units" *****
+ cunits();
+ break;
+ }
+ if((n8 >= 1) && (n8 <= 21))
+ goto a1000;
+
+ a3306:
+ if(strcom::toLower(blkcom::pTextA6[ 0 ]) == pRequests[ i - 1 ].m_sLongName)
+ goto a3294;
+ }
+
+ a3319:
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Illegal $-card. Stop at s.n. 3319 of \"cimage\" ." << std::endl;
+ stoptp();
+ cattach();
+ goto a1000;
+
+ a4000:
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::endl << " " << std::string(85, '=') << std::endl;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " End of file encounted in \"cimage\" while, attempting to read another data card. Stop." << std::endl << " " << std::string(85, '=') << std::endl;
+ stoptp();
+
+ a7014:
+ if(blkcom::pInEcho == nullptr)
+ return;
+ cecho();
+ }
+
+ void erexit(void)
+ {
+ // VAX-11 installation-dependent EMTP module. This is
+ // called by the top of "MAIN00", before any EMTP data input.
+ //int idum[ 3 ];
+ //nKWTVAX = 0;
+ datain::datain();
+ }
+
+ void dummy(void)
+ {
+ std::stringstream sTemp;
+ //
+ //(*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Dummy overlay function called. nchain = " << blkcom::nChain << ". Exiting." << std::endl << std::flush;
+ sTemp << " Dummy overlay function called. nchain = " << blkcom::nChain << ". Exiting." << std::endl << std::flush;
+ throw(std::runtime_error(sTemp.str().c_str()));
+ blkcom::nKill = 60;
+ }
+
+ // subroutine tapsav.
+ void tapsav(char *narray, std::fstream &n1, const long int &n2, const long int &n3)
+ {
+ // Near-universal module for dumping or restoring (central memory
+ // vs. disk) of /label/ . This does not work for those
+ // computers like Prime and Burroughs where common blocks
+ // are not ordered regularly in memory. Switch "KBURRO"
+ // selects between disk or virtual memory (/C29B01/).
+ int i;
+ int j;
+ int k;
+ int nKVecSv, n13;
+ //
+ long int n4, n9;
+ //
+ std::vector<long int> sKPen(5);
+ //
+ auto a5448 = [&](void)
+ {
+ if(n3 <= 1)
+ n1.write(&narray[ 0 ], n2);
+ else
+ n1.read(&narray[ 0 ], n2);
+ };
+ auto a6327 = [&](void)
+ {
+ if((blkcom::nChain == 20) && (blkcom::nMemSav == 1))
+ a5448 ();
+ else {
+ if(blkcom::nChain == 1)
+ a5448 ();
+ else {
+ if(!((blkcom::nChain == 6) || (blkcom::nChain == 8))) {
+ n13 = 29;
+ emtp::dimens(sKPen, n13, blkcom::sTrash, blkcom::sTrash);
+ nKVecSv = 2 * (blkcom::nIt + blkcom::nIt + blkcom::nIBr + blkcom::nTot + blkcom::nIoffd) + blkcom::nKSwtch + blkcom::nLHist;
+ n9 = blkcom::sSStat.m_nTLabl + nKVecSv * blkcom::pNByte[ 2 ] / blkcom::pNByte[ 3 ];
+ if(n9 >= sKPen[ 1 ] + 50) {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Error stop in \"tapsav\". Overflow of /c29b01/ storage. n2, kpen(2) =";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setw (8) << n2 << sKPen[ 1 ];
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " needed storage n9 =";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setw (8) << n9;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "\n memory requirement in integer words for virtual computer implementation of tapsav. Storage must\n";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "provide for all of --/label/--( deck \"labcom\" ), the several usages \"vecrsv\" and \"vecisv\" (over6-11), plus 50 extra cells.\n";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "nchain =" << std::setw (5) << blkcom::nChain << std::endl << std::flush;
+ emtp::stoptp();
+ } else {
+ j = 50;
+ if(n3 <= 1) {
+ for(k = 1; k <= n2; k++) {
+ ++j;
+ labcom::pKArray[ j - 1 ] = narray[ k - 1 ];
+ }
+ } else {
+ for(k = 1; k <= n2; k++) {
+ ++j;
+ narray[ k - 1 ] = labcom::pKArray[ j - 1 ];
+ }
+ }
+ }
+ }
+ }
+ }
+ };
+ //
+ if(narray) {
+ if(blkcom::nIprsUp >= 1) {
+ n9 = 0;
+ sKPen[ 1 ] = 0;
+ n4 = (size_t) narray;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "\n Top of \"tapsav\". n1 n2 n3 kburro n4" << std::endl << std::flush;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "0x" << std::setw(8) << std::setfill('0') << std::hex << &n1 << " " << n2;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " " << n3 << " " << blkcom::nKBurro << std::setw(8) << " " << n4 << std::endl << std::flush;
+ } else {
+ if(blkcom::nKBurro != 1)
+ a5448();
+ else
+ a6327();
+ }
+ if (blkcom::nIprsUp >= 1)
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Exit \"tapsav\". n9, kpen(2) = " << n9 << " " << sKPen[ 1 ] << std:: endl << std::flush;
+ }
+ }
+
+ /* subroutine main10. */
+
+ void main10(void)
+ {
+ subr10();
+ }
+
+ /* subroutine subr10. */
+
+ void subr10(void)
+ {
+ int nIprCBL;
+ int n24;
+ //
+ try {
+ blkcom::nKTab = 0;
+ FOREVER {
+ if(blkcom::nChain <= 20) {
+ if(blkcom::nKill != 0)
+ blkcom::nChain = 51;
+ else {
+ n24 = blkcom::nChain;
+ if(n24 < 1)
+ n24 = 1;
+ blkcom::nIprsUp = blkcom::pIprsOV[ n24 - 1 ];
+ nIprCBL = blkcom::nIprsUp;
+ if(blkcom::nM4Plot == 1)
+ over20::emtspy ();
+ if(blkcom::nChain == 0)
+ blkcom::nChain = 1;
+ switch (blkcom::nChain) {
+ case 1:
+#ifdef WITH_OVER1
+ over1::over1();
+#else
+ dummy();
+#endif
+ break;
+
+ case 2:
+#ifdef WITH_OVER2
+ over2();
+#else
+ dummy();
+#endif
+ break;
+
+ case 3:
+ case 4:
+ emtp::stoptp();
+ break;
+
+#ifdef WITH_OVER5
+ over5();
+#else
+ dummy();
+#endif
+ break;
+
+#ifdef WITH_OVER6
+ over6();
+#else
+ dummy();
+#endif
+ break;
+
+#ifdef WITH_OVER7
+ over7();
+#else
+ dummy();
+#endif
+ break;
+
+#ifdef WITH_OVER8
+ over8();
+#else
+ dummy();
+#endif
+ break;
+
+#ifdef WITH_OVER9
+ over9();
+#else
+ dummy();
+#endif
+ break;
+
+#ifdef WITH_OVER10
+ over10();
+#else
+ dummy();
+#endif
+ break;
+
+#ifdef WITH_OVER11
+ over11();
+#else
+ dummy();
+#endif
+ break;
+
+ case 12:
+#ifdef WITH_OVER12
+ over12();
+#else
+ dummy();
+#endif
+ break;
+
+ case 13:
+#ifdef WITH_OVER13
+ over13();
+#else
+ dummy();
+#endif
+ break;
+
+ case 14:
+#ifdef WITH_OVER14
+ over14();
+#else
+ dummy ();
+#endif
+ break;
+
+ case 15:
+#ifdef WITH_OVER15
+ over15();
+#else
+ dummy();
+#endif
+ break;
+
+ case 16:
+ case 17:
+ case 18:
+ case 19:
+#ifdef WITH_OVER16
+ over16();
+#else
+ dummy();
+#endif
+ break;
+
+ case 20:
+#ifdef WITH_OVER20
+ over20::over20();
+#else
+ dummy();
+#endif
+ break;
+ }
+ }
+ } else
+ break;
+ }
+ }
+ catch(std::exception &e) {
+ std::cerr << e.what() << std::endl;
+ exit(EXIT_FAILURE);
+ }
+ }
+ void setmar(int *n)
+ {
+ if (*n)
+ *n = 0;
+ }
+
+ void chrsiz(int *n)
+ {
+ if (*n)
+ *n = 0;
+ }
+
+ void setplt(void)
+ {
+ ;
+ }
+
+ void setstd (void)
+ {
+ ;
+ }
+
+ void interp(void)
+ {
+ ;
+ }
+
+ void namea6(const std::string &sText1, long int *n24)
+ {
+ // module for maintainance of alphanumeric vector texvec of
+ // "labcom". maxbus of "blkcom" is last used cell. n24 chooses
+ // mode of use: 0 will add text1, positive will locate it,
+ // and negative will destroy (remove) it.
+ int j;
+ int n17 = 0;
+ //
+ std::string sText2("unused");
+ //
+ if(blkcom::nMaxBus <= 0)
+ goto a3423;
+ for(j = 1; j <= blkcom::nMaxBus; j++)
+ if(strcom::toLower(sText1) == strcom::toLower(labcom::sTexVec[ j - 1 ]))
+ goto a3446;
+
+ a3423:
+ if(*n24 != 0)
+ goto a3438;
+ if (n17 == 0)
+ goto a3434;
+ labcom::sTexVec[ n17 - 1 ] = strcom::toLower (sText1);
+ *n24 = n17;
+ for(j = 1; j <= blkcom::nMaxBus; j++)
+ if(strcom::toLower(labcom::sTexVec[ j - 1 ]) != strcom::toLower(sText2)) {
+ ;
+ } else {
+ n17 = j;
+ goto a9000;
+ }
+ n17 = 0;
+ goto a9000;
+
+ a3434:
+ ++blkcom::nMaxBus;
+ if (blkcom::nMaxBus > blkcom::sSStat.m_nSize7)
+ exit(EXIT_FAILURE);
+ labcom::sTexVec[ blkcom::nMaxBus - 1 ] = strcom::toLower(sText1);
+ *n24 = blkcom::nMaxBus;
+ goto a9000;
+
+ a3438:
+ if(blkcom::nIprsUp >= 1) {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " +++++ Search of EMTP name vector bus through cell";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setw (5) << blkcom::nMaxBus;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " in \"namea6\" shows no match for\n";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " . \"";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setw (6) << sText1;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << "\". Return -intinf.";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setw (10) << *n24 << std::endl << std::flush;
+ }
+ *n24 = std::numeric_limits<int>::min();
+ goto a9000;
+
+ a3446:
+ if (*n24 < 0)
+ goto a3455;
+ *n24 = j;
+ goto a9000;
+
+ a3455:
+ labcom::sTexVec[ j - 1 ] = strcom::toLower (sText2);
+ n17 = j;
+
+ a9000:
+ if(blkcom::nIprsUp >= 6) {
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " Exit \"namea6\". text1, maxbus, n24, j =";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << " ";
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setw (6) << sText1;
+ (*reinterpret_cast<std::ostream *>(blkcom::pLFiles[ 5 ])) << std::setw (10) << blkcom::nMaxBus << *n24 << j << std::endl << std::flush;
+ }
+ }
+
+ void tables(void)
+ {
+ // Utility which is used to both dump and restore EMTP
+ // tables (central memory vs. disk). Usage is for both
+ // "statistics" (over12, over15, over20) and "start again"
+ // (over1, over20). Call to "tapsav" dumps /label/ .
+ // Also used by $restart request of "cimage" (called
+ // from "lookie" which is called by "subts3" of ov16).
+ // Also used by "restore" request of rtm, where table
+ // restoration is in "katalg" of overlay 20.
+ // Note about deck "synmac". If EMTP s.m. modeling
+ // Brandwajn (type-59), is to be deleted,
+ // then all s.m. subroutines ( smdat, smout, smpfit,
+ // smint, uncor, premec, elec, past,
+ // update, increm ) are to be destroyed, and
+ // deck "synmac" is to be removed from the present module.
+ // but then "dimension z(1)" should be added in its
+ // place, and the "n4 =" calculation involving "locint"
+ // should be replaced by the simple statements "n4 = 1" .
+ // comment card immediately preceding "synmac" -------------
+ // comment card immediately following "synmac" -------------
+ long int i, iprsav[] = { 0, 0, 0, 0 };
+ long int j;
+ long int ll0, ll1, ll2, ll4;
+ long int n1, n2, n3, n4, n5, n9, n24;
+ //
+ char *pBusOne = &blkcom::sBus1[ 0 ];
+ long int *pIDistX = &blkcom::nEnerg;
+ long int *pKBase = &blkcom::sMonCar.m_nKBase;
+ std::vector<long int> sIntegX;
+ std::vector<long int> sITemp;
+ std::vector<long int> sJTemp;
+ std::vector<long int> sKTemp;
+ std::vector<long int> sKPen;
+ //
+ ll1 = 1;
+ ll2 = 2;
+ ll4 = 4;
+ blkcom::nNWord1 = (size_t) blkcom::pVoltBC - (size_t) &sKPen;
+ blkcom::nNWord2 = (size_t) blkcom::pIDistX - (size_t) &blkcom::pLFilesSave[ 14 ];
+ // ... to complete.
+ }
+
+ // subroutine csup.
+
+ void csup(const long int &l)
+ {
+ ;
+ }
+
+}
+
+// end of file emtp.hpp