From 53560201f9ee81ffc8be32130b5c811f8831487b Mon Sep 17 00:00:00 2001
From: Luis Kornblueh <luis.kornblueh@mpimet.mpg.de>
Date: Wed, 9 Dec 2015 09:04:44 +0100
Subject: [PATCH] Add test cases for modulo and handling of uniq elements list
 merges.

---
 .gitignore       |   2 +
 Makefile.in      |  56 ++++------
 aclocal.m4       |  67 ++++++-----
 doc/Makefile.in  |  25 ++---
 src/Makefile.in  |  23 +---
 test/Makefile.am |  10 ++
 test/Makefile.in |  67 +++++++----
 test/modulo.c    |  23 ++++
 test/uniq.f90    | 282 +++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 427 insertions(+), 128 deletions(-)
 create mode 100644 test/modulo.c
 create mode 100644 test/uniq.f90

diff --git a/.gitignore b/.gitignore
index 5a5ecc98..d82266d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,3 +28,5 @@ test/output_control
 test/recurrence
 test/repetitor
 test/comp_weights
+test/modulo
+test/uniq
diff --git a/Makefile.in b/Makefile.in
index df063ed4..3293f34e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -14,17 +14,7 @@
 
 @SET_MAKE@
 VPATH = @srcdir@
-am__is_gnu_make = { \
-  if test -z '$(MAKELEVEL)'; then \
-    false; \
-  elif test -n '$(MAKE_HOST)'; then \
-    true; \
-  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
-    true; \
-  else \
-    false; \
-  fi; \
-}
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
 am__make_running_with_option = \
   case $${target_option-} in \
       ?) ;; \
@@ -88,6 +78,16 @@ POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
 subdir = .
+DIST_COMMON = INSTALL NEWS README AUTHORS ChangeLog \
+	$(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+	$(top_srcdir)/configure $(am__configure_deps) \
+	$(top_srcdir)/config/config.h.in COPYING config/compile \
+	config/config.guess config/config.sub config/depcomp \
+	config/install-sh config/missing config/ltmain.sh \
+	$(top_srcdir)/config/compile $(top_srcdir)/config/config.guess \
+	$(top_srcdir)/config/config.sub \
+	$(top_srcdir)/config/install-sh $(top_srcdir)/config/ltmain.sh \
+	$(top_srcdir)/config/missing
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_doxygen.m4 \
 	$(top_srcdir)/m4/ax_prog_ragel.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -96,8 +96,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_doxygen.m4 \
 	$(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
-DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
-	$(am__configure_deps) $(am__DIST_COMMON)
 am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
  configure.lineno config.status.lineno
 mkinstalldirs = $(install_sh) -d
@@ -160,15 +158,6 @@ ETAGS = etags
 CTAGS = ctags
 CSCOPE = cscope
 DIST_SUBDIRS = $(SUBDIRS)
-am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/config/compile \
-	$(top_srcdir)/config/config.guess \
-	$(top_srcdir)/config/config.h.in \
-	$(top_srcdir)/config/config.sub \
-	$(top_srcdir)/config/install-sh $(top_srcdir)/config/ltmain.sh \
-	$(top_srcdir)/config/missing AUTHORS COPYING ChangeLog INSTALL \
-	NEWS README config/compile config/config.guess \
-	config/config.sub config/depcomp config/install-sh \
-	config/ltmain.sh config/missing
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)
@@ -394,6 +383,7 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__confi
 	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \
 	$(am__cd) $(top_srcdir) && \
 	  $(AUTOMAKE) --gnu Makefile
+.PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
 	  *config.status*) \
@@ -624,15 +614,15 @@ dist-xz: distdir
 	$(am__post_remove_distdir)
 
 dist-tarZ: distdir
-	@echo WARNING: "Support for distribution archives compressed with" \
-		       "legacy program 'compress' is deprecated." >&2
+	@echo WARNING: "Support for shar distribution archives is" \
+	               "deprecated." >&2
 	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
 	tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
 	$(am__post_remove_distdir)
 
 dist-shar: distdir
-	@echo WARNING: "Support for shar distribution archives is" \
-	               "deprecated." >&2
+	@echo WARNING: "Support for distribution archives compressed with" \
+		       "legacy program 'compress' is deprecated." >&2
 	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
 	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
 	$(am__post_remove_distdir)
@@ -668,17 +658,17 @@ distcheck: dist
 	esac
 	chmod -R a-w $(distdir)
 	chmod u+w $(distdir)
-	mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst
+	mkdir $(distdir)/_build $(distdir)/_inst
 	chmod a-w $(distdir)
 	test -d $(distdir)/_build || exit 0; \
 	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
 	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
 	  && am__cwd=`pwd` \
-	  && $(am__cd) $(distdir)/_build/sub \
-	  && ../../configure \
+	  && $(am__cd) $(distdir)/_build \
+	  && ../configure \
 	    $(AM_DISTCHECK_CONFIGURE_FLAGS) \
 	    $(DISTCHECK_CONFIGURE_FLAGS) \
-	    --srcdir=../.. --prefix="$$dc_install_base" \
+	    --srcdir=.. --prefix="$$dc_install_base" \
 	  && $(MAKE) $(AM_MAKEFLAGS) \
 	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
 	  && $(MAKE) $(AM_MAKEFLAGS) check \
@@ -855,8 +845,6 @@ uninstall-am:
 	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
 	uninstall-am
 
-.PRECIOUS: Makefile
-
 
 doc:
 	cd doc && $(MAKE) $(AM_MAKEFLAGS) doc
diff --git a/aclocal.m4 b/aclocal.m4
index cc0029eb..f5ec97e9 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,6 +1,6 @@
-# generated automatically by aclocal 1.15 -*- Autoconf -*-
+# generated automatically by aclocal 1.14.1 -*- Autoconf -*-
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -20,7 +20,7 @@ You have another version of autoconf.  It may work, but is not guaranteed to.
 If you have problems, you may need to regenerate the build system entirely.
 To do so, use the procedure documented by the package, typically 'autoreconf'.])])
 
-# Copyright (C) 2002-2014 Free Software Foundation, Inc.
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -32,10 +32,10 @@ To do so, use the procedure documented by the package, typically 'autoreconf'.])
 # generated from the m4 files accompanying Automake X.Y.
 # (This private macro should not be called outside this file.)
 AC_DEFUN([AM_AUTOMAKE_VERSION],
-[am__api_version='1.15'
+[am__api_version='1.14'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 dnl require some minimum version.  Point them to the right macro.
-m4_if([$1], [1.15], [],
+m4_if([$1], [1.14.1], [],
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
 ])
 
@@ -51,14 +51,14 @@ m4_define([_AM_AUTOCONF_VERSION], [])
 # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
 # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
 AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.15])dnl
+[AM_AUTOMAKE_VERSION([1.14.1])dnl
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
 
 # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -103,14 +103,15 @@ _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
 # configured tree to be moved without reconfiguration.
 
 AC_DEFUN([AM_AUX_DIR_EXPAND],
-[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
-# Expand $ac_aux_dir to an absolute path.
-am_aux_dir=`cd "$ac_aux_dir" && pwd`
+[dnl Rely on autoconf to set up CDPATH properly.
+AC_PREREQ([2.50])dnl
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
 ])
 
 # AM_CONDITIONAL                                            -*- Autoconf -*-
 
-# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+# Copyright (C) 1997-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -141,7 +142,7 @@ AC_CONFIG_COMMANDS_PRE(
 Usually this means the macro was only invoked conditionally.]])
 fi])])
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -332,7 +333,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl
 
 # Generate code to set up dependency tracking.              -*- Autoconf -*-
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -408,7 +409,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
 
 # Do all the work for Automake.                             -*- Autoconf -*-
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -498,8 +499,8 @@ AC_REQUIRE([AC_PROG_MKDIR_P])dnl
 # <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
 # <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
 AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
-# We need awk for the "check" target (and possibly the TAP driver).  The
-# system "awk" is bad on some platforms.
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
 AC_REQUIRE([AC_PROG_AWK])dnl
 AC_REQUIRE([AC_PROG_MAKE_SET])dnl
 AC_REQUIRE([AM_SET_LEADING_DOT])dnl
@@ -572,11 +573,7 @@ to "yes", and re-run configure.
 END
     AC_MSG_ERROR([Your 'rm' program is bad, sorry.])
   fi
-fi
-dnl The trailing newline in this macro's definition is deliberate, for
-dnl backward compatibility and to allow trailing 'dnl'-style comments
-dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841.
-])
+fi])
 
 dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
 dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
@@ -605,7 +602,7 @@ for _am_header in $config_headers :; do
 done
 echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -616,7 +613,7 @@ echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_co
 # Define $install_sh.
 AC_DEFUN([AM_PROG_INSTALL_SH],
 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
-if test x"${install_sh+set}" != xset; then
+if test x"${install_sh}" != xset; then
   case $am_aux_dir in
   *\ * | *\	*)
     install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
@@ -626,7 +623,7 @@ if test x"${install_sh+set}" != xset; then
 fi
 AC_SUBST([install_sh])])
 
-# Copyright (C) 2003-2014 Free Software Foundation, Inc.
+# Copyright (C) 2003-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -648,7 +645,7 @@ AC_SUBST([am__leading_dot])])
 # Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
 # From Jim Meyering
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -683,7 +680,7 @@ AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
 
 # Check to see how 'make' treats includes.	            -*- Autoconf -*-
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -733,7 +730,7 @@ rm -f confinc confmf
 
 # Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
 
-# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+# Copyright (C) 1997-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -772,7 +769,7 @@ fi
 
 # Helper functions for option handling.                     -*- Autoconf -*-
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -801,7 +798,7 @@ AC_DEFUN([_AM_SET_OPTIONS],
 AC_DEFUN([_AM_IF_OPTION],
 [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -848,7 +845,7 @@ AC_LANG_POP([C])])
 # For backward compatibility.
 AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -867,7 +864,7 @@ AC_DEFUN([AM_RUN_LOG],
 
 # Check to make sure that the build environment is sane.    -*- Autoconf -*-
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -948,7 +945,7 @@ AC_CONFIG_COMMANDS_PRE(
 rm -f conftest.file
 ])
 
-# Copyright (C) 2009-2014 Free Software Foundation, Inc.
+# Copyright (C) 2009-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -1008,7 +1005,7 @@ AC_SUBST([AM_BACKSLASH])dnl
 _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
 ])
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -1036,7 +1033,7 @@ fi
 INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 AC_SUBST([INSTALL_STRIP_PROGRAM])])
 
-# Copyright (C) 2006-2014 Free Software Foundation, Inc.
+# Copyright (C) 2006-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -1055,7 +1052,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
 
 # Check how to create a tarball.                            -*- Autoconf -*-
 
-# Copyright (C) 2004-2014 Free Software Foundation, Inc.
+# Copyright (C) 2004-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
diff --git a/doc/Makefile.in b/doc/Makefile.in
index ea605d7a..2986daa1 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -14,17 +14,7 @@
 
 @SET_MAKE@
 VPATH = @srcdir@
-am__is_gnu_make = { \
-  if test -z '$(MAKELEVEL)'; then \
-    false; \
-  elif test -n '$(MAKE_HOST)'; then \
-    true; \
-  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
-    true; \
-  else \
-    false; \
-  fi; \
-}
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
 am__make_running_with_option = \
   case $${target_option-} in \
       ?) ;; \
@@ -88,6 +78,8 @@ POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
 subdir = doc
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+	$(srcdir)/Doxyfile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_doxygen.m4 \
 	$(top_srcdir)/m4/ax_prog_ragel.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -96,7 +88,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_doxygen.m4 \
 	$(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
-DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config/config.h
 CONFIG_CLEAN_FILES = Doxyfile
@@ -121,7 +112,6 @@ am__can_run_installinfo = \
     *) (install-info --version) >/dev/null 2>&1;; \
   esac
 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
-am__DIST_COMMON = $(srcdir)/Doxyfile.in $(srcdir)/Makefile.in
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
@@ -301,6 +291,7 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__confi
 	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu doc/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
 	  $(AUTOMAKE) --gnu doc/Makefile
+.PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
 	  *config.status*) \
@@ -397,8 +388,8 @@ distclean-generic:
 maintainer-clean-generic:
 	@echo "This command is intended for maintainers to use"
 	@echo "it deletes files that may require special tools to rebuild."
-@DX_COND_doc_FALSE@mostlyclean-local:
 @DX_COND_doc_FALSE@install-data-local:
+@DX_COND_doc_FALSE@mostlyclean-local:
 clean: clean-am
 
 clean-am: clean-generic clean-libtool mostlyclean-am
@@ -481,8 +472,6 @@ uninstall-am:
 	mostlyclean-libtool mostlyclean-local pdf pdf-am ps ps-am \
 	tags-am uninstall uninstall-am
 
-.PRECIOUS: Makefile
-
 
 @DX_COND_doc_TRUE@@DX_COND_pdf_TRUE@doxygen-pdf: @DX_DOCDIR@/@PACKAGE@.pdf
 
diff --git a/src/Makefile.in b/src/Makefile.in
index 53bbec88..9e09de60 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -15,17 +15,7 @@
 @SET_MAKE@
 
 VPATH = @srcdir@
-am__is_gnu_make = { \
-  if test -z '$(MAKELEVEL)'; then \
-    false; \
-  elif test -n '$(MAKE_HOST)'; then \
-    true; \
-  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
-    true; \
-  else \
-    false; \
-  fi; \
-}
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
 am__make_running_with_option = \
   case $${target_option-} in \
       ?) ;; \
@@ -89,6 +79,8 @@ POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
 subdir = src
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+	$(top_srcdir)/config/depcomp
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_doxygen.m4 \
 	$(top_srcdir)/m4/ax_prog_ragel.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -97,7 +89,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_doxygen.m4 \
 	$(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
-DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config/config.h
 CONFIG_CLEAN_FILES =
@@ -218,7 +209,6 @@ am__define_uniq_tagged_files = \
   done | $(am__uniquify_input)`
 ETAGS = etags
 CTAGS = ctags
-am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/config/depcomp
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
@@ -419,6 +409,7 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__confi
 	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
 	  $(AUTOMAKE) --gnu src/Makefile
+.PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
 	  *config.status*) \
@@ -741,8 +732,6 @@ uninstall-am: uninstall-libLTLIBRARIES
 	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
 	tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES
 
-.PRECIOUS: Makefile
-
 
 @HAVE_RAGEL_TRUE@mtime_iso8601.c: mtime_iso8601.rl
 @HAVE_RAGEL_TRUE@	$(RAGEL) -o mtime_iso8601.c mtime_iso8601.rl
diff --git a/test/Makefile.am b/test/Makefile.am
index 73cf5832..0019e4bb 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -10,6 +10,8 @@ bin_PROGRAMS = \
 	recurrence \
 	repetitor \
 	tas \
+	uniq \
+	modulo \
 	comp_weights \
         iconatm \
 	iconoce 
@@ -50,6 +52,14 @@ tas_SOURCES = tas.f90
 tas_LDADD = ../src/libmtime.la
 tas_LDFLAGS=
 
+uniq_SOURCES = uniq.f90
+uniq_LDADD = ../src/libmtime.la
+uniq_LDFLAGS=
+
+modulo_SOURCES = modulo.c
+modulo_LDADD = ../src/libmtime.la
+modulo_LDFLAGS=
+
 iconatm_SOURCES = iconatm.f90
 iconatm_LDADD = ../src/libmtime.la
 iconatm_LDFLAGS=
diff --git a/test/Makefile.in b/test/Makefile.in
index 72ab8da6..2085b02d 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -15,17 +15,7 @@
 @SET_MAKE@
 
 VPATH = @srcdir@
-am__is_gnu_make = { \
-  if test -z '$(MAKELEVEL)'; then \
-    false; \
-  elif test -n '$(MAKE_HOST)'; then \
-    true; \
-  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
-    true; \
-  else \
-    false; \
-  fi; \
-}
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
 am__make_running_with_option = \
   case $${target_option-} in \
       ?) ;; \
@@ -91,8 +81,11 @@ host_triplet = @host@
 bin_PROGRAMS = time_calculus$(EXEEXT) model_integration$(EXEEXT) \
 	example$(EXEEXT) duration$(EXEEXT) output_control$(EXEEXT) \
 	recurrence$(EXEEXT) repetitor$(EXEEXT) tas$(EXEEXT) \
-	comp_weights$(EXEEXT) iconatm$(EXEEXT) iconoce$(EXEEXT)
+	uniq$(EXEEXT) modulo$(EXEEXT) comp_weights$(EXEEXT) \
+	iconatm$(EXEEXT) iconoce$(EXEEXT)
 subdir = test
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+	$(top_srcdir)/config/depcomp
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_doxygen.m4 \
 	$(top_srcdir)/m4/ax_prog_ragel.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -101,7 +94,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_doxygen.m4 \
 	$(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
-DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config/config.h
 CONFIG_CLEAN_FILES =
@@ -150,6 +142,12 @@ model_integration_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
 	$(AM_CFLAGS) $(CFLAGS) $(model_integration_LDFLAGS) $(LDFLAGS) \
 	-o $@
+am_modulo_OBJECTS = modulo.$(OBJEXT)
+modulo_OBJECTS = $(am_modulo_OBJECTS)
+modulo_DEPENDENCIES = ../src/libmtime.la
+modulo_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(modulo_LDFLAGS) $(LDFLAGS) -o $@
 am_output_control_OBJECTS = output_control.$(OBJEXT)
 output_control_OBJECTS = $(am_output_control_OBJECTS)
 output_control_DEPENDENCIES = ../src/libmtime.la
@@ -181,6 +179,12 @@ time_calculus_DEPENDENCIES = ../src/libmtime.la
 time_calculus_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
 	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
 	$(time_calculus_LDFLAGS) $(LDFLAGS) -o $@
+am_uniq_OBJECTS = uniq.$(OBJEXT)
+uniq_OBJECTS = $(am_uniq_OBJECTS)
+uniq_DEPENDENCIES = ../src/libmtime.la
+uniq_LINK = $(LIBTOOL) $(AM_V_lt) --tag=FC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(FCLD) $(AM_FCFLAGS) $(FCFLAGS) \
+	$(uniq_LDFLAGS) $(LDFLAGS) -o $@
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
 am__v_P_0 = false
@@ -232,14 +236,16 @@ am__v_FCLD_0 = @echo "  FCLD    " $@;
 am__v_FCLD_1 = 
 SOURCES = $(comp_weights_SOURCES) $(duration_SOURCES) \
 	$(example_SOURCES) $(iconatm_SOURCES) $(iconoce_SOURCES) \
-	$(model_integration_SOURCES) $(output_control_SOURCES) \
-	$(recurrence_SOURCES) $(repetitor_SOURCES) $(tas_SOURCES) \
-	$(time_calculus_SOURCES)
+	$(model_integration_SOURCES) $(modulo_SOURCES) \
+	$(output_control_SOURCES) $(recurrence_SOURCES) \
+	$(repetitor_SOURCES) $(tas_SOURCES) $(time_calculus_SOURCES) \
+	$(uniq_SOURCES)
 DIST_SOURCES = $(comp_weights_SOURCES) $(duration_SOURCES) \
 	$(example_SOURCES) $(iconatm_SOURCES) $(iconoce_SOURCES) \
-	$(model_integration_SOURCES) $(output_control_SOURCES) \
-	$(recurrence_SOURCES) $(repetitor_SOURCES) $(tas_SOURCES) \
-	$(time_calculus_SOURCES)
+	$(model_integration_SOURCES) $(modulo_SOURCES) \
+	$(output_control_SOURCES) $(recurrence_SOURCES) \
+	$(repetitor_SOURCES) $(tas_SOURCES) $(time_calculus_SOURCES) \
+	$(uniq_SOURCES)
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
     n|no|NO) false;; \
@@ -264,7 +270,6 @@ am__define_uniq_tagged_files = \
   done | $(am__uniquify_input)`
 ETAGS = etags
 CTAGS = ctags
-am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/config/depcomp
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
@@ -445,6 +450,12 @@ comp_weights_LDFLAGS =
 tas_SOURCES = tas.f90
 tas_LDADD = ../src/libmtime.la
 tas_LDFLAGS = 
+uniq_SOURCES = uniq.f90
+uniq_LDADD = ../src/libmtime.la
+uniq_LDFLAGS = 
+modulo_SOURCES = modulo.c
+modulo_LDADD = ../src/libmtime.la
+modulo_LDFLAGS = 
 iconatm_SOURCES = iconatm.f90
 iconatm_LDADD = ../src/libmtime.la
 iconatm_LDFLAGS = 
@@ -467,6 +478,7 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__confi
 	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
 	  $(AUTOMAKE) --gnu test/Makefile
+.PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
 	  *config.status*) \
@@ -558,6 +570,10 @@ model_integration$(EXEEXT): $(model_integration_OBJECTS) $(model_integration_DEP
 	@rm -f model_integration$(EXEEXT)
 	$(AM_V_CCLD)$(model_integration_LINK) $(model_integration_OBJECTS) $(model_integration_LDADD) $(LIBS)
 
+modulo$(EXEEXT): $(modulo_OBJECTS) $(modulo_DEPENDENCIES) $(EXTRA_modulo_DEPENDENCIES) 
+	@rm -f modulo$(EXEEXT)
+	$(AM_V_CCLD)$(modulo_LINK) $(modulo_OBJECTS) $(modulo_LDADD) $(LIBS)
+
 output_control$(EXEEXT): $(output_control_OBJECTS) $(output_control_DEPENDENCIES) $(EXTRA_output_control_DEPENDENCIES) 
 	@rm -f output_control$(EXEEXT)
 	$(AM_V_FCLD)$(output_control_LINK) $(output_control_OBJECTS) $(output_control_LDADD) $(LIBS)
@@ -578,6 +594,10 @@ time_calculus$(EXEEXT): $(time_calculus_OBJECTS) $(time_calculus_DEPENDENCIES) $
 	@rm -f time_calculus$(EXEEXT)
 	$(AM_V_CCLD)$(time_calculus_LINK) $(time_calculus_OBJECTS) $(time_calculus_LDADD) $(LIBS)
 
+uniq$(EXEEXT): $(uniq_OBJECTS) $(uniq_DEPENDENCIES) $(EXTRA_uniq_DEPENDENCIES) 
+	@rm -f uniq$(EXEEXT)
+	$(AM_V_FCLD)$(uniq_LINK) $(uniq_OBJECTS) $(uniq_LDADD) $(LIBS)
+
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
 
@@ -585,6 +605,7 @@ distclean-compile:
 	-rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model_integration.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/modulo.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/recurrence.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time_calculus.Po@am__quote@
 
@@ -829,8 +850,6 @@ uninstall-am: uninstall-binPROGRAMS
 	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
 	tags tags-am uninstall uninstall-am uninstall-binPROGRAMS
 
-.PRECIOUS: Makefile
-
 
 mo_kind.$(OBJEXT): mo_kind.f90
 mo_output_event_types.$(OBJEXT):  mo_output_event_types.f90 mo_kind.$(OBJEXT)
diff --git a/test/modulo.c b/test/modulo.c
new file mode 100644
index 00000000..392c9a2b
--- /dev/null
+++ b/test/modulo.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <mtime_calendar.h>
+#include <mtime_timedelta.h>
+
+int main(int argc, char *argv[])
+{
+  initCalendar(PROLEPTIC_GREGORIAN);
+
+  {
+    struct _timedelta *td1  = newTimeDelta("PT10M");
+    struct _timedelta *td2  = newTimeDelta("PT2H");  
+
+    int64_t remainder, quot;
+        
+    remainder = moduloTimedelta(td2, td1, &quot);
+        
+    fprintf(stderr, "quot = %ld, rem = %ld\n", quot, remainder);
+  }
+  
+  return 0;
+}
diff --git a/test/uniq.f90 b/test/uniq.f90
new file mode 100644
index 00000000..0b6feda9
--- /dev/null
+++ b/test/uniq.f90
@@ -0,0 +1,282 @@
+program output_test
+
+  use mtime
+  
+  implicit none
+
+  integer, parameter :: i8 = selected_int_kind(14)
+  
+  integer, parameter :: nintvls = 8
+  
+  character(len=24) :: begin_str(nintvls)
+  character(len=24) :: end_str(nintvls)
+  character(len=24) :: intvl_str(nintvls)
+
+  type(datetime),  pointer :: mtime_begin => null()
+  type(datetime),  pointer :: mtime_end => null()
+  type(timedelta), pointer :: delta => null()
+  type(datetime),  pointer :: mtime_date => null()
+
+  type(julianday), pointer :: tmp_jd => null()
+  
+  type tmp_container
+    integer(i8) :: day
+    integer(i8) :: ms
+  end type tmp_container
+
+  type(tmp_container), allocatable, target :: mtime_date_container_a(:)
+  type(tmp_container), allocatable, target :: mtime_date_container_b(:)  
+  type(tmp_container), allocatable, target :: tmp(:)
+  type(tmp_container), allocatable :: mtime_date_uniq(:)
+  
+  type(tmp_container), pointer :: mtime_date_container(:) => null()
+  
+  integer :: indices_to_use(nintvls)
+  integer :: remaining_intvls, iselected_intvl
+  
+  integer :: iintvl
+  integer :: n_event_steps, n_event_steps_a, n_event_steps_b, remaining_event_steps, ierrstat   
+
+  logical :: l_active
+
+  call setCalendar(proleptic_gregorian)
+  
+  begin_str(1) = "1979-01-01T00:00:00Z"
+  end_str(1)   = "2009-01-01T00:00:00Z"
+!  end_str(1)   = "1979-01-02T00:00:00Z"  
+  intvl_str(1) = "PT6H"
+
+  begin_str(2) = "1979-01-01T00:00:00Z"
+  end_str(2)   = "2009-01-01T00:00:00Z"
+!  end_str(2)   = "1979-01-02T00:00:00Z"  
+  intvl_str(2) = "PT2H"
+
+  begin_str(3) = "1979-01-01T00:00:00Z"
+  end_str(3)   = "2009-01-01T00:00:00Z"
+!  end_str(3)   = "1979-01-02T00:00:00Z"  
+  intvl_str(3) = "PT6H"
+
+  begin_str(4) = "1979-01-01T00:00:00Z"
+  end_str(4)   = "2009-01-01T00:00:00Z"
+!  end_str(4)   = "1979-01-02T00:00:00Z"  
+  intvl_str(4) = "PT2H"
+
+  begin_str(5) = "1979-01-01T00:00:00Z"
+  end_str(5)   = "2009-01-01T00:00:00Z"
+!  end_str(5)   = "1979-01-02T00:00:00Z"  
+  intvl_str(5) = "PT2H"
+
+  begin_str(6) = "1979-01-01T00:00:00Z"
+  end_str(6)   = "2009-01-01T00:00:00Z"
+!  end_str(6)   = "1979-01-02T00:00:00Z"  
+  intvl_str(6) = "PT6H"
+
+  begin_str(7) = "1979-01-01T00:00:00Z"
+  end_str(7)   = "2009-01-01T00:00:00Z"
+!  end_str(7)   = "1979-01-02T00:00:00Z"  
+  intvl_str(7) = "PT1H"
+
+  begin_str(8) = "1979-01-01T00:00:00Z"
+  end_str(8)   = "2009-01-01T00:00:00Z"
+!  end_str(8)   = "1979-01-02T00:00:00Z"  
+  intvl_str(8) = "PT6H"
+
+  call remove_duplicate_intervals(begin_str, end_str, intvl_str, nintvls, indices_to_use, remaining_intvls)
+
+  n_event_steps = 0
+
+  tmp_jd => newJulianday(0_i8, 0_i8);
+
+  allocate(mtime_date_container_a(256), stat=ierrstat)
+  allocate(mtime_date_container_b(256), stat=ierrstat)      
+
+  mtime_date_container => mtime_date_container_a
+  
+  interval_loop:  do iselected_intvl = 1, remaining_intvls
+    iintvl = indices_to_use(iselected_intvl)
+    
+    write (0,*) 'Handling set ', iintvl
+    
+    mtime_begin => newDatetime(trim(begin_str(iintvl)))
+    mtime_end   => newDatetime(trim(end_str(iintvl)))
+    delta       => newTimedelta(trim(intvl_str(iintvl)))
+    
+    mtime_date  => mtime_begin
+    
+    event_loop: do
+      
+      n_event_steps = n_event_steps + 1
+      
+      if (n_event_steps > size(mtime_date_container)) then
+        allocate(tmp(2*size(mtime_date_container)), stat=ierrstat)
+        if (ierrstat /= 0) stop 'allocate failed'
+        tmp(1:size(mtime_date_container)) = mtime_date_container(:)
+        if (associated(mtime_date_container, mtime_date_container_a)) then
+          call move_alloc(tmp, mtime_date_container_a)
+          mtime_date_container => mtime_date_container_a
+        else
+          call move_alloc(tmp, mtime_date_container_b)
+          mtime_date_container => mtime_date_container_b
+        endif
+      endif
+
+      call getJulianDayFromDatetime(mtime_date, tmp_jd)
+      mtime_date_container(n_event_steps)%day = tmp_jd%day
+      mtime_date_container(n_event_steps)%ms = tmp_jd%ms
+
+      mtime_date = mtime_date + delta
+      
+      l_active = .not. (mtime_date > mtime_end)
+      
+      if (.not. l_active) exit event_loop
+      
+    enddo event_loop
+
+    write (0,*) '   events: ', n_event_steps
+
+    ! for first event set we do not remove douplicates
+
+    if (iintvl == 1) then
+      n_event_steps_a = n_event_steps
+      mtime_date_container => mtime_date_container_b
+      n_event_steps = 0
+      cycle interval_loop
+    else
+      n_event_steps_b = n_event_steps
+      n_event_steps = 0      
+
+      call merge2SortedAndRemoveDublicates(mtime_date_container_a, n_event_steps_a, &
+           &                               mtime_date_container_b, n_event_steps_b, &
+           &                               mtime_date_uniq, remaining_event_steps)
+    endif
+
+    write (0,*) '     remaining events: ', remaining_event_steps
+
+    if (remaining_event_steps > size(mtime_date_container_a)) then
+      allocate(tmp(size(mtime_date_container_a)), stat=ierrstat)
+      if (ierrstat /= 0) stop 'allocate failed'
+      tmp(1:remaining_event_steps) = mtime_date_uniq(1:remaining_event_steps)
+      call move_alloc(tmp, mtime_date_container_a)
+    endif
+    
+    n_event_steps_a = remaining_event_steps
+
+    deallocate(mtime_date_uniq)
+    
+  enddo interval_loop
+
+  deallocate(mtime_date_container_a)
+  deallocate(mtime_date_container_b)  
+  deallocate(tmp_jd)
+  
+contains
+
+  subroutine merge2SortedAndRemoveDublicates(InputArray1, nsize_IA1, &
+       &                                     InputArray2, nsize_IA2, &
+       &                                     OutputArray, nsize_OA)
+    type(tmp_container), intent(in) :: InputArray1(:)
+    type(tmp_container), intent(in) :: InputArray2(:)
+    type(tmp_container), allocatable, intent(out) :: OutputArray(:)
+    integer, intent(in) :: nsize_IA1
+    integer, intent(in) :: nsize_IA2
+    integer, intent(out) :: nsize_OA
+
+    integer(i8) :: diff
+    
+    integer :: n, na, nb
+    integer :: i, j, k
+    
+    na = nsize_IA1
+    nb = nsize_IA2 
+    n = na + nb
+
+    allocate(OutputArray(n))
+    
+    i = 1
+    j = 1
+    k = 1
+    
+    do while(i <= na .and. j <= nb)
+      diff = 86400000_i8 * (InputArray1(i)%day - InputArray2(j)%day) + InputArray1(i)%ms - InputArray2(j)%ms
+      if (diff < 0_i8) then
+        if (k == 1 .or. ((InputArray1(i)%day /= OutputArray(k-1)%day) .or. (InputArray1(i)%ms /= OutputArray(k-1)%ms))) then
+          OutputArray(k) = InputArray1(i)
+          k = k+1
+        endif
+        i=i+1
+      else if (diff > 0_i8) then
+        if (k == 1 .or. ((InputArray2(j)%day /= OutputArray(k-1)%day) .or. (InputArray2(j)%ms /= OutputArray(k-1)%ms))) then
+          OutputArray(k) = InputArray2(j)
+          k = k+1
+        endif
+        j = j+1
+      else
+        if (k == 1 .or. ((InputArray1(i)%day /= OutputArray(k-1)%day) .or. (InputArray1(i)%ms /= OutputArray(k-1)%ms))) then
+          OutputArray(k) = InputArray1(i)
+          k = k+1
+        endif
+        i = i+1
+        j = j+1
+      endif
+    enddo
+    
+    do while (i <= na)
+      if ((InputArray1(i)%day /= OutputArray(k-1)%day) .or. (InputArray1(i)%ms /= OutputArray(k-1)%ms)) then
+        OutputArray(k) = InputArray1(i)
+        k = k+1
+        i = i+1
+      else
+        i = i+1
+      endif
+    enddo
+    
+    do while (j <= nb)
+      if ((InputArray2(j)%day /= OutputArray(k-1)%day) .or. (InputArray2(j)%ms /= OutputArray(k-1)%ms)) then
+        OutputArray(k) = InputArray2(j)
+        k = k+1
+        j = j+1
+      else
+        j = j+1
+      endif
+    enddo
+    
+    ! do i = 1, k-1
+    !   write (0,*) OutputArray(i)
+    ! enddo
+
+    nsize_OA = k-1
+    
+  end subroutine merge2SortedAndRemoveDublicates
+
+  subroutine remove_duplicate_intervals(starts, ends, intvls, n, indices_to_use, remaining)
+    character(len=*), intent(in) :: starts(:)
+    character(len=*), intent(in) :: ends(:)
+    character(len=*), intent(in) :: intvls(:)
+    integer, intent(in) :: n         
+    integer, intent(out) :: indices_to_use(n)
+    integer, intent(out) :: remaining
+    
+    integer :: i, j
+    
+    remaining = 1
+    indices_to_use(1) = 1
+    
+    outer: do i = 2, n
+      do j = 1, remaining
+        if (trim(starts(j)) == trim(starts(i))) then
+          if (trim(ends(j)) == trim(ends(i))) then
+            if (trim(intvls(j)) == trim(intvls(i))) then
+              ! found a match so start looking again
+              cycle outer
+            endif
+          endif
+        endif
+      enddo
+      ! no match found so add it to the output
+      remaining = remaining + 1
+      indices_to_use(remaining) = i
+    end do outer
+    
+  end subroutine remove_duplicate_intervals
+
+end program output_test
-- 
GitLab