- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The integer value "I_MONTH" is not being passed correctly between subroutine "Monthly_Ratings" and Subroutine "Calculate_Ratings".
Cant figure out why. Would this be a compiler problem?
Thank you.
SUBROUTINE MONTHLY_RATINGS
C************************************************************************
C
C SUBROUTINE: MONTHLY_RATINGS
C FUNCTION: CALCULATES MONTHLY RATINGS
C CALLS SUBROUTINE CALCULATE TO CALCULATE RATINGS FOR EACH MONTH
C REV 0: 05/24 DML
C
C************************************************************************
REAL LOADLOSS, LOSSMVA
REAL MAXOIL,MAXCU
CHARACTER*20 TXDATE,LIMITING,LIMITING_MONTHLY
DIMENSION PU(288)
INTEGER FIRST,OILHOUR,OILMINUTE,CUHOUR,CUMINUTE
INTEGER PEAKHOUR,PEAKMINUTE
INTEGER PEAKHOUR_MONTHLY,PEAKMINUTE_MONTHLY,OILHOUR_MONTHLY
INTEGER OILMINUTE_MONTHLY,CUHOUR_MONTHLY,CUMINUTE_MONTHLY
INTEGER POST_STE_SUM,POST_STE_WIN
CHARACTER*63 TITLE
CHARACTER*25 TYPE
CHARACTER*35 CONSTRUCTION
CHARACTER*20 RATING
REAL monthly_ambient_F
C * * * * * * * * * * * * * * COMMON BLOCK * * * * * * * * * * * * * * *
COMMON/INPUT/TITLE,CORELOSS,LOADLOSS,LOSSMVA,HRLOSS,LOSSCALC,
1 ITYPE,XN,XM,INSULATION,WCORE,WTANK,GALLONS,HRMVA,OILRISE,
1 AVECU,DELTA,MAXCU(4),MAXOIL(4),DURATION(4),OILCALC,
1 SUMMERCYCLE(24),WINTERCYCLE(24),PERCENT,REPORTSIZE,CUTAU,OILTAU,
1 XNAMEPLATE,monthly_ambient_F(14,2)
COMMON/OUTPUTS/HOTSPOT(4,288),PMAX(4),PMVA(4,288),
1 TOPOIL(4,288),LIMITING(4),HOTSPOTMAX(4),TOPOILMAX(4),
1 KJ,CONVERGENCE(4),SOLUTION(4),OILHOUR(4),OILMINUTE(4),
1 CUHOUR(4),CUMINUTE(4),PEAKHOUR(4),PEAKMINUTE(4),AMBIENT(4)
COMMON/MONTHLY/PMAX_MONTHLY(14,4),HOTSPOT_MONTHLY(14,4,288),
1 PMVA_MONTHLY(14,4,288),TOPOIL_MONTHLY(14,4,288),
1 LIMITING_MONTHLY(14,4),HOTSPOTMAX_MONTHLY(14,4),
1 TOPOILMAX_MONTHLY(14,4),OILHOUR_MONTHLY(14,4),
1 OILMINUTE_MONTHLY(14,4),CUHOUR_MONTHLY(14,4),
1 CUMINUTE_MONTHLY(14,4),PEAKHOUR_MONTHLY(14,4),
1 PEAKMINUTE_MONTHLY(14,4),I_MONTH
COMMON/CONSTANTS1/RATIO,TGFL,
1 FIRST(8),LAST(8),CONSTRUCTION,RATING(8)
COMMON/PUNIT/PUSUM(288),PUWIN(288),
1 NSUMMER,NWINTER
C * * * * * * * * * * * * * * COMMON BLOCK * * * * * * * * * * * * * * *
DO 110 I=1,14
I_MONTH = I
AMBIENT(1) = (monthly_ambient_F(I,1)-32)/1.8
AMBIENT(2) = (monthly_ambient_F(I,2)-32)/1.8
AMBIENT(3) = (monthly_ambient_F(I,2)-32)/1.8
AMBIENT(4) = (monthly_ambient_F(I,2)-32)/1.8
CALL CALCULATE_RATINGS
DO 105 J=1,4
PMAX_MONTHLY(I,J)=PMAX(J)
PEAKHOUR_MONTHLY(I,J)=PEAKHOUR(J)
PEAKMINUTE_MONTHLY(I,J)=PEAKMINUTE(J)
TOPOILMAX_MONTHLY(I,J)=TOPOILMAX(J)
HOTSPOTMAX_MONTHLY(I,J)=HOTSPOTMAX(J)
OILHOUR_MONTHLY(I,J)=OILHOUR(J)
OILMINUTE_MONTHLY(I,J)=OILMINUTE(J)
CUHOUR_MONTHLY(I,J)=CUHOUR(J)
CUMINUTE_MONTHLY(I,J)=CUMINUTE(J)
LIMITING_MONTHLY(I,J)=LIMITING(J)
DO 100 K=1,288
PMVA_MONTHLY(I,J,K)=PMVA(J,K)
TOPOIL_MONTHLY(I,J,K)=TOPOIL(J,K)
HOTSPOT_MONTHLY(I,J,K)=HOTSPOT(J,K)
100 CONTINUE
105 CONTINUE
110 CONTINUE
I_MONTH = 0
RETURN
END
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Windows instruction using Microsoft Visual Studio.
prior to call insert a diagnostic
print *,"location of I_MONTH", LOC(I_MONTH)
Inside the called subroutine
insert the same line.
At runtime, expect the same location to be displayed. If it does not, something is wrong.
As you have not pasted the code properly, we cannot tell the character spacing.
To insert code properly, click on the ...'s to increase the list of options in the edit window.
Then click on the </>, button, click on the Markup button, a pull-down list is shown, Select Fortran, then paste your code in the edit window. Then exit the edit window.
The named common block /MONTHLY/ looks OK in both subroutines.
Assuming the addresses of I_MONTH are the same, then
In the caller procedure, before the call, examine the value of I_MONTH, and verify that it is what you expect.
Then, in the bottom of MS VS (where the Watch tab is located), you will see a tab for Breakpoints. If it is not there, at the top click
Debug | Windows | Breakpoints
click on the Breakpoints tab
In there, clicks: New | Data Breakpoint
in the location insert: loc(I_MONTH)
Then continue to a breakpoint in the second procedure where you observe the incorrect value for i_month
Note, if something alters the caller's I_MONTH you will have a break at that statement.
This may show you an array being indexed out of bounds.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Jim
I attached my code. In the meantime, I will try the "diagnostic print *,"location of I_MONTH", LOC(I_MONTH)" that you recommended.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
well for 20 minutes of fun I downloaded your program and put it in an IFX project in vs2022. I compiles OK. I found some input data in a comment so I copies to a file and put a line to open that as unit 5 (var G) in the read routine.
Anyway in the debugger in "Monthly_Ratings" it cycles through values 1 to 14 and in Subroutine "Calculate_Ratings" we get 1 to 14.
It then calls "Calculate_Ratings" from some other place with I_MONTH set to zero..... I stopped at that point.
I do no see the problem you describe, the common block with I_MONTH all check as consistent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok. thanks Andrew
When I run the program (look at fort.7 output file), I see I_Month being incremented from 1 to 14 in Monthly_Ratings subroutine, but after passing it to Calculate_Ratings subroutine, I_Month is increases directly from 0 to 19, with no increments in between.
I am using intel fortran compiler 17.0, and VS 2019.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
interesting
The hover in the debugger shows I_MONTH = 1 the print to console shows 0. Something is screwed.....
I changed the print to show the address also and had the same print before the call....
You can clearly see that memory address is different !!!!!!!!!!!!!! Something is broken.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your problem is CHARACTER*20 TXDATE,LIMITING,LIMITING_MONTHLY
LIMITING_MONTHLY is an array in a common BUT is not declared in all locations so at some places is is an array of char 20 and in others it is an array of integer. The memory locations then get foo bahed as a result. If you declared everything and used implicit none it would have been caught. The best quick fix is to declare all the common variables in a module and just use that module in all the places a common is used,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Andrew
Strange. I thought that I only had to declare the variable in a subroutine if I actually used it in that subroutine. Anyway. I declared them all in each subroutine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Everything should be declared everywhere as a matter of principle. This is a small program it would not take long.
1] Using implicit typing (assumed type based on the initial letter) is fraught with problems, it is so easy to get it wrong, for example misspelling a variable does not get picked up.
2] Commons are tedious and very obsolete, you must have everything matching everywhere. Putting the common declarations in an include file and including it where used is a fix for that as you can't have mismatches then and adding something adds in one place only, so much easier.
But I get that maybe people are not comfortable changing a way of working, if it 'works'. A solution using a data module would be the best 'easy' fix IMO.
Anyway problem solved for now.....
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page