CFPRIME FILEMG                                                          FILEMG      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 FILEMG                                                 FILEMG      3
     *(IUX,LMSG,IMSG,LEMSG,EMSG,SUBPMT,IKEY,JLENG,IEBK)                 FILEMG      4
CD                                                                      FILEMG      5
CD    TO OPEN A LOGICAL FILE ACCORDING TO THE FILE NAME FROM THE USER.  FILEMG      6
CD                                                                      FILEMG      7
CD    THE ARGUMENT LIST IS GIVEN BELOW.                                 FILEMG      8
CD                                                                      FILEMG      9
CD     IUX     LOGICAL UNIT NUMBER                                      FILEMG     10
CD     LMSG    LENGTH OF MESSAGE IN NUMBER OF CHARACTERS                FILEMG     11
CD     IMSG    MESSAGE TO BE PRINTED FOR PROMPTING THE USER             FILEMG     12
CD     LEMSG   LENGTH OF ERROR MESSAGE IN NUMBER OF CHARACTERS          FILEMG     13
CD     EMSG    ERROR MESSAGE, PRINTED IF ANY THING GOES WRONG           FILEMG     14
CD     SUBPMT  SUBROUTINE NAME OF THE CALLING ROUTINE                   FILEMG     15
CD     IKEY    FILE OPENING KEY (TYPE OF FILE TO BE OPENED)             FILEMG     16
CD     JLENG   FILE RECORD LENGTH IN 4 BYTE WORDS                       FILEMG     17
CD     IEBK    ERROR RETURN CODE                                        FILEMG     18
CD             -1  QUIT OR ABORT                                        FILEMG     19
CD              0  NORMAL RETURN                                        FILEMG     20
CD              1  TOO MANY MISTAKES                                    FILEMG     21
CD                                                                      FILEMG     22
CD    THE MAIN STEPS ARE AS FOLLOWS.                                    FILEMG     23
CD                                                                      FILEMG     24
      INCLUDE 'CNLSTA.INS'                                              FILEMG     25
      INCLUDE 'CNLUN.INS'                                               FILEMG     26
      INCLUDE 'CNMSG.INS'                                               FILEMG     27
C                                                                       FILEMG     28
      CHARACTER*80 IMSG,EMSG,STRING                                     FILEMG     29
      CHARACTER*50 FILENA                                               FILEMG     30
      CHARACTER*7 SUBPMT                                                FILEMG     31
C                                                                       FILEMG     32
      FILENA(1:1)=' '                                                   FILEMG     33
C                                                                       FILEMG     34
      MEMOUT=0                                                          FILEMG     35
C                                                                       FILEMG     36
   10 CONTINUE                                                          FILEMG     37
C                                                                       FILEMG     38
      MEMOUT=MEMOUT+1                                                   FILEMG     39
      IF(MEMOUT.GT.5)THEN                                               FILEMG     40
      WRITE(LOUT,1000)                                                  FILEMG     41
      IEBK=1                                                            FILEMG     42
      GOTO 100                                                          FILEMG     43
      ENDIF                                                             FILEMG     44
CD                                                                      FILEMG     45
CD    1. ASK FOR A FILE NAME IF IT'S NOT GIVEN ON THE COMMAND LINE      FILEMG     46
CD                                                                      FILEMG     47
CD       SAMPLE MESSAGE:                                                FILEMG     48
CD                                                                      FILEMG     49
CD       'Enter OUTPUT File Name for Dynamic Model Data'                FILEMG     50
CD                                                                      FILEMG     51
      CALL PMTRED(LOUT,LIN,JERR,LMSG,IMSG,'FIL',STRING,KREAD,PLAYBA)    FILEMG     52
             IF(RECORD) WRITE(IREC,'(A)')STRING                         FILEMG     53
             IF((JERR.LT.0).OR.(STRING(1:4).EQ.'QUIT').OR.              FILEMG     54
     1          (STRING(1:5).EQ.'ABORT').OR.                            FILEMG     55
     1          (STRING(1:4).EQ.'quit').OR.                             FILEMG     56
     1          (STRING(1:5).EQ.'abort') )THEN                          FILEMG     57
                IEBK=-1                                                 FILEMG     58
                KREAD=.TRUE.                                            FILEMG     59
                WRITE(LOUT,'(/A/)') ' FUNCTION ABORTED'                 FILEMG     60
                RETURN                                                  FILEMG     61
             ENDIF                                                      FILEMG     62
             LENFIL=LENS(STRING)                                        FILEMG     63
             FILENA(1:50)=STRING(1:50)                                  FILEMG     64
C                                                                       FILEMG     65
C            NO FILE NAME                                               FILEMG     66
C                                                                       FILEMG     67
             IF(LENFIL.LE.0)THEN                                        FILEMG     68
             KREAD=.TRUE.                                               FILEMG     69
             IF(PLAYBA)CALL PSTOP                                       FILEMG     70
             GOTO 10                                                    FILEMG     71
             ENDIF                                                      FILEMG     72
CD                                                                      FILEMG     73
CD    2. PARSE PARAMETER FOR A LOGICAL UNIT NUMBER                      FILEMG     74
CD                                                                      FILEMG     75
      CALL PARSIU(FILENA,LENFIL,IU,LO)                                  FILEMG     76
C                                                                       FILEMG     77
      IF(IU.GT.0)THEN                                                   FILEMG     78
      LENFIL=LO                                                         FILEMG     79
      STRING(1:LENFIL)=FILENA(1:LENFIL)                                 FILEMG     80
      IUX=IU                                                            FILEMG     81
      ELSEIF(IU.LT.0)THEN                                               FILEMG     82
      KREAD=.TRUE.                                                      FILEMG     83
      IF(PLAYBA)CALL PSTOP                                              FILEMG     84
      GOTO 10                                                           FILEMG     85
      ENDIF                                                             FILEMG     86
CD                                                                      FILEMG     87
CD    3. CHECK IF IU HAS EVER BEEN USED                                 FILEMG     88
CD                                                                      FILEMG     89
      CALL FBOKEP(IUX,IBACK)                                            FILEMG     90
C                                                                       FILEMG     91
          IF(IBACK.LT.0) THEN                                           FILEMG     92
          KREAD=.TRUE.                                                  FILEMG     93
          IF(PLAYBA)CALL PSTOP                                          FILEMG     94
          GOTO 10                                                       FILEMG     95
          ENDIF                                                         FILEMG     96
CD                                                                      FILEMG     97
CD    4. CALL SUBROUTINE OPENRE TO OPEN THE FILE                        FILEMG     98
CD                                                                      FILEMG     99
      CALL OPENRE(IUX,FILENA,JLENG,IKEY,ISTAT,LENFIL)                   FILEMG    100
C                                                                       FILEMG    101
      IF(ISTAT.NE.0)THEN                                                FILEMG    102
          MSG(1)=' *** '//EMSG(1:76)                                    FILEMG    103
          CALL PRTMSG(1)                                                FILEMG    104
          KREAD=.TRUE.                                                  FILEMG    105
          IF(PLAYBA)CALL PSTOP                                          FILEMG    106
          GOTO 10                                                       FILEMG    107
      ELSE                                                              FILEMG    108
          IEBK=0                                                        FILEMG    109
          LUNITS(IUX)=.TRUE.                                            FILEMG    110
      ENDIF                                                             FILEMG    111
C                                                                       FILEMG    112
 100  CONTINUE                                                          FILEMG    113
      RETURN                                                            FILEMG    114
 1000 FORMAT(/,' TOO MANY INVALID FILE NAMES',/)                        FILEMG    115
      END                                                               FILEMG    116
C                                                                       FILEMG    117
      SUBROUTINE PARSIU(FINAME,LE,IU,LO)                                FILEMG    118
CD                                                                      FILEMG    119
CD    TO PARSE PARAMETER FOR LOGICAL UNIT.                              FILEMG    120
CD                                                                      FILEMG    121
CD    FINAME  USER SPECIFIED NFILE NAME                                 FILEMG    122
CD    LO      WORD LENGTH OF FILE NAME (NOT DEFINED IF LOGICAL UNIT     FILEMG    123
CD            IS NOT SPECIFIED                                          FILEMG    124
CD    IU      THE SPECIFIED LOGICAL UNIT NUMBER                         FILEMG    125
CD            = -1 IF ERROR OR NOT SPECIFIED                            FILEMG    126
CD    LE      NOT USED                                                  FILEMG    127
CD                                                                      FILEMG    128
      INCLUDE 'CNLSTA.INS'                                              FILEMG    129
C                                                                       FILEMG    130
      CHARACTER*(*) FINAME                                              FILEMG    131
C                                                                       FILEMG    132
C   .....................................................               FILEMG    133
C   : read in unit number between < >                   :               FILEMG    134
C   :                                                   :               FILEMG    135
      LLSB=0                                                            FILEMG    136
      LRSB=0                                                            FILEMG    137
      LLSB=INDEX(FINAME,'<')                                            FILEMG    138
      LRSB=INDEX(FINAME,'>')                                            FILEMG    139
      IF((LLSB.NE.0) .AND.(LRSB.NE.0)) THEN                             FILEMG    140
          READ(FINAME(LLSB+1:LRSB-1),*,IOSTAT=IOS) IU                   FILEMG    141
          IF(IOS.NE.0) GOTO 120                                         FILEMG    142
          DO 100 I=LLSB-1,1                                             FILEMG    143
             IF(FINAME(I:I).NE.' ')GOTO 110                             FILEMG    144
 100      CONTINUE                                                      FILEMG    145
 110      LO=I                                                          FILEMG    146
      ELSEIF(LLSB.EQ.0.AND.LRSB.EQ.0)THEN                               FILEMG    147
          LO=0                                                          FILEMG    148
          IU=0                                                          FILEMG    149
      ELSE                                                              FILEMG    150
          GOTO 120                                                      FILEMG    151
      ENDIF                                                             FILEMG    152
      RETURN                                                            FILEMG    153
C    ............................................       :               FILEMG    154
C                                                                       FILEMG    155
C     ERROR                                                             FILEMG    156
C                                                                       FILEMG    157
 120  CONTINUE                                                          FILEMG    158
      WRITE(LOUT,'(/A/)') ' *** LOGICAL UNIT ERROR'                     FILEMG    159
      IU=-1                                                             FILEMG    160
      RETURN                                                            FILEMG    161
      END                                                               FILEMG    162
C                                                                       FILEMG    163
C                                                                       FILEMG    164
C                                                                       FILEMG    165
      SUBROUTINE FBOKEP(IU,IBACK)                                       FILEMG    166
CD                                                                      FILEMG    167
CD    TO TRACK THE USAGE OF A LOGICAL UNIT.                             FILEMG    168
CD                                                                      FILEMG    169
CD    IU    = THE LOGICAL UNIT                                          FILEMG    170
CD                                                                      FILEMG    171
CD    IBACK = 0 THE SPECIFIED UNIT IS OK TO BE USED                     FILEMG    172
CD          =-1 THE SPECIFIED UNIT HAS BEEN USED ALREADY                FILEMG    173
CD                                                                      FILEMG    174
      INCLUDE 'CNLSTA.INS'                                              FILEMG    175
      INCLUDE 'CNLUN.INS'                                               FILEMG    176
C                                                                       FILEMG    177
      IBACK=0                                                           FILEMG    178
      IF(IU.GT.100)THEN                                                 FILEMG    179
      WRITE(LOUT,1020) IU                                               FILEMG    180
      IBACK=-1                                                          FILEMG    181
      ELSEIF(IU.EQ.LIN.OR.IU.EQ.LOUT)THEN                               FILEMG    182
      WRITE(LOUT,1010) IU                                               FILEMG    183
      IBACK=-1                                                          FILEMG    184
      ELSE                                                              FILEMG    185
          IF(LUNITS(IU)) THEN                                           FILEMG    186
          WRITE(LOUT,1000) IU                                           FILEMG    187
          IBACK=-1                                                      FILEMG    188
          ENDIF                                                         FILEMG    189
      ENDIF                                                             FILEMG    190
C                                                                       FILEMG    191
      RETURN                                                            FILEMG    192
C                                                                       FILEMG    193
 1000 FORMAT(/,' *** ERROR LOGICAL UNIT NUMBER ',I2,' IS ALREADY IN USE'FILEMG    194
     1,/)                                                               FILEMG    195
 1010 FORMAT(/,' *** ERROR LOGICAL UNIT NUMBER ',I2,' IS RESERVED FOR', FILEMG    196
     1' SCREEN I/O')                                                    FILEMG    197
 1020 FORMAT(/,' *** ERROR THE LOGICAL UNIT NUMBER ',I4,' IS GREATER',  FILEMG    198
     1' THAN 100')                                                      FILEMG    199
C                                                                       FILEMG    200
      END                                                               FILEMG    201
