[Dart-dev] [5618] DART/branches/development: move the generate-seed function ( takes a timestamp and returns a 32-bit

nancy at ucar.edu nancy at ucar.edu
Mon Mar 26 13:52:14 MDT 2012


Revision: 5618
Author:   nancy
Date:     2012-03-26 13:52:14 -0600 (Mon, 26 Mar 2012)
Log Message:
-----------
move the generate-seed function (takes a timestamp and returns a 32-bit
integer suitable for a random number seed) into the time manager.  have
perfect_model_obs call it from there.  also make it very simple; convert
accumulated time into 64-bit integer seconds, and take the lower 32 bits.

unrelated housekeeping in this commit of the time manager; remove all
the 'implicit none' lines from inside every routine.  the module sets that 
as the default once at the top; it applies to all code in the module.  

Modified Paths:
--------------
    DART/branches/development/perfect_model_obs/perfect_model_obs.f90
    DART/branches/development/time_manager/time_manager_mod.f90

-------------- next part --------------
Modified: DART/branches/development/perfect_model_obs/perfect_model_obs.f90
===================================================================
--- DART/branches/development/perfect_model_obs/perfect_model_obs.f90	2012-03-23 20:31:47 UTC (rev 5617)
+++ DART/branches/development/perfect_model_obs/perfect_model_obs.f90	2012-03-26 19:52:14 UTC (rev 5618)
@@ -18,7 +18,8 @@
                                  E_ERR, E_MSG, E_DBG, nmlfileunit, timestamp,          &
                                  do_nml_file, do_nml_term, logfileunit, &
                                  open_file, close_file, finalize_utilities
-use time_manager_mod,     only : time_type, get_time, set_time, operator(/=), print_time
+use time_manager_mod,     only : time_type, get_time, set_time, operator(/=), print_time,   &
+                                 generate_seed
 use obs_sequence_mod,     only : read_obs_seq, obs_type, obs_sequence_type,                 &
                                  get_obs_from_key, set_copy_meta_data, get_obs_def,         &
                                  get_time_range_keys, set_obs_values, set_qc, set_obs,      &
@@ -123,6 +124,7 @@
 integer                 :: additional_qc, additional_copies, forward_unit
 integer                 :: ierr, io, istatus, num_obs_in_set, nth_obs
 integer                 :: model_size, key_bounds(2), num_qc, last_key_used
+integer                 :: seed
 
 real(r8)                :: true_obs(1), obs_value(1), qc(1)
 
@@ -216,9 +218,6 @@
 StateUnit = init_diag_output('True_State', 'true state from control', 1, state_meta)
 call trace_message('After  initializing output diagnostic file')
 
-! Initialize a repeatable random sequence for perturbations
-call init_random_seq(random_seq)
-
 ! Get the time of the first observation in the sequence
 write(msgstring, *) 'total number of obs in sequence is ', get_num_obs(seq)
 call error_handler(E_MSG,'perfect_main',msgstring)
@@ -277,7 +276,7 @@
       call trace_message('No more obs to evaluate, exiting main loop', 'perfect_model_obs:', -1)
       exit AdvanceTime
    endif
- 
+
    call trace_message('After  move_ahead checks time of data and next obs')
 
    if (curr_ens_time /= next_ens_time) then
@@ -296,6 +295,10 @@
       call trace_message('Model does not need to run; data already at required time', 'perfect_model_obs:', -1)
    endif
 
+   ! Initialize a repeatable random sequence for perturbations
+   seed = generate_seed(next_ens_time)
+   call init_random_seq(random_seq,seed)
+
    call trace_message('Before setup for next group of observations')
    write(msgstring, '(A,I7)') 'Number of observations to be evaluated', &
       num_obs_in_set
@@ -627,4 +630,5 @@
 
 !-------------------------------------------------------------------------
 
+
 end program perfect_model_obs

Modified: DART/branches/development/time_manager/time_manager_mod.f90
===================================================================
--- DART/branches/development/time_manager/time_manager_mod.f90	2012-03-23 20:31:47 UTC (rev 5617)
+++ DART/branches/development/time_manager/time_manager_mod.f90	2012-03-26 19:52:14 UTC (rev 5618)
@@ -10,7 +10,7 @@
 ! $Revision$
 ! $Date$
 
-use     types_mod, only : missing_i, digits12
+use     types_mod, only : missing_i, digits12, i8
 use utilities_mod, only : error_handler, E_DBG, E_MSG, E_WARN, E_ERR, &
                           register_module, dump_unit_attributes, to_upper, &
                           ascii_file_format
@@ -50,7 +50,7 @@
 
 ! Subroutines and functions operating on time_type
 public :: set_time, set_time_missing, increment_time, decrement_time, get_time
-public :: interval_alarm, repeat_alarm
+public :: interval_alarm, repeat_alarm, generate_seed
 
 ! List of available calendar types
 public :: THIRTY_DAY_MONTHS,    JULIAN,    GREGORIAN,  NOLEAP,   NO_CALENDAR, &
@@ -157,8 +157,6 @@
 ! Returns a time interval corresponding to this number of days and seconds.
 ! The arguments must not be negative but are otherwise unrestricted.
 
-implicit none
-
 integer, intent(in)           :: seconds
 integer, intent(in), optional :: days
 type(time_type)               :: set_time
@@ -214,8 +212,6 @@
 ! If the optional 'days' argument is not given, the days are converted
 ! to seconds and the total time is returned as seconds.
 
-implicit none
-
 type(time_type), intent(in)            :: time
 integer,         intent(out)           :: seconds
 integer,         intent(out), optional :: days
@@ -245,8 +241,6 @@
 !
 ! Increments a time by seconds and days; increments cannot be negative.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in)           :: seconds
 integer,         intent(in), optional :: days
@@ -288,8 +282,6 @@
 !
 ! Decrements a time by seconds and days; decrements cannot be negative.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in)           :: seconds
 integer,         intent(in), optional :: days
@@ -337,8 +329,6 @@
 !
 ! Returns true if time1 > time2
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 logical                     :: time_gt
 
@@ -357,8 +347,6 @@
 !
 ! Returns true if time1 >= time2
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 logical                     :: time_ge
 
@@ -375,8 +363,6 @@
 !
 ! Returns true if time1 < time2
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 logical                     :: time_lt
 
@@ -394,8 +380,6 @@
 !
 ! Returns true if time1 <= time2
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 logical                     :: time_le
 
@@ -412,8 +396,6 @@
 !
 ! Returns true if time1 == time2
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 logical                     :: time_eq
 
@@ -430,8 +412,6 @@
 !
 ! Returns true if time1 /= time2
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 logical                     :: time_ne
 
@@ -448,8 +428,6 @@
 !
 ! Returns sum of two time_types
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 type(time_type)             :: time_plus
 
@@ -467,8 +445,6 @@
 ! Returns difference of two time_types. WARNING: a time type is positive 
 ! so by definition time1 - time2  is the same as time2 - time1.
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 type(time_type)             :: time_minus
 
@@ -489,8 +465,6 @@
 !
 ! Returns time multiplied by integer factor n
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer,         intent(in) :: n
 type(time_type)             :: time_scalar_mult
@@ -530,8 +504,6 @@
 !
 ! Returns time multipled by integer factor n
 
-implicit none
-
 integer,         intent(in) :: n
 type(time_type), intent(in) :: time
 type(time_type)             :: scalar_time_mult
@@ -549,8 +521,6 @@
 !
 ! Returns the largest integer, n, for which time1 >= time2 * n.
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 integer                     :: time_divide
 
@@ -583,8 +553,6 @@
 !
 ! Returns the double precision quotient of two times
 
-implicit none
-
 type(time_type), intent(in) :: time1, time2
 real(digits12)              :: time_real_divide
 
@@ -608,8 +576,6 @@
 !
 ! Returns the largest time, t, for which n * t <= time
 
-implicit none
-
 integer,         intent(in) :: n
 type(time_type), intent(in) :: time
 type(time_type)             :: time_scalar_divide
@@ -653,8 +619,6 @@
 ! returns true and the alarm is incremented by the alarm_interval.  Watch
 ! for problems if the new alarm time is less than time + time_interval
 
-implicit none
-
 type(time_type), intent(in)    :: time, time_interval, alarm_interval
 type(time_type), intent(inout) :: alarm
 logical                        :: interval_alarm
@@ -682,8 +646,6 @@
 ! alarm_length is 2 hours, then repeat_alarm is true from time 2300 on 
 ! day n to time 0100 on day n + 1 for all n.
 
-implicit none
-
 type(time_type), intent(in) :: time, alarm_frequency, alarm_length
 logical                     :: repeat_alarm
 
@@ -808,8 +770,6 @@
 !
 ! Returns default calendar type for mapping from time to date.
 
-implicit none
-
 integer :: get_calendar_type
 
 if ( .not. module_initialized ) call time_manager_init
@@ -862,8 +822,6 @@
 !
 ! Given a time, computes the corresponding date given the selected calendar
 
-implicit none
-
 type(time_type), intent(in)  :: time
 integer,         intent(out) :: second, minute, hour, day, month, year
 
@@ -898,9 +856,6 @@
 !
 ! Computes date corresponding to time for gregorian calendar
 
-implicit none
-
-
 type(time_type), intent(in)  :: time
 integer,         intent(out) :: second, minute, hour, day, month, year
 
@@ -971,8 +926,6 @@
 ! Base date for Julian calendar is year 1 with all multiples of 4 
 ! years being leap years.
 
-implicit none
-
 type(time_type), intent(in)  :: time
 integer,         intent(out) :: second, minute, hour, day, month, year
 
@@ -1027,8 +980,6 @@
 ! Computes date corresponding to time interval for 30 day months, 12
 ! month years.
 
-implicit none
-
 type(time_type), intent(in)  :: time
 integer,         intent(out) :: second, minute, hour, day, month, year
 
@@ -1059,8 +1010,6 @@
 !
 ! Base date for no_leap calendar is year 1.
 
-implicit none
-
 type(time_type), intent(in)  :: time
 integer,         intent(out) :: second, minute, hour, day, month, year
 
@@ -1105,8 +1054,6 @@
 !   According to MarsWRF         :: 0001-00001_00:00:00  thru  0001-00669_23:59:59
 !   According to DART time_type  :: days=0, secs=0       thru  days=668, secs=86399
 
-implicit none
-
 type(time_type), intent(in)  :: time
 integer,         intent(out) :: second, minute, hour, day, month, year
 
@@ -1170,8 +1117,6 @@
 ! The year still starts on day 1
 ! year is always 1
 
-implicit none
-
 type(time_type), intent(in)  :: time
 integer,         intent(out) :: second, minute, hour, day, month, year
 
@@ -1228,8 +1173,6 @@
 ! any number of illegal dates; these should be checked for and generate
 ! errors as appropriate.
 
-implicit none
-
 integer, intent(in)           :: day, month, year
 integer, intent(in), optional :: seconds, minutes, hours
 type(time_type)               :: set_date
@@ -1270,8 +1213,6 @@
 !
 ! Computes time corresponding to date for gregorian calendar.
 
-implicit none
-
 integer, intent(in)           :: year, month, day 
 integer, intent(in), optional :: hours, minutes, seconds
 type(time_type)               :: set_date_gregorian
@@ -1346,8 +1287,6 @@
 !
 ! Returns time corresponding to date for julian calendar.
 
-implicit none
-
 integer, intent(in)           :: year, month, day
 integer, intent(in), optional :: hours, minutes, seconds
 type(time_type)               :: set_date_julian
@@ -1413,8 +1352,6 @@
 !
 ! Computes time corresponding to date for thirty day months.
 
-implicit none
-
 integer, intent(in)           :: year, month, day
 integer, intent(in), optional :: hours, minutes, seconds
 type(time_type)               :: set_date_thirty
@@ -1454,8 +1391,6 @@
 !
 ! Computes time corresponding to date for fixed 365 day year calendar.
 
-implicit none
-
 integer, intent(in)           :: year, month, day
 integer, intent(in), optional :: hours, minutes, seconds
 type(time_type)               :: set_date_no_leap
@@ -1512,8 +1447,6 @@
 !   According to MarsWRF         :: 0001-00001_00:00:00  thru  0001-00669_23:59:59
 !   According to DART time_type  :: days=0, secs=0       thru  days=668, secs=86399
 
-implicit none
-
 integer, intent(in)           :: year, month, day
 integer, intent(in), optional :: hours, minutes, seconds
 type(time_type)               :: set_date_gregorian_mars
@@ -1566,8 +1499,6 @@
 !cl number of days in year is now 100000, and there can only be 1 year.
 !cl valid until 2050 Earth date, by which time WRF will not be used.
 
-implicit none
-
 integer, intent(in)           :: year, month, day
 integer, intent(in), optional :: hours, minutes, seconds
 type(time_type)               :: set_date_solar_mars
@@ -1629,8 +1560,6 @@
 ! a Julian calendar, it matters which order these operations are done and
 ! we don't want to deal with stuff like that, make it an error).
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: increment_date
@@ -1681,8 +1610,6 @@
 !
 ! Given time and some date increment, computes new time for gregorian calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: years, months, days, hours, minutes, seconds
 type(time_type)                       :: increment_gregorian
@@ -1739,8 +1666,6 @@
 !
 ! Given time and some date increment, computes new time for julian calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: increment_julian
@@ -1823,8 +1748,6 @@
 !
 ! Given a time and some date increment, computes new time for thirty-day months.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: increment_thirty
@@ -1868,8 +1791,6 @@
 !
 ! Given time and some date increment, computes new time for julian calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: increment_no_leap
@@ -1947,8 +1868,6 @@
 !
 ! Given time and some date increment, computes new time for gregorian MARS calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: increment_gregorian_mars
@@ -1973,8 +1892,6 @@
 !
 ! Given time and some date increment, computes new time for gregorian MARS calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: increment_solar_mars
@@ -2009,8 +1926,6 @@
 ! a Julian calendar, it matters which order these operations are done and
 ! we don't want to deal with stuff like that, make it an error).
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: decrement_date
@@ -2061,8 +1976,6 @@
 !
 ! Given time and some date decrement, computes new time for gregorian calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: decrement_gregorian
@@ -2120,8 +2033,6 @@
 !
 ! Given time and some date decrement, computes new time for julian calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: decrement_julian
@@ -2200,8 +2111,6 @@
 !
 ! Given a time and some date decrement, computes new time for thirty day months.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: decrement_thirty
@@ -2241,8 +2150,6 @@
 !
 ! Given time and some date decrement, computes new time for julian calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: decrement_no_leap
@@ -2322,8 +2229,6 @@
 !
 ! Given time and some date decrement, computes new time for gregorian MARS calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: decrement_gregorian_mars
@@ -2348,8 +2253,6 @@
 !
 ! Given time and some date decrement, computes new time for gregorian MARS calendar.
 
-implicit none
-
 type(time_type), intent(in)           :: time
 integer,         intent(in), optional :: seconds, minutes, hours, days, months, years
 type(time_type)                       :: decrement_solar_mars
@@ -2381,8 +2284,6 @@
 ! Given a time, computes the corresponding date given the selected
 ! date time mapping algorithm
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_month
 
@@ -2415,8 +2316,6 @@
 !
 ! Returns the number of days in a gregorian month.
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_month_gregorian
 
@@ -2434,8 +2333,6 @@
 !
 ! Returns the number of days in a julian month.
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_month_julian
 
@@ -2456,8 +2353,6 @@
 ! Returns the number of days in a thirty day month (needed for transparent
 ! changes to calendar type).
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_month_thirty
 
@@ -2473,8 +2368,6 @@
 !--------------------------------------------------------------------------
 ! Returns the number of days in a 365 day year month.
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_month_no_leap
 
@@ -2493,8 +2386,6 @@
 !
 ! Returns the number of days in a gregorian MARS month.
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_month_gregorian_mars
 
@@ -2512,8 +2403,6 @@
 !
 ! Returns the number of days in a gregorian MARS month.
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_month_solar_mars
 
@@ -2538,8 +2427,6 @@
 !--------------------------------------------------------------------------
 ! Is this date in a leap year for default calendar?
 
-implicit none
-
 type(time_type), intent(in) :: time
 logical                     :: leap_year
 
@@ -2571,8 +2458,6 @@
 !
 ! Is this a leap year for gregorian calendar?
 
-implicit none
-
 type(time_type), intent(in) :: time
 logical                     :: leap_year_gregorian
 
@@ -2593,8 +2478,6 @@
 !
 ! Is this a leap year for julian calendar?
 
-implicit none
-
 type(time_type), intent(in) :: time
 logical                     :: leap_year_julian
 
@@ -2616,8 +2499,6 @@
 !
 ! No leap years in thirty day months, included for transparency. 
 
-implicit none
-
 type(time_type), intent(in) :: time
 logical                     :: leap_year_thirty
 
@@ -2634,8 +2515,6 @@
 !
 ! Another tough one; no leap year returns false for leap year inquiry.
 
-implicit none
-
 type(time_type), intent(in) :: time
 logical                     :: leap_year_no_leap
 
@@ -2652,8 +2531,6 @@
 ! Is this a leap year for gregorian calendar?
 ! trick question: answer is always no.
 
-implicit none
-
 type(time_type), intent(in) :: time
 logical                     :: leap_year_gregorian_mars
 
@@ -2673,8 +2550,6 @@
 ! Is this a leap year for gregorian calendar?
 ! trick question: answer is always no.
 
-implicit none
-
 type(time_type), intent(in) :: time
 logical                     :: leap_year_solar_mars
 
@@ -2701,8 +2576,6 @@
 !
 ! What is the length of the year for the default calendar type
 
-implicit none
-
 type(time_type) :: length_of_year
 
 if ( .not. module_initialized ) call time_manager_init
@@ -2732,8 +2605,6 @@
 !--------------------------------------------------------------------------
 !
 
-implicit none
-
 type(time_type) :: length_of_year_thirty
 
 if ( .not. module_initialized ) call time_manager_init
@@ -2747,8 +2618,6 @@
 function length_of_year_gregorian()
 !---------------------------------------------------------------------------
 
-implicit none
-
 type(time_type) :: length_of_year_gregorian
 
 if ( .not. module_initialized ) call time_manager_init
@@ -2765,8 +2634,6 @@
 function length_of_year_julian()
 !--------------------------------------------------------------------------
 
-implicit none
-
 type(time_type) :: length_of_year_julian
 
 if ( .not. module_initialized ) call time_manager_init
@@ -2780,8 +2647,6 @@
 function length_of_year_no_leap()
 !--------------------------------------------------------------------------
 
-implicit none
-
 type(time_type) :: length_of_year_no_leap
 
 if ( .not. module_initialized ) call time_manager_init
@@ -2795,8 +2660,6 @@
 function length_of_year_gregorian_mars()
 !---------------------------------------------------------------------------
 
-implicit none
-
 type(time_type) :: length_of_year_gregorian_mars
 
 if ( .not. module_initialized ) call time_manager_init
@@ -2808,8 +2671,6 @@
 function length_of_year_solar_mars()
 !---------------------------------------------------------------------------
 
-implicit none
-
 type(time_type) :: length_of_year_solar_mars
 
 if ( .not. module_initialized ) call time_manager_init
@@ -2830,8 +2691,6 @@
 !
 ! What is the number of days in this year for the default calendar type
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_year
 
@@ -2861,8 +2720,6 @@
 function days_in_year_thirty(time)
 !--------------------------------------------------------------------------
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_year_thirty
 
@@ -2877,8 +2734,6 @@
 function days_in_year_gregorian(time)
 !---------------------------------------------------------------------------
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_year_gregorian
 
@@ -2897,8 +2752,6 @@
 function days_in_year_julian(time)
 !--------------------------------------------------------------------------
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_year_julian
 
@@ -2917,8 +2770,6 @@
 function days_in_year_no_leap(time)
 !--------------------------------------------------------------------------
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_year_no_leap
 
@@ -2933,8 +2784,6 @@
 function days_in_year_gregorian_mars(time)
 !---------------------------------------------------------------------------
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_year_gregorian_mars
 
@@ -2947,8 +2796,6 @@
 function days_in_year_solar_mars(time)
 !---------------------------------------------------------------------------
 
-implicit none
-
 type(time_type), intent(in) :: time
 integer                     :: days_in_year_solar_mars
 
@@ -3016,8 +2863,6 @@
 
 ! Given a date, computes the day from the beginning of the year.
 
-implicit none
-
 integer, intent(in) :: day, month, year
 integer             :: julian_day
 
@@ -3160,8 +3005,6 @@
 !--------------------------------------------------------------------------------
 !
 
-implicit none
-
 integer,          intent(in)            :: file_unit
 character(len=*), intent(in),  optional :: form
 integer,          intent(out), optional :: ios_out
@@ -3215,8 +3058,6 @@
 ! If ios_out is specified, do not call error handler here, 
 ! but return so a better context message can be generated.
 
-implicit none
-
 integer,          intent(in)            :: file_unit
 type(time_type),  intent(in)            :: time
 character(len=*), intent(in),  optional :: form
@@ -3263,8 +3104,6 @@
 subroutine interactive_time(time)
 !------------------------------------------------------------------------
 
-implicit none
-
 type(time_type), intent(inout) :: time
 integer                        :: second, minute, hour, day, month, year
 
@@ -3294,6 +3133,30 @@
 
 end subroutine interactive_time
 
+!-------------------------------------------------------------------------
 
+function generate_seed(timestamp)
+
+! given a time type, turn it into as unique an integer as possible.
+! expected to be used to seed a random number generator in a way
+! that you can reproduce the same sequence if seeded again from
+! the same time value.
+
+type(time_type), intent(in) :: timestamp
+integer                     :: generate_seed
+
+integer                :: days,seconds
+integer(i8), parameter :: secs_day = 86400_i8
+
+if ( .not. module_initialized ) call time_manager_init
+
+call get_time(timestamp, seconds, days)
+
+generate_seed = iand((secs_day * days) + seconds, z'FFFFFFFF')
+
+end function generate_seed
+
+!-------------------------------------------------------------------------
+
 end module time_manager_mod
 


More information about the Dart-dev mailing list