#  This macro will create a new map & import the scan file.
#  if the scan file has a  .opr  extention, it is also reversed.
#
#  Then the macro does batch raster cleanup, assembly, vertex reduction
#  and reduces the resolution.  
#
#  Finally, the map is then saved, and the name of the scan file name is 
#  changed by appending  'bk'  to it.


#  This part only has effect if there is a scan file with  .opr  extention.
import  optr9  $map_name.opr
#  If a file HAS been imported, it is reflected.
reflect -h


#  This part only has effect if there is a scan file with  .opt  extention.
#  (it will overwrite any existing scan file)
import  optr9  $map_name.opt


# Do batch raster cleanup:
# 1. fill all single pixel holes
fill_holes
# 2. delete all single pixel points
del_points
# 3. make the fat lines thinner by trimming up to 6 pixels from both sides.
thin_lines 0 6
# 4. open all remaining solid areas
open_solids
# 5. delete all thinning generated spurs (up to 6 pixels long)
del_spurs 6
# 6. make sure all lines are 1 pixel wide
thin_lines 0 0
# 7. attempt to close very small gaps.
grow_spurs 1


# Now, the raster is traces & vector lines are formed.
assemble


# The original scan now replaces the edited scan which is no longer needed.
disprstr_get c
brstr_delete


# Next, the verticies are thinned.
vertex_thin 0 0 1.5 0


# Finaly, the resolution is reduced by a factor of 2, threshold of 2.
reduce_res  2  2


# save it.
save


# append  'bk'  to scan file (only one of the folling 2 commands will work)
execute mv /u2/ltdata/import/$map_name.opt /u2/ltdata/import/$map_name.optbk
execute mv /u2/ltdata/import/$map_name.opr /u2/ltdata/import/$map_name.oprbk
