!........................................................................ ! ! Subroutine : SPECIAL_OUTPUT (lat_0, lat_1, vari, con) ! !........................................................................ subroutine special_output (lat_0, lat_1, vari, con) use bmad !! use cesr_basic_mod use constraints_mod implicit none type (indep_var_struct) vari type (lat_struct), target :: lat_0, lat_1 type (ele_struct), pointer :: slave type (constraint_struct) con integer iu, i, ix, ixx integer j,k integer l integer index_betasing, index_scmating, index_anything, index_xquneing integer index_dx_dvcros, index_dx_dpretz, index_pcbeting integer idum integer len integer ix_attrib real(rp) coef character fmt*60, string*3000 character*100 string1(200) character*12 group_name character*18 type_name_loc character*80 sout logical :: first_time_through = .true. ! call string_trim(con%special_output, sout, ixx) if (index (sout, 'VCROSING7') /= 0 .or. index(sout, 'VNOSEING') /= 0) then iu = lunget() ! open (iu, file = 'vcrosing7.dat', & open (iu, file = sout(1:ixx)//'.dat') ! write (string, '(a, f9.6)') 'RAW_VCROSING_7: GROUP = {' write (string, '(a4,a8,a1,a1,a11)') 'RAW_',sout(1:ixx-1),'_',sout(ixx:ixx),': GROUP = {' do i = 1, vari%n_var ix = vari%v(i)%rindex if (lat_1%ele(ix)%n_slave /= 0) then do k = 1, lat_1%ele(ix)%n_slave slave => pointer_to_slave(lat_1%ele(ix), k) do l=1, lat_0%n_ele_max if(lat_0%ele(l)%name == slave%name )then coef = slave%value(k1$) - lat_0%ele(l)%value(k1$) exit endif end do write (string, '(3a, f9.6, a)') trim(string), trim(slave%name), ':', coef, ',' enddo else do l=1,lat_0%n_ele_max if(lat_0%ele(l)%name == lat_1%ele(ix)%name )then coef = lat_1%ele(ix)%value(k1$) - lat_0%ele(l)%value(k1$) exit endif end do write (string, '(3a, f9.6, a)') trim(string), trim(lat_1%ele(ix)%name), ':', coef, ',' endif enddo string = trim(string) // '}, K1, Type = "CSR '//sout(1:ixx-1)//' '//sout(ixx:ixx)//'"' ixx = index(string,'}') string(ixx-1:ixx-1)=' ' ! write to file write (iu, *) 'Call, file = ', trim(lat_0%input_file_name) do ix = index(string(1:75), ',', .true.) if (ix == 0) then write (iu, '(a)') trim(string) exit else write (iu, '(2a)') string(1:ix), ' &' string = ' ' // string(ix+1:) endif enddo write (iu, *) write (iu, *) 'End_file' write (iu, *) call showme (con, lat_1, iu) close (iu) endif if (index (sout, 'VCROSING8') /= 0) then iu = lunget() open (iu, file = 'vcrosing8.dat') write (string, '(a, f9.6)') 'RAW_VCROSING_8: GROUP = {' do k=1,lat_1%n_ele_max if (lat_1%ele(k)%name(1:4) /= 'Q48W' .and. lat_1%ele(k)%name(1:4) /= 'Q48E')cycle do l=1,lat_0%n_ele_max if(lat_0%ele(l)%name == lat_1%ele(k)%name )then coef = lat_1%ele(k)%value(k1$) - lat_0%ele(l)%value(k1$) exit endif end do write (string, '(3a, f9.6, a)') trim(string), trim(lat_1%ele(k)%name), ':', coef, ',' end do do i = 1, vari%n_var ix = vari%v(i)%rindex if (lat_1%ele(ix)%n_slave /= 0) then do k = 1, lat_1%ele(ix)%n_slave slave => pointer_to_slave(lat_1%ele(ix), k) do l=1, lat_0%n_ele_max if(lat_0%ele(l)%name == slave%name )then coef = slave%value(k1$) - lat_0%ele(l)%value(k1$) exit endif end do write (string, '(3a, f9.6, a)') trim(string), trim(slave%name), ':', coef, ',' enddo else do l=1,lat_0%n_ele_max if(lat_0%ele(l)%name == lat_1%ele(ix)%name )then coef = lat_1%ele(ix)%value(k1$) - lat_0%ele(l)%value(k1$) exit endif end do write (string, '(3a, f9.6, a)') trim(string), trim(lat_1%ele(ix)%name), ':', coef, ',' endif enddo string = trim(string) // '}, K1, Type = "CSR VCROSING 8"' ! write to file write (iu, *) 'Call, file = ', trim(lat_0%input_file_name) do ix = index(string(1:75), ',', .true.) if (ix == 0) then write (iu, '(a)') trim(string) exit else write (iu, '(2a)') string(1:ix), ' &' string = ' ' // string(ix+1:) endif enddo write (iu, *) write (iu, *) 'End_file' write (iu, *) call showme (con, lat_1, iu) close (iu) endif ! call string_trim(sout,group_name,len) group_name(9:9) = '_' group_name(10:len+1)= sout(9:len) index_dx_dpretz = index (sout(1:8), 'DX_PRETZ') index_dx_dvcros = index (sout(1:8), 'DX_VCROS') index_betasing = index (sout(1:8), 'BETASING') index_scmating = index (sout(1:8), 'SCMATING') index_xquneing = index (sout(1:8), 'XQUNEING') index_pcbeting = index (sout(1:8), 'PCBETING') if (any((/index_betasing, index_scmating, & index_dx_dvcros, index_dx_dpretz, index_xquneing, index_pcbeting/) /= 0)) then iu = lunget() ix_attrib = k1$ if(index_xquneing /= 0)ix_attrib=k2$ if(first_time_through)then open (iu, file = group_name(1:len+1)//'.dat') first_time_through = .false. else open (iu, file = group_name(1:len+1)//'.dat', status = 'old') endif write (string, '(3a, f9.6)')'RAW_', group_name,': GROUP = {' idum=0 do i = 1, vari%n_var ix = vari%v(i)%rindex if (lat_1%ele(ix)%n_slave /= 0 .and. & lat_1%ele(ix)%lord_status /= super_lord$) then do k = 1, lat_1%ele(ix)%n_slave slave => pointer_to_slave(lat_1%ele(ix), k) do l=1, lat_0%n_ele_max if(lat_0%ele(l)%name == slave%name )then coef = slave%value(ix_attrib) - lat_0%ele(l)%value(ix_attrib) exit endif end do write (string, '(3a, f9.6, a)') trim(string), & trim(slave%name), ':', coef, ',' idum = idum+1 if(index_xquneing == 0)then write (string1(idum), '(2a,f9.6)')trim(slave%name), & '[k1] =', slave%value(ix_attrib) else write (string1(idum), '(2a,f9.6)')trim(slave%name), & '[k2] =', slave%value(ix_attrib) endif enddo else do l=1,lat_0%n_ele_max if(lat_0%ele(l)%name == lat_1%ele(ix)%name )then coef = lat_1%ele(ix)%value(ix_attrib) - lat_0%ele(l)%value(ix_attrib) exit endif end do write (string, '(3a, f9.6, a)') trim(string), & trim(lat_1%ele(ix)%name), ':', coef, ',' idum = idum+1 if(index_xquneing == 0)then write (string1(idum), '(2a,f9.6)')trim(lat_1%ele(ix)%name), & '[k1] =', lat_1%ele(ix)%value(ix_attrib) else write (string1(idum), '(2a,f9.6)')trim(lat_1%ele(ix)%name), & '[k2:=', lat_1%ele(ix)%value(ix_attrib) endif endif enddo ix = len_trim(string) if(index_dx_dpretz /= 0)type_name_loc = '"CSR_DX_PRETZ ' // sout(9:9) // '"' if(index_dx_dvcros /= 0)type_name_loc = '"CSR DX_VCROS ' // sout(9:9) // '"' if(index_betasing /= 0)type_name_loc = '"CSR BETASING ' // sout(9:9) // '"' if(index_scmating /= 0)type_name_loc = '"CSR SCMATING ' // sout(9:9) // '"' if(index_xquneing /= 0)type_name_loc = '"CSR XQUNEING ' // sout(9:9) // '"' if(index_pcbeting /= 0)type_name_loc = '"CSR PCBETING ' // sout(9:len) // '"' if(index_xquneing == 0)string = string(:ix-1) // '}, K1, Type = ' // type_name_loc if(index_xquneing /= 0)string = string(:ix-1) // '}, K2, Type = ' // type_name_loc ! write to file write (iu, *) 'Call, file = ', trim(lat_0%input_file_name) do ix = index(string(1:75), ',', .true.) if (ix == 0) then write (iu, '(a)') trim(string) exit else write (iu, '(2a)') string(1:ix), ' &' string = ' ' // string(ix+1:) endif enddo write(iu, *) do i=1,idum write(iu, '(a)')string1(i) end do write (iu, *) write (iu, *) 'End_file' write (iu, *) call showme (con, lat_1, iu) close (iu) endif ! if (index (sout(1:8), 'ROTQ_NOB') /= 0) then iu = lunget() open (iu, file = sout//'.dat') group_name = 'ROTQ_NOB_'//sout(9:9) write (string, '(2a, f9.6)')group_name,': GROUP = {' do i = 1, vari%n_var ix = vari%v(i)%rindex if (lat_1%ele(ix)%n_slave /= 0) then if(lat_1%ele(ix)%name(1:8) .ne. 'RAW_QTUNE' .and. & lat_1%ele(ix)%name(1:5) .ne. 'QTUNE') then do k = 1, lat_1%ele(ix)%n_slave slave => pointer_to_slave (lat_1%ele(ix), k) do l=1, lat_0%n_ele_max if(lat_0%ele(l)%name == slave%name )then coef = slave%value(tilt$) - lat_0%ele(l)%value(tilt$) exit endif enddo write (string, '(3a, f9.6, a)') trim(string), trim(slave%name), ':', coef, ',' enddo endif else do l=1,lat_0%n_ele_max if(lat_0%ele(l)%name == lat_1%ele(ix)%name )then coef = lat_1%ele(ix)%value(tilt$) - lat_0%ele(l)%value(tilt$) exit endif enddo write (string, '(3a, f9.6, a)') trim(string), trim(lat_1%ele(ix)%name), ':', coef, ',' endif enddo ix = len_trim(string) type_name_loc = '"CSR ROTQ NOB ' // sout(9:9) // '"' string = string(:ix-1) // '}, tilt, Type = ' // type_name_loc ! write to file write (iu, *) 'Call, file = ', trim(lat_0%input_file_name) do ix = index(string(1:75), ',', .true.) if (ix == 0) then write (iu, '(a)') trim(string) exit else write (iu, '(2a)') string(1:ix), ' &' string = ' ' // string(ix+1:) endif enddo write (iu, *) write (iu, *) 'End_file' write (iu, *) call showme (con, lat_1, iu) close (iu) endif ! if (index (sout(2:8), 'PHASING') /= 0) then iu = lunget() open (iu, file = sout//'.dat') group_name = sout(1:8)//'_'//sout(9:9) write (string, '(3a, f9.6)') 'RAW_', group_name,': GROUP = {' do i = 1, vari%n_var ix = vari%v(i)%rindex if (lat_1%ele(ix)%n_slave /= 0) then do k = 1, lat_1%ele(ix)%n_slave slave => pointer_to_slave(lat_1%ele(ix), k) do l=1, lat_0%n_ele_max if(lat_0%ele(l)%name == slave%name )then coef = slave%value(k1$) - lat_0%ele(l)%value(k1$) exit endif end do write (string, '(3a, f9.6, a)') trim(string), trim(slave%name), ':', coef, ',' enddo else do l=1,lat_0%n_ele_max if(lat_0%ele(l)%name == lat_1%ele(ix)%name )then coef = lat_1%ele(ix)%value(k1$) - lat_0%ele(l)%value(k1$) exit endif end do write (string, '(3a, f9.6, a)') trim(string), trim(lat_1%ele(ix)%name), ':', coef, ',' endif enddo ix = len_trim(string) type_name_loc = & '"CSR '//sout(1:8)//' '//sout(9:9) // '"' string = string(:ix-1) // '}, K1, Type = ' // type_name_loc ! write to file write (iu, *) 'Call, file = ', trim(lat_0%input_file_name) do ix = index(string(1:75), ',', .true.) if (ix == 0) then write (iu, '(a)') trim(string) exit else write (iu, '(2a)') string(1:ix), ' &' string = ' ' // string(ix+1:) endif enddo write (iu, *) write (iu, *) 'End_file' write (iu, *) call showme (con, lat_1, iu) close (iu) endif index_anything = index (sout(1:8), 'ANYTHING') if (index_anything /= 0 )then iu = lunget() open (iu, file = sout//'.dat') if(index_anything /= 0)then group_name(1:9) = 'ANYTHING_' group_name(10:10)=sout(9:9) endif write (string, '(3a, f9.6)')'RAW_', group_name,': GROUP = {' idum=0 do i = 1, vari%n_var ix = vari%v(i)%rindex if (lat_1%ele(ix)%n_slave /= 0 .and. & lat_1%ele(ix)%lord_status /= super_lord$) then do k = 1, lat_1%ele(ix)%n_slave slave => pointer_to_slave(lat_1%ele(ix), k) do l=1, lat_0%n_ele_max if(lat_0%ele(l)%name == slave%name )then coef = slave%value(k1$) - lat_0%ele(l)%value(k1$) exit endif end do write (string, '(3a, f9.6, a)') trim(string), trim(slave%name), ':', coef, ',' idum = idum+1 write (string1(idum), '(2a,f9.6)')trim(slave%name), '[k1] =', slave%value(k1$) enddo else do l=1,lat_0%n_ele_max if(lat_0%ele(l)%name == lat_1%ele(ix)%name )then coef = lat_1%ele(ix)%value(k1$) - lat_0%ele(l)%value(k1$) exit endif end do write (string, '(3a, f9.6, a)') trim(string), & trim(lat_1%ele(ix)%name), ':', coef, ',' idum = idum+1 write (string1(idum), '(2a,f9.6)')trim(lat_1%ele(ix)%name), & '[k1] =', lat_1%ele(ix)%value(k1$) endif enddo ix = len_trim(string) if(index_anything /= 0)type_name_loc = '"CSR ANYTHING ' // sout(9:9) // '"' string = string(:ix-1) // '}, K1, Type = ' // type_name_loc ! write to file write (iu, *) 'Call, file = ', trim(lat_0%input_file_name) do ix = index(string(1:75), ',', .true.) if (ix == 0) then write (iu, '(a)') trim(string) exit else write (iu, '(2a)') string(1:ix), ' &' string = ' ' // string(ix+1:) endif enddo write(iu, *) do i=1,idum write(iu, '(a)')string1(i) end do write (iu, *) write (iu, *) 'End_file' write (iu, *) call showme (con, lat_1, iu) close (iu) endif end subroutine special_output