EBM Project Update
Project Description
Figure out how to run Jacob's Fortran Energy Balance Model through Mathematica. Put in inputs within Mathematica notebook, then receive/extract all data through the same notebook.
Idea 1: Use MathLink (status: not working)
- MathLink
- allows external programs both to call Mathematica, and to be called by Mathematica. By using MathLink, you can, for example, treat Mathematica essentially like a subroutine embedded inside an external program. You can also use MathLink to let Mathematica call individual functions inside an external program. (MathLink (as well as LibraryLink) are designed to be used in conjunction with programs written in C/C++. )
Where I'm at here is I have outlined the 4 steps/goals that if accomplished would allow me to successfully use MathLink. I have successfully accomplished the first two steps, yet the other two remain unworking…
- Successfully test MathLink using the example file they have built into Mathematica by compiling the example C++ program and template file into an executable file which is then run through Mathematica.
- SUCCESS
- Figure out how to call a Fortran 90 subroutine from a C++ program.
- SUCCESS
- Successfully test MathLink's ability to call an external FORTRAN subroutine from Mathematica by moving the meat of the example C++ program to a FORTRAN test subroutine, and then compile the example C++ program, the test FORTRAN subroutine, and the example template file into an executable file which is then run through Mathematica.
- UNSUCCESSFUL (I keep on running into various bugs)
- Do the same as step 3, yet instead of the example C++ program, create a wrapper which will call the EBM driver.f90 instead of the test FORTRAN subroutine.
- UNSUCCESSFUL (can only work if I figure out step 3)
Idea 2: Use LibraryLink (status: semi-working)
- LibrayLink
- provides a powerful way to connect external code to the Wolfram Language, enabling high-speed and memory-efficient execution. It does this by allowing dynamic libraries to be directly loaded into the Wolfram Language kernel so that functions in the libraries can be immediately called from the Wolfram Language.
I think I finally have LibraryLink working at least well enough for us to use it in conjunction with Jacob's EBM model. When I run it through Mathematica, I can now…
- Successfully extract:
- globally averaged temperature (double)
- minimum global temperatures by lat band (array size 18)
- maximum global temperatures by lat band (array size 18)
- Unsuccessfully extract:
- average global temperatures by lat band (array size 18)
I think this may not be an issue for our purposes, as it seems like we only need the globally averaged temperature. In addition, if we want an approximated average temp array, I can calculate that just by averaging the min and max temp arrays, as I did in the Mathematica notebook.
Gif Demonstrating that LibraryLink is Working by Showing how the Temperature Arrays change with Obliquity*…
*(the avg temp array used here was calculated by averaging the min and max temp arrays, it was NOT calculated directly from the EBM program)
Attachments (1)
-
plotOblVar.gif (642.1 KB) - added by 6 years ago.
Variation of Temperature Arrays with Obliquity
Download all attachments as: .zip
Comments
No comments.