PSSE user model compiling error - fortran

I have just started to learn PSSE model writing. As a starting point, I tried to compile PSSE example givem in Programe Operation Manuel page 21-16 and got the following errors. I use the Env. Manager and it seems that all paths and libs for Microsoft visual studio 2010 and Intel visual fortran 15.0 are set properly. I also set the PATH to PSSBIN folder and LIB to PSSLIB. Can anyone please suggest me where I'm going wrong?
The model code:
SUBROUTINE DEMOEX(I,ISLOT)
C
INCLUDE 'COMON4.INS'
C
INTEGER I,ISLOT
C
C I = MACHINE ARRAY INDEX
C ISLOT = ARRAY ALLOCATION TABLE INDEX
C J = STRTIN(1,ISLOT) [ USES CON(J) THROUGH CON(J+2) ]
C K = STRTIN(2,ISLOT) [ USES STATE(K) AND STATE(K+1) ]
C
INTRINSIC MAX, ABS
EXTERNAL BADMID, DOCUHD
C
INTEGER IB, J, K, IBUS, JJ
REAL VERROR
LOGICAL NEW
CHARACTER IM*2
C
IF (MODE.EQ.8)
. CON_DSCRPT(1)='Tr'
. CON_DSCRPT(2)='K'
. CON_DSCRPT(3)='Te'
. RETURN
...FIN
C
C GET STARTING 'CON' AND 'STATE' INDICES
C
J=STRTIN(1,ISLOT)
K=STRTIN(2,ISLOT)
C
IF (MODE .GT. 4) GO TO 1000
C
C BUS SEQUENCE NUMBER NEGATIVE IF MACHINE
C IS OFF-LINE, SVS OR INDUCTION MACHINE
C
IB=NUMTRM(I)
IF (IB.LE.0) RETURN
C
IF (MIDTRM) GO TO 900
GO TO (100,200,300,400), MODE
C
C MODE = 1 - INITIALIZE
C
100 STATE(K)=ECOMP(I)
STATE(K+1)=EFD(I)
VREF(I)=ECOMP(I) + EFD(I)/CON(J+1)
IF (EFD(I).LT.0.) WRITE(LPDEV,307) NUMBUS(IB),MACHID(I)
RETURN
C
C MODE = 2 - CALCULATE DERIVATIVES
C
200 DSTATE(K)=(ECOMP(I)-STATE(K))/CON(J)
VERROR=VREF(I)+VOTHSG(I)-STATE(K)
DSTATE(K+1)=(CON(J+1)*VERROR-STATE(K+1))/CON(J+2)
RETURN
C
C MODE = 3 - SET EFD
C
300 EFD(I)=MAX(STATE(K+1),0.)
RETURN
C
C MODE = 4 - SET NINTEG
C
400 NINTEG=MAX(NINTEG,K+1)
RETURN
C
C MODE > 4
C
1000 IM=MACHID(I)
IB=ABS(NUMTRM(I))
IBUS=NUMBUS(IB)
C
IF (MODE.EQ.6) GO TO 2000
C
TO PRINT-HEADING
C .
. UNLESS (NEW)
. . NEW=.TRUE.
. . CALL DOCUHD(*1900)
. . WRITE(IPRT,97) IBUS,IM
. ...FIN
C .
...FIN
END
2000 END
The error messages:
ifort /nologo /assume:buffered_io /traceback /libs:dll /threads /c /Qip /extend_source:132 /noaltparam
/fpscomp:logicals /Qprec /warn:nodeclarations /warn:unused /warn:truncated_source /Qauto /fp:source /iface:cvf
/define:DLLI /include:"C:\Program Files (x86)\PTI\PSSE33\PSSLIB" /object:"D:\IVF15test\DEMOEX.obj"
/module:"D:\IVF15test" "D:\IVF15test\DEMOEX.f"
D:\IVF15test\DEMOEX.f(10): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: BLOCK
PROGRAM BLOCKDATA MODULE INTEGER REAL COMPLEX TYPE BYTE CHARACTER CLASS ...
IF (MODE.EQ.8)
------------------------^
D:\IVF15test\DEMOEX.f(11): error #5082: Syntax error, found '.' when expecting one of: <LABEL>
<END-OF-STATEMENT> ; BLOCK PROGRAM BLOCKDATA MODULE INTEGER REAL COMPLEX ...
. CON_DSCRPT(1)='Tr'
----------^
D:\IVF15test\DEMOEX.f(12): error #5082: Syntax error, found '.' when expecting one of: <LABEL>
<END-OF-STATEMENT> ; BLOCK PROGRAM BLOCKDATA MODULE INTEGER REAL COMPLEX ...
. CON_DSCRPT(2)='K'
----------^
D:\IVF15test\DEMOEX.f(13): error #5082: Syntax error, found '.' when expecting one of: <LABEL>
<END-OF-STATEMENT> ; BLOCK PROGRAM BLOCKDATA MODULE INTEGER REAL COMPLEX ...
. CON_DSCRPT(3)='Te'
----------^
D:\IVF15test\DEMOEX.f(14): error #5082: Syntax error, found '.' when expecting one of: <LABEL>
<END-OF-STATEMENT> ; BLOCK PROGRAM BLOCKDATA MODULE INTEGER REAL COMPLEX ...
. RETURN
----------^
D:\IVF15test\DEMOEX.f(15): error #5082: Syntax error, found '.' when expecting one of: <LABEL>
<END-OF-STATEMENT> ; BLOCK PROGRAM BLOCKDATA MODULE INTEGER REAL COMPLEX ...
...FIN
----------^
D:\IVF15test\DEMOEX.f(18): error #5149: Illegal character in statement label field [I]
IF (MODE .GT. 4) GO TO 1000
^
D:\IVF15test\DEMOEX.f(18): error #5149: Illegal character in statement label field [F]
IF (MODE .GT. 4) GO TO 1000
-^
D:\IVF15test\DEMOEX.f(18): error #5149: Illegal character in statement label field [(]
IF (MODE .GT. 4) GO TO 1000
---^
D:\IVF15test\DEMOEX.f(18): error #5149: Illegal character in statement label field [M]
IF (MODE .GT. 4) GO TO 1000
----^
D:\IVF15test\DEMOEX.f(18): error #5276: Unbalanced parentheses
IF (MODE .GT. 4) GO TO 1000
---------------^
D:\IVF15test\DEMOEX.f(15): catastrophic error: Could not recover from previous syntax error
compilation aborted for D:\IVF15test\DEMOEX.f (code 1)

it's better to write code using fortran... but, you didn't finished flex code from pom.pdf section 21.9... I finished code in flex language, and you can compile that now without errors, but with warnings (some declared variables code didn't use etc.), I'm not sure that it will be work correct in psse environment...
C
C[UEXC] 05/23/02 EXAMPLE USER EXCITATION SYSTEM MODEL
C
C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C * *
C * THIS PROGRAM AND ITS DOCUMENTATION ARE TRADE SECRETS OF POWER TECHNO- *
C * LOGIES, A DIVISION OF S&W CONSULTANTS, INC. THEY HAVE BEEN LEASED TO *
C * YOU, OUR CLIENT, *
C * SUBJECT TO TERMS WHICH PROHIBIT YOU FROM DISCLOSING OR TRANSFERRING *
C * THE PROGRAM OR ITS DOCUMENTATION, WHETHER IN ITS ORIGINAL OR MODIFIED *
C * FORM, TO A THIRD PARTY, OR FROM USING THE PROGRAM FOR ANY PURPOSE *
C * OTHER THAN COMPUTATION RELATING TO YOUR OWN SYSTEM. ANY SUCH *
C * TRANSFER OR USE BY YOU OR YOUR EMPLOYEES WILL CONSTITUTE A BREACH OF *
C * CONFIDENCE AND OF THE CONTRACT UNDER WHICH RIGHTS OF USE HAVE BEEN *
C * GRANTED. *
C * *
C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
SUBROUTINE UEXC(IARG,ISLOT)
C
C THIS IS A SIMPLIFIED EXAMPLE EXCITATION SYSTEM MODEL
C
C SUBROUTINE UEXC
C IARG = MACHINE ARRAY INDEX
C ISLOT = ARRAY ALLOCATION TABLE INDEX
C J = STRTIN(1,ISLOT) [ USES CON(J) THROUGH CON(J+8) ]
C K = STRTIN(2,ISLOT) [ USES STATE(K) AND STATE(K+3) ]
C
C USE DYNAMICS, ONLY: NUMTRM, STRTIN,
C * EFD,
C * ECOMP, VOTHSG, VREF,
C * VUEL, VOEL,
C * CON, VAR,
C * STORMT, STATE, DSTATE, STORE
C USE PSSCM4, ONLY: NUMBUS, BASVLT,
C * BUSNAM,
C * MACHID
C
C$INCLUDE PERM4.INS
C$INCLUDE DSCOM4.INS
$INSERT COMON4.INS
C
INTEGER IARG, ISLOT
C
C INTRINSIC MAX
EXTERNAL BADMID
C
INTEGER I, J, K, JJ, KK,
* IB, IBUS, IBPTR
REAL VERROR, VR, DEL2, FDBK, SS, R_TF_KF
LOGICAL HIGH, LOW, NEW
CHARACTER CB1*6, CB2*6
CHARACTER IM*2, VLTI*4
C
IF (MODE.EQ.8) GO TO 1500 ! GET DATA DESCRIPTIONS
I=IARG ! MACHINE ARRAY INDEX
J=STRTIN(1,ISLOT) ! STARTING 'CON'
K=STRTIN(2,ISLOT) ! STARTING 'STATE'
C
IF (MODE.GT.4) GO TO 1000
C
IB=NUMTRM(I) ! RETURN IF OFF-LINE
IF (IB.LE.0) RETURN ! OR SVS OR INDUCTION MACHINE
$1
C
C MODEL NOT IMPLEMENTED FOR MSTR/MRUN
C
IF (MIDTRM)
. CALL BADMID(I,IB,'UEXC')
. RETURN
...FIN
C
C MODE 2 - CALCULATE DERIVATIVES
IF (MODE.EQ.2) ! CALCULATE DERIVATIVES
C .
. WHEN (MIDTRM) ! MODE 2 Z-FORM
C . the midterm simulation mode is not implemented
C . .
C . .
. ...FIN
$1
. ELSE ! STATE SPACE
C . MODE 2 code portion is inserted here
C .
. . HIGH=STATE(K+1).GE.CON(J+3)
C .
. . WHEN (HIGH)
. . . STATE(K+1)=CON(J+3)
. . . STORE(K+1)=CON(J+3)
. . ...FIN
. . ELSE
. . . LOW=STATE(K+1).LE.CON(J+4)
C . . .
. . . IF (LOW)
. . . . STATE(K+1)=CON(J+4)
. . . . STORE(K+1)=CON(J+4)
. . . ...FIN
C . . .
. . ...FIN
C . .
C . . HANDLING SMALL TIME CONSTANTS
. . DEL2=2.*DELT
C . .
. . WHEN (CON(J).LE.DEL2)
. . . STORE(K)=ECOMP(I)
. . . STATE(K)=ECOMP(I)
. . ...FIN
. . ELSE DSTATE(K)=(ECOMP(I)-STATE(K))/CON(J)
C . .
. . DSTATE(K+2)=(STATE(K+1)/CON(J+5)-STATE(K+2))*CON(J+5)/CON(J+6)
C . .
. . FDBK=STATE(K+2)*CON(J+7)/CON(J+8)-STATE(K+3) ! FEEDBACK BLOCK OUTPUT
. . DSTATE(K+3)=FDBK/CON(J+8)
C . .
C . . TEMPORARY VARIABLE SS
. . SS=(VREF(I)+VOTHSG(I)-STATE(K)-FDBK)*CON(J+1)
C . .
. . WHEN (CON(J+2).LE.DEL2)
. . . STORE(K+1)=SS
. . . STATE(K+1)=SS
. . ...FIN
. . ELSE
. . . DSTATE(K+1)=(SS-STATE(K+1))/CON(J+2)
C . . .
. . . CONDITIONAL
. . . . (HIGH) IF (DSTATE(K+1).GT.0.) DSTATE(K+1)=0.
. . . . (LOW) IF (DSTATE(K+1).LT.0.) DSTATE(K+1)=0.
. . . ...FIN
C . . .
. . ...FIN
C . .
. ...FIN
C .
. RETURN
...FIN
$1
C MODE 3 - SET EFD
IF (MODE.EQ.3)
C .
. WHEN (MIDTRM) ! RESET STORES FOR CHANGE
C . the midterm simulation mode is not implemented
C . . ! IN DELT (MIDTERM)
C . .
. ...FIN
. ELSE EFD(I)=STATE(K+2) ! STATE SPACE
C . MODE 3 code portion is inserted here
C .
. RETURN
...FIN
$1
C MODE 1 - INITIALIZATION
IF (MODE.EQ.1) ! INITIALIZE
. WHEN (MIDTRM)
C . the midterm simulation mode is not implemented
C . .
C . .
. ...FIN
. ELSE
C . MODE 1 code portion is inserted here
C . . TEMPORARY VARIABLE SS
. . SS=CON(J+5)*EFD(I)
. . VREF(I)=ECOMP(I)+SS/CON(J+1)
C . .
. . IF (SS.GE.CON(J+3) .OR. SS.LE.CON(J+4))
. . . WRITE(LPDEV,307) NUMBUS(IB),MACHID(I)
. . ...FIN
C . .
. . STATE(K)=ECOMP(I)
. . STATE(K+1)=SS
. . STATE(K+2)=EFD(I)
. . STATE(K+3)=EFD(I)*CON(J+7)/CON(J+8)
. ...FIN
C .
. RETURN
...FIN
C
C MODE 4 -SET NINTEG
C MODE 4 code portion is inserted here
IF (K+3.GT.NINTEG) NINTEG=K+3
RETURN
$1
C MODE > 4
C
1000 IM=MACHID(I)
IB=ABS(NUMTRM(I))
IBUS=NUMBUS(IB)
C
IF (MODE.EQ.6) GO TO 2000
C
C MODE 5 OR 7 - ACTIVITY DOCU
C
IF (MODE.EQ.5)
. CALL DOCUHD(*1900)
. GO TO 1100
...FIN
C
$1
C DATA CHECKING CODE
C
C code portion # 1 for DOCU checking mode is inserted here
NEW=.FALSE.
DEL2=2.*DELT
C
UNLESS (CON(J).GT.0. .AND. CON(J).LE.5.0) ! TR
. PRINT-HEADING
. WRITE(IPRT,107) CON(J)
...FIN
C
UNLESS (CON(J+1).GE.10. .AND. CON(J+1).LE.500.0) ! KA
. PRINT-HEADING
. WRITE(IPRT,108) CON(J+1)
...FIN
C
UNLESS (CON(J+2).GT.0. .AND. CON(J+2).LE.1.0) ! TA
. PRINT-HEADING
. WRITE(IPRT,109) CON(J+2)
...FIN
C
UNLESS (CON(J+3).GE.0.5 .AND. CON(J+3).LE.10.0) ! VRMAX
. PRINT-HEADING
. WRITE(IPRT,110) CON(J+3)
...FIN
C
UNLESS (CON(J+4).GE.-10.0 .AND. CON(J+4).LE.0.) ! VRMIN
. PRINT-HEADING
. WRITE(IPRT,111) CON(J+4)
...FIN
C
UNLESS (CON(J+5).GE.-1.0 .AND. CON(J+5).LE.1.0) ! KE
. PRINT-HEADING
. WRITE(IPRT,112) CON(J+5)
...FIN
C
UNLESS (CON(J+6).GT.DEL2 .AND. CON(J+6).LE.1.0) ! TE
. PRINT-HEADING
. WRITE(IPRT,113) CON(J+6)
...FIN
C
UNLESS (CON(J+7).GE.0. .AND. CON(J+7).LE.0.3) ! KF
. PRINT-HEADING
. WRITE(IPRT,114) CON(J+7)
...FIN
C
UNLESS (CON(J+8).GT.DEL2 .AND. CON(J+8).LE.1.5) ! TF
. PRINT-HEADING
. WRITE(IPRT,115) CON(J+8)
...FIN
C
R_TF_KF=CON(J+8)/CON(J+7)
UNLESS (R_TF_KF.GE.5.0 .AND. R_TF_KF.LE.15.0) ! RATIO TF/KF
. PRINT-HEADING
. WRITE(IPRT,116) R_TF_KF
...FIN
C
C (DATA CHECKING PERFORMED FOR ALL CONS)
C
UNLESS (NEW) RETURN
C
C DATA TABULATION CODE
C
1100 JJ=J+8
KK=K+3
C
CALL VLTFOR(VLTI,BASVLT(IB))
IBPTR = 0
CALL ADINTN (JJ,CB1,IBPTR)
IBPTR = 0
CALL ADINTN (KK,CB2,IBPTR)
WRITE(IPRT,17) IBUS,BUSNAM(IB),VLTI,IM,J,CB1,K,CB2
WRITE(IPRT,27) (CON(K),K=J,JJ)
C
1900 RETURN
C
C MODE 6 - ACTIVITY DYDA
C
2000 WRITE(IPRT,507) IBUS,IM,(CON(K),K=J,J+8)
RETURN
$1
C MODE 8 - ASSIGN DESCRIPTIONS FOR DATA EDITOR
C
C MODE 8 code portion is inserted here
1500 CON_DSCRPT(1) ='TR'
CON_DSCRPT(2) ='KA'
CON_DSCRPT(3) ='TA'
CON_DSCRPT(4) ='VRMAX'
CON_DSCRPT(5) ='VRMIN'
CON_DSCRPT(6) ='KE'
CON_DSCRPT(7) ='TE'
CON_DSCRPT(8) ='KF'
CON_DSCRPT(9) ='TF'
RETURN
$1
C
C a code portion for DOCU report is inserted here
17 FORMAT(//6X,'** UEXC',' ** BUS NAME BSKV MACH',
* ' C O N S S T A T E S'/,
* I23,1X,A8,1X,A4,2X,A2,1X,2(I7,'-',A6))
27 FORMAT(/5X,'TR KA TA VRMAX VRMIN KE TE',
* ' KF TF'/
* 3X,F5.3,F8.2,2F7.3,2F8.3,3F7.3)
97 FORMAT(//' BUS',I7,' MACHINE ',A,':')
C
C code portion # 2 for DOCU checking mode (messages) is inserted here
C DOCU CHECKING MESSAGES
107 FORMAT(' TR=',F15.4)
108 FORMAT(' KA=',F15.4)
109 FORMAT(' TA=',F15.4)
110 FORMAT(' VRMAX=',F15.4)
111 FORMAT(' VRMIN=',F15.4)
112 FORMAT(' KE=',F15.4)
113 FORMAT(' TE=',F15.4)
114 FORMAT(' KF=',F15.4)
115 FORMAT(' TF=',F15.4)
116 FORMAT(' RATIO TF/KF=',F15.4)
C
307 FORMAT(' UEXC AT BUS',I7,' MACHINE ',A,
* ' INITIALIZED OUT OF LIMITS')
C a code portion for DYDA record is inserted here
507 FORMAT(I6,' ''USRMDL''',2X,A2,' ''UEXC''',1X,4G13.5,/7X,5G13.5,'/')
$1
TO PRINT-HEADING
C .
. UNLESS (NEW)
. . NEW=.TRUE.
. . CALL DOCUHD(*1900)
. . WRITE(IPRT,97) IBUS,IM
. ...FIN
C .
...FIN
C
END
(FLECS Version 22.60 - PTI)
----------------------------------------

This is not Fotran Code but Flex Code. You have to translate this code to Fortran.

Related

C++ Fill a 2D vector with alternate values

I have a 2D vector vector of characters grid[j][i] filled with various letters, I would like to create another 2D vector of characters twice the size of grid[j][i] filled alternately with points '.'(or spaces ' ') and grid[j][i] values.
For example :
grid new 2D vector
a b c d a . b . c . d
e f g h . . . . . . .
i j k l e . f . g . h
. . . . . . .
i . j . k . l
Does anyone have an idea of how to implement this in C++ using vectors ?
Thanks in advance for any help you could provide.
Easy right? If the row or column number is a multiple of 2 (1 based counting) then you want a . or ' ' inserted.
Here is some psuedo code:
for each row
if (row+1 mod 2)
add a row of .
else
for each column
if (col+1 mod 2)
add .
add grid[row][col]
and you are done!

Array reference in Stata?

I need a Stata code similar to this SAS code:
i=1;
do while (i <= 6);
A=B(C(i));
i=i+1;
end;
Both B and C are arrays as
B_1, B_2, B_3, B_4, B_5 and B_6
C_1, C_2, C_3, C_4, C_5 and C_6
For example, if i = 1, then C(i) = C_1.
For row 3, if C_1 = 5, then I want to set A to B_5.
my problem is with accessing the array entry B(C(i)). How can I write this access in Stata?
There isn't a one-to-one equivalent. See
FAQ . . . . . . . . . . . . . . . . Implementing SAS-like ARRAYs in Stata
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W. Gould
2/03 How do I implement SAS-like ARRAYs in Stata?
Here is a link.
This is a little clumsy, but (insofar as I understand the question) it does what you are asking for:
clear all
forvalues i = 1/6 {
scalar c_`i' = 7-`i'
}
forvalues i = 1/6 {
scalar b_`i' = ceil(100/`i')
}
// test method
forvalues i = 1/6 {
scalar a = b_`=c_`i''
di a
}
scalar list
Note that as you've written the question, a is overwritten each time, so presumably there are commands following "a = b(c(i))". The Stata syntax '=...' (with a proper opening single quote) evaluates the scalar c_'i' and inserts the resulting value in the name for b_?, which a is then set equal to.

Regex Replace on IBMi

I am looking for a way to use Regex Replace functions on IBM iseries.
As far as i know, i can use C++ librairies (regex.h) (source)
With this, i can only match regex, but not replace.
(using regcomp() to compile and regexec() to match the regex)
Does anyone know a way to do it ?
It's true that the C/C++ POSIX regular expression library doesn't have a built in regexp replace function, but you can accomplish the same thing using positional information from regexec() and the RPGLE %replace() built in function. (I'm assuming you're going to use RPGLE but you could use another language.)
For example, if you wanted to mask all but the last four digits of a phone number you could do this:
/include qcpysrc,regex_h
d regex_phone_number...
d ds inz likeds(regex_t)
d dsrm ds inz likeds(regmatch_t) dim(20)
d data s 52a inz varying
d pattern s 256a inz varying
d rc s 10i 0 inz(0)
/FREE
*inlr = *on ;
data = 'My phone #''s are: (444) 555 - 6666 and 777.888.9999' ;
dsply data ;
pattern = '\(?([0-9]{3})[ .)]*([0-9]{3})[ .-]*([0-9]{4})' ;
rc = regcomp(regex_phone_number :pattern :REG_EXTENDED) ;
if rc = 0 ;
dow '1' ;
rc = regexec(regex_phone_number :data
:regex_phone_number.re_nsub :%addr(dsrm) :0) ;
if rc <> 0 ;
leave ;
endif ;
data = %replace('***': data :dsrm(2).rm_so+1
:dsrm(2).rm_eo - dsrm(2).rm_so) ;
data = %replace('***': data :dsrm(3).rm_so+1
:dsrm(3).rm_eo - dsrm(3).rm_so) ;
enddo ;
endif ;
dsply data ;
regfree(regex_phone_number) ;
/END-FREE
Here's what the copy book regex_h looks like:
** Header file for calling the "Regular Expression" functions
** provided by the ILE C Runtime Library from an RPG IV
** program. Scott Klement, 2001-05-04
** Converted to qualified DS 2003-11-29
** Modified by Jarrett Gilliam 2014-11-05
**
** This copy book is for using the C regular expression library, regex.h, in RPG.
** You can go to http://www.regular-expressions.info/ to learn more about
** regular expressions. This regex flavor is POSIX ERE. You can go to
** http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rtref/regexec.htm
** to learn more about how the C functions work.
d/if defined(REGEX_H)
d/eof
d/endif
d/define REGEX_H
**------------------------------------------------------------
* cflags for regcomp()
**------------------------------------------------------------
d REG_BASIC c CONST(0)
d REG_EXTENDED c CONST(1)
d REG_ICASE c CONST(2)
d REG_NEWLINE c CONST(4)
d REG_NOSUB c CONST(8)
**------------------------------------------------------------
* eflags for regexec()
**------------------------------------------------------------
d REG_NOTBOL c CONST(256)
d REG_NOTEOL c CONST(512)
**------------------------------------------------------------
* errors returned
**------------------------------------------------------------
* RE pattern not found
d REG_NOMATCH c CONST(1)
* Invalid Regular Expression
d REG_BADPAT c CONST(2)
* Invalid collating element
d REG_ECOLLATE c CONST(3)
* Invalid character class
d REG_ECTYPE c CONST(4)
* Last character is \
d REG_EESCAPE c CONST(5)
* Invalid number in \digit
d REG_ESUBREG c CONST(6)
* imbalance
d REG_EBRACK c CONST(7)
* \( \) or () imbalance
d REG_EPAREN c CONST(8)
* \{ \} or { } imbalance
d REG_EBRACE c CONST(9)
* Invalid \{ \} range exp
d REG_BADBR c CONST(10)
* Invalid range exp endpoint
d REG_ERANGE c CONST(11)
* Out of memory
d REG_ESPACE c CONST(12)
* ?*+ not preceded by valid RE
d REG_BADRPT c CONST(13)
* invalid multibyte character
d REG_ECHAR c CONST(14)
* (shift 6 caret or not) anchor and not BOL
d REG_EBOL c CONST(15)
* $ anchor and not EOL
d REG_EEOL c CONST(16)
* Unknown error in regcomp() call
d REG_ECOMP c CONST(17)
* Unknown error in regexec() call
d REG_EEXEC c CONST(18)
**------------------------------------------------------------
* Structure of a compiled regular expression:
**------------------------------------------------------------
d REG_SUBEXP_MAX c 20
d regex_t ds qualified align based(template)
d re_nsub 10i 0
d re_comp *
d re_cflags 10i 0
d re_erroff 10i 0
d re_len 10i 0
d re_ucoll 10i 0 dim(2)
d re_lsub * DIM(REG_SUBEXP_MAX)
d re_esub * DIM(REG_SUBEXP_MAX)
d re_map 256a
d re_shift 5i 0
d re_dbcs 5i 0
**------------------------------------------------------------
* structure used to report matches found by regexec()
**------------------------------------------------------------
d regmatch_t ds qualified align based(template)
d rm_so 10i 0
d rm_ss 5i 0
d rm_eo 10i 0
d rm_es 5i 0
**------------------------------------------------------------
* regcomp() -- Compile a Regular Expression ("RE")
*
* int regcomp(regex_t *preg, const char *pattern,
* int cflags);
*
* where:
* preg (output) = the compiled regular expression.
* pattern (input) = the RE to be compiled.
* cflags (input) = the sum of the cflag constants
* (listed above) for this RE.
*
* Returns 0 = success, otherwise an error number.
**------------------------------------------------------------
d regcomp pr 10i 0 extproc('regcomp')
d preg like(regex_t)
d pattern * value options(*string)
d cflags 10i 0 value
**------------------------------------------------------------
* regexec() -- Execute a compiled Regular Expression ("RE")
*
* int regexec(const regex_t *preg, const char *string,
* size_t nmatch, regmatch_t *pmatch, int eflags);
*
* where:
* preg (input) = the compiled regular expression
* (the output of regcomp())
* string (input) = string to run the RE upon
* nmatch (input) = the number of matches to return.
* pmatch (output) = array of regmatch_t DS's
* showing what matches were found.
* eflags (input) = the sum of the flags (constants
* provided above) modifying the RE
*
* Returns 0 = success, otherwise an error number.
**------------------------------------------------------------
d regexec pr 10i 0 extproc('regexec')
d preg like(regex_t) const
d string * value options(*string)
d nmatch 10u 0 value
d pmatch * value
d eflags 10i 0 value
**------------------------------------------------------------
* regerror() -- return error information from regcomp/regexec
*
* size_t regerror(int errcode, const regex_t *preg,
* char *errbuf, size_t errbuf_size);
*
* where:
* errcode (input) = the error code to return info on
* (obtained as the return value from
* either regcomp() or regexec())
* preg (input) = the (compiled) RE to return the
* error for.
* errbuf (output) = buffer containing human-readable
* error message.
* errbuf_size (input) = size of errbuf (max length of msg
* that will be returned)
*
* returns: length of buffer needed to get entire error msg
**------------------------------------------------------------
d regerror pr 10u 0 extproc('regerror')
d errcode 10i 0 value
d preg like(regex_t) const
d errbuf * value
d errbuf_size 10i 0 value
**------------------------------------------------------------
* regfree() -- free memory locked by Regular Expression
*
* void regfree(regex_t *preg);
*
* where:
* preg (input) = regular expression to free mem for.
*
* NOTE: regcomp() will always allocate extra memory
* to be pointed to by the various pointers in
* the regex_t structure. if you don't call this,
* that memory will never be returned to the system!
**------------------------------------------------------------
d regfree pr extproc('regfree')
d preg like(regex_t)
Here's the output:
DSPLY My phone #'s are: (444) 555 - 6666 and 777.888.9999
DSPLY My phone #'s are: (***) *** - 6666 and ***.***.9999
The code could be improved by extracting the replace logic and putting it in a Procedure of it's own, creating a custom regexp replace function based on the POSIX library but it's not absolutely necessary.
The ILE C/C++ runtime library does not have a regex replace function available.
Java, however, has excellent support for regular expressions and integrates easily with RPGLE.
Introduction to Java and RPG
Using Regular Expressions in Java
I succeed in using Regex with Java.
I was inspired by this code from scott klement and that code from ibm.
The mix works well. I just added the replace function.
H
/include QSYSINC/QRPGLESRC,JNI
D newString pr O CLASS(*JAVA:'java.lang.String')
D EXTPROC(*JAVA:'java.lang.String':
D *CONSTRUCTOR)
D bytearray 32767A VARYING CONST
D getBytes PR 65535A VARYING
D EXTPROC(*JAVA:
D 'java.lang.String':
D 'getBytes')
D PatternCompile pr O CLASS(*JAVA:
D 'java.util.regex.Pattern')
D EXTPROC(*JAVA:
D 'java.util.regex.Pattern':
D 'compile') STATIC
D pattern O CLASS(*JAVA:'java.lang.String')
D PatternMatcher pr O CLASS(*JAVA:
D 'java.util.regex.Matcher')
D EXTPROC(*JAVA:
D 'java.util.regex.Pattern':
D 'matcher')
D comparestr O CLASS(*JAVA
D :'java.lang.CharSequence')
D CheckMatches pr 1N EXTPROC(*JAVA
D :'java.util.regex.Matcher'
D :'matches')
D DoReplace pr O CLASS(*JAVA:'java.lang.String')
D EXTPROC(*JAVA
D :'java.util.regex.Matcher'
D :'replaceAll')
D replacement O CLASS(*JAVA
D :'java.lang.String')
D RegExPattern s O CLASS(*JAVA:
D 'java.util.regex.Pattern')
D RegExMatcher s O CLASS(*JAVA:
D 'java.util.regex.Matcher')
D jstrStmt s like(jstring)
D jPatStr s like(jstring)
D jRepStr s like(jstring)
D jRepStr2 s like(jstring)
D result S 30A
/free
jPatStr = newString('^(\+33|0)([1-9][0-9]{8})$');
jstrStmt = newString('+33123456789');
jRepStr = newString('0$2');
RegExPattern = PatternCompile(jPatStr);
RegExMatcher = PatternMatcher(RegExPattern : jstrStmt);
if (CheckMatches(RegExMatcher) = *ON);
dsply ('it matches');
else;
dsply ('it doesn''t match');
endif;
jRepStr2 = DoReplace(RegExMatcher : jRepStr);
result = getBytes(jRepStr2);
dsply (%subst(result : 1 : 30));
*inlr = *on;
/end-free
It works, but with Java. I still work on the PASE Solution WarrenT suggested, but using PASE in an ILE program is such a pain...
The Young i Professionals Wiki has a page of Open Source Binaries. In the list is the PCRE Library (Perl Compatible Regular Expressions).
Let us know how this works out. I may try it myself ;-)
For excellent SQLRPGLE example and explanation refer to :
https://www.rpgpgm.com/2017/10/replacing-parts-of-strings-using-regexp.html
REGEXP_REPLACE
(
source-string
,
pattern-expression
,
replacement-string
,
start
,
occurence
,
flags
)

Can I "force" Cachegrind into analyzing an operation (or line)?

I am benchmarking the cache behaviour of two search algorithms that operate on a sorted range of items with Cachegrind. I have n items in a vector, and another vector that holds all valid indices. I use std::random_shuffle on the second vector, and do then perform n successful lookups on the items in the first vector. The function I am benchmarking looks roughly as follows:
template <typename Iterator>
void lookup_in_random_order(Iterator begin, Iterator end)
{
const std::size_t N = std::distance(begin, end);
std::vector<std::size_t> idx(N);
std::iota(idx.begin(), idx.end(), 0);
std::srand(std::time(0));
std::random_shuffle(idx.begin(), idx.end());
// Warm the cache -- I don't care about measuring this loop.
for(std::size_t i = 0; i < N; ++i)
my_search(begin, end, idx[i]);
std::random_shuffle(idx.begin(), idx.end());
// This one I would care about!
for(std::size_t i = 0; i < N; ++i)
{
int s = idx[i];
// Especially this line, of course.
my_search(begin, end, s);
}
}
I compile my code with g++ (with -g and -O2). I run Cachegrind and then cg_annotate. I get something like the following:
Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
. . . . . . . . . template <typename Iterator>
17 2 2 0 0 0 6 0 0 void lookup_in_random_order(Iterator begin, Iterator end)
. . . . . . . . . {
. . . . . . . . . const std::size_t N = std::distance(begin, end);
. . . . . . . . . std::vector<std::size_t> idx(N);
. . . . . . . . . std::iota(idx.begin(), idx.end(), 0);
. . . . . . . . .
4 0 0 0 0 0 2 1 1 std::srand(std::time(0));
. . . . . . . . . std::random_shuffle(idx.begin(), idx.end());
. . . . . . . . .
3,145,729 0 0 0 0 0 0 0 0 for(std::size_t i = 0; i < N; ++i)
. . . . . . . . . my_search(begin, end, idx[i]);
. . . . . . . . .
. . . . . . . . . std::random_shuffle(idx.begin(), idx.end());
. . . . . . . . .
3,145,729 1 1 0 0 0 0 0 0 for(std::size_t i = 0; i < N; ++i)
. . . . . . . . . {
1,048,575 0 0 1,048,575 132,865 131,065 0 0 0 int s = idx[i];
. . . . . . . . . my_search(begin, end, s);
. . . . . . . . . }
7 0 0 6 1 1 0 0 0 }
For some reason, some lines (especially the most interesting one!) consist of dots. Now, the Cachegrind manual says "Events not applicable for a line are represented by a dot. This is useful for distinguishing between an event which cannot happen, and one which can but did not."
How should this be interpreted? My first idea was that maybe the compiler optimizes my searches away. I thought this cannot be, because the program did spend quite a bit of time running. Still, I tried compiling without the -O2 flag and it seemed to work in a sense that now every line with a call to my_search recorded some numbers (no dots anymore!). However, this doesn't seem like the right way to go for obvious reasons.
In general, is there a way I can tell Cachegrind that "look at this line especially, I am very interested how many cache misses it causes"?
My guess is that with O2 it allows the compiler to perform automatic inlining of the functions where you see the dots. Cachegrind will not see the inlined function calls as the calls have dissappeared. Try "-fno-inline" (Compiler options)
Of course you will probably have different cache performance numbers with and without inlining.

converting a Peng Robinson equation code in fortran to C++

i would like someone to assist in converting this code to C++
c ----------------------------------------------------------------------
c Calculate pressure based on the generalized Peng-Robinson equation of state.
c for water.
c Variables Used ...
c T ... temperature (K)
c P ... vapor pressure (MPa)
c V ... volume (m^3/kmol)
c ----------------------------------------------------------------------
c Instructor: Nam Sun Wang
c ----------------------------------------------------------------------
common /cblock/T
c Program Header -------------------------------------------------------
print *, 'This program calculates pressure based on the'
print *, 'generalized Peng-Robinson equation of state for water.'
print *, ' '
c Temperature ----------------------------------------------------------
print *, 'Enter temperature (K): '
read *, T
c Generate a table of P at different values of V in 0.5 increments.
print *, ' '
print *, '------------------------'
print *, ' Volume Pressure '
print *, '(m^3/kmol) (MPa) '
print *, '------------------------'
c xx.x123456789012345678 --- ruler
do i=1, 100
V = 0.5*float(i)
print 650, V, P(V)
end do
c Some formats ---------------------------------------------------------
650 format(f7.1, 1p, e18.6)
end
c ----------------------------------------------------------------------
function P(V)
c ----------------------------------------------------------------------
c Calculate pressure based on the generalized Peng-Robinson equation of state.
c for water.
c ----------------------------------------------------------------------
common /cblock/T
c Gas Constant ---------------------------------------------------------
R = 8.314E-3 ! (in MPa m3/kmol K)
c Critical parameters for water ----------------------------------------
Tc = 647.3 ! (critical temperature in K)
Pc = 22.048 ! (critical pressure in MPa)
w = 0.344 ! (acentric factor, dimensionless)
c Peng-Robinson EOS parameters -----------------------------------------
xk = 0.37464 + 1.54226*w - 0.26992*w*w
alpha = ( 1. + xk*(1.-sqrt(T/Tc)) )**2
a = 0.45724*R*R*Tc*Tc*alpha/Pc
b = 0.07780*R*Tc/Pc
P = R*T/(V-b) - a/(V*(V+b)+b*(V-b))
end
Here are Some conversions for you, have a go and then post your results. We can then help you complete it.
a message
print *, '...'
replace with
cout << "..."
a counted loop
do i=1, 100
...
end do
replace with
for(int i = 1; i <= 100; ++i) {
....
}
a comment
.... ! A comment
replace with
....; // a comment
a variable
X = 99.879
replace with
float X = 99.879
a function
function P(V)
.
.
.
P = .... ! the result
replace with
double P(double V){
.
.
.
return ....; // the result
}
I know this is late but I came here looking for an answer and found another solution.
Try the package f2c. I just used it on your code sample and it worked perfectly. Although it is a bit ugly as it links to libraries that emulate Fortran functions like print but you could just use the main logic part and do the I/O yourself.