- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am in the process of converting the COMMON block structure to MODULE structure within a F95 program. There are about 60 COMMON blocks to convert, but I am beginning slowly. I had a previous issue over the weekend, but (thankfully) it was resolved with assistance via this forum.
My latest issue is as follows: In the original version of the program, I have a BLOCK DATA unit that initializes a number of large arrays (which hold thermophysical property data for various fluids; these arrays are never changed during program execution). Some of the arrays are 1-D; most are 2-D. These arrays are selectively shared with other program units via COMMON blocks. The arrays are initialized within the BLOCK DATA unit via DATA statements.
My approach to conversion has been to transform the BLOCK DATA unit into a 'parent' MODULE and leave the data statements that initialize the arrays unchanged. I then created other MODULEs that replace the COMMON blocks; these modules are USEd inside the 'parent' MODULE to selectively share the arrays with other program units (which also USE these data-sharing modules).
However, when I compile the program, I get the error message indicated in the subject header above.
1. Why cannot arrays (or variables) initialized via DATA statements be made accessible to other program units via use association?
2. Could someone please suggest (if possible) a *rudimentary* approach to accomplish my objectives as described above, which would involve as few changes as possible?
I already have some ideas about how to eliminate the DATA statements via array constructors, but the problem with this approach is that some of the arrays are currently initialized in sections (via implied DO loops), and the data was entered in row major order instead of column major order.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My suggestion is to put the DATA statements in the same modules in which the variables are declared, and to do away with the BLOCK DATA program unit altogether.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The issue is that you can't declare a variable in a module and then, in a separate program unit, use DATA to initialize the module variable. You can do this only with COMMONs. If you want to initialize module variables, as mecej4 says, you must do so in the same module where they are declared.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, mecej4, for your suggestion.
So it is possible to initialize an array variable with a DATA statement (instead of a type declaration) within a MODULE?
Would not that variable be made accessible to other program units via USE association, which violates the protocol?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just now saw your explanation, Steve.
Please see my last response to mecej4 -- So I can do it inside the module with a DATA statement (instead of a type declaration)?
If so, can I utilize an implied DO loop in the DATA statement to initialize sections of arrays (as it is currently being done in the old BLOCK DATA unit)? It would be extremely beneficial to me if it can be done this way.
Thanks in advance for any follow-up comments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a test program that may encourage you to proceed.
module globdata implicit none real, dimension(6) :: a integer i data (a(i),i=1,5,2) /11.0, 12.0, 13.0/, (a(i),i=2,6,2) /-14., -16.,-18./ end module program tst use globdata, only : a implicit none write(*,'(6F7.2)')a end program
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, mecej4, for the example program. It should prove to be very helpful -- although I am wondering:
1. Why is a(2) initialized three times [yielding a(2) = -18.] but a(3) and a(4) are left unspecified?
I understand the implied DO loop index parameters now: initial, final, increment !
2. What is the purpose of declaring Integer i in Program tst?
In any case, best regards to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jeffrey Hayen wrote:
1. Why is a(2) initialized three times [yielding a(2) = -18.] but a(3) and a(4) are left unspecified?
The "implied DO loop" (a(i),i=1,5,2) stands for a(1), a(3), a(5), and (a(i),i=2,6,2) stands for a(2), a(4), a(6).
2. What is the purpose of declaring Integer i in Program tst?None, and I have removed the declaration.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page