c begin file utility.f c c This file contains various utility subroutines to retrieve information c about the components. c c contained here are: c subroutine INFO (icomp,wm,ttp,tnbp,tc,pc,Dc,Zc,acf,dip,Rgas) c subroutine NAME (icomp,hname,hn80,hcas) c function WMOL (x) c subroutine XMASS (xmol,xkg,wmix) c subroutine XMOLE (xkg,xmol,wmix) c subroutine LIMITX (htyp,t,D,p,x,tmin,tmax,Dmax,pmax,ierr,herr) c subroutine LIMITK (htyp,icomp,t,D,p,tmin,tmax,Dmax,pmax,ierr,herr) c subroutine ERRMSG (ierr,herr) c c various arrays are dimensioned with parameter statements c parameter (ncmax=5) !max number of components in mixture c parameter (n0=-ncmax,nx=ncmax) c c ====================================================================== c ====================================================================== c subroutine INFO (icomp,wm,ttp,tnbp,tc,pc,Dc,Zc,acf,dip,Rgas) c c provides fluid constants for specified component c c input: c icomp--component number in mixture; 1 for pure fluid c outputs: c wm--molecular weight [g/mol] c ttp--triple point temperature [K] c tnbp--normal boiling point temperature [K] c tc--critical temperature [K] c pc--critical pressure [kPa] c Dc--critical density [mol/L] c Zc--compressibility at critical point [pc/(Rgas*Tc*Dc)] c acf--accentric factor [-] c dip--dipole moment [debye] c Rgas--gas constant [J/mol-K] c c written by M. McLinden, NIST Thermophysics Division, Boulder, Colorado c 01-31-97 MM, original version c 02-19-97 MM, add check that input icomp is within bounds c 10-02-97 MM, add compiler switches to allow access by DLL c c compiler switches to allow access by DLL; for use with Digital Visual c Fortran; these should be treated as comments by all other compilers c !MS$ATTRIBUTES DLLEXPORT :: INFO c implicit double precision (a-h,o-z) implicit integer (i-n) parameter (ncmax=5) !max number of components in mixture parameter (n0=-ncmax,nx=ncmax) common /NCOMP/ nc common /CCON/ xwm(n0:nx),xttp(n0:nx),xtnbp(n0:nx), & xtc(n0:nx),xpc(n0:nx),rhoc(n0:nx),Zcrit(n0:nx), & accen(n0:nx),dipole(n0:nx) common /Gcnst/ R c if (abs(icomp).le.nc) then wm=xwm(icomp) ttp=xttp(icomp) tnbp=xtnbp(icomp) tc=xtc(icomp) pc=xpc(icomp) Dc=rhoc(icomp) Zc=Zcrit(icomp) acf=accen(icomp) dip=dipole(icomp) Rgas=R else wm=0.0d0 ttp=0.0d0 tnbp=0.0d0 tc=0.0d0 pc=0.0d0 Dc=0.0d0 Zc=0.0d0 acf=0.0d0 dip=0.0d0 Rgas=R end if c RETURN end !subroutine INFO c c ====================================================================== c subroutine NAME (icomp,hname,hn80,hcas) c c provides name information for specified component c c input: c icomp--component number in mixture; 1 for pure fluid c outputs: c hname--component name [character*12] c hn80--component name--long form [character*80] c hcas--CAS (Chemical Abstracts Service) number [character*12] c c written by M. McLinden, NIST Thermophysics Division, Boulder, Colorado c 02-06-97 MM, original version c 02-19-97 MM, add check that input icomp is within bounds c 10-02-97 MM, add compiler switches to allow access by DLL c 12-01-97 MM, add synonyms to /CNAM80/ c c compiler switches to allow access by DLL; for use with Digital Visual c Fortran; these should be treated as comments by all other compilers c !MS$ATTRIBUTES DLLEXPORT :: NAME c implicit double precision (a-h,o-z) implicit integer (i-n) parameter (ncmax=5) !max number of components in mixture parameter (n0=-ncmax,nx=ncmax) character*1 htab,hnull character*12 hn,hcasn,hcas,hname character*80 hn80,hnam80,hsyn1,hsyn2 common /NCOMP/ nc common /CHAR/ htab,hnull common /CCAS/ hcasn(n0:nx) common /CNAM/ hn(n0:nx) common /CNAM80/ hnam80(n0:nx),hsyn1(n0:nx),hsyn2(n0:nx) c if (abs(icomp).le.nc) then hname=hn(icomp) hn80=hnam80(icomp) hcas=hcasn(icomp) else hname='not defined' hn80='not defined '// & ' ' hcas='not defined' end if c RETURN end !subroutine NAME c c ====================================================================== c function WMOL (x) c c molecular weight for a mixture of specified composition c c input: c x--composition array [array of mol frac] c c output (as function value): c WMOL--molar mass [g/mol], a.k.a. "molecular weight" c c written by M. McLinden, NIST Thermophysics Division, Boulder, Colorado c 01-10-96 MM, original version c 02-27-96 MM, parameter n0=-ncmax to accomodate ECS-thermo model c add Zcrit to common /CCON/ c 03-19-96 MM, add dipole moment to /CCON/ c 10-02-97 MM, add compiler switches to allow access by DLL c c compiler switches to allow access by DLL; for use with Digital Visual c Fortran; these should be treated as comments by all other compilers c !MS$ATTRIBUTES DLLEXPORT :: WMOL c implicit double precision (a-h,o-z) implicit integer (i-n) parameter (ncmax=5) !max number of components in mixture parameter (n0=-ncmax,nx=ncmax) dimension x(ncmax) common /NCOMP/ ncomp common /CCON/ wm(n0:nx),ttp(n0:nx),tnbp(n0:nx), & tc(n0:nx),pc(n0:nx),rhoc(n0:nx),Zcrit(n0:nx), & accen(n0:nx),dipole(n0:nx) c wsum=0.0d0 do 100 i=1,ncomp wsum=wsum+x(i)*wm(i) 100 continue WMOL=wsum c RETURN end !function WMOL c c ====================================================================== c subroutine XMASS (xmol,xkg,wmix) c c converts composition on a mole fraction basis to mass fraction c c input: c xmol--composition array [array of mol frac] c outputs: c xkg--composition array [array of mass frac] c wmix--molar mass of the mixture [g/mol], a.k.a. "molecular weight" c c written by M. McLinden, NIST Thermophysics Division, Boulder, Colorado c 04-08-96 MM, original version c 10-02-97 MM, add compiler switches to allow access by DLL c c compiler switches to allow access by DLL; for use with Digital Visual c Fortran; these should be treated as comments by all other compilers c !MS$ATTRIBUTES DLLEXPORT :: XMASS c implicit double precision (a-h,o-z) implicit integer (i-n) parameter (ncmax=5) !max number of components in mixture parameter (n0=-ncmax,nx=ncmax) dimension xmol(ncmax),xkg(ncmax),xsumi(ncmax) common /NCOMP/ nc common /CCON/ wm(n0:nx),ttp(n0:nx),tnbp(n0:nx), & tc(n0:nx),pc(n0:nx),rhoc(n0:nx),Zcrit(n0:nx), & accen(n0:nx),dipole(n0:nx) c xsum=0.0d0 do 200 i=1,nc xsumi(i)=xmol(i)*wm(i) xsum=xsum+xsumi(i) 200 continue wmix=xsum xsinv=1.0d0/xsum do 240 i=1,nc xkg(i)=xsumi(i)*xsinv 240 continue c RETURN end !subroutine XMASS c c ====================================================================== c subroutine XMOLE (xkg,xmol,wmix) c c converts composition on a mass fraction basis to mole fraction c c input: c xkg--composition array [array of mass frac] c outputs: c xmol--composition array [array of mol frac] c wmix--molar mass of the mixture [g/mol], a.k.a. "molecular weight" c c written by M. McLinden, NIST Thermophysics Division, Boulder, Colorado c 04-08-96 MM, original version c 10-02-97 MM, add compiler switches to allow access by DLL c c compiler switches to allow access by DLL; for use with Digital Visual c Fortran; these should be treated as comments by all other compilers c !MS$ATTRIBUTES DLLEXPORT :: XMOLE c implicit double precision (a-h,o-z) implicit integer (i-n) parameter (ncmax=5) !max number of components in mixture parameter (n0=-ncmax,nx=ncmax) dimension xmol(ncmax),xkg(ncmax),xsumi(ncmax) common /NCOMP/ nc common /CCON/ wm(n0:nx),ttp(n0:nx),tnbp(n0:nx), & tc(n0:nx),pc(n0:nx),rhoc(n0:nx),Zcrit(n0:nx), & accen(n0:nx),dipole(n0:nx) c xsum=0.0d0 wsum=0.0d0 do 200 i=1,nc xsumi(i)=xkg(i)/wm(i) xsum=xsum+xsumi(i) 200 continue wmix=xsum xsinv=1.0d0/xsum do 240 i=1,nc xmol(i)=xsumi(i)*xsinv wsum=wsum+xmol(i)*wm(i) 240 continue wmix=wsum c RETURN end !subroutine XMASS c c ====================================================================== c subroutine LIMITX (htyp,t,D,p,x,tmin,tmax,Dmax,pmax,ierr,herr) c c returns limits of a property model as a function of composition c and/or checks input t, D, p against those limits c c Pure fluid limits are read in from the .fld files; for mixtures, a c simple mole fraction weighting in reduced variables is used. c c Attempting calculations below the mininum temperature and/or above c the maximum density will result in an error. These will often c correspond to a physically unreasonable state; also many equations of c state do not extrapolate reliably to lower T's and higher D's. c c A warning is issued if the temperature is above the maximum but below c 1.5 times the maximum; similarly pressures up to twice the maximum c result in only a warning. Most equations of state may be c extrapolated to higher T's and P's. Temperatures and/or pressures c outside these extended limits will result in an error. c c inputs: c htyp--flag indicating which models are to be checked [character*3] c 'EOS': equation of state for thermodynamic properties c 'ETA': viscosity c 'TCX': thermal conductivity c 'STN': surface tension c t--temperature [K] c D--molar density [mol/L] c p--pressure [kPa] c x--composition array [mol frac] c N.B.--all inputs must be specified, if one or more are not c available, (or not applicable as in case of surface tension) c use reasonable values, such as: c t = tnbp c D = 0 c p = 0 c outputs: c tmin--minimum temperature for model specified by htyp [K] c tmax--maximum temperature [K] c Dmax--maximum density [mol/L] c pmax--maximum pressure [kPa] c ierr--error flag: 0 = all inputs within limits c <>0 = one or more inputs outside limits: c -1 = 1.5*tmax > t > tmax c 1 = t < tmin or t > 1.5*tmax c 2 = D > Dmax or D < 0 c -4 = 2*pmax > p > pmax c 4 = p < 0 or p > 2*pmax c 8 = component composition < 0 or > 1 c and/or composition sum < 0 or > 1 c if multiple inputs are outside limits, ierr = abs[sum(ierr)] c with the sign determined by the most severe excursion c (ierr > 0 indicate an error--calculations not possible, c ierr < 0 indicate a warning--results may be questionable) c herr--error string (character*255 variable if ierr<>0) c c written by M. McLinden, NIST Thermophysics Division, Boulder, Colorado c 05-30-96 MM, original version c 06-03-96 MM, p > 2*pmax and t > 1.5*tmax result in error c add htyp to argument list c 02-21-97 MM, add checks for viscosity and thermal conductivity c 06-03-97 MM, initialize ierr = 0 and herr = hnull c 06-04-97 EWL, zero delsum and xsum before do loop c 06-17-97 MM, change format on xsum error c 10-02-97 MM, add compiler switches to allow access by DLL c 12-05-97 MM, x(i) missing in summation for max density c c compiler switches to allow access by DLL; for use with Digital Visual c Fortran; these should be treated as comments by all other compilers c !MS$ATTRIBUTES DLLEXPORT :: LIMITX c implicit double precision (a-h,o-z) implicit integer (i-n) logical lerr,lwarn,ltemp parameter (ncmax=5) !max number of components in mixture parameter (n0=-ncmax,nx=ncmax) parameter (nrf0=0) !lower limit for transport ref fluid arrays dimension x(ncmax) dimension tred(ncmax),Dred(ncmax) dimension tmn(ncmax),tmx(ncmax),Dmx(ncmax),pmx(ncmax) character*1 htab,hnull character*3 htyp character*75 herrt,herrd,herrp character*120 herrx character*255 herr common /NCOMP/ nc common /CHAR/ htab,hnull common /CCON/ wm(n0:nx),ttp(n0:nx),tnbp(n0:nx), & tcrit(n0:nx),pcrit(n0:nx),Dcrit(n0:nx),Zcrit(n0:nx), & accen(n0:nx),dipole(n0:nx) common /EOSLIM/ tmeos(n0:nx),txeos(n0:nx),peos(n0:nx),Deos(n0:nx) common /WLMSTN/ tmstn(n0:nx),txstn(n0:nx) common /WLMTCX/ tmtcx(nrf0:nx),txtcx(nrf0:nx),ptcx(nrf0:nx), & Dtcx(nrf0:nx) common /WLMETA/ tmeta(nrf0:nx),txeta(nrf0:nx),peta(nrf0:nx), & Deta(nrf0:nx) c c initialize flags and strings c c write (*,*) ' LIMITX--entering with htyp,t = ',htyp,t ierr=0 ierrt=0 ierrd=0 ierrp=0 ierrx=0 xsum=0.0d0 herr=hnull herrt=' ' herrd=' ' herrp=' ' herrx=' ' nchart=1 nchard=1 ncharp=1 ncharx=1 lerr=.false. lwarn=.false. c if (htyp.eq.'EOS' .or. htyp.eq.'eos') then c equation of state ltemp=.true. !EOS cannot be extrapolated to lower temps do 100 i=1,nc tmn(i)=tmeos(i) tmx(i)=txeos(i) Dmx(i)=Deos(i) pmx(i)=peos(i) 100 continue else if (htyp.eq.'STN' .or. htyp.eq.'stn') then c surface tension model ltemp=.false. !STN may be extrapolated to lower temps do 120 i=1,nc tmn(i)=tmstn(i) tmx(i)=txstn(i) Dmx(i)=9.99d99 !density and pressure limits not applicable pmx(i)=9.99d99 !for surface tension--set to large number c write (*,*) ' LIMITX-STN; i,Tmin,Tmax: ',i,tmn(i),tmx(i) 120 continue else if (htyp.eq.'TCX' .or. htyp.eq.'tcx') then c thermal conductivity ltemp=.true. !transport cannot be extrapolated to lower temps c write (*,*) ' LIMITX--about to check thermal conductivity ' do 140 i=1,nc tmn(i)=tmtcx(i) tmx(i)=txtcx(i) Dmx(i)=Dtcx(i) pmx(i)=ptcx(i) 140 continue else if (htyp.eq.'ETA' .or. htyp.eq.'eta') then c viscosity ltemp=.true. !transport cannot be extrapolated to lower temps do 160 i=1,nc tmn(i)=tmeta(i) tmx(i)=txeta(i) Dmx(i)=Deta(i) pmx(i)=peta(i) 160 continue else c unknown model specification--use EOS limits ltemp=.true. do 180 i=1,nc tmn(i)=tmeos(i) tmx(i)=txeos(i) Dmx(i)=Deos(i) pmx(i)=peos(i) 180 continue end if c if (nc.eq.1) then c special case--pure component tmin=tmn(1) tmax=tmx(1) Dmax=Dmx(1) pmax=pmx(1) else c general mixture case taumin=0.0d0 taumax=0.0d0 delmax=0.0d0 c delmin=0.0d0 pmax=0.0d0 xsum=0.0d0 do 200 i=1,nc call REDK (i,tred(i),Dred(i)) taumin=taumin+x(i)*tred(i)/tmn(i) taumax=taumax+x(i)*tred(i)/tmx(i) delmax=delmax+x(i)*Dmx(i)/Dred(i) pmax=pmax+x(i)*pmx(i) xsum=xsum+x(i) if (x(i).lt.-1.0d-10 .or. x(i).gt.1.0000000001d0) then lerr=.true. ierrx=8 end if 200 continue call REDX (x,trmix,Drmix) tmin=trmix/taumin tmax=trmix/taumax Dmax=Drmix*delmax if (xsum.lt.0.9999999999d0 .or. xsum.gt.1.0000000001d0) then lerr=.true. ierrx=8 end if end if c c check inputs against limits c if (t.lt.tmin) then if (ltemp) then lerr=.true. ierrt=1 else lwarn=.true. ierrt=-1 end if write (herrt,1010) t,tmin nchart=70 1010 format (' temperature below lower limit, T =',1pe11.3, & ' K, Tmin =',1pe11.3,' K;') else if (t.gt.1.5d0*tmax) then lerr=.true. ierrt=1 write (herrt,1011) t,tmax nchart=72 1011 format (' temperature > 1.5 x upper limit, T =',1pe11.3, & ' K, Tmax =',1pe11.3,' K;') else if (t.gt.tmax) then lwarn=.true. ierrt=-1 write (herrt,1012) t,tmax nchart=70 1012 format (' temperature above upper limit, T =',1pe11.3, & ' K, Tmax =',1pe11.3,' K;') end if if (D.lt.0.0d0) then lerr=.true. ierrd=2 write (herrd,1020) D nchard=36 1020 format (' density < 0, D =',1pe11.3,' mol/L;') else if (D.gt.Dmax) then lerr=.true. ierrd=2 write (herrd,1021) D,Dmax nchard=74 1021 format (' density above upper limit, D =',1pe11.3, & ' mol/L, Dmax =',1pe11.3,' mol/L;') end if if (p.lt.0.0d0) then lerr=.true. ierrp=4 write (herrp,1040) p ncharp=34 1040 format (' pressure < 0, P =',1pe11.3,' kPa;') else if (p.gt.2.0d0*pmax) then lerr=.true. ierrp=4 write (herrp,1042) p,pmax ncharp=71 1042 format (' pressure > 2 x upper limit, P =',1pe11.3, & ' kPa, Pmax =',1pe11.3,' kPa;') else if (p.gt.pmax) then lwarn=.true. ierrp=-4 write (herrp,1044) p,pmax ncharp=71 1044 format (' pressure above upper limit, P =',1pe11.3, & ' kPa, Pmax =',1pe11.3,' kPa;') end if if (ierrx.ne.0) then write (herrx,1080) xsum,(x(i),i=1,nc) ncharx=113 1080 format (' composition(s) out of range, Xsum =',f13.10, & ' mol frac, X(i) =',5f13.10) end if c c compose error string and compute overall value of ierr c if (lerr .or. lwarn) then c write (*,*) ' LIMITX--nchart,d,p,x:',nchart,nchard,nchard,ncharx c write (*,1999) ' LIMITX--herrt: ',herrt(1:nchart) c write (*,1999) ' LIMITX--herrd: ',herrd(1:nchard) c write (*,1999) ' LIMITX--herrp: ',herrp(1:ncharp) c write (*,1999) ' LIMITX--herrx: ',herrx(1:ncharx) c1999 format (1x,a16,a80) c write (*,*) ' LIMITX--#char: t,d,p,x,sum: ',nchart,nchard, c & ncharp,ncharx,nchart+nchard+ncharp+ncharx herr='one or more inputs are out of range: '//herrt(1:nchart) & //herrd(1:nchard)//herrp(1:ncharp)//herrx(1:ncharx) & //hnull if (lerr) then ierr=abs(ierrt)+abs(ierrd)+abs(ierrp)+abs(ierrx) else if (lwarn) then ierr=-abs(ierrt)-abs(ierrd)-abs(ierrp)-abs(ierrx) end if end if c RETURN end !subroutine LIMITX c c ====================================================================== c subroutine LIMITK (htyp,icomp,t,D,p,tmin,tmax,Dmax,pmax,ierr,herr) c c returns limits of a property model (read in from the .fld files) for c a mixture component and/or checks input t, D, p against those limits c c This routine functions in the same manner as LIMITX except that the c composition x is replaced by the component number icomp. c c Attempting calculations below the mininum temperature and/or above c the maximum density will result in an error. These will often c correspond to a physically unreasonable state; also many equations of c state do not extrapolate reliably to lower T's and higher D's. c c A warning is issued if the temperature is above the maximum but below c 1.5 times the maximum; similarly pressures up to twice the maximum c result in only a warning. Most equations of state may be c extrapolated to higher T's and P's. Temperatures and/or pressures c outside these extended limits will result in an error. c c inputs: c htyp--flag indicating which models are to be checked [character*3] c 'EOS': equation of state for thermodynamic properties c 'ETA': viscosity c 'TCX': thermal conductivity c 'STN': surface tension c icomp--component number in mixture; 1 for pure fluid c t--temperature [K] c D--molar density [mol/L] c p--pressure [kPa] c x--composition array [mol frac] c N.B.--all inputs must be specified, if one or more are not c available, (or not applicable as in case of surface tension) c use reasonable values, such as: c t = tnbp c D = 0 c p = 0 c outputs: c tmin--minimum temperature for model specified by htyp [K] c tmax--maximum temperature [K] c Dmax--maximum density [mol/L] c pmax--maximum pressure [kPa] c ierr--error flag: 0 = all inputs within limits c <>0 = one or more inputs outside limits: c -1 = 1.5*tmax > t > tmax c 1 = t < tmin or t > 1.5*tmax c 2 = D > Dmax or D < 0 c -4 = 2*pmax > p > pmax c 4 = p < 0 or p > 2*pmax c if multiple inputs are outside limits, ierr = abs[sum(ierr)] c with the sign determined by the most severe excursion c (ierr > 0 indicate an error--calculations not possible, c ierr < 0 indicate a warning--results may be questionable) c herr--error string (character*255 variable if ierr<>0) c c written by M. McLinden, NIST Phys & Chem Properties Div, Boulder, CO c 03-18-97 MM, original version; based on LIMITX c 06-03-97 MM, initialize ierr = 0 and herr = hnull c 10-02-97 MM, add compiler switches to allow access by DLL c c compiler switches to allow access by DLL; for use with Digital Visual c Fortran; these should be treated as comments by all other compilers c !MS$ATTRIBUTES DLLEXPORT :: LIMITK c implicit double precision (a-h,o-z) implicit integer (i-n) logical lerr,lwarn,ltemp parameter (ncmax=5) !max number of components in mixture parameter (n0=-ncmax,nx=ncmax) parameter (nrf0=0) !lower limit for transport ref fluid arrays character*1 htab,hnull character*3 htyp character*75 herrt,herrd,herrp character*120 herrx character*255 herr common /NCOMP/ nc common /CHAR/ htab,hnull common /CCON/ wm(n0:nx),ttp(n0:nx),tnbp(n0:nx), & tcrit(n0:nx),pcrit(n0:nx),Dcrit(n0:nx),Zcrit(n0:nx), & accen(n0:nx),dipole(n0:nx) common /EOSLIM/ tmeos(n0:nx),txeos(n0:nx),peos(n0:nx),Deos(n0:nx) common /WLMSTN/ tmstn(n0:nx),txstn(n0:nx) common /WLMTCX/ tmtcx(nrf0:nx),txtcx(nrf0:nx),ptcx(nrf0:nx), & Dtcx(nrf0:nx) common /WLMETA/ tmeta(nrf0:nx),txeta(nrf0:nx),peta(nrf0:nx), & Deta(nrf0:nx) c c initialize flags and strings c c write (*,*) ' LIMITK--entering with htyp,t = ',htyp,t ierr=0 ierrt=0 ierrd=0 ierrp=0 herr=hnull herrt=' ' herrd=' ' herrp=' ' herrx=' ' nchart=1 nchard=1 ncharp=1 ncharx=1 lerr=.false. lwarn=.false. i=icomp c if (htyp.eq.'EOS' .or. htyp.eq.'eos') then c equation of state ltemp=.true. !EOS cannot be extrapolated to lower temps tmin=tmeos(i) tmax=txeos(i) Dmax=Deos(i) pmax=peos(i) else if (htyp.eq.'STN' .or. htyp.eq.'stn') then c surface tension model ltemp=.false. !STN may be extrapolated to lower temps tmin=tmstn(i) tmax=txstn(i) Dmax=-9.99d99 !density and pressure limits not applicable pmax=-9.99d99 !for surface tension--set to large number else if (htyp.eq.'TCX' .or. htyp.eq.'tcx') then c thermal conductivity ltemp=.true. !transport cannot be extrapolated to lower temps tmin=tmtcx(i) tmax=txtcx(i) Dmax=Dtcx(i) pmax=ptcx(i) else if (htyp.eq.'ETA' .or. htyp.eq.'eta') then c viscosity ltemp=.true. !transport cannot be extrapolated to lower temps tmin=tmeta(i) tmax=txeta(i) Dmax=Deta(i) pmax=peta(i) 160 continue else c unknown model specification--use EOS limits ltemp=.true. tmin=tmeos(i) tmax=txeos(i) Dmax=Deos(i) pmax=peos(i) end if c c check inputs against limits c if (t.lt.tmin) then if (ltemp) then lerr=.true. ierrt=1 else lwarn=.true. ierrt=-1 end if write (herrt,1010) t,tmin nchart=70 1010 format (' temperature below lower limit, T =',1pe11.3, & ' K, Tmin =',1pe11.3,' K;') else if (t.gt.1.5d0*tmax) then lerr=.true. ierrt=1 write (herrt,1011) t,tmax nchart=72 1011 format (' temperature > 1.5 x upper limit, T =',1pe11.3, & ' K, Tmax =',1pe11.3,' K;') else if (t.gt.tmax) then lwarn=.true. ierrt=-1 write (herrt,1012) t,tmax nchart=70 1012 format (' temperature above upper limit, T =',1pe11.3, & ' K, Tmax =',1pe11.3,' K;') end if if (D.lt.0.0d0) then lerr=.true. ierrd=2 write (herrd,1020) D nchard=36 1020 format (' density < 0, D =',1pe11.3,' mol/L;') else if (D.gt.Dmax) then lerr=.true. ierrd=2 write (herrd,1021) D,Dmax nchard=74 1021 format (' density above upper limit, D =',1pe11.3, & ' mol/L, Dmax =',1pe11.3,' mol/L;') end if if (p.lt.0.0d0) then lerr=.true. ierrp=4 write (herrp,1040) p ncharp=34 1040 format (' pressure < 0, P =',1pe11.3,' kPa;') else if (p.gt.2.0d0*pmax) then lerr=.true. ierrp=4 write (herrp,1042) p,pmax ncharp=71 1042 format (' pressure > 2 x upper limit, P =',1pe11.3, & ' kPa, Pmax =',1pe11.3,' kPa;') else if (p.gt.pmax) then lwarn=.true. ierrp=-4 write (herrp,1044) p,pmax ncharp=71 1044 format (' pressure above upper limit, P =',1pe11.3, & ' kPa, Pmax =',1pe11.3,' kPa;') end if c c compose error string and compute overall value of ierr c if (lerr .or. lwarn) then c write (*,*) ' LIMITK--nchart,d,p,x:',nchart,nchard,nchard,ncharx c write (*,1999) ' LIMITK--herrt: ',herrt(1:nchart) c write (*,1999) ' LIMITK--herrd: ',herrd(1:nchard) c write (*,1999) ' LIMITK--herrp: ',herrp(1:ncharp) c write (*,1999) ' LIMITK--herrx: ',herrx(1:ncharx) c1999 format (1x,a16,a80) c write (*,*) ' LIMITK--#char: t,d,p,x,sum: ',nchart,nchard, c & ncharp,ncharx,nchart+nchard+ncharp+ncharx herr='one or more inputs are out of range: '//herrt(1:nchart) & //herrd(1:nchard)//herrp(1:ncharp)//herrx(1:ncharx) & //hnull if (lerr) then ierr=abs(ierrt)+abs(ierrd)+abs(ierrp) else if (lwarn) then ierr=-abs(ierrt)-abs(ierrd)-abs(ierrp) end if end if c RETURN end !subroutine LIMITK c c ====================================================================== c subroutine ERRMSG (ierr,herr) c c write error messages to default output; this subroutine should be c called immediately after any call to a subroutine which potentially c can error out c c inputs: c ierr--error flag: 0 = successful (no message will be written) c <0 = warning c >0 = error c herr--error string (character*255 variable) c c outputs: c none--error string written to default output c c N.B. the statement which writes output to the screen is c commented out to avoid problems with DLL; this must be c uncommented if you wish to see error messages on the screen; c alternately, open a file from within your application and c replace the "write (*,1000)" with "write (unit=i,1000)" to c write the messages to that file (where i is logical unit) c c written by M. McLinden, NIST Thermophysics Division, Boulder, Colorado c 09-11-95 MM, original version c 07-30-96 MM, also write out the value of ierr c 03-26-97 EWL, change name ERROR --> ERRMSG as 'error' is standard c routine in Lahey Fortran90 c 10-02-97 MM, add compiler switches to allow access by DLL c c compiler switches to allow access by DLL; for use with Digital Visual c Fortran; these should be treated as comments by all other compilers c !MS$ATTRIBUTES DLLEXPORT :: ERRMSG c implicit integer (i-k,m,n) character*255 herr c c herr=herr !avoid compiler warning, but possible segmentation violation if (ierr.ne.0) then d write (*,1000) ierr,herr end if d1000 format (1x,'ierr = ',i4,2x,a255) c RETURN end !subroutine ERRMSG c c c 1 2 3 4 5 6 7 c23456789012345678901234567890123456789012345678901234567890123456789012 c c ====================================================================== c end file utility.f c ======================================================================