Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Array bound exceeded using higher compilers

playxy
Beginner
1,230 Views
I am working on a model which name is DAYCENT. I will make some modifications for this model (I need to change some source codes). The source codes of this model were written in mixed languages of Microsoft Fortran PowerStation v4.0 and Visual C++4.0. All files can pass compile and link, and can build the executable file under the above two compilers. The executable file can run smoothly, without any errors. However, this model was developed in another university. I received all source code files, but I don't have the above version of compilers. I use Compaq Visual Fortran v6.0 and Microsoft Visual C++ 6.0. When I used these two higher version of compilers , I could pass the compile, link and build the executable file without errors. But when I ran the executable file which was built under the higher version of compilers, I met the array bounds exceeded eorrors like this:

forrtl: severe (161): Program Exception - array bounds exceeded

I assume this problem was caused by using higher compilers. It's very hard to fix the array bounds exceeded errors. Do you have any ideas to fixed this problem? Could this problem be fixed by change the project setting?


Your help would be highly appreciated.
0 Kudos
8 Replies
sdrajan
Beginner
1,230 Views
The problem that you have described is usually due to sloppy programming. For example, you may have a subroutine of the form

SUBROUTINE ALPHA (A, N)
DIMENSION A(N)
....
A(N+1) = X
...

You have two options. You could run the program using the debugger (debug version), find the invalid statement and fix it. This solution implies that you have a working knowledge of the program. The second option is easier but dangerous. Once you locate the part of the program generating the error, you could change the program to something like the following form.

SUBROUTINE ALPHA (A, N)
DIMENSION A(*)

The out-of-bounds check will not be carried out and the program may run to completion generating correct results.

Good luck.

Rajan
0 Kudos
sdrajan
Beginner
1,230 Views
I completely forgot about the third option that you asked about - changing compiler settings. Click on Project-Settings. Select the Fortran tab. With the Category being General, look at the bottom window titled Project Options. If the Project Settings are Win32 Debug, you should find one of the options as /check:bounds. Highlight this and delete it. Now rebuild your project.

Note that array bound check is carried out only with the debug version of the program not the release version.

Rajan
0 Kudos
playxy
Beginner
1,230 Views
Hi Rajan,

Thanks for your reply. After I unchecked the "Array and strings bounds" box option, The program passed the link and got the excutable file. When I ran this excutable file, no error message was displayed this time, but the running stopped at the same location with the executable file that I checked the "Array and strings bounds" box.

I am quite sure this program is providing correct results because it has been widely tested and used. I used the same data and parameter data, and used the excutable file that formed from the earlier version compilers, it ran well and I received the correct results.

This means it will not fix my problem if I change the "Array and strings bounds" option.

For your first and second options, the error line is 189 (see below):

188 call csched(cadds,friso,1.0,
189 & cdonor(UNLABL),strcis(lyr,UNLABL),
190 & cdonor(LABELD),strcis(lyr,LABELD),
191 & 1.0,accum)

However, the arrays are not defined in subroutine csched.f. Csched.f calls another subroutine, and then call another another subroutine... It's so complex that I can't fix it. But it works well using the excutable that was formed from the earlier version of compilers.

Any other solutions do you have for this problem?

Yong
0 Kudos
jayfortranuser
Beginner
1,230 Views
Hi Yong,
I am working on daycent too and have similar problems. Would like to contact wit me?
Thanks
Hong
0 Kudos
Steven_L_Intel1
Employee
1,230 Views
Yong,
When the program stops now, you say it is in the same place. Is it with the same error message? If so, then you were not successful in turning off the array bounds checking.
Please do this. Right click on the project for the executable that failsand select Properties..Fortran..Command Line. Copy the command line text as shown there and paste it into a reply to this message. This will let us see what options that project is being built with. If this project uses a library of another project, repeat this step for the other project.
0 Kudos
jayfortranuser
Beginner
1,230 Views

Hi Steve,

I am not sure if Young is still around because his last message was a year ago.

I am working on the same model (daycent) using the same version of compilers (Compaq Visual Fortran 6.6 and Microsoft Visual C++ 6.0. Both of them are managed by Microsoft Visual Studio 6.0) and had the same problems to run the model.

After I turnedoff the array bounds checking, I could run the model, butit stopped because 'Nitrogen soil pools are unbalanced'. After I changed the comment

if (fabs(npool_sum - minerl_sum) > 1.0E-5) {

fprintf(stdout, "Nitrogen soil pools are unbalanced. ");

to

if (fabs(npool_sum - minerl_sum) > 0.014) {

fprintf(stdout, "Nitrogen soil pools are unbalanced. ");

the program continued and then stopped because of Stack Overflow error and I found the time (year) was 197132288.0000 instead of 1971.0.

It seems that Fortran and C didnt communicate each other properly. The daycent programmer suggested me to read compiler documentation to learn how to do mixed language programming and how to pass values between subroutines, how arrays are handled. To check if values are being passed correctly, she suggested me to put extra print/write statements in the subroutines before and after the call to another subroutine, at the beginning and the end of the called subroutine, and after the return to the original subroutine from the called subroutine to print out values that are passed to the calling subroutine and modified by the called subroutine to make sure that the variables retain their values in both subroutines.

The daycent model is developed by Microsoft Visual C++ version 4.0 and Fortran PowerStation 4.0. Do you think I should try to fix the problem or try to get old compilers they are using?

Thanks

Hong

0 Kudos
hoda_d_
Beginner
1,230 Views
0 Kudos
Judith_W_Intel
Employee
1,230 Views

Hoda - Please post this problem in the Fortran compiler forum. This is the C++ compiler forum.

good luck.

 

0 Kudos
Reply