|
|||
|
down vote favorite
share [g+] share [fb] share [tw] I'm working with fortran subroutines of a finite element analysis program. I have to share variables between the two subroutines so I'm using COMMON blocks. The problem is that only some of the variables are passed to the other subroutine, others are not. My code is like this: First subroutine: real knom, krot COMMON /kVAR/ kmom, krot SAVE /kVAR/ Second subroutine I use the same syntax. I'm controlling the results by writing kmom and krot values in each subroutine to a txt file: write(6,*) 'I am in URDFIL', or 'I am in UFIELD' 1 KINC, kmom, krot The results are: I am in URDFIL 1 -16700 -2.3857285E-03 I am in UFIELD 2 -16700 -1155769886 So the value of krot is lost. Any advise is most welcome. Thanks, Joćo P.S.: I've posted this question in http://stackoverflow.com but I haven't got any reply |
|
|
||||
|
||||
|
|
|
|||
|
Hi
You forgot to declare krot in UFIELD so it was implicitly declared as integer(*). Adding "real krot" to UFIELD should fix the problem. If this is new code, I highly recommend adding implicit none to avoid these kinds of problems. Regards Rafik Visit the Fortran Cafe at http://ibm.com/rational/cafe/ * I'm basing my guess on the fact that the binary representations for -2.3857285E-03 and -1155769886 are the same. "Joćo André" <jpcgandre@gmail.com> wrote in message news:22375789.11.1333854629187.JavaMail.geo-discussion-forums@vbbfj25... down vote favorite share [g+] share [fb] share [tw] I'm working with fortran subroutines of a finite element analysis program. I have to share variables between the two subroutines so I'm using COMMON blocks. The problem is that only some of the variables are passed to the other subroutine, others are not. My code is like this: First subroutine: real knom, krot COMMON /kVAR/ kmom, krot SAVE /kVAR/ Second subroutine I use the same syntax. I'm controlling the results by writing kmom and krot values in each subroutine to a txt file: write(6,*) 'I am in URDFIL', or 'I am in UFIELD' 1 KINC, kmom, krot The results are: I am in URDFIL 1 -16700 -2.3857285E-03 I am in UFIELD 2 -16700 -1155769886 So the value of krot is lost. Any advise is most welcome. Thanks, Joćo P.S.: I've posted this question in http://stackoverflow.com but I haven't got any reply |
|
|||
|
Joćo André <jpcgandre@gmail.com> wrote:
> My code is like this: First subroutine: > > real knom, krot > > COMMON /kVAR/ kmom, krot > SAVE /kVAR/ > > Second subroutine I use the same syntax. I'm controlling the results by > writing kmom and krot values in each subroutine to a txt file: > > write(6,*) 'I am in URDFIL', or 'I am in UFIELD' > 1 KINC, kmom, krot > The results are: > I am in URDFIL 1 -16700 -2.3857285E-03 > I am in UFIELD 2 -16700 -1155769886 Rafik gave the answer to your problem. Clearly, you didn't actually use completely "the same syntax" in both routines - just part of the same syntax, evidently missing the real declaration for krot. Note also the suspicious difference between the real declaration of knom versus the kmom in the COMMON block. Let me just note that this illustrates yet again the reasons for posting the whole actual code instead of excerpts and descriptions of it. The description turned out to be wrong here, and that error was exactly the problem. This case happened to be easy to diagnose anyway; others aren't. I'll second Rafik's suggestion to use implicit none. I'll go further and suggest using f90 modules instead of common blocks. Comon blocks are a *LOT* more error prone (particularly without implicit none). Some cases can be awfully tricky to diagnose. -- Richard Maine | Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|