formatting .dat files for rhino

XFLR5, a wing analysis/profile plotting software exports the wing profile coordinates into a .dat file.
in order to use this file with rhino, you must reformat it from this:

 1.00000     0.00000
 0.95544     0.00396
 0.91361     0.00764
 ...

to this:

1.00000,0.00000
0.95544,0.00396
0.91361,0.00764
...

because I’m lazy, I wrote a Z-shell script to automate this process
it also adds commands to the file, so you can use the readCommandFile command to automatically plot the airfoil

#! /bin/zsh

#Guandi97
#micropenguin.net

function help
{
	echo -e DaTRhiCoor: Data to Rhino Coordinates!
	awk 'BEGIN {printf("usage: %s [-flags] \n","DaTRhiCoor")}'
	echo -e "flags:\n\t-r\tadd rhino commands\n\t-n\tdon't add commands"
	echo -e "the game"
	exit
}
if [[ $# -lt 2 ]] 
then
	help
fi
if [[ ! ( -a $2 ) ]]
then
	echo "file '$2' not found"
else
	if [[ -z $3 ]]
	then
		3="output"
	fi	
	if [[ $1 == "-r" ]]
	then
		echo !interpCrv | tee $3
	fi

	feof=0
	i=0
	linA=$(wc -l $2 | tr ' ' '\n' | grep -e '^\d')
	linB=$(echo -e $linA | awk '{print $1*2}')

	stream=$(cat $2 | tr ' ' '\n' | grep -e '^\d\|^-\d')
	for i in {1..$linA..2}
	do
		let "j = i+1"
		echo -e $stream | sed -n "${i}p" | tr '\n' ',' | tee -a $3
		echo -e $stream | sed -n "${j}p" | tee -a $3
	done
	if [[ $1 == "-r" ]]
	then
		echo -e 'enter\ninterpCrv' | tee -a $3
	fi
	let "linA = linA+1"
	for i in {$linA..$linB..2}
	do
		let "j = i+1"
		echo -e $stream | sed -n "${i}p" | tr '\n' ',' | tee -a $3
		echo -e $stream | sed -n "${j}p" | tee -a $3
	done
	if [[ $1 == "-r" ]]
	then
		echo -e enter | tee -a $3
	fi	
	
	echo -e "\ndone: $linB lines parsed"
	
fi

Leave a Reply

Your email address will not be published. Required fields are marked *