Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing unit numbers from a shared library (FLIBS)

Status
Not open for further replies.

NickFort

Technical User
Jun 10, 2010
113
0
0
I'm playing around with FLIBS ( and getting some strange behaviour with csv_write.

To test just this module, I copy "csv_tst.f90" from "/tests/strings" and "csv_file.f90", "csv_file_1d.f90", "csv_file_2d.f90" from "/src/strings" to the same folder.

If I compile it with

Code:
gfortran csv_file.f90 csv_tst.f90 -o test

it runs just fine.

However, if I compile the module to a shared library like so:

Code:
gfortran csv_file.f90 -c
gfortran -shared csv_file.f90 -o csv.dll
gfortran csv_tst.f90 -L. csv.dll -o test

the test doesn't work properly. It writes the correct output, except not to the specified file, but to "fort.10" (10 is the unit number specified for the file). The specified file remains empty.

Does anyone have any idea why this is happening, and more importantly, how to get it to work correctly?

--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
 
Reply from Arjen Markus, in case anyone is interested:

The problem is that shared libraries and programs internally use
different tables for files they have opened. A similar problem occurs
when you allocate memory in a program and try to deallocate it in
a shared library. Best way to view the relationship: they are
essentially two programs that can share data, but not resources.

Here is what you do: open the file via a routine in the shared
library and write to it only via routines in that library. That
way you do not have to worry about this nasty aspect.

--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top