refract_dopicks.f 12.9 KB
Newer Older
1
2
c this is <refract_dopicks.f>
c------------------------------------------------------------------------------
thomas.forbriger's avatar
thomas.forbriger committed
3
c $Id$
4
5
6
7
8
c
c 05/07/98 by Thomas Forbriger (IfG Stuttgart)
c
c all we have to do to work with picking
c
thomas.forbriger's avatar
thomas.forbriger committed
9
c ----
10
c refract is free software; you can redistribute it and/or modify
thomas.forbriger's avatar
thomas.forbriger committed
11
12
13
14
c it under the terms of the GNU General Public License as published by
c the Free Software Foundation; either version 2 of the License, or
c (at your option) any later version. 
c 
15
c refract is distributed in the hope that it will be useful,
thomas.forbriger's avatar
thomas.forbriger committed
16
17
18
19
20
21
22
23
24
c but WITHOUT ANY WARRANTY; without even the implied warranty of
c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c GNU General Public License for more details.
c 
c You should have received a copy of the GNU General Public License
c along with this program; if not, write to the Free Software
c Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
c ----
c
25
26
27
28
c REVISIONS and CHANGES
c    05/07/98   V1.0   Thomas Forbriger
c    18/07/98   V1.1   now allow one single pick per each trace
c                      - changed traveltime units to [km] and [s]
29
c    24/05/00   V1.2   subdivided readttpicks
30
31
c    19/03/02   V1.3   plot traveltime picks also in color and with larger
c                      crosses at the breaks 
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
c
c==============================================================================
c
      subroutine addpick(xcoor, ycoor)
c 
c add another pick at (xcoor,ycoor)
c
      include 'refract_dim.inc'
      include 'refract_data.inc'
      include 'refract_picks.inc'
      include 'refract_para.inc'
      include 'refract_model.inc'
      include 'refract_seipar.inc'
c 
      real xcoor,ycoor
c
c declare variables
c
      integer pick, i
      real realtime
      real mindist, dist, newoff
c
      if (debug) print *,'DEBUG: plpar_pickmode ',plpar_pickmode
c 
      if ((plpar_pickmode.lt.1).or.(plpar_pickmode.gt.pick_ntypes))
     &   stop 'ERROR (addpick): invalid pickmode'
c check range
      if ((xcoor.gt.tov_tmax).or.(xcoor.lt.tov_tmin).or.
     &    (ycoor.gt.tov_rmax).or.(ycoor.lt.tov_rmin)) then
        call refract_warning('WARNING (addpick): out of frame')
      else
c check range
        if (pick_n(plpar_pickmode).ge.pick_max) then
          call refract_warning('WARNING (addpick): reached maximum pick count')
        else
c ok - go and remove picks from plot
          call refract_pgpicks(plpar_pickmode, .false.)
c in case of arrival time mode: make traces sticky
          if (plpar_pickmode.eq.6) then
            mindist=abs(ycoor-roffset(1))
            newoff=roffset(1)
            do i=1,ntraces
              dist=abs(ycoor-roffset(i))
              if (dist.lt.mindist) then
                mindist=dist
                newoff=roffset(i)
              endif
            enddo
            ycoor=newoff
          endif
c look for next position
          pick=1
          do while ((pick.le.pick_n(plpar_pickmode)).and.(pick.gt.0))
            if (pick_y(pick,plpar_pickmode).gt.ycoor) then
c shift all to insert the new pick
              do i=pick_n(plpar_pickmode),pick,-1
                pick_x(i+1,plpar_pickmode)=pick_x(i,plpar_pickmode)
                pick_y(i+1,plpar_pickmode)=pick_y(i,plpar_pickmode)
              enddo 
c insert pick
              pick_n(plpar_pickmode)=pick_n(plpar_pickmode)+1
              pick_x(pick,plpar_pickmode)=
     &          realtime(xcoor,ycoor)
              pick_y(pick,plpar_pickmode)=ycoor
              pick=-1
            endif
            pick=pick+1
          enddo
c handle pick to be appended
          if (pick.eq.(pick_n(plpar_pickmode)+1)) then
            pick_n(plpar_pickmode)=pick_n(plpar_pickmode)+1
            pick_x(pick_n(plpar_pickmode),plpar_pickmode)=
     &        realtime(xcoor,ycoor)
            pick_y(pick_n(plpar_pickmode),plpar_pickmode)=ycoor
          endif
c that's it - display picks again
          call refract_pgpicks(plpar_pickmode, .true.)
c
          if (plpar_pickmode.eq.1) then
            if ((elem_modbox).and.(mod_valid)) then
              flag_replot=.true.
            endif
            mod_valid=.false.
          endif
        endif
      endif
c 
      return
      end
c
c----------------------------------------------------------------------
c
      subroutine delpick(xcoor,ycoor)
c
c delete pick nearest to cursor
c
      real xcoor,ycoor
c 
      include 'refract_dim.inc'
      include 'refract_picks.inc'
      include 'refract_para.inc'
      include 'refract_model.inc'
      include 'refract_seipar.inc'
c
c declare variables
c
      real thisdist, lastdist
      integer pick, i
      real redtime
c
c 
      if ((plpar_pickmode.lt.1).or.(plpar_pickmode.gt.pick_ntypes))
     &   stop 'ERROR (delpick): invalid pickmode'
c check range
      if ((xcoor.gt.tov_tmax).or.(xcoor.lt.tov_tmin).or.
     &    (ycoor.gt.tov_rmax).or.(ycoor.lt.tov_rmin)) then
        call refract_warning('WARNING (delpick): out of frame')
      else
c check range
        if (pick_n(plpar_pickmode).lt.1) then
          call refract_warning('WARNING (delpick): no pick to delete')
        else
c ok - go and remove picks from plot
          call refract_pgpicks(plpar_pickmode, .false.)
c search nearest pick
          lastdist=((ycoor-pick_y(1,plpar_pickmode))/(tov_rmax-tov_rmin))**2
          lastdist=lastdist+((xcoor-redtime(pick_x(1,plpar_pickmode),
     &      pick_y(1,plpar_pickmode)))/
     &      (tov_tmax-tov_tmin))**2
          pick=1
          do i=1,pick_n(plpar_pickmode)
            thisdist=((ycoor-pick_y(i,plpar_pickmode))/(tov_rmax-tov_rmin))**2
            thisdist=thisdist+((xcoor-redtime(pick_x(i,plpar_pickmode),
     &        pick_y(i,plpar_pickmode)))/
     &        (tov_tmax-tov_tmin))**2
            if (thisdist.lt.lastdist) then
              pick=i
              lastdist=thisdist
            endif
          enddo
c delete pick
          if (pick.lt.pick_n(plpar_pickmode)) then
            do i=pick,pick_n(plpar_pickmode)-1
              pick_x(i,plpar_pickmode)=pick_x(i+1,plpar_pickmode)
              pick_y(i,plpar_pickmode)=pick_y(i+1,plpar_pickmode)
            enddo
          endif
          pick_n(plpar_pickmode)=pick_n(plpar_pickmode)-1
c that's it - display picks again
          call refract_pgpicks(plpar_pickmode, .true.)
c 
          if (plpar_pickmode.eq.1) then
            if ((elem_modbox).and.(mod_valid)) then
              flag_replot=.true.
            endif
            mod_valid=.false.
          endif
        endif
      endif
      return
      end
c
c----------------------------------------------------------------------
c 
      subroutine refract_eraseallpicks
c 
c erase all picks
c
      include 'refract_picks.inc'
c
      integer i
c
      do i=1,pick_ntypes
        call refract_pgpicks(i, .false.)
      enddo
c
      return
      end
c
c----------------------------------------------------------------------
c 
      subroutine refract_plotallpicks
c 
c plot all picks
c
      include 'refract_picks.inc'
c
      integer i
c
      do i=1,pick_ntypes
        call refract_pgpicks(i, .true.)
      enddo
c
      return
      end
c
c----------------------------------------------------------------------
c
      subroutine refract_pgpicks(i, f)
c 
c plot picks of set i if flag is .true.
c erase otherwise
234
235
236
c
c 19/03/2002      plot traveltime picks also in color and with larger crosses
c                 at the breaks 
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
c
      include 'refract_picks.inc'
      include 'refract_para.inc'
c 
      integer i
      logical f
c 
      integer j
      real redtime
c 
      if ((i.lt.1).or.(i.gt.pick_ntypes))
     &  stop 'ERROR (pgpicks): check picktype'
c 
c select style
      if (pick_n(i).gt.0) then
        call pgsave
253
        if (plflag_picol) call refract_selstyle(i+1)
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
        if (.not.(f)) then
          call pgsci(0)
        endif
c 
c other mode for single picks
        if (i.eq.6) then
          call pgsch(2.)
          do j=1,pick_n(i)
            call pgpt1(redtime(pick_x(j,i),pick_y(j,i)),pick_y(j,i),2)
          enddo
        else
          call pgmove(redtime(pick_x(1,i),pick_y(1,i)),pick_y(1,i))
          if (pick_n(i).gt.1) then
            do j=2,pick_n(i)
              call pgdraw(redtime(pick_x(j,i),pick_y(j,i)),pick_y(j,i))
            enddo
          endif
          if (i.eq.plpar_pickmode) then
272
273
274
            call pgsave
            call pgsch(2.)
            call pgslw(5)
275
276
277
            do j=1,pick_n(i)
              call pgpt1(redtime(pick_x(j,i),pick_y(j,i)),pick_y(j,i),5)
            enddo
278
            call pgunsa
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
          endif
          if (i.eq.1) then
            call pgmove(0., 0.)
            call pgdraw(redtime(pick_x(1,1),pick_y(1,1)),pick_y(1,1))
          endif
        endif
c 
        call pgunsa
      endif
c 
      return
      end
c 
c----------------------------------------------------------------------
c
      subroutine refract_readtappicks
c 
c read taper picks from file
c
      include 'refract_picks.inc'
      include 'refract_dim.inc'
      include 'refract_pgpara.inc'
      include 'refract_para.inc'
c 
      character*80 filename, junk
c
      write(6, 50)
      read(5, 51) filename
      print *,'reading from ',filename(1:index(filename,' '))
c 
      call tf_ttapread(filename,pick_x(1,2), pick_y(1,2), pick_n(2),
     &  pick_max, junk)
c 
      flag_replot=.true.
c 
      return
   50 format('input filename for tapers:')
   51 format(a)
      end
c 
c----------------------------------------------------------------------
c
      subroutine refract_writetappicks
c 
c write taper picks to file 
c
      include 'refract_picks.inc'
      include 'refract_dim.inc'
      include 'refract_pgpara.inc'
c 
      character*80 filename
      integer lu
      parameter(lu=10)
c
      write(6, 50)
      read(5, 51) filename
      print *,'writing to ',filename(1:index(filename,' '))
c 
      open(lu, file=filename)
      close(lu, status='delete')
c 
      call tf_ttapwrite(filename,pick_x(1,2), pick_y(1,2), pick_n(2),
     &  pick_max, pg_title)
c 
      return
   50 format('output filename for tapers:')
   51 format(a)
      end
c 
c----------------------------------------------------------------------
c
350
      subroutine refract_doreadttpicks(filename, iset)
351
352
c 
c read traveltime picks from file to pickset iset
353
c perform actual reading
354
355
356
357
358
c
      include 'refract_picks.inc'
      include 'refract_para.inc'
c 
      integer iset
359
360
      character*(*) filename
c
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
      integer lu, i
      parameter(lu=10)
c 
      if ((iset.lt.1).or.(iset.gt.pick_ntypes))
     &   stop 'ERROR (readttpicks): wrong pickset number'
c
      open(lu, file=filename, status='old', err=99)
      read(lu, '(/,i10)', err=98, end=97) pick_n(iset)
c 
      if (pick_n(iset).le.pick_max) then
        do i=1,pick_n(iset)
          read(lu, *, err=98, end=97) pick_y(i,iset), pick_x(i,iset)
          pick_y(i, iset)=pick_y(i,iset)*1000.
        enddo
c 
        flag_replot=.true.
        print *,'  ',pick_n(iset),' picks read to set ',iset
      else
        call refract_warning('WARNING (readttpicks): too many samples')
      endif
c 
      close(lu, err=96)
c 
      return
   99 stop 'ERROR (readttpicks): opening travel time file'
   98 stop 'ERROR (readttpicks): reading travel time file'
   97 stop 'ERROR (readttpicks): reading travel time file - unexpected end'
   96 stop 'ERROR (readttpicks): closing travel time file'
      end
c 
c----------------------------------------------------------------------
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
c
      subroutine refract_readttpicks(iset)
c 
c read traveltime picks from file to pickset iset
c ask for filename and call reading subroutine
c
      include 'refract_picks.inc'
      include 'refract_para.inc'
c 
      integer iset
c 
      character*80 filename
c 
      if ((iset.lt.1).or.(iset.gt.pick_ntypes))
     &   stop 'ERROR (readttpicks): wrong pickset number'
c
      write(6, 50)
      read(5, 51) filename
      print *,'reading from ',filename(1:index(filename,' '))
      call refract_doreadttpicks(filename, iset)
c 
      return
   50 format('input filename for traveltimes:')
   51 format(a)
      end
c 
c----------------------------------------------------------------------
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
c
      subroutine refract_writettpicks(iset)
c 
c write traveltime picks to file from pickset iset
c
      include 'refract_picks.inc'
      include 'refract_dim.inc'
      include 'refract_pgpara.inc'
c 
      integer iset
c 
      character*80 filename
      integer lu, i
      parameter(lu=10)
c 
      if ((iset.lt.1).or.(iset.gt.pick_ntypes))
     &   stop 'ERROR (readttpicks): wrong pickset number'
c
      write(6, 50)
      read(5, 51) filename
      print *,'writing to ',filename(1:index(filename,' '))
c 
      open(lu, file=filename, err=98)
      write(lu, '(a)', err=97) pg_title
      write(lu, '(i5)', err=97) pick_n(iset)
      write(lu, '(2f12.7)', err=97) (pick_y(i,iset)/1000., pick_x(i,iset),
     &   i=1,pick_n(iset))
      close(lu, err=96)
c 
      return
   50 format('output filename for traveltimes:')
   51 format(a)
   98 stop 'ERROR (writettpicks): opening travel time file'
   97 stop 'ERROR (writettpicks): writing travel time file'
   96 stop 'ERROR (writettpicks): closing travel time file'
      end
c 
c ----- END OF refract_dopicks.f -----