/* @(#) amlname: ld_post92_tl.aml
/* @(#)
/* @(#) creation date:  December 1993
/* @(#) modifications:  thru July 1994
/* @(#)            by:  Carol Brandt
/* @(#)                 Randy Fusaro September 1994 (formerly postal version)
/* @(#)                 C Brandt October 1994
/* @(#)
/* @(#) This .aml was created for the task of loading all of the 
/* @(#) postal version TIGER/Line files into ARC/INFO format.  
/* @(#) Additions include creating templates to load RTF, RTG, and
/* @(#) RTZ.  Modifications made for the Post Postal TIGER/Line files include 
/* @(#) Eliminating RTF and RTG, and creating RT9, RTS, RTH, and RTC. RTs 1 and 3
/* @(#) Must be altered in info.  The field lengths have remained the same (for the
/* @(#) most part), but field items have changed.
/* @(#)
/*      TIGER/Line is a trademark of the U.S. Bureau of the Census
/*
/*      Developed by staff in the Geographic Base Development Branch
/*                                Geography Division
/*                                U.S. Bureau of the Census
/*                                Washington, D.C. 20233
/*                                (301) 763-4664
/*
/*      Please note:  the TIGER/Line file must be named using a
/*      specific format.  The format for acceptance by ARC INFO 
/*      requires that the record type be the last character of
/*      the file name ie: tgr12345.rt1, tgr12345.rt2, etc.  Also,
/*      ARC INFO does not accept a number as the first character of
/*      the file name, so, at a minimun, the inout file name should have
/*      a character, the state/county code and the record type:
/*      f123451, f123452, etc.
/*
/*      this aml will take a TIGER/Line file and run it through
/*      the TIGERTOOL command then relate the .PCODE file with 
/*      the .PAT, relate the .ACODE file with the .AAT,
/*      JOIN the .PCODE with the .PAT, and JOIN the .ACODE with
/*      the .AAT
/*
/*      TIGERTOOL automatically adds a number (1, 2, or 3) after the
/*      coverage name prefix.  The cover1 is comprised of the feature
/*      network and the polygon coverage.  cover2 is the output point
/*      coverage.  cover3 is the POINT landmark coverage. 
/*
/*      This aml joins the information from Record Type A
/*      to the output point coverage (cover2).
/*
/*      The information from the Record Type I is joined
/*      to the point lankmark coverage (cover3)
/*
/*      this aml assumes it is run in the same directory where the
/*      file is located, or that the full directory/path name is
/*      used when running this aml
/*
/*      RTZ was created as an INFO data file to
/*      RELATE with the line coverage.  The aml adds to the
/*      standard RELATE file (cover.rel) created by TIGERTOOL 
/*      to accommodate these data files.  However, the name of
/*      the INFO RELATE file is changed to cover1.rel to allow
/*      its inclusion in the export process.  
/*
/*      ESRI sez that one should NEVER join the .AAT and the .ACODE
/*      files.  We have found updating the file much easier with the
/*      attributes joined.  However, the user must be careful if the 
/*      files are joined:
/*              1) the geocoding module uses the .acode file - if you
/*                 decide to join the .aat and the .acode you MUST
/*                 recreate the .acode from the .aat prior to using the 
/*                 geocoding module
/*              2) the ARCTIGER command uses the .acode file - you MUST
/*                 recreate the .acode file prior to converting your
/*                 arc coverage back into TIGER/Line format
/*
/*      Staff in the Geographic Base Development Branch have
/*      created an .aml to recreate the .acode file.
/*
/*      Global Variables:       cover - the output coverage prefix 
/*                              in_file - the input file prefix
/*                              pathname - path to raw TIGER/Line files
/*
/* @(#) Three arguments are required to run this aml.
/* @(#)       argument one: the TIGER/Line filename prefix
/* @(#)       argument two: the output cover name prefix (cannot begin with numeral)
/* @(#)       argument three : the pathname where TIGER/Line files reside
/* @(#)
/* @(#) Example:   &r ld_post92_tl tgr24005.p1 balt /cdrom/24/005/
/*
&ARGS .in_file .cover .pathname
/*
&messages &on
&severity &warning &fail
&severity &error &fail
/*
/*      check for arguments - if no arguments, return appropriate mesage
/*
&if [null %.in_file%] &then  
    &return &warning usage: ~ 
ld_post92_tl <in file prefix> <out file prefix> <TIGER/Line pathname> 
/*
&if [null %.cover%] &then
    &return &warning usage: ~
ld_post92_tl <in file prefix> <out file prefix> <TIGER/Line pathname>
/*
&if [null %.pathname%] &then 
    &return &warning usage: ~
ld_post92_tl <in file prefix> <out file prefix> <TIGER/Line pathname>
/*
/*
/*      first, take the raw TIGER files and run them through
/*      the TIGERTOOL command to create coverages
/*
&sys date
&type
&type Beginning TIGERTOOL Process
&type
/*
TIGERTOOL %.pathname%%.in_file% %.cover%
/*
&type
&type TIGERTOOL Completed
&type
/*
/*      in INFO, get the cover and sort the .PCODE file into
/*      cover-id order.  relate the .PCODE file to the .PAT and
/*      put CENPOLID into the .PAT
/*
/*      make sure upper case characters are used for INFO
/*
&set .in_file = [Translate %.in_file%]
&set .cover = [Translate %.cover%]
/*
&DATA ARC INFO
ARC
SELECT %.cover%1.PCODE
SORT ON %.cover%1-ID
SELECT %.cover%1.PAT
RELATE %.cover%1.PCODE BY %.cover%1-ID ORDERED NUMERIC
CALC CENID = $1CENID
CALC POLYID = $1POLYID
CALC CENPOLID = CENPOLID
QUIT STOP
&END
/*
/*      once the .PAT has a CENPOLID, join the .PCODE file
/*      with the .PAT to get all those attributes into the 
/*      .PAT - rather than having to fool with messy RELATES
/*      use the cover-id field as the link.
/*
/*      also, JOIN the .AAT file with the .ACODE file to get the 
/*      line attributes into the .AAT - also, so one does not have
/*      to fool with those messy RELATES
/*      then, rebuild the cover using the polygon option. 
/*
JOINITEM %.cover%1.PAT %.cover%1.PCODE %.cover%1.PAT %.cover%1-ID CENPOLID ORDERED
JOINITEM %.cover%1.AAT %.cover%1.ACODE %.cover%1.AAT RECNUM RECNUM ORDERED
CREATELABELS %.cover%1
BUILD %.cover%1 POLY
/*
/*      use INFO again to redefine CTBNA and BLK into a combined field.
/*      use this combined field in later processes to link to other
/*      data files
/*
&DATA ARC INFO
ARC
SELECT %.cover%1.PAT
REDEFINE
75, TR_BLK, 10, 10, C
82, H2O_BLK, 2, 2, I

MOVEITEM TR_BLK TO TR_BLK
REM
SEL %.cover%1.AAT
REDEFINE
50, NAME, 38, 38, C
91, LEFTADDRESSES, 22, 22, C
113, RGTADDRESSES, 22, 22, C
142, ZIPL_SYM, 2, 2, I
147, ZIPR_SYM, 2 ,2, I

QUIT STOP 
&END
/*
/*      get the information from the Record Type A file and
/*      join it with the point coverage: cover2.PAT
/*
JOINITEM %.cover%2.PAT %.cover%2.TYPEA %.cover%2.PAT CENPOLID CENPOLID ORDERED
BUILD %.cover%2 POINT
/*
/*      join the landmark information with the landmark 
/*      point cover: cover3.PAT 
/*
JOINITEM %.cover%3.PAT %.cover%3.XCODE %.cover%3.PAT %.cover%3-ID %.cover%3-ID ORDERED
BUILD %.cover%3 POINT
/*
/*      Join the point coverage (cover2.PAT) information with the 
/*      line and area coverage (cover1.PAT) to add polygon attribute
/*      information to the forst coverage.  This adds Congressional
/*      District information to the polygons from the points
/*
JOINITEM %.cover%1.PAT %.cover%2.PAT %.cover%1.PAT CENPOLID BLK ORDERED
/*
/*      The following process takes as long to complete as the loading
/*      of the TIGER/Line file (if not longer).  The whole process is
/*      commented out for this reason.  I continue to look for a
/*      faster/better way to accomplish this task.  However, adding
/*      the ZIP Code to polygons is not correct anyway.  ZIP Code
/*      is a feature network attribute.  This process adds the first
/*      ZIP Code encountered to the polygon.  It does not take a
/*      majority ZIP if more than a single ZIP is attached to the
/*      polygon (introducing inaccuracies).
/*      I neglected to take out the ADDITEM here on purpose (in case 
/*      I get to it or if someone else wants to have this long
/*      process run during the load).  Also, a later ADDITEM adds a 
/*      field AFTER the ZIP field.
/*
/*      Add the five-digit ZIP Code to the polygon cover
/*
ADDITEM %.cover%1.PAT %.cover%1.PAT ZIP 5 5 I # URBFLAG
/*
/*   &DATA ARC INFO
/*   ARC
/*   SEL %.cover%1.PAT
/*   REDEFINE
/*   17,LPOLY#,4,5,B
/*   17,RPOLY#,4,5,B
/*
/*   RELATE %.cover%1.AAT 1 BY LPOLY#
/*   CALC ZIP = $1ZIPL
/*   REM
/*   SEL %.cover%1.PAT
/*   RESEL ZIP = 0
/*   RELATE %.cover%1.AAT BY RPOLY#
/*   CALC ZIP = ZIPR
/*   REM
/*   Q STOP
/*   &END
/*
/*      the TIGERTOOL process runs a frequency on the 
/*      TIGER/Line ID (Record Number) to verify that there are
/*      no duplicate IDs.  Any errors of this type are stored 
/*      in the %.cover%1.DUPS INFO file.
/*      the TIGERTOOL process also runs a frequency on the 
/*      polygon IDs.  Any errors of this type are stored in
/*      the %.cover%1.ERRORS INFO file.
/*      the following data block will delete these two INFO files
/*      if they contain no records (no errors).
/*      AT THIS POINT IN TIME, THE FOLLOWING DELETES THE FILES
/*      IT DOES NOT TAKE THE CONTENTS INTO ACCOUNT
/*
/*&DATA ARC INFO
/*ARC
/*SELECT %.cover%1.ERROR
/*IF $NOSEL = 0
/*DELETE %.cover%1.ERROR
/*Y
/*REM
/*SELECT %.cover%1.DUPS
/*IF $NOSEL = 0 
/*DELETE %.cover%1.DUPS
/*Y
/*REM
/*QUIT STOP
/*&END
/*
/*      Add the CFCC and Landmark Name from the INFO file
/*      %.cover%3.TYPE8 to the feature network/polygon covereage
/*      (%.cover%1)
/*      the following adds the CFCC and Landmark Name fields to
/*      the %.cover%1.PAT
/*      then, it relates the INFO file %.cover%3.TYPE8 with
/*      the %.cover%1.PAT
/*
ADDITEM %.cover%1.PAT %.cover%1.PAT CFCC 3 3 C # ZIP
ADDITEM %.cover%1.PAT %.cover%1.PAT LANAME 30 30 C # CFCC
/*
&DATA ARC INFO
ARC
SEL %.cover%1.PAT
RELATE %.cover%3.TYPE8 1 BY CENPOLID ORDERED
RESEL CENPOLID = $1CENPOLID
REM
MOVEITEM $1CFCC TO CFCC
MOVEITEM $1LANAME TO LANAME
REM
Q STOP
&END
/*
/*      Now that the CFCC and Landmark Names are in the polygon
/*      cover, look at the water blocks (CFCC = *99*).  Where there
/*      was no landmark, code these water blocks as 'H00'.  Additionally,
/*      so we know these were not in RT7 and RT8, enter 'Water'
/*      to the LANAME field.
/* 
&DATA ARC INFO 
ARC
SEL %.cover%1.PAT
RESEL H2O_BLK = 99
RESEL CFCC CN '   '
MOVEITEM 'H00' TO CFCC
MOVEITEM 'Water' TO LANAME
REM
Q STOP
&END
/*
/*      Run frequencies on the polygon and linear coverages based
/*      on the CFCC.  Add SYMBOL to each of the frequency INFO files
/*      created, and code the symbol field based on the CFCC.  Then,
/*      the user can use one command to draw the coverage using
/*      color symbology.
/*      In ARCPLOT
/*      For lines, use:  arclines %.cover%1 cfcc %.cover%1_line_cfcc.freq
/*      For polys, use: polygonshades %.cover%1 cfcc %.cover%1_poly_cfcc.freq
/*
FREQUENCY %.cover%1.AAT %.cover%1_LINE_CFCC.FREQ CF#
CFCC
END
END

FREQUENCY %.cover%1.PAT  %.cover%1_POLY_CFCC.FREQ CF#
CFCC 
END 
END

ADDITEM %.cover%1_LINE_CFCC.FREQ %.cover%1_LINE_CFCC.FREQ SYMBOL 3 3 I # CFCC
ADDITEM %.cover%1_POLY_CFCC.FREQ %.cover%1_POLY_CFCC.FREQ SYMBOL 3 3 I # CFCC
/*
/*      the following linecolors are set based on lineset color
/*      the polygon colors are set based on shadeset colornames
/*      
/*      to display the polygons in different colors based on the
/*      cfcc, use: POLYGONSHADES %.cover%1 CFCC %.cover%1_POLY_CFCC.FREQ
/*      the name of the frequency file is changed later in the aml
/*      so that the file will export along with the cover.  The name
/*      at the end of this process is %.cover%1.POLY_CFCC_FREQ
/*
/*      to display the lines in different colors based in the cfcc,
/*      use: ARCLINES %.cover%1 CFCC %.cover%1_LINE_CFCC.FREQ
/*      the name of the frequency file is changed later in the aml
/*      so that the file will export along with the cover.  The name
/*      at the end of this process is %.cover%1.LINE_CFCC_FREQ
/* 
&DATA ARC INFO
ARC
SEL %.cover%1_LINE_CFCC.FREQ
RESEL CFCC CN 'H'
CALC SYMBOL = 4
NSEL
RESEL CFCC CN 'A1'
CALC SYMBOL = 1
NSEL
RESEL CFCC CN 'A'
CALC SYMBOL = 14
NSEL
RESEL CFCC CN 'B'
CALC SYMBOL = 2
NSEL
RESEL CFCC CN 'C'
CALC SYMBOL = 7
NSEL
RESEL CFCC CN 'D'
CALC SYMBOL = 7
NSEL
RESEL CFCC CN 'F'
CALC SYMBOL = 5
NSEL
RESEL CFCC CN 'E'
CALC SYMBOL = 6
NSEL
RESEL SYMBOL LT 1
CALC SYMBOL = 9
REM
REM
SEL %.cover%1_POLY_CFCC.FREQ
RESEL CFCC CN 'H' 
CALC SYMBOL = 43 
NSEL
RESEL CFCC CN 'D10' 
CALC SYMBOL = 62
NSEL
RESEL CFCC CN 'D43'  
CALC SYMBOL = 110
NSEL
RESEL CFCC CN 'D51'  
CALC SYMBOL = 119
NSEL
RESEL CFCC CN 'D85'  
CALC SYMBOL = 70 
NSEL
RESEL CFCC CN 'D83'  
CALC SYMBOL = 68
NSEL
RESEL CFCC CN 'D82'
CALC SYMBOL = 119
NSEL
RESEL CFCC NC '  '
RESEL SYMBOL LT 1
CALC SYMBOL = 23
REM
REM
Q STOP
&END
/*
/*
/*      load Record Type 9 into INFO if the 9 record type exists
/*
/*      this loads the 9 Record Type information into INFO
/*      The information from RT9 is RELATEd to the cover.  The
/*      information can be moved into the cover if one desires.
/*
&if [exists %.pathname%%.in_file%9 -file] &then ~
    &do
    &type
    &type Begin Load_RT9
    &type
    &call load_rt9
    &type RT9 Completed
    &end
&else
    &type This file has no 9 Type record
/*
/*
/*      load Record Type C into INFO if the C record type exists
/*
/*     this loads the C Record Type information into INFO
/*     The information from RTC is RELATEd to the cover.  The 
/*     information can be moved into the cover if one desires.
/*
&if [exists %.pathname%%.in_file%c -file] &then ~
    &do
    &type 
    &type Begin Load_RTC
    &type
    &call load_rtc
    &type RTC Completed
    &end
&else
   &type This file has no C Type Record
/*
/*
/*      load Record Type H into INFO if the H record type exists
/*
/*     this loads the H Record Type information into INFO
/*     The information from RTH is RELATEd to the cover.  The
/*     information can be moved into the cover if one desires.
/*
&if [exists %.pathname%%.in_file%h -file] &then ~
    &do  
    &type
    &type Begin Load_RTH 
    &type
    &call load_rth
    &type RTH Completed  
    &end    
&else  
   &type This file has no H Type Record
/*
/*
/*      load Record Type S into INFO if the S record type exists
/*
/*     this loads the S Record Type information into INFO
/*     The information from RTS is RELATEd to the cover.  The
/*     information can be moved into the cover if one desires.
/*
&if [exists %.pathname%%.in_file%s -file] &then ~
    &do  
    &type
    &type Begin Load_RTS 
    &type
    &call load_rts
    &type RTS Completed
    &end    
&else  
   &type This file has no S Type Record
/*
/*
/*      change the storage of alternate names and additional 
/*      address range information - RT5 and RT6
/*      in INFO, both alternate names and additional address
/*      range information is stored in a single file, the
/*      %.cover%1.ALTER file.
/*      the following will take the alternate names out of 
/*      the ALTER file and create a different INFO file
/*      named %.cover%1.ANAME - it contains only feature
/*      names
/*      the following also takes the additional address
/*      range information and creates an additional INFO
/*      file called %.cover%1.ALTADD
/*      this uses the raw TIGER/Line file to incorporate 
/*      the record sequence field that ESRI does not
/*      include when creating their version of alternate
/*      names and additional address ranges
/*      the forthcoming Postal TIGER/Line file may use
/*      the record sequence number in conjunction with 
/*      the nine-digit ZIP Code
/*
/*
/*      test for the existence of the INFO file containing the
/*      alternate name and additional address information
/*
&if [exists %.cover%1.ALTER -info] &then ~
  &do
    &if [exists %.pathname%%.in_file%5 -file] &then ~
        &do
        &type
        &type Beginning to move alternate names
        &type
        &call chg_name
        &type
        &type Names moved to %.cover%1.ANAME
        &type
        &end
    &else
    &type No Alternate Names for %.cover%1
  &end
/*
/*
/*      then move additional address ranges into new INFO file
/*
    &do
    &if [exists %.pathname%%.in_file%6 -file] &then ~
        &do
        &type
        &type Beginning to move additional addresses
        &type
        &call chg_add
        &type
        &type Addresses moved to %.cover%1.ALTADD
        &type
        &end
    &else
    &type No Additional Address Ranges for %.cover%1
    &end
/*
/*
/*      load Record Type Z into INFO if the Z record type exists
/*
/*      this loads the Z Record Type information into INFO
/*      Two relationships are added to the RELATE created by
/*      TIGERTOOL.  The two relationships link the ZIP+4
/*      information to RT1 (the information stored on the 
/*      feature network proper and RT6 (the additional address
/*      information).
/*
/*
&if [exists %.pathname%%.in_file%z -file] &then ~
    &do
    &type
    &type Begin Load_RTZ
    &type
    &call load_rtz
    &type RTZ Completed
    &end
&else
   &type This file has no Z Type Record
/*
/*
/*      Add a field to hold a shortened feature name - use the 
/*      INFO command CONCATENATE
/*
/* CHANGED THE FOLLOWING CHARACTER SPEC FROM INTEGER AS PER
/* CAROL BRANDT'S INSTRUCTIONS 95/02/16 17:07 
additem %.cover%1.aat %.cover%1.aat SH_NAME 20 20 C # TOLAT
&DATA ARC INFO
ARC
SEL %.cover%1.AAT
CONCATENATE SH_NAME FROM FDPRE +,FNAME +,FTYPE +,FDSUF
REM

Q STOP
&END
/*
/*      copy the relationship file to rename it so that it will
/*      can be included in the archive - export - process
/*      if the relationship name does not include the cover
/*      number (1) it will not go into the exported arc coverage
/*      copy the lookup table files for the same reason
/*
/*
&type Changing the name of %.cover%.REL to %.cover%1.REL
/*
copyinfo %.cover%.REL %.cover%1.REL
/*
&type Changing the name of %.cover%1_POLY_CFCC.FREQ to %.cover%1.POLY_CFCC_FREQ
/*
copyinfo %.cover%1_POLY_CFCC.FREQ %.cover%1.POLY_CFCC_FREQ
/* 
&type Changing the name of %.cover%1_LINE_CFCC.FREQ to %.cover%1.LINE_CFCC_FREQ
/*
copyinfo %.cover%1_LINE_CFCC.FREQ %.cover%1.LINE_CFCC_FREQ
/*
/*      after copying the three files listed above,
/*      delete the ones originally created by the arc process
/*
&DATA ARC INFO
ARC
SEL %.cover%.REL
DELETE %.cover%.REL
Y
SEL %.cover%1_POLY_CFCC.FREQ
DELETE %.cover%1_POLY_CFCC.FREQ
Y
SEL %.cover%1_LINE_CFCC.FREQ
DELETE %.cover%1_LINE_CFCC.FREQ
Y
SEL %.cover%1.REL
RESEL TABLE-ID CN '2'
PURGE
Y
Q STOP
&END
/*
&type Done creating coverages
&type
&type begin archive process
/*
&sys date
/*
/*      export the %.cover%1 for archive the feature network
/*      and polygon information
/*      export the %.cover%3 for archiving the point landmarks
/*      after archiving the coverage, delete it
/*      and all other covers created in this process
/*
&type  Archiving coverages is possible
&type  That portion of the process is commented out in this aml
/*
/*      export cover %.cover%1 %.cover%1
/*      export cover %.cover%3 %.cover%3
/*
/*      kill %.cover%1 all
kill %.cover%2 all
/*      kill %.cover%3 all
/*
&sys date
/*
&return
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
/*      routine load_rt9
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
&routine load_rt9
/*
/*      if the 9 Record Type exists, use translate to remove
/*      carriage return and linefeed characters from the file
/*      Define an INFO file, load the data, then delete the
/*      translated files
/*
&set .in_file = [Translate %.in_file% abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ]
/*
    &sys tr -d '\012' < %.pathname%%.in_file%9 > %.in_file%9_tr
    &sys tr -d '\015' < %.in_file%9_tr > %.in_file%9_tr2
/*
&DATA ARC INFO
ARC
DEFINE %.cover%1.RT9
RT,1,C
VERSION,4,I
STATE,2,C
COUNTY,3,C
CENID,5,C
POLYID,10,I
SOURCE,1,C
CFCC,3,C
KGLNAME,30,C
ZIP,5,I
ZIP4,4,I
NUMBER,11,I
NAME,8,I
FILLER,1,C

REM
SEL %.cover%1.RT9
GET ../%.in_file%9_tr2 COPY

REM
REM
REDEFINE
11,CENPOLID,15,15,I

REM
CALC CENPOLID = CENPOLID

SEL %.cover%1.RT9
SORT ON CENPOLID

SEL %.cover%.REL
ADD
NEW9
%.cover%1.RT9
INFO
CENPOLID
CENPOLID
ORDERED
RO


Q STOP 
&END 
/* 
/*
/*      remove excess copies of Record Type 9
/*
&sys rm %.in_file%9_t*
/*
&return
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
/*      routine load_rtc
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
&routine load_rtc
/*
/*      if the C Record Type exists, use translate to remove
/*      carriage return and linefeed characters from the file
/*      Define an INFO file, load the data, then delete the
/*      translated files
/*
&set .in_file = [Translate %.in_file% abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ]
/*
&sys tr -d '\012' < %.pathname%%.in_file%c > %.in_file%c_tr
&sys tr -d '\015' < %.in_file%c_tr > %.in_file%c_tr2
/*
&DATA ARC INFO
ARC
DEFINE %.cover%1.RTC
RT,1,C
VERSION,4,I
STATE,2,C
COUNTY,3,C
FIPSYR,2,C
FIPS,5,C
FIPSCC,2,C
FIPSPDC,1,C
PSAD,2,C
ANRC,2,C
CSMA,2,C
MA,4,C
AIR,4,C
VTD,6,C
UA,4,C
NAME,66,C

REM
SEL %.cover%1.RTC
GET ../%.in_file%c_tr2 COPY

Q STOP
&END
/*
/*
/*      remove the excess copies of Record Type C
/*
&sys rm %.in_file%c_t*
/*
&return
/*
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
/*      routine load_rth
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
&routine load_rth
/*
/*      if the H Record Type exists, use translate to remove
/*      carriage return and linefeed characters from the file
/*      Define an INFO file, load the data, then delete the
/*      translated files
/*
&set .in_file = [Translate %.in_file% abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ]
/*
&sys tr -d '\012' < %.pathname%%.in_file%h > %.in_file%h_tr
&sys tr -d '\015' < %.in_file%h_tr > %.in_file%h_tr2
/*
&DATA ARC INFO
ARC
DEFINE %.cover%1.RTH
RT,1,C
VERSION,4,I
STATE,2,C
COUNTY,3,C
RECNUM,10,I
HIST,1,C
SOURCE,1,C
TLIDFR1,10,I
TLIDFR2,10,I
TLIDTO1,10,I
TLIDTO2,10,I

REM
SEL %.cover%1.RTH
GET ../%.in_file%h_tr2 COPY

SORT ON RECNUM

SEL %.cover%.REL
ADD
HIST
%.cover%1.RTH
INFO
RECNUM
RECNUM
ORDERED
RO
 
Q STOP
&END
/*
/*
/*      remove the excess copies of Record Type H
/*
&sys rm %.in_file%h_t*
/*
&return
/*
/*
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
/*      routine load_rts
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
&routine load_rts
/*
/*      if the S Record Type exists, use translate to remove
/*      carriage return and linefeed characters from the file
/*      Define an INFO file, load the data, then delete the
/*      translated files
/*
&set .in_file = [Translate %.in_file% abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ]
/*
&sys tr -d '\012' < %.pathname%%.in_file%s > %.in_file%s_tr
&sys tr -d '\015' < %.in_file%s_tr > %.in_file%s_tr2
/*
&DATA ARC INFO
ARC
DEFINE %.cover%1.RTS
RT,1,1,C
VERSION,4,4,I
STATE,2,2,C
COUNTY,3,3,C
CENID,5,5,C
POLYID,10,10,I
WATER,1,1,C
CSMA,4,4,C
MA,4,4,C
FAIR,5,5,C
AIR,4,4,C
TRUSTL,1,1,C
ANRC,2,2,C
CSTATE,2,2,C
CCOUNTY,3,3,C
FCCITY,5,5,C
FMCD,5,5,C
FSMCD,5,5,C
FPLC,5,5,C
CTBNA,6,6,C
BLK,4,4,C
RS10,1,1,C
CDC,2,2,C
SSDC,6,6,C
SHDC,6,6,C
VTD0,6,6,C
RS11,6,6,C
RS12,1,1,C
RS13,5,5,C
RS14,5,5,C
FILLER,1,1,C

REDEFINE
11,CENPOLID,15,15,I

REM 
SEL %.cover%1.RTS
GET ../%.in_file%s_tr2 COPY 
  
CALC CENPOLID = CENPOLID

SEL %.cover%.REL
ADD
SSS
%.cover%1.RTS
INFO
CENPOLID
CENPOLID
ORDERED
RO

Q STOP   
&END 
/*
/*
/*      remove the excess copies of Record Type S

/*
&sys rm %.in_file%s_t*
/*
&return
/*
/*
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
/*
/*      routine chg_name
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
&routine chg_name
/*
/*      access INFO, select the alternate name/address file
/*      create one INFO file for name, a second for addresses
/*      is created in the subroutine chg_add
/*
/*
&DATA ARC INFO
ARC
CALC $COMMA-SWITCH = -1
SEL %.cover%1.ALTER
RESEL RT = 5
OUTPUT ../%.cover%_names INIT
PRINT 1T,RT,2T,RECNUM,12T,FDPRE,14T,FNAME,44T,FTYPE,48T,FDSUF,50T,'XX'
OUTPUT XXXNSP
REM
REM
DEFINE %.cover%1.ANAME
RT,1,1,C
RECNUM, 10,10,I
FDPRE,2,2,C
FNAME,30,30,C
FTYPE,4,4,C
FDSUF,2,2,C
XXX,2,2,C
 
SEL %.cover%1.ANAME
GET ../%.cover%_names COPY
SORT ON RECNUM
REM
Q STOP
&END
/*
/*
/*      Add a field to hold a shortened feature name - use the  
/*      INFO command CONCATENATE 
/*
additem %.cover%1.ALTER %.cover%1.ALTER SH_NAME 20 20 C # FDSUF
/* 
&DATA ARC INFO 
ARC 
SEL %.cover%1.AAT 
CONCATENATE SH_NAME FROM FDPRE +,FNAME +,FTYPE +,FDSUF 
REM 
 
Q STOP   
&END 
/* 
/*      remove the system file created
/*      translate added because when creating the system file in
/*      INFO, the system file is named with lower case characters
/*
&set .cover = [Translate %.cover% abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ]
/*
&sys rm %.cover%_names
/*
/*      return cover name to original case
&set .cover = [Translate %.cover%]
/*
&return
/*
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
/*      routine chg_add
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
&routine chg_add
/* 
/*      the reason I am loading RT6 separately (not using the INFO
/*      <cover>.ALTER) is because we want to use the Record Sequence
/*      (RTSQ) field.  This information is not loaded into the 
/*      ALTER file.  The RTSQ field will become important in the
/*      Postal Version of the TIGER/Line Files.  The ZIP+4 Codes
/*      will relate to a TLID and RTSQ Number.  The user can determine
/*      which address range belongs with which ZIP+4 Code based
/*      on the RTSQ number.  For example: where a line segment
/*      has multiple address range records, the address record
/*      with RTSQ 3 will relate to the ZIP+4 Code with RTSQ 3.
/*
/*      remove any carriage return line feed characters from the 
/*      RT6 file 
/*
&set .in_file = [Translate %.in_file% abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ]
/*
&sys tr -d '\012' < %.pathname%%.in_file%6 > %.in_file%6_tr
&sys tr -d '\015' < %.in_file%6_tr > %.in_file%6_tr2
/*
/*      access INFO, select the alternate name/address file
/*      create one INFO file for name, a second for addresses
/*
/*      ARC/INFO does strange things to the LEFTADD1 field if
/*      I ask it to load the field as integer.  With $COMMA-SWITCH
/*      in the default, commas appear in the field.  I called ESRI
/*      and they said that they tried it and got the same stuff.  
/*      They also said that they tried ALTERing the field after
/*      the information was in INFO and it was fine.  I ALTERed
/*      the field back to integer, but I get the commas again.
/*      The only way to eliminate the commas in the integer field
/*      is to CALC the field equal to itself.  The problem with 
/*      this approach is that the resulting field contains zero (0).
/*      All other integer fields remain blank - causing inconsistent
/*      data display.  Of course, we could CALC each field to itself
/*      but then, do we want zeros in every address field where no
/*      addresses exist?  I think not.
/*
/*      So, ALWAYS set $COMMA-SWITCH = -1 and you will never see
/*      the commas in the LEFTADD1 filed.
/*
&DATA ARC INFO
ARC
CALC $COMMA-SWITCH = -1
DEFINE %.cover%1.ALTADD
RT,1,1,I
VERSION,4,4,C
RECNUM, 10,10,I
RTSQ,3,3,I
LEFTADD1,11,11,C
LEFTADD2,11,11,I
RGTADD1,11,11,I
RGTADD2,11,11,I
FRIMPLADD,1,1,C
TOIMPLADD,1,1,C
FRIMPRADD,1,1,C
TOIMPRADD,1,1,C
ZIPL,5,5,C
ZIPR,5,5,C

SEL %.cover%1.ALTADD
GET ../%.in_file%6_tr2 COPY

REDEFINE
6,TLID_SEQ,13,13,C
 
REM     The TLID_SEQ field is created to have the ability to 
REM     link the correct ZIP+4 Code to the correct address
REM     range record in the RT6 file. 
 
SEL %.cover%1.ALTADD
MOVEITEM TLID_SEQ TO TLID_SEQ
SORT ON TLID_SEQ
REM
ALTER,LEFTADD1,,,I,,,,,,

Q STOP
&END
/*
/*      remove any translated files created to move the alternate
/*      address information into a new INFO file
/*
&sys rm %.in_file%6_t*
/*
&return
/*
/*
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
/*      routine load_rtz
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
&routine load_rtz
/*
/*      check for the existence of Record Type Z
/*      if it is resident in the directory, remove the carriage
/*      return and line feed characters from the file.
/*      define a template in INFO and copy the version of the
/*      translated file into INFO
/*
&set .in_file = [Translate %.in_file% abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ]
/*
&if [exists %.in_file%z -file] &then ~
&do
    &sys tr -d '\012' < %.pathname%%.in_file%z > %.in_file%z_tr
    &sys tr -d '\015' < %.in_file%z_tr > %.in_file%z_tr2
/*
&set .cover = [Translate %.cover%]
/*
&DATA ARC INFO   
ARC
CALC $COMMA-SWITCH = -1
REM
DEFINE %.cover%1.RTZ
RT,1,1,I 
VERSION,4,4,C
RECNUM,10,10,I 
RTSQ,3,3,I 
ZIP4L,4,4,C 
ZIP4R,4,4,C
 
REM
SEL %.cover%1.RTZ 
GET ../%.in_file%z_tr2 COPY
 
REM
REM
REDEFINE 
19,LSECTOR,2,2,C 
21,LSEGMENT,2,2,C 
23,RSECTOR,2,2,C 
25,RSEGMENT,2,2,C
6,TLID_SEQ,13,13,C 
19,INT_LSEC,2,2,I
23,INT_RSEC,2,2,I
 
REM     The TLID_SEQ field is created to have the ability to 
REM     link the correct ZIP+4 Code to the correct address
REM     range record in the RT6 file. 
 
SEL %.cover%1.RTZ 
MOVEITEM TLID_SEQ TO TLID_SEQ
SORT ON TLID_SEQ 
 
SEL %.cover%.REL
ADD
ZZZ
%.cover%1.RTZ
INFO
RECNUM
RECNUM
ORDERED
RO
 
SEL %.cover%.REL
ADD
Z6
%.cover%1.RTZ
INFO
TLID_SEQ
TLID_SEQ
ORDERED 
RO
 
Q STOP
&END
/*
&end
/*
/*      remove excess copies of Record Type Z
/*
&sys rm %.in_file%z_tr*
/*
&return
/*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *