C program hello C print *, "Hello World! dfnsnfksn" C end program hello C 6/09 fixed initialization SUBROUTINE USRKPG (SOUT, NSUBS, IDXSUB, ITYPE, NINT, 2 INT, NREAL, REAL, IDS, NPO, 3 NBOPST, NIWORK, IWORK, NWORK, WORK, 4 NC, NR, STOIC, RATES, FLUXM, 5 FLUXS, XCURR, NTCAT, RATCAT, NTSSAT, 6 RATSSA, KCALL, KFAIL, KFLASH, NCOMP, 7 IDX, Y, X, X1, X2, 8 NRALL, RATALL, NUSERV, USERV, NINTR, 9 INTR, NREALR, REALR, NIWR, IWR, * NWR, WR) C------------------------------------------------------------------------------- C Purpose: This routine is a simple illustration of an Aspen Plus C user-defined kinetic routine that can be used with any C of the kinetic reactors (RCSTR, RPlug, or RBatch), or the C pressure relief flowsheeting option. A simple power law C rate expression was chosen so that this example can be C easily compared with a companion example stored as C PLUGPLAW.INP. The companion example utilizes a standard C power law reaction object in place of the user routine. C Comparison of these examples will provide a better C illustration of how kinetic expressions are defined in C Aspen Plus. C C The ethanol and acetic acid reaction is considered in this C example. Ethyl acetate and water are formed. Both forward C and backward reactions are considered. C C The Aspen Plus diagnostic message facility is also C illustrated. Messages are printed to the history file based C on the diagnostic level requested by the simulation. C Messages are printed for diagnostic levels 5 and 6. C C C Revision: 10/96, developed by D. Jacas C 10/96, reviewed by M. Jarvis C C Supporting C Files: Input file to test this routine: PLUGUSR1.INP (attached) C C Refs: Aspen Plus User Models Manual Reference. C------------------------------------------------------------------------------- C IMPLICIT NONE C C DECLARE VARIABLES USED IN DIMENSIONING C INTEGER NSUBS, NINT, NPO, NIWORK,NWORK, + NC, NR, NTCAT, NTSSAT,NCOMP, + NRALL, NUSERV,NINTR, NREALR,NIWR, + NWR C- Arrays in Argument List C These arrays are adjustable and are dimensioned as shown in Chapter C 11 of the User's Models Manual. The stream vector's dimension will C be determined by Aspen Plus at run-time. C------------------------------------------------------------------------ C- Labeled commons are provided to pass data for specific reactor types. C- RCSTR #include "rcst_rcstri.cmn" #include "rxn_rcstrr.cmn" C- RPLUG #include "rplg_rplugi.cmn" #include "rplg_rplugr.cmn" EQUIVALENCE (XLEN, RPLUGR_UXLONG) EQUIVALENCE (DIAM, RPLUGR_UDIAM) C- RBATCH #include "rbtc_rbati.cmn" #include "rbtc_rbatr.cmn" C- Pressure Relief #include "rbtc_presrr.cmn" C------------------------------------------------------------------------ C- Two general labeled commons are provided for physical property data. #include "rxn_rprops.cmn" EQUIVALENCE (TEMP, RPROPS_UTEMP) EQUIVALENCE (PRES, RPROPS_UPRES) EQUIVALENCE (VFRAC, RPROPS_UVFRAC) EQUIVALENCE (BETA, RPROPS_UBETA) EQUIVALENCE (VVAP, RPROPS_UVVAP) EQUIVALENCE (VLIQ, RPROPS_UVLIQ) EQUIVALENCE (VLIQS, RPROPS_UVLIQS) #include "pputl_ppglob.cmn" C------------------------------------------------------------------------ C- A general user common is provided for all user-specified routines. C This common is documented in Appendix A of the User Models manual. #include "ppexec_user.cmn" EQUIVALENCE (RMISS, USER_RUMISS) EQUIVALENCE (IMISS, USER_IUMISS) C------------------------------------------------------------------------ C- Commons and Declarations for the Aspen Plus Error Reporting Facility. C C 10 text lines are provided for user-defined code to report errors C and warnings to the Aspen Plus error reporting facililty. This C facility will inform the user routine whether this error or warning C should be printed based on the currrent diagnostic level that was C specified in the simulation. It also logs all errors and warnings C so that a tabulated summary can be reported at the end of a run and C writes the errors in the simulation history file. Each line contains C 80 characters. The equivalence statements below enable direct access C to any line of the buffer using a FORTRAN WRITE statement. For C example, to start writing on the first line of the error buffer, use C the variable IERW1 in a FORTRAN write statement. Use ERW2 to start C writing on the second line, ERW3 for the third, up to ERW10 for the C tenth line. The dimension for each IERWn variable is set to the number C of lines remaining in the buffer plus the current line, ie. IERW6 is C dimensioned to 5 so that lines 6 through 10 can be accessed directly. #include "dms_errout.cmn" EQUIVALENCE (IERROUT, ERROUT_IEROUT) C C DECLARE ARGUMENTS C INTEGER IDXSUB(NSUBS),ITYPE(NSUBS), INT(NINT), + IDS(2),NBOPST(6,NPO),IWORK(NIWORK), + IDX(NCOMP), INTR(NINTR), IWR(NIWR), + NREAL, KCALL, KFAIL, KFLASH,I, + IAA, IETOH, IETAC, IH2O, IPAA INTEGER IPETOH,IPETAC,IPH2O, KV, KDIAG, + KER REAL*8 SOUT(1), WORK(NWORK), + STOIC(NC,NSUBS,NR), RATES(NC), + FLUXM(1), FLUXS(1), RATCAT(NTCAT), + RATSSA(NTSSAT), Y(NCOMP), + X(NCOMP), X1(NCOMP), X2(NCOMP) REAL*8 RATALL(NRALL),USERV(NUSERV), + REALR(NREALR),WR(NWR), XCURR, TEMP, + PRES, VMXL, DVMX, TK C C C DECLARE LOCAL VARIABLES C INTEGER IPROG(2), IMISS, DMS_KFORMC,DMS_IRRCHK REAL*8 REAL(NREAL), XLEN, DIAM, VFRAC, BETA, + VVAP, VLIQ, VLIQS, RMISS, CAA, + CETOH, CETAC, CH2O, RRATE1,RRATE2, + RNET, AREA, VOLLF CHARACTER*80 IERROUT(10), IERW1(10), IERW2(9), IERW3(8) + , IERW4(7), IERW5(6), IERW6(5), IERW7(4), IERW8(3) + , IERW9(2), IERW10 EQUIVALENCE (IERROUT(1), IERW1), (IERROUT(2), IERW2), + (IERROUT(3), IERW3), (IERROUT(4), IERW4), + (IERROUT(5), IERW5), (IERROUT(6), IERW6), + (IERROUT(7), IERW7), (IERROUT(8), IERW8), + (IERROUT(9), IERW9), (IERROUT(10), IERW10) C- Declaration for Aspen Plus diagnositic reporting routine. C Diagnostics will be printed in this example when the diagnostic C level for the block is set to 5 or higher, 4 is the default. The C following declaration will enable the diagnostic routines to print C the name of this routine with the diagnostic message. C C DATA STATEMENTS C DATA IPROG /4HUSRK, 4HIN / C=============================================================================== C- Initialize rates vector. C This vector is used to specify the rate of change for each component. 50 FORMAT(T15,'Total Molar Flow: ',d14.7,/, + T15,'Realr(1-4): ',d14.7,(', ',d14.7),/, + T33, d14.7,(', ',d14.7),/, + T15,'Rgas: ',d14.7,/, + T15,'Tk (K): ',d14.7,/, + T15,'Rnet: ',d14.7,/, + T15,'Vvap: ',d14.7,/, + T15,'Vliq: ',d14.7,/, + T15,'Tube Area: ',d14.7,/, + T15,'Overall Component Rate (kmol/sec): ',d14.7 ) 60 FORMAT(T17,'Component Data ',/, + T20,'Acetic Acid Mole Fraction: ',F10.4,/, + T32,'Conc (kmol/m3): ',F10.4,/, + T20,'Ethanol Mole Fraction: ',F10.4,/, + T32,'Conc (kmol/m3): ',F10.4,/, + T20,'Ethyl Acetate Mole Fraction: ',F10.4,/, + T32,'Conc (kmol/m3): ',F10.4,/, + T20,'Water Mole Fraction: ',F10.4,/, + T32,'Conc (kmol/m3): ',F10.4,/, + T20,'Density (m3/kgmol): ',F10.4) C C BEGIN EXECUTABLE CODE C DO I = 1, NC RATES(I) = 0. END DO IPAA = 0 IPETOH = 0 IPETAC = 0 IPH2O = 0 CAA = 0. CETOH = 0. CETAC = 0. CH2O = 0. C=============================================================================== C Locate component indices used in this routine based on formula name. C These indices correspond to the order that each component is declared C in the Components paragraph of the simulation input file or on the C Components Specifications Selection sheet. This section of code is optional. C It enables the user routine to automatically use the correct indices C if the component order is changed, or if components are inserted or C deleted from the components paragraph. C C In this example, the component index will be obtained for: C C Component CID Formula C --------- --- ------- C ACETIC ACID AA C2H4O2-1 C ETHANOL ETOH C2H6O-2 C ETHYL-ACETATE ETAC C4H8O2-3 C WATER H2O H2O C=============================================================================== IAA =DMS_KFORMC ('C2H4O2-1') IETOH =DMS_KFORMC ('C2H6O-2') IETAC =DMS_KFORMC ('C4H8O2-3') IH2O =DMS_KFORMC ('H2O') C=============================================================================== C Locate the packed component indices. C Only the mole fractions for components that are present will be C passed via the argument list. This data will be stored in the C order that each component is declared in the Components paragraph of C the simulation input file or on the Components Specifications Selection sheet. C The components that are not present are skipped. This type of vector C is called a packed vector in Aspen Plus. The IDX vector passed to this C routine is a list of the component indices that are present. The packed C component index is the order of the component in that list. C=============================================================================== DO I=1, NCOMP IF (IDX(I).EQ.IAA) THEN IPAA=I ELSE IF (IDX(I).EQ.IETOH) THEN IPETOH=I ELSE IF (IDX(I).EQ.IETAC) THEN IPETAC=I ELSE IF (IDX(I).EQ.IH2O) THEN IPH2O=I END IF END DO C=============================================================================== C Calculate the liquid concentration of each component. C The rate expression in this example is based on molar concentration. C The component concentration can be calculated from mole fraction C using the molar density obtained from the liquid molar volume C physical property monitor (VOLL). The temperature and pressure C were passed to this routine through the PPROPS common. X, NCOMP, C and IDX were obtained from the argument list. NBOPST is also C obtained from the argument list. It contains the physical property C option set that was defined for the block that is calling this routine. C C KV is set to 1 to specify that the only the property, VMX, be C calculated. VMX has m3/kgmol units. C=============================================================================== KV=1 CALL PPMON_VOLL ( TEMP , PRES , X , NCOMP , IDX, NBOPST, + KDIAG, KV, VMXL, DVMX, KER ) IF (IPAA .NE. 0) CAA = X(IPAA)/VMXL IF (IPETOH .NE. 0) CETOH = X(IPETOH)/VMXL IF (IPETAC .NE. 0) CETAC = X(IPETAC)/VMXL IF (IPH2O .NE. 0) CH2O = X(IPH2O)/VMXL C=============================================================================== C Calculate the forward and backward second order reaction rates. C The pre-exponential factor and activation energy are passed as C reaction real parameters (REALR). These are defined on the C User Subroutine form. This form is accessed by C selecting Reactions from the Data menu and then C selecting the Reactions submenu. C C Reactor temperature, tk, in degrees K. C All parameters have SI units. The pre-exponential factor, Realr(1) C and Realr(3), have m3/kmol-sec units. The activation energy, C Realr(2) and Realr(4), have J/kmol units. These units are C user selectable. The real parameters entered into the Reaction C paragraph must have the same units as those expected by this routine. C Units conversion is not performed for real parameters. C TK=TEMP RRATE1 = REALR(1)*DEXP(-REALR(2)/(PPGLOB_RGAS*TK))*CETOH* + CAA RRATE2 = REALR(3)*DEXP(-REALR(4)/(PPGLOB_RGAS*TK))*CETAC* + CH2O RNET = RRATE1 - RRATE2 C=============================================================================== C Convert rates to kmol/sec per length units using the tube diameter. The C actual volume occupied by the liquid (VOLLF) is applied to the rate C to accomodate the case when some vapor exists. Both VLIQ and VVAP cannot C be used directly for the plug flow reactor which are the actual volume C of the liquid and vapor for the current integration length. The number C of integration divisions must be considered to use this variable directly. AREA= 3.141592654/4.*DIAM**2. VOLLF=VLIQ/(VLIQ+VVAP) RATES(IETOH) = -RNET*AREA*VOLLF RATES(IAA) = -RNET*AREA*VOLLF RATES(IETAC) = RNET*AREA*VOLLF RATES(IH2O) = RNET*AREA*VOLLF C=============================================================================== C Diagnostic Section C C ASPEN PLUS function IRRCHK is used to control the printing of diagnostics. C Diagnostics are printed for level 5 and above. C IRRCHK arguments: C 1st argument is the name of this routine, C 2nd argument denotes type of error or diagnostic, C 3rd argument can be used as a message identifier, C 4th argument is the current diagnostic level obtained from the C USER labeled common, C 5th argument should be set to IMISS from USER labeled common, C 6th argument is not currently implemented, should be set to zero, C 7th argument indicates whether this routine is a physical property C routine, zero=NO, 1=Yes, C 8th argument indicates header type, C 0=no header, 1=cursory header, 2=normal header IF(DMS_IRRCHK(IPROG,5,9001,USER_LMSG,IMISS,0,0,2) .NE. 0) + THEN C This write fills the entire error buffer. C Separate write and errprt call statements must be used if C more than 10 lines should be printed. WRITE(IERROUT, 50) SOUT(NC+1), REALR(1), REALR(2) + , REALR(3), REALR(4) + , PPGLOB_RGAS, TK, RNET, VVAP, VLIQ, AREA, DABS(RATES( + IETOH)) C Request that all ten lines be printed C These lines may not be printed if MAX-PRINT declared in the C simulation has been exceeded. CALL DMS_ERRPRT(10) END IF C------------------------------------------------------------------------ C- Print more detailed diagnostics for a diagnostic level of 6. IF(DMS_IRRCHK(IPROG,6,9002,USER_LMSG,IMISS,0,0,2) .NE. 0) + THEN C Either the IERWn or IERROUT variables may be used to define buffer. WRITE(IERW1, 60) X(IPAA), CAA, X(IPETOH), CETOH, + X(IPETAC), CETAC, X(IPH2O), CH2O, VMXL CALL DMS_ERRPRT(10) END IF RETURN END C===============================================================================
Write, Run & Share Fortran code online using OneCompiler's Fortran online compiler for free. It's one of the robust, feature-rich online compilers for Fortran language, running on the latest version 7. Getting started with the OneCompiler's Fortran compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Fortran
and start coding.
OneCompiler's Fortran online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Fortran program which takes name as input and prints hello message with your name.
program hello
character :: name*30
read *, name
print *, "Hello ", name
end program hello
Fortran language was initially developed for scientific calculations by IBM in 1957. It has a number of in-built functions to perform mathematical calculations and is ideal for applications which has more mathematical calculations.
Data type | Description | Usage |
---|---|---|
Integer | To store integer variables | integer :: x |
Real | To store float values | real :: x |
Complex | To store complex numbers | complex :: x,y |
Logical | To store boolean values True or false | logical :: x=.True. , logical :: x = .FALSE. |
Character | To store characters and strings | character :: x |
Variable is a name given to the storage area in order to manipulate them in our programs.
data type :: variable_name
Array is a collection of similar data which is stored in continuous memory addresses.
data-type, dimension (x,y) :: array-name
integer, dimension(3,3) :: cube
Do is used to execute a set of statement(s) iteratively when a given condition is true and the loop variable must be an integer.
do i = start, stop [,step]
! code
end do
Do-While is used to execute a set of statement(s) iteratively when a given condition is true.
do while (condition)
!Code
end do
If is used to execute a set of statements based on a condition.
if (logical-expression) then
!Code
end if
If is used to execute a set of statements based on a condition and execute another set of statements present in else block, if condition specified in If block fails.
if (logical-expression) then
!code when the condition is true
else
!code when the condition fails
end if
Case is similar to switch in C language.
[name:] select case (regular-expression)
case (value1)
! code for value 1
... case (value2)
! code for value 2
...
case default
! default code
...
end select [name]