/******************************************************************************* /* Program: gridmosaic.aml /* Usage: &r gridmosaic /* Ex: &r gridmosaic mosgrid 6 grid.lst /* /* Inputs: outgrid - Name of output grid created by mosaicing. Grid /* name is limited to 12 characters. /* numingrids - Number of individual grids to be mosaiced. Program /* limit is 49 individual grids. /* qfile - ASCII file which contains grid names for /* individual grids to be mosaiced. File can contain /* full pathnames if mosaicing grids in different /* workspaces. /* /* Output: Mosaiced grid of the same resolution as the input grids /* /* Notes: Run this program without arguments to see the usage and examples. /* Program assumes that the input grids are integer grids. /* /* History: DJHester 08/26/97 Initial coding for mosaicing quad-based /* elevation grids /******************************************************************************* /* &args outgrid numingrids qfile &severity &error &routine bailout &s prog = [ENTRYNAME %aml$file% -NOEXT -FILE] /* current AML being run &watch %prog%.watch /* /***** Check for correct usage and correct argument types ***** /* &if [NULL %qfile%] &then &do &s error_case = 1 &call error_cond &end &s qfile = [locase %qfile%] &if [EXISTS %qfile% -FILE] = .FALSE. &then &do &s error_case = 2 &call error_cond &end &if [TYPE %numingrids%] NE -1 &then &do &s error_case = 3 &call error_cond &end &if %numingrids% GT 49 &then &do &s error_case = 4 &call error_cond &end &if [LENGTH %outgrid%] GT 12 &then &do &s error_case = 5 &call error_cond &end /* /***** Check for existence of output grid ***** /* &if [EXISTS %outgrid% -GRID] &then &do &s error_case = 6 &call error_cond &end /* /***** Set terminal ***** /* &if [NULL [EXTRACT 1 [SHOW &terminal]]] &then &terminal 9999 /* /***** Read qfile for individual grids to be mosaiced ***** /* &type &type ****************************** &type Open %qfile% for reading &type ****************************** &type &s unit = [OPEN %qfile% OK -READ] &if %ok% ne 0 &then &call open_cond &s fstat = 0 &s gridnumber = 0 &do &while [CALC %fstat% = 0] &s ingrid = [READ %unit% FSTAT] &if %fstat% = 0 &then /* /***** Check for existence of input grid ***** /* &do &if ^ [EXISTS %ingrid% -GRID] &then &do &s error_case = 7 &call error_cond &end /* /***** Create string of grids to mosaic /* &s gridnumber = %gridnumber% + 1 &if %gridnumber% GT 49 &then &do &s error_case = 4 &call error_cond &end &if %gridnumber% = 1 &then &s gridlist = %ingrid% &else &s gridlist = %gridlist%,%ingrid% &if [LENGTH %gridlist%] GT 1024 &then &do &s error_case = 8 &call error_cond &end &end &end &s closestat = [CLOSE %unit%] /* /***** Mosaic individual grids into a composite grid ***** /* DISPLAY 0 GRID %outgrid% = MOSAIC(%gridlist%) QUIT &type ************************************************************************* &type END OF MOSAICING GRIDS &type &type %prog% has created %outgrid% from %gridnumber% grids in %qfile% &type Processing completed [DATE -DOW] [DATE -CAL] [DATE -AMPM] &type ************************************************************************* /* /* &watch &off &return /* /* /*------------------------------------------------------------------------------ /*------------------------------ ROUTINE LIST -------------------------------- /*------------------------------------------------------------------------------ /* /* /*------------------ &routine ERROR_COND /*------------------ /* &severity &error &routine bailout &if [UPCASE [SHOW PROGRAM]] = GRID &then QUIT &messages &on &type \\*************** PROGRAM [TRANSLATE %prog%] HALTED ***************** /* &if %error_case% = 1 &then /***** Incomplete program arguments &do &type USAGE: &r %prog% &type Ex: &r %prog% mosgrid 6 grid.lst &end &if %error_case% = 2 &then /***** File list of grids to mosaic does not exist &type File listing grids to mosaic does not exist!!! &if %error_case% = 3 &then /***** Number of input grids not an integer value &type Number of input grids must be an integer value!!! &if %error_case% = 4 &then /***** Too many input grids &type Limit is 49 grids for mosaicing!!! &if %error_case% = 5 &then /***** Output grid name > 12 characters &type Output grid name is too long - must be 12 characters or less!!! &if %error_case% = 6 &then /***** Mosaiced grid already exists &type Output grid already exists!!! &if %error_case% = 7 &then /***** Input grid does not exist &type Input grid to be mosaiced does not exist!!! &if %error_case% = 8 &then /***** String length of grids to mosaic too long &do &type String length of grids to mosaic is too long. &type %prog% halted after reading %ingrid%. &type Edit %qfile% to less than %gridnumber% grids. &end &if %error_case% = 9 &then /***** No available AML file units &type No available AML file units!!! &if %error_case% = 10 &then /***** Could not open file &type Could not open %qfile% file!!! /* &type Process halted [DATE -DOW] [DATE -CAL] [DATE -AMPM] &type *********************************************************\ /* &watch &off &return; &return &error /* /*----------------- &routine OPEN_COND /*----------------- /* /***** Program reports open condition /* &select %ok% &when 0 &type %qfile% opened successfully &when 100 &do &s error_case = 9 &call error_cond &end &when 101 &do &s error_case = 2 &call error_cond &end &when 102 &do &s error_case = 10 &call error_cond &end &end /* /*--------------- &routine BAILOUT /*--------------- /* &severity &error &ignore &type \*** Error occurred at line %aml$errorline% in %aml$errorfile% &watch &off &return; &return &error /*