/* Program: img_convert.aml /* /* Purpose: Converts a single image or a bunch of wildcarded images to /* the specified output format. /* /* Usage: &r img_convert /* Ex: &r %prog% denver.bil tiff /* &r %prog% *.img bil /* &r %prog% * tiff /* /* Notes: Supported input formats: TIFF, BIL, BIP, BSQ, RLC, /* SUNRASTER, ERDAS, IMAGINE, GRASS /* Supported output formats: TIFF, BIL, BIP, BSQ, RLC, /* SUNRASTER, ERDAS, IMAGINE /* If running Arc 7.1 or higher, also supports JPEG, BMP input /* and output. /* Run this program without arguments to see the usage and examples. /* /* Input: Any image supported by Arc. /* /* Output: Image(s) in the specified format with appropriate file /* name extension(s). /* /* History: JKosovich USGS 09/10/97 Original coding /* JKosovich USGS 04/09/98 Fixed SEARCH usage /* /* /*------------------------------------------------------------------------------ /* &args input outformat &severity &error &routine bailout &s prog = [ENTRYNAME %aml$file% -NOEXT -FILE] /* current AML being run /* /***** Determine ARC/INFO version for supported image formats ***** /* &s arcver = [EXTRACT 1 [SHOW VERSION]] /* eg. 7.0.4, 7.1, 7.1.1 &s arcver1 = [BEFORE %arcver% .] /* eg. 7 &if %arcver1% < 7 &then &return &warning \*** NOTE: Must use Arc version 7.0 or newer (%arcver%)\\ &s arcver2 = [SUBSTR [AFTER %arcver% .] 1 1] /* digit after the 7, eg. 0, 1 &if %arcver2% = 0 & %arcver1% = 7 &then /* if 7.0.3, 7.0.4, etc. &do &s inlist1 = TIFF, BIL, BIP, BSQ, RLC, &s inlist2 = SUNRASTER, ERDAS, IMAGINE, GRASS &s outlist1 = TIFF, BIL, BIP, BSQ, RLC, &s outlist2 = SUNRASTER, ERDAS, IMAGINE &s exmpl = img &end &else &if %arcver2% > 0 | %arcver1% > 7 &then /* if 7.1, 7.1.1, 8.0, etc. &do &s inlist1 = TIFF, JPEG, BIL, BIP, BMP, BSQ, RLC, &s inlist2 = SUNRASTER, ERDAS, IMAGINE, GRASS &s outlist1 = TIFF, JPEG, BIL, BIP, BMP, BSQ, RLC, &s outlist2 = SUNRASTER, ERDAS, IMAGINE &s exmpl = jpeg &end &s outlist = %outlist1% %outlist2% /* /***** Check for proper number of args ***** /* &if [NULL %outformat%] &then &call usage /* /***** Check for supported output image formats ***** /* &if [KEYWORD %outformat% %outlist%] <= 0 &then /* if not found or ambiguous &call usage &if [UPCASE %outformat%] = JPEG &then &s outformat = JFIF /* to pass into Arc:CONVERTIMAGE /* /***** If input is a single file ***** /* &if [SEARCH %input% *] = 0 &then /* if no *, then treat as single file &do &if ^ [EXISTS %input% -FILE] &then &return &warning \*** ERROR: File %input% not found in directory!\\ &if ^ [EXISTS %input% -IMAGE] &then &return &warning \*** ERROR: File %input%: Unrecognized image format!\\ &else CONVERTIMAGE %input% [ENTRYNAME %input% -NOEXT -FILE] %outformat% &end /* /***** If input is a wildcard string ***** /* &else &do &s tmpfile = xximgconv &if [EXISTS %tmpfile% -FILE] &then &s dok = [DELETE %tmpfile%] &s numimg = [FILELIST %input% %tmpfile% -FULL -IMAGE] &if %numimg% = 0 &then &do &s dok = [DELETE %tmpfile%] &return &warning \*** NOTE: No "%input%" files found in directory.\\ &end &s file = [OPEN %tmpfile% ook -READ] &s eof = .FALSE. &s image = [UNQUOTE [READ %file% rok]] /* /***** Actual image conversion ***** /* &do &until %eof% /* Or: until %rok% = 102 CONVERTIMAGE %image% [ENTRYNAME %image% -NOEXT -FILE] %outformat% &s image = [UNQUOTE [READ %file% rok]] &if %rok% = 102 &then &s eof = .TRUE. /*Or: &s eof = [NULL %image%] &end /* End do until /* /***** Close and delete file ***** /* &s cok = [CLOSE %file%] &s dok = [DELETE %tmpfile%] &end /* End wildcard loop /* /***** All done, exit successfully ***** /* &type \******************************************************** &type AML Program completed successfully. &type Thanks for using %prog%.aml, [UPCASE [USERNAME]]! &type ********************************************************\\ &return /* /* /*----------------------------- ROUTINE USAGE -------------------------------- /* &routine usage /* &type &type ********************************************************************** &type *** USAGE: &r %prog% &type *** Ex: &r %prog% denver.%exmpl% tiff &type *** &r %prog% *.%exmpl% bil &type *** &r %prog% * tiff &type *** Supported input formats: %inlist1% &type *** %inlist2% &type *** Supported output formats: %outlist1% &type *** %outlist2% &type **********************************************************************\\ &return; &return /* /* /*----------------------------- ROUTINE BAILOUT ------------------------------ /* &routine bailout /* &severity &error &ignore /* /***** Close files (no problem if not open) and delete temp file ***** /* &s cok = [CLOSE -ALL] &if [EXISTS %tmpfile% -FILE] &then &s dok = [DELETE %tmpfile%] /* &type \***** Error occurred at line %aml$errorline% in %aml$errorfile% *****\ /* &return; &return; &return