Commit 0e29ef4e authored by Anne Fouilloux's avatar Anne Fouilloux
Browse files

bug fix when looping over months/dates

parent 30006de2
......@@ -352,9 +352,11 @@ class EIFlexpart:
def create(self, inputfiles, outputdir):
index_keys=["date","time","stepRange"]
indexfile="date_time_stepRange.idx"
silentremove(indexfile)
grib=GribTools(inputfiles.files)
iid=grib.index(index_keys=index_keys, index_file = indexfile)
print 'index done...'
silentremove("fort.10")
silentremove("fort.11")
silentremove("fort.12")
......@@ -388,6 +390,7 @@ class EIFlexpart:
type = grib_get(gid, 'type')
step = grib_get(gid, 'stepRange')
cflextime = self.getFlexpartTime(type,step, time)
# print 'cyear '+cyear+'/'+cmonth+'/'+'/EI'+cyear[2:4]+cmonth+cday+cflextime
while 1:
if gid is None: break
paramId = grib_get(gid, 'paramId')
......@@ -419,6 +422,7 @@ class EIFlexpart:
p=subprocess.check_call(['CONVERT2'])
# create the corresponding output file fort.15 (generated by CONVERT2) + fort.16 (paramId 167 and paramId 168)
mkdir_p(outputdir+'/'+cyear+'/'+cmonth+'/')
print "outputdir = " + outputdir+'/'+cyear+'/'+cmonth+'/'+'/EI'+cyear[2:4]+cmonth+cday+cflextime
fout = open(outputdir+'/'+cyear+'/'+cmonth+'/EI'+cyear[2:4]+cmonth+cday+cflextime,'wb')
shutil.copyfileobj(open('fort.15','rb'), fout)
shutil.copyfileobj(open('fort.16','rb'), fout)
......@@ -426,6 +430,15 @@ class EIFlexpart:
grib_index_release(iid)
def clean(self):
def __del__(self):
print "clean"
silentremove("fort.10")
silentremove("fort.11")
silentremove("fort.12")
silentremove("fort.13")
silentremove("fort.15")
silentremove("fort.16")
silentremove("fort.18")
silentremove("VERTICAL.EC")
silentremove("date_time_stepRange.idx")
......@@ -117,6 +117,7 @@ class GribTools:
# Create index from a list of files if it does not exist or read it
def index(self,index_keys=["mars"], index_file = "my.idx"):
print "index to be done"
self.iid = None
if (os.path.exists(index_file)):
......
......@@ -91,11 +91,7 @@ def main():
retrieve="no"
for date in daterange( start, end ):
# if new year & month then we create a new directory to store output files
er_date = date
if date.strftime("%Y%m") != current_ym:
current_outputdir = outputdir + "/" + date.strftime("%Y") + '/' + date.strftime("%m") + '/'
mkdir_p(current_outputdir)
if current_ym != "":
if date.strftime("%Y%m") != current_ym and current_ym != "":
retrieve="yes"
if date == end:
......@@ -105,8 +101,14 @@ def main():
# we need to retrieve MARS data for this period (maximum one month)
flexpart = EIFlexpart()
dates= ir_date.strftime("%Y%m%d") + "/to/" + er_date.strftime("%Y%m%d")
current_outputdir = outputdir + "/" + ir_date.strftime("%Y") + '/' + ir_date.strftime("%m") + '/'
mkdir_p(current_outputdir)
print "retrieve " + dates + " in dir " + current_outputdir
flexpart.retrieve(server, dates, options.times, options.area, options.levels, current_outputdir)
ir_date = er_date
ir_date = date
retrieve="no"
er_date = date
current_ym = date.strftime("%Y%m")
......
......@@ -89,7 +89,7 @@ def main():
for date in daterange( start, end ):
# data retrieved by year/month
if cyear != date.year or cmonth != date.month:
print 'year : ' + str(date.year) + ' month : ', date.month
print 'Prepare year : ' + str(date.year) + ' month : ', date.month
cyear = date.year
cmonth = date.month
......@@ -101,6 +101,7 @@ def main():
flexpart = EIFlexpart()
flexpart.create(inputfiles, outputdir)
if __name__ == "__main__":
main()
###############################################################################
#
# Top level Makefile for ECMWFDATA software
#
# Last modified: August 20, 2013
#
###############################################################################
.SUFFIXES: .o .c .f .f90 .f95 .F
.f90.o:
$(F90C) -c $(F90FLAGS) $<
TARGET_ARCH =
OPT = -g -O
DEBUG = -g -O
LIB =
FC=gfortran -m64 -fdefault-real-8 -fcray-pointer -fno-second-underscore -ffixed-line-length-132 -fopenmp -fconvert=big-endian -fmax-stack-var-size=100000000
F90C=gfortran -m64 -fdefault-real-8 -fcray-pointer -fno-second-underscore -ffixed-line-length-132 -fopenmp -fconvert=big-endian -fmax-stack-var-size=100000000
GRIB_API_INCLUDE = $(GRIB_API_FFLAGS)
GRIB_API_LIB = $(GRIB_API_LDFLAGS)
FFLAGS = $(OPT) $(DEBUG) -I. $(GRIB_API_INCLUDE)
F90FLAGS = $(OPT) $(DEBUG) -I. $(GRIB_API_INCLUDE)
LDFLAGS = $(OPT) $(DEBUG)
EMOSLIB=$(EMOS_LDFLAGS)
LIB = $(EMOSLIB) $(GRIB_API_LIB) -lgcc -lm -fdefault-integer-8 -lgfortran -ljasper
F90=$(F90C)
BINDIR = .
EXE = CONVERT2
all: ${EXE}
clean:
rm *.o *.mod ${EXE}
phgrreal.o: phgrreal.f90
$(F90) -c -g -O3 -fopenmp phgrreal.f90
grphreal.o: grphreal.f90
$(F90) -c -g -O3 -fopenmp grphreal.f90
ftrafo.o: ftrafo.f90
$(F90) -c -g -O3 -fopenmp ftrafo.f90
CONVERT2: phgrreal.o grphreal.o ftrafo.o rwGRIB2.o preconvert.o
$(F90) $(DEBUG) $(OPT) -o CONVERT2 ftrafo.o phgrreal.o grphreal.o rwGRIB2.o preconvert.o ${LIB}
#
# End of the Makefile
#
###############################################################################
###############################################################################
#
# Top level Makefile for ECMWFDATA software
#
# Last modified: August 20, 2013
#
###############################################################################
.SUFFIXES: .o .c .f .f90 .f95 .F
.f90.o:
$(F90C) -c $(F90FLAGS) $<
TARGET_ARCH =
OPT = -g -O
DEBUG = -g -O
LIB =
FC=ifort -O2 -m64 -mcmodel=medium -safe-cray-ptr -real-size 64 -openmp
F90C=ifort -O2 -m64 -mcmodel=medium -safe-cray-ptr -real-size 64 -openmp
GRIB_API_INCLUDE = $(GRIB_API_FFLAGS)
GRIB_API_LIB = $(GRIB_API_LDFLAGS)
FFLAGS = $(OPT) $(DEBUG) -I. $(GRIB_API_INCLUDE)
F90FLAGS = $(OPT) $(DEBUG) -I. $(GRIB_API_INCLUDE)
LDFLAGS = $(OPT) $(DEBUG)
EMOS_LDFLAGS = -L/cluster/software/src/openifs/emos_000392 -lemosR64
EMOSLIB=$(EMOS_LDFLAGS)
LIB = $(EMOSLIB) $(GRIB_API_LIB) -lgcc -lm -lgfortran -ljasper -openmp
F90=$(F90C)
BINDIR = .
EXE = CONVERT2
all: ${EXE}
clean:
rm *.o *.mod ${EXE}
phgrreal.o: phgrreal.f90
$(F90) -c -g -O3 -fopenmp phgrreal.f90
grphreal.o: grphreal.f90
$(F90) -c -g -O3 -fopenmp grphreal.f90
ftrafo.o: ftrafo.f90
$(F90) -c -g -O3 -fopenmp ftrafo.f90
CONVERT2: phgrreal.o grphreal.o ftrafo.o rwGRIB2.o preconvert.o
$(F90) $(DEBUG) $(OPT) -o CONVERT2 ftrafo.o phgrreal.o grphreal.o rwGRIB2.o preconvert.o ${LIB}
#
# End of the Makefile
#
###############################################################################
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment