orig/falsecolor.csh
author Axel Jacobs <axel@jaloxa.eu>
Mon, 14 Apr 2014 22:21:17 +0100
changeset 73 87fa3132a136
parent 0 0aa115157c9c
permissions -rw-r--r--
New IES test file with spaces in file name
axel@0
     1
#!/bin/csh -fe
axel@0
     2
# RCSid: $Id: falsecolor.csh,v 2.19 2008/11/10 19:08:19 greg Exp $
axel@0
     3
#
axel@0
     4
# Create false color image with legend
axel@0
     5
#
axel@0
     6
# Added user-definable legend 2004/01/20 Rob Guglielmetti
axel@0
     7
axel@0
     8
onintr quit
axel@0
     9
set td=`mktemp -d /tmp/fc.XXXXXX`
axel@0
    10
set mult=179
axel@0
    11
set label=Nits
axel@0
    12
set scale=1000
axel@0
    13
set decades=0
axel@0
    14
set redv='def_red(v)'
axel@0
    15
set grnv='def_grn(v)'
axel@0
    16
set bluv='def_blu(v)'
axel@0
    17
set ndivs=8
axel@0
    18
set picture='-'
axel@0
    19
set cpict=
axel@0
    20
set loff=0
axel@0
    21
set legwidth=100
axel@0
    22
set legheight=200
axel@0
    23
while ($#argv > 0)
axel@0
    24
	switch ($argv[1])
axel@0
    25
	case -lw:
axel@0
    26
		shift argv
axel@0
    27
		set legwidth="$argv[1]"
axel@0
    28
		breaksw
axel@0
    29
	case -lh:
axel@0
    30
		shift argv
axel@0
    31
		set legheight="$argv[1]"
axel@0
    32
		breaksw
axel@0
    33
	case -m:
axel@0
    34
		shift argv
axel@0
    35
		set mult="$argv[1]"
axel@0
    36
		breaksw
axel@0
    37
	case -s:
axel@0
    38
		shift argv
axel@0
    39
		set scale="$argv[1]"
axel@0
    40
		if ("$scale" =~ [aA]*) set needfile
axel@0
    41
		breaksw
axel@0
    42
	case -l:
axel@0
    43
		shift argv
axel@0
    44
		set label="$argv[1]"
axel@0
    45
		breaksw
axel@0
    46
	case -log:
axel@0
    47
		shift argv
axel@0
    48
		set decades=$argv[1]
axel@0
    49
		breaksw
axel@0
    50
	case -r:
axel@0
    51
		shift argv
axel@0
    52
		set redv="$argv[1]"
axel@0
    53
		breaksw
axel@0
    54
	case -g:
axel@0
    55
		shift argv
axel@0
    56
		set grnv="$argv[1]"
axel@0
    57
		breaksw
axel@0
    58
	case -b:
axel@0
    59
		shift argv
axel@0
    60
		set bluv="$argv[1]"
axel@0
    61
		breaksw
axel@0
    62
	case -spec:
axel@0
    63
		set redv='1.6*v-.6'
axel@0
    64
		set grnv='if(v-.375,1.6-1.6*v,8/3*v)'
axel@0
    65
		set bluv='1-8/3*v'
axel@0
    66
		breaksw
axel@0
    67
	case -i:
axel@0
    68
		shift argv
axel@0
    69
		set picture="$argv[1]"
axel@0
    70
		breaksw
axel@0
    71
	case -p:
axel@0
    72
		shift argv
axel@0
    73
		set cpict="$argv[1]"
axel@0
    74
		breaksw
axel@0
    75
	case -ip:
axel@0
    76
	case -pi:
axel@0
    77
		shift argv
axel@0
    78
		set picture="$argv[1]"
axel@0
    79
		set cpict="$argv[1]"
axel@0
    80
		breaksw
axel@0
    81
	case -cl:
axel@0
    82
		set docont=a
axel@0
    83
		set loff=12
axel@0
    84
		breaksw
axel@0
    85
	case -cb:
axel@0
    86
		set docont=b
axel@0
    87
		set loff=13
axel@0
    88
		breaksw
axel@0
    89
	case -e:
axel@0
    90
		set doextrem
axel@0
    91
		set needfile
axel@0
    92
		breaksw
axel@0
    93
	case -n:
axel@0
    94
		shift argv
axel@0
    95
		set ndivs="$argv[1]"
axel@0
    96
		breaksw
axel@0
    97
	default:
axel@0
    98
		echo bad option "'$argv[1]'"
axel@0
    99
		exit 1
axel@0
   100
	endsw
axel@0
   101
	shift argv
axel@0
   102
end
axel@0
   103
if ($?needfile && "$picture" == '-') then
axel@0
   104
	cat > $td/picture
axel@0
   105
	set picture=$td/picture
axel@0
   106
endif
axel@0
   107
if ("$scale" =~ [aA]*) then
axel@0
   108
	set LogLmax=`phisto $picture | tail -2 | sed -n '1s/	[0-9]*$//p'`
axel@0
   109
	set scale=`ev "$mult/179*10^$LogLmax"`
axel@0
   110
endif
axel@0
   111
cat > $td/pc0.cal <<_EOF_
axel@0
   112
PI : 3.14159265358979323846 ;
axel@0
   113
scale : $scale ;
axel@0
   114
mult : $mult ;
axel@0
   115
ndivs : $ndivs ;
axel@0
   116
axel@0
   117
or(a,b) : if(a,a,b);
axel@0
   118
EPS : 1e-7;
axel@0
   119
neq(a,b) : if(a-b-EPS,1,b-a-EPS);
axel@0
   120
btwn(a,x,b) : if(a-x,-1,b-x);
axel@0
   121
clip(x) : if(x-1,1,if(x,x,0));
axel@0
   122
frac(x) : x - floor(x);
axel@0
   123
boundary(a,b) : neq(floor(ndivs*a+.5),floor(ndivs*b+.5));
axel@0
   124
axel@0
   125
interp_arr2(i,x,f):(i+1-x)*f(i)+(x-i)*f(i+1);
axel@0
   126
interp_arr(x,f):if(x-1,if(f(0)-x,interp_arr2(floor(x),x,f),f(f(0))),f(1));
axel@0
   127
def_redp(i):select(i,0.18848,0.05468174,
axel@0
   128
0.00103547,8.311144e-08,7.449763e-06,0.0004390987,0.001367254,
axel@0
   129
0.003076,0.01376382,0.06170773,0.1739422,0.2881156,0.3299725,
axel@0
   130
0.3552663,0.372552,0.3921184,0.4363976,0.6102754,0.7757267,
axel@0
   131
0.9087369,1,1,0.9863);
axel@0
   132
def_red(x):interp_arr(x/0.0454545+1,def_redp);
axel@0
   133
def_grnp(i):select(i,0.0009766,2.35501e-05,
axel@0
   134
0.0008966244,0.0264977,0.1256843,0.2865799,0.4247083,0.4739468,
axel@0
   135
0.4402732,0.3671876,0.2629843,0.1725325,0.1206819,0.07316644,
axel@0
   136
0.03761026,0.01612362,0.004773749,6.830967e-06,0.00803605,
axel@0
   137
0.1008085,0.3106831,0.6447838,0.9707);
axel@0
   138
def_grn(x):interp_arr(x/0.0454545+1,def_grnp);
axel@0
   139
def_blup(i):select(i,0.2666,0.3638662,0.4770437,
axel@0
   140
0.5131397,0.5363797,0.5193677,0.4085123,0.1702815,0.05314236,
axel@0
   141
0.05194055,0.08564082,0.09881395,0.08324373,0.06072902,
axel@0
   142
0.0391076,0.02315354,0.01284458,0.005184709,0.001691774,
axel@0
   143
2.432735e-05,1.212949e-05,0.006659406,0.02539);
axel@0
   144
def_blu(x):interp_arr(x/0.0454545+1,def_blup);
axel@0
   145
axel@0
   146
isconta = if(btwn(0,v,1),or(boundary(vleft,vright),boundary(vabove,vbelow)),-1);
axel@0
   147
iscontb = if(btwn(0,v,1),btwn(.4,frac(ndivs*v),.6),-1); 
axel@0
   148
axel@0
   149
ra = 0;
axel@0
   150
ga = 0;
axel@0
   151
ba = 0;
axel@0
   152
axel@0
   153
in = 1;
axel@0
   154
axel@0
   155
ro = if(in,clip($redv),ra);
axel@0
   156
go = if(in,clip($grnv),ga);
axel@0
   157
bo = if(in,clip($bluv),ba);
axel@0
   158
_EOF_
axel@0
   159
cat > $td/pc1.cal <<_EOF_
axel@0
   160
norm : mult/scale/le(1);
axel@0
   161
axel@0
   162
v = map(li(1)*norm);
axel@0
   163
axel@0
   164
vleft = map(li(1,-1,0)*norm);
axel@0
   165
vright = map(li(1,1,0)*norm);
axel@0
   166
vabove = map(li(1,0,1)*norm);
axel@0
   167
vbelow = map(li(1,0,-1)*norm);
axel@0
   168
axel@0
   169
map(x) = x;
axel@0
   170
axel@0
   171
ra = ri(nfiles);
axel@0
   172
ga = gi(nfiles);
axel@0
   173
ba = bi(nfiles);
axel@0
   174
_EOF_
axel@0
   175
set pc0args=(-f $td/pc0.cal)
axel@0
   176
set pc1args=(-f $td/pc1.cal)
axel@0
   177
if ($?docont) then
axel@0
   178
	set pc0args=($pc0args -e "in=iscont$docont")
axel@0
   179
endif
axel@0
   180
if ("$cpict" == "") then
axel@0
   181
	set pc1args=($pc1args -e 'ra=0;ga=0;ba=0')
axel@0
   182
else if ("$cpict" == "$picture") then
axel@0
   183
	set cpict=
axel@0
   184
endif
axel@0
   185
if ("$decades" != "0") then
axel@0
   186
	set pc1args=($pc1args -e "map(x)=if(x-10^-$decades,log10(x)/$decades+1,0)")
axel@0
   187
	set imap="imap(y)=10^((y-1)*$decades)"
axel@0
   188
else
axel@0
   189
	set imap="imap(y)=y"
axel@0
   190
endif
axel@0
   191
if ( $legwidth > 20 && $legheight > 40 ) then
axel@0
   192
pcomb $pc0args -e 'v=(y+.5)/yres;vleft=v;vright=v' \
axel@0
   193
		-e 'vbelow=(y-.5)/yres;vabove=(y+1.5)/yres' \
axel@0
   194
		-x $legwidth -y $legheight > $td/scol.hdr
axel@0
   195
( echo "$label"; cnt $ndivs \
axel@0
   196
		| rcalc -e '$1='"($scale)*imap(($ndivs-.5-"'$1'")/$ndivs)" \
axel@0
   197
		-e "$imap" | sed -e 's/\(\.[0-9][0-9][0-9]\)[0-9]*/\1/' ) \
axel@0
   198
	| psign -s -.15 -cf 1 1 1 -cb 0 0 0 \
axel@0
   199
		-h `ev "floor($legheight/$ndivs+.5)"` > $td/slab.hdr
axel@0
   200
else
axel@0
   201
	set legwidth=0
axel@0
   202
	set legheight=0
axel@0
   203
	(echo "" ; echo "-Y 1 +X 1" ; echo "aaa" ) > $td/scol.hdr
axel@0
   204
	cp $td/scol.hdr $td/slab.hdr
axel@0
   205
endif
axel@0
   206
if ( $?doextrem ) then
axel@0
   207
	pextrem -o $picture > $td/extrema
axel@0
   208
	set minpos=`sed 2d $td/extrema | rcalc -e '$2=$2;$1=$1+'"$legwidth"`
axel@0
   209
	set minval=`rcalc -e '$1=($3*.27+$4*.67+$5*.06)*'"$mult" $td/extrema | sed -e 2d -e 's/\(\.[0-9][0-9][0-9]\)[0-9]*/\1/'`
axel@0
   210
	set maxpos=`sed 1d $td/extrema | rcalc -e '$2=$2;$1=$1+'"$legwidth"`
axel@0
   211
	set maxval=`rcalc -e '$1=($3*.27+$4*.67+$5*.06)*'"$mult" $td/extrema | sed -e 1d -e 's/\(\.[0-9][0-9][0-9]\)[0-9]*/\1/'`
axel@0
   212
	psign -s -.15 -a 2 -h 16 $minval > $td/minv.hdr
axel@0
   213
	psign -s -.15 -a 2 -h 16 $maxval > $td/maxv.hdr
axel@0
   214
	pcomb $pc0args $pc1args $picture $cpict \
axel@0
   215
		| pcompos $td/scol.hdr 0 0 \
axel@0
   216
			+t .1 "\!pcomb -e 'lo=1-gi(1)' $td/slab.hdr" \
axel@0
   217
			`ev 2 $loff-1` -t .5 $td/slab.hdr 0 $loff \
axel@0
   218
		  - $legwidth 0 $td/minv.hdr $minpos $td/maxv.hdr $maxpos
axel@0
   219
else
axel@0
   220
	pcomb $pc0args $pc1args $picture $cpict \
axel@0
   221
		| pcompos $td/scol.hdr 0 0 \
axel@0
   222
			+t .1 "\!pcomb -e 'lo=1-gi(1)' $td/slab.hdr" \
axel@0
   223
			`ev 2 $loff-1` -t .5 $td/slab.hdr 0 $loff \
axel@0
   224
			- $legwidth 0
axel@0
   225
endif
axel@0
   226
quit:
axel@0
   227
rm -rf $td