DIAG.sml

  Download

More scripts: Scripts By Jack

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# ------------------------------------------------------------
# DIAG.sml
# ------------------------------------------------------------
# SET WARNING LEVEL: Refer to B5 & B6.
  $warnings 3
# ------------------------------------------------------------
# DEFINE VARIABLES FOR GENERAL CHARACTER STRINGS:
# Refer to B7.
  string t$,p$,p1$,p2$,p3$,p4$,p5$,p6$,p7$,p8$,p9$;
  string p10$,p11$,p12$,p13$,p14$,p15$,p16$,p17$,p18$,p19$;
  string p20$,p21$;
# ------------------------------------------------------------
# CLEAR CONSOLE WINDOW & REQUEST REPOSITIONING:
# Refer to B7, B8 & B9.
  clear();
  p1$ = "CONSOLE-WINDOW ADJUSTMENT\n";
  p2$ = "* REPOSITION the CONSOLE WINDOW.\n";
  p3$ = "* Then, CLICK the OK Button.";
  p$  = p1$ + p2$ + p3$;
  PopupMessage(p$);
# ------------------------------------------------------------
# DEFINE proc checkHisto(Band)
# PURPOSE: Check that Input Raster has a Full (Unsampled)
#          Histogram.  If Not, Then Recompute Histogram.
  proc checkHisto (raster Band) begin
     local numeric sampleInt;
     sampleInt = HistogramGetSampleInterval(Band);
     if (sampleInt > 1) begin
        DeleteHistogram(Band); CreateHistogram(Band,0);
     end
     else if (sampleInt == -1) then	begin
        CreateHistogram(Band,0);
     end
  end
# ------------------------------------------------------------
# DEFINE PROCEDURE writeTitle: Refer to B13 & B14.
# PURPOSE: WRITES TITLE & AUTHOR INFO TO CONSOLE WINDOW.
  proc writeTitle() begin
     printf("DIAG.sml:\n");
     printf("         VERSION: November 15, 2005\n");
     printf("         PURPOSE: PRODUCE DIAG PRODUCTS ");
     printf("RELATED TO SRFIs, PVI & PBI.\n");
     printf("         DETAILS: FAQs_by_Jack A & C\n");
     printf("          AUTHOR: Dr. Jack F. Paris\n");
     printf("    CONTACT INFO: [email protected] ");
     printf(" 303-775-1195\n");
     printf("     ALLOWED USE: ONLY NON-COMMERCIAL\n\n");
  end
# ------------------------------------------------------------
# WRITE TITLE & AUTHOR INFORMATION: Refer to B14.
  writeTitle();
# ------------------------------------------------------------
# DECLARE VARIABLES RELATED TO USER INPUTS:
# Refer to B15 & B16.
  string site$;
  numeric imager,vnir;
# ------------------------------------------------------------
# DECLARE VARIABLES DIRECTLY RELATED TO USER PROVIDED VALUES:
# Refer to B15 & B16.
  string imager$;
# ------------------------------------------------------------
# DECLARE STRING VARIABLE RELATED TO ALL RASTER TYPES:
# Refer to B17. 
  string rtype$;
# ------------------------------------------------------------
# DECLARE VARIABLES RELATED TO BARE-SOIL & DENSE VEG SEARCHES:
# Refer to B17.
  numeric wpvis,pbi2s,pvi1v;
  numeric pvi1s,pvi2s,pbi1s,pbi2s;
# ------------------------------------------------------------
# DECLARE VARIABLES RELATED TO PURE-PIXEL SEARCH:
# Refer to B17.
  numeric boxsize,sdmaxs,sdmaxv,oddcheck;
# ------------------------------------------------------------
# DECLARE VARIABLES RELATED TO BOOLEAN ENABLERS:
# Refer to B15 & B16
  numeric pCB,pBL,pGL,pYL,pRL,pRE,pNA,pNB;
  numeric pMA,pMB,pMC,pMD,pME,pMF,pMG;
# ------------------------------------------------------------
# DECLARE VARIBLES RELATED TO FOR-EACH LOOPS:
  numeric mk,pvi,pbi,pvisd,nlins,ncols;
# ------------------------------------------------------------
# DECLARE LIST OF POSSIBLE INPUT RASTERS:
  raster MK,SRFICB,SRFIBL,SRFIGL,SRFIYL,SRFIRL,SRFIRE;
  raster SRFINA,SRFINB,SRFIMA,SRFIMB,SRFIMC,SRFIMD;
  raster SRFIME,SRFIMF,SRFIMG,PVI,PBI;
# ------------------------------------------------------------
# DECLARE LIST OF POSSIBLE OUTPUT RASTERS:
  raster DCB,DBL,DGL,DYL,DRL,DRE,DNA,DNB;
  raster DMA,DMB,DMC,DMD,DME,DMF,DMG;
# ------------------------------------------------------------
# GET NAME OF SITE FROM THE USER: Refer to B17.
  t$  = "SITE NAME";
  p1$ = "SITE-NAME ENTRY\n";
  p2$ = "* ENTER the SITE NAME.\n";
  p3$ = "* Then, CLICK the OK Button.\n\n";
  p4$ = "SITE-NAME ENTERED:";
  p$  = p1$ + p2$ + p3$ + p4$;
  site$ = PopupString(p$,"",t$);
  printf("           SITE NAME: %s\n",site$);
# ------------------------------------------------------------
# GET IMAGER NUMBER FROM THE USER: Refer to B17.
  p1$  = "IMAGER-NUMBER SELECTION\n";
  p2$  = "  IMAGER\n";
  p3$  = "  NUMBER:  SYSTEM NAME\n";
  p4$  = "       1:  QuickBird 2 MS\n";
  p5$  = "       2:  Ikonos 2 MS\n";
  p6$  = "       3:  OrbView 3 MS\n";
  p7$  = "       4:  Landsat 7 ETM+\n";
  p8$  = "       5:  Landsat 5 TM\n";
  p9$  = "       6:  Landsat 5 MSS\n";
  p10$ = "       7:  Landsat 4 TM\n";
  p11$ = "       8:  Landsat 4 MSS\n";
  p12$ = "       9:  Landsat 3 MSS\n";
  p13$ = "      10:  Landsat 2 MSS\n";
  p14$ = "      11:  Landsat 1 MSS\n";
  p15$ = "      12:  Terra ASTER\n";
  p16$ = "      13:  Terra MODIS\n";
  p17$ = "      14:  Aqua MODIS\n";
  p18$ = "* Either ACCEPT the Default NUMBER,\n";
  p19$ = "* Or, SELECT a Different NUMBER.\n";
  p20$ = "* Then, CLICK the OK Button.\n\n";
  p21$ = "IMAGER-NUMBER SELECTED:";
  p$   = p1$ + p2$ + p3$ + p4$ + p5$ + p6$ + p7$ + p8$ + p9$;
  p$   = p$ + p10$ + p11$ + p12$ + p13$ + p14$ + p15$ + p16$;
  p$   = p$ + p17$ + p18$ + p19$ + p20$ + p21$;
  imager = PopupNum(p$,1,1,14,0);  
# ------------------------------------------------------------
# GENERATE IMAGER-SPECIFIC PARAMETERS: Refer to B25.
  if (imager == 1) then begin
     imager$ = "QuickBird 2 MS";
     pBL=1; pNA=1;
  end
  if (imager == 2) then begin
     imager$ = "Ikonos 2 MS"; pBL=1; pNA=1;
  end
  if (imager == 3) then begin
     imager$ = "OrbView 3 MS"; pBL=1; pNA=1;
  end
  if (imager == 4) then begin
     imager$ = "Landsat 7 ETM+";
     pBL=1; pNA=1; pMB=1; pMC=1;
  end
  if (imager == 5) then begin
     imager$ = "Landsat 5 TM";
     pBL=1; pNA=1; pMB=1; pMC=1;
  end
  if (imager == 6) then begin
     imager$ = "Landsat 5 MSS"; pRE=1; pNB=1;
  end
  if (imager == 7) then begin
     imager$ = "Landsat 4 TM"; 
     pBL=1; pNA=1; pMB=1; pMC=1;
  end
  if (imager == 8) then begin
     imager$ = "Landast 4 MSS"; pRE=1; pNB=1;
  end
  if (imager == 9) then begin
     imager$ = "Landsat 3 MSS"; pRE=1; pNB=1;
  end
  if (imager == 10) then begin
     imager$ = "Landsat 2 MSS"; pRE=1; pNB=1;
  end
  if (imager == 11) then begin
     imager$ = "Landsat 1 MSS"; pRE=1; pNB=1;
  end
  if (imager == 12) then begin
     imager$ = "Terra ASTER";
     pNA=1; pMB=1; pMC=1; pMD=1; pME=1;
     pMF=1; pMG=1;
     p1$ = "VNIR ONLY or ALL OPTION:\n";
     p2$ = "     OPTION 1: VNIR ONLY\n";
     p3$ = "     OPTION 2: ALL 9 BANDS\n";
     p4$ = "OPTION ENTERED:";
     p$ = p1$ + p2$ + p3$ + p4$;
     vnir = PopupNum(p$,2,1,2,0);
     if (vnir == 1) then begin
        pMB=0; pMC=0; pMD=0; pME=0;
        pMF=0; pMG=0;
     end
 end
  if (imager == 13) then begin
     imager$ = "Terra MODIS"; 
     pBL=1; pNA=1; pMA=1; pMB=1; pMC=1;
  end
  if (imager == 14) then begin
     imager$ = "Aqua MODIS";
     pBL=1; pNA=1; pMA=1; pMB=1; pMC=1;
  end
  printf("              IMAGER: %s\n",imager$);
# ------------------------------------------------------------
# GET SOIL-SEARCH PVI-WIDTH PARAMETER: Refer to C3.
  p1$ = "SOIL-SEARCH PVI-WIDTH ENTRY\n";
  p2$ = "  FORMAT: NNN\n";
  p3$ = "   RANGE: 2  to 500\n";
  p4$ = "* Either ACCEPT the Default WIDTH,\n";
  p5$ = "* Or, ENTER a Different WIDTH.\n";
  p6$ = "* Then, CLICK the OK Button.\n\n";
  p7$ = "SOIL-SEARCH PVI-WIDTH ENTERED:";
  p$  = p1$ + p2$ + p3$ + p4$ + p5$ + p6$ + p7$;
  wpvis = PopupNum(p$,200,2,500,0);
  pvi1s = 1000 - int(wpvis / 2);
  pvi2s = 1000 + int(wpvis / 2);
  printf("            SOIL BOX: ");
  printf("%4d < PVI < %4d\n",pvi1s,pvi2s);
# ------------------------------------------------------------
# GET SOIL-SEARCH PBI-MAX PARAMETER: Refer to C4.
  p1$ = "SOIL-SEARCH PBI-MAX ENTRY\n";
  p2$ = "  FORMAT: NNN\n";
  p3$ = "   RANGE: 500 to 2500\n";
  p4$ = "* Either ACCEPT the Default PBI-MAX,\n";
  p5$ = "* Or, ENTER a Different PBI-MAX.\n";
  p6$ = "* Then, CLICK the OK Button.\n\n";
  p7$ = "SOIL-SEARCH PBI-MAX ENTERED:";
  p$  = p1$ + p2$ + p3$ + p4$ + p5$ + p6$ + p7$;
  pbi2s = PopupNum(p$,1100,500,2500,0);
  pbi1s = int(0.3 * pbi2s);
  printf("                      ");
  printf("%4d < PBI < %4d\n",pbi1s,pbi2s);
# ------------------------------------------------------------
# GET VEG-SEARCH PVI-MIN PARAMETER: Refer to C5.
  p1$ = "VEG-SEARCH PVI-MIN ENTRY\n";
  p2$ = "  FORMAT: NNNN\n";
  p3$ = "   RANGE:  900 to 2500\n";
  p4$ = "* Either ACCEPT the Default PVI-MIN,\n";
  p5$ = "* Or, ENTER a Different PVI-MIN.\n";
  p6$ = "* Then, CLICK the OK Button.\n\n";
  p7$ = "VEG-SEARCH PVI-MIN ENTERED:";
  p$  = p1$ + p2$ + p3$ + p4$ + p5$ + p6$ + p7$;
  pvi1v = PopupNum(p$,1300,900,2500,0);
  printf("            ");
  printf("VEG TEST: %4d < PVI\n",pvi1v);
# ------------------------------------------------------------
# GET TEXTURE-FILTER PARAMETER FOR SOIL: Refer to C6.
  p1$ = "PURE-SOIL-PIXEL SOIL-SD-MAX ENTRY\n";
  p2$ = "  FORMAT: NN\n";
  p3$ = "   RANGE:  1 to 42\n";
  p4$ = "* Either ACCEPT the Default SOIL-SD-MAX,\n";
  p5$ = "* Or, ENTER a Different SOIL-SD-MAX.\n";
  p6$ = "* Then, CLICK the OK Button.\n\n";
  p7$ = "PURE-PIXEL SOIL-SD-MAX ENTERED:";
  p$  = p1$ + p2$ + p3$ + p4$ + p5$ + p6$ + p7$;
  sdmaxs = PopupNum(p$,14,1,42,0);
  printf("     SOIL PVI-SD MAX: %2d\n",sdmaxs);
  sdmaxv = int(sdmaxs * (pvi1v + 2000) / 2000);
# ------------------------------------------------------------
# TEXTURE-FILTER PARAMETER FOR VEG: Refer to C6.
  p1$ = "PURE-VEG-PIXEL VEG-SD-MAX ENTRY\n";
  p2$ = "  FORMAT: NN\n";
  p3$ = "   RANGE:  1 to 42\n";
  p4$ = "* Either ACCEPT the Default VEG-SD-MAX,\n";
  p5$ = "* Or, ENTER a Different PVI-SD-MAX.\n";
  p6$ = "* Then, CLICK the OK Button.\n\n";
  p7$ = "PURE-PIXEL PVI-SD-MAX ENTERED:";
  p$  = p1$ + p2$ + p3$ + p4$ + p5$ + p6$ + p7$;
  sdmaxv = PopupNum(p$,sdmaxv,1,84,0);
  printf("      VEG PVI-SD MAX: %2d\n",sdmaxv);
# ------------------------------------------------------------
# TEXTURE-FILTER BOX-SIZE: Refer to C6.
  p1$ = "PURE-PIXEL BOX-SIZE ENTRY\n";
  p2$ = "  FORMAT: NN\n";
  p3$ = "   RANGE:  3 to 11\n";
  p4$ = "    NOTE: MUST be an ODD INTEGER\n";
  p5$ = "* Either ACCEPT the Default BOX-SIZE,\n";
  p6$ = "* Or, ENTER a Different BOX-SIZE.\n";
  p7$ = "* Then, CLICK the OK Button.\n\n";
  p8$ = "PURE-PIXEL BOX-SIZE ENTERED:";
  p$  = p1$ + p2$ + p3$ + p4$ + p5$ + p6$ + p7$ + p8$;
  boxsize = PopupNum(p$,5,3,11,0);
  oddcheck = boxsize / 2 - int(boxsize * 1.01 / 2);
  if (oddcheck < 0.1) then boxsize = boxsize + 1;
  printf("     FILTER BOX SIZE: %d\n\n",boxsize); 
# ------------------------------------------------------------
# RASTER DATA TYPE (16-bit unsigned integers):
  rtype$ = "16-bit unsigned";
# ------------------------------------------------------------
# OPEN INPUT RASTERS:
  printf("LIST OF INPUT RASTERS:\n");
  if (pCB) then begin
     printf(" SRFICB");
     GetInputRaster( SRFICB);
     nlins = NumLins(SRFICB); ncols = NumCols(SRFICB);
     checkHisto(SRFICB);
  end
  if (pCB) then begin
     if (pBL) then begin
        printf(" SRFIBL");
        GetInputRaster(SRFIBL,nlins,ncols,rtype$);
        checkHisto(SRFIBL);
     end
  end
  else begin
     if (pBL) then begin
        printf(" SRFIBL");
        GetInputRaster(SRFIBL);
        checkHisto(SRFIBL);
        nlins = NumLins(SRFIBL); ncols = NumCols(SRFIBL);
     end
  end
  printf(" SRFIGL");
  if (pBL) then begin
     printf(" SRFIGL");
     GetInputRaster(SRFIGL,nlins,ncols,rtype$);
     checkHisto(SRFIGL);
  end
  else begin
     printf(" SRFIGL");
     GetInputRaster(SRFIGL);
     nlins = NumLins(SRFIGL); ncols = NumCols(SRFIGL);
     checkHisto(SRFIGL);
  end
  if (pYL) then begin
     printf(" SRFIYL");
     GetInputRaster(SRFIYL,nlins,ncols,rtype$);
     checkHisto(SRFIYL);
  end
  GetInputRaster(SRFIRL,nlins,ncols,rtype$); 
  if (pRE) then begin
     printf(" SRFIRE");
     GetInputRaster(SRFIRE,nlins,ncols,rtype$);
     checkHisto(SRFIRE);
  end
  if (pNA) then begin
     printf(" SRFINA");
     GetInputRaster(SRFINA,nlins,ncols,rtype$);
     checkHisto(SRFINA);
  end
  if (pNB) then begin
     printf(" SRFINB");
     GetInputRaster(SRFINB,nlins,ncols,rtype$);
     checkHisto(SRFINB);
  end
  if (pMA) then begin
     printf(" SRFIMA");
     GetInputRaster(SRFIMA,nlins,ncols,rtype$);
     checkHisto(SRFIMA);
  end
  if (pMB) then begin
     printf(" SRFIMB");
     GetInputRaster(SRFIMB,nlins,ncols,rtype$);
     checkHisto(SRFIMB);
  end
  if (pMC) then begin
     printf(" SRFIMC");
     GetInputRaster(SRFIMC,nlins,ncols,rtype$);
     checkHisto(SRFIMC);
  end
  if (pMD) then begin
     printf(" SRFIMD");
     GetInputRaster(SRFIMD,nlins,ncols,rtype$);
     checkHisto(SRFIMD);
  end
  if (pME) then begin
     printf(" SRFIME");
     GetInputRaster(SRFIME,nlins,ncols,rtype$);
     checkHisto(SRFIME);
  end
  if (pMF) then begin
     printf(" SRFIMF");
     GetInputRaster(SRFIMF,nlins,ncols,rtype$);
     checkHisto(SRFIMF);
  end
  if (pMG) then begin
     printf(" SRFIMG");
     GetInputRaster(SRFIMG,nlins,ncols,rtype$);
     checkHisto(SRFIMG);
  end
  GetInputRaster(MK,nlins,ncols,"binary");
  checkHisto(MK);
  printf(" MK");
  GetInputRaster(PVI,nlins,ncols,rtype$);
  checkHisto(PVI);
  printf(" PVI");
  GetInputRaster(PBI,nlins,ncols,rtype$);
  checkHisto(PBI);
  printf(" PBI\n\n");
# ------------------------------------------------------------
# SET UP OUTPUT RASTERS:
  printf("LIST OF OUTPUT RASTERS:\n");
  if (pCB) then begin
     printf(" DCB");
     GetOutputRaster(DCB,nlins,ncols,rtype$);
     IgnoreNull(DCB); CopySubobjects(SRFICB,DCB,"GEOREF");
     CopySubobjects(SRFICB,DCB,"CONTAB");
  end
  if (pBL) then begin
     printf(" DBL");
     GetOutputRaster(DBL,nlins,ncols,rtype$);
     IgnoreNull(DBL); CopySubobjects(SRFIBL,DBL,"GEOREF");
     CopySubobjects(SRFIBL,DBL,"CONTAB");
  end
  printf(" DGL");
  GetOutputRaster(DGL,nlins,ncols,rtype$);
  IgnoreNull(DGL); CopySubobjects(SRFIGL,DGL,"GEOREF");
  CopySubobjects(SRFIGL,DGL,"CONTAB");
  if (pYL) then begin
     printf(" DYL");
     GetOutputRaster(DYL,nlins,ncols,rtype$);
     IgnoreNull(DYL); CopySubobjects(SRFIYL,DYL,"GEOREF");
     CopySubobjects(SRFIYL,DYL,"CONTAB");
  end
  printf(" DRL");
  GetOutputRaster(DRL,nlins,ncols,rtype$);
  IgnoreNull(DRL); CopySubobjects(SRFIRL,DRL,"GEOREF");
  CopySubobjects(SRFIRL,DRL,"CONTAB");
  if (pRE) then begin
     printf(" DRE");
     GetOutputRaster(DRE,nlins,ncols,rtype$);
     IgnoreNull(DRE); CopySubobjects(SRFIRE,DRE,"GEOREF");
     CopySubobjects(SRFIRE,DRE,"CONTAB");
  end
  if (pNA) then begin
     printf(" DNA");
     GetOutputRaster(DNA,nlins,ncols,rtype$);
     IgnoreNull(DNA); CopySubobjects(SRFINA,DNA,"GEOREF");
     CopySubobjects(SRFINA,DNA,"CONTAB");
  end
  if (pNB) then begin
     printf(" DNB");
     GetOutputRaster(DNB,nlins,ncols,rtype$);
     IgnoreNull(DNB); CopySubobjects(SRFINB,DNB,"GEOREF");
     CopySubobjects(SRFINB,DNB,"CONTAB");
  end
  if (pMA) then begin
     printf(" DMA");
     GetOutputRaster(DMA,nlins,ncols,rtype$);
     IgnoreNull(DMA); CopySubobjects(SRFIMA,DMA,"GEOREF");
     CopySubobjects(SRFIMA,DMA,"CONTAB");
  end
  if (pMB) then begin
     printf(" DMB");
     GetOutputRaster(DMB,nlins,ncols,rtype$);
     IgnoreNull(DMB); CopySubobjects(SRFIMB,DMB,"GEOREF");
     CopySubobjects(SRFIMB,DMB,"CONTAB");
  end
  if (pMC) then begin
     printf(" DMC");
     GetOutputRaster(DMC,nlins,ncols,rtype$);
     IgnoreNull(DMC); CopySubobjects(SRFIMC,DMC,"GEOREF");
     CopySubobjects(SRFIMC,DMC,"CONTAB");
  end
  if (pMD) then begin
     printf(" DMD");
     GetOutputRaster(DMD,nlins,ncols,rtype$);
     IgnoreNull(DMD); CopySubobjects(SRFIMD,DMD,"GEOREF");
     CopySubobjects(SRFIMD,DMD,"CONTAB");
  end
  if (pME) then begin
     printf(" DME");
     GetOutputRaster(DME,nlins,ncols,rtype$);
     IgnoreNull(DME); CopySubobjects(SRFIME,DME,"GEOREF");
     CopySubobjects(SRFIME,DME,"CONTAB");
  end
  if (pMF) then begin
     printf(" DMF");
     GetOutputRaster(DMF,nlins,ncols,rtype$);
     IgnoreNull(DMF); CopySubobjects(SRFIMF,DMF,"GEOREF");
     CopySubobjects(SRFIMF,DMF,"CONTAB");
  end
  if (pMG) then begin
     printf(" DMG");
     GetOutputRaster(DMG,nlins,ncols,rtype$);
     IgnoreNull(DMG); CopySubobjects(SRFIMG,DMG,"GEOREF");
     CopySubobjects(SRFIMG,DMG,"CONTAB");
  end
# ------------------------------------------------------------
# SEARCH FOR BARE-SOIL & DENSE VEGETATION PIXELS:
# Refer to C7.
  printf("\n\nSEARCHING FOR BARE-SOIL & DENSE-VEG PIXELS.\n");
  printf("     This takes a few minutes.  Please Wait.\n");
  for each MK begin
     mk = MK;
     if (mk) then begin
        pvi = PVI;
#       BARE-SOIL & PVI-TEXTURE FILTER:
        if (pvi < pvi2s and pvi > pvi1s) then begin
           pbi = PBI;
           if (pbi < pbi2s and pbi > pbi1s) then begin
              pvisd = FocalSD(PVI,boxsize,boxsize);
              if (pvisd < sdmaxs) then begin
                 if (pCB) then DCB = SRFICB;
                 if (pBL) then DBL = SRFIBL;
                 DGL = SRFIGL;
                 if (pYL) then DYL = SRFIYL;
                 DRL = SRFIRL;
                 if (pRE) then DRE = SRFIRE;
                 if (pNA) then DNA = SRFINA;
                 if (pNB) then DNB = SRFINB;
                 if (pMA) then DMA = SRFIMA;
                 if (pMB) then DMB = SRFIMB;
                 if (pMC) then DMC = SRFIMC;
                 if (pMD) then DMD = SRFIMD;
                 if (pME) then DME = SRFIME;
                 if (pMF) then DMF = SRFIMF;
                 if (pMG) then DMG = SRFIMG;
              end
           end
        end
#       DENSE-VEG & PVI-TEXTURE FILTER:
        if (pvi > pvi1v) then begin
           pvisd = FocalSD(PVI,boxsize,boxsize);
           if (pvisd < sdmaxv) then begin
              if (pCB) then DCB = SRFICB;
              if (pBL) then DBL = SRFIBL;
              DGL = SRFIGL;
              if (pYL) then DYL = SRFIYL;
              DRL = SRFIRL;
              if (pRE) then DRE = SRFIRE;
              if (pNA) then DNA = SRFINA;
              if (pNB) then DNB = SRFINB;
              if (pMA) then DMA = SRFIMA;
              if (pMB) then DMB = SRFIMB;
              if (pMC) then DMC = SRFIMC;
              if (pMD) then DMD = SRFIMD;
              if (pME) then DME = SRFIME;
              if (pMF) then DMF = SRFIMF;
              if (pMG) then DMG = SRFIMG;
           end
        end
     end
  end
# ------------------------------------------------------------
# CREATE PYRAMIDS & CLOSE RASTERS: Refer to C7
  printf("\nCREATE PYRAMIDS & CLOSE RASTERS:\n");
  CloseRaster(PVI); CloseRaster(PBI);
  if (pCB) then begin
     printf(" DCB");
     CloseRaster(SRFICB);
     SetNull(DCB,0); CreateHistogram(DCB,0);
     CreatePyramid(DCB,0); CloseRaster(DCB);
  end
  if (pBL) then begin
     printf(" DBL");
     CloseRaster(SRFIBL);
     SetNull(DBL,0); CreateHistogram(DBL,0);
     CreatePyramid(DBL,0); CloseRaster(DBL);
  end
  printf(" DGL");
  CloseRaster(SRFIGL);
  SetNull(DGL,0); CreateHistogram(DGL,0);
  CreatePyramid(DGL,0); CloseRaster(DGL);
  if (pYL) then begin
     printf(" DYL");
     CloseRaster(SRFIYL);
     SetNull(DYL,0); CreateHistogram(DYL,0);
     CreatePyramid(DYL,0); CloseRaster(DYL);
  end
  printf(" DRL");
  CloseRaster(SRFIRL);
  SetNull(DRL,0); CreateHistogram(DRL,0);
  CreatePyramid(DRL,0); CloseRaster(DRL);
  if (pRE) then begin
     printf(" DRE");
     CloseRaster(SRFIRE);
     SetNull(DRE,0); CreateHistogram(DRE,0);
     CreatePyramid(DRE,0); CloseRaster(DRE);
  end
  if (pNA) then begin
     printf(" DNA");
     CloseRaster(SRFINA);
     SetNull(DNA,0); CreateHistogram(DNA,0);
     CreatePyramid(DNA,0); CloseRaster(DNA);
  end
  if (pNB) then begin
     printf(" DNB");
     CloseRaster(SRFINB);
     SetNull(DNB,0); CreateHistogram(DNB,0);
     CreatePyramid(DNB,0); CloseRaster(DNB);
  end
  if (pMA) then begin
     printf(" DMA");
     CloseRaster(SRFIMA);
     SetNull(DMA,0); CreateHistogram(DMA,0);
     CreatePyramid(DMA,0); CloseRaster(DMA);
  end
  if (pMB) then begin
     printf(" DMB");
     CloseRaster(SRFIMB);
     SetNull(DMB,0); CreateHistogram(DMB,0);
     CreatePyramid(DMB,0); CloseRaster(DMB);
  end
  if (pMC) then begin
     printf(" DMC");
     CloseRaster(SRFIMC);
     SetNull(DMC,0); CreateHistogram(DMC,0);
     CreatePyramid(DMC,0); CloseRaster(DMC);
  end
  if (pMD) then begin
     printf(" DMD");
     CloseRaster(SRFIMD);
     SetNull(DMD,0); CreateHistogram(DMD,0);
     CreatePyramid(DMD,0); CloseRaster(DMD);
  end
  if (pME) then begin
     printf(" DME");
     CloseRaster(SRFIME);
     SetNull(DME,0); CreateHistogram(DME,0);
     CreatePyramid(DME,0); CloseRaster(DME);
  end
  if (pMF) then begin
     printf(" DMF");
     CloseRaster(SRFIMF);
     SetNull(DMF,0); CreateHistogram(DMF,0);
     CreatePyramid(DMF,0); CloseRaster(DMF);
  end
  if (pMG) then begin
     printf(" DMG");
     CloseRaster(SRFIMG);
     SetNull(DMG,0); CreateHistogram(DMG,0);
     CreatePyramid(DMG,0); CloseRaster(DMG);
  end
  printf("\n\n");
  printf("FOR ANALYSIS HINTS: Read FAQs_by_Jack: C\n");
  printf("                    Especially: C8\n");