/* /* Program: DOQHDR.AML /* /* Version: 1.0 /* /* Release: 1 /* /* Purpose: Creates the ARC/INFO .hdr file needed by ARC/INFO to /* display USGS DOQs with the new Keyword Header format. This /* has been written in a way to make it easy to revise if changes /* are made to the new DOQ header format in the future... /* /* Usage: &r %prog% /* Ex: &r %prog% golden.doq NAD83 0 0 /* &r %prog% golden.doq nad27 0 -4000000 /* /* Language: ARC/INFO version 7.0 or higher /* /* System: Data General AViiON UNIX Workstations/Servers, DG/UX 5.4R3.10 /* /* /****************************** HISTORY **************************************/* /* Author Site Date Event /* ------ ---- ---- ----- /* David Roach, MCMC, 4/22/97 Original Coding /* JKosovich RMMC 04/18/97 Added Usage, variable for cell size, bailout /* routine, xshift argument, checks if B&W (.BIL) /* or color (.BIP), rename to .bil/.bip /* /*******************************************************************************/* /*============================ DISCLAIMER ====================================/* /* Although this program has been used by the U.S. Geological Survey (USGS), /* no warranty, expressed or implied, is made by the USGS as to the accuracy /* and functioning of the program and related program material, nor shall /* the fact of distribution constitute any such warranty, and no /* responsibility is assumed by the USGS in connection therewith. /* /*==============================================================================/* /* /************************* LINKS TO OTHER PROGRAMS ***************************/* /* Referenced by: Arc command line or doqhead.aml /* Programs called: None /* Subroutines called: None /* /************************** INPUT/OUTPUT COVERAGES ***************************/* /* Input: DOQ file needing a .hdr file to be created for ARC/INFO. /* /* Output: .hdr /* /**************************** AML VARIABLES **********************************/* /* Local variables: /* /* Global variables: /* /* /* /*============================================================================== /*========================= BEGIN MAIN PROGRAM =============================== /*==============================================================================/* /* &args filename nadin xshift yshift &severity &error &routine bailout &s prog = [ENTRYNAME %aml$file% -NOEXT -FILE] /* current AML being run &s path = [DIR %aml$fullfile%] &amlpath %path% &menupath [SHOW &amlpath] /* /***** Check usage and correct argument format ***** /* &if [NULL %yshift%] &then &do &type \\USAGE: &r %prog% &type Ex: &r %prog% golden.doq NAD83 0 0 &type &r %prog% golden.doq nad27 0 -4000000\\ &return &error &end &if ^ [EXISTS %filename% -FILE] &then &return &error \\ERROR (%prog%): File %filename% not found.\\ &s nadin = [UPCASE %nadin%] &if %nadin% not in {'NAD27','NAD83'} &then &return &error \\ERROR (%prog%): Datum must be either NAD27 or NAD83.\\ &if [TYPE %xshift%] > 0 or [TYPE %yshift%] > 0 &then &return &error \\ERROR (%prog%): and must be numeric.\\ &type \Please wait... /* /***** Set variables ***** /* &s doqfile [BEFORE %filename% .] &s ext = [LOCASE [AFTER %filename% .]] /* /***** Read image header information. After last keyword, header will be ***** /***** padded with blank lines ending with an "*", and the final header ***** /***** line will contain the keyword END_USGS_HEADER. ***** /* &s fileunit = [open %filename% openstat -r] &if %openstat% ne 0 &then &return &error Error Opening %doqfile%... &s keeplooping = .TRUE. &s record1 = [unquote [read %fileunit% readstat]] &s record = [UPCASE [extract 1 %record1%]] &if %record% = '*' &then &s keeplooping = .FALSE. &if %record% = 'END_USGS_HEADER' &then &s keeplooping = .FALSE. &do &while %keeplooping% /* &if %record% = 'BAND_ORGANIZATION' &then /* B&W or color &do /* Format can be bil, bip, bsq, or "single file" &s format = [TRIM [LOCASE [EXTRACT 2 %record1%]] -BOTH "] &if %format% not in {'bil','bip','bsq'} &then &s format = bil &end &if %record% = 'SAMPLES_AND_LINES' &then /* columns & rows &do &s ncols = [extract 2 %record1%] &s nrows = [extract 3 %record1%] &end &if %record% = 'HORIZONTAL_DATUM' &then /* primary horiz datum &s datum1 = [UPCASE [EXTRACT 2 %record1%]] &if %record% = 'HORIZONTAL_RESOLUTION' &then /* x,y ground resolution &s cellsize = [extract 2 %record1%] &if %record% = 'SECONDARY_HORIZONTAL_DATUM' &then /* secondary horiz datum &s datum2 = [UPCASE [EXTRACT 2 %record1%]] &if %record% = 'XY_ORIGIN' &then /* primary datum UL xy &do &s x1 = [extract 2 %record1%] &s y1 = [extract 3 %record1%] &end &if %record% = 'SECONDARY_XY_ORIGIN' &then /* secondary datum UL xy &do &s x2 = [extract 2 %record1%] &s y2 = [extract 3 %record1%] &end &if %record% = 'BYTE_COUNT' &then /* header bytes to skip &s skipbytes = [extract 2 %record1%] &s record1 = [unquote [read %fileunit% readstat]] &s record = [UPCASE [extract 1 %record1%]] &if [QUOTE %record%] = '*' &then &s keeplooping = .FALSE. &if [QUOTE %record%] = 'END_USGS_HEADER' &then &s keeplooping = .FALSE. /* &end &s closestat = [close -all] /* /***** Determine what datum x,y coords should use from input datum arg ***** /***** and input image's primary & secondary datums. ***** /***** (I.E. if user wants NAD83, and image's primary datum = 83, then ***** /***** use primary x,y values. If user wants NAD27 and image's primary ***** /***** datum = 83, use secondary x,y values. HOWEVER (for those rare ***** /***** DOQs created as NAD27), if user wants 83 and image's primary datum ***** /***** is NAD27, then use secondary x,y values. Likewise, if user wants ***** /***** 27 and image's primary datum = 27, then use primary x,y values.] ***** /* &if %nadin% = %datum1% &then /* if input datum arg = image's primary datum &do &s x = %x1% &s y = %y1% &end &else &if %nadin% = %datum2% &then /* if input datum = image's secondary datum &do &s x = %x2% &s y = %y2% &end &else /* otherwise, default to primary just in case &do &s x = %x1% &s y = %y1% &end /* /***** Add xshift and yshift to x, y if appropriate ***** /* &if %xshift% ^= 0 &then &s x = [CALC %x% + %xshift%] &if %yshift% ^= 0 &then &s y = [CALC %y% + %yshift%] /* /***** Set flag to rename image file if wrong or missing extension ***** /* &if ^ [NULL %ext%] &then &do &if %ext% ^= %format% &then &s rename = .TRUE. &else &s rename = .FALSE. &end &else &s rename = .TRUE. /* /***** Write the .hdr file ***** /* &if [EXISTS %doqfile%.hdr -FILE] &then &s dok = [DELETE %doqfile%.hdr -FILE] &s fileunit = [open %doqfile%.hdr openstat -write] &if %openstat% ne 0 &then &return &error \\ERROR (%prog%): Error creating %doqfile%.hdr file!\\ &s writestat = [write %fileunit% [quote NROWS %nrows%]] &s writestat = [write %fileunit% [quote NCOLS %ncols%]] &if %format% = bip &then &do &s writestat = [write %fileunit% [quote NBANDS 3]] &s writestat = [write %fileunit% [quote LAYOUT [UPCASE %format%]]] &end &s writestat = [write %fileunit% [quote ULXMAP %x%]] &s writestat = [write %fileunit% [quote ULYMAP %y%]] &s writestat = [write %fileunit% [quote XDIM %cellsize%]] &s writestat = [write %fileunit% [quote YDIM %cellsize%]] &s writestat = [write %fileunit% [quote SKIPBYTES %skipbytes%]] &s closestat = [close %fileunit%] /* /***** Rename original image to .bil (Black&White) or .bip (color). /***** If Arc version before 7.0.3, then [RENAME ] will not exist, use mv /* &if %rename% &then &do &severity &error &ignore &s renok = [RENAME %filename% %doqfile%.%format% -FILE] &if %aml$sev% = 2 &then &system /bin/mv %filename% %doqfile%.%format% &severity &error &routine bailout &if ^ [EXISTS %doqfile%.%format% -FILE] &then &type \%prog%: Could not rename input image to %doqfile%.%format% - rename manually.\ &end &type \%prog%: Header file %doqfile%.hdr created for [UPCASE %format%] image %doqfile%.%format%.\\ &return /* /* /*------------------- &routine bailout /*------------------- /* /***** Unanticipated errors are trapped here /* &severity &error &ignore &type \*** Error occurred at line %aml$errorline% in %aml$errorfile%\ &return; &return &error