/[MITgcm]/MITgcm_contrib/jmc_script/extract_MON
ViewVC logotype

Annotation of /MITgcm_contrib/jmc_script/extract_MON

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (hide annotations) (download)
Fri Jan 8 16:43:58 2021 UTC (4 years, 6 months ago) by jmc
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +3 -2 lines
change file permission

1 jmc 1.1 #! /usr/bin/env bash
2    
3 jmc 1.2 # $Header: /u/gcmpack/MITgcm_contrib/jmc_script/extract_MON,v 1.1 2020/11/09 17:36:04 jmc Exp $
4     # $Name: $
5 jmc 1.1
6     tmpfil=TTT.$$
7     if [ $# -le 1 ]
8     then
9     echo 'Usage: '`basename $0`' file_input file_output [n]'
10     echo ' ==> extract lines with "MON" out off file_input to file_output'
11     echo ' start at the 1rst [or n^th] "%MON time_tsnumber"'
12     echo ' or (n<0) after the (-n)^th line that match the last record'
13     exit
14     else
15     if test $# = 2 ; then n1=1 ; else n1=$3 ; fi
16     file=$1 ; output=$2 ;
17     echo ' ==> extract lines with "MON" out off file='$file ' to '$output
18     fi
19 jmc 1.2
20 jmc 1.1 #----------------------------------------------------------
21     touch $output $tmpfil
22     sed -n '/%MON/p' $1 | sed 's/(PID\.TID 000.\.000.) //g' >> $tmpfil
23     #egrep '%MON|cg2d_init_res' $1 | sed 's/(PID\.TID 000.\.000.) //g' >> $tmpfil
24    
25     if test $n1 = 0
26     then
27     echo ' take all lines'
28     cat $tmpfil >> $output
29     rm -f $tmpfil
30     exit
31     fi
32    
33     if [ $n1 -lt 0 ]
34     then
35     #- used to add the 1rst "Shap global diagnostic" (if test $n1 = -1):
36     # select lines starting just after the -$n1 ^th line that match the last record
37     n0=`expr 0 - $n1`
38     line=`tail -1 $tmpfil | sed 's/= .....................//g'`
39     num0=`sed -n "/$line/=" $tmpfil | sed -n "$n0 p"`
40     num1=`expr $num0 + 1`
41     else
42     # select lines starting at the $n1 ^th "time_tsnumber" record
43     num1=`sed -n '/%MON time_tsnumber/=' $tmpfil | sed -n "$n1 p"`
44     fi
45     echo ' start at line' $num1 ' :'
46     sed -n "$num1 p" $tmpfil
47    
48     sed -n "$num1,$ p" $tmpfil >> $output
49     rm -f $tmpfil
50     exit

  ViewVC Help
Powered by ViewVC 1.1.22