CFPRIME OPENRE                                                          OPENRE      1
C***********************************************************************RIGHTE      1
C*                                                                     *RIGHTE      2
C*        Extended Transient-Midterm Stability Program (ETMSP)         *RIGHTE      3
C*        ====================================================         *RIGHTE      4
C*                                                                     *RIGHTE      5
C*       Copyright (C) (1993) Electric Power Research Institute        *RIGHTE      6
C*                                                                     *RIGHTE      7
C* EPRI reserves all rights in the software and associated             *RIGHTE      8
C* documentation as delivered. The software and its associated         *RIGHTE      9
C* documention or any portion thereof may not be reproduced in any form*RIGHTE     10
C* whatsoever without the consent of EPRI, except as explicity provided*RIGHTE     11
C* for by license. Licensee shall submit a detailed description to EPRI*RIGHTE     12
C* of any changes or modifications to the software within two (2)      *RIGHTE     13
C* months after such changes or modifications are made. At EPRI's sole *RIGHTE     14
C* discretion, the software, as changed or modified, shall be given a  *RIGHTE     15
C* new designation sufficiently different from its then current        *RIGHTE     16
C* designation as to prevent mistake,confusion, or deception as between*RIGHTE     17
C* the current software as changed or modified.                        *RIGHTE     18
C*                                                                     *RIGHTE     19
C* A license under EPRI's rights in the software can be obtained       *RIGHTE     20
C* directly from EPRI.                                                 *RIGHTE     21
C*                                                                     *RIGHTE     22
C* This program and supporting materials may be independently available*RIGHTE     23
C* from Electric Power Software centre (EPSC) for an appropriate       *RIGHTE     24
C* distribution fee. The EPSC is a service of                          *RIGHTE     25
C*                                                                     *RIGHTE     26
C*                    Power Computing Company                          *RIGHTE     27
C*                    1930 Hi Line                                     *RIGHTE     28
C*                    Dallas, Tx 75207                                 *RIGHTE     29
C*                                                                     *RIGHTE     30
C* NEITHER EPRI, ANY MEMBER OF EPRI, NOR ANY PERSON OR  ORGANIZATION   *RIGHTE     31
C* ACTING ON BEHAVE OF THEM:                                           *RIGHTE     32
C*                                                                     *RIGHTE     33
C* 1. MAKE ANY WARRANTY OR REPRESENTATION WHATSOEVER, EXPRESS OR       *RIGHTE     34
C*    IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS OR *RIGHTE     35
C*    ANY PURPOSE WITH RESPECT TO THE SOFTWARE OR ITS ASSOCIATED       *RIGHTE     36
C*    DOCUMENTATION; OR                                                *RIGHTE     37
C*                                                                     *RIGHTE     38
C* 2. ASSUMES ANY LIABILITY WHATSOEVER WITH RESPECT TO ANY USE OF THE  *RIGHTE     39
C*    SOFTWARE OR ITS ASSOCIATED DOCUMENTATION OR ANY PORTION THEREOF  *RIGHTE     40
C*    OR WITH RESPECT TO ANY DAMAGES WHICH MAY RESULT FROM SUCH USE.   *RIGHTE     41
C*                                                                     *RIGHTE     42
C* THIS NOTICE MAY NOT BE REMOVED FROM THE SOFTWARE BY ANY USER        *RIGHTE     43
C* THEREOF.                                                            *RIGHTE     44
C*                                                                     *RIGHTE     45
C***********************************************************************RIGHTE     46
      SUBROUTINE OPENRE (IUNIT,FILENA,JLENG,IKEY,ISTAT,LFN)             OPENRE      3
CD                                                                      OPENRE      4
CD    THIS IS A NON-PORTABLE ROUTINE USED BY ETMSP TO OPEN FILES.       OPENRE      5
CD                                                                      OPENRE      6
C  CALLED BY :                                                          OPENRE      7
C  FLODA1(IKEY=1) - OPEN OLD FORMATTED LOADFLOW FILE                    OPENRE      8
C  FLODA2(IKEY=2) - OPEN OLD UNFORMATTED  LOADFLOW FILE                 OPENRE      9
C  FLODA4(IKEY=2) - "    "        "                                     OPENRE     10
C  FLODA5(IKEY=2) - "    "        "                                     OPENRE     11
C  DBHEAD(IKEY=3) - OPEN DYNANIC MODEL DATA BANK FILE                   OPENRE     12
C  FRELAY(IKEY=3) - OPEN RELAY DATA BANK FILE                           OPENRE     13
C  READEP(IKEY=4) - OPEN DIR ACCES SCRATCD FILE RECORD LENGTH=32*4 BYTE OPENRE     14
C  READIE(IKEY=4) - OPEN DIR ACCES SCRATCD FILE RECORD LENGTH=32*4 BYTE OPENRE     15
C  LSHDAT(IKEY=4) - OPEN DIR ACCES SCRATCD FILE RECORD LENGTH=32*4 BYTE OPENRE     16
C  LSWITD(IKEY=4) - OPEN DIR ACCES SCRATCD FILE RECORD LENGTH=32*4 BYTE OPENRE     17
C  EDTFIL(IKEY=4) - OPEN DIR ACCES SCRATCD FILE RECORD LENGTH=32*4 BYTE OPENRE     18
C  LSWITD(IKEY=4) - OPEN DIR ACCES SCRATCD FILE RECORD LENGTH=32*4 BYTE OPENRE     19
C  SETUPT(IKEY=5) - OPEN DIR ACCES NEW FILE RECORD LENGTH=128*4 BYTES   OPENRE     20
C  BEGREC(IKEY=6) - OPEN NEW FORMATTED RECORD FILE LENGTH=80 BYTES      OPENRE     21
C  HELPSC(IKEY=6) - OPEN NEW FORMATTED DEBUG PRINTING FILE LENGTH=133   OPENRE     22
C  LSWITD(IKEY=6) - OPEN NEW FORMATTED SWITCHING SUMMARY FILE           OPENRE     23
C                   LENGTH=133                                          OPENRE     24
C  SETUP (IKEY=6) - OPEN NEW FORMATTED MESSSAGE & WARNING FILE          OPENRE     25
C                   LENGTH=133                                          OPENRE     26
C  SETUP (IKEY=6) - OPEN NEW FORMATTED PROGRAM PROGRESS REPORT FILE     OPENRE     27
C                   LENGTH=133                                          OPENRE     28
C  SETUP (IKEY=6) - OPEN NEW FORMATTED SIMULATION RESULT FILE           OPENRE     29
C                   LENGTH=133                                          OPENRE     30
C  TABDAT(IKEY=6) - OPEN NEW FORMATTED DATA TABULATION AND              OPENRE     31
C                   INITIALIZATION PRINTING FILE LENGTH=133             OPENRE     32
C  TABINI(IKEY=6) - OPEN NEW FORMATTED INITIALIZATION PRINTING FILE     OPENRE     33
C                   LENGTH=133                                          OPENRE     34
C  FLOPSF(IKEY=7) - OPEN DIR ACCES OLD UNFORMATED FILE LENGTH=64        OPENRE     35
C  SWITDA(IKEY=8) - OPEN SEQUENTIAL FORMATTED FILE                      OPENRE     36
C  CFLRUN(IKEY=9) - OPEN SEQUENTIAL FORMATTED SCRATCH FILE              OPENRE     37
C  CFLRUN(IKEY=10)- OPEN UNKNOWN SEQUENTIAL FORMATTED FILE              OPENRE     38
C                                                                       OPENRE     39
C!!      CHARACTER*32 FILENA                                            OPENRE     40
      CHARACTER*(*) FILENA                                              OPENRE     41
C                                                                       OPENRE     42
*IF OMVAX                                                               OPENRE     43
*ENDIF                                                                  OPENRE    103
*IF OPRIME                                                              OPENRE    104
*ENDIF                                                                  OPENRE    161
*IF OMIBM                                                               OPENRE    162
*ENDIF                                                                  OPENRE    224
*IF OWIBM                                                               OPENRE    225
      JJLEN=JLENG*4                                                     OPENRE    226
      GOTO(110,120,130,140,150,160,170,180,190,200)IKEY                 OPENRE    227
C                                                                       OPENRE    228
 110  CONTINUE                                                          OPENRE    229
      OPEN(IUNIT,FILE=FILENA(1:LFN)                                     OPENRE    230
     &,STATUS='OLD',IOSTAT=ISTAT,FORM='FORMATTED')                      OPENRE    231
      RETURN                                                            OPENRE    232
 120  CONTINUE                                                          OPENRE    233
      OPEN(IUNIT,FILE=FILENA(1:LFN)                                     OPENRE    234
     &,STATUS='OLD',FORM='UNFORMATTED',IOSTAT=ISTAT)                    OPENRE    235
      RETURN                                                            OPENRE    236
 130  CONTINUE                                                          OPENRE    237
      OPEN(IUNIT,FILE=FILENA(1:LFN),STATUS='OLD'                        OPENRE    238
     &,ACCESS='DIRECT',IOSTAT=ISTAT,RECL=JJLEN)                         OPENRE    239
      IF(ISTAT.EQ.0) RETURN                                             OPENRE    240
C     ERROR OPENNING DB FILE, SET FLAG BEFORE RETURN                    OPENRE    241
      IKEY=-1                                                           OPENRE    242
      RETURN                                                            OPENRE    243
 140  CONTINUE                                                          OPENRE    244
      OPEN (IUNIT,STATUS='SCRATCH',ACCESS='DIRECT',RECL=JJLEN           OPENRE    245
     &,FORM='UNFORMATTED')                                              OPENRE    246
      RETURN                                                            OPENRE    247
 150  CONTINUE                                                          OPENRE    248
      IF(LFN.EQ.0) THEN                                                 OPENRE    249
      OPEN (IUNIT,STATUS='UNKNOWN',ACCESS='DIRECT'                      OPENRE    250
     &,RECL=JJLEN,FORM='UNFORMATTED')                                   OPENRE    251
C                                                                       OPENRE    252
      ELSE                                                              OPENRE    253
      OPEN(IUNIT,FILE=FILENA(1:LFN),STATUS='UNKNOWN',ACCESS='DIRECT'    OPENRE    254
     &,RECL=JJLEN,FORM='UNFORMATTED')                                   OPENRE    255
      ENDIF                                                             OPENRE    256
C                                                                       OPENRE    257
      RETURN                                                            OPENRE    258
 160  CONTINUE                                                          OPENRE    259
      OPEN(IUNIT,FILE=FILENA(1:LFN),STATUS='UNKNOWN',IOSTAT=ISTAT       OPENRE    260
     &,FORM='FORMATTED')                                                OPENRE    261
      RETURN                                                            OPENRE    262
C                                                                       OPENRE    263
 170  CONTINUE                                                          OPENRE    264
       OPEN (IUNIT,FILE=FILENA(1:LFN),STATUS='OLD',ACCESS='DIRECT',     OPENRE    265
     * FORM='UNFORMATTED',RECL=JJLEN,IOSTAT=ISTAT)                      OPENRE    266
       RETURN                                                           OPENRE    267
 180  CONTINUE                                                          OPENRE    268
      OPEN(IUNIT,FILE=FILENA(1:LFN),STATUS='OLD'                        OPENRE    269
     &,IOSTAT=ISTAT,FORM='FORMATTED')                                   OPENRE    270
       RETURN                                                           OPENRE    271
C                                                                       OPENRE    272
 190   CONTINUE                                                         OPENRE    273
       OPEN(IUNIT,STATUS='SCRATCH',ACCESS='SEQUENTIAL',                 OPENRE    274
     +  FORM='FORMATTED')                                               OPENRE    275
       RETURN                                                           OPENRE    276
C                                                                       OPENRE    277
 200   CONTINUE                                                         OPENRE    278
       OPEN(IUNIT,FILE=FILENA(1:LFN),STATUS='UNKNOWN',                  OPENRE    279
     +  ACCESS='SEQUENTIAL',FORM='FORMATTED')                           OPENRE    280
       RETURN                                                           OPENRE    281
*ENDIF                                                                  OPENRE    282
*IF OAPOLO                                                              OPENRE    283
*ENDIF                                                                  OPENRE    340
*IF OWSUN                                                               OPENRE    341
*ENDIF                                                                  OPENRE    398
*IF OWDEC                                                               OPENRE    399
*ENDIF                                                                  OPENRE    456
*IF OMSDOS                                                              OPENRE    457
*ENDIF                                                                  OPENRE    516
      END                                                               OPENRE    517
C                                                                       OPENRE    518
      SUBROUTINE CLOSEF(IUX)                                            OPENRE    519
CD                                                                      OPENRE    520
CD    THIS IS THE CENTRALIZED ROUTINE USED BY ETMSP TO CLOSE A LOGICAL  OPENRE    521
CD    FILE.                                                             OPENRE    522
CD                                                                      OPENRE    523
      INCLUDE 'CNLUN.INS'                                               OPENRE    524
      INCLUDE 'CNUNIT.INS'                                              OPENRE    525
      INCLUDE 'CNLSTA.INS'                                              OPENRE    526
C                                                                       OPENRE    527
      IF(IUX.NE.LIN.AND.IUX.NE.LOUT)THEN                                OPENRE    528
C                                                                       OPENRE    529
      IF(LUNITS(IUX))CLOSE(IUX)                                         OPENRE    530
C                                                                       OPENRE    531
*IF -MIBM                                                               OPENRE    532
      LUNITS(IUX)=.FALSE.                                               OPENRE    533
*ENDIF                                                                  OPENRE    534
C                                                                       OPENRE    535
      ENDIF                                                             OPENRE    536
C                                                                       OPENRE    537
      RETURN                                                            OPENRE    538
C                                                                       OPENRE    539
C     CLOSE ALL FILES                                                   OPENRE    540
C                                                                       OPENRE    541
      ENTRY CLOSEA                                                      OPENRE    542
CD                                                                      OPENRE    543
CD    THIS IS THE CENTRALIZED ROUTINE USED BY ETMSP TO CLOSE ALL        OPENRE    544
CD    LOGICAL UNITS OPENED DURING THE EXCUTION OF THE PROGRAM.          OPENRE    545
CD                                                                      OPENRE    546
C                                                                       OPENRE    547
C     WRITE ENDFILE TO DATA PRINTING AND SIWTCHING SUMMARY FILES        OPENRE    548
C                                                                       OPENRE    549
      IF(LUNITS(IU18))ENDFILE(IU18)                                     OPENRE    550
      IF(LUNITS(IU51))ENDFILE(IU51)                                     OPENRE    551
      IF(LUNITS(IU6))ENDFILE(IU6)                                       OPENRE    552
      IF(LUNITS(IU16))ENDFILE(IU16)                                     OPENRE    553
      IF(LUNITS(IU17))ENDFILE(IU17)                                     OPENRE    554
C                                                                       OPENRE    555
      DO 100 I=1,100                                                    OPENRE    556
      IF(LUNITS(I))CLOSE(I)                                             OPENRE    557
 100  CONTINUE                                                          OPENRE    558
      RETURN                                                            OPENRE    559
      END                                                               OPENRE    560
