summaryrefslogtreecommitdiffstats
path: root/funtools/funtest/timev
blob: d5e71e33d7ad0b0cb8da850118a3a5b8c69268ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/sh
# set -x

PLATFORM=`uname`
VERBOSE=0
SW="-r"
X=504
Y=512

STDIN=/dev/null
OPROG=funcnts
NPROG=../funcnts
OFILE=${HOME}/data/snr.fits
NFILE=${HOME}/data/snr.ev.gz


EAWK='start==1&&NF>0{tpix += $2; tarea +=$3; print $0};/^---- ------------ ---------$/{start=1}END{print tpix,tarea}'

SAWK='start==1&&NF>0{tpix += $2; tarea +=$3};/^---- ------------ ---------$/{start=1}END{print tpix,tarea}'

FAWK='{tpix = $1};END{print tpix}'

while [ x"$1" != x ]; do
  case $1 in
  -1)
    DO1=YES
    shift
    continue;;
  -b)
    shift
    B=$1
    shift
    continue;;
  -c)
    shift
    C="$1\;"
    shift
    continue;;
  -e)
    FIELD=`${OPROG} ${OFILE}${B} "field" | awk "$SAWK" | awk "$FAWK"`
    echo "FIELD: $FIELD"
    echo " "
    M="-"
    shift
    continue;;
  -f)
    shift
    FILE=$1
    shift
    continue;;
  -n)
    shift
    NPROG=$1
    shift
    continue;;
  -o)
    shift
    OPROG=$1
    shift
    continue;;
  -p)
    shift
    STDIN=$1
    if [ x`echo $STDIN | awk -F. '{print $NF}'` = x"gz" ]; then
      NFILE=stdin.gz
    else
      NFILE=stdin
    fi
    shift
    continue;;
  -P)
    PURE=YES
    DO1=YES
    NPROG=../funcnts.pure
    shift
    continue;;
  -s)
    shift
    SW=$1
    shift
    continue;;
  -v)
    VERBOSE=1
    shift
    continue;;
  -V)
    VERBOSE=2
    shift
    continue;;
  -x)
    shift
    X=$1
    shift
    continue;;
  -y)
    shift
    Y=$1
    shift
    continue;;
  *)
    shift
    continue;;
  esac
done

X2=`echo "$X + 10" | bc`
Y2=`echo "$Y + 10" | bc`
X3=`echo "$X + 20" | bc`
Y3=$Y
X4=`echo "$X + 10" | bc`
Y4=`echo "$Y - 10" | bc`

B1=`echo "$X - 100" | bc`
B2=`echo "$X + 99" | bc`
B3=`echo "$Y - 100" | bc`
B4=`echo "$Y + 99" | bc`
if [ x"$B" = x ]; then
  B="[$B1:$B2,$B3:$B4,3]"
fi

echo "OPROG="${OPROG} "OFILE="${OFILE}${B} X=${X} Y=${Y}
echo "NPROG="${NPROG} "NFILE="${NFILE}${B} X=${X} Y=${Y}

IFS="	"
while read ARG1 ARG2 ARG3; do
  if [ x"$ARG1" = x ]; then
    continue
  fi
  if [ x`echo $ARG1 | sed 's/^#.*/YES/g'` = x"YES" ]; then
    continue
  fi
  CMD=$ARG1
  eval "ARG2=\"${C}$ARG2\""
  eval "ARG3=\"${C}$ARG3\""
  if [ x$CMD = xZIEXACT ]; then
    if [ x$FILTER_PAINT = xtrue ]; then
      continue
    else
      CMD=EXACT
    fi
  fi
  if [ x$CMD = xZEXACT ]; then
    if [ x$FILTER_PAINT = xtrue ]; then
      CMD=SUM
    else
      CMD=EXACT
    fi
  fi
  case $CMD in
  OPROG)
    OPROG=$ARG2
    ;;
  NPROG)
    NPROG=$ARG2
    ;;
  FILE)
    FILE=$ARG2
    ;;
  EXCLUDE)
    FIELD=`$OPROG ${OFILE}${B} "field" | awk "$SAWK" | awk "$FAWK"`
    echo "FIELD: $FIELD"
    echo " "
    M="-"
    ;;
  EXIT)
    exit
    ;;
  EXACT)
    if [ x"$DO1" = xYES ]; then
      echo "${M}DO1: $ARG3"
      ($NPROG ${SW} ${NFILE}${B} "${M}$ARG3") >funcnts2.out 2>&1
    else
      echo "${M}EXACT: $ARG2 ... $ARG3"
      ($OPROG ${SW} ${OFILE}${B} "$ARG2" | awk $EAWK) >funcnts1.out 2>err.log
      if test $? -ne 0; then
        echo "skipping $NPROG due to error"
      else
        (cat $STDIN | $NPROG ${SW} ${NFILE}${B} "${M}$ARG3" | awk $EAWK) >funcnts2.out 2>&1
        if [ x$M = x ]; then
          diff funcnts1.out funcnts2.out
        else
          V1=`cat funcnts1.out | awk $FAWK`
          V2=`cat funcnts2.out | awk $FAWK`
          V2=`echo "$FIELD-$V2" | bc`
          if [ $V1 != $V2 ]; then
              echo "V1=$V1 V2=$V2"
          fi
        fi
      fi
    fi
    echo " "
    ;;
  REV)
    if [ x"$DO1" = xYES ]; then
      echo "${M}DO1: $ARG3"
      (cat $STDIN | $NPROG ${SW} ${NFILE}${B} "${M}$ARG3") >funcnts2.out 2>&1
    else
      echo "${M}REV: $ARG2 ... $ARG3"
      ($OPROG ${SW} ${OFILE}${B} "$ARG2" | awk $EAWK) >tfuncnts1.out 2>err.log
      if test $? -ne 0; then
        echo "skipping $NPROG due to error"
      else
        (cat $STDIN | $NPROG ${SW} ${NFILE}${B} "${M}$ARG3" | awk $EAWK) >tfuncnts2.out 2>&1
        if [ x$M = x ]; then
          awk 'NF==3{print $0}' < tfuncnts1.out | sort -r | awk '{print $2,$3}' > funcnts1.out
          awk 'NF==3{print $2,$3}' < tfuncnts2.out >funcnts2.out 2>&1
          diff funcnts1.out funcnts2.out
        else
          V1=`cat funcnts1.out | awk $FAWK`
          V2=`cat funcnts2.out | awk $FAWK`
          V2=`echo "$FIELD-$V2" | bc`
          if [ $V1 != $V2 ]; then
              echo "V1=$V1 V2=$V2"
          fi
        fi
      fi 
   fi
    echo " "
    ;;
  SUM)
    if [ x"$DO1" = xYES ]; then
      echo "${M}DO1: $ARG3"
      (cat $STDIN | $NPROG ${SW} ${NFILE}${B} "${M}$ARG3") >funcnts2.out 2>&1
    else
      echo "${M}SUM:   $ARG2 ... $ARG3"
      ($OPROG ${SW} ${OFILE}${B} "$ARG2" | awk $SAWK) >funcnts1.out 2>err.log
      if test $? -ne 0; then
        echo "skipping $NPROG due to error"
      else
        (cat $STDIN | $NPROG ${SW} ${NFILE}${B} "${M}$ARG3" | awk $SAWK) >funcnts2.out 2>&1
        if [ x$M = x ]; then
          diff funcnts1.out funcnts2.out
        else
          V1=`cat funcnts1.out | awk $FAWK`
          V2=`cat funcnts2.out | awk $FAWK`
          V2=`echo "$FIELD-$V2" | bc`
          if [ $V1 != $V2 ]; then
              echo "V1=$V1 V2=$V2"
          fi
        fi
      fi
    fi
    echo " "
    ;;
  *)
    echo "ERROR: unknown command: $CMD"
    exit 1
    ;;
  esac
  if [ $VERBOSE = 1 ]; then
    echo "***** funcnts1.out *****"
    cat funcnts1.out
  fi
  if [ $VERBOSE = 2 ]; then
    echo "***** funcnts1.out *****"
    cat funcnts1.out
    echo "***** funcnts2.out *****"
    cat funcnts2.out
  fi
  rm -f err.log
done

rm -f funcnts1.out funcnts2.out tfuncnts1.out tfuncnts2.out