Commit 2216556d authored by Uehara Minoru's avatar Uehara Minoru 💬
Browse files

Upload New File

parent 4c8fdcb7
"""
Created on Juin 2021
@author: Philippe Dussouillez <dussouillez@cerege.fr >
@author: Minoru UEHARA <uehara@cerege.fr>
20210623 Initial release
"""
#!/usr/bin/python
# conversion des fichiers txt en saf dans un répertoire
#
import re
import glob
import sys
if len(sys.argv) < 2:
rep='./'
else:
rep = sys.argv[1]
print(rep)
files = glob.glob(rep+"*.txt")
print(files)
for f in files:
if f.find('.txt') > 0 :
#
# Lecture du fichier txt
#
fich=f
print('input: '+f)
fin = open(fich, 'r')# ouverture fichier entree
# lecture entete fichier
lines = fin.readlines()
l0=lines[0].rstrip('\n')
station=l0[16:18] # code station
l1=lines[1].rstrip('\n')
srt=l1[16:]
f=float(srt)
sr=re.match(r"\Sw+ \w+",l0)
l2=lines[2].rstrip('\n')
date=l2[16:] # date
jj=l2[16:18]
mm=l2[19:21]
aa=l2[22:]
l3=lines[3].rstrip('\n')
time=l3[16:] # heure
hh=l3[16:18]
mi=l3[19:21]
ss=l3[22:24]
#
# ecriture du fichier saf
#
fichout=rep + station + '_'+ aa +mm+jj+'_'+hh+mi+ss + '_V2.saf'
print('output:' + fichout)
fout = open(fichout, 'w')
fout.write("SESAME ASCII data format (saf) v. 1\n")
fout.write("SAMP_FREQ = " + srt +'\n')
fout.write(f"NDAT = {len(lines)-5} \n")
fout.write("STA_CODE = "+station + '_'+ aa +mm+jj+'_'+hh+mi+ss+'\n')
fout.write("START_TIME = " + aa+' ' + mm+' ' + jj +' '+hh+' '+mi+' '+ss+'\n')
fout.write("CH0_ID = Z (V)\n")
fout.write("CH1_ID = X (N)\n")
fout.write("CH2_ID = Y (E)\n")
fout.write("UNITS = mm/s\n")
fout.write("# Vert, NS, EW\n")
fout.write("####-------------------------------------------------------\n")
counter = 0
for line in lines[5:]:
# lecture données
#fields = ['t','x','y','z']
dstr=line.split(' ')
txyz = [float(d) for d in dstr]
fout.write("{3:e} {1:e} {2:e}\n".format(*txyz))
counter = counter +1
if counter%100 == 0:
print(".", end="")
fout.close()
print(f"done {counter} data lines")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment