Guest User

Untitled

a guest
Dec 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. ;Split the huge CCCP sourcelist into
  2. ;just IR matched sources and further
  3. ;into their classifications
  4.  
  5. pro split_cccp_xspec_sourcelist,ir_sav,all_srclist,srclist_out,subset_type
  6.  
  7. ;SUBSET_TYPE = 1 for all IR matches, 2 for IMPS, 3 for TTauri
  8. ;4 for AB, 5 for OB and 6 for unc.
  9.  
  10. ;test call--> split_cccp_xspec_sourcelist,'xsed_collation_cccp.sav','all.srclist','test',2
  11.  
  12. if n_params() lt 3 then begin
  13. print, 'Syntax --> split_cccp_sourcelist,ir_sav,all_srclist,srclist_out,subset_type = 1,2,3,4 or 5'
  14. return
  15. endif
  16.  
  17. if not keyword_set(subset_type) then begin
  18. print, 'Define subset_type, 1 = all_ir, 2, = IMPS, 3 = OB, 4 =TTauri, 5 = AB'
  19. return
  20. endif
  21.  
  22. ;Restoring variable with ir sources
  23. restore,ir_sav,/verbose
  24.  
  25. ;Reading in all sources from sourcelist
  26. openr,lun,all_srclist,/get_lun
  27. all_sources = ''
  28. rows = ''
  29. while not EOF(lun) do begin
  30. readf,lun,rows
  31. all_sources = [all_sources,rows]
  32. endwhile
  33. free_lun, lun
  34.  
  35. ;To hold convention of 0 being first element
  36. all_sources = all_sources[1:*]
  37. print, 'There are '+strmid(string(n_elements(all_sources)),2)+' sources'
  38.  
  39.  
  40. ;We now want to iterate through xname for matches to all_sources, since the
  41. ;arrays are not the same length we must hold xname constant and compare to all_sources
  42. count = 0
  43. for i = 0,n_elements(xname)-1 do begin
  44.  
  45. ;All IR only sourcelist
  46. case subset_type of
  47. 1: begin
  48. ind_match = where(strmid(all_sources,0,18) eq strtrim(xname[i],2) and impsclass[i] ne '-',n_match)
  49. if n_match ne 0 then begin
  50. if count eq 0 then begin
  51. ind_all = ind_match
  52. endif else begin
  53. ind_all = [ind_all, ind_match ]
  54. endelse
  55. count++
  56. endif
  57. end
  58.  
  59. ;IMPS only sourcelist
  60. 2: begin
  61. ind_match = where(strmid(all_sources,0,18) eq strtrim(xname[i],2) and impsclass[i] eq 'IMPS',n_match)
  62. if n_match ne 0 then begin
  63. if count eq 0 then begin
  64. ind_all = ind_match
  65. endif else begin
  66. ind_all = [ind_all, ind_match ]
  67. endelse
  68. count++
  69. endif
  70. end
  71.  
  72. ;TTauri only sourcelist
  73. 3: begin
  74. ind_match = where(strmid(all_sources,0,18) eq strtrim(xname[i],2) and impsclass[i] eq 'TTauri',n_match)
  75. if n_match ne 0 then begin
  76. if count eq 0 then begin
  77. ind_all = ind_match
  78. endif else begin
  79. ind_all = [ind_all, ind_match ]
  80. endelse
  81. count++
  82. endif
  83. end
  84.  
  85. ;AB only sourcelist
  86. 4: begin
  87. ind_match = where(strmid(all_sources,0,18) eq strtrim(xname[i],2) and impsclass[i] eq 'AB',n_match)
  88. if n_match ne 0 then begin
  89. if count eq 0 then begin
  90. ind_all = ind_match
  91. endif else begin
  92. ind_all = [ind_all, ind_match ]
  93. endelse
  94. count++
  95. endif
  96. end
  97.  
  98. ;OB only sourcelist
  99. 5: begin
  100. ind_match = where(strmid(all_sources,0,18) eq strtrim(xname[i],2) and impsclass[i] eq 'OB',n_match)
  101. if n_match ne 0 then begin
  102. if count eq 0 then begin
  103. ind_all = ind_match
  104. endif else begin
  105. ind_all = [ind_all, ind_match ]
  106. endelse
  107. count++
  108. endif
  109. end
  110.  
  111. ;unc. only sourcelist
  112. 6: begin
  113. ind_match = where(strmid(all_sources,0,18) eq strtrim(xname[i],2) and impsclass[i] eq 'unc.',n_match)
  114. if n_match ne 0 then begin
  115. if count eq 0 then begin
  116. ind_all = ind_match
  117. endif else begin
  118. ind_all = [ind_all, ind_match ]
  119. endelse
  120. count++
  121. endif
  122. end
  123.  
  124. endcase
  125. endfor
  126.  
  127. sorted_ir_sources = all_sources[ind_all]
  128. n_sorted_ir_sources = n_elements(sorted_ir_sources)
  129.  
  130. ;Defining ending of output textfile nomenclature
  131. out_suffix = ['', '_all_IR', '_IMPS', '_TTauri', '_AB', '_OB', '_unc'] + '.srclist'
  132. out_suffix = out_suffix[subset_type]
  133. print, 'There are '+strtrim(string(n_sorted_ir_sources),2)+' '+out_suffix+' sources'
  134. print, 'Output name is '+srclist_out+out_suffix
  135.  
  136. ;Printing sources to a new text file
  137. openw,1,srclist_out+out_suffix
  138. for i=0L,n_sorted_ir_sources-1 do printf,1,sorted_ir_sources[i]
  139.  
  140. close,/all
  141.  
  142.  
  143. end
Add Comment
Please, Sign In to add comment