Altering the curves in a .page with bash

All geopsy forums are in their very early stage. So a restricted number of forums has been created. If your question does not fit into one of the available categories, post here.
admin
Site Admin
Posts: 417
Joined: Mon Aug 13, 2007 11:48 am
Location: ISTerre
Contact:

Altering the curves in a .page with bash

Postby admin » Wed Jan 30, 2008 5:56 pm

We assume that a file dc.page exits and contains plots of dispersion curves , slowness versus frequency. We want to transform them into wavelength versus slowness. Additionally, we would like to smooth these curves in a "clever" way which keep the up-down traveltimes constant.

We first extract the content.xml file contained in the .page file:

Code: Select all

tar xvfpz dc.page

The content.xml file is an xml file encoded in UTF16 (unicode). With 'cat', 'awk',... unicode may not be considered properly. First we convert it to basic ascii encoding:

Code: Select all

iconv -f UTF16 -t ASCII contents.xml > contents-ascii.xml

All dispersion curves can be extracted from the xml content:

Code: Select all

cat contents-ascii.xml | awk '/[0-9\.]+ +[0-9\.]+ +[0-9\.]+/{print $0}'

The next step is to modify these parts of the xml content without touching the rest. We replace the [frequency,slowness] by [slowness, 1/(frequency*slowness)=wavelength].

Code: Select all

cat contents-ascii.xml | awk '/[0-9\.]+ +[0-9\.]+ +[0-9\.]+/{print $2 " " 1/($1*$2)}!/[0-9\.]+ +[0-9\.]+ +[0-9\.]+/{print $0}' > contents.xml

We re-direct everything to content.xml to build a new .page file. If the original dc.page contains other files (usually starting by bin_...) you must pack them as well in the new file. Skip 'bin_data_100*' if your original dc.page file contains no binary file.

Code: Select all

tar cvfpz dc-wavelength.page bin_data_100* contents.xml

The created file can opened in figue:

Code: Select all

figue dc-wavelength.page

You may be a bit disappointed because all plots are probably blank. This is just a problem of axis limits. Change the axis properties as you want, make use of mkup files to propagate them if you have various plots. Save your changes to dc-wavelength.page.

Secondly, we can calculate the smoothed slowness curves keeping the traveltimes constant. We start from the last dc-wavelength.page.
We first extract the content.xml file contained in the .page file and convert it:

Code: Select all

tar xvfpz dc-wavelength.page
iconv -f UTF16 -t ASCII contents.xml > contents-ascii.xml

We revert the sort of curves obtained so far to get increasing wavelengths:

Code: Select all

cat contents-ascii.xml | awk 'BEGIN{n=0}/[0-9\.]+ +[0-9\.]+ +[0-9\.]+/{x[n]=$0;n++}!/[0-9\.]+ +[0-9\.]+ +[0-9\.]+/{if (n>0){for(i=n-1;i>=0;i--)print x[i];n=0};print $0}' > tmp

We compute the smoothing itself:

Code: Select all

cat tmp | awk 'BEGIN{l=0;s=0}/[0-9\.]+ +[0-9\.]+ +[0-9\.]+/{nl=$2;s+=$1*(nl-l);l=nl;print s/l " " $2}!/[0-9\.]+ +[0-9\.]+ +[0-9\.]+/{s=0;l=0;print $0}' > contents.xml

The contents.xml can be converted to .page file the same way as shown above.

bre
Posts: 13
Joined: Tue Oct 30, 2007 11:24 am
Location: University Potsdam

Converting page file from frequeny/slowness to wavelength

Postby bre » Thu Feb 07, 2008 12:59 pm

Hi Marc,

I just tried to follow your instructions about converting the dispersion curves from the page file (for our brandnew NERIES data), but when I type the third line

cat contents-ascii.xml | awk '/[0-9\.]+ +[0-9\.]+ +[0-9\.]+/{print $2 " " 1/($1*$2)}!/[0-9\.]+ +[0-9\.]+ +[0-9\.]+/{print $0}' > contents.xml

my computer responds:

/[0: Event not found.

As I'm not so familiar with regular expressions (at least not with such complicated ones), I do not know what it does not like about the !/ stuff... Any idea? Should this work for all shells or just in bash? (Already tried both bash and csh, no difference in response).

Brigitte

bre
Posts: 13
Joined: Tue Oct 30, 2007 11:24 am
Location: University Potsdam

Solution found

Postby bre » Fri Feb 08, 2008 12:16 pm

Just found out what was the difficulty - in my bash, I need to add a space behind the "!" so the regular expression is interpreted correctly. :)

Brigitte


Return to “Miscellaneous”

Who is online

Users browsing this forum: No registered users and 1 guest