!
!  NeXtMidas macro for converting a text file
!    of lat/lon/alt to a type 3000 file (cities.prm) and then
!    performing a HEADERMOD so data can be easily plotted in a
!    GEO plot (plot <file> view=geo).
!
!    ALT (all values currently ZERO)                 (float, F4.2)
!    LAT (Latitiude; degrees)                        (float, F10.6)
!    LON (Longitude; degrees)                        (float, F12.7)
!    CITY (City Name; text)                          (ascii, a32)
!
!
startmacro FN:outfile[cities.tmp] FN:infile[nxm.sys.dat.cities.txt]

call setDatDir
invoke infile infile.replace("nxm.sys.dat",^{datDir});

say "Converting {^infile} to MIDAS Type 3000 file ^{outfile}"
say ""

! CONVERT the text file cities.txt to a MIDAS BLUE Type 3000 file
! Use the defined formatting
!  4-CHAR. DOUBLE
!  2 SPACES
!  10-CHAR. DOUBLE
!  4 SPACES
!  12-CHAR. DOUBLE
!  1 SPACE
!  32-CHAR. ASCII
!
! Skipping the first three lines of the file which contain header information
!  NOTE:  Fields are of fixed length.  This means that numeric valuies must be padded
!         with ZEROS (3.140000 = d8) and ASCII values must be padded with spaces ("nxm     " = a8)
!
!NTN ORIG (using a8) convert cities.txt t2b cities d4|2x|d10|4x|d12|1x|a8 3
convert infile t2b outfile d4|2x|d10|4x|d12|1x|a32 3

! LIST the TYPE 3000 file created
list outfile

! Perform a HEADERMOD on the Type 3000 cities file to "convert" it
!  to a TYPE 5010 file
!  Specify:
!   New file type        : TY=5010
!   Frame-of-Reference   : Earth Centered Reference (fr=ecr)
!   Number of Components : nc=2
!   Component One        : (NAME=pos,  FORMAT=Vector Double, TYPE=GEODETIC, UNITS=DISTANCE)
!   Component Two        : (NAME=name, FORMAT=ASCII, TYPE=none, UNITS=none)
!    Definitions of Component TYPE and UNITS are as follows:
!     - TYPE is the numeric component_type code
!       --  0 = UNDEFINED
!       --  1 = SCALAR
!       --  2 = CARTESIAN
!       --  3 = SPHERICAL
!       --  4 = CYLINDRIC
!       --  5 = ELLIPSOID
!       --  6 = GEODETIC
!       -- 10 = MATRIX
!     - UNITS is the numeric units code
!       --  0 = NONE
!       --  1 = TIME
!       --  2 = DELAY
!       --  3 = FREQUENCY
!       --  4 = TIMECODE
!       --  5 = DISTANCE
!       --  6 = SPEED
!       --  7 = ACCELERATION
!       -- 61 = LATITUDE
!       -- 62 = LONGITUDE
!       -- 63 = LONGITUDE_FT
!       -- 64 = ALTITUDE
!
!NTN ORIG headermod cities type=5010 fr=ecr nc=2 c(1)=(pos,vd,6,5) c(2)=(name,1a,0,0)
! changed fr=ecr to rf=ecr and c(2)=(name,1a,0,0) to c(2)=(name,4a,0,0)
headermod outfile type=5010 rf=ecr nc=2 c(1)=(pos,vd,6,5) c(2)=(name,4a,0,0)

! Get the STATISTICS on the Type 5010 file created
status outfile

! DATALIST the Type 5010 file created
datalist outfile

! PLOT the outfile on the world in a GEODETIC view
plot world|outfile view=geo

endmacro

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
