
        subroutine  read_jma_stn_fix
	include 'common_stncod.inc'
	include 'common_format.inc'
        open(7,file=stndata_file)
        do nst=1,10000
           read(7,101,end=1) stnobs(nst),n,phiobs(nst),ramobs(nst),
     1 altobs(nst)
           nstobs=nst
           enddo
 101  format(a7,i4,f8.4,f9.4,f7.3,f6.2)
 1    continue
      return
      end



       subroutine  read_jma_stn
	include 'common_stncod.inc'
	include 'common_format.inc'
        character*80 text,text2
        character*15 text15(5)
        open(7,file=stndata_file)
        write(*,*) 'station data file=',stndata_file
        do 50 nst=1,10000
           read(7,'(a80)',end=1) text
           if(text(1:1).eq.''.or.text(1:1).eq.'#') go to 50
        do 15 j=8,80
              if(text(j:j).eq.'-') then
                 if(text(j-1:j-1).ne.' ') then
                  text=text(1:j-1)//' '//text(j:80)
                  go to 16
                  endif
                  endif
 15               continue
 16               continue



cc           write(*,*) text
           j=0
           nc=0
           j1=1
           do 5 jj=1,80
              j=j+1
              if(j.ge.80) go to 3
              if(text(j:j).ne.' ') go to 5
               nc=nc+1  
               text15(nc)=text(j1:j-1)
               if(nc.ge.5) go to 3
               do jq=1,10
                  j=j+1
                  if(j.ge.80) go to 3
                  if(text(j:j).ne.' ') then
                     j1=j
                     j=j-1
                     go to 5
                     endif
                     enddo
              go to 3     
 5                   continue
 3           continue
c             write(*,*) nc
cc         write(*,'(5a15)') (text15(n),n=1,nc)  
         stnobs(nst)=text15(1)(1:7)
         n=0
         if(nc.eq.3) then
           altobs(nst)=0.0
          read(text15(2),*) phiobs(nst)
          read(text15(3),*) ramobs(nst)
           go to 10
           endif
           n3=1
           do j=1,15
           if(text15(2)(j:j).eq.'.') n3=0
           enddo
           if(n3.eq.1) read(text15(2),*) n
              read(text15(n3+2),*) phiobs(nst)
              read(text15(n3+3),*) ramobs(nst)
              read(text15(n3+4),*) altobs(nst)
c           read(7,101,end=1) stnobs(nst),n,phiobs(nst),ramobs(nst),
c     1 altobs(nst)
 10        continue
           nstobs=nst
        write(*,101) stnobs(nst),nst,phiobs(nst),ramobs(nst),
     1 altobs(nst)
         iw=0
         if(phiobs(nst).gt.90.0.or.phiobs(nst).lt.-90.0) iw=1
         if(ramobs(nst).gt.180.0.or.ramobs(nst).lt.-180.0) iw=2
         if(altobs(nst).lt.-9.0.or.altobs(nst).gt.9.0) iw=3
         if(iw.ne.0) then
            write(*,*) text
            write(*,*) 'Station data incorrect  !!!!'
            write(*,*) 'Station file correct ?=',stndata_file
            if(iw.eq.3) write(*,*) 'Altitude should be put in km'
           if(iw.eq.1) write(*,*) 'latitude incorrect'
         if(iw.eq.2) write(*,*) 'longitude  incorrect'
       write(*,*) 'Station file name must be etc/wave_dir.dat line 3'
       read(*,*) iok
       endif
 50   continue
 101  format(a7,i4,f9.4,f10.4,f7.3,f6.2)
 1    continue

cc            read(*,*) iok

      return
      end


      subroutine read_vel_model
       character*80 text

	include 'common_format.inc' 
	include 'common_stncod.inc'
	include 'common_channel.inc'
      common /c_trav_plate/idelg(81),idepg(61),trav_land_p(61,61,81),
     1 trav_land_s(61,61,81),trav_sea_p(61,61,81),trav_sea_s(61,61,81),
     2 ndep_tbl,ndel_tbl
       common  /c_vel_hh/alnso(50,2),hdepa(50),nso
ccc   read station code,station number,lat., long., and altitude
	radius=6371.05
        vel_model_file='../etc/vel_model.dat'
	write(*,*) 'vel model=',vel_model_file
        open(7,file=vel_model_file)	
 1      read(7,'(a80)') text
	if(text(1:1).eq.'#') go to 1
	read(text,'(20(1x,a2))') (comptype(j),j=1,20)
	write(*,'(2x,20a3)')  (comptype(j),j=1,20)
	ntype_velmodel=0
        nwin_01_sec=1   !0.1 samp data
        nwin_32_format=0
 3         read(7,'(a80)') text
           if(text(1:1).eq.'#') go to 3
           write(*,*) text
           read(text,*) ntype_velmodel   
	write(*,*) '1:Tohoku,2:JMA,3:layer(Sea), 4:2.5 Ray trace,',
     1 '5:land,sea',ntype_velmodel
        ntype_velmodel_org=ntype_velmodel
 4      read(7,'(a80)') text
        if(text(1:1).eq.'#') go to 4
      read(text,*) ((al(k,kps),be(k,kps),k=1,2),kps=1,2),hm
      write(*,120) ((al(k,kps),be(k,kps),k=1,2),kps=1,2),hm
  120 format(2x,'p-vel=',4f7.2,2x,'s-vel=',4f7.2,f6.1)

      write(*,*) 'vel model=',ntype_velmodel
	rmoho=radius-hm
        if(ntype_velmodel.le.2) go to 10
 5      read(7,'(a80)') text
        if(text(1:1).eq.'#') go to 5
	   read(text,*) nso
	   write(*,131) nso
 131	   format('Layered vel model Num of Layer=',i3)
	   do k=1,nso
	      read(7,*) hdepa(k),alnso(k,1),alnso(k,2)
	      write(*,130) k, hdepa(k),alnso(k,1),alnso(k,2)
 130	      format(i3,f7.2,2f8.4)
	      enddo
c              endif
 10           continue
	close(7)

           return
        end
   
        subroutine read_auto_device(auto_device_file)
	include 'common_format.inc'
        include 'common_arriv.inc'
	character*80 auto_device_file
	write(*,*) 'auto_device file=',auto_device_file

	open(11,file=auto_device_file)
  100   format(a50)
	read(11,100) stn_cor_file	            	! 1  JMA mag cor data
	read(11,100) vel_model_file               ! 6 vel model
      read(11,100) pick_dir                     ! 7 input pick directory
      read(11,100) event_list                   ! 8 input hypo_month file
      read(11,100) p_s_stncor_file              ! 9 p_s_stncor_file 
	write(*,100) stn_cor_file		            ! 1  JMA mag cor data
	write(*,100) win_ch_file                	! 2  Win channel Table.
	write(*,100) wave_directory_file          ! 3  continuous waveform dir
	write(*,100) trg_dir                      ! 4  trigger wave directory
	write(*,100) display_data_file            ! 5  display.dat
	write(*,100) vel_model_file               ! 6 vel model
        write(*,100) pick_dir                ! 7 input pick directory
        write(*,100) event_list              ! 8 input hypo_month file
        write(*,100) p_s_stncor_file         ! 9 p_s_stncor_file 

  110   format(5x,a50)
	close(11)
	return
	end

      subroutine hypo_remove_threshhold_val
      include 'common_arriv.inc'
      character*80 file
      file='../etc/hypo_remove.dat'
      open(7,file=file)
      read(7,*,err=11) err_min         !1 err_min      Minimum sd_cross
      read(7,*,err=11) rat_stn_sd2     !2 remove error picks sd2=2.0*sd
      read(7,*,err=11) sd_remove       !3 remove hypo when large sd (sec)
      read(7,*,err=11) dl_remove       !4 remove hypo when large location error (km)
      read(7,*,err=11) rat_err_eq      !5 remove hypo if rate of large sd eq high
      read(7,*,err=11) del_lim_sd      !6 Limit of average epicentral distance as far
      read(7,*,err=11) fmag_rm_s       !7 magnitude to remove S arrival
      close(7)      
      return
 11   continue 
      write(*,*) '../etc/hypo_remove.dat error !!!!'
      write(*,*) 'check read_stn.f sub hypo_remove_threshhold_val'
      read(*,*) iok
      return
      end
