Python Can Fortran 77 Code Be Used to Debug Python Code for Solving ODEs Using Radau5?
- Thread starter member 657093
- Start date
Click For Summary
The discussion centers around the challenges of translating Fortran code into Python, particularly for a system of 66 ordinary differential equations (ODEs) related to atmospheric emissions. The original poster seeks assistance in running the Fortran code to obtain variable values for comparison with their Python implementation. They express difficulty in understanding the Fortran code, noting that it lacks a main program to call the necessary subroutines and print results. Participants emphasize the need for a main program to execute the subroutines correctly and suggest that without it, the Fortran code cannot be run as intended. There is a consensus that debugging the Fortran code is essential before any translation can be effectively completed. Some participants recommend hiring a Fortran programmer for more specialized help, as the code's current state does not provide the expected output. The conversation highlights the complexities of working with legacy code and the importance of having complete, functional code before attempting to translate it into another programming language.
Technology news on Phys.org
Filip Larsen
Gold Member
- 2,030
- 974
Perhaps you can use https://www.onlinegdb.com/online_fortran_compiler or similar.
member 657093
I don't know Fortran even though I've already tried this link. But I can't get it to give me the values for my variables!!Filip Larsen said:Perhaps you can use https://www.onlinegdb.com/online_fortran_compiler or similar.
FactChecker
Science Advisor
Homework Helper
- 9,327
- 4,618
I don't see anywhere that the final solution is printed. It looks like you need to write a main program that calls these subroutines and then prints the values. You should see if the reference that had this code also has a sample of what and how to call the subroutines and print results.
member 657093
This piece of code is the actual formulation of a system of 66 ODEs (66 species) to solve for atmospheric emissions of several compounds. I am trying to replicate the formulation in Python because my solver is Python-based. However, if my formulation is wrong then I won't be able to solve it. As I don't understand Fortran, I need someone to provide me with the values of the variables in the actual formulation like RC, DJ, Y, T for TIME=331250 for comparison with my Python formulation.FactChecker said:I don't see anywhere that the final solution is printed. It looks like you need to write a main program that calls these subroutines and then prints the values. You should see if the reference that had this code also has a sample of what and how to call the subroutines and print results.
FactChecker
Science Advisor
Homework Helper
- 9,327
- 4,618
Right, but something has to call these subroutines in the correct way to get answers. An example of that would really help. Someone might know FORTRAN very well (Not me. I am rusty and don't have a compiler.) and still not know how to use these subroutines.Vick said:This piece of code is the actual formulation of a system of 66 ODEs (66 species) to solve for atmospheric emissions of several compounds. I am trying to replicate the formulation in Python because my solver is Python-based. However, if my formulation is wrong then I won't be able to solve it. As I don't understand Fortran, I need someone to provide me with the values of the variables in the actual formulation like RC, DJ, Y, T for TIME=331250 for comparison with my Python formulation.
If you know how to do it, even with your Python version, that would probably help a lot.
member 657093
You want my Python formulation?FactChecker said:Right, but something has to call these subroutines in the correct way to get answers. An example of that would really help. Someone might know FORTRAN very well (Not me. I am rusty and don't have a compiler.) and still not know how to use these subroutines.
If you know how to do it, even with your Python version, that would probably help a lot.
Attachments
PeterDonis
Mentor
- 49,261
- 25,312
Please do not post code in attachments. You can use BBCode tags to put code directly in your post.Vick said:You want my Python formulation?
member 657093
What if the code is very long?PeterDonis said:Please do not post code in attachments. You can use BBCode tags to put code directly in your post.
PeterDonis
Mentor
- 49,261
- 25,312
It will still be more readable in a BBCode code block than an attachment.Vick said:What if the code is very long?
Or, if you have it online already in some accessible location (like a public github repository), you can post a link to that.
Also, if the code is really that long and complicated, expecting people to help you rewrite it in a forum discussion here might be too much to expect.
member 657093
Ok understood. But I'm actually expecting them to copy and run it on their compiler and to provide me with the results.PeterDonis said:It will still be more readable in a BBCode code block than an attachment.
Or, if you have it online already in some accessible location (like a public github repository), you can post a link to that.
Also, if the code is really that long and complicated, expecting people to help you rewrite it in a forum discussion here might be too much to expect.
PeterDonis
Mentor
- 49,261
- 25,312
That might be too much to expect here too. You would need someone who was familiar not just with FORTRAN but with this particular code. The best place to find such a person would be at whatever place the code originally came from.Vick said:I'm actually expecting them to copy and run it on their compiler and to provide me with the results.
member 657093
[CODE lang="python" title="EMEP formulation"]import numpy as nptt = np.empty(10)FactChecker said:Right, but something has to call these subroutines in the correct way to get answers. An example of that would really help. Someone might know FORTRAN very well (Not me. I am rusty and don't have a compiler.) and still not know how to use these subroutines.
If you know how to do it, even with your Python version, that would probably help a lot.
tt[0] = 4*3600
tt[1] = 20*3600
for i in range(1,5):
tt[2*i] = tt[0] +24*3600*i
tt[2*i+1] = tt[1] +24*3600*i
print(tt)
# initial conditions
u = np.empty(66)
for i in range(0,13):
u = 1.e+7
for i in range(13, 66):
u = 100.
u[0] = 1.e+9
u[1] = 5.e+9
u[2] = 5.e+9
u[3] = 3.8e+12
u[4] = 3.5e+13
u[13] = 5.e+11
u[37] = 1.e-3
print()
print(u)# listing of species
ls = ['NO', 'NO2', 'SO2', 'CO', 'CH4', 'C2H6',
'NC4H10', 'C2H4', 'C3H6', 'OXYL', 'HCHO', 'CH3CHO',
'MEK', 'O3', 'HO2', 'HNO3', 'H2O2', 'H2',
'CH3O2', 'C2H5OH', 'SA', 'CH3O2H', 'C2H5O2', 'CH3COO',
'PAN', 'SECC4H', 'MEKO2', 'R2OOH', 'ETRO2', 'MGLYOX',
'PRRO2', 'GLYOX', 'OXYO2', 'MAL', 'MALO2', 'OP',
'OH', 'OD', 'NO3', 'N2O5', 'ISOPRE', 'NITRAT',
'ISRO2', 'MVK', 'MVKO2', 'CH3OH', 'RCO3H', 'OXYO2H',
'BURO2H', 'ETRO2H', 'PRRO2H', 'MEKO2H', 'MALO2H', 'MACR',
'ISNI', 'ISRO2H', 'MARO2', 'MAPAN', 'CH2CCH3', 'ISONO3',
'ISNIR', 'MVKO2H', 'CH2CHR', 'ISNO3H', 'ISNIRH', 'MARO2H']
# mixing height in cm
HMIX = 1.2e+5
# distribution of VOC emissions among species
FRAC6=0.07689
FRAC7=0.41444
FRAC8=0.03642
FRAC9=0.03827
FRAC10=0.24537
FRAC13=0.13957
VEKT6=30.0
VEKT7=58.0
VEKT8=28.0
VEKT9=42.0
VEKT10=106.0
VEKT13=46.0
VMHC=1.0/(FRAC6/VEKT6+FRAC7/VEKT7+FRAC8/VEKT8+ \
FRAC9/VEKT9+FRAC10/VEKT10+FRAC13/VEKT13)# values for NOX and HC emissions in molecules/cm**2xs
EMNOX = 2.5e+11
EMHC = 2.5e+11# rural case
FACISO = 1.0
FACHC = 1.0
FACNOX = 1.0
# Emissions in molec/(cm^2*s) of NO, NO2, SO2, CO, CH4, C2H6, NC4H10,
# C2H4, C3H6, O-XYLENE, C2H5OH and ISOPRENE
EMIS1 = EMNOX * FACNOX
EMIS2 = 0.0
EMIS3 = EMNOX * FACNOX
EMIS4 = EMHC*10.0 * FACHC
EMIS5 = 0.0
EMIS6 = EMHC*FRAC6/VEKT6*VMHC * FACHC
EMIS7 = EMHC*FRAC7/VEKT7*VMHC * FACHC
EMIS8 = EMHC*FRAC8/VEKT8*VMHC * FACHC
EMIS9 = EMHC*FRAC9/VEKT9*VMHC * FACHC
EMIS10= EMHC*FRAC10/VEKT10*VMHC* FACHC
EMIS11= 0.5 * FACISO * EMHC
EMIS12= 0.0
EMIS13= EMHC*FRAC13/VEKT13*VMHC* FACHC# time-dependent EMEP coefficients
M = 2.55e+19
O2 = 5.2e+18
XN2 = 1.99e+19
RPATH3 = 0.65
RPATH4 = 0.35# dissociation rate coefficient
TIME = 331250 # to input
TIMEH=TIME/3600.
ITIMEH=int(TIMEH)
I24HRS=ITIMEH/24+1
TIMEOD=int(24. -(I24HRS-1))+(TIMEH-ITIMEH)
print()
print(TIMEOD)
# XLHA local hour angle
XLHA=(1.0+TIMEOD*3600.0/4.32e+4)*np.pi
# FI (Norwegian PHI!) latitude, dekl solar declination
# here latitude = 50 deg. N
FI=50.0*np.pi/180.0
DEKL=23.5*np.pi/180.0
SEC=1.0/(np.cos(XLHA)*np.cos(FI)*np.cos(DEKL)+np.sin(FI)*np.sin(DEKL))# def of temperature variation
# XP=8.7D-5*TIMEOD*3600.D0-2.83
# T=8.3D0*SIN(XP)+289.86
# for simplicity
# T temperature in K
T=298.0
# def of water vapor concentration
XQ=-7.93e-5*TIMEOD*3600.0+2.43
RH=23.0*np.sin(XQ)+66.5
XZ=(597.3-0.57*(T-273.16))*18.0/1.986*(1.0/T-1.0/273.16)
H2O=6.1078*np.exp(-XZ)*10.0/(1.38e-16*T)*RH
A = [1.23e-3,2.00e-4,1.45e-2,2.20e-5,3.00e-6, \
5.40e-5,6.65e-5,1.35e-5,2.43e-5,5.40e-4, \
2.16e-4,5.40e-5,3.53e-2,8.94e-2,3.32e-5,2.27e-5]
B = [0.60, 1.40, 0.40, 0.75, 1.25, \
0.79, 0.60, 0.94, 0.88, 0.79, \
0.79, 0.79, 0.081, 0.059, 0.57, 0.62]
# SEC = 1./np.cos(THETA) # THETA is solar zenith angle# Calculate values of photolysis rates DJ(1..16), based
# upon RGD A & B coefficients and correction factors from HOUGH (1988)
DJ = np.empty(16)
if TIMEOD < 4.0 or TIMEOD >= 20.0:
# in the dark
for i in range(16):
DJ = 1.0e-40
else:
# daytime
for i in range(16):
DJ = A*np.exp(-B*SEC)
if DJ < 0.0:
break
print()
print(DJ)
# Set up chemical reaction rate coefficients:
RC = np.empty(266)
for i in range(266):
RC = 0.0
# assuming 80% N2, 20% O2
RC[0]=5.7e-34*(T/300.0)**(-2.8) * M * O2
# unchanged, as source of O+NO+O2 reaction rate unknown.
RC[4]=9.6e-32*(T/300.0)**(-1.6) * M
# estimate from Demore(1990) (=A92) O(d)+N2 and DeMore O(D)+O2
RC[6] =2.0e-11*np.exp(100.0/T) * M
RC[10] =1.8e-12*np.exp(-1370.0/T)
RC[11] =1.2e-13*np.exp(-2450.0/T)
RC[12] =1.9e-12*np.exp(-1000.0/T)
RC[13] =1.4e-14*np.exp(-600.0/T)
RC[14] =1.8e-11*np.exp(+110.0/T)
RC[16] =3.7e-12*np.exp(240.0/T)
# M.J (from Wayne et al.)
RC[18] =7.2e-14*np.exp(-1414.0/T)
# RC[18] =7.2e-13*np.exp(-1414.0/T)
# M.J suggests that rc(27) be omitted:
# RC[27] =8.5e-13*np.exp(-2450.0/T)
# My change to get similar to A92 troe.
RC[28] =7.1e+14*np.exp(-11080.0/T)
RC[29] =4.8e-11*np.exp(+250.0/T)
# De More,1990 .. no change : oh + h2o2
RC[30] =2.9e-12*np.exp(-160.0/T)
# : oh + h2
RC[32] =7.7e-12*np.exp(-2100.0/T)
# My, similar to DeMore et al complex : oh+hno3
RC[34] =1.0e-14*np.exp(785.0/T)
# Mike Jenkin`s suggestion for ho2 + ho2 reactions: (from DeMore et al.)
RC[35] =2.3e-13*np.exp(600.0/T)
RC[35] = RC[36] + M * 1.7e-33*np.exp(1000.0/T)
RC[35] = RC[35] * (1.0 + 1.4e-21 * H2O *np.exp(2200.0/T))
RC[58] =3.9e-12*np.exp(-1885.0/T)
# : ch3o2 + no
RC[59] =4.2e-12*np.exp(180.0/T)
# A92 + A90 assumption that ka = 0.5D0 * k
RC[60] =5.5e-14*np.exp(365.0/T)
# A92 + A90 assumption that kb = 0.5D0 * k
RC[61] =5.5e-14*np.exp(365.0/T)
RC[62] =3.3e-12*np.exp(-380.0/T)
# : ho2 + ch3o2
RC[64] =3.8e-13*np.exp(780.0/T)
# new: ch3ooh + oh -> hcho + oh
RC[66] =1.0e-12*np.exp(190.0/T)
# new: ch3ooh + oh -> ch3o2
RC[67] =1.9e-12*np.exp(190.0/T)
RC[70] =7.8e-12*np.exp(-1020.0/T)
# new: c2h5o2 + ho2 -> c2h5ooh (r2ooh)
RC[73] =6.5e-13*np.exp(650.0/T)
RC[74] =5.6e-12*np.exp(310.0/T)
# TOR90 assumption w.r.t. rc(67) : c2h5ooh + oh -> ch3cho + oh
# RC[75] = 5.8 * RC[66]
RC[75] = 5.8e-12*np.exp(190.0/T)
# : approximation to troe expression
RC[77] =1.34e+16*np.exp(-13330.0/T)
# additional reactions :-
# : ho2 + ch3coo2 -> rco3h
RC[87] =1.3e-13*np.exp(1040.0/T)
# : ho2 + ch3coo2 -> rco2h + o3
RC[88] =3.0e-13*np.exp(1040.0/T)
RC[93] =2.8e-12*np.exp(530.0/T)
# D & J, gives results very close to A92
RC[80] =1.64e-11*np.exp(-559.0/T)RC[82] =RC[59]
RC[104]=RC[59]
RC[109]=RC[59]
# A90/PS isnir + no
RC[161]=RC[59]
# A90/PS isono3 + no
RC[163]=RC[59]
# From RGD, but very similar to A92 Troe
RC[108]=1.66e-12*np.exp(474.0/T)
RC[111]=1.2e-14*np.exp(-2630.0/T)
RC[122]=6.5e-15*np.exp(-1880.0/T)
RC[125] = RC[59]
RC[219] = RC[59]
RC[235] = RC[59]
# natural voc reactions #
# isoprene + o3 -> products
RC[149] = 12.3e-15*np.exp(-2013.0/T)
# isoprene + oh -> isro2
RC[150] = 2.54e-11*np.exp(410.0/T)
# isoprene-RO2 + no
RC[151] = RC[59]
# methylvinylketone (mvk) + oh
RC[152] = 4.13e-12*np.exp(452.0/T)
# mvko2 + no
RC[153] = RC[59]
# macr + oh
RC[157] = 1.86e-11*np.exp(175.0/T)
# ch2cch3 + no
RC[158] = RC[59]
# mvk + o3
RC[159] = 4.32e-15*np.exp(-2016.0/T)
# RC[254] = 9.9e-16*np.exp(-731.0/T)
# aerosol formation and depositions ..x
# parameterization of heterogeneous loss in 1./s for humidities
# less than 90%. applied to hno3, h2o2, h2so4, ch3o2h.
RC[42]=5.e-6
if(RH > 0.90):
RC[42]=1.e-4
RC[43] =RC[42]
RC[44] =RC[42]RC[7] =2.2e-10
# My (?) , similar to A92 troe expression.
RC[19] =1.4e-12
# My (?) , similar to A92 troe expression.
RC[20] =1.4e-11
# RGD Note (=DeMore?)
RC[25] =4.1e-16
# RGD
RC[38] =1.35e-12
# RGD
RC[39] =4.0e-17
# A92, assuming all products are ch3cho
RC[63] =3.2e-12
# A92, with temperature dependance neglected.
RC[65] =9.6e-12
RC[68] =5.8e-16
RC[69] =2.4e-13
RC[71] =8.9e-12
# A92 : approximation to troe expression
RC[76] =1.0e-11
# : ch3coo2 + no
RC[78] =2.0e-11
#: sum of two pathways
RC[79] =1.1e-11
# cmj RC[83] =2.5e-14
# kho2ro2 : estimate of rate of ho2 + higher RO2, suggested by Yvonne
RC[84] =1.0e-11
# ignoring slight temperature dependance
RC[85] =1.15e-12
# MJ suggestion.. combine oh + secc4h9o2, meko2 rates =>
# RC[86]= RC[67] + RC[85], approx. at 298
RC[86]= 4.8e-12
# new A92 : oh + ch3co2h -> ch3o2
RC[89] =8.0e-13
# Approximates to A92 Troe ...
RC[124]=2.86e-11
# rate for ch2chr + oh, = k68+k125 (propene), Yv.
RC[145] = 3.2e-11
# rate for isono3h + oh, = k156 (isro2h), Yv.
RC[146] = 2.0e-11
# MY GUESS rate of oh + mvko2h
RC[147] = 2.2e-11
# MY GUESS rate of oh + other biogenic ooh
RC[148] = 3.7e-11
# kho2ro2 : estimate of rate of ho2 + higher RO2, suggested by Yvonne
# isro2 + ho2
RC[154] =RC[84]
# isro2h + oh
RC[155] =2.0e-11
# isro2h + o3
RC[156] =8.0e-18
# isni + oh
RC[160] =3.35e-11
# isopre + no3
RC[162] =7.8e-13
# RC[162] =7.8e-16
# Unchanged, also in IVL scheme
RC[218]=2.0e-11
RC[220]=1.1e-11
RC[221]=1.7e-11
# MJ suggestion.. combine oh + malo2h rates =>
# RC[222]= RC[67] + RC[218]
RC[222]= 2.4e-11
RC[233]=1.37e-11
# MJ suggestion.. combine rc(68) with rc(234) =>
# RC[234]= RC[67] + RC[233]
RC[234]= 1.7e-11
# deposition loss rate coefficients vd/hmix, vd in cm/s.
# hno3 calculated rc(46)
# so2 0.5 rc(47)
# h2o2 0.5 rc(47)
# no2 0.2 rc(48)
# o3 0.5 rc(49)
# pan 0.2 rc(50)
# h2so4 0.1 rc(51)
# simple approx. for now - reduce all vg by 4 at night to allow
# for surface inversion......
delta=1.0
if(TIMEOD >= 20.0 or TIMEOD < 4.0):
delta=0.25
# if(timeod.ge.20.D0.or.timeod.le.4.D0) delta=0.25D0
# if (night) delta=0.25D0
RC[45] =2.0 * delta /HMIX
RC[46] =0.5 * delta /HMIX
RC[47] =0.2 * delta /HMIX
RC[48] =0.5 * delta /HMIX
RC[49] =0.2 * delta /HMIX
RC[50] =0.1 * delta /HMIX
# dep. of organic peroxides = 0.5 cms-1
RC[51] = 0.5 *delta /HMIX
# dep. of ketones, RCHO = 0.3 cms-1
RC[52] = 0.3 *delta /HMIX
print()
print(RC)
# ODEs
Du = np.empty(66)
Du[1-1] = DJ[3-1]*u[2-1]+DJ[13-1]*u[39-1]+RC[19-1]*u[2-1]*u[39-1]+EMIS1/HMIX- \
(RC[5-1]*u[36-1]+RC[11-1]*u[14-1]+RC[17-1]*u[15-1]+RC[72-1]*u[23-1]+RC[79-1]* \
(u[24-1]+ u[57-1])+RC[15-1]*u[39-1]+RC[60-1]*(u[19-1]+u[26-1]+u[27-1]+u[29-1]+u[31-1]+u[33-1]+ \
u[35-1]+u[43-1]+u[45-1]+u[59-1]+u[61-1]+u[60-1]))*u[1-1]
Du[2-1] = u[1-1]*(RC[5-1]*u[36-1]+RC[11-1]*u[14-1]+RC[17-1]*u[15-1]+RC[72-1]*u[23-1]+ \
RC[79-1]*(u[24-1]+u[57-1])+0.2e+1*RC[15-1]*u[39-1])+RC[60-1]*u[1-1]* \
(u[19-1]+u[26-1]+u[27-1]+u[29-1]+u[31-1]+u[33-1]+u[35-1]+u[59-1])+ \
RC[60-1]*u[1-1]*(0.86*u[43-1]+0.19e+1*u[61-1]+0.11e+1*u[60-1]+0.95*u[45-1])+ \
DJ[14-1]*u[39-1]+DJ[5-1]*u[16-1]+DJ[15-1]*u[40-1]+RC[29-1]*u[40-1]+RC[78-1]* \
(u[25-1]+u[58-1])-(DJ[3-1]+RC[12-1]*u[14-1]+RC[20-1]*u[39-1]+RC[21-1]*u[37-1]+RC[48-1]+RC[77-1]* \
(u[24-1]+u[57-1]))*u[2-1]
Du[3-1] = EMIS3/HMIX-(RC[39-1]*u[37-1]+RC[40-1]*u[19-1]+RC[47-1])*u[3-1]
Du[4-1] = EMIS4/HMIX+u[37-1]*(RC[66-1]*u[11-1]+2.0*RC[221-1]*u[32-1]+RC[222-1]* u[30-1])+ \
u[14-1]*(0.44*RC[112-1]*u[8-1]+0.4*RC[123-1]*u[9-1]+0.5e-1*RC[160-1]*u[44-1]+0.5e-1* \
RC[150-1]*u[41-1])+u[11-1]*(DJ[6-1]+DJ[7-1]+RC[69-1]*u[39-1])+DJ[8-1]*u[12-1]+DJ[11-1]*u[30-1]+2.0*DJ[7-1]*u[32-1]-RC[70-1]*u[37-1]*u[4-1]
Du[5-1] = EMIS5/HMIX+0.7e-1*RC[123-1]*u[14-1]*u[9-1]-RC[59-1]*u[37-1]*u[5-1]
Du[6-1] = EMIS6/HMIX-RC[71-1]*u[37-1]*u[6-1]
Du[7-1] = EMIS7/HMIX-RC[81-1]*u[37-1]*u[7-1]
Du[8-1] = EMIS8/HMIX-(RC[109-1]*u[37-1]+RC[112-1]*u[14-1])*u[8-1]
Du[9-1] = EMIS9/HMIX+0.7e-1*RC[150-1]*u[14-1]*u[41-1]-(RC[123-1]*u[14-1]+RC[125-1]*u[37-1])*u[9-1]
Du[10-1] = EMIS10/HMIX-RC[234-1]*u[37-1]*u[10-1]
Du[11-1] = u[19-1]*(RC[60-1]*u[1-1]+(2.0*RC[61-1]+RC[62-1])*u[19-1]+RC[80-1]*u[24-1]+RC[40-1]*u[3-1])+ \
u[37-1]*(RC[63-1]*u[46-1]+RC[67-1]*u[22-1])+u[1-1]*RC[60-1]* \
(2.0*u[29-1]+u[31-1]+0.74*u[43-1]+0.266*u[45-1]+0.15*u[60-1])+u[14-1]* \
(0.5*RC[123-1]*u[9-1]+RC[112-1]*u[8-1]+0.7*RC[157-1]*u[56-1]+0.8*RC[160-1]*u[44-1]+0.8*RC[150-1]* \
u[41-1])+2.0*DJ[7-1]*u[32-1]+DJ[16-1]* \
(u[22-1]+0.156e+1*u[50-1]+u[51-1])-(RC[66-1]*u[37-1]+DJ[6-1]+DJ[7-1]+RC[69-1]*u[39-1]+RC[53-1])*u[11-1]
Du[12-1] = u[1-1]*(RC[72-1]*u[23-1]+RC[83-1]*u[26-1]*RPATH4+RC[105-1]*u[27-1]+RC[126-1]*u[31-1]+ \
0.95*RC[162-1]*u[61-1]+0.684*RC[154-1]*u[45-1])+u[37-1]* \
(RC[64-1]*u[20-1]+RC[76-1]*u[28-1]+RC[76-1]*u[50-1])+0.5*RC[123-1]*u[14-1]*u[9-1]+0.4e-1* \
RC[160-1]*u[14-1]*u[44-1]+DJ[16-1]*(u[28-1]+0.22*u[50-1]+0.35*u[49-1]+u[51-1]+u[52-1])- \
(DJ[8-1]+RC[75-1]*u[37-1]+RC[53-1])*u[12-1]
Du[13-1] = RC[83-1]*u[1-1]*u[26-1]*RPATH3+(0.65*DJ[16-1]+RC[76-1]*u[37-1])*u[49-1]+RC[76-1]*u[37-1]*u[51-1]+ \
(RC[159-1]*u[1-1]+DJ[16-1])*u[59-1]+0.95*RC[162-1]*u[1-1]*u[61-1]-(DJ[9-1]+RC[86-1]*u[37-1]+RC[53-1])*u[13-1]
Du[14-1] = RC[1-1]*u[36-1]+RC[89-1]*u[15-1]*u[24-1]-(RC[11-1]*u[1-1]+RC[12-1]*u[2-1]+RC[13-1]*u[37-1]+RC[14-1]*u[15-1]+RC[49-1]+ \
RC[112-1]*u[8-1]+RC[123-1]*u[9-1]+RC[157-1]*u[56-1]+RC[160-1]*u[44-1]+RC[150-1]* \
u[41-1]+DJ[1-1]+DJ[2-1])*u[14-1]
s1 = u[37-1]*(RC[13-1]*u[14-1]+RC[31-1]*u[17-1]+RC[33-1]*u[18-1]+RC[39-1]*u[3-1]+RC[63-1]*u[46-1]+RC[64-1]* \
u[20-1]+RC[66-1]*u[11-1]+RC[70-1]*u[4-1]+RC[221-1]*u[32-1])+u[19-1]* \
(RC[40-1]*u[3-1]+2.0*RC[61-1]*u[19-1]+0.5*RC[80-1]*u[24-1])+DJ[11-1]*u[30-1]+u[1-1]*RC[60-1]* \
(u[19-1]+u[29-1]+u[31-1]+u[33-1]+u[35-1]+0.95*u[45-1]+u[26-1]*RPATH3+0.78*u[43-1]+u[59-1]+ \
0.5e-1*u[61-1]+0.8*u[60-1])+RC[72-1]*u[1-1]*u[23-1]+DJ[8-1]*u[12-1]
Du[15-1] = s1+2.0*DJ[6-1]*u[11-1]+DJ[16-1]*(u[22-1]+u[28-1]+0.65*u[49-1]+u[50-1]+u[51-1]+u[48-1]+u[53-1])+ \
u[39-1]*(RC[26-1]*u[17-1]+RC[69-1]*u[11-1])+u[14-1]*(0.12*RC[112-1]*u[8-1]+0.28*RC[123-1]*u[9-1]+ \
0.6e-1*RC[160-1]*u[44-1])+0.6e-1*RC[150-1]*u[14-1]*u[41-1]- \
(RC[14-1]*u[14-1]+RC[17-1]*u[1-1]+RC[30-1]*u[37-1]+2.0*RC[36-1]* \
u[15-1]+RC[65-1]*u[19-1]+RC[74-1]*u[23-1]+(RC[88-1]+RC[89-1])*u[24-1]+ \
RC[85-1]*(u[26-1]+u[29-1]+u[31-1]+u[27-1]+u[57-1]+u[45-1]+u[61-1]+u[59-1]+u[33-1]+ \
u[35-1]+u[43-1]+u[60-1]))*u[15-1]
Du[16-1] = RC[21-1]*u[2-1]*u[37-1]+u[39-1]*(RC[26-1]*u[17-1]+RC[69-1]*u[11-1])-(RC[35-1]*u[37-1]+DJ[5-1]+RC[45-1])*u[16-1]
Du[17-1] = RC[36-1]*u[15-1]**2-(RC[31-1]*u[37-1]+DJ[4-1]+RC[43-1]+RC[26-1]*u[39-1]+RC[47-1])*u[17-1]
Du[18-1] = DJ[7-1]*u[11-1]+u[14-1]*(0.13*RC[112-1]*u[8-1]+0.7e-1*RC[123-1]*u[9-1])-RC[33-1]*u[37-1]*u[18-1]
Du[19-1] = u[37-1]*(RC[59-1]*u[5-1]+RC[68-1]*u[22-1])+u[24-1]*(RC[79-1]*u[1-1]+2.0*RC[94-1]*u[24-1])+ \
DJ[8-1]*u[12-1]+DJ[16-1]*u[47-1]+0.31*RC[123-1]*u[14-1]*u[9-1]-(RC[40-1]*u[3-1]+RC[60-1]*u[1-1]+ \
2.0*RC[61-1]*u[19-1]+2.0*RC[62-1]*u[19-1]+ \
RC[65-1]*u[15-1]+0.5*RC[80-1]*u[24-1])*u[19-1]
Du[20-1] = EMIS13/HMIX-RC[64-1]*u[37-1]*u[20-1]
Du[21-1] = (RC[40-1]*u[19-1]+RC[39-1]*u[37-1])*u[3-1]+0.5e-1*EMIS3/HMIX-RC[51-1]*u[21-1]
Du[22-1] = RC[65-1]*u[15-1]*u[19-1]-(RC[43-1]+DJ[16-1]+(RC[67-1]+RC[68-1])*u[37-1])*u[22-1]
Du[23-1] = u[37-1]*(RC[71-1]*u[6-1]+RC[68-1]*u[28-1])+0.35*DJ[16-1]*u[49-1]+RC[83-1]*u[1-1]*u[26-1]* \
RPATH4+DJ[9-1]*u[13-1]-(RC[72-1]*u[1-1]+RC[74-1]*u[15-1])*u[23-1]
Du[24-1] = u[37-1]*(RC[75-1]*u[12-1]+RC[222-1]*u[30-1]+RC[68-1]*u[47-1])+RC[105-1]* \
u[1-1]*u[27-1]+RC[78-1]*u[25-1]+DJ[11-1]*u[30-1]+DJ[9-1]*u[13-1]+DJ[16-1]*u[52-1]+ \
0.684*RC[154-1]*u[1-1]*u[45-1]-(RC[77-1]*u[2-1]+RC[79-1]*u[1-1]+RC[80-1]*u[19-1]+ \
2.0*RC[94-1]*u[24-1]+(RC[88-1]+RC[89-1])*u[15-1])*u[24-1]
Du[25-1] = RC[77-1]*u[24-1]*u[2-1]-(RC[50-1]+RC[78-1])*u[25-1]
Du[26-1] = u[37-1]*(RC[81-1]*u[7-1]+RC[68-1]*u[49-1])-(RC[83-1]*u[1-1]+RC[85-1]*u[15-1])*u[26-1]
Du[27-1] = u[37-1]*(RC[86-1]*u[13-1]+RC[87-1]*u[52-1])-(RC[105-1]*u[1-1]+RC[85-1]*u[15-1])*u[27-1]
Du[28-1] = RC[74-1]*u[15-1]*u[23-1]-((RC[76-1]+RC[68-1])*u[37-1]+DJ[16-1]+RC[52-1])*u[28-1]
Du[29-1] = u[37-1]*(RC[109-1]*u[8-1]+RC[68-1]*u[50-1])-(RC[110-1]*u[1-1]+RC[85-1]*u[15-1])*u[29-1]
Du[30-1] = RC[236-1]*u[1-1]*u[33-1]+RC[220-1]*u[1-1]*u[35-1]+0.266*RC[154-1]*u[1-1]*u[45-1]+ \
0.82*RC[160-1]*u[14-1]*u[44-1]+DJ[16-1]*(u[48-1]+u[53-1])-(DJ[11-1]+RC[222-1]*u[37-1])*u[30-1]
Du[31-1] = u[37-1]*(RC[125-1]*u[9-1]+RC[68-1]*u[51-1])-(RC[126-1]*u[1-1]+RC[85-1]*u[15-1])*u[31-1]
Du[32-1] = RC[220-1]*u[1-1]*u[35-1]+DJ[16-1]*u[53-1]-(2.0*DJ[7-1]+RC[221-1]*u[37-1])*u[32-1]
Du[33-1] = u[37-1]*(RC[234-1]*u[10-1]+RC[235-1]*u[48-1])-(RC[236-1]*u[1-1]+RC[85-1]*u[15-1])*u[33-1]
Du[34-1] = RC[236-1]*u[1-1]*u[33-1]+DJ[16-1]*u[48-1]-RC[219-1]*u[37-1]*u[34-1]
Du[35-1] = u[37-1]*(RC[219-1]*u[34-1]+RC[223-1]*u[53-1])-(RC[220-1]*u[1-1]+RC[85-1]*u[15-1])*u[35-1]
Du[36-1] = DJ[1-1]*u[14-1]+DJ[3-1]*u[2-1]+DJ[14-1]*u[39-1]+RC[7-1]*u[38-1]+0.2*RC[160-1]*u[14-1]* \
u[44-1]+0.3*RC[150-1]*u[14-1]*u[41-1]-(RC[1-1]+RC[5-1]*u[1-1])*u[36-1]s1 = 2.0*RC[8-1]*H2O*u[38-1]+u[15-1]*(RC[14-1]*u[14-1]+RC[17-1]*u[1-1])+2.0*DJ[4-1]*u[17-1]+DJ[5-1]*u[16-1]
s2 = s1+DJ[16-1]*(u[22-1]+u[28-1]+u[47-1]+u[49-1]+u[50-1]+u[52-1]+u[48-1]+u[53-1])
s3 = s2+u[14-1]*(0.15*RC[123-1]*u[9-1]+0.8e-1*RC[160-1]*u[44-1])
s4 = s3
s6 = 0.55*RC[150-1]*u[14-1]*u[41-1]
s8 = -1
s11 = RC[222-1]*u[30-1]+RC[75-1]*u[12-1]+RC[81-1]*u[7-1]+RC[87-1]*u[52-1]+RC[86-1]* \
u[13-1]+RC[235-1]*u[48-1]+RC[109-1]*u[8-1]+RC[125-1]*u[9-1]+RC[234-1]*u[10-1]+ \
RC[223-1]*u[53-1]+RC[219-1]*u[34-1]+RC[31-1]*u[17-1]+RC[21-1]*u[2-1]+RC[148-1]* \
u[62-1]+RC[64-1]*u[20-1]+RC[39-1]*u[3-1]+RC[71-1]*u[6-1]
s10 = s11+RC[30-1]*u[15-1]+RC[59-1]*u[5-1]+RC[70-1]*u[4-1]+RC[35-1]*u[16-1]+RC[13-1]* \
u[14-1]+RC[221-1]*u[32-1]+RC[68-1]*(u[22-1]+u[28-1]+u[47-1]+u[50-1]+u[51-1]+u[49-1])+ \
RC[66-1]*u[11-1]+RC[151-1]*u[41-1]+RC[153-1]*u[44-1]+RC[63-1]*u[46-1]+RC[33-1]*u[18-1]+ \
RC[158-1]*u[54-1]+RC[146-1]*u[63-1]+RC[149-1]*(u[65-1]+u[66-1])+RC[147-1]*u[64-1]+ \
RC[161-1]*u[55-1]
s11 = u[37-1]
s9 = s10*s11
s7 = s8*s9
s5 = s6+s7
Du[37-1] = s4+s5
Du[38-1] = DJ[2-1]*u[14-1]-(RC[7-1]+RC[8-1]*H2O)*u[38-1]
Du[39-1] = (RC[29-1]+DJ[15-1])*u[40-1]+RC[12-1]*u[14-1]*u[2-1]+RC[35-1]*u[37-1]*u[16-1]- \
(RC[15-1]*u[1-1]+RC[26-1]*u[17-1]+RC[163-1]*u[41-1]+RC[19-1]*u[2-1]+RC[20-1]* \
u[2-1]+DJ[13-1]+DJ[14-1]+RC[69-1]*u[11-1])*u[39-1]
Du[40-1] = RC[20-1]*u[39-1]*u[2-1]-(RC[29-1]+DJ[15-1]+RC[45-1])*u[40-1]
Du[41-1] = EMIS11/HMIX-(RC[151-1]*u[37-1]+RC[163-1]*u[39-1]+RC[150-1]*u[14-1])*u[41-1]
Du[42-1] = RC[45-1]*u[16-1]+2.0*RC[44-1]*u[40-1]-RC[51-1]*u[42-1]
Du[43-1] = u[37-1]*(RC[151-1]*u[41-1]+RC[156-1]*u[56-1])+0.12*RC[152-1]*u[1-1]* \
u[43-1]-(RC[152-1]*u[1-1]+RC[155-1]*u[15-1])*u[43-1]
Du[44-1] = RC[60-1]*u[1-1]*(0.42*u[43-1]+0.5e-1*u[60-1])+0.26*RC[150-1]*u[14-1]* \
u[41-1]-(RC[153-1]*u[37-1]+RC[160-1]*u[14-1])*u[44-1]
Du[45-1] = RC[153-1]*u[44-1]*u[37-1]+RC[148-1]*u[37-1]*u[62-1]-(RC[154-1]*u[1-1]+RC[85-1]*u[15-1])*u[45-1]
Du[46-1] = RC[62-1]*u[19-1]**2-RC[63-1]*u[37-1]*u[46-1]
Du[47-1] = RC[88-1]*u[15-1]*u[24-1]-(RC[68-1]*u[37-1]+DJ[16-1]+RC[52-1])*u[47-1]
Du[48-1] = RC[85-1]*u[15-1]*u[33-1]-(RC[235-1]*u[37-1]+DJ[16-1]+RC[52-1])*u[48-1]
Du[49-1] = RC[85-1]*u[15-1]*u[26-1]-((RC[76-1]+RC[68-1])*u[37-1]+DJ[16-1]+RC[52-1])*u[49-1]
Du[50-1] = RC[85-1]*u[15-1]*u[29-1]-((RC[76-1]+RC[68-1])*u[37-1]+DJ[16-1]+RC[52-1])*u[50-1]
Du[51-1] = RC[85-1]*u[15-1]*u[31-1]-((RC[76-1]+RC[68-1])*u[37-1]+DJ[16-1]+RC[52-1])*u[51-1]
Du[52-1] = RC[85-1]*u[15-1]*u[27-1]-(RC[87-1]*u[37-1]+DJ[16-1]+RC[52-1])*u[52-1]
Du[53-1] = RC[85-1]*u[15-1]*u[35-1]-(RC[223-1]*u[37-1]+DJ[16-1]+RC[52-1])*u[53-1]
Du[54-1] = RC[60-1]*u[1-1]*(0.32*u[43-1]+0.1*u[60-1])+0.67*RC[150-1]*u[14-1]*u[41-1]-RC[158-1]*u[37-1]*u[54-1]
Du[55-1] = RC[60-1]*u[1-1]*(0.14*u[43-1]+0.5e-1*u[45-1]+0.85*u[60-1])-RC[161-1]*u[37-1]*u[55-1]
Du[56-1] = RC[155-1]*u[15-1]*u[43-1]-(RC[156-1]*u[37-1]+RC[157-1]*u[14-1]+RC[52-1])*u[56-1]
Du[57-1] = 0.5*RC[158-1]*u[37-1]*u[54-1]+RC[78-1]*u[58-1]+RC[149-1]*u[37-1]*u[66-1]- \
(RC[77-1]*u[2-1]+RC[79-1]*u[1-1]+RC[85-1]*u[15-1])*u[57-1]
Du[58-1] = RC[77-1]*u[57-1]*u[2-1]-(RC[50-1]+RC[78-1])*u[58-1]
Du[59-1] = RC[79-1]*u[1-1]*u[57-1]+RC[146-1]*u[37-1]*u[63-1]-(RC[159-1]*u[1-1]+RC[85-1]*u[15-1])*u[59-1]
Du[60-1] = RC[163-1]*u[39-1]*u[41-1]+RC[147-1]*u[37-1]*u[64-1]-(RC[164-1]*u[1-1]+RC[85-1]*u[15-1])*u[60-1]
Du[61-1] = RC[161-1]*u[37-1]*u[55-1]+RC[149-1]*u[37-1]*u[65-1]-(RC[162-1]*u[1-1]+RC[85-1]*u[15-1])*u[61-1]
Du[62-1] = RC[85-1]*u[15-1]*u[45-1]-(RC[148-1]*u[37-1]+RC[52-1])*u[62-1]
Du[63-1] = RC[85-1]*u[15-1]*u[59-1]-(RC[146-1]*u[37-1]+RC[52-1])*u[63-1]
Du[64-1] = RC[85-1]*u[15-1]*u[60-1]-(RC[147-1]*u[37-1]+RC[52-1])*u[64-1]
Du[65-1] = RC[85-1]*u[15-1]*u[61-1]-(RC[149-1]*u[37-1]+RC[52-1])*u[65-1]
Du[66-1] = RC[85-1]*u[15-1]*u[57-1]-(RC[149-1]*u[37-1]+RC[52-1])*u[66-1]
print()
print(Du)
[/CODE]
phyzguy
Science Advisor
- 5,288
- 2,355
Have you tried using f2py? It allows you to compile the fortran code as a Python module.
https://numpy.org/devdocs/f2py/f2py-examples.html
https://numpy.org/devdocs/f2py/f2py-examples.html
Vanadium 50
Staff Emeritus
Science Advisor
Education Advisor
Gold Member
Dearly Missed
- 35,003
- 21,712
Are you sure "expect" is the word you want? Demanding work of volunteers is seldom the best strategy, Other adjectives might be applied.Vick said:But I'm actually expecting them to copy and run it on their compiler and to provide me with the results.
Besides:
FactChecker said:I don't see anywhere that the final solution is printed.
So what you're really asking is for us to debug the FORTRAN code first, as it does not do what you want it to.
member 657093
I am actually asking help from a Fortran programmer to provide me with the values of the variables RC, DJ, Y, T, DY for TIME=331250 from the Fortran code as it stands to compare with my Python values to see if I understood the formulation correctly.Vanadium 50 said:Are you sure "expect" is the word you want? Demanding work of volunteers is seldom the best strategy, Other adjectives might be applied.
Besides:So what you're really asking is for us to debug the FORTRAN code first, as it does not do what you want it to.
Vanadium 50
Staff Emeritus
Science Advisor
Education Advisor
Gold Member
Dearly Missed
- 35,003
- 21,712
I think your best bet then is to hire a FORTRAN programmer. If the FORTRAN doesn't do exactly what you want it to do, it is not reasonable to expect us to modify it, much less demand it.
jtbell
Staff Emeritus
Science Advisor
Homework Helper
- 16,029
- 7,745
I see several subroutines, but no main program. One of the subroutines (EMEPCF) is invoked (CALLed) by two of the others (FEVAL and JEVAL). None of the other subroutines (including FEVAL and JEVAL) are invoked anywhere in this code.
Clearly you need a main program that invokes these subroutines, in some specific sequence, and probably with some specific input data (unless some of these subroutines themselves initialize all the variables with data coded into them).
Clearly you need a main program that invokes these subroutines, in some specific sequence, and probably with some specific input data (unless some of these subroutines themselves initialize all the variables with data coded into them).
Vanadium 50
Staff Emeritus
Science Advisor
Education Advisor
Gold Member
Dearly Missed
- 35,003
- 21,712
If the problem were to turn working FORTRAN into working Python, that would be one thing. But the problem is to turn non-working FORTRAN into working Python,
As people have noted, there is no main program, just subroutines. As the OP has noted, he needs more output than is provided by the code he posted.
Yes, I know he expects this. Doesn't mean its going to happen or is even possible.
As people have noted, there is no main program, just subroutines. As the OP has noted, he needs more output than is provided by the code he posted.
Yes, I know he expects this. Doesn't mean its going to happen or is even possible.
member 657093
You are taking a reply I made to PeterDonis out of context! I didn't demand anything! I asked a question and I EXPECT someone who knows the subject to help. I didn't expect for others to play with words and make a whole issue out of the words!!!!!Vanadium 50 said:I think your best bet then is to hire a FORTRAN programmer. If the FORTRAN doesn't do exactly what you want it to do, it is not reasonable to expect us to modify it, much less demand it.
PeterDonis
Mentor
- 49,261
- 25,312
Actually, "expect" in English does carry a connotation of "demand" as you are using it in the above quote.Vick said:I EXPECT someone who knows the subject to help
As far as helping, sometimes the best help you will get is for people to point out to you that the problem is insoluble as you have described it. That might well be the case here, since the FORTRAN code isn't even complete to start with, so someone who is familiar with this particular FORTRAN library would have to complete the FORTRAN code first. The fact that no such person has come forward in this thread means there likely isn't such a person among PF's members. You would have to go back to the place where the FORTRAN code originally came from, as I suggested before.
member 657093
My problem is the following:
If I had a Python code that says:
The only addition I would need is to add:
As I am not Fortran literate, I was expecting some help in this way, where the Fortran programmer can call the subroutine and ask to print the values of the variables; just as I did for the second bit of Python code above.
If I had a Python code that says:
Python:
def test(a):
b = 13
return a*b
The only addition I would need is to add:
Python:
c = test(5)
print(c)
As I am not Fortran literate, I was expecting some help in this way, where the Fortran programmer can call the subroutine and ask to print the values of the variables; just as I did for the second bit of Python code above.
member 657093
PeterDonis said:Actually, "expect" in English does carry a connotation of "demand" as you are using it in the above quote.
As far as helping, sometimes the best help you will get is for people to point out to you that the problem is insoluble as you have described it. That might well be the case here, since the FORTRAN code isn't even complete to start with, so someone who is familiar with this particular FORTRAN library would have to complete the FORTRAN code first. The fact that no such person has come forward in this thread means there likely isn't such a person among PF's members. You would have to go back to the place where the FORTRAN code originally came from, as I suggested before.
expect
verb (used with object)
1/ to look forward to; regard as likely to happen; anticipate the occurrence or the coming of
2/ to look for with reason or justification
There are different meanings; my meaning in asking this question is to anticipate the occurrence; whereas you took the second meaning!!
PeterDonis
Mentor
- 49,261
- 25,312
"If". But what is left out of the FORTRAN code actually that simple? What if it's not?Vick said:My problem is the following:
If...
member 657093
I don't know that as I do not know Fortran! But are you saying that, as the code stands, a Fortran programmer cannot do anything to call up and compile a subroutine in that code?PeterDonis said:"If". But what is left out of the FORTRAN code actually that simple? What if it's not?
PeterDonis
Mentor
- 49,261
- 25,312
Yes, because in the context in which you used the term, the second meaning is the one a typical reader is more likely to infer. The first meaning is more likely in an impersonal context, for example: "I expect the sun to rise tomorrow morning." But if you say to me "I expect you to do X", I'm going to take that in the sense of the second meaning, i.e., that you think you have some reason or justification for asking me to do X for you, so that if I refuse, I have failed you in some way.Vick said:you took the second meaning
PeterDonis
Mentor
- 49,261
- 25,312
Yes. And that means you don't know whether what you are asking for is actually that simple or not. What if it's not?Vick said:I don't know that as I do not know Fortran!
I am not a FORTRAN expert so I can't say. But people who apparently do know some FORTRAN are giving you responses in this thread that, to me, indicate that what you are asking for is not that simple and not something that someone unfamiliar with the FORTRAN library in question is going to be able to do.Vick said:are you saying that, as the code stands, a Fortran programmer cannot do anything to call up and compile a subroutine in that code?
member 657093
You told me to go to the source! But the source is only this! They have an introduction to the problem and what it involves. As the formulation is lengthy, they just pointed out to this Fortran code. sourcePeterDonis said:something that someone unfamiliar with the FORTRAN library in question is going to be able to do.
member 657093
Who exactly? jtbell? Because to me he looks like he knows Fortran.PeterDonis said:But people who apparently do know some FORTRAN
member 657093
Can you please make one and call up these subroutines to print the values of variables RC, DJ, Y, T, DY for TIME=331250?jtbell said:you need a main program that invokes these subroutines
Similar threads
- Replies
- 3
- Views
- 2K
- · Replies 14 ·
- Replies
- 14
- Views
- 5K
- Replies
- 1
- Views
- 1K
- · Replies 2 ·
- Replies
- 2
- Views
- 1K
- · Replies 10 ·
- Replies
- 10
- Views
- 3K
- · Replies 55 ·
- Replies
- 55
- Views
- 6K
- · Replies 4 ·
- Replies
- 4
- Views
- 5K
- · Replies 9 ·
- Replies
- 9
- Views
- 2K
- · Replies 3 ·
- Replies
- 3
- Views
- 1K
- Replies
- 7
- Views
- 2K