Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Program arrayReduction2

program arrayReduction
implicit none
    
    real, dimension(1:6) :: a = (/21.0, 12.0, 33.0, 24.0, 15.0, 16.0/)
    
    Print *, maxval(a)
    Print *, minval(a)
    Print *, sum(a)
    Print *, product(a)
    
end program arrayReduction

Compile and Execute FORTRAN-95 Online

program one

Implicit none

Real,Dimension(:,:),allocatable:: stroke,lvdt,total

Integer::strokenum,lvdtnum,i,totalnum,maxnum,k,j

!OPEN(1,file="input.txt",ACTION="READ")
!OPEN(2,file="output.txt",ACTION="WRITE",STATUS="new")


read(*,*) strokenum,lvdtnum

totalnum=strokenum+lvdtnum

!maxnum=max(strokenum,lvdtnum)

allocate(stroke(strokenum,3),lvdt(lvdtnum,2),total(totalnum,4))

DO  i=1,strokenum
read(*,*)  stroke(i,1:2)
END DO

DO  i=1,lvdtnum
read(*,*)  lvdt(i,1:2)
END DO


stroke(1:strokenum,3)=222222


write(*,*) ""
write(*,*) "Stroke Matrix is:"
DO  i=1,strokenum
Write(*,*)  stroke(i,1:3)
END DO

write(*,*) ""
write(*,*) "Lvdt Matrix is:"
DO  i=1,lvdtnum
Write(*,*)  lvdt(i,1:2)
END DO

k=1

Do i=1,strokenum


500     if (stroke(i,1)<=lvdt(j,1)) then
        write(*,*) "ddddddddd"
        total(k,1)=stroke(i,1)
        k=k+1
        j=1
        else 
        write(*,*) "ffffffff"
        total(k,1)=lvdt(j,1)
        k=k+1
        j=j+1
        go to 500
        end if
        
        
        

end do   

write(*,*) ""
write(*,*) "total Matrix is:"
DO  i=1,totalnum
Write(*,*)  total(i,1:2)
END DO

end program one

Učitaj matricu K, generiraj matricu L, ispi&scaron;i obje matrice, izračunaj Z=K-L, ispi&scaron;i mat. Z, izračunaj aritmetičku sredinu mat. Z

module procedures
  implicit none

contains

subroutine printArray (darray)      
   real, dimension (:,:), intent(inout) :: darray

   integer :: s1, s2     
   integer :: i, j     
   
   s1 = size(darray,1)
   s2 = size(darray,2)
   
   print *, s1,s2
   
   do i = 1, s1           
      do j = 1, s2                
         print*, "darray(",i,",",j,") = ", darray(i,j)           
      end do      
   end do  
   
end subroutine printArray 



subroutine calculateArray (K,L,Z)      
   real, dimension (:,:), intent(inout) :: K,L,Z

   integer :: s1, s2     
   integer :: i, j     
   
   s1 = size(K,1)
   s2 = size(K,2) 
   
   do i = 1, s1           
      do j = 1, s2                
         ! read*,darray(i,j)
         ! ovo treba uključiti
         Z(i,j)=K(i,j)-L(i,j)
      end do      
   end do  

end subroutine calculateArray


subroutine fillArray (darray)      
   real, dimension (:,:), intent(inout) :: darray

   integer :: s1, s2     
   integer :: i, j     
   
   s1 = size(darray,1)
   s2 = size(darray,2)
   
   print *, s1,s2
   
   do i = 1, s1           
      do j = 1, s2                
         ! read*,darray(i,j)
         ! ovo treba uključiti
         darray(i,j)=1
         print*, "darray(",i,",",j,") = ", darray(i,j) 
      end do      
   end do  

end subroutine fillArray 


! this function computes the area of a circle with radius r  
function aritSredina (darray)  

! function result     
implicit none      

   ! dummy arguments        
   real :: aritSredina   
   
   ! local variables 
   real, dimension (:,:), intent(inout) :: darray
   
   
   integer :: s1, s2     
   integer :: i, j   
   real :: sredina
   
   sredina = 0
   
   s1 = size(darray,1)
   s2 = size(darray,2)
   
   
   do i = 1, s1           
      do j = 1, s2                
         sredina = sredina + darray(i,j)
      end do      
   end do  
   
   aritSredina = sredina  / (s1 * s2)
   
end function aritSredina

end module


program dynamic_array 
    use procedures
    
implicit none 

   !rank is 2, but size not known   
   real, dimension (:,:), allocatable :: darray 
   real, dimension (:,:), allocatable :: K,L,Z
   integer :: s1, s2     
   integer :: i, j    
   real :: sredina
   
   print*, "Enter the size of the array:"     
   ! read*, s1, s2
   ! Ovaj read treba odkomentirati u pravom programu i komentirati treba s1,s2
   ! Kompajler ima problema sa standarnim inputom pa s1 i s2 postavljam ovdje ručno
   s1 = 4
   s2 = 4
   
   ! allocate memory      
   allocate ( K(s1,s2) )      
   allocate ( L(s1,s2) )   
   allocate ( Z(s1,s2) )  
   
   call fillArray(K) 
   call fillArray(L) 
   
   call printArray(K)
   call printArray(L)
   
   call calculateArray(K,L,Z) 
   call printArray(Z)
   
   print *, ""
   print *, "Aritmetička sredina matrice Z je ",  aritSredina(Z)  

   
   deallocate (K)  
end program dynamic_array

Compile and Execute FORTRAN-95 Online

program HW03_04
   implicit none
   real::x=0
   integer::i
   Do i=1,7
   print*, 'number=', x
   x=x+3
   end do
end program HW03_04

Program arrayProg

program arrayProg
   
   real :: numbers(5) !One dimension integer array
   integer :: matrix(3,3), i, j !two dimwnsional real array
   
   !assing some values to the array numbers
   do i=1, 5
        numbers(i) = i * 2.0
   end do
   
   !Display the values
   do i=1, 3
        Print *, numbers(i)
   end do
   
   !Assing some values to the array matrix
   do i=1, 3
        do j=1, 3
            matrix(i,j) = i+j
        end do
   end do
   
   !Display the values
   do i=1, 3
        do j=1, 3
            Print *, matrix(i,j)
        end do
   end do
   
   !Short hand assignment
   numbers = (/1.5, 3.2, 4.5, 0.9, 7.2/)
   
   !Display the values
   do i=1, 5
        Print *, numbers(i)
   end do
   
end program arrayProg

test.....................................

program instruens_fabulam
  implicit none  

  ! the variables
  integer stat
  character(79) :: line

  ! this opens the input file
  open (25, file='text.txt', status='old', iostat=stat)


  ! this opens the output file
  open (50, file='outtext.txt', status='unknown', iostat=stat)


  ! runs file
  do while (.true.)
    read (25, '(A)', end=79) line ! reads input line
    write(*, '(80A)') line        ! writes line to the screen
	
    write(50, '(A)') trim(line)   ! writes line to output file, removes trailing characters
    
    
  enddo
  
  ! this closes the files
  79 continue
  close (25)
  close (50)
    
end program instruens_fabulam

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.