/* make_header.aml /* Arc AML to create Arc header (.hdr) file from Keyword Header /* (April, 1997) records of USGS digital orthophotoquads (DOQQ) /* single command-line argument is the DOQQ image file /* DECatts USGS-NMD-RMMC-RTA, 16-December-1997 &args imagefile &if [null %imagefile%] &then &return &inform make_header: usage: MAKE_HEADER &if ^ [exists %imagefile% -file] &then &return &warning make_header: error: image file %imagefile% does not exist &s prefix [before %imagefile% '.'] &if [exists %prefix%.hdr -file] &then &return &warning make_header: warning: header file %prefix%.hdr already exists &s unit [open %imagefile% ook -r] &if %ook% ^= 0 &then &return &warning make_header: error: image file can not be opened for reading. &s firstword [trim [before [read %unit% rok] ' ']] &if %firstword% ^= BEGIN_USGS_DOQ_HEADER &then &do &s cok [close %unit%] &return &warning make_header: error: image file is not Keyword Header format &end &s flag .false. &s count 0 &s error .false. &s done .false. &do &until %done% &s string [read %unit% rok] &if %rok% = 102 &then &s done .true. &else &do &s par [trim [translate [before %string% ' ']]] &if %par% = SAMPLES_AND_LINES &then &do &s count [calc %count% + 2] &s samples [trim [before [trim [after %string% 'SAMPLES_AND_LINES']] ' ']] &s lines [trim [before [trim [after %string% %samples%]] ' ']] &end &else &if %par% = XY_ORIGIN &then &do &s count [calc %count% + 2] &s x1 [trim [before [trim [after %string% 'XY_ORIGIN']] ' ']] &s y1 [trim [before [trim [after %string% %x1%]] ' ']] &end &else &if %par% = SECONDARY_XY_ORIGIN &then &do &s x2 [trim [before [trim [after %string% 'SECONDARY_XY_ORIGIN']] ' ']] &s y2 [trim [before [trim [after %string% %x2%]] ' ']] &end &else &if %par% = HORIZONTAL_RESOLUTION &then &do &s count [calc %count% + 1] &s rez [trim [before [trim [after %string% 'HORIZONTAL_RESOLUTION']] ' ']] &end &else &if %par% = BYTE_COUNT &then &do &s flag .true. &s count [calc %count% + 1] &s header_bytes [trim [before [trim [after %string% 'BYTE_COUNT']] ' ']] &end &else &if %par% = HORIZONTAL_COORDINATE_SYSTEM &then &s system [trim [before [trim [after %string% 'HORIZONTAL_COORDINATE_SYSTEM']] ' ']] &else &if %par% = COORDINATE_ZONE &then &s zone [trim [before [trim [after %string% 'COORDINATE_ZONE']] ' ']] &else &if %par% = HORIZONTAL_UNITS &then &s units [trim [before [trim [after %string% 'HORIZONTAL_UNITS']] ' ']] &else &if %par% = HORIZONTAL_DATUM &then &s datum1 [trim [before [trim [after %string% 'HORIZONTAL_DATUM']] ' ']] &else &if %par% = SECONDARY_HORIZONTAL_DATUM &then &s datum2 [trim [before [trim [after %string% 'HORIZONTAL_DATUM']] ' ']] &else &do &if %flag% & %count% < 6 &then &s done .true. &if %flag% & %count% < 6 &then &s error .true. &end &if %flag% & %count% = 6 &then &s done .true. &end &end &s cok [close %unit%] &if %error% &then &return &warning make_header: error: header information is incomplete /* Check the required parameters &if ^ [variable samples] &then &do &s error .true. &type make_header: error: image samples were not defined &end &if ^ [variable lines] &then &do &s error .true. &type make_header: error: image lines were not defined &end &if ^ [variable x1] &then &do &s error .true. &type make_header: error: primary X coordinate not defined &end &if ^ [variable y1] &then &do &s error .true. &type make_header: error: primary Y coordinate not defined &end &if ^ [variable rez] &then &do &s error .true. &type make_header: error: image resolution not defined &end &if ^ [variable datum1] &then &s datum1 UNKNOWN &if %error% &then &return &warning make_header: aborted /* Check the secondary coordinate parameters &s secondary .false. &s count 0 &if [variable x2] &then &s count [calc %count% + 1] &if [variable y1] &then &s count [calc %count% + 1] &if ^ [variable datum2] &then &s datum2 UNKNOWN &if %count% > 1 &then &s secondary .true. /* Check other informational parameters &if ^ [variable system] &then &s system UNKNOWN &if ^ [variable zone] &then &s zone UNKNOWN &if ^ [variable units] &then &s units UNKNOWN /* Write header file &s header [open %prefix%.hdr ook -w] &s wok [write %header% [quote ncols %samples%]] &s wok [write %header% [quote nrows %lines%]] &s wok [write %header% 'ulxmap '%x1%' /* primary-X in '%datum1%] &s wok [write %header% 'ulymap '%y1%' /* primary-Y in '%datum1%] &if %secondary% &then &do &s wok [write %header% 'ulxmap '%x2%' /* secondary-X in '%datum2%] &s wok [write %header% 'ulymap '%y2%' /* secondary-Y in '%datum2%] &end &s wok [write %header% [quote xdim %rez%]] &s wok [write %header% [quote ydim %rez%]] &s wok [write %header% [quote skipbytes %header_bytes%]] &s cok [close %header%] /* Report &type Image parameters for %imagefile% &type Coordinate system is: %system% &type Coordinate zone is: %zone% &type Coordinate units are: %units% &type Primary datum is: %datum1% &type Lines: %lines% Samples: %samples% &if %units% = UNKNOWN &then &type Image resolution is: %rez% in unknown units &else &type Image resolution is: %rez% %units% &type Image parameters have been written to %prefix%.hdr &if %secondary% &then &do &type make_header: warning: two coordinate system references in %prefix%.hdr &type make_header: warning: you must remove one coordinate pair in %prefix%.hdr &end &return