!........................................................................ ! ! Subroutine : max_or_min_disp(CON, CO, i_con, value, location) ! ! Description: If the constrained parameter is displacement this ! routine will find the maximum or minimum or target of the ! parameter in the range ! ! Arguments : ! INPUT: CON -- constraints structure ! CO -- closed orbit structure ! i_con -- constraint number(integer) ! ! OUTPUT: CON.c(i_con).actual_value (real), value of the parameter ! of the i_con constraint ! CON.c(i_con).location (integer), LAT element number where ! minimum or maximum or target value of constrained ! parameter appears ! ! Mod/Commons: ! ! Calls : ! ! Author : ! ! Modified : ! !........................................................................ ! ! ! $Log$ ! Revision 1.9 2007/01/30 16:15:13 dcs ! merged with branch_bmad_1. ! ! Revision 1.5 2006/05/03 18:59:57 mjf7 ! Added elec_co_angle constraint for electrons closed orbit angle ! ! Revision 1.4 2003/08/12 01:45:50 mjf7 ! Fixed some parameter inconsistencies and added four more subroutines to modules. - mjf ! ! Revision 1.3 2003/06/05 18:33:28 cesrulib ! synch with bmad union removal ! ! Revision 1.2 2003/04/30 17:14:52 cesrulib ! dlr's changes since last import ! ! Revision 1.1.1.1 2002/12/13 19:23:29 cesrulib ! import bmadz ! ! !........................................................................ ! subroutine max_or_min_disp(con, co, i_con, value, location) use bmad use constraints_mod implicit none type (coord_struct), allocatable :: co(:) type (constraint_struct) con integer i_con, location real(rp) value integer i, i1, i2, j real(rp) xpos, ypos, param real(rp) xvel, yvel ! i1 = con%c(i_con)%where1_ix i2 = con%c(i_con)%where2_ix if (i1 > i2) then print *, 'ERROR IN MAX_OR_MIN: LOCATION1 AFTER LOCATION2!' print *, 'Variable:', var_name(con%c(i_con)%variable) print *, 'Location/index 1: ', con%c(i_con)%where1, i1 print *, 'Location/index 2: ', con%c(i_con)%where2, i2 call err_exit endif ! location = -1 ! dummy do i = i1, i2 if (i == i1 .or. i2 > i1) then if ( (con%c(i_con)%variable == displacement_$) .or. & (con%c(i_con)%variable == elec_displace$) ) then xpos = co(i)%vec(1) ypos = co(i)%vec(3) if(con%c(i_con)%plane == x_plane$)then param = xpos elseif(con%c(i_con)%plane == y_plane$) then param = ypos else param = sqrt(xpos**2 + ypos**2) endif elseif ( (con%c(i_con)%variable == co_angle$) .or. & (con%c(i_con)%variable == elec_co_angle$) ) then xvel = co(i)%vec(2) yvel = co(i)%vec(4) if(con%c(i_con)%plane == x_plane$)then param = xvel elseif(con%c(i_con)%plane == y_plane$) then param = yvel else param = sqrt(xvel**2 + yvel**2) endif else print *, & ' Variable type is not displacement_$ or co_angle$ in MAX_OR_MIN_DISP' call err_exit endif if (con%c(i_con)%constraint == minz$) then if (param < value .or. location < 0) then value = param location = i endif elseif (con%c(i_con)%constraint == maxz$) then if (param > value .or. location < 0) then value = param location = i endif else print *, 'ERROR IN MAX_OR_MIN: CONSTRAINT TYPE IS NOT MAX OR MIN!' print *, 'Variable:', var_name(con%c(i_con)%variable) print *, 'Constraint:', con%c(i_con)%constraint call err_exit endif endif end do return end