netlist3.cpp
Download: netlist3_C.zip
This program tests the circuit class. It allows us to parse simple netlist files.
// netlist3.cpp : Defines the entry point for the console application. // //#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <conio.h> #include "circuit.h" //int _tmain(int argc, _TCHAR* argv[]) int main(int argc, char *argv[]) { char *filename; char buf[128]; FILE *in; if (argc<2) { printf("Enter filename: "); gets_s(buf,127); filename = buf; } else filename = argv[1]; errno_t nerr = fopen_s(&in,filename,"r"); if (nerr) { printf("file: %s not found\n",filename); _getch(); return EXIT_FAILURE; } circuit ckt; ckt.read(in); fclose(in); ckt.build_node_list(); ckt.list_devices(); printf("\nNode list:\n"); ckt.list_nodes(); /* add pause in debugger printf("Press any key to exit ...\n"); _getch(); */ return 0; } /* #include <windows.h> #include <gdiplus.h> using namespace Gdiplus; VOID OnPaint(HDC hdc) { Graphics graphics(hdc); Pen pen(Color(255, 0, 0, 255)); graphics.DrawLine(&pen, 0, 0, 200, 100); } */
C:\classes\ece538\work\netlist3>netlist3 r1.net 1: % Resistance in series 2: % alphanumeric node names 3: R R1 N_3 0 2 [0 0] 4: R R2 N_4 N_3 4 [1 0 1] 5: I I1 N_4 0 -1 [-1 0] R R1 nodes 1 0 value 2 loc[0 0] R R2 nodes 2 1 value 4 loc[1 0] rotate 1 I I1 nodes 2 0 value -1 loc[-1 0] Node list: 0 0 1 N_3 2 N_4
The following has an unimplemented circuit device:
C:\classes\ece538\work\netlist3>netlist3 test.net 1: % This is a test of circuit file parser 2: R R1 N_2 N_1 3k 3: R R2 N_2 N_3 4MEG 4: V V1 N_1 N_3 5 unrecognized device: V 5: R R3 N_3 0 2 R R1 nodes 1 2 value 3000 loc[0 0] R R2 nodes 1 3 value 4e+006 loc[0 0] R R3 nodes 3 0 value 2 loc[0 0] Node list: 0 0 1 N_2 2 N_1 3 N_3
Maintained by John Loomis, updated Sun Feb 04 16:05:24 2007