Index: python/CONTROL_OD.glob.025
===================================================================
--- python/CONTROL_OD.glob.025	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
+++ python/CONTROL_OD.glob.025	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -0,0 +1,34 @@
+DAY1 
+DAY2 
+DTIME 3
+M_TYPE AN FC FC FC FC FC FC FC FC FC FC FC AN FC FC FC FC FC FC FC FC FC FC FC
+M_TIME 00 00 00 00 00 00 00 00 00 00 00 00 12 12 12 12 12 12 12 12 12 12 12 12
+M_STEP 00 01 02 03 04 05 06 07 08 09 10 11 00 01 02 03 04 05 06 07 08 09 10 11
+M_CLASS OD
+M_STREAM OPER
+M_NUMBER OFF
+M_EXPVER 
+M_GRID 250 
+M_LEFT -179750
+M_LOWER -90000
+M_UPPER 90000
+M_RIGHT 180000
+M_LEVEL 137
+M_RESOL 799
+M_GAUSS 0
+M_ACCURACY 24
+M_OMEGA 0
+M_OMEGADIFF 0
+M_ETA 1
+M_ETADIFF 0
+M_DPDETA 1
+M_SMOOTH 0
+M_FORMAT GRIB2
+M_ADDPAR /186/187/188/235/139/39
+PREFIX ENH
+ECSTORAGE 0
+ECTRANS 1
+ECFSDIR ectmp:/${USER}/econdemand/
+MAILOPS ${USER}
+MAILFAIL ${USER}
+EOF
Index: python/CONTROL_ZAMG_SYNTH
===================================================================
--- python/CONTROL_ZAMG_SYNTH	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
+++ python/CONTROL_ZAMG_SYNTH	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -0,0 +1,31 @@
+DAY1
+DAY2
+DTIME 3
+M_TYPE PF PF PF PF PF PF PF PF 
+M_TIME 00 00 00 00 12 12 12 12 
+M_STEP 00 03 06 09 00 03 06 09 
+M_STREAM ENFO 
+PREFIX EN
+M_UPPER 90000
+M_LOWER -90000
+M_LEFT  -179500
+M_RIGHT 180000
+M_CLASS OD
+M_NUMBER 1/TO/50
+M_GRID 500
+M_RESOL 319
+M_SMOOTH 0
+M_GAUSS 1
+M_ETA 1
+M_ETAPAR 77
+M_DPDETA 1
+M_LEVEL 91
+M_LEVELIST 1/TO/91
+M_ADDPAR 186/187/188/235/139/39/134
+M_FORMAT GRIB1
+ECSTORAGE 0
+ECTRANS 0
+DEBUG 1
+ECFSDIR ectmp:/${USER}/ecops
+MAILOPS ${USER}
+MAILFAIL ${USER}
Index: python/CONTROL_ZAMG_SYNTH_ENAN
===================================================================
--- python/CONTROL_ZAMG_SYNTH_ENAN	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
+++ python/CONTROL_ZAMG_SYNTH_ENAN	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -0,0 +1,33 @@
+DAY1
+DAY2
+DTIME 3
+M_TYPE AN FC AN FC AN FC AN FC 
+M_TIME 00 18 06 06 12 06 18 18 
+M_STEP 00 09 00 03 00 09 00 03
+M_ACCTIME 06/18
+M_ACCMAXSTEP 12
+M_STREAM ELDA 
+PREFIX EN
+M_UPPER 90000
+M_LOWER -90000
+M_LEFT  -179500
+M_RIGHT 180000
+M_CLASS OD
+M_NUMBER 0/to/25
+M_GRID 500
+M_RESOL 319
+M_SMOOTH 0
+M_GAUSS 0
+M_ETA 1
+M_ETAPAR 77
+M_DPDETA 1
+M_LEVEL 137
+M_LEVELIST 1/TO/137
+M_ADDPAR 186/187/188/235/139/39/134
+M_FORMAT GRIB1
+ECSTORAGE 1
+ECTRANS 0
+DEBUG 0
+ECFSDIR ectmp:/${USER}/ecops
+MAILOPS ${USER}
+MAILFAIL ${USER}
Index: python/CONTROL_ZAMG_SYNTH_ENFO
===================================================================
--- python/CONTROL_ZAMG_SYNTH_ENFO	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
+++ python/CONTROL_ZAMG_SYNTH_ENFO	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -0,0 +1,31 @@
+DAY1
+DAY2
+DTIME 3
+M_TYPE PF PF PF PF PF PF PF PF 
+M_TIME 00 00 00 00 12 12 12 12 
+M_STEP 00 03 06 09 00 03 06 09 
+M_STREAM ENFO 
+PREFIX OP
+M_UPPER 90000
+M_LOWER -90000
+M_LEFT  -179500
+M_RIGHT 180000
+M_CLASS OD
+M_NUMBER 1/TO/50
+M_GRID 500
+M_RESOL 319
+M_SMOOTH 0
+M_GAUSS 1
+M_ETA 0
+M_ETAPAR 77
+M_DPDETA 1
+M_LEVEL 91
+M_LEVELIST 1/TO/91
+M_ADDPAR 186/187/188/235/139/39/134
+M_FORMAT GRIB1
+ECSTORAGE 1
+ECTRANS 0
+DEBUG  0
+ECFSDIR ectmp:/${USER}/ecops
+MAILOPS ${USER}
+MAILFAIL ${USER}
Index: python/CONTROL_ZAMG_SYNTH_ENFOCF
===================================================================
--- python/CONTROL_ZAMG_SYNTH_ENFOCF	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
+++ python/CONTROL_ZAMG_SYNTH_ENFOCF	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -0,0 +1,31 @@
+DAY1
+DAY2
+DTIME 3
+M_TYPE CF CF CF CF CF CF CF CF 
+M_TIME 00 00 00 00 12 12 12 12 
+M_STEP 00 03 06 09 00 03 06 09 
+M_STREAM ENFO 
+PREFIX OP
+M_UPPER 90000
+M_LOWER -90000
+M_LEFT  -179500
+M_RIGHT 180000
+M_CLASS OD
+M_NUMBER 0
+M_GRID 500
+M_RESOL 319
+M_SMOOTH 0
+M_GAUSS 1
+M_ETA 0
+M_ETAPAR 77
+M_DPDETA 1
+M_LEVEL 91
+M_LEVELIST 1/TO/91
+M_ADDPAR 186/187/188/235/139/39/134
+M_FORMAT GRIB1
+ECSTORAGE 1
+ECTRANS 0
+DEBUG  0
+ECFSDIR ectmp:/${USER}/ecops
+MAILOPS ${USER}
+MAILFAIL ${USER}
Index: python/FlexpartTools.py
===================================================================
--- python/FlexpartTools.py	(revision 5862eb9fb86828345e2b1eff400e37c52de16432)
+++ python/FlexpartTools.py	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -49,4 +49,5 @@
 from gribapi import *
 from GribTools import GribTools
+from opposite import opposite
 
 def interpret_args_and_control(*args,**kwargs):
@@ -411,4 +412,30 @@
 
     return sfeld
+
+def add_previousday_ifneeded(attrs):
+
+    if attrs['type']=='FC' and 'acc' not in attrs['target']:
+        steps=attrs['step'].split('/')
+        times=attrs['time'].split('/')
+        addpday=False
+        #for t in times:
+            #for s in steps:
+        if int(times[0])+int(steps[0])>23:
+            addpday=True
+        if(addpday):
+            dates=attrs['date'].split('/')
+            start_date=dates[0]
+            syear=int(start_date[:4])
+            smonth=int(start_date[4:6])
+            sday=int(start_date[6:])
+            start = datetime.date( year = syear, month = smonth, day = sday )
+            startm1=start- datetime.timedelta(days=1)
+
+            attrs['date']='/'.join([startm1.strftime("%Y%m%d")]+dates[1:])
+            print('CHANGED FC start date to '+startm1.strftime("%Y%m%d")+'to accomodate TIME='+times[0]+', STEP='+steps[0])
+
+    return
+
+
 
 class Control:
@@ -704,4 +731,7 @@
         del attrs['marsclass']
         attrs['class'] = mclass
+
+        add_previousday_ifneeded(attrs)
+
         target = attrs.get('target')
         if not int(self.public):
@@ -769,5 +799,5 @@
         self.types=dict()
         try:
-            if c.maxstep>len(c.type):    # Pure forecast mode
+            if c.maxstep>24: #len(c.type):    # Pure forecast mode
                 c.type=[c.type[0]] # AP changed this index from 1 to 0
                 c.step=['{:0>3}'.format(int(c.step[0]))]
@@ -804,5 +834,5 @@
 
 
-                if ((ty.upper() == 'AN' and mod(int(c.time[i]),int(c.dtime))==0) or \
+                if ((ty.upper() == 'AN' and mod(int(c.time[i]),int(c.dtime))==0 and int(c.step[i])==0) or \
                    (ty.upper() != 'AN' and mod(int(c.step[i]),int(c.dtime))==0 and \
                     mod(int(c.step[i]),int(c.dtime))==0) ) and \
@@ -1206,4 +1236,17 @@
                 p=subprocess.check_call(['grib_set','-s','edition=2,productDefinitionTemplateNumber=8',ofile,ofile+'_2'])
                 p=subprocess.check_call(['mv',ofile+'_2',ofile])
+        if c.debug==0:
+            inputfiles=glob.glob('*.grb')
+            for grb in inputfiles:
+                try:
+                    os.remove(grb)
+                except:
+                    pass
+        if c.stream=='ELDA':
+            opposite(self.inputdir+'/'+c.prefix)
+            for i in range(len(self.outputfilelist)):
+                if self.outputfilelist[i][-4:]!='N000' :
+                    j=int(self.outputfilelist[i][-3:])
+                    self.outputfilelist.append(self.outputfilelist[i][:-3]+'{:0>3}'.format(j+25))
 
         if int(c.ectrans)==1 and c.ecapi==False:
@@ -1276,5 +1319,9 @@
         wrfpars=toparamId('sp/mslp/skt/2t/10u/10v/2d/z/lsm/sst/ci/sd/stl1/stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4',table128)
 #        index_keys=["date","time","stepRange"]
-        index_keys=["date","time","step"]
+        if '/' in c.number:
+            index_keys=["number","date","time","step"]
+        else:
+            index_keys=["date","time","step"]
+
         indexfile=c.inputdir+"/date_time_stepRange.idx"
         silentremove(indexfile)
@@ -1333,4 +1380,10 @@
                     if timestamp<slimit or timestamp>elimit:
                         continue
+                else:
+                    if c.maxstep<24:
+                        if cdateH<c.start_date+'00':
+                            continue
+                        if cdateH>c.end_date+'23':
+                            continue
 
 
@@ -1432,4 +1485,10 @@
                 else:
                     suffix=cdateH[2:10]
+                try:
+                    numberindex=index_keys.index('number')
+                    if len(index_vals[numberindex])>1:
+                        suffix=suffix+'.N{:0>3}'.format(int(prod[numberindex]))
+                except:
+                    pass
 
                 fnout+=suffix
@@ -1460,9 +1519,14 @@
         grib_index_release(iid)
 
+        return
+
     def deacc_fluxes(self, inputfiles, c):
 
         table128=init128(c.flexextractdir+'/grib_templates/ecmwf_grib1_table_128')
         pars=toparamId(self.params['OG_acc_SL'][0],table128)
-        index_keys=["date","time","step"]
+        if '/' in c.number:
+            index_keys=["number","date","time","step"]
+        else:
+            index_keys=["date","time","step"]
         indexfile=c.inputdir+"/date_time_stepRange.idx"
         silentremove(indexfile)
@@ -1475,5 +1539,5 @@
         for key in index_keys:
             key_vals = grib_index_get(iid,key)
-
+            print(key_vals)
             l=[]
             for k in key_vals:
@@ -1521,14 +1585,22 @@
 
             fnout=c.inputdir+'/'
+            numbersuffix=''
+            try:
+                numberindex=index_keys.index('number')
+                if len(index_vals[numberindex])>1:
+                    numbersuffix='.N{:0>3}'.format(int(prod[numberindex]))
+            except:
+                pass
+
             if c.maxstep>12:
-                fnout+='flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step-2*int(c.dtime))
-                gnout=c.inputdir+'/flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step-int(c.dtime))
-                hnout=c.inputdir+'/flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step)
+                fnout+='flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step-2*int(c.dtime))+numbersuffix
+                gnout=c.inputdir+'/flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step-int(c.dtime))+numbersuffix
+                hnout=c.inputdir+'/flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step)+numbersuffix
                 g=open(gnout,'w')
                 h=open(hnout,'w')
             else:
-                fnout+='flux'+fdate.strftime('%Y%m%d%H')
-                gnout=c.inputdir+'/flux'+(fdate+datetime.timedelta(hours=int(c.dtime))).strftime('%Y%m%d%H')
-                hnout=c.inputdir+'/flux'+sdates.strftime('%Y%m%d%H')
+                fnout+='flux'+fdate.strftime('%Y%m%d%H')+numbersuffix
+                gnout=c.inputdir+'/flux'+(fdate+datetime.timedelta(hours=int(c.dtime))).strftime('%Y%m%d%H')+numbersuffix
+                hnout=c.inputdir+'/flux'+sdates.strftime('%Y%m%d%H')+numbersuffix
                 g=open(gnout,'w')
                 h=open(hnout,'w')
@@ -1556,5 +1628,5 @@
                     values=(reshape(values,(nj,ni))).flatten()/fak
                     vdp.append(values[:]) # save the accumulated values
-                    if c.marsclass.upper() == 'EA' or \
+                    if c.marsclass.upper() in ('EA') or \
                        step<=int(c.dtime):
                         svdp.append(values[:]/int(c.dtime))
Index: python/job.temp
===================================================================
--- python/job.temp	(revision 5862eb9fb86828345e2b1eff400e37c52de16432)
+++ python/job.temp	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -11,5 +11,5 @@
 #SBATCH --error=flex_ecmwf.%j.out
 #SBATCH --mail-type=FAIL
-#SBATCH --time=12:00:00
+#SBATCH --time=24:00:00
 
 ## CRAY specific batch requests
Index: python/job.temp.o
===================================================================
--- python/job.temp.o	(revision fb8810cda0dbbf0169e05332ef2fe5632ef1214e)
+++ python/job.temp.o	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -11,5 +11,5 @@
 #SBATCH --error=flex_ecmwf.%j.out
 #SBATCH --mail-type=FAIL
-#SBATCH --time=12:00:00
+#SBATCH --time=24:00:00
 
 ## CRAY specific batch requests
Index: python/opposite.py
===================================================================
--- python/opposite.py	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
+++ python/opposite.py	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -0,0 +1,53 @@
+import os,sys,glob
+from gribapi import *
+import numpy
+
+def opposite(prefix):
+    fclist=glob.glob(prefix+'*'+'N000')
+    
+    for fcn in fclist:
+        nprefix=fcn.split('N000')[0]
+        f=open(nprefix+'N{:0>3}'.format(0),'rb')
+        fcvalues=[]
+        while 1:
+            try:
+                fid=grib_new_from_file(f)
+                if fid is not None:
+                    fcvalues.append(grib_get_array(fid,'values'))
+                    grib_release(fid)
+                else:
+                    break
+            except:
+                break
+        for i in range(1,26):
+            try:
+                g=open(nprefix+'N{:0>3}'.format(i),'rb')
+                h=open(nprefix+'N{:0>3}'.format(i+25),'wb')
+                j=0
+                while 1:
+                    try:
+                        gid=grib_new_from_file(g)
+                        if gid is not None:
+                            values=grib_get_array(gid,'values')
+                            grib_set_array(gid,'values',values-2*(values-fcvalues[j]))
+                            grib_set(gid, 'number', i+25)
+                            grib_write(gid,h)
+                            grib_release(gid)
+                            j+=1
+                        else:
+                            break
+                    except:
+                        break
+                g.close()
+                h.close()
+                print('wrote '+nprefix+'N{:0>3}'.format(i+25))
+            except:
+                break
+        f.close()
+    return
+                
+if __name__ == "__main__":
+    opposite(os.path.expandvars('EN'))
+
+               
+        
Index: python/prepareFLEXPART.py
===================================================================
--- python/prepareFLEXPART.py	(revision e18f4b5f53f063ab746e1307bdd3162d31cb3e8a)
+++ python/prepareFLEXPART.py	(revision 21938083773b1bba2e82ee565f34eba3445dfa1a)
@@ -37,4 +37,5 @@
 from GribTools import GribTools
 from FlexpartTools import EIFlexpart, Control,interpret_args_and_control, cleanup
+from opposite import opposite
 
 hostname=socket.gethostname()
