help with module

help with module

module parameters
integer,protected:: &
fstart=0, &!0=>start from scratch
&!1=>read restart file
ldim=3, &!Lattice dimension
norb=3, &!Number of orbital calc.
nrsite=14, &!Nearest neighbour in real space
nasite=73109, &!Number of site in AS Map
ntype=2, &!Number of atom type
nsite=369902, &!Total number of n.n. in AS Map
maxrec=12, &!Number of recursion step
lorbit=9, &!Number of orbital(s+p+d)
nscf=101, &!SCF loop
imax=172, &
info=172, &
llmax=16, &
jl=7, &
ienum=7, &!Number of seeds for fitting
nkp=17, &!Number of points extrapolated
!for a and b
nfn=900, &
spn=2 !1=>up spin;2=>down spin

real*8,protected:: &
emin=-0.9d0, &!emax->emin=energy range
emax=1.00d0, &!
z_a=26.0d0, &!Atomic number of atom A
z_b=24.0d0, &!Atomic number of atom B
c_a=18.0, &!Core electron atom A
c_b=18.0, &!Core electron atom B
x=0.7, &!Conc. of atom type A
ALPF=0.005882d0,&
ALPS=0.34850d0, &!POTPAR for orb. S
ALPP=0.05303d0, &!POTPAR for orb. P
ALPD=0.01071d0, &!POTPAR for orb. D
ruban=0.10d0, &
amix=0.06d0 !Mixing scheme parameter

character(7)::ASMAP='BCC_MAP'
character(7)::CHK_A='CHECK_A',CHK_B='CHECK_B'
character(8)::STRUCTURE ='INFO_BCC'

integer::ntsite,ienump,npn
real::filling,e_a,e_b,y

ntsite=nrsite+3 ! Dimension of AS Map
ienump=ienum+1 !
e_a=z_a-c_a ! Valence electron atom A
e_b=z_b-c_b ! Valence electron atom B
filling=x*e_a+y*e_b !
npn=lorbit*ienump !
y=1.00d0-x ! Conc. of atom type B
end module parameters

In this module,when i am definning like "ntsite=nrsite+3" and so on,
its giving error like
error #6274: This statement must not appear in the specification part
of a module
ntsite=nrsite+3 ! Dimension of AS Map
and so on for all the remainning lines. does it mean i cannot declare
values in module in this way? I checked the J3 manual with no help.

9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

MODULE statement has syntax:

MODULE name

[specification-part]

[CONTAINS

module-subprogram

[module-subprogram]...]

END[ MODULE [name]]

Where the specification-part can only have nonexecutable statement that declares the attributes of data objects. ""ntsite=nrsite+3" is a executable assignment statement so it can not be put there. You may move those lines causing error into a module procedue. Details about "MODULE" statement can be found in the compiler documentation -> language reference.

well, I think if he did:

integer, parameter :: nrsite = 14

then he could do

integer, parameter :: ntsite = nrsite + 3

without problem.

Ricardo Reis 'Non Serviam' @ http://www.lasef.ist.utl.pt @ http://www.radiozero.pt @ http://rreis.tumblr.com @ http://www.flickr.com/photos/rreis

yes! using parameter is doing fine.....but there is some other problem...where parameter is not good

Quoting - roddur
yes! using parameter is doing fine.....but there is some other problem...where parameter is not good

can you be more specific?

Ricardo Reis 'Non Serviam' @ http://www.lasef.ist.utl.pt @ http://www.radiozero.pt @ http://rreis.tumblr.com @ http://www.flickr.com/photos/rreis

ok, let me explain what i want to do!i have some variables that should be available to all other prgrams; so i use the module.
but some of them,like x,y,e_a,c_a etc. varies from 1 run to another(all other are constant between runs). like:
module parameters

! use kinds
! PUBLIC
integer,parameter:: &
fstart=0, &!0=>start from scratch
! &!1=>read restart file
lattice=221, &
ldim=3, &!Lattice dimension
norb=3, &!Number of orbital calc.
nrsite=14, &!Nearest neighbour in real space
nasite=73109, &!Number of site in AS Map
ntype=2, &!Number of atom type
ntsite=nrsite+3,&!Dimension of AS Map
nsite=369902, &!Total number of n.n. in AS Map
maxrec=12, &!Number of recursion step
lorbit=9, &!Number of orbital(s+p+d)
nscf=101, &!SCF loop
imax=172, &
info=172, &
llmax=16, &
jl=7, &
ienum=7, &!Number of seeds for fitting
ienump=ienum+1, &
nkp=17, &!Number of points extrapolated
!for a and b
nfn=900, &
spn=2, &!1=>up spin;2=>down spin
npn=lorbit*ienump

real*8,parameter:: &
emin=-0.9d0, &!emax->emin=energy range
emax=1.00d0, &!
z_a=26.0d0, &!Atomic number of atom A
z_b=24.0d0, &!Atomic number of atom B
c_a=18.0, &!Core electron atom A
c_b=18.0, &!Core electron atom B
e_a=z_a-c_a, &!Valence electron atom A
e_b=z_b-c_b, &!Valence electron atom B
x=0.7, &!Conc. of atom type A
y=1.00d0-x, &!Conc. of atom type B
ALPF=0.005882d0,&
ALPS=0.34850d0, &!POTPAR for orb. S
ALPP=0.05303d0, &!POTPAR for orb. P
ALPD=0.01071d0, &!POTPAR for orb. D
ruban=0.10d0, &
amix=0.06d0, &!Mixing scheme parameter
filling=x*e_a+y*e_b
character(7)::ASMAP='BCC_MAP'
character(7)::CHK_A='CHECK_A',CHK_B='CHECK_B'
character(8)::STRUCTURE ='INFO_BCC'
end module parameters

What i am doing till now is changing them for each run and "make" it eachtime.

Now what i want to do is use x,y e_a etc as command line argument(or read from a namelist or whatever) and do the same thin so that i dont have to remake for each run.
any way of doing that?

Quoting - roddur
ok, let me explain what i want to do!i have some variables that should be available to all other prgrams; so i use the module.
but some of them,like x,y,e_a,c_a etc. varies from 1 run to another(all other are constant between runs). like:
module parameters

! use kinds
! PUBLIC
integer,parameter:: &
fstart=0, &!0=>start from scratch
! &!1=>read restart file
lattice=221, &
ldim=3, &!Lattice dimension
norb=3, &!Number of orbital calc.
nrsite=14, &!Nearest neighbour in real space
nasite=73109, &!Number of site in AS Map
ntype=2, &!Number of atom type
ntsite=nrsite+3,&!Dimension of AS Map
nsite=369902, &!Total number of n.n. in AS Map
maxrec=12, &!Number of recursion step
lorbit=9, &!Number of orbital(s+p+d)
nscf=101, &!SCF loop
imax=172, &
info=172, &
llmax=16, &
jl=7, &
ienum=7, &!Number of seeds for fitting
ienump=ienum+1, &
nkp=17, &!Number of points extrapolated
!for a and b
nfn=900, &
spn=2, &!1=>up spin;2=>down spin
npn=lorbit*ienump

real*8,parameter:: &
emin=-0.9d0, &!emax->emin=energy range
emax=1.00d0, &!
z_a=26.0d0, &!Atomic number of atom A
z_b=24.0d0, &!Atomic number of atom B
c_a=18.0, &!Core electron atom A
c_b=18.0, &!Core electron atom B
e_a=z_a-c_a, &!Valence electron atom A
e_b=z_b-c_b, &!Valence electron atom B
x=0.7, &!Conc. of atom type A
y=1.00d0-x, &!Conc. of atom type B
ALPF=0.005882d0,&
ALPS=0.34850d0, &!POTPAR for orb. S
ALPP=0.05303d0, &!POTPAR for orb. P
ALPD=0.01071d0, &!POTPAR for orb. D
ruban=0.10d0, &
amix=0.06d0, &!Mixing scheme parameter
filling=x*e_a+y*e_b
character(7)::ASMAP='BCC_MAP'
character(7)::CHK_A='CHECK_A',CHK_B='CHECK_B'
character(8)::STRUCTURE ='INFO_BCC'
end module parameters

What i am doing till now is changing them for each run and "make" it eachtime.

Now what i want to do is use x,y e_a etc as command line argument(or read from a namelist or whatever) and do the same thin so that i dont have to remake for each run.
any way of doing that?

just separate the declarations.

like:

integer, parameter :: param1=x1, param2=x2, etc
integer :: var1,var2,var3

or if you are more of a tidy person use two modules, one for parameters and the other for common variables wich you initialize after reading some file or from keyboard input

Ricardo Reis 'Non Serviam' @ http://www.lasef.ist.utl.pt @ http://www.radiozero.pt @ http://rreis.tumblr.com @ http://www.flickr.com/photos/rreis

If I read your post correctly I do exactly what you are trying to do all the time. I tend to try to use modules in an OO fashion; they each represent an objoct or a class of objects, with the appropriate procedures to operate on these objects declared as functions or subroutines below the CONTAINS line of the module. So parameters which are never modified can be declared as parameters, but if you have constants which you want to initialize at run time but do not change during each run you can declare them in a module with the fortran 2003 attribute: PROTECTED. e.g. REAL, PROTECTED :: var_which_is_read_only_outside_the_module. I think of this as a black box with a window, it is a nice way to have the pros of global variables without the cons. This way you can have access to these protected variables outside the module via use association, but they can only be modified by calling routines defined within the module. Additionally, modules provide the ability to protect your namespace by using ONLY: clauses which allow you to limit access to entities within the module from the scoping unit which USEs the module, and allow you to alias procedures (and I beleive entities such as derived types and variables) which may already be defined in the host scoping unit.

Here is a code snippet:

MODULE init_constants
  IMPLICIT NONE
  INTEGER, PARAMETER :: iparam1 = 1, iparam2 = 2, max_arg_len = 70 ! characters
 REAL,       PARAMETER :: rparam1 = 10.0, rparam2 = 20.0
  CHARACTER(len=max_arg_len), DIMENSION(:), ALLOCATABLE, PROTECTED :: raw_args

 ! Define more variables, parameters, derived types, interfaces, etc.

CONTAINS
  SUBROUTINE get_cmdli_arguments(correct_num_args)
    INTEGER, INTENT(in), OPTIONAL :: correct_num_args
    INTEGER :: i, n_args

    n_args = COMMAND_ARGUMENT_COUNT() ! Fortran 2003 
    IF (PRESENT(correct_num_args)) THEN
      IF (n_args /= correct_num_args) THEN
        ! CALL ERROR()
        ! RETURN ! With some error code
      END IF
    END IF
    ALLOCATE(raw_args(n_args))
    DO i = 1, n_args
      CALL get_command_argument(i,raw_args(i))
    END DO
  END SUBROUTINE get_cmli_arguments
END MODULE init_constants

Note that command line arguments are read in as character variables and you will have to use read statements to read these character variables (i.e. internal file) into the appropriate real, integer, etc. variables. If you wish you maye do this from within the currect module. Simply change raw_args PROTECTED attribute to PRIVATE, declare REAL or INTEGER variables as PROTECTED, and define another subroutine in the module to read the apropriate raw_arg into the appropriate protected variable. From your main program simply USE init_constants, and then before you start any computations CALL get_cmli_arguments and then if desired CALL the subroutine you wrote to convert/READ the command line arguments into each one's appropriate variable. For a more complicated example see my file IOutils.f90.

-Zaak

Thanks everybody ...its done

Login to leave a comment.