billgray1234
Programmer
- Mar 14, 2011
- 39
Hi all
I'm new to this forum. I have a problem in Fortran 90. It is described below.
The line 'IMPLICIT NONE' makes it impossible to implicitly declare VARIABLES. I'd like to know if there is a similar line (or way of declaring) that makes it impossible to implicitly declare STATEMENTS -- in particular, the statement 'USE MODULE_NAME' (where MODULE_NAME is the name of a module being USEd). The reason is that, to my understanding, it is possible to 'implicitly' have the line 'USE MODULE_NAME'. An example of how this is done is given below.
Consider 3 files (in Fortran 90):
1. module_set_precision.f90
2. module_peter.f90
3. main_program.f90
They are described briefly below.
1. set the level of precision of numerical calculations.
module_set_precision.f90
------------------------
MODULE set_precision
INTEGER, PARAMETER :: P_REAL = SELECTED_REAL_KIND(P=15)
END MODULE set_precision
2. a module that contains a subroutine. the important line in the subroutine is 'USE set_precision'.
module_peter.f90
----------------
MODULE peter
USE set_precision
IMPLICIT NONE
CONTAINS
SUBROUTINE bill(input,output)
...
REAL(KIND=P_REAL),INTENT(IN) :: input
REAL(KIND=P_REAL),INTENT(OUT) :: output
...
END SUBROUTINE bill
END MODULE peter
3. the main program, that uses both MODULE set_precision and MODULE peter. if written 'correctly', this main program looks something like this:
main_program.f90
----------------
IMPLICIT NONE
USE set_precision
USE peter
...
REAL(KIND=P_REAL) :: steve
REAL(KIND=P_REAL) :: daniel
...
CALL bill(steve, daniel)
...
END
4. the problem
In the above file main_program.f90, included explicitly is the line
IMPLICIT NONE
which means that all VARIABLES must be declared explicitly. but, in the same main program, it is possible to 'accidentally' forget to include the line
USE set_precision
(in order to USE MODULE set_precision), and yet this line is still 'implicitly' declared (in the main program) because of the line
USE peter
(which USEs MODULE peter), because MODULE peter 'explicitly' has the line 'USE set_precision'. the resulting 'incorrect' main program would look like this:
main_program.f90
----------------
IMPLICIT NONE
USE peter
...
REAL(KIND=P_REAL) :: steve
REAL(KIND=P_REAL) :: daniel
...
CALL bill(steve, daniel)
...
END
this is not good programming.
i've read about the words PRIVATE, PUBLIC. but i'm not sure if they are the solution to this problem.
i've also read that the position of the line 'USE set_precision' (in MODULE peter) could be causing this problem. currently, it is positioned BELOW the line 'MODULE peter' (thereby giving the whole content of MODULE peter access to it). maybe, it should instead be positioned BELOW the line 'SUBROUTINE bill (input,output)', so that only 'SUBROUTINE bill' has access to it. the resulting module/subroutine would look like this:
module_peter.f90
----------------
MODULE peter
IMPLICIT NONE
CONTAINS
SUBROUTINE bill(input,output)
USE set_precision
...
REAL(KIND=P_REAL),INTENT(IN) :: input
REAL(KIND=P_REAL),INTENT(OUT) :: output
...
END SUBROUTINE bill
END MODULE peter
but again, i'm not sure if that is the solution to this problem.
can anyone offer any suggestions to this problem?
any help would be appreciated.
cheers
bill g
billgray1234@hotmail.com
I'm new to this forum. I have a problem in Fortran 90. It is described below.
The line 'IMPLICIT NONE' makes it impossible to implicitly declare VARIABLES. I'd like to know if there is a similar line (or way of declaring) that makes it impossible to implicitly declare STATEMENTS -- in particular, the statement 'USE MODULE_NAME' (where MODULE_NAME is the name of a module being USEd). The reason is that, to my understanding, it is possible to 'implicitly' have the line 'USE MODULE_NAME'. An example of how this is done is given below.
Consider 3 files (in Fortran 90):
1. module_set_precision.f90
2. module_peter.f90
3. main_program.f90
They are described briefly below.
1. set the level of precision of numerical calculations.
module_set_precision.f90
------------------------
MODULE set_precision
INTEGER, PARAMETER :: P_REAL = SELECTED_REAL_KIND(P=15)
END MODULE set_precision
2. a module that contains a subroutine. the important line in the subroutine is 'USE set_precision'.
module_peter.f90
----------------
MODULE peter
USE set_precision
IMPLICIT NONE
CONTAINS
SUBROUTINE bill(input,output)
...
REAL(KIND=P_REAL),INTENT(IN) :: input
REAL(KIND=P_REAL),INTENT(OUT) :: output
...
END SUBROUTINE bill
END MODULE peter
3. the main program, that uses both MODULE set_precision and MODULE peter. if written 'correctly', this main program looks something like this:
main_program.f90
----------------
IMPLICIT NONE
USE set_precision
USE peter
...
REAL(KIND=P_REAL) :: steve
REAL(KIND=P_REAL) :: daniel
...
CALL bill(steve, daniel)
...
END
4. the problem
In the above file main_program.f90, included explicitly is the line
IMPLICIT NONE
which means that all VARIABLES must be declared explicitly. but, in the same main program, it is possible to 'accidentally' forget to include the line
USE set_precision
(in order to USE MODULE set_precision), and yet this line is still 'implicitly' declared (in the main program) because of the line
USE peter
(which USEs MODULE peter), because MODULE peter 'explicitly' has the line 'USE set_precision'. the resulting 'incorrect' main program would look like this:
main_program.f90
----------------
IMPLICIT NONE
USE peter
...
REAL(KIND=P_REAL) :: steve
REAL(KIND=P_REAL) :: daniel
...
CALL bill(steve, daniel)
...
END
this is not good programming.
i've read about the words PRIVATE, PUBLIC. but i'm not sure if they are the solution to this problem.
i've also read that the position of the line 'USE set_precision' (in MODULE peter) could be causing this problem. currently, it is positioned BELOW the line 'MODULE peter' (thereby giving the whole content of MODULE peter access to it). maybe, it should instead be positioned BELOW the line 'SUBROUTINE bill (input,output)', so that only 'SUBROUTINE bill' has access to it. the resulting module/subroutine would look like this:
module_peter.f90
----------------
MODULE peter
IMPLICIT NONE
CONTAINS
SUBROUTINE bill(input,output)
USE set_precision
...
REAL(KIND=P_REAL),INTENT(IN) :: input
REAL(KIND=P_REAL),INTENT(OUT) :: output
...
END SUBROUTINE bill
END MODULE peter
but again, i'm not sure if that is the solution to this problem.
can anyone offer any suggestions to this problem?
any help would be appreciated.
cheers
bill g
billgray1234@hotmail.com