- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to select elements in an array that meet a certain condition.
program subsetting implicit none real,dimension(100)::A ! I declare an array(say,B) elements of which are greater than 0.15 in A call random_number(A) ! I have to select elements that are greater than 0.15 and store them in B end program subsetting
The problem here is that I don't know how many elements are greater than 0.15. How can I write a code for getting the array B?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
program subsetting implicit none real,dimension(100)::A ! I declare an array(say,B) elements of which are greater than 0.15 in A real, allocatable, dimension(:) :: B call random_number(A) ! I have to select elements that are greater than 0.15 and store them in B B = PACK(A,(A > 0.15)) print *, B end program subsetting
Compile with /standard-semantics (Fortran > Language > Enable F2003 Semantics)
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
program subsetting implicit none real,dimension(100)::A ! I declare an array(say,B) elements of which are greater than 0.15 in A real, allocatable, dimension(:) :: B call random_number(A) ! I have to select elements that are greater than 0.15 and store them in B B = PACK(A,(A > 0.15)) print *, B end program subsetting
Compile with /standard-semantics (Fortran > Language > Enable F2003 Semantics)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
PACK! Thanks you, Steve.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page