!
! This is the mars check file
!
! Each request is checked again each rule
! The rules have the following syntax:
!
!   RULE   ---> if TEST then ACTION 
!
!
!   TEST   ---> PARAMETER  =  VALUE
!          ---> PARAMETER  >  VALUE
!          ---> PARAMETER  <  VALUE
!          ---> PARAMETER  >= VALUE
!          ---> PARAMETER  <= VALUE
!          ---> PARAMETER  <> VALUE
!          ---> PARAMETER  in LIST_OF_VALUES
!          ---> not TEST
!          ---> TEST and TEST
!          ---> TEST or TEST
!          ---> ( TEST )
!
!
!   ACTION ---> error    MESSAGE
!          ---> warning	 MESSAGE
!          ---> info	 MESSAGE
!          ---> mail	 MESSAGE
!          ---> set      PARAMETER = VALUE
!          ---> unset    PARAMETER 
!
!
!
! B.Raoult
! Wed Feb 13 15:07:49 GMT 1991
!

# Remove access to marsodb
%if (_VERB = ARCHIVE %or 
	 _VERB = STAGE %or 
	 _VERB = FLUSH %or 
	 _VERB = REMOVE)
	%and DATABASE=marsodb %then
	%unset DATABASE

%include "oldrd.chk"


%if CLASS = OD %and (TYPE = CM %or TYPE = CS %or TYPE = CR) %and DOMAIN = G %then 
	%warning "Domain forced to E"
	%set DOMAIN = E

%if (TYPE = IM %or TYPE = SIM %or TYPE = OLDIM) %and STREAM <> SSMI %then
	%set REPRES = SV
	%unset PARAM
	%unset LEVTYPE
	%unset LEVELIST
	%unset RESOL
	%unset DUPLICATES 
	%unset GRID 
	%unset ROTATION 

# Simulated radiances
%if (TYPE = SSD) %then
	%unset LEVTYPE
	%unset LEVELIST


%if (TYPE = IM  %or TYPE = OLDIM) %and STREAM <> SSMI %then
	%unset STEP


%if TYPE = OB %or TYPE = FB  %or STREAM = SSMI %or TYPE = AI %or TYPE = AF %or TYPE = AB %or TYPE = OFB %or TYPE = MFB %or TYPE = OAI %then 
	%set REPRES = BU
	%unset PARAM  
	%unset STEP  
	%unset LEVTYPE  
	%unset LEVELIST  
	%unset GRID 
	%unset ROTATION 

%if TYPE = TF %then
	%set REPRES = BU
	%unset PARAM
	%unset LEVTYPE
	%unset LEVELIST
	%unset GRID 
	%unset ROTATION

%if TYPE = AB %then
	%unset TIME

%if TYPE = OB %or TYPE = FB %then
	%unset ORDER

%if TYPE = CL %then
	%unset STEP

%if LEVTYPE = SFC %or LEVTYPE = WAVE %then 
	%unset LEVELIST

%if LEVTYPE = SFC %and CLASS = OD %and STREAM = OPER %then
	%set REPRES = GG

%if LEVTYPE = SFC %and CLASS = ER %and STREAM = OPER %and (TYPE = AN %or TYPE = FC) %and (%not REPRES) %then
	%set REPRES = GG

%if LEVTYPE = SFC %and CLASS = OD %and STREAM = OPER %and (TYPE = IA %or TYPE = AN) %and DATE < 19830420 %then
	%set REPRES = LL

%if (_VERB = RETRIEVE %and TYPE = TU) %then
	%set REPRES = LL

%if %not ( TYPE = OLDIM %or TYPE = OB %or TYPE = FB %or TYPE = AI %or TYPE = AF %or TYPE = AB %or TYPE = TF %or TYPE = OFB %or TYPE = MFB %or TYPE = OAI) %then 
	%unset OBSTYPE 
	%unset OBSGROUP 
	%unset DUPLICATES 

%if %not ( TYPE = IM %or TYPE = OLDIM %or TYPE = SIM %or TYPE = OB %or TYPE = FB %or TYPE = AI %or TYPE = AF %or TYPE = AB %or TYPE = TF %or TYPE = OFB %or TYPE = MFB %or TYPE = SSD %or TYPE=OAI) %then 
	%unset IDENT 

%if _VERB = LIST %and %not OBSGROUP %and (TYPE = OB %or TYPE = FB %or TYPE = AI %or TYPE = AF %or TYPE = AB %or TYPE = TF %or TYPE = OFB %or TYPE = MFB %or TYPE=OAI) %then
	%set OBSGROUP = ALL

%if GRID=O  %and (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %then %unset GRID
%if GRID=AV  %and (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %then %unset GRID

# READ can have RESOL=AUTO and GRID=ANY 
%if (RESOL=AUTO %or RESOL=AV) %and ((%not GRID) %or (GRID = ANY)) %then %unset RESOL

%if (STYLE = DISSEMINATION) %and (RESOL=AUTO %or (%not RESOL)) %then 
	%warning "Force RESOL=AV when STYLE=DISSEMINATION"
	%set RESOL=AV

%if AREA = E %then
	%set AREA = 73.5/-27/33/45

%if (AREA = G %or AREA = GLOBE) %and (_APPL = diss) %then
	%warning "Expand global AREA for dissemination to AREA = 90/0/-90/359.99"
	%set AREA = 90/0/-90/359.99

%if AREA = G %then
	%set _AREA_N = 0
	%set _AREA_W = 0
	%set _AREA_S = 0
	%set _AREA_E = 0

%if AREA = G %and (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %then %unset AREA
%if AREA = GLOBE %and (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %then %unset AREA

%if FORMAT = P %or FORMAT = PACKED  %then %unset FORMAT

# %if FORMAT %then %warning "Format is not yet implemented" %unset FORMAT


%if USE = NORMAL     %then %unset USE
%if USE = STAGE     %then %set TARGET="/dev/null" %unset FIELDSET %set EXPECT=0
%if COSTONLY = N %then %unset COSTONLY

%if (CLASS = EI) %and (GRID = 128 %or GRID=0.75) %then 
    %warning "For full resolution grid, it is recommended to use RESOL=AV to prevent any truncation before transformation"


!
!
!
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and CLASS=ANY     %then %unset CLASS
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and STREAM=ANY    %then %unset STREAM
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and MODEL=ANY     %then %unset MODEL
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and LEVTYPE=ANY   %then %unset LEVTYPE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and LEVELIST=ANY  %then %unset LEVELIST
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and TYPE=ANY      %then %unset TYPE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and PARAM=ANY     %then %unset PARAM
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and DATE=ANY      %then %unset DATE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and TIME=ANY      %then %unset TIME
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and STEP=ANY      %then %unset STEP
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and ANOFFSET=ANY %then %unset ANOFFSET
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and AREA=ANY      %then %unset AREA
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and GRID=ANY      %then %unset GRID
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and ROTATION=ANY  %then %unset ROTATION
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and STYLE=ANY     %then %unset STYLE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and RESOL=ANY     %then %unset RESOL
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and ORDER=0       %then %unset ORDER
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and EXPVER=ANY    %then %unset EXPVER
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and REFERENCE=ANY %then %unset REFERENCE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and DOMAIN=ANY    %then %unset DOMAIN
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and ORIGIN=ANY    %then %unset ORIGIN
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and CHANNEL=ANY   %then %unset CHANNEL
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and RANGE=ANY     %then %unset RANGE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and LEADTIME=ANY  %then %unset LEADTIME
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and OPTTIME=ANY   %then %unset OPTTIME

%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and PADDING=ANY     %then %unset PADDING
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and SYSTEM=ANY     %then %unset SYSTEM
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and METHOD=ANY     %then %unset METHOD
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and PRODUCT=ANY     %then %unset PRODUCT
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and SECTION=ANY     %then %unset SECTION
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and LATITUDE=ANY     %then %unset LATITUDE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and LONGITUDE=ANY     %then %unset LONGITUDE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and NUMBER=ANY     %then %unset NUMBER
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and QUANTILE=ANY     %then %unset QUANTILE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and ITERATION=ANY     %then %unset ITERATION
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and DIAGNOSTIC=ANY     %then %unset DIAGNOSTIC
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and INSTRUMENT=ANY     %then %unset INSTRUMENT
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and FILTER=ANY     %then %unset FILTER
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and INTERPOLATION=ANY     %then %unset INTERPOLATION
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and REFDATE=ANY     %then %unset REFDATE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and HDATE=ANY     %then %unset HDATE
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and FREQUENCY=ANY     %then %unset FREQUENCY
%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and DIRECTION=ANY     %then %unset DIRECTION




%if TYPE <> CF %and TYPE <> PF %and TYPE <> CV %then %unset ENSEMBLE
%if TYPE <> CM %and TYPE <> CS  %then %unset CLUSTER
%if TYPE <> FP %then %unset PROBABILITY


#%if TYPE <> CF %and 
%if TYPE <> PF %and 
	TYPE <> CM %and 
	TYPE <> CS %and 
	TYPE <> CR %and 
	TYPE <> CV %and 
	TYPE <> SV %and 
	TYPE <> AS %and 
	TYPE <> FP %and 
	TYPE <> ED %and 
	TYPE <> TU %and 
	TYPE <> CI %and
	TYPE <> ME %and 
	TYPE <> FF %and           # Ocean
	TYPE <> ICP %and 
	TYPE <> SOT %and 
	TYPE <> FCMEAN %and
	TYPE <> FCMAX %and
	TYPE <> FCMIN %and
	TYPE <> FCSTDEV %and
	TYPE <> SVAR %and
	CLASS <> TI %and
	CLASS <> S2 %and
	STREAM <> MOFC %and 
	STREAM <> WAMF %and 
	STREAM <> MOFM %and 
	STREAM <> WMFM %and 
	STREAM <> SEAS %and 
	STREAM <> WASF %and
	STREAM <> WAMF %and
	STREAM <> SFMM %and
	STREAM <> SMMA %and
	STREAM <> SEAP %and 
	STREAM <> SWMM %and
	STREAM <> OCEA %and
# New Monthly Forecast
	STREAM <> MNFC %and
    STREAM <> MNFH %and
    STREAM <> MNFA %and
    STREAM <> MNFW %and
    STREAM <> MFHW %and
    STREAM <> MFAW %and
    STREAM <> MNFM %and
    STREAM <> MFHM %and
    STREAM <> MFAM %and
    STREAM <> MFWM %and
    STREAM <> MHWM %and
    STREAM <> MAWM %and
# New Multi-model
	STREAM <> MMSF %and 
	STREAM <> MSMM %and 
	STREAM <> WAMS %and 
	STREAM <> MSWM %and 
	STREAM <> MMSA %and 
# Ensemble Data Assimilation
	STREAM <> ENDA %and 
	STREAM <> EWDA %and 
	STREAM <> EDMM %and 
	STREAM <> EDMO %and 
	STREAM <> EWMM %and 
	STREAM <> EWMO %and 
	STREAM <> ELDA %and 
	STREAM <> EWLA %and 
# Ensemble Supplementary data
	STREAM <> ESPD %and 
# Multi-model Multi-annual
	STREAM <> MMAF %and 
	STREAM <> MMAM %and 
	STREAM <> MMAW %and 
	STREAM <> MMWM %and 
	STREAM <> SEAS %then
	%unset NUMBER

%if STREAM <> ENFH %and 
	STREAM <> ENWH %and
	STREAM <> EFHO %and
	STREAM <> EHMM %and
	STREAM <> EWHO %then
	%unset HDATE

%if (TYPE <> PD %and 
    TYPE <> CD %and
    TYPE <> PB) %then
	%unset QUANTILE

%if ( STREAM = MNFM %or
	STREAM = MFHM %or
    STREAM = MFAM %or
    STREAM = MFWM %or
    STREAM = MHWM %or
    STREAM = ESMM %or
    STREAM = EHMM %or
    STREAM = MAWM )
	%then
	%unset STEP

%if ( STREAM = MFHM %and
	( TYPE = EM %or TYPE = ES %or TYPE = SES) )
	%then 
	%unset DATE

%if ( STREAM = MNFH %and
	( TYPE = EM %or TYPE = ES %or TYPE = SES %or TYPE = ED ) )
	%then
	%unset DATE

%if (_VERB = RETRIEVE %or _VERB = ARCHIVE) %and 
	(STREAM <> MOFC %and STREAM <> WAMF %and STREAM <> MOFM %and STREAM <> WMFM) %and 
	(TYPE = CF %or TYPE = EM %or TYPE = ES %or TYPE = SES %or TYPE = TAEM %or TYPE = TAES) %then 
	%unset ENSEMBLE %unset NUMBER

! For read
%if _VERB = READ %and CLASS  <> ANY %then %warning "CLASS  ignored in READ"
%if _VERB = READ %and REPRES <> ANY %then %warning "REPRES ignored in READ"

%if _VERB = READ %then 
	%unset CLASS 
	%unset REPRES

%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %and TYPE = FG %and STEP = 0 %and STREAM = OPER  
	%then 
		%warning "First Guess step 0 removed"
		%error   "Please, use STEP=06 instead"


! =========================================
! For wave, there is no step for FG
%if (STREAM = WAVE %or STREAM = SCWV %or STREAM = DCWV) %and TYPE = FG %and STEP <> 0 %then 
	%warning "For wave first-guess, step is ignored and set to zero"
	%set     STEP = 0

! =========================================
! There are no waves in altitude
%if STREAM = WAVE %or 
	STREAM = WAEF %or 
	STREAM = WEHS %or 
	STREAM = WEOV %or 
	STREAM = WAMO %or 
	STREAM = SCWV %or 
	STREAM = DCWV %or 
	STREAM = WVHC %or
	STREAM = EWHC %or
	STREAM = MAWV %or
	STREAM = WASF %or 
	STREAM = WAMF %or
	STREAM = WMFM %or
	STREAM = SWMM %or
	STREAM = MNFW %or
	STREAM = MFHW %or
	STREAM = MFAW %or
	STREAM = MFWM %or
	STREAM = MHWM %or
	STREAM = MAWM %or
	STREAM = WAMS %or
	STREAM = DACW %or
	STREAM = EWDA %or
	STREAM = LWWV %or
	STREAM = EWLA %or
	STREAM = EWMM %or
	STREAM = EWMO %or
	STREAM = MSWM %then

	%warning "For wave data, LEVTYPE forced to Surface"
	%set     LEVTYPE = SFC
	%unset   LEVELIST

!===========================================================

!
! Avoid use of ENSEMBLE, CLUSTER and PROBABILITY in new MARS retrieval editors

%if TYPE = PF %and ENSEMBLE = OFF %then %unset ENSEMBLE
%if (TYPE = CM %or TYPE = CS %or TYPE = CR) %and CLUSTER = OFF %then %unset CLUSTER
%if (TYPE = FP) %and PROBABILITY = OFF %then %unset PROBABILITY

%if STREAM <> WAVE %and 
	STREAM <> SCWV %and 
	STREAM <> DCWV %and 
	STREAM <> MAWV %and 
	STREAM <> WASF %and 

	STREAM <> WAEF %and 
	STREAM <> EWDA %and 

	STREAM <> MNFW %and 
	STREAM <> MFHW %and 
	STREAM <> MFAW %and 

	STREAM <> WVHC %and
	STREAM <> EWHC %and

	STREAM <> ENWH %and
	STREAM <> EWHO %and

	STREAM <> LWWV %and
	STREAM <> EWLA %and

	STREAM <> WAMF %then 
	%unset FREQUENCY %unset DIRECTION

! Avoid visiting all mars tree on the server
%if (_VERB = LIST %and OUTPUT <> BROWSER %and (%not CLASS))   %then 
	%warning "Missing CLASS. Force to Operations"
	%set CLASS= OD

%if (_VERB = LIST %and OUTPUT <> BROWSER %and CLASS <> RD  %and (%not DATE) %and (%not PSEUDODATE) ) %then 
	%warning "Missing DATE. Force to yesterday"
	%set DATE = -1

%if (_VERB = LIST %and OUTPUT <> BROWSER %and CLASS <> RD  %and (%not STREAM) ) %then 
	%warning "Missing STREAM. Force to Daily archive"
	%set STREAM = OPER

%if (_VERB = LIST %and OUTPUT <> BROWSER %and CLASS <> RD  %and (%not EXPVER) ) %then 
	%warning "Missing EXPVER. Force to 1"
	%set EXPVER = 1

%if (_VERB = LIST %and OUTPUT <> BROWSER %and CLASS <> RD  %and (%not TYPE) ) %then 
	%warning "Missing TYPE. Force to Analysis"
	%set TYPE = AN

%if (_VERB = LIST %and OUTPUT <> BROWSER %and CLASS = RD  %and (%not EXPVER) ) %then 
	%error "Missing EXPVER. Please, specify one"

%if (_VERB = LIST %and OUTPUT = TREE %and (%not HIDE)) %then 
	%set HIDE=FILE/LENGTH/MISSING/OFFSET/ID/COST/MONTH/YEAR


! Observation retrieval from new MARS
%if (_VERB = RETRIEVE %and (STREAM = SSBT %or STREAM = E1)) %then
	%warning "Changed STREAM to OPER"
	%set STREAM = OPER

%if (_VERB = RETRIEVE %and STREAM = SSMI) %then
	%warning "Changed STREAM=OPER, TYPE=OB"
	%set STREAM = OPER
	%set TYPE = OB

%if (ACCURACY = N) %and (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %then
	%unset ACCURACY

%if (ACCURACY = R %or ACCURACY = L) %then
	%warning "ACCURACY Low or Reduced force to 8 bits"
	%set ACCURACY = 8

%if (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) 
	%and _VERB = RETRIEVE 
	%and SOURCE 
	%and (%not DATABASE) %then
	%set DATABASE = file

%if (_VERB = ARCHIVE %or 
	 _VERB = FLUSH %or 
	 _VERB = STAGE %or 
	 _VERB = LIST %or 
	 _VERB = REMOVE)
	%and (EXPVER=fdy1) 
	%and (%not DATABASE) %then
	%set DATABASE = mars grib2


%if (_VERB = ARCHIVE %or 
	 _VERB = FLUSH %or 
	 _VERB = STAGE %or 
	 _VERB = LIST %or 
	 _VERB = REMOVE)
	%and (CLASS=E4 %or 
	      CLASS=EI %or
		  CLASS=ER %or 
		  CLASS=PV %or 
		  CLASS=DM %or 
		  CLASS=CS %or 
		  CLASS=TO %or 
		  CLASS=DT %or 
		  CLASS=EL %or 
		  CLASS=YT %or 
		  CLASS=MC %or 
		  CLASS=EM %or 
		  CLASS=E2 %or 
		  CLASS=NR %or 
		  CLASS=J5 %or 
		  CLASS=RM %or 
		  CLASS=ME %or 
		  CLASS=EN) 
	%and (%not DATABASE) %then
	%set DATABASE = marser

%if (_VERB = ARCHIVE %or 
	 _VERB = FLUSH %or 
	 _VERB = STAGE %or 
	 _VERB = LIST %or 
	 _VERB = REMOVE)
	%and (CLASS=TI %or
	      CLASS=S2)
	%and (%not DATABASE) %then
	%set DATABASE = marsth

%if (_VERB = ARCHIVE %or 
	 _VERB = STAGE %or 
	 _VERB = FLUSH %or 
	 _VERB = LIST %or 
	 _VERB = REMOVE)
	%and CLASS=OD 
	%and EXPVER < 10
	%and (%not DATABASE) %then
	%set DATABASE = marsod

%if (_VERB = ARCHIVE %or 
	 _VERB = STAGE %or 
	 _VERB = FLUSH %or 
	 _VERB = LIST %or 
	 _VERB = REMOVE)
	%and CLASS=OD 
	%and EXPVER > 9
	%and (%not DATABASE) %then
	%set DATABASE = marsode

%if (_VERB = ARCHIVE %or 
	 _VERB = STAGE %or 
	 _VERB = FLUSH %or 
	 _VERB = LIST %or 
	 _VERB = REMOVE)
	%and (CLASS=CO %or CLASS=SR %or CLASS=LA %or CLASS=MS)
	%and (%not DATABASE) %then
	%set DATABASE = marsms

%if (_VERB = ARCHIVE %or 
	 _VERB = FLUSH %or 
	 _VERB = STAGE %or 
	 _VERB = REMOVE %or 
	 _VERB = LIST)
	%and (CLASS<>E4 %and 
	      CLASS<>EI %and
	      CLASS<>TI %and
	      CLASS<>S2 %and
		  CLASS<>ER %and 
		  CLASS<>PV %and 
		  CLASS<>DM %and 
		  CLASS<>OD %and 
		  CLASS<>TO %and
		  CLASS<>DT %and
		  CLASS<>EN %and
		  CLASS<>CO %and
		  CLASS<>RM %and
		  CLASS<>SR %and
		  CLASS<>LA %and
		  CLASS<>EL %and
		  CLASS<>MS %and
		  CLASS<>ME %and
		  CLASS<>EM %and
		  CLASS<>E2 %and
		  CLASS<>MC %and
		  CLASS<>NR %and
		  CLASS<>J5 %and
		  CLASS<>RM %and
		  CLASS<>CS)
	%and (%not DATABASE) %then
	%set DATABASE = marsrd

# ocean
%if LEVTYPE = DP
	%and (SECTION = M %or SECTION = Z) 
	%and (PRODUCT = INST %or PRODUCT = TACC %or PRODUCT = TAVG)
	%then
	%unset LEVELIST

# Special case for TIMS, V
%if LEVTYPE = DP
	%and SECTION = V
	%and PRODUCT = TIMS 
	%then
	%unset LEVELIST

%if LEVTYPE = DP
	%and TYPE = OR
	%and (%not PRODUCT)
	%then
		%warning "Default PRODUCT for Ocean ReAnalysis set to Instantaneous"
		%set PRODUCT = INST


# Year & month
%if _VERB = RETRIEVE %and (YEAR %or MONTH) %then
	%unset DATE

# Boundary Conditions (BC)
%if _VERB = RETRIEVE %and CLASS = OD %and TIME = 00 %and STREAM = OPER %and DATE >= 20000906 %and EXPVER = 02
%then 
	%warning "From 20000906 onwards, please use EXPVER=1"
	%warning "STREAM=SCDA for Boundary Conditions Project data"

%if _VERB = RETRIEVE %and CLASS = OD %and TIME = 00 %and STREAM = WAVE %and DATE >= 20000906 %and EXPVER = 02
%then 
	%warning "From 20000906 onwards, please use EXPVER=1"
	%warning "STREAM=SCWV for Boundary Conditions wave data"

%if (_VERB = ARCHIVE %and (STREAM = SFMM %or STREAM = SWMM %or STREAM = SMMA) %and VERIFY) %then
	%error "Please, use FCMONTH instead of VERIFY for archiving"
	%error "Exiting..."

%if ((CLASS <> OD %and CLASS <> EN %and CLASS <> ME) %and SYSTEM ) %then
	%unset SYSTEM

# A bit of paranoia...

%if _VERB = REMOVE %and CLASS = OD %and %not DATABASE %then
	%set DATABASE = dhstest
	
# That should be disabled in mars.def anyway

%if _VERB = REMOVE %and (
	CLASS = ER %or
	CLASS = E4 %or 
	CLASS = EI %or 
	CLASS = EM %or 
	CLASS = E2 %or 
	CLASS = CS %or 
	CLASS = PV %or 
	CLASS = TO %or 
	CLASS = DT %or 
	CLASS = PE %or 
	CLASS = MC %or 
	CLASS = ME %or 
	CLASS = DM
	) %then
	%error "Cannot remove this data..."


%if (CLASS = IT %and MODEL = HRM) %or (CLASS = CO) %then
	%warning "Post-processing directives are ignored"
	%set _POSTPROCESSING = 0

%if (STREAM = MODA %or STREAM = MSDA %or STREAM = EDMO %or STREAM = EWMO) %and (CLASS <> ER) %then
	%unset TIME
	%unset STEP

%if (STREAM = MDFA) %then
	%unset TIME

%if (CLASS <> TO %and CLASS <> DT) %or STREAM <> SEAP %then
	%unset LEADTIME
	%unset OPTTIME

%if (CLASS=DT) %then
	%unset METHOD

#########################################
# Migration from old images to new images
#########################################

# Meteosat
%if (TYPE=IM %and OBSTYPE=0 %and (IDENT=52 %or IDENT=53 %or IDENT=54))  %then 
	%warning "Replacing OBSTYPE=0 by CHANNEL=2, INSTRUMENT=205"
	%unset OBSTYPE 
	%set CHANNEL    = 2 
	%set INSTRUMENT = 205

%if (TYPE=IM %and OBSTYPE=10 %and (IDENT=52 %or IDENT=53 %or IDENT=54))  %then 
	%warning "Replacing OBSTYPE=10 by CHANNEL=3, INSTRUMENT=205"
	%unset OBSTYPE 
	%set CHANNEL    = 3 
	%set INSTRUMENT = 205

%if (TYPE=IM %and OBSTYPE=20 %and (IDENT=52 %or IDENT=53 %or IDENT=54))  %then 
	%warning "Replacing OBSTYPE=10 by CHANNEL=1, INSTRUMENT=205"
	%unset OBSTYPE 
	%set CHANNEL    = 1 
	%set INSTRUMENT = 205

# GOES
%if (TYPE=IM %and OBSTYPE=0 %and (IDENT=252 %or IDENT=253 %or IDENT=254 %or IDENT=255 %or IDENT=256)) %then 
	%warning "Replacing OBSTYPE=0 by CHANNEL=4, INSTRUMENT=615"
	%unset OBSTYPE 
	%set CHANNEL    = 4 
	%set INSTRUMENT = 615

%if (TYPE=IM %and OBSTYPE=10 %and (IDENT=252 %or IDENT=253 %or IDENT=254 %or IDENT=255 %or IDENT=256)) %then 
	%warning "Replacing OBSTYPE=10 by CHANNEL=1, INSTRUMENT=615"
	%unset OBSTYPE 
	%set CHANNEL    = 1 
	%set INSTRUMENT = 615

%if (TYPE=IM %and OBSTYPE=20 %and (IDENT=252 %or IDENT=253 %or IDENT=254 %or IDENT=255 %or IDENT=256)) %then 
	%warning "Replacing OBSTYPE=20 by CHANNEL=3, INSTRUMENT=615"
	%unset OBSTYPE 
	%set CHANNEL    = 3 
	%set INSTRUMENT = 615

################################################
# end of Migration from old images to new images
################################################

%if (FCMONTH %or FCPERIOD)  %and (_APPL = mars %or _APPL = marsG2 %or _APPL = msserver %or _APPL = uniserver) %then 
	%unset STEP

# %if (STREAM = SFMM %or STREAM = SWMM %or STREAM = SMMA %or STREAM = MMSA) %then
# 	%unset STEP
# 

%if (CLASS = TI %or CLASS = S2) %then                %unset DOMAIN
%if (CLASS = TI %or CLASS = S2) %and TYPE = CF %then %set NUMBER=0
%if CLASS = TI %and TYPE = FC %then %set STREAM=OPER
%if (CLASS = TI %or CLASS = S2) %and (%not EXPVER) %then %set EXPVER=PROD

%if CLASS = DM %and TYPE = FC %then %set TIME=0

# ANOFFSET not valid unless Long window 4dvar 
%if STREAM <> LWDA %and 
	STREAM <> LWWV %and
	STREAM <> ELDA %and 
	STREAM <> EWLA %then
	%unset ANOFFSET


# ERA Interim Data Server at full resolution
%if ((DATASET = interim_full_daily)  %and
    ((TYPE <> AN %and TYPE <> FC) %or
	 (TYPE = FC %and (STEP > 12 %or LEVTYPE <> SFC)))) %then
	 %error "Dataset ERA-Interim full resolution available only for Analysis and Forecast surface fluxes at time-step <= 12"
	 %fail


# Double-archiving marsrd/marsrd-cluster
#%if ((_VERB = ARCHIVE %or 
#	 _VERB = FLUSH %or 
#	 _VERB = REMOVE) %and 
#    (DATABASE = marsrd)) %then %set DATABASE = marsrd/marsrd-cluster


#%if ((_VERB = ARCHIVE %or 
#	 _VERB = FLUSH %or 
#	 _VERB = REMOVE) %and 
#     (DATABASE = marstest)) %then %set DATABASE = marstest/marsdev-core

%include "rt_by_obsgroup.chk"
