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

Annotation of /MITgcm_contrib/jmc_script/comment_out_params

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


Revision 1.1 - (hide annotations) (download)
Fri Dec 10 20:09:01 2010 UTC (13 years, 3 months ago) by jmc
Branch: MAIN
CVS Tags: testing_tag01, HEAD
a script to comment out a parameter in parameter files

1 jmc 1.1 #! /usr/bin/env bash
2     #
3     # $Header: /u/gcmpack/MITgcm/tools/calc_diagnostics_dims,v 1.1 2004/02/13 06:05:49 edhill Exp $
4     # $Name: $
5    
6     # The purpose of this script is to modify parameter files
7     # by commenting out lines which set a given parameter
8    
9     usage()
10     {
11     cat <<EOF
12    
13     Usage: $0 params data_file_list
14     where:
15     params : is the name of the parameter to comment out
16     data_file_list : is the list of parameter file to process
17    
18     EOF
19     }
20    
21     COMMANDL="$0 $@"
22    
23     if [ $# -lt 2 ] ; then
24     if test "x$1" != 'x-h' -a "x$1" != 'x-help' ; then
25     echo ""
26     echo "ERROR: Need to specify 1 parameter and (at least) 1 file to modify"
27     fi
28     usage ; exit
29     fi
30     VAR_NAME="$1"
31     shift
32     DATA_FILES=$*
33    
34     prt=1 # 0 : no print ; 1 print modified file ; 2 more printing
35     tmpFile=TTT.$$
36    
37     for ff in $DATA_FILES
38     do
39     if test -f $ff ; then
40     if [ $prt -ge 2 ] ; then echo ' processing file:' $ff ; fi
41     flag=0
42     #- comment out (in $ff) all parameters from list: 'VAR_NAME'
43     for yy in $VAR_NAME
44     do
45     if [ $prt -ge 2 ] ; then echo -n ' commenting out:' $yy ; fi
46     nn=`grep -i -c "^ *$yy *=" $ff`
47     if [ $nn -ge 1 ]
48     then
49     listN=`grep -i -n "^ *$yy *=" $ff | sed 's/:.*$//'`
50     if [ $prt -ge 2 ] ; then echo " : found on line: $listN" ; fi
51     for ll in $listN
52     do
53     if test $flag = 0 ; then cp -p -f $ff $ff.bak ; fi
54     sed "$ll s/^./#&/" $ff > $tmpFile
55     #diff $tmpFile $ff
56     mv -f $tmpFile $ff
57     flag=1
58     done
59     else if [ $prt -ge 2 ] ; then echo ' : not found' ; fi
60     fi
61     done
62     if [ $prt -ge 1 -a $flag -eq 1 ] ; then
63     echo ' change file:' $ff
64     fi
65     else
66     if [ $prt -ge 1 ] ; then echo " file '$ff' not found" ; fi
67     fi
68     done

  ViewVC Help
Powered by ViewVC 1.1.22