CFPRIME REMASS                                                          REMASS      1
C***********************************************************************RIGHTE      1
C*                                                                     *RIGHTE      2
C*               Output Analysis Program for ETMSP (OAP)               *RIGHTE      4
C*               =======================================               *RIGHTE      5
C*                                                                     *RIGHTE     11
C*        copyright @(1993) Electric Power Research Institute          *RIGHTE     12
C*                                                                     *RIGHTE     13
C* EPRI reserves all rights in the software and associated             *RIGHTE     14
C* documentation as delivered. The software and its associated         *RIGHTE     15
C* documention or any portion thereof may not be reproduced in any form*RIGHTE     16
C* whatsoever without the consent of EPRI, except as explicity provided*RIGHTE     17
C* for by license. Licensee shall submit a detailed description to EPRI*RIGHTE     18
C* of any changes or modifications to the software within two (2)      *RIGHTE     19
C* months after such changes or modifications are made. At EPRI's sole *RIGHTE     20
C* discretion, the software, as changed or modified, shall be given a  *RIGHTE     21
C* new designation sufficiently different from its then current        *RIGHTE     22
C* designation as to prevent mistake,confusion, or deception as between*RIGHTE     23
C* the current software as changed or modified.                        *RIGHTE     24
C*                                                                     *RIGHTE     25
C* A license under EPRI's rights in the software can be obtained       *RIGHTE     26
C* directly from EPRI.                                                 *RIGHTE     27
C*                                                                     *RIGHTE     28
C* This program and supporting materials may be independently available*RIGHTE     29
C* from Electric Power Software centre (EPSC) for an appropriate       *RIGHTE     30
C* distribution fee. The EPSC is a service of                          *RIGHTE     31
C*                                                                     *RIGHTE     32
C*                    Power Computing Company                          *RIGHTE     33
C*                    1930 Hi Line                                     *RIGHTE     34
C*                    Dallas, Tx 75207                                 *RIGHTE     35
C*                                                                     *RIGHTE     36
C* NEITHER EPRI, ANY MEMBER OF EPRI, NOR ANY PERSON OR  ORGANIZATION   *RIGHTE     37
C* ACTING ON BEHAVE OF THEM:                                           *RIGHTE     38
C*                                                                     *RIGHTE     39
C* 1. MAKE ANY WARRANTY OR REPRESENTATION WHATSOEVER, EXPRESS OR       *RIGHTE     40
C*    IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS OR *RIGHTE     41
C*    ANY PURPOSE WITH RESPECT TO THE SOFTWARE OR ITS ASSOCIATED       *RIGHTE     42
C*    DOCUMENTATION; OR                                                *RIGHTE     43
C*                                                                     *RIGHTE     44
C* 2. ASSUMES ANY LIABILITY WHATSOEVER WITH RESPECT TO ANY USE OF THE  *RIGHTE     45
C*    SOFTWARE OR ITS ASSOCIATED DOCUMENTATION OR ANY PORTION THEREOF  *RIGHTE     46
C*    OR WITH RESPECT TO ANY DAMAGES WHICH MAY RESULT FROM SUCH USE.   *RIGHTE     47
C*                                                                     *RIGHTE     48
C* THIS NOTICE MAY NOT BE REMOVED FROM THE SOFTWARE BY ANY USER        *RIGHTE     49
C* THEREOF.                                                            *RIGHTE     50
C*                                                                     *RIGHTE     51
C***********************************************************************RIGHTE     52
C                                                                       REMASS      3
      SUBROUTINE REMASS(X,Y,M,N ,IU8,N1,N2,LRECFD)                      REMASS      4
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCREMASS      5
CD                                                                      REMASS      6
CD         THIS ROUTINE READS PLOTTING DATA FROM CHANNEL FILE.          REMASS      7
CD         IF THE NUMBER OF DATA POINT IN THE CHANNEL FILE EXCEEDS      REMASS      8
CD         THE DIMENSION OF THE STORAGE ARRAY, TWO OPIONS CAN BE        REMASS      9
CD         CHOOSEN BY THE USERS :                                       REMASS     10
CD                                                                      REMASS     11
CD         1) (D)efault - PROGRAM WILL SKIP BETWEEN DATA POINTS         REMASS     12
CD                        IN SATISFIES THE DIMENSION RESTRICTION        REMASS     13
CD         2) (W)indow  - USER CAN CHOSE TO PLOT PORTION ON THE         REMASS     14
CD                        CURVE BY SPECIFYING THE STARTING AND          REMASS     15
CD                        ENDING TIMES. IF THE NUMBER OF POINTS         REMASS     16
CD                        WITHIN THE WINDOW STILL EXCEEDS THE           REMASS     17
CD                        DIMENSION, THE TIME SPAN SPECIFIED BY         REMASS     18
CD                        THE USER WILL BE TRUNCATED IN ORDER TO        REMASS     19
CD                        MEET THE DIMENSION RESTRICTION.               REMASS     20
CD                                                                      REMASS     21
CD                                                                      REMASS     22
CD              CALLING PARAMETERS :                                    REMASS     23
CD                                                                      REMASS     24
CD                        IU8 - Unit number to read from                REMASS     25
CD                     X(M,N) - X-axis arrry (normally time axis)       REMASS     26
CD                     Y(M,N) - Y-axis array                            REMASS     27
CD                      MAXPT - Returns with the maximum number of      REMASS     28
CD                              data point                              REMASS     29
CD              KRECFD(MCHNL) - Array with record and field pointers    REMASS     30
CD                              info for each channel requested.        REMASS     31
CD                                                                      REMASS     32
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCREMASS     33
      REAL*4 X(M,N),Y(M,N)                                              REMASS     34
      INCLUDE 'DBFLG.INS'                                               REMASS     35
C!                                                                      REMASS     36
      INCLUDE 'PARAM.INS'                                               REMASS     37
      INCLUDE 'SOAPC1.INS'                                              REMASS     38
      INCLUDE 'JJNAME.INS'                                              REMASS     39
      INCLUDE 'XYARAY.INS'                                              REMASS     40
C                                                                       REMASS     41
      COMMON /REC9/ IRECS,NREC,IREC9(128)                               REMASS     42
C!                                                                      REMASS     43
      INTEGER LRECFD(MCHNL,2)                                           REMASS     44
C      INTEGER MAXPT(N)                                                 REMASS     45
C                                                                       REMASS     46
      COMMON /RECPT/ KRSTRT, ISTNAM, IIDARY, ITYARY, IHREC,ICHAN,       REMASS     47
     *          NPFL,LRREC,IRREC,MMAX,NSTART                            REMASS     48
      COMMON /MMIN/ XMMIN(MCHNL+1),XMMAX(MCHNL+1)                       REMASS     49
      LOGICAL IEND                                                      REMASS     50
      CHARACTER*80 STRING,MSG                                           REMASS     51
      CHARACTER*2 UID                                                   REMASS     52
      REAL*4  TBUF(128)                                                 REMASS     53
      LDEBUG=DEBUG(4)                                                   REMASS     54
C   .....................................................               REMASS     55
C   : Debug show contains of record/field pointer array :               REMASS     56
C   :                                                   :               REMASS     57
      IF(LDEBUG) THEN                                                   REMASS     58
        WRITE(IDBOUT,1011)                                              REMASS     59
        DO 90 I=1,MCHNL                                                 REMASS     60
           WRITE(IDBOUT,1010) LRECFD(I,1),LRECFD(I,2)                   REMASS     61
   90   CONTINUE                                                        REMASS     62
 1010   FORMAT(1X,2I20)                                                 REMASS     63
 1011   FORMAT(1X,'+++(REMASS)+++ (1ST LINE IS NUMBER OF CHANNELS',/,   REMASS     64
     1         1X,'      PHYSICAL RECORD #       FIELD NUMBER ',/,      REMASS     65
     1         1X,'      ------------------      -------------')        REMASS     66
      ENDIF                                                             REMASS     67
C    :...................................................:              REMASS     68
C   ....................................................................REMASS     69
C   : Initialize pointers before starting                               REMASS     70
C   : Point next record pointer NREC to absolute start of data KRSTRT   REMASS     71
      NSTART=KRSTRT                                                     REMASS     72
      NREC=KRSTRT                                                       REMASS     73
C   : Initialize Maximum number of points MM                            REMASS     74
      MM=0                                                              REMASS     75
C   : Initialize pointer to beginning of a time step. The first one beinREMASS     76
C   : the absolute start of time step data                              REMASS     77
      IBEGIN=KRSTRT                                                     REMASS     78
      TOLD=0.0                                                          REMASS     79
C   :...................................................................REMASS     80
C     : READ RECORD 1 FOR TIME STEP          :                          REMASS     81
 15     MM=MM+1                                                         REMASS     82
        CALL DAFLWR(IU8,1,NREC,TBUF,128,IEND)                           REMASS     83
        NOWREC=NREC                                                     REMASS     84
        IF(TBUF(2).GT.99999)THEN                                        REMASS     85
            MM=MM-1                                                     REMASS     86
        ELSEIF(TOLD.GT.TBUF(2))THEN                                     REMASS     87
            MM=MM-1                                                     REMASS     88
        ELSE                                                            REMASS     89
         TOLD=TBUF(2)                                                   REMASS     90
         IBEGIN=IBEGIN+IRECS                                            REMASS     91
         NREC=IBEGIN                                                    REMASS     92
         IF(.NOT.IEND) GOTO 15                                          REMASS     93
        ENDIF                                                           REMASS     94
        MMAX=MM                                                         REMASS     95
        MSKIP=1                                                         REMASS     96
        MMSRT=9999                                                      REMASS     97
C                                                                       REMASS     98
        IF (MM.GT.M)THEN                                                REMASS     99
   25    WRITE(LOUT,1030)MM,M                                           REMASS    100
 1030    FORMAT(/,10X,'TOO MANY DATA PONITS IN THE CHANNEL FILE' ,/,    REMASS    101
     &   10X,'NO. OF POINT READ IN =',I5,'  NO. OF POINT ALLOWED =',    REMASS    102
     &   I5,/,10X,'TO PLOT THE CURVE PLEASE ENTER'//,                   REMASS    103
     &   10X,' (D)efault - PLOT THE WHOLE CURVE BUT SKIP SOME PLOT ',   REMASS    104
     &   /,23X, 'POINTS IN BETWEEN',//,                                 REMASS    105
     &   10X,' (W)indow  - PLOT PORTION OF THE CURVE WITH USER ',/,     REMASS    106
     &   23X,'SPECIFIED STARTING AND ENDING TIMES',//)                  REMASS    107
         MSG='Enter option   (D)efault  or  (W)indow '                  REMASS    108
         CALL PMTRED(LOUT,LIN,JERR,39,MSG,'XXX',STRING)                 REMASS    109
         IF(RECORD) WRITE(IREC,9000) STRING                             REMASS    110
         IF(STRING(1:1).NE.'D'.AND.STRING(1:1).NE.'d'.AND.              REMASS    111
     &      STRING(1:1).NE.'W'.AND.STRING(1:1).NE.'w')GOTO 25           REMASS    112
         IF(STRING(1:1).EQ.'D' .OR. STRING(1:1).EQ.'d')THEN             REMASS    113
           NSTART=KRSTRT                                                REMASS    114
           FACT=FLOAT(MM)/FLOAT(M)                                      REMASS    115
           IF(FACT.LT.1.4)THEN                                          REMASS    116
             MMSRT=2*(M-2)-MM                                           REMASS    117
             MSKIP=1                                                    REMASS    118
             MMAX=MMSRT+(MM-2-MMSRT)/2                                  REMASS    119
           ELSE                                                         REMASS    120
             MMSRT=9999                                                 REMASS    121
             MSKIP=INT(FACT)+1                                          REMASS    122
             MMAX=MM/MSKIP                                              REMASS    123
           ENDIF                                                        REMASS    124
         ELSE                                                           REMASS    125
           MMSRT=9999                                                   REMASS    126
           MSKIP=1                                                      REMASS    127
           MMAX=MM                                                      REMASS    128
         ENDIF                                                          REMASS    129
         IF(STRING(1:1).EQ.'W' .OR. STRING(1:1).EQ.'w')THEN             REMASS    130
          MSG='Enter START and END time values.'                        REMASS    131
          CALL PMTRED(LOUT,LIN,JERR,ISLEN(MSG),MSG,'XXX',STRING)        REMASS    132
          IF(RECORD) WRITE(IREC,9000) STRING                            REMASS    133
 9000     FORMAT(A80)                                                   REMASS    134
          READ(STRING,*,IOSTAT=IOS) XSTART,XEND                         REMASS    135
          NREC=KRSTRT                                                   REMASS    136
          IBEGIN=KRSTRT                                                 REMASS    137
          MMST=1                                                        REMASS    138
          NSTART=KRSTRT                                                 REMASS    139
          IF(XSTART.GT.0.0)THEN                                         REMASS    140
           MM=0                                                         REMASS    141
 35        MM=MM+1                                                      REMASS    142
           CALL DAFLWR(IU8,1,NREC,TBUF,128,IEND)                        REMASS    143
           NOWREC=NREC                                                  REMASS    144
           IF(TBUF(2).GE.XSTART)THEN                                    REMASS    145
            MMST=MM-1                                                   REMASS    146
            NSTART=IBEGIN                                               REMASS    147
            GOTO 45                                                     REMASS    148
           ENDIF                                                        REMASS    149
           IF(.NOT.IEND) THEN                                           REMASS    150
             IBEGIN=IBEGIN+IRECS                                        REMASS    151
             NREC=IBEGIN                                                REMASS    152
             GOTO 35                                                    REMASS    153
           ENDIF                                                        REMASS    154
 45        CONTINUE                                                     REMASS    155
C           KRSTRT=NSTART                                               REMASS    156
        ENDIF                                                           REMASS    157
C                                                                       REMASS    158
           NREC=KRSTRT                                                  REMASS    159
           IBEGIN=KRSTRT                                                REMASS    160
           MM=0                                                         REMASS    161
 55        MM=MM+1                                                      REMASS    162
           CALL DAFLWR(IU8,1,NREC,TBUF,128,IEND)                        REMASS    163
           NOWREC=NREC                                                  REMASS    164
           IF(TBUF(2).GE.XEND.OR.TBUF(2).GT.99999.)THEN                 REMASS    165
            MMED=MM-1                                                   REMASS    166
            NEND=IBEGIN                                                 REMASS    167
            GOTO 65                                                     REMASS    168
           ENDIF                                                        REMASS    169
           IF(.NOT.IEND) THEN                                           REMASS    170
             IBEGIN=IBEGIN+IRECS                                        REMASS    171
             NREC=IBEGIN                                                REMASS    172
             GOTO 55                                                    REMASS    173
           ENDIF                                                        REMASS    174
 65        CONTINUE                                                     REMASS    175
                                                                        REMASS    176
         MMAX=MMED-MMST                                                 REMASS    177
         IF(MMAX.GT.M)THEN                                              REMASS    178
          MMAX=MIN(MMAX,M-1)                                            REMASS    179
          WRITE(LOUT,1550)                                              REMASS    180
 1550     FORMAT(' WARNING : THE NO. OF POINT WITHIN THE SPECIFIED ',   REMASS    181
     &        /, '           RANGE STILL EXCEEDS THE ALLOWED LIMIT ',   REMASS    182
     &        /, '           THE TIME RANGE IS FURTHER SHORTENED BY',   REMASS    183
     &        /, '           THE PROGRAM IN ORDER TO PLOT THE CURVE.')  REMASS    184
         ENDIF                                                          REMASS    185
       ENDIF                                                            REMASS    186
      ENDIF                                                             REMASS    187
C                                                                       REMASS    188
 75   NREC=NSTART                                                       REMASS    189
      IBEGIN=NSTART                                                     REMASS    190
C                                                                       REMASS    191
       DO 85 MM=1,MMAX                                                  REMASS    192
C                                                                       REMASS    193
        CALL DAFLWR(IU8,1,NREC,TBUF,128,IEND)                           REMASS    194
        NOWREC=NREC                                                     REMASS    195
C     :.......................................:                         REMASS    196
C                                                                       REMASS    197
C     ........................................................          REMASS    198
C     : Start filling in the Y-array one row at a time (I)   :          REMASS    199
C     : LRECFD(1,1) contains the number of channel requested :          REMASS    200
C     : Index (I) - Y-arrray column number                   :          REMASS    201
C     : Index (II) - LRECFD index array. Column 1 = record#; :          REMASS    202
C     :                                  Column 2 = field#   :          REMASS    203
        II=N1                                                           REMASS    204
           X(MM,1)=TBUF(2)                                              REMASS    205
        DO 110 I=N1,N2                                                  REMASS    206
           X(MM,I)=X(MM,1)                                              REMASS    207
           II=II+1                                                      REMASS    208
           CALL UNPACK(UID,NTYPE,ITY(1,KCH(II)))                        REMASS    209
           IF(LRECFD(II,1).NE.(NOWREC-IBEGIN)) THEN                     REMASS    210
              NREC=IBEGIN+LRECFD(II,1)-1                                REMASS    211
              CALL DAFLWR(IU8,1,NREC,TBUF,128,IEND)                     REMASS    212
              NOWREC=NREC                                               REMASS    213
           ENDIF                                                        REMASS    214
           IF(NTYPE.EQ.2.OR.NTYPE.EQ.3.OR.NTYPE.EQ.23.OR.NTYPE.EQ.24.OR.REMASS    215
     *        NTYPE.EQ.36.OR.NTYPE.EQ.37.OR.NTYPE.EQ.33.OR.             REMASS    216
     *        NTYPE.EQ.34.OR.NTYPE.EQ.42.OR.NTYPE.EQ.43.OR.             REMASS    217
     *        NTYPE.EQ.6)THEN                                           REMASS    218
              Y(MM,I)=TBUF(LRECFD(II,2))*BASPC                          REMASS    219
           ELSEIF(NTYPE.EQ.5)THEN                                       REMASS    220
              Y(MM,I)=(1.0+TBUF(LRECFD(II,2)))*FQBASE                   REMASS    221
           ELSEIF(NTYPE.EQ.25)THEN                                      REMASS    222
              Y(MM,I)=(1.0-TBUF(LRECFD(II,2)))*FQBASE                   REMASS    223
           ELSE                                                         REMASS    224
              Y(MM,I)=TBUF(LRECFD(II,2))                                REMASS    225
           ENDIF                                                        REMASS    226
                                                                        REMASS    227
           IF(RELATE)THEN                                               REMASS    228
             CALL UNPACK(UID,NTYPE,ITY(1,KCH(II)))                      REMASS    229
             IF(NTYPE.EQ.4)THEN                                         REMASS    230
               CALL RECFLD(IREF,KRECRD,KFIELD)                          REMASS    231
               KRECRD=(NREC-1)+KRECRD-KRECFD(II,1)                      REMASS    232
               CALL DAFLWR(IU8,1,KRECRD,TBUF,128,IEND)                  REMASS    233
               Y(MM,I)=Y(MM,I)-TBUF(KFIELD)                             REMASS    234
             ENDIF                                                      REMASS    235
           ENDIF                                                        REMASS    236
                                                                        REMASS    237
 110    CONTINUE                                                        REMASS    238
C      :........................................................:       REMASS    239
        IF(IEND) GOTO 940                                               REMASS    240
        IF(MM.GT.MMSRT)THEN                                             REMASS    241
          IX=2                                                          REMASS    242
        ELSE                                                            REMASS    243
          IX=MSKIP                                                      REMASS    244
        ENDIF                                                           REMASS    245
        IBEGIN=IBEGIN+IRECS*IX                                          REMASS    246
        NREC=IBEGIN                                                     REMASS    247
85    CONTINUE                                                          REMASS    248
C   :                                                                   REMASS    249
C   :...................................................................REMASS    250
C                                                                       REMASS    251
 940  CONTINUE                                                          REMASS    252
      DO 115 I=N1,N2                                                    REMASS    253
        MAXPT(I)=MMAX                                                   REMASS    254
  115 CONTINUE                                                          REMASS    255
C   ........................................................            REMASS    256
C   : Debug write                                          :            REMASS    257
C   :                                                      :            REMASS    258
      IF(LDEBUG) THEN                                                   REMASS    259
        WRITE(IDBOUT,1300)MM                                            REMASS    260
        DO 120 I=1,MM                                                   REMASS    261
          WRITE(IDBOUT,1200) (X(I,II),Y(I,II),II=N1,N2)                 REMASS    262
 1200     FORMAT(1X,12F10.5)                                            REMASS    263
 120    CONTINUE                                                        REMASS    264
 1300   FORMAT(1X,'+++(REMASS)++ NUMBER OF DATA POINTS :',I6)           REMASS    265
      ENDIF                                                             REMASS    266
C   :.......................................................:           REMASS    267
                                                                        REMASS    268
      RETURN                                                            REMASS    269
      END                                                               REMASS    270
