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