Unidata McIDAS-X
McBASI script, CFILLCLP.MCB
REM ? CFILLCLP.MCB - Produce a color-filled rendition of a gridded data set
REM ?
REM ? Name: CFILLCLP.MCB
REM ?
REM ? Purpose: Produce a color-filled rendition of a gridded data set
REM ? that may be clipped so that the represented values exist
REM ? only over non-water areas.
REM ?
REM ? Invocation:
REM ?
REM ? RUN iiii ppp lll ddd ttt fff pro ooo c d sss xxx FILE=CFILLCLP.MCB
REM ? ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^___^_ scratch image dataset members
REM ? | | | | | | | | | |________ display image (Y/N)?
REM ? | | | | | | | | |__________ clip the image at land (Y/N)?
REM ? | | | | | | | |_____________ ADDE image dataset member
REM ? | | | | | | |_________________ grid parameter projection
REM ? | | | | | |_____________________ grid parameter forecast hour
REM ? | | | | |_________________________ grid parameter time
REM ? | | | |_____________________________ grid parameter day
REM ? | | |_________________________________ grid parmater level
REM ? | |_____________________________________ grid parameter name
REM ? |_________________________________________ ADDE input GRID dataset
REM ?
REM ? Method:
REM ?
REM ? CFILLCLP.MCB basically:
REM ? o gets a listing of the specified grid so that its
REM ? shape (nrows,ncols) is known; the shape is used
REM ? to set the scale factors for the resultant image
REM ? representation of the GRID
REM ? o turns the specified grid into an image
REM ? o optionally clips the resultant image at the land-water
REM ? boundary
REM ? o updates the resultant image with the correct DAY and TIME
REM ? o displays the composite image if the user asked for it
REM ?
REM ? NOTES:
REM ?
REM ? 1) IMORTANT: You can not default positional parameters with
REM ? an 'X'. If you do, that positional parameter is interpreted
REM ? as a space by RUN. Use 'N' for a place holder for character
REM ? positionals.
REM ?
REM ? 2) The dataset element TOPO/GLOB must be available in order to
REM ? clip the output at land/sea boundaries
REM ?
REM ? EXAMPLE:
REM ?
REM ? RUN RTGRIDS/ETA T 850 N N 12 LAMB MYDATA/IMAGES.3020 Y Y FILE=CFILLCLP.MCB
REM ?
REM History: 19980602 - Created for the COMET Faculty SatMet course
REM 19990720 - Updated for Unidata McIDAS-X 7.60
REM 20000714 - Added support for grid projection
REM Added SIZE= to IMGFILT commands; preserves
REM calculate output image size
REM Changed map color to level 8 (gray in GRAPHIC.GRX)
REM Add projection to command line
REM 20020330 - Added centering of image display
REM ? ----------
REM Definition of variables used in the following:
REM
REM Variable Use
REM Input: I$ ADDE GRID data set to copy from
REM J$ GRID projection string
REM P$ gridded Parameter name
REM L$ gridded parameter Level
REM D$ gridded parameter Day
REM T$ gridded parameter Time
REM F$ gridded parameter Forecast time
REM R$ gridded parameter pRojection
REM O$ ADDE Output image dataset member
REM C$ Clip the image at land-water boundary (Y/N)?
REM L$ dispLay the resultant composite image (Y/N)?
REM S$ ADDE Scratch member #1
REM X$ ADDE scratch member #2
REM Internal: L counter
REM N position number in output dataset
REM P$ projection of input grid
REM R number of rows in input grid
REM C number of columns in input grid
REM S1 line scale factor for output image (calculated)
REM S2 element scale factor for output image (calculated)
REM
REM First, get input ADDE dataset members and nominal image time
1 INPUT I$, P$, L$, D$, T$, F$, R$, O$, C$, V$, S$, X$
REM Check to make sure that the input GRID dataset was specified
IF I$ = "" STOP "You must specify an input GRID ADDE dataset"
REM Check to make sure that the PARameter was specified
IF P$ = "" STOP "You must specify a parameter name "
P$ = "PAR=" + P$
REM Check the input level. If not set, default it
IF L$ <> "N" LET L$ = " LEV=" + L$:GOTO 2
L$ = ""
REM Check the input DAY.
2 IF D$ <> "N" LET D$ = " DAY=" + D$:GOTO 3
D$ = ""
REM Check the input TIME.
3 IF T$ <> "N" LET T$ = " TIME=" + T$:GOTO 4
T$ = ""
REM Check the input Forecast TIME.
4 IF F$ <> "N" LET F$ = " FHOUR=" + F$:GOTO 5
F$ = ""
REM Check the input projection.
5 IF R$ <> "N" LET R$ = " GPRO=" + R$:GOTO 6
R$ = ""
REM Check to make sure that output ADDE image dataset member was specified
6 IF O$ = "" PRINT "You must specify an output ADDE image dataset member":STOP
PRINT "Output dataset member: ";O$
N = INDEX(O$,".")
IF N <> 0 GOTO 7
STOP "You must specify a position in the output dataset " + O$
REM See if the user wants to clip the resulting image at land-water boundaries
7 IF C$ = "" LET C$ = "Y" GOTO 8
IF MID$(C$,1,1) = "Y" LET C$ = "Y"
REM See if user wants to load the resulting composite image
8 IF V$ = "" LET V$ = "Y":GOTO 9
IF MID$(V$,1,1) <> "Y" LET V$ = "N"
REM Get scratch member or specify default
9 IF S$ = "" LET S$ = "MYDATA/IMAGES.9990":GOTO 10
IF MID$(S$,1,1) = "N" LET S$ = "MYDATA/IMAGES.9990"
REM Get second scratch member or specify default
10 IF X$ = "" LET X$ = "MYDATA/IMAGES.9991":GOTO 11
IF MID$(X$,1,1) = "N" LET X$ = "MYDATA/IMAGES.9991"
REM Check to see that the grid exists; if not exit with a warning
11 KEYIN "GRDLIST ";I$;" ";P$;L$;D$;T$;F$;R$;" FORM=ALL DEV=F GRDLST.OUT"
OPEN "GRDLST.OUT",10,80
INPUT @10,A$:INPUT @10,A$:INPUT @10,A$:INPUT @10,Z$
IF MID$(A$,1,4) <> EOF$ GOTO 20
STOP "GRDLIST from " + I$ + " failed"
20 J$ = MID$(Z$,77,4)
INPUT @10,A$:CLOSE 10
R = VAL(MID$(A$,27,4))
C = VAL(MID$(A$,45,4))
REM Get frame size and set scaling factors
30 S = PEEK(PEEK(-1) + 3000)
E = INT( S / 65536 )
L = S - (65536 * E)
S1 = INT(L/R)
S2 = INT(E/C)
IF J$ = "MERC" GOTO 40
IF S1 < S2 LET S2 = S1
IF S2 < S1 LET S1 = S2
REM Use the GRDIMG ADDE command to convert the GRID data set object
REM to an image object
40 KEYIN "GRDIMG ";I$;" ";O$;" MAG=";S1;" ";S2;" ";P$;L$;D$;T$;F$;R$
REM Create a filter mask if the user wants the output clipped at land-sea
50 IF C$ = "N" GOTO 60
KEYIN "IMGCOPY ";O$;" ";S$;" SIZE=ALL DEV=NNN"
KEYIN "IMGREMAP TOPO/GLOB ";S$;" SMOOTH=YES DEV=NNN"
KEYIN "IMGFILT ";S$;" ";S$;" ";X$;" FILTER=CORE 149 149 255 0 SIZE=ALL DEV=NNN"
KEYIN "IMGFILT ";O$;" ";X$;" ";S$;" FILTER=DIS 0 255 1 255 0 SIZE=ALL DEV=NNN"
KEYIN "IMGCOPY ";S$;" ";O$;" SIZE=ALL DEV=NNN"
REM Adjust the image directory entries to reflect the actual grid day/time
60 D$ = MID$(Z$,56,5)
T$ = MID$(Z$,62,8)
M$ = MID$(Z$,1,27)
KEYIN "IMGCHA ";O$;" DAY=";D$;" TIME=";T$;" MEMO='";M$;"'"
REM Display the image if the user asked for it
70 IF V$ <> "Y" GOTO 900
L = INT( (R*S1)/2 )
E = INT( (C*S2)/2 )
KEYIN "IMGDISP ";O$;" LINELE=";L;" ";E;" PLACE=CENTER EU=BREF SF=YES REFRESH='ERASE G;MAP SAT 8'"
REM Delete scratch data member
900 KEYIN "IMGDEL ";S$;" DEV=NNN"
KEYIN "IMGDEL ";X$;" DEV=NNN"
REM Done!
999 PRINT "CFILLCLP: Done":STOP