Density of state of a linear lattice

In summary: COS(kx*a0) WRITE ( * * ) Energy= w + ( i * eta ) LoopWaveVector : DO kx=-1000,1000 WRITE ( * * ) ek= 2 * t0*COS(kx*a0) WRITE ( * * ) GreenFunc= Energy - ek END DO LoopWaveVector END DO LoopEnergy
  • #1
MahdiI84
22
1
TL;DR Summary
hi ,I wrote the code in Fortran for the density of state of a linear lattice. Because I am new to Fortran coding, my program has many errors. Please help me. Thank you.
Fortran:
PROGRAM DensityOfState
    IMPLICIT NONE

    INTEGER :: omega , t0 , a0 ,kx
    omega=1 ; t0 =1 ; a0=1

    REAL :: kx  , eta , w , ek
     eta=0.0015
     REAL,PARAMETER :: pi=3.14

    COMPLEX , PARAMETER ::i=(0,1)

    COMPLEX :: Energy
    COMPLEX :: Density
    COMPLEX :: GreenFunc    LoopEnergy : DO w=-2,+2,0.001
       WRITE(*,*)  Energy= w +( i * eta)
   
    LoopWaveVector : DO kx=-1000,1000
     WRITE(*,*)    ek= 2*t0*COS(kx*a0)
 
       WRITE(*,*)  GreenFunc= Energy - ek
   
    END DO LoopEnergy
    END DO LoopWaveVector
    WRITE(*,*) IMAG(GreenFunc)
    Density= (1.0/pi*omega)*IMAG(GreenFunc)
     WRITE(*,*) Density
     END PROGRAM DensityOfState

((AND ERRORS))

1>------ Build started: Project: Console3, Configuration: Debug Win32 ------

1>Compiling with Intel(R) Visual Fortran Compiler XE 13.0.0.089 [IA-32]...

1>Source1.f90

error #5082: Syntax error, found IDENTIFIER 'ENERGY' when expecting one of: ( % [ . = =>

error #5082: Syntax error, found IDENTIFIER 'EK' when expecting one of: ( % [ . = =>

error #5082: Syntax error, found IDENTIFIER 'GREENFUNC' when expecting one of: ( % [ . = =>

error #6236: A specification statement cannot appear in the executable section.

error #6236: A specification statement cannot appear in the executable section.

error #6236: A specification statement cannot appear in the executable section.

error #6236: A specification statement cannot appear in the executable section.

error #6236: A specification statement cannot appear in the executable section.

error #6236: A specification statement cannot appear in the executable section.

error #6404: This name does not have a type, and must have an explicit type. [ETA]

error #6404: This name does not have a type, and must have an explicit type. [W]

error #6063: An INTEGER or REAL data type is required in this context. [W]

warning #6041: The increment in a DO is zero or evaluates to zero. [0.001]

error #6458: This name must be the name of a variable with a derived type (structure type) [WRITE]error #6404: This name does not have a type, and must have an explicit type.

error #6458: This name must be the name of a variable with a derived type (structure type) [WRITE]

warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL. [COS]

1 error #6404: This name does not have a type, and must have an explicit type. [COS]

error #6458: This name must be the name of a variable with a derived type (structure type) [WRITE]

error #6404: This name does not have a type, and must have an explicit type. [ENERGY]

error #6404: This name does not have a type, and must have an explicit type. [EK]

error #6606: The block construct names must match, and they do not. [LOOPENERGY]

error #6606: The block construct names must match, and they do not. [LOOPWAVEVECTOR]

error #6404: This name does not have a type, and must have an explicit type. [GREENFUNC]

warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL. [IMAG]

error #6404: This name does not have a type, and must have an explicit type. [IMAG]

error #6404: This name does not have a type, and must have an explicit type. [DENSITY]

error #6404: This name does not have a type, and must have an explicit type. [PI]

1>compilation aborted for c:\users\mahdi\documents\visual studio 2012\Projects\Console3\Console3\Source1.f90 (code 1)
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
When you get a long list of errors, usually the best thing to do is to address the first one listed and see of that fixes things.

One thing I notice is that you have declared kx twice. That's a problem. Based on your code, I believe you intend for it to be in integer loop control variable. If so, get rid of the REAL declaration.
Another is that you have an executable statements mixed in amongst your declarations, namely eta = 0.0015

I would rearrange the first few lines like so, with Fortran 90-style variable initializations for omega t0, a0 and eta instead of assignment statements:
Fortran:
PROGRAM DensityOfState
    IMPLICIT NONE
 
    INTEGER :: omega=1 , t0=1 , a0=1 ,kx   ! *** Note that kx is declared twice
    ! omega=1 ; t0 =1 ; a0=1
 
    REAL :: kx  , eta=0.0015 , w , ek               ! *** Get rid of kx on this line
    ! eta=0.0015
     REAL,PARAMETER :: pi=3.14
 
    COMPLEX , PARAMETER ::i=(0,1)
 
    COMPLEX :: Energy
    COMPLEX :: Density
    COMPLEX :: GreenFunc

The changes above should eliminate at least some of the errors you showed.

After that, I would reorganize the two loops to make them more readable. The compiler doesn't care, but it's harder for humans to follow your logic. I would also get rid of your construct names (LoopEnergy and LoopWaveVector) and just add comments
Fortran:
DO w= -2, +2, 0.001                                      ! Energy loop
       WRITE(*,*)  Energy= w +( i * eta)
    
      DO kx=-1000,1000                              !   WaveVector loop
         WRITE(*,*)    ek= 2*t0*COS(kx*a0)  
         WRITE(*,*)  GreenFunc= Energy - ek
     END DO LoopEnergy

END DO LoopWaveVector
 
  • Like
Likes MahdiI84
  • #3
Hi mark44 ,thank you very much for your help. I will correct the points you mentioned.I will declaration the result again
 
  • #4
I corrected the bugs you mentioned and the result was as follows.Is not cosine the function introduced in the Fortran default? So why give an error for that?

warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL. [COS]

error #6404: This name does not have a type, and must have an explicit type. [COS]

compilation aborted for C:\Users\mahdi\Documents\Visual Studio 2012\Projects\Console3\Console3\Source1.f90 (code 1)
 
  • #5
Maybe COS( real * integer ) expects a real argument, without the integer datatype ?
 
  • Like
Likes MahdiI84
  • #6
Hi, thank you for your help. But I also tried this solution:

ek= 2*t0*COS(kx)*a0

But this error appeared

warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL. [COS]

error #6404: This name does not have a type, and must have an explicit type. [COS]
 
  • #7
The one line is out of context.
We need to see the code block that declares the type of kx and calls Cos( kx ).
 
  • Like
Likes MahdiI84
  • #8
corrected coding is as follows:

COMPLEX , PARAMETER ::i=(0,1)

COMPLEX :: Energy
COMPLEX :: Density
COMPLEX :: GreenFunc


DO w=-2,+2,0.001 ! Energy loop
Energy=w+i*eta
WRITE(*,*) Energy

DO kx=-1000,1000 ! WaveVector loop
ek= 2*t0*COS(kx)*a0
WRITE(*,*) ek


GreenFunc= Energy - ek

WRITE(*,*) GreenFunc

END DO
END DO
WRITE(*,*) IMAG(GreenFunc)
Density= (1.0/pi*omega)*IMAG(GreenFunc)
WRITE(*,*) Density
END PROGRAM DensityOfState
 
  • #9
And a warning and an error related to COSwarning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL. [COS]

error #6404: This name does not have a type, and must have an explicit type. [COS]
 
  • #10
You do not explicitly declare kx. I believe kx will be an integer.
But the intrinsic; real = Cos( real ); requires a real argument in radians.
 
  • Like
Likes MahdiI84
  • #11
thank you so much.it's ok:thumbup:
 
  • Like
Likes Baluncore
  • #12
Experienced FORTRAN programmers include the line IMPLICIT NONE at the head of their code, so they will be warned if they fail to explicitly declare the type of a variable.

That prevents many problems with data types taking the implicit type determined by the first character of the variable name; Variable names beginning with { i, j, k, l, m, n } are INTEGER, all others REAL, unless otherwise declared.

https://en.wikipedia.org/wiki/Fortran_95_language_features#Implicit_and_explicit_typing
 
  • Like
Likes MahdiI84
  • #13
Baluncore said:
Experienced FORTRAN programmers include the line IMPLICIT NONE at the head of their code, so they will be warned if they fail to explicitly declare the type of a variable.
The OP did include IMPLICIT NONE in the code shown in post #1.
 
  • Like
Likes MahdiI84
  • #14
your "do w" loop is of bad form, you should, loop counters should be integers.

DO w= 0,2001
someVariable = -2.0 + float(w)
Energy=someVariable +i*eta
WRITE(*,*) Energy Stylistically, I'd change i = cmplx(0,1) to ic=cmplx(0,1) so you don't get confused. I've also gotten into the habit of iteration variables written as, say, ii as opposed to i etc. My codes are less confusing to read down the road.

just my 2 cents...
 
  • Like
Likes MahdiI84
  • #15
Thank you very much for your guidance. If I change the W loop in your way, what will be the step? Because in this case, the step must be the value of 0.001.
 
  • #16
I'm sorry, early morning.

set w to an integer, then

someVariable = -2.0 + float(w)*0.001
 
  • Like
Likes MahdiI84
  • #17
Hi, good morning too. you'r welcome. The program runs without any problems and has no errors. But the final answer is not correct. I have coded an energy loop with 4000 outputs and a loop (kx) with 2000 outputs, but I do not receive this amount of data from the program. I do not know maybe my program has a fundamental problem.
 

1. What is the density of state of a linear lattice?

The density of state of a linear lattice refers to the number of energy states per unit volume that are available to a particle in the lattice. It is a measure of the number of possible energy states that a particle can occupy at a given energy level.

2. How is the density of state of a linear lattice calculated?

The density of state can be calculated using the formula D(E) = V/(2π)^3 * (2m/h^2)^3/2 * E^(1/2), where V is the volume of the lattice, m is the mass of the particles, h is Planck's constant, and E is the energy level.

3. What is the relationship between the density of state and the energy of a particle in a linear lattice?

The density of state increases as the energy of the particle increases. This means that there are more available energy states for the particle to occupy at higher energy levels.

4. How does the density of state change with the size of the lattice?

The density of state is directly proportional to the volume of the lattice. This means that as the size of the lattice increases, the density of state also increases, resulting in more available energy states for the particles.

5. How does the density of state differ for different types of particles in a linear lattice?

The density of state is dependent on the mass of the particles in the lattice. Heavier particles will have a lower density of state compared to lighter particles at the same energy level. This is because the formula for calculating density of state includes the particle's mass.

Similar threads

  • Other Physics Topics
Replies
12
Views
1K
  • Programming and Computer Science
Replies
11
Views
14K
  • Programming and Computer Science
Replies
6
Views
6K
Replies
6
Views
1K
Replies
1
Views
578
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Sci-Fi Writing and World Building
Replies
10
Views
2K
  • Programming and Computer Science
Replies
4
Views
15K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
Back
Top