fortran90 - Some questions about a piece of Fortran code, new to Fortran -


i ran piece of fortran code rather difficult understand.
1. name of structure of code / (i1,i1=0,nn-1) /?
how can print directly in code see content?
2. i'm looking ways change value of nn without re-compiling, how should this? nn supposed length of array omega.
3. how should setup length of omega in case of changeable nn? mean when i'll have no parameter (nn=20) anymore.

  program test_20140919   ! test   implicit none   integer nn   parameter (nn=20)   real omega(nn)    call test_real(nn, 2.0, 4.0, omega)    print *, omega   end program test_20140919    !c ===    subroutine test_real(nn, o1, o2, omega)         integer nn   real o1, o2   real omega(nn)    print *, nn   omega = o1 +  (o2*o1)*(/ (i1,i1=0,nn-1) /)/real(nn-1)   print *, real(nn)   return   end 

i've compiled line gfortran test.f -ffree-form -o test in terminal.

upd revised version of code due answers vladimir f:

      module subs          implicit none        contains          subroutine test_real(nn, o1, o2, omega)                 integer nn           real o1, o2           real :: omega(:)            if (.not. allocated(omega)) allocate(omega(nn))           omega = o1 +  (o2*o1)*(/ (i1,i1=0,nn-1) /)/real(nn-1)           print *, real(nn)          end subrotine        end module        program test_20140920       ! test          use subs          implicit none          integer nn         real, allocatable :: omega(:)          read(*,*) nn          allocate(omega(nn))          call test_real(nn, 2.0, 4.0, omega)          print *, omega       end program test_20140920 

1) (/ ... /) array constructor.

the expression (i1,i1=0,nn-1) implied-do loop.

2) read using read statement

     integer :: nn       read(*,*) nn 

3) use allocatable array

real, allocatable :: omega(:)  ...  allocate(omega(nn)) 

i recommend read fortran tutorial or fortran book , familiarize these concepts.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -