In the past, I had a problem. Basically, I was unsuccessful at converting my large Fortran program with many C calls to use the iso_c_binding standard because I ran out of time. (I was repeatedly forced to redo the new iso_c_binding interface that I was trying to develop.)
I don’t remember the exact compilers or details of the code. I just know that my employer cancel the project.
Question: In the future if this situation occurs, how can I prevent this problem from happening?
Isolate all the routines to a module. The calls from the program should use intrinsic Fortran types as much as possible and be converted to appropriate C types in the module. Using the module as an abstraction layer you are free to create modules specific to particular programming environments. If the function is available as a compiler extension or requires specific coding because the ISO_C_BINDING interface is not available or can simply be implemented with a simple C binding is then all isolated to the module. Modern AI products may be able to give much more accurate assistance than was the case just a few months ago. Look for libraries on the WWW that already provide ISO_C_BINDING interfaces to many of the most common system calls via C. We had C interfaces before ISO_C_BINDING where that basic tactic worked successfully, and continued to be useful while the ability for Fortran to call C became defined in the standard. Recently, particularly with some clarifications and enhancements to passing character data the bindings have become simpler to implement reliably but an approach using wrappers is still useful in my opinion.
I would practice making calls to and from C with simple interfaces, gradually experimenting with more challenging calls. Try to solve some calls available in the public libraries without looking at the public code first; and then study the differences between your solution and the readily available ones.
Polling Questions:Does everyone agree with this process? Is more clarification required to implement this process? Does anyone have something to add to add to this process? What would make this process difficult to implement and in simple words what would you do in these situations?
Yes, @urbanjost’s answer is spot on. @giraffe2 if you have any specific questions, share what work you did and what you tried to do, and the outcome and what you want to achieve.
I did the work two years ago, so the line by line details of my work have been forgotten. I do not have access to that code.
But overall, what I remember trying to do is create a specific iso_c_binding interface one-by-one for each C routine call from Fortran. Because each time, there were “similar” C calls, the new interface led to errors that required adjustments to the code to remove the errors.
Each new iso_c_binding interface would require adjustments to previous iso_c_binding interfaces added, etc., etc., etc., etc., etc.
Ultimately after months working on the fixes, and because I was never given a completion date. I ran out of time and had to submit what I had. What I submitted did not compile. (I just wasn’t finished doing the work.)
A few months later, I left that employer for other reasons.
I guess. What I should be asking is for a more simpler description of urbanjost’s answer to my original question, something such as a process that I should follow next time, maybe practical examples for each step.