I am attempting to write a user model in Fortran that can be connected to the Aspen Plus process simulator. Can Fortran 90 be used, or does Aspen only work with the older Fortran 77? I have checked the Aspen Plus documentation, but can find nothing about which versions of Fortran it is compatible with.
Nat was right that Aspen doesn't care as long as your compiler can produce a DLL from the Fortran 90 code (which most do). However, I found that the Aspen files that need to be included in most user models are written in fixed format (the formatting style used back with Fortran 77). So when using Fortran 90 code in free format you get a bunch of compiler errors because of the mix of fixed and free formatting. There is a solution though: put directives around the include lines that switch to fixed format only for the included files.
Here is an example I got from the Aspen support center. It is a user model that is supposed to calculate the viscosity of a compound.
SUBROUTINE MUL2U (T, P, Z, N, IDX, & IRW, IIW, KCALC, KOP, NDS, & KDIAG, QMX, DQMX, KER) IMPLICIT REAL*8 (A-H,O-Z) #include "dms_plex.cmn" #include "ppexec_user.cmn" integer b(1) equivalence (b(1), ib(1)) integer dms_ifcmnc integer limuusr limuusr=dms_ifcmnc('MUUSR') ! The following input language is required to define A and B ! (just define them for the 1st component in the list) ! PROPERTIES RKS-MU SOLU-WATER=2 ! PROPERTIES RK-SOAVE ! PROP-REPLACE RKS-MU RK-SOAVE ! PROP MULMX MULMXUSR ! USER-PROPS MUUSR 1 1 2 ! ! PROP-DATA MUUSR-1 ! PROP-LIST MUUSR ! PVAL WATER -5 20 ! To check that parameters are correctly transferred, set global diagnostics: ! HISTORY PROP-LEVEL=5 AA = B(limuusr + 1) BB = B(limuusr + 2) if (KDIAG .GE. 5) then WRITE (USER_NHSTRY, *)'A = ', AA, ' B = ', BB endif qmx = exp(AA + BB / T) dqmx = - BB * qmx / (T * T) RETURN END subroutine mul2u
The example was originally written for Fortran 77 (so it used fixed formatting), and I made the few changes necessary for it to be compiled using free formatting. However, when compiling you get a string of errors that come from the Aspen files included in the subroutine (so dms_plex.cmn and ppexec_user.cmn). Here is an example of one of the errors:
c:\Program Files (x86)\AspenTech\AprSystem V8.8\Engine\commons/ppexec_user.cmn(7): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: %FILL <IDENTIFIER> INTEGER USER_IUMISS, USER_NGBAL, USER_IPASS, -------------------------------------------------------^
Again, it seems that the compiler gives the error because the Aspen files are written in fixed format and we are compiling with free format. To get around this use directives that switch to fixed format and back again.
!DEC$ NOFREEFORM #include "dms_plex.cmn" #include "ppexec_user.cmn" !DEC$ FREEFORM
When I use these directives around the include statement then the compiler works without errors and I can use a Fortran 90 user model in Aspen.
I'm not 100% on this, but I don't think that AspenPlus itself cares. This is because AspenPlus calls a Fortran compiler to compile-and-link your code, then it consumes your code as a
.dll (dynamic link library). The details behind your Fortran and how the compiler compiles it seem to beyond the scope of AspenPlus's concern.
So, AspenPlus is probably happy as long as the compiler can compile your code into a library that links properly.
So, it'd seem like the version of Fortran accepted would be a function of your compiler. As long as your compiler turns the Fortran into a
.dll with the call convention that AspenPlus expects, it's probably sufficient.