clear all
%Title: awaveFileMake.m
%MATLAB
%Author: K. Todd Lowe, kelowe@vt.edu
%Date begun: 1/25/2006
%Last update: 2/7/2006
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Usage notes:
% The following lines of the script indicate the data to be entered into
% the awave.exe program available from Dr. Mason's design software
% portfolio. To use this script, refer to the notes in the right hand
% columns that describe the variables that must be entered. After deciding
% the proper value for the paramters, enter them in the active portion of
% the script next to the variable name. After entering all the data,
% running the script will produce a file with the proper formatting to be
% used with the awave.exe code.

%Known issues: Non-circular fuselage cross-sections not yet supported.
%              Canard airfoil sections must be same inboard and outboard.
%       Modification log:   
%       2/7/2006    Fixed order of fuselage segment inputs  KTL
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Input the directory for the awave.exe program:
writeFile='c:\awaveInputs.in';      
%Name the test case used:
writeName='First test case';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

fid=fopen(writeFile,'w');
fprintf(fid,'%s\n',writeName);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Prelimary inputs:
J0=1;%          1- 3     = 0, No reference area
%                        = 1, Reference area will be input and used
%                        = 2, Reference area from previous
%                             configuration will be used

J1=1;          %4- 6     = 0, No wing
%                        = 1, Cambered wing data will be input
%                        =-1, Uncambered wing data will be input
%                        = 2, Wing data from previous configuration
%                             will be used

J2=-1;%          7- 9     = 0, No fuselage
%                        = 1, Arbitrarily shaped fuselage
%                        =-1, Circular fuselage
%                        = 2, Fuselage data from previous
%                             configuration will be used

J3=1;%         10-12     = 0, No pod
%                        = 1, Pod data will be input
%                        = 2, Pod data from previous configuration
%                             will be used

J4=1;%         13-15     = 0, No fin (Vertical tail)
%                        = 1, Fin data will be input
%                        = 2, Fin data from previous configuration
%                             will be used

J5=0;%         16-18     = 0, No canard (Horizontal tail)
%                        = 1, Canard data will be input
%                        = 2, Canard data from previous
%                             configuration will be used

J6=0;%         19-21     = 1, Complete configuration is symmetrical
%                             with respect to the X-Y plane, implies
%                             an uncambered circular fuselage if a
%                             fuselage exists.
%                        =-1, The circular fuselage is symmetrical
%                             (uncambered)
%                        = 0, No X-Y plane symmetry

NWAF=18;%       22-24     Number of airfoil sections used to describe
%                        the wing (minimum = 2, maximum = 20)

NWAFOR=20;%     25-27     Number of stations at which ordinates are
%                        input for each wing airfoil section
%                        (minimum = 3, maximum = 30)
%                        If given a negative sign, the program
%                        will expect to read both upper and lower
%                        ordinates.  If positive, the airfoil is
%                        assumed to be symmetrical.

NFUS=1;%       28-30     Number of fuselage segments
%                        (minimum = 1, maximum = 4)

NRADX(1)=24;%   31-33     Number of points per station used to
%                        represent a half-section of the first
%                        fuselage segment.  For circular fuselages,
%                        NRADX y and z coordinates are computed
%                        (minimum = 3, maximum = 30)

NFORX(1)=22;%   34-36     Number of stations for first fuselage
%                        segment (minimum = 4, maximum = 30)

NRADX(2)=0;%   37-39     Same as NRADX(1) but for second segment

NFORX(2)=0;%   40-42     Same as NFORX(1) but for second segment

NRADX(3)=0;%   43-45     Same as NRADX(1) but for third segment

NFORX(3)=0;%   46-48     Same as NFORX(1) but for third segment

NRADX(4)=0;%   49-51     Same as NRADX(1) but for fourth segment

NFORX(4)=0;%   52-54     Same as NFORX(1) but for fourth segment

NP=4;%         55-57     Number of pods described (maximum = 9)

NPODOR=9;%     58-60     Number of stations at which pod radii are
%           input (minimum = 4, maximum = 30)

NF =1;%        61-63     Number of fins (vertical tails) described
%                        (maximum = 6) If given a negative sign, the
%                        program will expect to read ordinates for
%                        both the outboard and inboard sides of the
%                        fins.  If positive, the airfoils are
%                        assumed to be symmetrical.

NFINOR=10;%     64-66     Number of stations at which ordinates are
%                        input for each fin airfoil
%                        (minimum = 3, maximum = 10)

NCAN=0;%       67-69     Number of canards (horizontal tails)
%                        defined (maximum = 2).  If given a negative
%                        sign, the program will expect to read
%                        ordinates for both the root and tip.  If
%                        positive, the root and tip airfoils are
%                        assumed to be the same.

NCANOR=0;%     70-72     Number of stations at which ordinates are
%                        input for each canard airfoil
%                        (minimum = 3, maximum = 10) 
%                        If given a negative sign, the program
%                        will expect to read both upper and lower
%                        ordinates.  If positive, the airfoil is
%                        assumed to be symmetrical.
%End preliminary inputs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf(fid,'%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d  CONTROL\n', ...
    J0,J1,J2,J3,J4,J5,J6,NWAF,NWAFOR,NFUS,NRADX(1),NFORX(1),NRADX(1),NFORX(2),...
    NRADX(3),NFORX(3),NRADX(4),NFORX(4),NP,NPODOR,NF,NFINOR,NCAN,NCANOR);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Reference Area Card: Format(3F7.0)  Input only if J0 = 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
REFA=200;%          Reference wing area used for drag coefficient
%      computation

CBAR=2;%          Wing reference chord for use in aerodynamic moment
%        coefficients

XMC=10;%           x coordinate of moment reference center
% 
% Note: CBAR and XMC are not used in AWAVE but may be used in other
%       programs which use this type of geometry deck.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if J0==1
    fprintf(fid,'%7.1f%7.1f%7.1f                                                   REFA\n',REFA,CBAR,XMC);
end

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% 
%                     Configuration Data Cards 
% 
% 
%      Data describing the configuration are input in seven column
% fields with a decimal point, with up to ten fields per card.  If
% more than ten fields are required, additional cards are used.
% 
%      Columns 73 and up are used for identification.  This usually
% consists of a key word and a number or combination of numbers
% identifying that card within the group.  For example, "WAFORG 3"
% would be the card specifying the location of the third airfoil,
% and "TZORD 3-2" might be the second card defining the mean camber
% line for the third airfoil.  This identification is not used by
% the program, but it is useful because all configuration data are
% input in the same format, and it all looks alike.  Suggested
% identifiers are provided.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% 
%                         Wing Data Cards
% 
% 
%      If J1 = 0 or 2, no wing data is input.  Only one wing may be
% defined for a configuration.  Input must include Wing Percent
% Chord Location Card(s), Wing Airfoil Location Cards, and Wing
% Airfoil Ordinate Cards.  Wing Mean Camber Line Cards are optional
% depending on J1.
% 
if abs(J1)==1
    
    % 
    % % Wing Percent Chord Location Card(s): Format(10F7.0)  NWAFOR values
    % %   are input, ten to a card.  (Identifier = XAF)
    % 
    %   XAF(I)        Locations in percent chord ((x/c)*100) at which the
    %                 ordinates of all wing airfoils are to be specified.
    

    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %Enter wing airfoil coordinates as a percent of the chord in the following
    %array:
    XAF=[0.000  0.250  0.500  0.750  1.000  3.000  5.000  7.500 10.000 15.000...
            20.000 30.000 40.000 50.000 60.000 70.000 80.000 90.000 95.000 100.000  ];
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    for i=1:NWAFOR
        if mod(i,10)==0
            fprintf(fid,'%7.3f  XAF %i\n',XAF(i),floor(i/10));
        else
            fprintf(fid,'%7.3f',XAF(i));
        end
    end
    if mod(NWAFOR,10)~=0
        num2Fill=10-mod(NWAFOR,10);
        for i=1:num2Fill
            fprintf(fid,'       ');
        end
        fprintf(fid,'  XAF %i\n',ceil(NWAFOR/10));
    end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % 
    %
    %
    % 
    % Wing Airfoil Location Cards: Format(4F7.0)  NWAF cards are input,
    %   one for each airfoil, in order, from the most inboard airfoil to
    %   the most outboard.  (Identifier = WAFORG)
    % 
    %   Columns       Description
    % 
    %     1- 7        x coordinate of airfoil leading edge
    % 
    %     8-14        y coordinate of airfoil leading edge
    % 
    %    15-21        z coordinate of airfoil leading edge
    % 
    %    22-28        airfoil streamwise chord length
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %For each of the airfoil sections specified by NWAF, enter the X, Y, Z
    %coordinates of the leading edge and the streamwise chord length of the
    %airfoil. Format: WAFORG=[X1 Y1 Z1 C1
    %                             X2 Y2 Z2 C2
    %                             ...
    %                             XNWAF YNWAF ZNWAF CNWAF];
    
    WAFORG=[65.923  6.000 -1.206    142.012                      
        79.874 10.000 -3.053   128.061               
        93.822 14.000 -4.469   114.113                                            
        107.774 18.000 -5.309   100.161                                           
        121.722 22.000 -5.826   86.213                                            
        135.673 26.000 -6.033   72.262                                           
        149.621 30.000 -6.021   58.314                                            
        165.574 34.574 -5.675   42.362                                            
        168.999 38.000 -5.639   39.439                                           
        172.999 42.000 -5.244   36.027                                           
        176.999 46.000 -5.013   32.614                                            
        180.999 50.000 -4.919   29.201                                            
        184.999 54.000 -4.841   25.789                                            
        188.999 58.000 -4.781   22.376                                            
        192.999 62.000 -4.736   18.964                                           
        196.999 66.000 -4.699   15.551                                            
        200.999 70.000 -4.663   12.138           
        204.322 73.323 -4.629   9.303];                                 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    for i=1:NWAF
        fprintf(fid,'%7.3f%7.3f%7.3f%7.3f                                            WAFORG%3d\n',WAFORG(i,1),WAFORG(i,2),WAFORG(i,3),WAFORG(i,4),i);
    end
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % 
    % Wing Mean Camber Line Cards: Format(10F7.0)  Input only if J1 = 1.
    %   NWAFOR values are input for each airfoil, ten to a card.  Each
    %   airfoil is started on a new card.  NWAF sets of data are input,
    %   one for each airfoil.  (Identifier = TZORD)
    % 
    %   TZORD(I,J)    Delta z value, referenced to the z coordinate of
    %                 the airfoil leading edge, at the Jth wing percent
    %                 chord location for the Ith wing airfoil.
    % 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %Enter the Delta-z values for the wing airfoil mean camber line in the following
    %maxtrix. Each row refers to the airfoil sections with leading edges
    %specified in WAFORG (with quantity NWAF). Each column refers to the airfoil stations as
    %specified in XAF (with quantity NWAFOR).
    
    
    TZORD=[  0.000  0.004  0.009  0.012  0.016  0.034  0.035  0.012 -0.033 -0.160 -0.323 -0.714 -1.145 -1.591 -2.025 -2.434 -2.804 -3.126 -3.265 -3.396 
        0.000  0.009  0.018  0.027  0.035  0.096  0.143  0.181  0.203  0.214   0.193  0.082 -0.093 -0.308 -0.547 -0.798 -1.053 -1.305 -1.428 -1.550  
        0.000  0.012  0.024  0.036  0.047  0.135  0.210  0.289  0.354  0.458     0.530  0.608  0.617  0.576  0.493  0.379  0.240  0.081 -0.005 -0.094  
        0.000  0.013  0.025  0.038  0.050  0.145  0.230  0.324  0.407  0.551     0.668  0.845  0.957  1.020  1.040  1.024  0.978  0.904  0.858  0.808  
        0.000  0.013  0.025  0.037  0.050  0.144  0.231  0.330  0.419  0.581     0.720  0.949  1.123  1.251  1.341  1.398  1.426  1.426  1.417  1.405  
        0.000  0.012  0.023  0.035  0.046  0.134  0.217  0.312  0.399  0.559     0.701  0.943  1.140  1.300  1.428  1.529  1.604  1.658  1.678  1.694  
        0.000  0.010  0.020  0.030  0.040  0.118  0.192  0.277  0.356  0.504     0.636  0.868  1.066  1.235  1.378  1.502  1.605  1.693  1.731  1.766  
        0.000  0.008  0.016  0.023  0.031  0.090  0.147  0.213  0.276  0.389     0.495  0.681  0.844  0.986  1.112  1.225  1.324  1.413  1.454  1.493  
        0.000  0.007  0.014  0.021  0.028  0.082  0.134  0.194  0.251  0.356     0.448  0.617  0.763  0.891  1.005  1.106  1.198  1.280  1.318  1.355  
        0.000  0.006  0.011  0.017  0.023  0.066  0.107  0.153  0.196  0.275     0.347  0.470  0.575  0.665  0.744  0.813  0.874  0.929  0.954  0.978  
        0.000  0.005  0.009  0.013  0.017  0.051  0.083  0.120  0.155  0.216     0.269  0.360  0.433  0.496  0.547  0.593  0.632  0.666  0.682  0.697  
        0.000  0.004  0.008  0.012  0.016  0.046  0.073  0.106  0.136  0.190    0.237  0.312  0.374  0.424  0.467  0.503  0.535  0.563  0.577  0.590  
        0.000  0.003  0.007  0.011  0.014  0.041  0.066  0.095  0.120  0.164     0.203  0.268  0.320  0.362  0.397  0.428  0.454  0.478  0.489  0.500  
        0.000  0.003  0.006  0.009  0.012  0.034  0.055  0.080  0.103  0.142     0.175  0.230  0.276  0.312  0.343  0.369  0.393  0.415  0.425  0.435  
        0.000  0.002  0.005  0.008  0.010  0.030  0.049  0.068  0.086  0.120     0.151  0.199  0.237  0.271  0.299  0.324  0.347  0.368  0.377  0.387  
        0.000  0.002  0.004  0.006  0.008  0.025  0.040  0.057  0.073  0.102    0.128  0.172  0.208  0.236  0.263  0.288  0.310  0.330  0.340  0.349  
        0.000  0.001  0.003  0.005  0.006  0.019  0.030  0.044  0.057  0.082     0.104  0.143  0.173  0.202  0.228  0.252  0.274  0.293  0.302  0.310  
        0.000  0.002  0.003  0.003  0.005  0.015  0.025  0.038  0.049  0.067     0.084  0.115  0.147  0.174  0.198  0.221  0.238  0.254  0.260  0.266  ];
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    if J1==1
        
        for j=1:NWAF
            for i=1:NWAFOR
                if mod(i,10)==0
                    fprintf(fid,'%7.3f  TZORD %i-%i\n',TZORD(j,i),j,floor(i/10));
                else
                    fprintf(fid,'%7.3f',TZORD(j,i));
                end
            end
            if mod(NWAFOR,10)~=0
                num2Fill=10-mod(NWAFOR,10);
                for i=1:num2Fill
                    fprintf(fid,'       ');
                end
                fprintf(fid,'  TZORD %i-%i\n',j,ceil(NWAFOR/10));
            end
        end
        
    end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % 
    % Wing Airfoil Ordinate Cards: Format(10F7.0)  NWAF sets of data are
    %   input, one for each airfoil. NWAFOR values are input for each
    %   airfoil, ten to a card.  Each airfoil is started on a new card.
    %   If NWAFOR < 0, the wing is not symmetric and two sets of data
    %   are input for each airfoil, the distance from the mean camber
    %   line to the upper surface followed (on a new card) by the
    %   distance from the lower surface to the mean camber line.  Both
    %   are expressed as percent chord as described below.  (Identifier
    %   = WAFORD)
    % 
    %   WAFORD(I,J)   Airfoil half-thickness ordinates of the wing,
    %                 expressed as percent chord (100 * (t/c) / 2),
    %                 at the Jth wing percent chord location for the
    %                 Ith wing airfoil.
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    %Enter the thickness values for the wing airfoil stations. Each row refers to the airfoil sections with leading edges
    %specified in WAFORG (with quantity NWAF). In the case of asymmetrical airfoils, single sections
    %are specified in pairs of rows, the first being the top surface and second the bottom. 
    %Each column refers to the airfoil stations as
    %specified in XAF (with quantity NWAFOR).
    
    WAFORD=[ 0.0000 0.1048 0.1886 0.2393 0.2764 0.4564 0.5774 0.6970 0.7968 0.9565   1.0828 1.2716 1.3966 1.4657 1.4855 1.3143 0.9364 0.4756 0.2382 0.0000  
        0.0000 0.1043 0.1879 0.2386 0.2755 0.4547 0.5751 0.6943 0.7936 0.9526   1.0781 1.2656 1.3891 1.4566 1.4728 1.2950 0.9202 0.4670 0.2338 0.0000  
        0.0000 0.1038 0.1870 0.2378 0.2743 0.4528 0.5722 0.6908 0.7896 0.9477   1.0724 1.2582 1.3798 1.4452 1.4567 1.2711 0.9005 0.4566 0.2286 0.0000  
        0.0000 0.1031 0.1859 0.2366 0.2727 0.4500 0.5685 0.6864 0.7845 0.9413   1.0649 1.2485 1.3677 1.4305 1.4353 1.2410 0.8759 0.4437 0.2221 0.0000  
        0.0000 0.1022 0.1845 0.2351 0.2706 0.4465 0.5636 0.6805 0.7776 0.9327   1.0549 1.2356 1.3514 1.4109 1.4060 1.2018 0.8444 0.4272 0.2138 0.0000  
        0.0000 0.1010 0.1825 0.2329 0.2676 0.4414 0.5567 0.6724 0.7681 0.9209   1.0409 1.2175 1.3285 1.3832 1.3631 1.1490 0.8029 0.4057 0.2029 0.0000  
        0.0000 0.0992 0.1796 0.2294 0.2629 0.4337 0.5464 0.6600 0.7537 0.9029   1.0200 1.1901 1.2938 1.3407 1.2962 1.0737 0.7450 0.3758 0.1879 0.0000  
        0.0000 0.0968 0.1751 0.2232 0.2548 0.4203 0.5291 0.6392 0.7296 0.8728   0.9843 1.1435 1.2337 1.2648 1.1820 0.9586 0.6595 0.3318 0.1659 0.0000  
        0.0000 0.0964 0.1743 0.2221 0.2533 0.4177 0.5258 0.6353 0.7250 0.8671   0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6441 0.3240 0.1620 0.0000  
        0.0000 0.0964 0.1743 0.2221 0.2533 0.4178 0.5258 0.6353 0.7250 0.8671   0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6441 0.3240 0.1620 0.0000  
        0.0000 0.0965 0.1743 0.2220 0.2532 0.4177 0.5258 0.6353 0.7250 0.8671   0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6441 0.3240 0.1620 0.0000
        0.0000 0.0964 0.1743 0.2221 0.2533 0.4178 0.5258 0.6353 0.7250 0.8671   0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6441 0.3240 0.1620 0.0000  
        0.0000 0.0965 0.1743 0.2220 0.2532 0.4177 0.5258 0.6353 0.7250 0.8671   0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6441 0.3240 0.1620 0.0000  
        0.0000 0.0963 0.1742 0.2221 0.2533 0.4178 0.5258 0.6353 0.7250 0.8671   0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6441 0.3240 0.1620 0.0000  
        0.0000 0.0964 0.1743 0.2220 0.2532 0.4177 0.5258 0.6353 0.7250 0.8671   0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6442 0.3240 0.1620 0.0000  
        0.0000 0.0965 0.1744 0.2221 0.2532 0.4177 0.5258 0.6353 0.7250 0.8671   0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6442 0.3240 0.1620 0.0000  
        0.0000 0.0966 0.1745 0.2220 0.2531 0.4177 0.5258 0.6353 0.7250 0.8671   0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6441 0.3240 0.1620 0.0000  
        0.0000 0.0965 0.1744 0.2221 0.2532 0.4177 0.5258 0.6353 0.7250 0.8671  0.9776 1.1346 1.2223 1.2500 1.1606 0.9378 0.6441 0.3240 0.1620 0.0000 ];
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if NWAFOR>0    
        for j=1:NWAF
            for i=1:NWAFOR
                if mod(i,10)==0
                    fprintf(fid,'%7.3f  WAFORD %i-%i\n',WAFORD(j,i),j,floor(i/10));
                else
                    fprintf(fid,'%7.3f',WAFORD(j,i));
                end
            end
            if mod(NWAFOR,10)~=0
                num2Fill=10-mod(NWAFOR,10);
                for i=1:num2Fill
                    fprintf(fid,'       ');
                end
                fprintf(fid,'  WAFORD %i-%i\n',j,ceil(NWAFOR/10));
            end
        end
    else
        for j=1:NWAF*2
            for i=1:NWAFOR
                if mod(i,10)==0
                    fprintf(fid,'%7.3f  WAFORD %i-%i\n',WAFORD(j,i),floor(j/2+.5),floor(i/10)+mod(j,2));
                else
                    fprintf(fid,'%7.3f',WAFORD(j,i));
                end
            end
            if mod(NWAFOR,10)~=0
                num2Fill=10-mod(NWAFOR,10);
                for i=1:num2Fill
                    fprintf(fid,'       ');
                end
                fprintf(fid,'  WAFORD %i-%i\n',j,ceil(NWAFOR/10));
            end
        end
    end
    
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% 
%                       Fuselage Data Cards
% 
% 
%      If J2 = 0 or 2, no fuselage data is input.  Otherwise, NFUS
% sets of fuselage data are input.  Each set consists of Fuselage
% Station Cards and, depending on the options specified on the
% Geometry Input Control Card, Fuselage Camber Cards, Fuselage Area
% Cards, and/or Fuselage cross section y coordinate and z coordinate
% Cards.  Fuselage segments and stations within each segment must be
% in order of increasing x.
if abs(J2)==1
    % 
    % 
    % Fuselage Station Card(s): Format(10F7.0)   NFORX(I) values are 
    %   input, ten to a card, for the Ith fuselage segment.  
    %   (Identifier = XFUS)
    % 
    %   XFUS(I,J)     x coordinate of the Jth station for the Ith
    %                 fuselage segment
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Enter the x-coordinates for the fuselage cross-sections. The columns correspond 
    % to the station location (with quantity NFORX(I)). The rows correspond to the
    % segments (with number NFUS)
    
    XFUS=[  0.000 11.540 23.080 34.620 46.160 57.701 65.930 69.241 80.781 92.321 103.860 115.400 126.940 138.480 150.020 175.025 200.030 207.930 225.032 250.036 275.039 300.000];
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
        % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Fuselage Camber Card(s): Format(10F7.0)   Input only for circular,
    %   cambered fuselages (J2 = -1, J6 = 0).  NFORX(I) values are 
    %   input, ten to a card, for the Ith fuselage segment.  
    %   (Identifier = ZFUS)
    % 
    %   ZFUS(J,I)     z coordinate of the center of the Jth station of
    %                 the Ith fuselage segment
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    % Enter the z-coordinates for the fuselage cross-sections. The columns correspond 
    % to the station location (with quantity NFORX(I)). The rows correspond to the
    % segments (with number NFUS)
    
    ZFUS=[  0.000  0.295  0.494  0.608  0.648  0.627  0.574  0.553  0.438  0.293 0.129 -0.043 -0.213 -0.369 -0.500 -0.648 -0.518 -0.354  0.001  1.021  2.652  5.000 ];
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% Fuselage Area Card(s): Format(10F7.0)   Input only for circular
%   fuselages (J2 = -1).  NFORX(I) values are input, ten to a card,
%   for the Ith fuselage segment.  (Identifier = FUSARD)
% 
%   FUSARD(J,I)   Cross-sectional area of the Jth station of the Ith
%                 fuselage segment

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Enter the x-coordinates for the fuselage cross-sections. The columns correspond 
    % to the station location (with quantity NFORX(I)). The rows correspond to the
    % segments (with number NFUS)
    
    FUSARD=[   0.00   7.24  23.40  45.78  70.17  91.54 101.74 105.86 111.76 110.78 106.43 102.15  99.90  99.90 101.13 104.05 109.00 105.53  97.92  62.87  22.02   0.00 ];
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    for j=1:NFUS
        for i=1:NFORX(j)
            if mod(i,10)==0
                fprintf(fid,'%7.3f  XFUS %i-%i\n',XFUS(j,i),j,floor(i/10));
            else
                fprintf(fid,'%7.3f',XFUS(j,i));
            end
        end
        if mod(NFORX(j),10)~=0
            num2Fill=10-mod(NFORX(j),10);
            for i=1:num2Fill
                fprintf(fid,'       ');
            end
            fprintf(fid,'  XFUS %i-%i\n',j,ceil(NFORX(j)/10));
        end
        
       if J2==-1 & J6==0
            for i=1:NFORX(j)
                if mod(i,10)==0
                    fprintf(fid,'%7.3f  ZFUS %i-%i\n',ZFUS(j,i),j,floor(i/10));
                else
                    fprintf(fid,'%7.3f',ZFUS(j,i));
                end
            end
            if mod(NFORX(j),10)~=0
                num2Fill=10-mod(NFORX(j),10);
                for i=1:num2Fill
                    fprintf(fid,'       ');
                end
                fprintf(fid,'  ZFUS %i-%i\n',j,ceil(NFORX(j)/10));
            end
        end
   
    

    if J2==-1

   
        for i=1:NFORX(j)
            if mod(i,10)==0
                fprintf(fid,'%7.2f  FUSARD %i-%i\n',FUSARD(j,i),j,floor(i/10));
            else
                fprintf(fid,'%7.2f',FUSARD(j,i));
            end
        end
        if mod(NFORX(j),10)~=0
            num2Fill=10-mod(NFORX(j),10);
            for i=1:num2Fill
                fprintf(fid,'       ');
            end
            fprintf(fid,'  FUSARD %i-%i\n',j,ceil(NFORX(j)/10));
        end
    end
    
end
    
    
end
    
    % 


end
% 
% 
% Fuselage Coordinate Card(s): Format(10F7.0)  Input only for
%   arbitrary cross section fuselages (J2 = 1).  NRADX(I) values are
%   input, ten to a card, for the y coordinate followed by NRADX(I)
%   values for the z coordinate for the points defining a
%   half-section of the Jth station of the Ith fuselage segment.
%   The z coordinates are started on a new card.  The points are
%   ordered from bottom to top.  (Identifiers = Y and Z)
% 
%   Y(K,J,I)      y coordinate of the Kth point defining the Jth
%                 station of the Ith fuselage segment
% 
%   Z(K,J,I)      z coordinate of the Kth point defining the Jth
%                 station of the Ith fuselage segment
% 
% 
if J2==1
end

% 
%                     Pod (Nacelle) Data Cards 
% 
% 
%      If J3 = 0 or 2, no pod data is input.  Otherwise, NP sets of
% cards are input, one for each pod defined.  Each set consists of a
% Pod Location Card and Pod Station and Radius Cards.  Pods are
% located symmetrically, i.e., unless the y coordinate is 0., a
% mirror image at -y is asssumed.  If y = 0., a single pod on the
% configuration centerline is defined.
% 
if J3==1
    % 
    % Pod (Nacelle) Location Card: Format(3F7.0)  One card is input
    %   in each set defining the pod location.  (Identifier = PODORG)
    % 
    %   Columns       Description
    % 
    %     1- 7        x coordinate of the origin of the Ith pod
    % 
    %     8-14        y coordinate of the origin of the Ith pod
    % 
    %    15-21        z coordinate of the origin of the Ith pod
    % 
    % 
    % Pod (Nacelle) Station Card(s): Format(10F7.0)   NPODOR values are 
    %   input, ten to a card, for the pod currently being defined.
    %   (Identifier = XPOD)
    % 
    %   XPOD(I,J)     X location of the Jth station for the Ith pod
    %                 referenced to the pod origin, i. e., the first
    %                 value must be zero, and the last value is the
    %                 length of the pod.
    % 
    % 
    % Pod (Nacelle) Radius Card(s): Format(10F7.0)   NPODOR values are 
    %   input, ten to a card, for the pod currently being defined.
    %   (Identifier = PODR)
    % 
    %   PODR(I,J)     Pod radius at the Jth station of the Ith pod
    % 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % For each pod, make a new row in the following arrays. PODORG gives
    % the locations of each pod, first collumn x coord. second y, third z.
    % XPOD gives the station values where pod radii will be input. The number of
    % stations equils NPODOR input above. Finally PODR are the pod radii, again
    % with NPODOR inputs.
    
    PODORG=[189.000 17.787 -8.300     
        189.000 32.074 -8.300
        189.000 17.787 -8.300 
        189.000 32.074 -8.300   ];%
    XPOD=[0.000  3.631  7.262 10.783 14.303 17.579 20.855 24.021 27.186
        0.000  3.631  7.262 10.783 14.303 17.579 20.855 24.021 27.186 
        0.000  2.523  5.000  7.373  9.700 12.000 14.303 16.615 18.930
        0.000  2.523  5.000  7.373  9.700 12.000 14.303 16.615 18.930 ];
    PODR=[ 2.129  2.218  2.308  2.349  2.391  2.384  2.377  2.323  2.268  
        2.129  2.218  2.308  2.349  2.391  2.384  2.377  2.323  2.268  
        0.000  0.360  0.554  0.738  0.815  0.733  0.592  0.417  0.000 
        0.000  0.378  0.565  0.733  0.855  0.810  0.637  0.434  0.000 ];
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    for j=1:NP
        fprintf(fid,'%7.3f%7.3f%7.3f                                                   PODORG %i\n',PODORG(j,1),PODORG(j,2),PODORG(j,3),j);
        for i=1:NPODOR
            if mod(i,10)==0
                fprintf(fid,'%7.3f  XPOD %i-%i\n',XPOD(j,i),j,floor(i/10));
            else
                fprintf(fid,'%7.3f',XPOD(j,i));
            end
        end
        if mod(NPODOR,10)~=0
            num2Fill=10-mod(NPODOR,10);
            for i=1:num2Fill
                fprintf(fid,'       ');
            end
            fprintf(fid,'  XPOD %i-%i\n',j,ceil(NPODOR/10));
        end
        for i=1:NPODOR
            if mod(i,10)==0
                fprintf(fid,'%7.3f  PORD %i-%i\n',PODR(j,i),j,floor(i/10));
            else
                fprintf(fid,'%7.3f',PODR(j,i));
            end
        end
        if mod(NPODOR,10)~=0
            num2Fill=10-mod(NPODOR,10);
            for i=1:num2Fill
                fprintf(fid,'       ');
            end
            fprintf(fid,'  PORD %i-%i\n',j,ceil(NPODOR/10));
        end
    end
    
    
end
% 
% 
if J4==1
    %                   Fin (Vertical Tail) Data Cards 
    % 
    % 
    %      If J4 = 0 or 2, no fin data is input.  Otherwise, NF sets of
    % cards are input, one for each fin defined.  Each set consists of a
    % Fin Planform Card, a Fin Percent Chord Location Card, and Fin
    % Airfoil Ordinate Card(s).  Fins are located symmetrically, i.e.,
    % unless the y coordinates are 0., a mirror image at -y is asssumed.
    % If y = 0., a single vertical tail on the configuration centerline
    % is defined.
    % 
    % 
    % Fin (Vertical Tail) Planform Card: Format(3F7.0)  One card is
    %   input in each set defining the fin location and planform.
    %   (Identifier = FINORG)
    % 
    %   Columns       Description
    % 
    %     1- 7        x coordinate of the lower airfoil leading edge
    % 
    %     8-14        y coordinate of the lower airfoil leading edge
    % 
    %    15-21        z coordinate of the lower airfoil leading edge
    % 
    %    22-28        Chord length of the lower airfoil
    % 
    %    29-35        x coordinate of the upper airfoil leading edge
    % 
    %    36-42        y coordinate of the upper airfoil leading edge
    % 
    %    43-49        z coordinate of the upper airfoil leading edge
    % 
    %    50-56        Chord length of the upper airfoil
    % 
    % 
    % Fin (Vertical Tail) Percent Chord Location Card: Format(10F7.0)
    %   NFINOR values are input.  (Identifier = XFIN)
    % 
    %   XFIN(I,J)     Locations in percent chord ((x/c)*100) at which
    %                 the airfoil ordinates of the Ith fin are to be
    %                 specified.
    % 
    % 
    % Fin (Vertical Tail) Airfoil Ordinate Card(s): Format(10F7.0)
    %   NFINOR values are input.  If NF < 0, the fin airfoil is not
    %   symmetric with respect to the inclined plane defined on the Fin
    %   Planform Card and two sets of ordinates are input, the distance
    %   from the inclined plane to the outboard surface followed by the
    %   distance from the inboard surface to the inclined plane.  Both
    %   are expressed as percent chord as described below.
    %   (Identifier = FINORD)
    % 
    %   FINORD(I,J)   Airfoil half-thickness ordinates of the Ith fin,
    %                 expressed as percent chord (100 * (t/c) / 2).
    % 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % For each fin (vertical tail), make a new row in the following arrays. 
    %FINORG gives the locations of each fin, with the first collumn x coord. of lower leading edge, 
    % second y of lower LE, third z of lower LE, fourth chord length of lower airfoil,
    % fifth x coord. of upper leading edge, sixth y of upper LE, seventh z of upper LE,
    % eigth chord length of upper airfoil.
    %
    %XFIN gives the station values where fin airfoil half-thickness ordinates
    % are given with NFINOR inputs.
    %FINORD gives the fin half-thicknesses, again with NFINOR inputs.
    % 
    
    FINORG=[245.450  0.000  3.000 44.098   274.907  0.000 20.008  8.820 ];
    XFIN=[0.00   0.50   1.00   5.00  10.00  25.00  50.00  75.00  95.00 100.00];
    FINORD=[   0.00   0.20   0.29   0.58   0.80   1.15   1.19   0.67   0.14   0.00];
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    for j=1:NF
        fprintf(fid,'%7.3f%7.3f%7.3f%7.3f%7.3f%7.3f%7.3f%7.3f                FINORG %i\n',FINORG(j,1),FINORG(j,2),FINORG(j,3),FINORG(j,4),FINORG(j,5),FINORG(j,6),FINORG(j,7),FINORG(j,8),j);
        for i=1:NFINOR
            if mod(i,10)==0
                fprintf(fid,'%7.2f  XFIN %i-%i\n',XFIN(j,i),j,floor(i/10));
            else
                fprintf(fid,'%7.2f',XFIN(j,i));
            end
        end
        if mod(NFINOR,10)~=0
            num2Fill=10-mod(NFINOR,10);
            for i=1:num2Fill
                fprintf(fid,'       ');
            end
            fprintf(fid,'  XFIN %i-%i\n',j,ceil(NFINOR/10));
        end
        for i=1:NFINOR
            if mod(i,10)==0
                fprintf(fid,'%7.2f  FINORD %i-%i\n',FINORD(j,i),j,floor(i/10));
            else
                fprintf(fid,'%7.2f',FINORD(j,i));
            end
        end
        if mod(NFINOR,10)~=0
            num2Fill=10-mod(NFINOR,10);
            for i=1:num2Fill
                fprintf(fid,'       ');
            end
            fprintf(fid,'  FINORD %i-%i\n',j,ceil(NFINOR/10));
        end
    end
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                Canard (Horizontal Tail) Data Cards 
% 
% 
%      If J5 = 0 or 2, no canard data is input.  Otherwise, NCAN
% sets of cards are input, one for each canard or horizontal tail
% defined.  Each set consists of a Canard Planform Card, a Canard
% Percent Chord Location Card, and Canard Airfoil Ordinate Card(s).
% 
if J5==1
    % 
    % Canard (Horizontal Tail) Planform Card: Format(3F7.0)  One card is
    %   input in each set defining the canard location and planform.
    %   (Identifier = CANORG)
    % 
    %   Columns       Description
    % 
    %     1- 7        x coordinate of the inboard airfoil leading edge
    % 
    %     8-14        y coordinate of the inboard airfoil leading edge
    % 
    %    15-21        z coordinate of the inboard airfoil leading edge
    % 
    %    22-28        Chord length of the inboard airfoil
    % 
    %    29-35        x coordinate of the outboard airfoil leading edge
    % 
    %    36-42        y coordinate of the outboard airfoil leading edge
    % 
    %    43-49        z coordinate of the outboard airfoil leading edge
    % 
    %    50-56        Chord length of the outboard airfoil
    % 
    % 
    % Canard (Horizontal Tail) Percent Chord Location Card:
    %   Format(10F7.0)  NCANOR values are input.  (Identifier = XCAN)
    % 
    %   XCAN(I,J)     Locations in percent chord ((x/c)*100) at which
    %                 the airfoil ordinates of the Ith canard are to be
    %                 specified.
    % 
    % 
    % Canard (Horizontal Tail) Airfoil Ordinate Card(s): Format(10F7.0)
    %   NCANOR values are input.  If NCAN < 0, the outboard canard
    %   airfoil is different from the inboard airfoil, and two sets of
    %   ordinates are input, inboard airfoil data followed (starting on
    %   a new card) by outboard airfoil data.  If NCANOR < 0, the canard
    %   airfoil is not symmetric with respect to the inclined plane
    %   defined on the Canard Planform Card and two sets of ordinates
    %   are input, the distance from the inclined plane to the upper
    %   surface followed by the distance from the lower surface to the
    %   inclined plane.  If both NCAN < 0 and NCANOR < 0, four sets of
    %   ordinates are required in the following order: inboard upper
    %   surface, outboard upper surface, inboard lower surface, and
    %   outboard lower surface.  Each set is started on a new card.
    %   (Identifier = CANORD)
    % 
    %   CANORD(I,J)   Airfoil half-thickness ordinates of the Ith canard,
    %                 expressed as percent chord (100 * (t/c) / 2).
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    % For each canard (horizontal tail), make a new row in the following arrays. 
    %CANORG gives the locations of each canard, with the first collumn x coord. of inboard leading edge, 
    % second y of inboard LE, third z of inboard LE, fourth chord length of inboard airfoil,
    % fifth x coord. of outboard leading edge, sixth y of outboard LE, seventh z of outboard LE,
    % eigth chord length of outboard airfoil.
    %
    %XCAN gives the station values where canard airfoil half-thickness ordinates
    % are given with NCANOR inputs.
    %CANORD gives the canard half-thicknesses, again with NCANOR inputs.
    
    CANORG=[245.450  0.000  0 44.098   274.907  20.000 0  8.820 ];
    
    XCAN=[0.00   0.50   1.00   5.00  10.00  25.00  50.00  75.00  95.00 100.00];
    
    CANORD=[ 0.00   0.20   0.29   0.58   0.80   1.15   1.19   0.67   0.14   0.00];
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    for j=1:NCAN
        fprintf(fid,'%7.3f%7.3f%7.3f%7.3f%7.3f%7.3f%7.3f%7.3f                CANORG %i\n',CANORG(j,1),CANORG(j,2),CANORG(j,3),CANORG(j,4),CANORG(j,5),CANORG(j,6),CANORG(j,7),CANORG(j,8),j);
        for i=1:NCANOR
            if mod(i,10)==0
                fprintf(fid,'%7.2f  XCAN %i-%i\n',XCAN(j,i),j,floor(i/10));
            else
                fprintf(fid,'%7.2f',XCAN(j,i));
            end
        end
        if mod(NCANOR,10)~=0
            num2Fill=10-mod(NCANOR,10);
            for i=1:num2Fill
                fprintf(fid,'       ');
            end
            fprintf(fid,'  XCAN %i-%i\n',j,ceil(NCANOR/10));
        end
        for i=1:NCANOR
            if mod(i,10)==0
                fprintf(fid,'%7.2f  CANORD %i-%i\n',CANORD(j,i),j,floor(i/10));
            else
                fprintf(fid,'%7.2f',CANORD(j,i));
            end
        end
        if mod(NCANOR,10)~=0
            num2Fill=10-mod(NCANOR,10);
            for i=1:num2Fill
                fprintf(fid,'       ');
            end
            fprintf(fid,'  CANORR %i-%i\n',j,ceil(NCANOR/10));
        end
    end
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
%                      Case Definition Input Data
% 
% 
% Case Control Card: Format(A4,11I4)  Integer input must be right
%   justified in the indicated 4-column field.  As many Case Control
%   Cards as desired may be input.  If NREST > 0, the Case Control
%   Card is followed by a Restraint Card, but only one Restraint
%   Card may be input per configuration.
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Enter the case descriptions for each of the variables described below.
% make a new row for each case in the arrays given.
%  Variable                    Description
% 
NCASE=['M2.0'  %           Case number or other 4 character descriptor
    'M1.6'
    'M1.2'
    'BOOM']; 
% 
MACH=[2000  %             Mach number * 1000
    1600
    1200
    1000 ];    
NX= [60               %     Number of intervals on x axis
    60
    60
    60];
% 
NTHETA =[16  %              Number of thetas
    16
    16
    16];
JRST=[1      %          Equivalent body data control= 0, Compute equivalent body areas, drags etc.
    1     %                        = 1, Perform minimum calculations required for
    1    %                             wave drag (saves ~25% execution time)
    1];


IALPH =[0             %Angle of attack x 100
    0
    0
    0];   

for i=1:length(NCASE)
    fprintf(fid,'%4s%4i%4i%4i                %4i%4i                                CASE %i\n',NCASE(i,:),MACH(i),NX(i),NTHETA(i),JRST(i),IALPH(i),i);
end

disp('File write successful')
fclose(fid);