Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declare array help

Status
Not open for further replies.

hotsu

Technical User
Dec 18, 2007
1
CA
I'm new to FORTRAN programming and I've been working with code that was first compiled with Digital Visual Fortran 5.0 and am now using Intel Visual Fortran 10.1. I corrected most of the errors but I can't figure out how to declare veh(i) in this subroutine below:

Code:
      SUBROUTINE read_veh()
      
          USE IFQWIN	
          USE commod                    ! Access to commod.f90  

          IMPLICIT NONE    
          INTEGER(4)               i,nveh         
          READ (8,11) rad,lane,shoulder  
          READ(8,10) nveh, noption

   10     FORMAT(I1,1x,I1)
      
          DO i=1,nveh
          READ(8,11) veh(i).w,veh(i).wb,veh(i).ero,veh(i).efo,veh(i).pin 
   11     FORMAT(5(F5.2,1x),A1)              
          END DO
      END

The commod module looks like this:

Code:
      MODULE commod

          IMPLICIT NONE
          INTEGER(4)     black,blue,green,red,cyan,purple,brown,yellow,white,grey,orange,pick,nveh,noption
          REAL(8)        rad,lane,shoulder

          TYPE vehicle_dim
                  CHARACTER(25)         name
                  CHARACTER(1)          steer
                  INTEGER(4)            veh(9)
                  REAL(8)               x1,y1,x2,y2,w,wb,ero,efo,pin,b                     
          END TYPE vehicle_dim
      
      END MODULE commod

In the main program I use OPEN statements of this sort:
OPEN (6,FILE='out.dat')
OPEN (8,FILE='in.dat')

 
Code:
! for a static size
TYPE (vehicle_dim), dimension(10)::veh
! for a dynamic size
TYPE (vehicle_dim), dimension(:), allocatable::veh
...
allocate (veh(nveh))

You have to remember to deallocate when you've finished
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top