recursion - Recursive Combination on Fortran -


i wrote recursive program on fortran calculate combinations of npoints of ndim dimensions follows. first wrote program on matlab , running. in fortran, problem after first iteration assigning absurd values list of points, no explanation. give me hand?

program main    implicit none     integer :: ndim, k, npontos, contador,i,iterate, test    integer, dimension(:), allocatable :: pontos     print*, ' '    print*, 'npoints?'    read *, npontos    print*, 'ndim?'    read *, ndim    k=1    contador = 1    open(450,file= 'combination.out',form='formatted',status='unknown')    write(450,100) 'comb  ','stat  ',(' pt ',i,' ',i=1,ndim)    write(450,120) ('xxxxxxxxxx ',i=1,ndim+1)    allocate(pontos(ndim))     i=1,4    pontos(i)=i    end      test = iterate(pontos, ndim, npontos,k,contador)          end program main           recursive integer function iterate(pontos, ndim, npontos, k,contador)            implicit none            integer, intent(in) :: ndim, k, npontos            integer,dimension(:) :: pontos            integer contador,inic,i,j,m               if (k.eq.ndim)                  inic=pontos(ndim)                  = pontos(ndim),npontos                     pontos(k)=                     write(*,*) pontos(:)                       contador=contador+1                  end                  pontos(ndim)= inic + 1                              else                  inic = pontos (k)                  j = pontos(k),(npontos-ndim+k)                      pontos(k)=j                      pontos= iterate(pontos, ndim, npontos, k+1,contador)                 end             end if               pontos(k)=inic+1;            if (pontos(k).gt.(npontos-ndim+k+1))                 m =k+1,ndim                     pontos(m)=pontos(m-1)+1                 end             end if                         end function iterate 

there many issues in code... stopped debugging it. got far, it's comment.

this doesn't make sense:

pontos= iterate(pontos, ndim, npontos, k+1,contador) 

you changing pontos inside iterate, , never set return value within function.

you need a) provide result statement recursive functions (and set it) or b) convert subroutine. since modifying @ least 1 dummy argument, should go b).

since using assumed-shape dummy arguments, need specify interface function/subroutine, either explicitly or module.

neither format 100 nor format 120 specified in code.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

c# - Retrieve google contact -

javascript - How to insert selected radio button value into table cell -