- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(I repost this because my previous post is in other people's thread. BM please help me delete the old one, thanks) I have a common block data as follow: BLOCK DATA I want to transfer all common blocks to Module, and create a module as: MODULE LCONTR But I have questions about this. In the common block, the variables are initialized with deafult values, but how can I initilize the variabes in module? Because my code will use common block data many times, in my understanding, it will set all the variables as the deaults values when it start tousethem (the program will change the values during the running, and initialize themat every beginning of the loop). But with module, how can I do the same thing? Thanks in advance! |
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
MODULE LCONTR
INTEGER, PARAMETER :: K_INT = SELECTED_INT_KIND(9)
INTEGER, PARAMETER :: K_DBL = SELECTED_REAL_KIND(15,300)
INTEGER(K_INT) :: IREST = -1
INTEGER(K_INT) :: ISTR = 100
INTEGER(K_INT) :: IS1 = 0
INTEGER(K_INT) :: IS2 = 0
INTEGER(K_INT) :: NPC = 1
INTEGER(K_INT) :: NDERIREST = 123
REAL(K_DBL) :: EPS = 1.0D-9
REAL(K_DBL) :: SC2MIN = -1.D0
END
I have also taken the liberty to replace your use of the extensions INTEGER*4 and REAL*8 with the recommended style using standard-conforming and portable features of the language.
The key to the initialization question is to use the double-colon form of declaration and the initialization clause with an equals sign.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, steve.
So, in my code, when I declear variables, should I also use the standard-conforming and portable features as
USE LCONTR, ONLY: K_INT, KDBL
Implicit none
INTEGER(K_INT) I,J,K
REAL(K_DBL) E,F,G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you do this, rather than have constants such as 1.0D0, you would use 1.0_K_DBL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
KIND(0)
and
KIND(0.0D0)
This gives you that compiler's kind value for default integer and for double precision. If you don't have specific requirements for number of digts, etc., this may be a simpler alternative.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Technically, your code relies on extensions to Fortran, so is not absolutely required to operate in a portable way, even where compilers accept it.
I believe I have seen posted articles on recommended style for doing what I think you want. A good textbook also should show reasonably sane methods. Since an initializer implies SAVE, you could set up the module like
integer :: irest = -1
...
or you could USE the module in the main program and assign values prior to use elsewhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
MADsblionel:
INTEGER, PARAMETER :: K_INT = SELECTED_INT_KIND(9)
INTEGER, PARAMETER :: K_DBL = SELECTED_REAL_KIND(15,300)
I have also taken the liberty to replace your use of the extensions INTEGER*4 and REAL*8 with the recommended style using standard-conforming and portable features of the language.
Hi Steve,
why is that kind of declarationbetter? I used integer*4 because I knew that this would handle numbersfrom -2147483648 to 2147483647. Is that different on other platforms or other compiler?
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're on a forum dedicated to runninga decidedly nonportable compiler IVF on Windows. I you want portable use Mingw. gfortran is now part of GCC. As far as *4, *8, and *16 goes, they work across ia32, Intel64, and IA64.
Gerry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
![](/skins/images/3344F5B3B76C91485ED0E980FD0CA95E/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page