#!/usr/local/bin/perl

# Copyright 1996 Shamim Mohamed, spm@crl.com

# This file is part of the plotfoil package.
# See http://www.crl.com/~spm/rec.models.rc/ for more details.

# This file may be redistributed under the Gnu Public License (GPL) Version 2.

# Usage: conversion.pl file1 file2 file3 ... 
#
# This will convert all the files from Lednicer format to Selig format.  If
# the file is not recognised to be in Lednicer format, it will be left
# untouched.
#
# The original file will be saved as file1.bak.

# Lednicer format:
#  BOEING-VERTOL VR-1 AIRFOIL
# 25.        25.
#
#  0.         0.
#   .00559     .01673
#   .03729     .03336
# ...
#   .98650     .00223
#  1.0         .0000
#
#  0.         0.
#   .00559    -.01001
#   .01850    -.01570
# ...
#   .94622    -.00395
#   .98650    -.00083
#  1.0         .0000
#
# Selig format:
#	      SD-8020
#          1.0 0
#          0.9 0.011
#          0.85 0.02
#          ...
#          1.0 0
#

$tmpfile = "tmp-nacafix-$$";

foreach $filename (@ARGV) {

    if(! -f $filename) {
	print STDERR "Couldn't open $filename -- skipping\n";
	next;
    }

    open(INFILE, $filename);
    open(OUTFILE, ">$tmpfile");
    # Print the name
    print OUTFILE scalar ;

    $_ = scalar ;
    ($u, $l) = split(' ');

    $_ = scalar ;
    # This should have been a blank line
    if (/[0-9]/) {
	print STDERR "I don't think $filename is in this format! Skipping\n";
	next;
    }

    for ($i = 0; $i < $u; $i++) {
	$_ = scalar ;
	($x, $upper) = split(' ');
	$upper{$i} = $x . " " . $upper . "\n";
    }
    $_ = scalar ;
    # This should be a blank line
    if (/[0-9]/) {
	print STDERR "I don't think $filename is in this format! Skipping\n";
	next;
    }

    for ($i = 0; $i < $l; $i++) {
	$_ = scalar ;
	($x, $lower) = split(' ');
	$lower{$i} = $x . " " . $lower . "\n";
    }

    for($i = $u-1; $i >= 0; $i--) {
	print OUTFILE  $upper{$i};
    }
    # 0.0 0.0 will occur twice if we start from 0
    for($i = 1; $i < $l; $i++) {
	print OUTFILE $lower{$i};
    }
    close(INFILE); close(OUTFILE);
    rename($filename, $filename . ".bak");
    rename($tmpfile, $filename);
}

exit 0;

[Top] [UIUC Applied Aerodynamics Group]