Blame view

GUI/SW2/SRC/src/netlist/NetList.cpp 30.1 KB
886c558b   Steve Greedy   SACAMOS Public Re...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
//**************************************************************************************************
//                                           NetList.cpp                                           *
//                                          -------------                                          *
// Started     : 2003-09-01                                                                        *
// Last Update : 2016-10-25                                                                        *
// Copyright   : (C) 2003-2016 MSWaters                                                            *
//**************************************************************************************************

//**************************************************************************************************
//                                                                                                 *
//      This program is free software; you can redistribute it and/or modify it under the          *
//      terms of the GNU General Public License as published by the Free Software Foundation;      *
//      either version 3 of the License, or (at your option) any later version.                    *
//                                                                                                 *
//**************************************************************************************************

#include "NetList.hpp"

//**************************************************************************************************
// Allocate storage for static data members.

wxFileName      NetList::m_ofnLoadFile;
wxFileName      NetList::m_ofnSaveFile;
ArrayFileName   NetList::m_oaSchemFiles;

wxArrayString   NetList::m_osaNetLst;
wxArrayString   NetList::m_osaTitle;
wxArrayString   NetList::m_osaIncludes;
ArrayComponent  NetList::m_oaCpnts;
wxArrayString   NetList::m_osaModels;
wxArrayString   NetList::m_osaSubCcts;

wxArrayString   NetList::m_osaNodeLbls;

bool            NetList::m_bIsValid=false;

//**************************************************************************************************
// Constructor.

NetList::NetList( void )
{
}

//**************************************************************************************************
// Destructor.

NetList::~NetList( )
{
}

//**************************************************************************************************
// Extract the title for the netlist.
//
// Noyes : - Traditionally the first line in the netlist is the title.
//         - An '*' at the start of a line seems to be used as a comment designator.
//         - If the file was created by gnetlist or gSpiceUI throw it away.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bLoadTitle( void )
{
  // Clear the title string array object attribute
  m_osaTitle.Clear( );

  // Check that the circuit isn't empty
  if( m_osaNetLst.IsEmpty( ) )          return( false );

  // If the first line is empty assume there is no title
  wxString  os1 = m_osaNetLst.Item( 0 );
  if( os1.IsEmpty( ) )                  return( true );

  // If the first line doesn't begin with an '*' then assume it is the title
  if( os1.GetChar( 0 ) != wxT('*') )
  {
    os1 = wxT("* ") + os1;
    m_osaTitle.Add( os1 );
    return( true );
  }

  // If the netlist was created using gnetlist the first line will look something like the
  // following :
  //   gnetlist -v -g spice-sdb -o filter-lp-1.ckt filter-lp-1.sch
  if( os1.Contains( wxT("gnetlist") ) ) return( true );

  // If the netlist was created by gSpiceUI the start of the file will look something like this :
  //   ********************************************************************************
  //   *           Electronic circuit simulation file generated by gSpiceUI           *
  //   *                         Version 0.9.93 (2015-04-03)                          *
  //   ********************************************************************************
  if(        m_osaNetLst.Item( 0 ).find_first_not_of( wxT('*') ) != wxString::npos ) ;
  else if( ! m_osaNetLst.Item( 1 ).Contains( APP_NAME )                            ) ;
  else if( ! m_osaNetLst.Item( 2 ).Contains( wxT("Version") )                      ) ;
  else if(   m_osaNetLst.Item( 3 ).find_first_not_of( wxT('*') ) != wxString::npos ) ;
  else                                  return( true );

  // Accept all lines beginning with an '*' as the title
  for( size_t sz1=0; sz1<m_osaNetLst.GetCount( ); sz1++ )
  {
    os1 = m_osaNetLst.Item( sz1 );
    if( os1.GetChar( 0 ) != wxT('*') ) break;
    m_osaTitle.Add( os1 );
  }

  return( true );
}

//**************************************************************************************************
// Extract any include directives.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bLoadIncludes( void )
{
  wxString  os1, os2;
  size_t    sz1;

  // Clear the includes string array object attribute
  m_osaIncludes.Clear( );

  // Need at least a title line, 2 components and an include directive
  if( m_osaNetLst.GetCount( ) < 4 ) return( true );

  // Scan circuit description for include directives
  for( sz1=0; sz1<m_osaNetLst.GetCount( ); sz1++ )
  {
    os1 = m_osaNetLst.Item( sz1 );

    if( bIsSubCkt( os1 ) ) continue;
    if( os1.IsEmpty( )   ) continue;

    os2 = os1;
    os2.MakeUpper( );

    if( os2.StartsWith( wxT(".INCLUDE ") ) ) m_osaIncludes.Add( os1 );
  }

  return( true );
}

//**************************************************************************************************
// Extract all the component description lines from the circuit description.
//
// A component line is identified if the first character in the line is an alpha character and its
// length is greater than 8. The following examples shows a component description of minimum length
// (a resistor connected to nodes 1 and 0 of value 9 Ohm) :
//
//   R1 1 0 9
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bLoadCpnts( void )
{
  wxString   os1, os2;
  size_t     sz1;
  Component  oCpnt;

  // Clear the components string array object attribute
  m_oaCpnts.Clear( );

  // Need at least a title line and 2 components
  if( m_osaNetLst.GetCount( ) < 3 ) return( false );

  // Reset the sub-circuit detection function
  os1 = wxT(".ENDS");
  bIsSubCkt( os1 );

  // Scan circuit description for components
  for( sz1=1; sz1<m_osaNetLst.GetCount( ); sz1++ )
  {
    // Retrieve the next line from the netlist
    os1 = m_osaNetLst.Item( sz1 );

    // Ignore all component definitions inside a sub-circuit block
    if( bIsSubCkt( os1 ) )    continue;

    // Determine if this line is a valid component description
    oCpnt = os1;
    if( ! oCpnt.bIsValid( ) ) continue;

    // A valid component description was found
    m_oaCpnts.Add( oCpnt );
  }

  // Circuit description must have components
  if( m_oaCpnts.IsEmpty( ) )         return( false );

  m_oaCpnts.Sort( &Component::iCompare );

  return( true );
}

//**************************************************************************************************
// Extract all the model description lines from the circuit description.
//
// A model description can consist of 1 or more lines and is identified if the line begins with
// ".MODEL ". Subsequent lines beginning with a '+' character are appended to the model description.
// The format is illustrated in the following example:
//
//   .MODEL CMOSN NMOS (LEVEL=2 LD=0.265073u TOX=418.0e-10
//   + NSUB=1.53142e+16 VTO=0.844345 KP=4.15964e-05 GAMMA=0.863074
//   + CJ=0.0003844 MJ=0.488400 CJSW=5.272e-10 MJSW=0.300200 PB=0.700000)
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bLoadModels( void )
{
  wxString  osModel;
  wxString  os1, os2;
  size_t    sz1;

  // Clear the models string array object attribute
  m_osaModels.Clear( );

  // Need at least a title line, 2 components and a model description line
  if( m_osaNetLst.GetCount( ) < 4 ) return( true );

  // Reset sub-circuit detection function
  os1 = wxT(".ENDS");
  bIsSubCkt( os1 );

  // Scan circuit description for models
  for( sz1=0; sz1<m_osaNetLst.GetCount( ); sz1++ )
  {
    os1 = m_osaNetLst.Item( sz1 );

    if( bIsSubCkt( os1 ) )                     continue;
    if( os1.IsEmpty( ) && osModel.IsEmpty( ) ) continue;

    os2 = os1;
    os2.MakeUpper( );

    if( os2.StartsWith( wxT(".MODEL ") ) )
    { // First line of model description found
      if( ! osModel.IsEmpty( ) ) m_osaModels.Add( osModel );
      osModel = os1;
    }
    else if( os1.GetChar( 0 ) == wxT('+') )
    { // Intermediate line of model description found
      if( osModel.Length( ) > 1 ) osModel << wxT('\n') << os1;
    }
    else if( ! osModel.IsEmpty( ) )
    { // Last line of model description found
      m_osaModels.Add( osModel );
      osModel.Empty( );
    }
  }

  return( true );
}

//**************************************************************************************************
// Extract any sub-circuit descriptions from the circuit description (netlist).
//
// The format of a sub-circuit description is illustrated in the following example :
//
//   .SUBCKT CCTNAME 1 5
//   R1 1 2 1K
//   R2 2 3 2K
//   R3 3 4 3K
//   R4 4 5 4K
//   .ENDS CCTNAME
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bLoadSubCcts( void )
{
  wxString  osSubCct;
  wxString  os1, os2;
  size_t    sz1;

  // Clear the sub-circuit string array object attribute
  m_osaSubCcts.Clear( );

  // Need at least a title line, 2 components and a sub-circuit description containing 2 lines
  if( m_osaNetLst.GetCount( ) < 7 ) return( true );

  // Scan circuit description for sub-circuits
  for( sz1=0; sz1<m_osaNetLst.GetCount( ); sz1++ )
  {
    os1 = m_osaNetLst.Item( sz1 );

    if( os1.IsEmpty( ) && osSubCct.IsEmpty( ) ) continue;

    os2 = os1;
    os2.MakeUpper( );

    if(      os2.StartsWith( wxT(".SUBCKT ") ) )
    { // First line in sub-circuit description found
      osSubCct = os1;
    }
    else if( os2.StartsWith( wxT(".ENDS") ) )
    { // Last line in sub-circuit description found
      if( ! osSubCct.IsEmpty( ) )
      {
        osSubCct << wxT('\n') << os1;
        m_osaSubCcts.Add( osSubCct );
        osSubCct.Empty( );
      }
    }
    else if( ! osSubCct.IsEmpty( ) )
    { // Intermediate line in sub-circuit description found (ignoring all comments)
      if( os1[ 0 ] != wxT('*') ) osSubCct << wxT('\n') << os1;
    }
  }

  return( true );
}

//**************************************************************************************************
// Extract all nodes labels from the component array.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bLoadNodeLbls( void )
{
  wxString  os1;
  size_t    sz1, sz2;
  int       i1;

  // Clear the node lables string array object attribute
  m_osaNodeLbls.Clear( );

  // Check that there are some components
  if( m_oaCpnts.IsEmpty( ) )     return( false );

  for( sz1=0; sz1<m_oaCpnts.GetCount( ); sz1++ )
  {
    Component & roCpnt = m_oaCpnts.Item( sz1 );
    if( roCpnt.rosaGetNodes( ).IsEmpty( ) ) continue;

    for( sz2=0; sz2<roCpnt.rosaGetNodes( ).GetCount( ); sz2++ )
    {
      os1 = roCpnt.rosaGetNodes( ).Item( sz2 );
      if( m_osaNodeLbls.Index( os1 ) == wxNOT_FOUND )
        m_osaNodeLbls.Add( os1 );
    }
  }

  // Check that some node labels were collected
  if( m_osaNodeLbls.IsEmpty( ) ) return( false );

  // Remove the earth / ground nodes if present
  if( ( i1=m_osaNodeLbls.Index( wxT("0") ) )   != wxNOT_FOUND ) m_osaNodeLbls.RemoveAt( i1 );
  if( ( i1=m_osaNodeLbls.Index( wxT("GND") ) ) != wxNOT_FOUND ) m_osaNodeLbls.RemoveAt( i1 );

  // Sort the list of node labels
  m_osaNodeLbls.Sort( &iStrCmpNode );

  return( true );
}

//**************************************************************************************************
// Extract the schematic file name/s the netlist was derived from.
//
// When gSpiceUI imports a netlist from schematic file/s it places a reference to the schematic
// file/s near the top of the netlist file as follows :
//   "* Schematics : <path>/circuit1.sch <path>/circuit2.sch"
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bLoadSchemFiles( void )
{
  wxString  os1, os2;
  size_t    sz1;

  // Scan the netlist for a reference any schematic file name/s it was derived from
  for( sz1=0; sz1<m_osaNetLst.GetCount( ); sz1++ )
  {
    os1 = m_osaNetLst.Item( sz1 );

    if( os1.IsEmpty( )   )                              continue;
    if( os1.GetChar( 0 ) != wxT('*') )                  continue;
    if( os1.StartsWith( wxT("* Schematic : "), &os2 ) )
    {
      // Set the schematic file name/s
      if( ! bSetSchemFiles( os2 ) ) return( false );
      break;
    }
  }

  return( true );
}

//**************************************************************************************************
// This function indicates whether a line in a sequence of lines falls within a sub-circuit
// definition block.
//
// Argument List :
//   A line in a sequence of lines to be tested
//
// Return Values :
//   true  - The line does    falls within a su-circuit definition block
//   false - The line doesn't falls within a su-circuit definition block

bool  NetList::bIsSubCkt( wxString & roLine )
{
  static  bool      bIsSubCkt=false;  // This flag's state must be preserved between calls
          wxString  os1;

  os1 = roLine;
  os1.MakeUpper( );
  if( os1.StartsWith( wxT(".SUBCKT") ) ) bIsSubCkt = true;
  if( os1.StartsWith( wxT(".ENDS") ) )   bIsSubCkt = false;

  return( bIsSubCkt );
}

//**************************************************************************************************
// Makes the object and its attributes empty and frees memory allocated to it.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bClear( void )
{
  m_osaNetLst  .Clear( );

  m_osaTitle   .Clear( );
  m_osaIncludes.Clear( );
  m_oaCpnts    .Clear( );
  m_osaModels  .Clear( );
  m_osaSubCcts .Clear( );

  m_osaNodeLbls.Clear( );

  m_bIsValid = false;

  return( true );
}

//**************************************************************************************************
// Do the current object attributes constitute a valid netlist?
//
// Return Values:
//   true  - Valid
//   false - Not valid

bool  NetList::bValidate( void )
{
  m_bIsValid = true;

  // Check that there is a title
  if( m_osaTitle.IsEmpty( ) )     { m_bIsValid = false; return( false ); }

  // Check that there are at least two components defined
  if( m_oaCpnts.GetCount( ) < 2 ) { m_bIsValid = false; return( false ); }

  return( true );
}

//**************************************************************************************************
// Load (or reload) a circuit description from file.
//
// Argument List :
//   rosFName - The name of the file to be loaded (if this string is empty it's a reload operation)
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bLoadFile( const wxString & rosFName )
{
  wxString  os1;

  // Is this a load or reload operation?
  if( ! rosFName.IsEmpty( ) )
       { if( ! bSetLoadFile( rosFName )          )        return( false ); }
  else { if( m_ofnLoadFile.GetFullPath( ).IsEmpty( ) )    return( false ); }

  bClear( );  // Clear the object attributes

  // Open the netlist file
  wxTextFile  oFileCct( m_ofnLoadFile.GetFullPath( ) );
  oFileCct.Open( );
  if( ! oFileCct.IsOpened( )       ) { oFileCct.Close( ); return( false ); }
  if( oFileCct.GetLineCount( ) < 3 ) { oFileCct.Close( ); return( false ); }

  // Load the netlist file contents into the netlist string array
  for( os1=oFileCct.GetFirstLine(); !oFileCct.Eof(); os1=oFileCct.GetNextLine() )
    m_osaNetLst.Add( os1 );

  // The following line picks up the last line in the file if it has no line termination character
  if( os1.Length( ) > 0 ) m_osaNetLst.Add( os1 );

  oFileCct.Close( ); // Close the netlist file

  return( true );
}

//**************************************************************************************************
// Save (or resave) the circuit description to file.
//
// Argument List :
//   rosFName - The name of the file to be saved
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bSaveFile( const wxString & rosFName )
{
  size_t  sz1;

  // Is this a save or resave?
  if( ! rosFName.IsEmpty( ) )
       { if( ! bSetSaveFile( rosFName ) ) return( false ); }
  else { if( ! m_ofnSaveFile.IsOk( )    ) return( false ); }

  // Open the file
  wxTextFile  oFileCct( m_ofnSaveFile.GetFullPath( ) );
  if( oFileCct.Exists( ) )
       { if( ! oFileCct.Open( )   )       return( false ); }
  else { if( ! oFileCct.Create( ) )       return( false ); }

  // Clear the file if it contains lines
  for( sz1=oFileCct.GetLineCount( ); sz1>0; sz1-- )
    oFileCct.RemoveLine( 0 );

  // Save the contents of the netlist string array to file
  for( sz1=0; sz1<m_osaNetLst.GetCount( ); sz1++ )
    oFileCct.AddLine( m_osaNetLst.Item( sz1 ) );

  // Save the changes to disk
  oFileCct.Write( );
  oFileCct.Close( );

  return( true );
}

//**************************************************************************************************
// Load the various object attributes with information from the netlist string array : m_osaNetLst.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bLoad( void )
{
  // Does the netlist string array contain anything?
  if( m_osaNetLst.IsEmpty( ) )
    m_bIsValid = false;
  else
  {
    m_bIsValid = true;

    // Attempt to extract the circuit description information
    if( ! bLoadTitle     ( ) ) m_bIsValid = false;
    if( ! bLoadIncludes  ( ) ) m_bIsValid = false;
    if( ! bLoadCpnts     ( ) ) m_bIsValid = false;
    if( ! bLoadModels    ( ) ) m_bIsValid = false;
    if( ! bLoadSubCcts   ( ) ) m_bIsValid = false;
    if( ! bLoadNodeLbls  ( ) ) m_bIsValid = false;
    if( ! bLoadSchemFiles( ) ) m_bIsValid = false;
  }

  return( m_bIsValid );
}

//**************************************************************************************************
// Save the various object attributes information to the netlist string array : m_osaNetLst.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bSave( void )
{
  wxString  os1, os2;
  size_t    sz1;

  // Clear the netlist string array contents and frees memory
  m_osaNetLst.Clear( );

  // Save the gSpiceUI banner lines eg. :
  //   ********************************************************************************
  //   *           Electronic circuit simulation file generated by gSpiceUI           *
  //   *                         Version 0.9.93 (2015-04-03)                          *
  //   ********************************************************************************
  os1.Empty( );
  os1.append( 78, wxT('*') );
  m_osaNetLst.Add( os1 );

  os2 = wxString( wxT("Electronic circuit simulation file generated by ") ) + APP_NAME;
  os2.insert( (size_t) 0, (os1.Len( ) - os2.Len( ) - 2)/2, wxT(' ') );
  os2.append(              os1.Len( ) - os2.Len( ) - 2   , wxT(' ') );
  m_osaNetLst.Add( wxT('*') + os2 + wxT('*') );

  os2 = wxString( wxT("Version ") ) + APP_VERSION + wxT(" (") + APP_DATE + wxT(")");
  os2.insert( (size_t) 0, (os1.Len( ) - os2.Len( ) - 2)/2, wxT(' ') );
  os2.append(              os1.Len( ) - os2.Len( ) - 2   , wxT(' ') );
  m_osaNetLst.Add( wxT('*') + os2 + wxT('*') );

  m_osaNetLst.Add( os1 );
  m_osaNetLst.Add( wxT("") );

  // Save the schematic file name/s if specified
  if( ! m_oaSchemFiles.IsEmpty( ) )
  {
    os1 = wxT("* Schematic : ") + rosGetSchemFiles( );
    m_osaNetLst.Add( os1 );
    m_osaNetLst.Add( wxT("") );
  }

  // Save any pre-existing title line/s
  if( ! m_osaTitle.IsEmpty( ) )
  {
    for( sz1=0; sz1<m_osaTitle.GetCount( ); sz1++ )
      m_osaNetLst.Add( m_osaTitle[ sz1 ] );
    m_osaNetLst.Add( wxT("") );
  }

  // Save the include directives
  if( ! m_osaIncludes.IsEmpty( ) )
  {
    m_osaNetLst.Add( wxT("********** Include Directives **********") );
    m_osaNetLst.Add( wxT("") );
    for( sz1=0; sz1<m_osaIncludes.GetCount( ); sz1++ )
      m_osaNetLst.Add( m_osaIncludes[ sz1 ] );
    m_osaNetLst.Add( wxT("") );
  }

  // Save the component definition lines
  m_osaNetLst.Add( wxT("********** Component Definitions **********") );
  m_osaNetLst.Add( wxT("") );
  for( sz1=0; sz1<m_oaCpnts.GetCount( ); sz1++ )
    m_osaNetLst.Add( m_oaCpnts[ sz1 ].rosGetString( ) );
  m_osaNetLst.Add( wxT("") );

  // Save the sub-circuit definitions
  if( ! m_osaSubCcts.IsEmpty( ) )
  {
    m_osaNetLst.Add( wxT("********** Sub-Circuit Definitions **********") );
    m_osaNetLst.Add( wxT("") );
    for( sz1=0; sz1<m_osaSubCcts.GetCount( ); sz1++ )
    {
      m_osaNetLst.Add( m_osaSubCcts[ sz1 ] );
      m_osaNetLst.Add( wxT("") );
    }
  }

  // Save the model definition lines
  if( ! m_osaModels.IsEmpty( ) )
  {
    m_osaNetLst.Add( wxT("********** Model Definitions **********") );
    m_osaNetLst.Add( wxT("") );
    for( sz1=0; sz1<m_osaModels.GetCount( ); sz1++ )
    {
      m_osaNetLst.Add( m_osaModels[ sz1 ] );
      m_osaNetLst.Add( wxT("") );
    }
  }

  // Save the circuit description terminator
  m_osaNetLst.Add( wxT(".END") );

  return( true );
}

//**************************************************************************************************
// Set the load (netlist) file name.
//
// Argument List :
//   rosFName - The load file name
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bSetLoadFile( const wxString & rosFName )
{
  wxFileName  ofn1;

  ofn1 = rosFName;

  // Is the file name valid and does it exist?
  if( ! ofn1.IsOk( ) )       return( false );
  if( ! ofn1.FileExists( ) ) return( false );

  m_ofnLoadFile = ofn1;

  return( true );
}

//**************************************************************************************************
// Set the save (netlist) file name.
//
// Argument List :
//   rosFName - The save file name
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bSetSaveFile( const wxString & rosFName )
{
  wxFileName  ofn1;

  ofn1 = rosFName;

  // Is the file name valid?
  if( ! ofn1.IsOk( ) ) return( false );

  m_ofnSaveFile = ofn1;

  return( true );
}

//**************************************************************************************************
// Set the schematic file name/s from which the netlist file was derived.
//
// Argument List :
//   rosaFName - The schematic file name/s
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bSetSchemFiles( const wxArrayString & rosaFNames )
{
  wxFileName  ofn1;
  size_t      sz1;

  // Clear the schematic file name/s attribute
  m_oaSchemFiles.Clear( );

  for( sz1=0; sz1<rosaFNames.GetCount( ); sz1++ )
  {
    ofn1 = rosaFNames.Item( sz1 );

    // Is the file name valid and does it exist?
    if( ! ofn1.IsOk( ) )       continue;
    if( ! ofn1.FileExists( ) ) continue;

    m_oaSchemFiles.Add( ofn1 );
  }

  return( true );
}

//**************************************************************************************************
// Set the schematic file name/s from which the netlist was derived.
//
// Argument List :
//   rosFName - The schematic file name/s
//
// Return Values :
//   true  - Success
//   false - Failure

bool  NetList::bSetSchemFiles( const wxString & rosFNames )
{
  return( bSetSchemFiles( roasStrToArr( rosFNames ) ) );
}

//**************************************************************************************************
// Return a reference to an wxArrayString object containing a list of the schematic file names.
//
// Return Values :
//   Success - The schematic file names
//   Failure - An empty wxArrayString object

const wxArrayString & NetList::roasGetSchemFiles( void )
{
  static  wxArrayString  oas1;
          size_t         sz1;

  oas1.Empty( );

  for( sz1=0; sz1<m_oaSchemFiles.GetCount( ); sz1++ )
    oas1.Add( m_oaSchemFiles.Item( sz1 ).GetFullPath( ) );

  return( oas1 );
}

//**************************************************************************************************
// Return a reference to a wxString object containing a list of the schematic file names.
//
// Return Values :
//   Success - The schematic file names
//   Failure - An empty wxString object

const wxString & NetList::rosGetSchemFiles( void )
{
  static  wxString  os1;
          size_t    sz1;

  os1.Empty( );

  for( sz1=0; sz1<m_oaSchemFiles.GetCount( ); sz1++ )
  {
    if( ! os1.IsEmpty( ) ) os1 << wxT(' ');
    os1 << m_oaSchemFiles.Item( sz1 ).GetFullPath( );
  }

  return( os1 );
}

//**************************************************************************************************
// Get a reference to the Component object in m_oaCpnts with a specified name.
//
// Argument List :
//   rosName - The component name (label)
//
// Return Values :
//   Success - The component reference in m_oaCpnts
//   Failure - An empty Component object

const Component & NetList::roGetCpnt( const wxString & rosName )
{
  static  Component  oCpntEmpty;
          wxString   os1, os2;
          size_t     sz1;

  if( rosName  .IsEmpty( ) ) return( oCpntEmpty );
  if( m_oaCpnts.IsEmpty( ) ) return( oCpntEmpty );

  for( sz1=0; sz1<m_oaCpnts.GetCount( ); sz1++ )
    if( m_oaCpnts.Item( sz1 ).rosGetName( ) == rosName )
      return( m_oaCpnts.Item( sz1 ) );

  return( oCpntEmpty );
}

//**************************************************************************************************
// Print the object attributes.
//
// Argument List :
//   rosPrefix - A prefix to every line displayed (usually just spaces)

void  NetList::Print( const wxString & rosPrefix )
{
  wxString  os1;
  size_t    sz1;

  os1 = m_ofnLoadFile.GetFullPath( );
  std::cout << rosPrefix.mb_str( ) << "m_ofnLoad        : " << os1.mb_str( ) << '\n';
  os1 = m_ofnSaveFile.GetFullPath( );
  std::cout << rosPrefix.mb_str( ) << "m_ofnSave        : " << os1.mb_str( ) << '\n';
  os1 = rosGetSchemFiles( );
  std::cout << rosPrefix.mb_str( ) << "m_osSchemFiles   : " << os1.mb_str( ) << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osaNetLst[ ]   : ";
  if( ! m_osaNetLst.IsEmpty( ) )
  {
    for( sz1=0; sz1<m_osaNetLst.GetCount( ); sz1++ )
    {
      if( sz1 > 0 ) std::cout << rosPrefix.mb_str( ) << "                   ";
      std::cout << m_osaNetLst.Item( sz1 ).mb_str( ) << '\n';
    }
  }
  else std::cout << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osaTitle[ ]    : ";
  if( ! m_osaTitle.IsEmpty( ) )
  {
    for( sz1=0; sz1<m_osaTitle.GetCount( ); sz1++ )
    {
      if( sz1 > 0 ) std::cout << rosPrefix.mb_str( ) << "                   ";
      std::cout << m_osaTitle.Item( sz1 ).mb_str( ) << '\n';
    }
  }
  else std::cout << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osaIncludes[ ] : ";
  if( ! m_osaIncludes.IsEmpty( ) )
  {
    for( sz1=0; sz1<m_osaIncludes.GetCount( ); sz1++ )
    {
      if( sz1 > 0 ) std::cout << rosPrefix.mb_str( ) << "                   ";
      std::cout << m_osaIncludes.Item( sz1 ).mb_str( ) << '\n';
    }
  }
  else std::cout << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_oaCpnts[ ]     : ";
  if( ! m_oaCpnts.IsEmpty( ) )
  {
    for( sz1=0; sz1<m_oaCpnts.GetCount( ); sz1++ )
    {
      if( sz1 > 0 ) std::cout << rosPrefix.mb_str( ) << "                   ";
      std::cout << m_oaCpnts.Item( sz1 ).rosGetString( ).mb_str( ) << '\n';
    }
  }
  else std::cout << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osaModels[ ]   : ";
  if( ! m_osaModels.IsEmpty( ) )
  {
    for( sz1=0; sz1<m_osaModels.GetCount( ); sz1++ )
    {
      if( sz1 > 0 ) std::cout << rosPrefix.mb_str( ) << "                   ";
      std::cout << m_osaModels.Item( sz1 ).mb_str( ) << '\n';
    }
  }
  else std::cout << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osaSubCcts[ ]  : ";
  if( ! m_osaSubCcts.IsEmpty( ) )
  {
    for( sz1=0; sz1<m_osaSubCcts.GetCount( ); sz1++ )
    {
      if( sz1 > 0 ) std::cout << rosPrefix.mb_str( ) << "                   ";
      std::cout << m_osaSubCcts.Item( sz1 ).mb_str( ) << '\n';
    }
  }
  else std::cout << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_bIsValid       : "
            << ( m_bIsValid ? "true" : "false") << '\n';
}

//**************************************************************************************************
//                                          Test Utility                                           *
//**************************************************************************************************

#ifdef TEST_NETLIST

using  namespace  std;

// Function prototypes

void  Usage( char * psAppName );

//**************************************************************************************************

int  main( int argc, char * argv[ ] )
{
  // This function is used in wxBase only and only if an wxApp object isn't created at all. In this
  // case wxInitialize( ) must be called in main( ) before calling any other wxWidgets functions.
  if( ! wxInitialize( ) ) exit( EXIT_FAILURE );

  wxString  osCpnt;
  wxString  os1;

  // Validate the argument count passed to the application
  if( argc > 3 )                    { Usage( argv[ 0 ] ); exit( EXIT_FAILURE ); }

  // Process the command line arguments
  if( argc > 1 )
  {
    os1 = wxConvLibc.cMB2WC( argv[ 1 ] );
    if( os1.at( 0 ) == wxT('-') )
    {
      if( os1.at( 1 ) == wxT('h') ) { Usage( argv[ 0 ] ); exit( EXIT_SUCCESS ); }
      else                          { Usage( argv[ 0 ] ); exit( EXIT_FAILURE ); }
    }
  }
  else                              { Usage( argv[ 0 ] ); exit( EXIT_FAILURE ); }

  // Display the utility banner
  cout << "\n  Netlist Class Test Utility"
       << "\n  Version 1.03 (2016-09-27)\n";

  // Create a NetList object
  NetList  oNetLst;

  cout << "\nLoad the netlist file : ";
  if( oNetLst.bLoadFile( os1 ) ) cout << "Success";
  else                           cout << "Failure";
  cout << "\n";

  cout << "\ntNetLst.Print( ) :\n";
  oNetLst.Print( );

  cout << "\n";

  // This function must be called for each successful call to wxInitialize( ). Clean up; the library
  // can't be used any more.
  wxInitialize( );

  exit( EXIT_SUCCESS );
}

//**************************************************************************************************

void  Usage( char * psAppName )
{
  cout << "\nUsage   : " << psAppName << " [-OPTIONS] [FILE]"
       << "\nOptions : -h   : Print usage (this message)"
       << "\n          FILE : A circuit description (NetList) file"
       << "\n\n";
}

#endif // TEST_NETLIST

//**************************************************************************************************