- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How come if I put the same Common header (ex. "Common / bubspec / xlambda, xin, c, rbc, bub") in two different procedures, the values still change? Is there something I am forgetting to do?
Link Copied
9 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't understand what you mean by "the values still change" What behavior are you expecting? The idea of COMMON is that a common block is shared among all the program units which declare it. You must make sure that the common block is declared exactly the same way in each program unit.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My main goal is to use those variables declared in the common statement, as global variables. Is that the only way, or is there a simpler way to reach my goal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well, that's one way. Another is to declare your variables in a MODULE which you then USE where necessary.
What behavior do you see that you don't expect?
Steve
What behavior do you see that you don't expect?
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have the Common header in 2 different procedures, and I read the value in in the first procedure, and use it for calculations in the second. But when I go to use the variable in the second procedure, its value that was declared in the first procedure is lost, and is set to '0'. What am I doing wrong, or what am I forgetting to do?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Without seeing your actual code, I don't know what you're doing wrong. Can you post a short (10-20 line) example that demonstrates the problem? Bracket your code in the post with
Steve
and.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First Procedure
Second Procedure
INTEGER FUNCTION zref_TF_D1_CB(S) !DEC$ attributes C::zref_TF_D1_CB LOGICAL*1 S(1) CHARACTER*256 S2 INTEGER*4 zref Common / refqnt / zref INCLUDE 'FGLUE.INC' INCLUDE 'ADDGLBL.INC' INCLUDE 'GUIDEFS.INC' INCLUDE 'GUI.INC' zref_TF_D1_CB = 1 Call TecUtilLockOn() CALL FExtGetCharFromCString(S,S2,ILen) READ(S2(1:ILen),*, IOSTAT=iErr) zref Call TecUtilLockOff() RETURN END
Second Procedure
Subroutine AssignData () Integer*4 rgas, unref, tobs, itwod, xref, yref, zref, iseed common / refqnt / yref,zref,sigman,sigmat,pv,s,unref,Fr,we,re ... open(7,file='D:jpfCavatCavatlarry.inp',status='unknown') write (7,*) xref write (7,*) yref write (7,*) zref close (7) ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah, that explains it.
Your COMMON statement must be the same in every routine. A COMMON declares a shared memory region and the variables are laid out in the region in the order you list them in the COMMON statement. If you have different variable lists, the variables appear to be in different places.
Usually, one puts COMMON statements in an INCLUDE file and INCLUDEs it in each routine. As I mentioned earlier, the modern alternative is to have a MODULE which declares the variables, and then you USE the module where needed.
Steve
Your COMMON statement must be the same in every routine. A COMMON declares a shared memory region and the variables are laid out in the region in the order you list them in the COMMON statement. If you have different variable lists, the variables appear to be in different places.
Usually, one puts COMMON statements in an INCLUDE file and INCLUDEs it in each routine. As I mentioned earlier, the modern alternative is to have a MODULE which declares the variables, and then you USE the module where needed.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Read in Procedure
Write out Procedure
Common.fi
I did what you said and put the common statements in the INCLUDE file and INCLUDEd it in each routine, but the variable is still changing. Ex. It reads in the value '8', and prints out ' 1.1210388E-44'
Sorry if I am just making something simple complicated
Jake
INTEGER FUNCTION zref_TF_D1_CB(S) !DEC$ attributes C::zref_TF_D1_CB LOGICAL*1 S(1) CHARACTER*256 S2 INTEGER*4 zref Include 'Common.fi' INCLUDE 'FGLUE.INC' INCLUDE 'ADDGLBL.INC' INCLUDE 'GUIDEFS.INC' INCLUDE 'GUI.INC' zref_TF_D1_CB = 1 Call TecUtilLockOn() CALL FExtGetCharFromCString(S,S2,ILen) READ(S2(1:ILen),*, IOSTAT=iErr) zref Call TecUtilLockOff() RETURN END
Write out Procedure
Subroutine AssignData () Include 'Common.fi' open(7,file='D:jpfCavatCavatlarry.inp',status='unknown') write (7,*) zref close (7) Return End
Common.fi
Common / turbulence / iturb Common / Param / tobs, iseed Common / bubspec / xlambda, xin, c, rbc, bub Common / bubspec / bubcount Common / refqnt / rref, uref, dref,vref,aref,pinf,tref,rgas,xref common / refqnt / yref,zref,sigman,sigmat,pv,unref,Fr,we,re Common / testing / IMax, JMax, KMax, NumZones, NumVars, Length
I did what you said and put the common statements in the INCLUDE file and INCLUDEd it in each routine, but the variable is still changing. Ex. It reads in the value '8', and prints out ' 1.1210388E-44'
Sorry if I am just making something simple complicated
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Add explicit type declarations for all the COMMON variables in Common.fi and remove them, where they appear, in the routines. You have, for example, Zref declared as Integer in the Read In procedure, but it's not typed at all in the Write procedure, so it is REAL by default.
Get into the habit of putting IMPLICIT NONE just after the SUBROUTINE, FUNCTION or PROGRAM statement throughout your code, and explicitly declare everything. It will save you many headaches.
Steve
Get into the habit of putting IMPLICIT NONE just after the SUBROUTINE, FUNCTION or PROGRAM statement throughout your code, and explicitly declare everything. It will save you many headaches.
Steve

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page