/************************************************************************************************
/* Image preparation for work in ArcInfo Workstation by Glen Stichbury
/*						g.stichbury@gmail.com 
/*
/* This script requires a variables script to run, setting up the
/* input file location (%.inlocation%), output file location (%.outlocation%),
/* image identifier (%.number%), original image name (%.original%) including file 
/* extension eg .tif and a clip coverage for the rectification (%.clip%).
/* An example of the first two lines in the script would be:
/* &sv	.clip	E:\Glen\Masters\workstation\NDSI\clip														
/* &sv	.original	RossSea.2004356.terra.250m.tif	;	&sv 	.number	2004356	;	&sv	.inlocation	E:\Glen\Masters\workstation\images	;	&sv	.outlocation	E:\Glen\Masters\workstation\NDSI	;	&r rectify.txt
/* This script is set up to run processes on .tif files. Other image types
/* would require a universal change from .tif to the desired file extension.
/* 
/************************************************************************************************
&call workspace
&call Rectify
&call imagegrid
&call float
&return
/************************************************************************************************
&routine workspace

&if [show program] ne ARC &then quit

&if [exists %.outlocation%/Grids/%.number% -workspace] &then
&type +++Workspace Exists+++
&else createworkspace %.outlocation%/Grids/%.number%

&if [exists %.outlocation2%/%.number% -workspace] &then
&type +++Workspace Exists+++
&else createworkspace %.outlocation2%/%.number%


&return
/************************************************************************************************
&routine Rectify

&if [show program] ne ARC &then quit

&if [exist %.outlocation%/%.number%.tif -file] ~
  &then &sys erase %.outlocation%/%.number%.tif

&type +++Rectifying %.original%+++
rectify %.inlocation%.\%.original% %.outlocation%\%.number% # # %.clip%
&return
/************************************************************************************************
&routine imagegrid

&if [show program] ne ARC &then quit

&if [exist %.outlocation%/Grids/%.number%/%.number% -grid] ~
  &then kill %.outlocation%/Grids/%.number%/%.number% all

&type +++Converting %.number% to Grid+++
imagegrid %.outlocation%\%.number% %.outlocation%/Grids/%.number%/%.number%

&return
/************************************************************************************************
&routine float

&if [show program] ne GRID &then &do
&if [show program] ne ARC &then quit
grid
&end

&if [exist %.outlocation2%/%.number%/%.number% -grid] ~
  &then kill %.outlocation2%/%.number%/%.number% all


&type +++Converting %.number% to Float+++
/*%.outlocation2%/%.number%/%.number% = float(%.outlocation%/Grids/%.number%/%.number%)

/*&return

&if [exist %.outlocation2%/%.number%/%.number%c1 -grid] ~
  &then kill %.outlocation2%/%.number%/%.number%c1 all
&if [exist %.outlocation2%/%.number%/%.number%c2 -grid] ~
  &then kill %.outlocation2%/%.number%/%.number%c2 all
&if [exist %.outlocation2%/%.number%/%.number%c3 -grid] ~
  &then kill %.outlocation2%/%.number%/%.number%c3 all

%.outlocation2%/%.number%/%.number%c1 = float(%.outlocation%/Grids/%.number%/%.number%c1)
%.outlocation2%/%.number%/%.number%c2 = float(%.outlocation%/Grids/%.number%/%.number%c2)
%.outlocation2%/%.number%/%.number%c3 = float(%.outlocation%/Grids/%.number%/%.number%c2)

&return
/************************************************************************************************