orig/ra_pfm.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     1
#!/bin/csh -f
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     2
# RCSid $Id: ra_pfm.csh,v 2.5 2006/11/17 19:14:54 greg Exp $
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     3
#
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     4
# Convert to/from Poskanzer Float Map image format using pvalue
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     5
#
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     6
if (`uname -p` == powerpc) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     7
	set machend=big
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     8
else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     9
	set machend=little
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    10
endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    11
while ($#argv > 0)
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    12
	if ("$argv[1]" == "-r") then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    13
		set reverse
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    14
	else if (! $?inp) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    15
		set inp="$argv[1]"
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    16
	else if (! $?out) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    17
		set out="$argv[1]"
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    18
	else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    19
		goto userr
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    20
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    21
	shift argv
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    22
end
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    23
if ($?reverse) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    24
	if (! $?inp) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    25
		goto userr
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    26
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    27
	set opt=""
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    28
	set hl="`head -3 $inp:q`"
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    29
	if ("$hl[1]" == "Pf") then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    30
		set opt=($opt -b)
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    31
	else if ("$hl[1]" != "PF") then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    32
		echo "Input not a Poskanzer Float Map"
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    33
		exit 1
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    34
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    35
	if (`ev "if($hl[3],1,0)"`) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    36
		set filend=big
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    37
	else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    38
		set filend=little
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    39
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    40
	if ($filend != $machend) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    41
		set opt=($opt -dF)
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    42
	else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    43
		set opt=($opt -df)
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    44
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    45
	set res=($hl[2])
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    46
	if ($?out) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    47
		tail +4 $inp:q | pvalue -r -h $opt +y $res[2] +x $res[1] > $out:q
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    48
	else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    49
		tail +4 $inp:q | pvalue -r -h $opt +y $res[2] +x $res[1]
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    50
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    51
	exit $status
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    52
endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    53
if (! $?inp) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    54
	goto userr
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    55
endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    56
set res=(`getinfo -d < $inp:q`)
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    57
if ($?out) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    58
	( echo PF ; echo $res[4] $res[2] ) > $out:q
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    59
	if ($machend == little) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    60
		echo "-1.000000" >> $out:q
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    61
	else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    62
		echo "1.000000" >> $out:q
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    63
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    64
	if ("$res[1]" == "-Y") then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    65
		pflip -v $inp:q | pvalue -h -H -df >> $out:q
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    66
	else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    67
		pvalue -h -H -df $inp:q >> $out:q
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    68
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    69
else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    70
	echo PF
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    71
	echo $res[4] $res[2]
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    72
	if ($machend == little) then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    73
		echo "-1.000000"
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    74
	else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    75
		echo "1.000000"
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    76
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    77
	if ("$res[1]" == "-Y") then
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    78
		pflip -v $inp:q | pvalue -h -H -df
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    79
	else
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    80
		pvalue -h -H -df $inp:q
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    81
	endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    82
endif
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    83
exit $status
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    84
userr:
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    85
echo "Usage: $0 input.hdr [output.pfm]"
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    86
echo "   or: $0 -r input.pfm [output.hdr]"
0aa115157c9c Added original CSH script from HEAD-20110409.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    87
exit 1