|
|
 |
 |
 |
 |
Fortran Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
HELP: "The number of subscripts is incorrect."
I'M WRITING A SUBROUTINE TO GENERATE A INITIAL ARRAY: SUBROUTINE MS(NX,NT) INTEGER NX I REAL DX DIMENSION X(NX,1) DO I=1,NX X(I)=I*DX END DO END THE FEEDBACK IS: Error: The number of subscripts is incorrect. [X] WHAT'S THE PROBLEM IN THIS PROGRAM? THANKS ALOT WENBIN
> WHAT'S THE PROBLEM IN THIS PROGRAM? THANKS ALOT
The number of subscripts is incorrect. -- FX
> WHAT'S THE PROBLEM IN THIS PROGRAM? THANKS ALOT
The number of subscripts is incorrect (for variable X). -- FX
FX wrote: >> WHAT'S THE PROBLEM IN THIS PROGRAM? THANKS ALOT > The number of subscripts is incorrect (for variable X).
So, if I wanna express X(I)=I*dX, how to set the subscripts of X? thanks
Wenbin Hu wrote: > FX wrote: >>> WHAT'S THE PROBLEM IN THIS PROGRAM? THANKS ALOT >> The number of subscripts is incorrect (for variable X). > So, if I wanna express X(I)=I*dX, how to set the subscripts of X? > thanks
Well, you've declared X to be a two-dimensional array. Thus, you need two subscripts. cheers, Rich
On Apr 17, 12:33 pm, Wenbin Hu <h@ecn.purdue.edu> wrote:
> I'M WRITING A SUBROUTINE TO GENERATE A INITIAL ARRAY: > SUBROUTINE MS(NX,NT) > INTEGER NX I > REAL DX > DIMENSION X(NX,1) > DO I=1,NX > X(I)=I*DX > END DO > END > THE FEEDBACK IS: > Error: The number of subscripts is incorrect. [X] > WHAT'S THE PROBLEM IN THIS PROGRAM? THANKS ALOT > WENBIN
You are declaring a TWO dimensional array at the top. But you are referencing a ONE dimensional array at the bottom. A ONE dimensional array has ONE subscript. So you need to code DIMENSION X(NX) In Fortran it is conventional to think of a row vector or a column vector as one dimensional, not as a 1 row matrix or a 1 column matrix. HTH -- elliot [Obviously tne next version of MIX needs an RPM instruction - "Read Programmer's Mind"]
On Apr 17, 12:33 pm, Wenbin Hu <h@ecn.purdue.edu> wrote: > I'M WRITING A SUBROUTINE TO GENERATE A INITIAL ARRAY: > SUBROUTINE MS(NX,NT) > INTEGER NX I
I think there should be a comma between NX and I. Use IMPLICIT NONE in all Fortran code.
Wenbin Hu <h @ecn.purdue.edu> wrote: > I'M WRITING A SUBROUTINE TO GENERATE A INITIAL ARRAY: > SUBROUTINE MS(NX,NT) > INTEGER NX I > REAL DX > DIMENSION X(NX,1) > DO I=1,NX > X(I)=I*DX > END DO > END > THE FEEDBACK IS: > Error: The number of subscripts is incorrect. [X] > WHAT'S THE PROBLEM IN THIS PROGRAM? THANKS ALOT
Others have pointed out the problem that the error message refers to (the incorrect number of subscripts), and Beliavsky noted the missing comma, so I won't repeat those. They are purely syntactic errors. I will note two other "issues" with the code. They might be artifacts of having a cut-down sample or code still in development, but still I think them worth pointing out. First, and simplest, DX is never defined here. More subtle is that what you have for X is an automatic local array. I'm not at all sure whether that's what you want; there isn't enough context for me to tell, but I'm suspicious that it isn't. An automatic local array always "goes away" when the subroutine returns. That kind of behavior doesn't sound consistent with the description of generating an "initial" array. I would also like to reiterate and emphasize Beliavsky's suggestion to use IMPLICIT NONE. Then declare the types of all variables (as you will have to with that feature). I recommend never using the DIMENSION statement at all; declare your X array with a REAL statement instead of a DIMENSION statement. IMPLICIT NONE helps even experts in the language. For newcomers such as your self, the help provided by IMPLICIT NONE is even more important. As a purely stylistic comment, this looks very reminiscent of 1970's code, with the all caps, the lack of indentation, and the use of implicit type declaration. The caps and indentation are of no great consequence other than appearance (though there are times when appearance matters and you wouldn't want people to think that the code was from 30 years ago), but the implicit typing is a real issue. -- Richard Maine | Good judgement comes from experience; email: last name at domain . net | experience comes from bad judgement. domain: summertriangle | -- Mark Twain
Wenbin Hu wrote: > I'M WRITING A SUBROUTINE TO GENERATE A INITIAL ARRAY: > SUBROUTINE MS(NX,NT) > INTEGER NX I > REAL DX > DIMENSION X(NX,1) > DO I=1,NX > X(I)=I*DX > END DO > END > THE FEEDBACK IS: > Error: The number of subscripts is incorrect. [X] > WHAT'S THE PROBLEM IN THIS PROGRAM? THANKS ALOT > WENBIN
An array that is neither a subprogram argument nor an allocatable array must have dimensions that are known at compile time. -- N. Shamsundar
N. Shamsundar <shamsun @uh.edu> wrote: > An array that is neither a subprogram argument nor an allocatable array > must have dimensions that are known at compile time. That is not accurate. In f90 and subsequent, such a thing is perfectly fine. There is even a specific term for such arrays; they are called automatic. In f77, there is no such thing as an allocatable array, so the claim doesn't fit there either. Some f77 compilers have allocatable arrays as vendor extensions, but then some f77 compilers also have automatic arrays as vendor extensions. Now I have doubts, mentioned in another posting, as to whether an automatic array fits the intended application, but that's a different question. -- Richard Maine | Good judgement comes from experience; email: last name at domain . net | experience comes from bad judgement. domain: summertriangle | -- Mark Twain
|
 |
 |
 |
 |
|