Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to search number of occurence in fortran

I am new in fortran. I want to know, for example if I have an 1d array,
indices=(/1, 1, 1, 2 , 2 ,10, 11 /) and I want to know how many times 1 occur (answer should be 3), number 2 should be 2 times, num 10 should be 1 also number 11, . I already tried to find out if there is intrinsic function but ‘count’ function works differently.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use the count intrinsic with a comparison operator, e.g.

integer :: indices(5)
indices = [1, 1, 1, 2, 2, 10, 11]
write(*,*) count(indices==1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading