Thread: Rename SAC Files

Started: 2015-06-24 12:12:42
Last activity: 2015-06-24 20:19:29
Topics: SAC Help
Massita Putriastuti
2015-06-24 12:12:42
Hello, can anyone tell me how to rename sac files? I have a problem because my sac files name have a type like this (YR.ME01..HHZ.D.2013.280.000000.SAC), but I need it to be like this (2013.280.00.00.00.000.YR.ME01.BHZ.SAC). Can we do it using SAC? Thank you for your help.
  • Geo .
    2015-06-24 20:19:29
    Hello Massita,
    Here's an example shell + SAC program that uses saclst utility to rename
    files. You may adapt this to your needs.

    Januka.

    #!/bin/sh

    # rename rdseed/mseed output .SAC files to standard name
    # yyyy.jday.hh.min.sec.stnm.channel.sac
    # Modify data_dir as needed.
    # Created On: 19 Feb 2015

    echo 'Enter wildcard [e.g. *.SAC, *__SAC]:'
    read wcard

    cur_dir=`pwd`
    data_dir='my_computer/data_directory'

    cd $data_dir

    sacfiles=`ls $wcard`

    for sacfile in $sacfiles
    do
    date=`saclst KZDATE f $sacfile | awk '{print $2}'`
    yy=`echo "$date" | awk -F"/" '{print $1}'`

    jd=`saclst NZJDAY f $sacfile | awk '{print $2}'`

    time=`saclst KZTIME f $sacfile | awk '{print $2}'`
    hh=`echo "$time" | awk -F":" '{print $1}'`
    min=`echo "$time" | awk -F":" '{print $2}'`
    sec=`echo "$time" | awk -F":" '{print $3}'`

    stnm=`saclst KSTNM f $sacfile | awk '{print $2}'`
    cmpnt=`saclst KCMPNM f $sacfile | awk '{print $2}'`

    new_name="$yy.$jd.$hh.$min.$sec.$stnm.$cmpnt.SAC"

    echo "OLD NAME: $sacfile"
    echo "NEW NAME: $new_name"

    # Files are renamed here
    echo "$sacfile" | awk -v name=$new_name '{print "mv "$1" "name" "}' | sh
    done

    cd $cur_dir

    Januka Attanayake
    Postdoctoral Research Associate
    Laboratório de Sismologia
    Complexo Interdisciplinar
    Departamento de Física
    Instituto Superior Técnico
    Av. Rovisco Pais, 1
    1049-001 Lisboa, Portugal

    Honorary Research Associate
    University College London
    London, UK

    University email: januka.attanayake<at>ist.utl.pt
    Homepage: http://sites.google.com/site/janukaattanayake/

    On 24 June 2015 at 13:12, Massita Putriastuti <massitacindy<at>gmail.com>
    wrote:

    Hello, can anyone tell me how to rename sac files? I have a problem
    because my sac files name have a type like this
    (YR.ME01..HHZ.D.2013.280.000000.SAC), but I need it to be like this
    (2013.280.00.00.00.000.YR.ME01.BHZ.SAC). Can we do it using SAC? Thank you
    for your help.

    ----------------------
    SAC Help (http://ds.iris.edu/message-center/topic/sac-help/)

    Sent via IRIS Message Center (http://ds.iris.edu/message-center/)
    Update subscription preferences at http://ds.iris.edu/account/profile/


12:24:19 v.f0c1234e