Common block file

  • Follow


How would I go about changing a common block that is used as a file
and referenced with include statements in every sub and function into
a module.  Keep in mind that there is a vast amount of variables in
the common block. I've seen the tutorials on changing small common
blocks over, but not for when they are separate files.

Shawn
0
Reply saquisenberry (24) 2/27/2008 9:10:41 PM

On Feb 27, 3:10=A0pm, Shawn <saquisenbe...@gmail.com> wrote:
> How would I go about changing a common block that is used as a file
> and referenced with include statements in every sub and function into
> a module. =A0Keep in mind that there is a vast amount of variables in
> the common block. I've seen the tutorials on changing small common
> blocks over, but not for when they are separate files.
>
> Shawn

The simplest way is just to add "module <name>" before and "end
module" after and then replace the include with use.  I usually
include many "local" modules before the program main, but you can
compile them in separate files as well (rename the .inc file to .f90
and compile it after adding the module/end module.

module mycommon

   common /myc/ item

   integer :: item

end module

program MemoryStatus

use mycommon

=2E..

end program MemoryStatus
subroutine sub()

use mycommon

end subroutine
0
Reply garylscott (1357) 2/27/2008 9:38:29 PM


@gmail.com> wrote in message 
news:a1295c3f-3b23-41c7-b6e9-6e878ad7f3ed@d4g2000prg.googlegroups.com...
> How would I go about changing a common block that is used as a file
> and referenced with include statements in every sub and function into
> a module.  Keep in mind that there is a vast amount of variables in
> the common block. I've seen the tutorials on changing small common
> blocks over, but not for when they are separate files.
>
> Shawn

See my posting on this last year:

http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/22177bc6c41f5ad4/b154e8cbd59254f7?lnk=gst&q=common+from+fortran77+to+fortran+90#b154e8cbd59254f7

-- 
Qolin

Email: my qname at domain dot com
Domain: qomputing


0
Reply qolin.SEE_SIGNATURE (154) 2/27/2008 9:54:00 PM

Shawn wrote:

> How would I go about changing a common block that is used as a file
> and referenced with include statements in every sub and function into
> a module.  Keep in mind that there is a vast amount of variables in
> the common block. I've seen the tutorials on changing small common
> blocks over, but not for when they are separate files.

At least if it is one file you know that the variables have the same
name in all routines using that file.  Are the declaration statements
for those variables also in the include file?

-- glen

0
Reply gah (12302) 2/27/2008 10:27:47 PM

> At least if it is one file you know that the variables have the same
> name in all routines using that file.  Are the declaration statements
> for those variables also in the include file?
>
> -- glen

The include file is basically a large globals variable declaration
list.  The bulk of the files are auto declared using the i-n option
with character vars being explicitly declared.  The actual program
uses this list with very little variable passing otherwise.  Or did I
miss the question?

Shawn
0
Reply saquisenberry (24) 2/27/2008 11:13:21 PM

Shawn wrote:
>> At least if it is one file you know that the variables have the same
>> name in all routines using that file.  Are the declaration statements
>> for those variables also in the include file?
>>
>> -- glen
> 
> The include file is basically a large globals variable declaration
> list.  The bulk of the files are auto declared using the i-n option
> with character vars being explicitly declared.  The actual program
> uses this list with very little variable passing otherwise.  Or did I
> miss the question?
> 
> Shawn

In that case you are going to have to keep the common statement inside 
the module - because it's the only declaration of the variables. That 
doesn't hurt, but it will make it a bit more awkward to make some other 
modernisations/improvements (such as making some of the arrays 
allocatable, allowing greater flexibility in the size of problem you can 
consider) - you can't do that with an array in common, but you can with 
an array in a module. Now of course you can remove the arrays from the 
COMMON statements (they must already be declared elsewhere to dimension 
them) but if the common blocks also contain scalar variables, you'll 
have to do it on an individual basis. If your code contains any use of 
EQUIVALENCE, you'll need to be very wary at this point, and run a bunch 
of before-and-after test cases to check for any storage association 
which this has screwed up.

Otherwise what I would suggest as a next step would be simply to remove 
the COMMON line(s), leaving the module containing just variable 
declarations.

-- 
Catherine Rees Lay

Polyhedron Software Ltd. Registered Office: Linden House,
93 High St, Standlake, Witney, OX29 7RH, United Kingdom.
Registered in England No.2541693. Vat Reg No. GB 537 3214 57
0
Reply catherine.news (58) 2/29/2008 10:20:44 AM

5 Replies
31 Views

(page loaded in 1.989 seconds)


Reply: