!+ ! Subroutine set_species (species, err_flag) ! ! Output: ! species -- Integer: Species taken ! err_flag -- Logical: Set True if there is an error. False otherwise. !- subroutine set_species (species, err_flag) use cesrv_struct use cesrv_interface use input_mod implicit none integer species, cur(2), ix_train character(40) line logical err_flag logical debug ! err_flag = .true. debug = .false. if (logic%beam_species == -1 .or. logic%beam_species == 1) then species = logic%beam_species elseif (logic%beam_species /= 0) then print *, 'ERROR: LOGIC%BEAM_SPECIES MUST BE SET TO -1, 0, OR 1' if (logic%command_file_open) then print *, ' CLOSING THE COMMAND FILE.' logic%command_file_open = .false. endif return else do call vxgetn('CSR CURRENTS', 1, 2, cur) if (debug) cur = [0, 1] if (cur(1) > 0 .and. cur(2) == 0) then species = -1 exit elseif (cur(1) == 0 .and. cur(2) > 0) then species = 1 exit elseif (cur(1) /= 0) then print *, 'CSR_CURRENTS SHOWS BOTH SPIECES PRESENT!' print *, 'PLEASE SET LOGIC%BEAM_SPECIES TO -1 OR +1 TO TAKE AN ORBIT.' if (logic%command_file_open) then print *, ' CLOSING THE COMMAND FILE.' logic%command_file_open = .false. endif return else print *, 'CSR_CURRENTS SHOWS NO CURRENT!' print *, 'IF THERE IS CURRENT PLEASE SET LOGIC%BEAM_SPECIES TO -1 OR +1 TO TAKE AN ORBIT.' if (logic%command_file_open) then call speech ('CESRV PROBLEM: THERE DOES NOT SEEM TO BE ANY CURRENT IN THE TRAIN LOOKED AT BY XETEC! ' // & 'PLEASE PROVIDE ASSISTANCE.') endif call read_a_line ('Do you want to CHECK again, or ABORT? (CR = CHECK)', line) call str_upcase(line, line) if (len_trim(line) == 0) cycle if (index('CHECK', trim(line)) == 1) cycle if ('DEBUG' == trim(line)) then debug = .true. cycle endif if (index('ABORT', trim(line)) == 1) then if (logic%command_file_open) then print *, 'TO BE SAFE I AM CLOSING THE COMMAND FILE...' close (logic%iu_command_file) logic%command_file_open = .false. endif return endif endif enddo endif call vxputn ('CSRBPM COMD ', 8, 8, species) call vmgetn ('CSRBPM COMD ', 9, 9, ix_train) print *, 'Orbit will be taken for: ', particle_name(species) print *, ' with train index: (from XETEC)', ix_train err_flag = .false. end subroutine set_species