| 1 |
!----------------------------------------------------------------- |
| 2 |
! |
| 3 |
! This file is (or was) part of SPLASH, a visualisation tool |
| 4 |
! for Smoothed Particle Hydrodynamics written by Daniel Price: |
| 5 |
! |
| 6 |
! http://users.monash.edu.au/~dprice/splash |
| 7 |
! |
| 8 |
! SPLASH comes with ABSOLUTELY NO WARRANTY. |
| 9 |
! This is free software; and you are welcome to redistribute |
| 10 |
! it under the terms of the GNU General Public License |
| 11 |
! (see LICENSE file for details) and the provision that |
| 12 |
! this notice remains intact. If you modify this file, please |
| 13 |
! note section 2a) of the GPLv2 states that: |
| 14 |
! |
| 15 |
! a) You must cause the modified files to carry prominent notices |
| 16 |
! stating that you changed the files and the date of any change. |
| 17 |
! |
| 18 |
! Copyright (C) 2012 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!------------------------------------------------------------------------- |
| 24 |
! Module implementing generic menu where objects can be added |
| 25 |
! to/deleted from a list |
| 26 |
!------------------------------------------------------------------------- |
| 27 |
module promptlist |
| 28 |
implicit none |
| 29 |
interface |
| 30 |
subroutine print_objlist(nobj) |
| 31 |
integer, intent(in) :: nobj |
| 32 |
end subroutine |
| 33 |
end interface |
| 34 |
|
| 35 |
interface |
| 36 |
subroutine add_obj(istart,iend,nobj) |
| 37 |
integer, intent(in) :: istart,iend |
| 38 |
integer, intent(inout) :: nobj |
| 39 |
end subroutine add_obj |
| 40 |
end interface |
| 41 |
|
| 42 |
interface |
| 43 |
subroutine delete_obj(iobj,nobj) |
| 44 |
integer, intent(in) :: iobj,nobj |
| 45 |
end subroutine delete_obj |
| 46 |
end interface |
| 47 |
|
| 48 |
contains |
| 49 |
|
| 50 |
subroutine prompt_list(nobj,maxobj,objname,print_objlist,add_obj,delete_obj) |
| 51 |
use prompting, only:prompt |
| 52 |
integer, intent(inout) :: nobj |
| 53 |
integer, intent(in) :: maxobj |
| 54 |
character(len=*), intent(in) :: objname |
| 55 |
procedure(), pointer, intent(in) :: print_objlist,add_obj,delete_obj |
| 56 |
character(len=1) :: charp |
| 57 |
logical :: done,first |
| 58 |
integer :: istart,iend,ipick |
| 59 |
|
| 60 |
ipick = nobj + 1 |
| 61 |
done = .false. |
| 62 |
first = .true. |
| 63 |
charp = 'a' |
| 64 |
objmenu: do while(.not.done) |
| 65 |
call print_objlist(nobj) |
| 66 |
iend = maxobj |
| 67 |
if (nobj > 0 .or. .not.first) then |
| 68 |
charp='q' |
| 69 |
print* |
| 70 |
call prompt(' a)dd '//trim(objname)//', e)dit, d)elete, c)lear all or q)uit/finish?',& |
| 71 |
charp,list=(/'a','e','d','c','q','s','S','Q'/),noblank=.true.) |
| 72 |
select case(charp) |
| 73 |
case('a') |
| 74 |
istart = nobj |
| 75 |
iend = nobj + 1 |
| 76 |
case('e') |
| 77 |
if (nobj > 0) then |
| 78 |
ipick = 0 |
| 79 |
if (nobj > 1) then |
| 80 |
call prompt(' pick a '//objname//' to edit ',ipick,0,nobj) |
| 81 |
else ! if there is only one object, no need to ask which one |
| 82 |
print "(/,a)",' >> editing '//objname//' #1' |
| 83 |
ipick = 1 |
| 84 |
endif |
| 85 |
if (ipick > 0) then |
| 86 |
istart = ipick - 1 |
| 87 |
iend = istart + 1 |
| 88 |
else |
| 89 |
istart = 0 |
| 90 |
iend = 1 |
| 91 |
first = .false. |
| 92 |
cycle objmenu |
| 93 |
endif |
| 94 |
else |
| 95 |
istart = 0 |
| 96 |
iend = 1 |
| 97 |
endif |
| 98 |
first = .false. |
| 99 |
case('d') |
| 100 |
if (nobj > 0) then |
| 101 |
ipick = 0 |
| 102 |
call prompt(' pick a '//objname//' to delete ',ipick,0,nobj) |
| 103 |
call delete_obj(ipick,nobj) |
| 104 |
else |
| 105 |
print*,'nothing to delete!' |
| 106 |
endif |
| 107 |
first = .false. |
| 108 |
cycle objmenu |
| 109 |
case('c') |
| 110 |
nobj = 0 |
| 111 |
first = .false. |
| 112 |
cycle objmenu |
| 113 |
case('q','Q','s','S') |
| 114 |
done = .true. |
| 115 |
case default |
| 116 |
istart = 0 |
| 117 |
iend = maxobj |
| 118 |
end select |
| 119 |
else |
| 120 |
istart = 0 |
| 121 |
iend = 1 |
| 122 |
endif |
| 123 |
if (.not.done) call add_obj(istart,iend,nobj) |
| 124 |
first = .false. |
| 125 |
enddo objmenu |
| 126 |
|
| 127 |
return |
| 128 |
end subroutine prompt_list |
| 129 |
|
| 130 |
end module promptlist |