!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
program gen_to_grid
!
! Description:
!
! This is a belated attempt to automate what has hitherto been done one line
! segment at a time to turn a finely discretized capsule generatrix, containing
! a number of critical points such as shoulder step corners that need to be
! preserved into a computational surface grid form of the geometry. The curv-
! ature-based redistribution of CAPSULE_GRID can easily be thwarted by such
! geometric features. A common example is the need to split the generatrix at
! the top of a shoulder seal step. That corner marks the end of the forebody
! part of the generatrix and the beginning of the aft body part. Since these
! two parts are usually gridded separately, the step corner is not seen and is
! thus not clustered as it needs to be. Capturing of a parachute lid corner is
! another example.
!
! The CAPSULE_GRID work-around is to provide it with a generatrix that is
! discretized in the desired surface grid form and will be retained exactly
! through appropriate choice of the ni_forebody and ni_aft_body control inputs.
! This ancillary utility is intended to simplify preparation of that carefully
! discretized form of the generatrix, undoubtedly through trial and error.
!
! Strategy:
!
! A control table scheme is employed. The first two table columns contain
! the (x,y) coordinates of all critical points to be preserved exactly. The
! further columns contain the type of point distribution for each line segment,
! the desired number of points, and first and last arc-length increments that
! may or may not be used, depending on the distribution type.
!
! Sample Input:
!
! Enter the control table as the first command line argument (not on stdin).
! Following the header lines, the table needs to be numeric and complete, so
! unused entries on the last line are entered as 99 to indicate "irrelevant."
! The critical points are expected to be ordered nose to tail.
!
! RevB.generatrix.tecplot.dat
! -1 = high-end clustering (ds2); 0 = uniform; 1 = low-end clustering (ds1)
! 2 = 2-sided clustering (ds1 and ds2);
! 3 = curv.-based redistribution; ds1, ds2 = power, ismooth = 0.5, -3 say;
! 4 = redistribute with same relative distrib. as the following file(s).
! x y type npts ds1 ds2
! 0. 0. 3 199 0.5 -3
! 0.91790681 2.31206956 2 31 6.57237E-03 0.001
! 0.9967 2.280235 2 7 0.001 0.001
! 0.9967 2.2730 2 251 0.001 0.0015
! 2.5759 1.292678 2 29 0.0015 0.003
! 2.66407 1.17542 2 127 0.003 0.015
! 3.816567 0.43700926 2 52 0.015 9.77421E-03
! 3.892025 0.087901 0 10 99 99
! 3.895 0.0 99 99 99 99
!
! The initial generatrix data are expected to be in the file on line 1. It
! may include optional header lines. Any third column of (zero?) z coordinates
! is ignored. Once the table has been prepared, the (x,y) columns of critical
! points should be extracted and plotted as symbols on the generatrix curve.
! These critical points will replace the nearest points within the generatrix
! data, from which each line segment is drawn for redistribution according to
! the specs. on the first line of a pair of critical point control lines.
!
! The example does not include a type 4 segment, but if it did, the name
! of the file containing the desired relative distribution would appear below
! the 4 = ... header line. Any further type 4 file names would follow in order.
! Any such files should omit header lines and include a third column of z
! coordinates (most likely zeros). E.g.,
!
! nose-xyz-given.dat
! -1 = high-end clustering (ds2); 0 = uniform; 1 = low-end clustering (ds1);
! 2 = 2-sided clustering (ds1 and ds2);
! 3 = curvature-based redistrib.; ds1, ds2 = power, ismooth = 0.5, -3 say;
! 4 = redistribute with same relative distrib. as the following file(s).
! RevB.111.fore.dat
! x y type npts ds1 ds2
! 0. 0. 4 229 99 99
! 9.9670000E-01 2.285189859737330e+00 99 99 99 99
!
! Note that, because of the way the earlier 3-space utility MORPH_LINE_SEGMENT
! was remodularized, the user here is prompted for any type 4 files containing
! desired relative point distributions. Cut and paste RevB.111.fore.dat in this
! example.
!
! Output:
!
! The output gridded form of the generatrix is named surface_grid_xy.dat
! or surface_grid_xyz.dat depending on a prompt for whether to include a z = 0.
! column as expected by the Hypgen volume-gridding scheme.
!
! History:
!
! 06/01/2023 D.A.Saunders Initial design.
! 06/07/2023 " " Completion of initial implementation & testing.
! 06/08/2023 " " The curvdis2 option needs two more controls.
! Make use of the unused ds1, ds2 inputs.
! 0.5 and -3 are recommended for the forebody of
! a typical sphere/cone.
! 10/31/2023 " " Rude surprise for Halloween: Kaelan Hansson
! found that gfortran does not support getarg,
! advising that Fortran 2003 and later provides
! this similar intrinsic:
! get_command_argument (number [, value, length,
! status]) instead.
! 11/19/2023 " " Retrofitted the type 4 option to impose the
! relative distribution of an indicated segment.
! Any reasonable point count may be specified.
! 04/27/2024 " " Since the Hypgen script expects three-column
! xyz input, provide for including z = 0. in the
! output (or not).
!
! Author: David Saunders, AMA, Inc. at NASA Ames Research Center, CA.
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!