modules?

There is something basic I don’t understand about modules. I want to convert include files that shared data via the old common block structure by changing the files to modules.

Extracted the basic issue to a simple example. If I leave the module in the file with the program and other subroutines, no problem. If I take the module out as a separate file I get the following typical error:
E:\PGI_5-11-2013mod2\Source Files\fall.f90(8) : error F0004 : Corrupt or Old Module file E:\PGI_5-11-2013mod2\Include Files\constants.mod
error F0004 : Corrupt or Old Module file E:\PGI_5-11-2013mod2\Include Files\constants.mod

Could someone suggest what I’m doing wrong please?

      module constants
         integer, parameter :: np=2000, dbl=selected_real_kind(14,100)
         real(dbl) :: g=9.807, dtmin=.001, kspg=10., mass = 100.0
      end module constants



      program fall
!
      use constants
      implicit none
!
!   Program to calculate the dynamics of a falling body
!
      real(dbl), allocatable :: v(:),z(:),t(:), zreal(:)
      real(dbl) dt
      integer nsteps
!
      allocate (v(np),z(np),t(np),zreal(np))
      call input(z,dt)
      call odesolve(v,z,t,dt,nsteps)
      call realans(t,z,nsteps,zreal)
      call output (t,z,zreal,v,nsteps)
      stop
      end


      subroutine input (z,dt)
      use constants
      implicit none
.
.
      return
      end


      subroutine odesolve(v,z,t,dt,nsteps)
      use constants
      implicit none
!
      real (dbl) v(*),z(*),t(*),dt,c0,c1
      integer i,nsteps
.
.
      return
      end


      subroutine realans(t,z,nsteps,zreal)
      use constants
      implicit none
.
.
      return
      end

      subroutine output(t,z,zreal,v,nsteps)
      use constants, only : dbl
      implicit none
.
.
      return
      end

Same problem with either PVF 13.4 or 13.5 using VS2008 in Windows 7 64-bit.

Thanks

Hi Ralph,

This error typically occurs when the module file being using was created with a different compiler (either an older PGI or another vendor). Can you try cleaning out the Include directory and then recompiling?

Thanks,
Mat

Matt,

That was the source code and the include directory was clean. Redid it, same result.

constants module (constants.mod)

      module constants
!
         integer, parameter :: np=2000, dbl=selected_real_kind(14,100)
!
         real(dbl) :: g=9.807,dtmin=.001, kspg=10., mass = 100.0
!
      end module constants

program.f90

      program fall
!
      use constants
!
      implicit none
!
!   Program to calculate the dynamics of a falling body
!
      real(dbl), allocatable :: v(:),z(:),t(:), zreal(:)
      real(dbl) dt
      integer nsteps
!
      allocate (v(np),z(np),t(np),zreal(np))
      call input(z,dt)
      call odesolve(v,z,t,dt,nsteps)
      call realans(t,z,nsteps,zreal)
      call output (t,z,zreal,v,nsteps)
      stop
      end
!
      subroutine input (z,dt)
      use constants
      implicit none
!
      real(dbl) z(*),dt
!
      write(6,'(a)',advance='no') ' Initial height (meters): '
      read *, z(1)
      write(6,'(a)',advance='no') 'Time step size (seconds): '
      read *, dt
      if(dt.le.0.) dt=dtmin
      return
      end
!
      subroutine odesolve(v,z,t,dt,nsteps)
!
      use constants
      implicit none
!
      real (dbl) v(*),z(*),t(*),dt,c0,c1
      integer i,nsteps
!
      t(1)=0.
      v(1)=0.
!
!   Set some useful constants
!
      c1=dt*kspg/mass
      c0= c1*z(1)-g*dt
!
      do 100 i=2,np
         v(i)= (c0-c1*z(i-1)+(1.-0.25*c1*dt)*v(i-1))/(1.+.25*c1*dt)
         z(i)= z(i-1)+dt*.5*(v(i)+v(i-1))
         t(i)=t(i-1)+dt
         if(z(i).lt.0.) go to 200
 100     continue
      write(6,*) 'Ran out of space to continue integration'
      write(6,*) ' Last height was ',z(np),' meters'
      i=np
 200  nsteps=i
!     return
      end
!
      subroutine realans(t,z,nsteps,zreal)
      use constants
      implicit none
!
      real(dbl) t(*),z(*),zreal(*),c1,c2
      integer i,nsteps
      c1=g*mass/kspg
      c2=sqrt(kspg/mass)
!
      do 10 i=1,nsteps
  10  zreal(i)=c1*cos(c2*t(i)) + z(1)-c1
      return
      end
!
      subroutine output(t,z,zreal,v,nsteps)
      use constants, only : dbl
      implicit none
!
      real(dbl) v(*),z(*),t(*), zreal(*)
      integer nsteps,i
      print *, 'Results are in fall.output'
      open (11,file='fall.output')
      write(11,2000)
      do 300 i=1,nsteps
      write(11,2001) t(i),z(i),zreal(i),z(i)-zreal(i)
 300  continue
 2000 format (21x,'Computed',8x,'Actual',/,
     &        6x,'Time',12x,'Height',9x,'Height',9x,'Error')
 2001 format (1x,1p,4e15.7)
      return
      end

Compiler directives:
-g -Bstatic -Mbackslash -I"F:\test-PGI\Include files" -I"d:\program files\pgi\win64\13.5\include" -I"D:\Program Files\PGI\Microsoft Open Tools 11\include" -I"D:\Program Files\PGI\Microsoft Open Tools 11\PlatformSDK\include" -Minform=warn

This has gota be something simple that I’m doing wrong.

Ralph,

Your test case compiles for me using 13.5, both within PVF and from the command line. It’s possible that the location of the generated constants.mod could be an issue. What have you specified for PVF’s Fortran | General | Module Path property?

Annemarie

Annemarie,

Yes, I’ve input the module path in PVF’s Fortran->General->Module Path. I’ve also tried it in same location as the .f90 file and in both at the same time. I assume your file extension is .mod but I’ve tried .f90 too.

I’m using PVF in VS2008 in Windows 7 64-bit. Same resolute for PVF 13.4 and 13.5.

I’m totally stumped.


-ralph

Ralph, let’s try this to see if we can get what works for me working for you using the sample source you provided.

  1. Create a new PVF solution in C:\tmp.
  2. Add a new source file to the project, name it constants.f90, and paste in the code for module constants. (Please do not use an existing file.)
  3. Add another new source file to the project, name it fall.f90, and paste in the code for program fall.
  4. Use the solution explorer to verify that in your PVF project the Source Files folder contains both constants.f90 and fall.f90.
  5. Build the solution.

That should be all that’s required to build the sample code. Let me know how it goes.

Annemarie

Yes, that does work. Which drive is used shouldn’t be an issue and the process does repeat on my F-drive with no problem.

Here is the main differences between the process you outlined and what I’ve done previously.
– I’ve been creating a container folder on my F drive, e.g. PGI_5-14-2013.
– I then typically add 3 new folders in PGI_5-14-2013 1) Include Files, 2) Resource Files, and 3) Source Files where each of these have the files you would expect from their names. I didn’t want to place all the various type files in a single location.
– Next I create a PVF solution in PGI_5-14-2013
– Add my files from their folders into the solution folders.
– Setup up debugger, compiler, build, etc. options with appropriate paths for includes, modules, and working location.
– Build
I’ve also tried both .mod and .f90 extensions on the modules, didn’t have an effect.

My process has worked fine for a year+ when I was using include files but something is clearly amiss with the module files. (Of course that doesn’t mean my process fits the standard.)

So at least a couple things could be the source of my problems.

  1. My files aren’t down in the lower solution folders as those of the simple case.
  2. I don’t always use VS2008 templates to build source files, include files, or module files. If there is some attribute in their hidden data then simple creation of such files using a text editor could present problems.

I can play around with this some more but what are your thoughts at this point?

Annemarie,
After some testing with the simple case, I conclude that

  1. the module must be in the solution folder, i.e. the folder that contains the .pvfproj file. Placing the module in an alternate path and telling the compiler where via the compiler directive, Fortran->General->Module Path, doesn’t work.
  2. the extension for the module must be .f90.
  3. I can place source files (program, subroutines) and include files in other places and load via the VS standard add function plus a path as needed in the compiler directives.

-ralph

Ralph,

When you add the Fortran file containing the module code (i.e., constants.f90) to the PVF project, are you adding it to the ‘Include Files’ folder? If so, that is likely the problem. The module source code needs to be compiled like all the other Fortran source and should be in the PVF project’s ‘Source Files’ folder.

Annemarie

Annemarie,

The only place the module file will work (i.e. complete a successful build) is when the constants.f90 file is physically located in the solution folder and has been added to the PVF project’s “Sources Files” via the add existing file option. Nothing else works.


-ralph

I have now converted previous include files to modules within my code. And have been able to locate the modules to different storage places.

Thanks for the help.