aboutsummaryrefslogtreecommitdiff
path: root/Linlimit.f
blob: 5360b73b62f399d50c7ce93736195e3d472e9084 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

      subroutine linlimit 
c******************************************************************************
c     This routine marks the range of lines to be considered in a 
c     particular line calculations, depending on the type of calculation
c     (e.g. synthetic spectrum, single line curve-of-growth, etc.)
c******************************************************************************

      implicit real*8 (a-h,o-z)
      include 'Linex.com'
      include 'Pstuff.com'


      lineflag = 0
c*****for single-line computations, the line rage is the whole line set;
c     this will be called from "ewfind"
      if     (mode == 1) then
         lim1line = 1
         lim2line = nlines
          return


c*****for deriving abundances from single of lines of one species, delimit
c     the lines of that species as the range; called from "abfind"
      elseif (mode == 2) then
         if (lim2line == nlines) then
            if (nlines == 1) then
               lim1line = 1
               lim2line = 1
               mode = -1
            else
               lim1line = -1
            endif
            return
         endif
         if (lim1line == 0) then
            lim1line = 1 
         else
            lim1line = lim2line + 1
         endif
         if (lim1line == nlines) then
            lim2line = lim1line
            return
         else
            oldatom = atom1(lim1line)
            do j=lim1line+1,nlines
               if (atom1(j) /= oldatom) then
                  lim2line = j - 1
                  return
               endif
            enddo
         endif
         lim2line = nlines
         return


c*****for spectrum synthesis, find the range of lines to include at each
c     wavelength step; called from "synspec"; if requested synthesis
c     begins more than 10A blueward or goes on more than 105A redward of the
c     linelist limits, the synthesis aborts with a message;
      elseif (mode == 3) then
         wavelo = wave - delta
         wavehi = wave + delta
c        requested synthesis too far from linelist limits
         if     (wavehi < wave1(1)-10.0) then
            write (*,1004)
            stop
         elseif (wavelo > wave1(nlines)+10.0 .and.
     .           nlines+nstrong < 2500) then
            write (*,1005)
            stop
         endif
c        blank synthesis at start or end of requested wavelength range
         if     (wavehi < wave1(1)) then
            lim1line = 1
            lim2line = 1
            lineflag = -1
            return
         elseif (wavelo > wave1(nlines)) then
            lim1line = nlines
            lim2line = nlines
            lineflag = -1
            return
         endif
c        requested synthesis region is at least partially within the line list
c        first set the lower synthesis limit; at the beginning of a synthesis
c        of with a new chunk of lines, lim1line = 0
         if (lim1line==0 .or. wavelo < wave1(1)) lim1line = 1
         do j=lim1line,nlines
            if (wavelo < wave1(j)) then
               lim1line = j
               exit
            endif
         enddo
c        now set the upper synthesis limit
         do j=lim1line,nlines
            if (wavehi < wave1(j)) then
               lim2line = j - 1
               if (lim1line==lim2line .and.
     .             wavelo> wave1(lim1line)) then
                  lineflag = -1
               endif
               return
            endif
         enddo   
c        here the end of the line list has been reached; decide whether
c        to read in more lines
         if (nlines+nstrong == 2500) then
            lim2line = -1
         else
            lim2line = nlines
         endif
         return


c*****for blended line force fits to the EWs, the range is a set of
c     lines in a particular blend
      elseif (mode == 4) then
         if (lim1line == 0) lim1line = 1
         if (group(lim1line) /= 0.) then
            write (array,1001)
            call prinfo (10)
            write (array,1002)
            call prinfo (11)
            stop
         endif
         if (lim1line == nlines) then
            lim2line = lim1line
         else
            do j=lim1line+1,nlines
               if (group(j) /= 1) then
                  lim2line = j - 1
                  return
               endif
            enddo
            lim2line = nlines
         endif
         return
      else
         write (array,1003) mode
         call prinfo (10)
         stop
      endif


c*****format statements
1001  format ('TROUBLE! THE FIRST LINE IN THE GROUP')
1002  format ('DOES NOT DEFINE A NEW GROUP OF LINES!  I QUIT!')
1003  format ('mode = ', i3, ' BUT IT MUST BE 1-4 ONLY; I QUIT!')
1004  format ('synthesis begins more than 10A blueward of the',
     .        ' linelist start; I QUIT!')
1005  format ('synthesis ends more than 10A redward of the',
     .        ' linelist end; I QUIT!')


      end