Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion c_data_override/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ AM_FCFLAGS = $(FC_MODINC). $(FC_MODOUT)$(MODDIR)
noinst_LTLIBRARIES = lib_c_data_override.la

# Each convenience library depends on its source.
lib_c_data_override_la_SOURCES = c_data_override.F90
lib_c_data_override_la_SOURCES = c_data_override.F90 \
include/c_data_override_0d.fh \
include/c_data_override_0d.inc

c_data_override_mod.mod : c_data_override.F90

Expand Down
45 changes: 42 additions & 3 deletions c_data_override/c_data_override.F90
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
module c_data_override_mod

use FMS, only: FmsMppDomain2D, FmsMppDomainUG, FATAL, fms_mpp_error
use FMS, only: fms_data_override_init

use c_fms_mod, only : cFMS_get_domain_from_id
use FMS, only: fms_data_override_init, fms_data_override
use FMS, only: fms_string_utils_c2f_string, fms_string_utils_f2c_string
use FMS, only: fms_time_manager_set_time, fms_time_manager_set_date, FmsTime_type

use c_fms_mod, only : cFMS_get_domain_from_id, NAME_LENGTH, MESSAGE_LENGTH

use iso_c_binding
implicit none

private

public :: cFMS_data_override_0d_cfloat
public :: cFMS_data_override_0d_cdouble
public :: cFMS_data_override_init
public :: cFMS_data_override_set_time

integer, public, bind(C, name="CFLOAT_MODE") :: CFLOAT_MODE = c_float
integer, public, bind(C, name="CDOUBLE_MODE") :: CDOUBLE_MODE = c_double

type(FmsTime_type) :: data_override_time

contains

Expand Down Expand Up @@ -56,4 +64,35 @@ subroutine cFMS_data_override_init(atm_domain_id, ocn_domain_id, ice_domain_id,

end subroutine cFMS_data_override_init


subroutine cFMS_data_override_set_time(year, month, day, hour, minute, second, tick, err_msg)&
bind(C, name="cFMS_data_override_set_time")

implicit none
integer, intent(in), optional :: year
integer, intent(in), optional :: month
integer, intent(in), optional :: day
integer, intent(in), optional :: hour
integer, intent(in), optional :: minute
integer, intent(in), optional :: second
integer, intent(in), optional :: tick
character, intent(out), optional :: err_msg(MESSAGE_LENGTH)

character(MESSAGE_LENGTH-1) :: err_msg_f = ""

data_override_time = fms_time_manager_set_date(year = year, &
month = month, &
day = day, &
hour = hour, &
minute = minute, &
second = second, &
tick = tick, &
err_msg = err_msg_f)

if(present(err_msg) .and. err_msg_f /= '') call fms_string_utils_f2c_string(err_msg, err_msg_f)

end subroutine cFMS_data_override_set_time

#include "c_data_override_0d.fh"

end module c_data_override_mod
11 changes: 11 additions & 0 deletions c_data_override/c_data_override.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
#ifndef C_DATA_OVERRIDE_H
#define C_DATA_OVERRIDE_H

#include <stdbool.h>

extern const int CFLOAT_MODE;
extern const int CDOUBLE_MODE;

extern void cFMS_data_override_0d_cfloat(char *gridname, char *fieldname_code, float *data_out, bool *override,
int *data_index);

extern void cFMS_data_override_0d_cdouble(char *gridname, char *fieldname_code, float *data_out, bool *override,
int *data_index);

extern void cFMS_data_override_init(int *atm_domain_id, int *ocn_domain_id, int *ice_domain_id, int *land_domain_id,
int *land_domainUG_id, int *mode);

extern void cFMS_data_override_set_time(int *year, int *month, int *day, int *hour, int *minute, int *second,
int *tick, char *err_msg);

#endif
15 changes: 15 additions & 0 deletions c_data_override/include/c_data_override_0d.fh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#undef CFMS_DATA_OVERRIDE_0D_
#undef CFMS_DATA_OVERRIDE_0D_BINDC_
#undef CFMS_DATA_OVERRIDE_0D_TYPE_
#define CFMS_DATA_OVERRIDE_0D_ cFMS_data_override_0d_cfloat
#define CFMS_DATA_OVERRIDE_0D_BINDC_ "cFMS_data_override_0d_cfloat"
#define CFMS_DATA_OVERRIDE_0D_TYPE_ real(c_float)
#include "c_data_override_0d.inc"

#undef CFMS_DATA_OVERRIDE_0D_
#undef CFMS_DATA_OVERRIDE_0D_BINDC_
#undef CFMS_DATA_OVERRIDE_0D_TYPE_
#define CFMS_DATA_OVERRIDE_0D_ cFMS_data_override_0d_cdouble
#define CFMS_DATA_OVERRIDE_0D_BINDC_ "cFMS_data_override_0d_cdouble"
#define CFMS_DATA_OVERRIDE_0D_TYPE_ real(c_double)
#include "c_data_override_0d.inc"
32 changes: 32 additions & 0 deletions c_data_override/include/c_data_override_0d.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
subroutine CFMS_DATA_OVERRIDE_0D_(gridname, fieldname_code, data_out, override, data_index) &
bind(C, name=CFMS_DATA_OVERRIDE_0D_BINDC_)

use FMS, only : fms_time_manager_get_date

implicit none
character(c_char), intent(in) :: gridname(NAME_LENGTH)
character(c_char), intent(in) :: fieldname_code(NAME_LENGTH)
CFMS_DATA_OVERRIDE_0D_TYPE_, intent(out) :: data_out
logical(c_bool), intent(out), optional :: override
integer, intent(in), optional :: data_index

character(len=NAME_LENGTH-1) :: gridname_f
character(len=NAME_LENGTH-1) :: fieldname_code_f

CFMS_DATA_OVERRIDE_0D_TYPE_ :: data_out_f
logical :: override_f

gridname_f = fms_string_utils_c2f_string(gridname)
fieldname_code_f = fms_string_utils_c2f_string(fieldname_code)

call fms_data_override(gridname = gridname_f, &
fieldname_code = fieldname_code_f, &
data_out = data_out, &
time = data_override_time, &
override = override_f, &
data_index = data_index)

if(present(override)) override = logical(override_f, c_bool)

end subroutine CFMS_DATA_OVERRIDE_0D_

26 changes: 6 additions & 20 deletions c_diag_manager/c_diag_manager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ module c_diag_manager_mod

use FMS, only : fms_string_utils_c2f_string, fms_string_utils_f2c_string

use FMS, only : THIRTY_DAY_MONTHS, GREGORIAN, JULIAN, NOLEAP, FmsTime_type, Operator(+)
use FMS, only : fms_time_manager_init, fms_time_manager_set_date
use FMS, only : fms_time_manager_set_calendar_type, fms_time_manager_set_time

use FMS, only : FmsTime_type, Operator(+)
use FMS, only : fms_time_manager_set_date, fms_time_manager_set_time

use FMS, only : fms_time_manager_get_date

use FMS, only : FmsMppDomain2D
Expand All @@ -22,7 +21,7 @@ module c_diag_manager_mod
use c_fms_utils_mod, only : cFMS_pointer_to_array

use iso_c_binding

implicit none

private
Expand Down Expand Up @@ -63,11 +62,6 @@ module c_diag_manager_mod
integer, public, bind(C, name="DIAG_OCEAN") :: DIAG_OCEAN_C = DIAG_OCEAN
integer, public, bind(C, name="DIAG_ALL") :: DIAG_ALL_C = DIAG_ALL

integer, public, bind(C, name="THIRTY_DAY_MONTHS") :: THIRTY_DAY_MONTHS_C = THIRTY_DAY_MONTHS
integer, public, bind(C, name="GREGORIAN") :: GREGORIAN_C = GREGORIAN
integer, public, bind(C, name="JULIAN") :: JULIAN_C = JULIAN
integer, public, bind(C, name="NOLEAP") :: NOLEAP_C = NOLEAP

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmalatino, cfms_init changed.
time_manager_init and calendar setting have been removed from c_diag_manager.
time_manager_init is now called in cfms_init.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. Will update in subsequent PR in pyFMS. To track these changes lets open issues in pyFMS moving forward.

contains

subroutine cFMS_diag_end() bind(C, name="cFMS_diag_end")
Expand All @@ -78,23 +72,15 @@ subroutine cFMS_diag_end() bind(C, name="cFMS_diag_end")
end subroutine cFMS_diag_end

!cFMS_diag_init
subroutine cFMS_diag_init(diag_model_subset, time_init, err_msg, calendar_type) bind(C, name='cFMS_diag_init')
subroutine cFMS_diag_init(diag_model_subset, time_init, err_msg) bind(C, name='cFMS_diag_init')

implicit none
integer, intent(in), optional :: diag_model_subset
integer, intent(in), optional :: time_init(6)
integer, intent(in), optional :: calendar_type
character(c_char), intent(out), optional :: err_msg(MESSAGE_LENGTH)

integer :: nfields

integer :: nfields
character(len=MESSAGE_LENGTH-1) :: err_msg_f = "None"
integer :: calendar_type_f = NOLEAP

if(present(calendar_type)) calendar_type_f = NOLEAP

call fms_time_manager_init()
call fms_time_manager_set_calendar_type(calendar_type_f)

call fms_diag_init(diag_model_subset = diag_model_subset, &
time_init = time_init, &
Expand Down
7 changes: 1 addition & 6 deletions c_diag_manager/c_diag_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ extern const int DIAG_OTHER;
extern const int DIAG_OCEAN;
extern const int DIAG_ALL;

extern const int THIRTY_DAY_MONTHS;
extern const int GREGORIAN;
extern const int JULIAN;
extern const int NOLEAP;

extern void cFMS_diag_init(int *diag_model_subset, int *time_init, int *calendar_type, char *err_msg);
extern void cFMS_diag_init(int *diag_model_subset, int *time_init, char *err_msg);

extern int cFMS_diag_axis_init_cfloat(char *name, int *naxis_data, float *axis_data, char *units, char *cart_name,
char *long_name, int *direction, char *set_name, int *edges, char *aux,
Expand Down
23 changes: 20 additions & 3 deletions c_fms/c_fms.F90
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ module c_fms_mod
use FMS, only : fms_mpp_domains_set_compute_domain, fms_mpp_domains_set_data_domain, fms_mpp_domains_set_global_domain
use FMS, only : fms_mpp_domains_update_domains

use FMS, only : THIRTY_DAY_MONTHS, GREGORIAN, JULIAN, NOLEAP
use FMS, only : fms_time_manager_init, fms_time_manager_set_calendar_type


use FMS, only : GLOBAL_DATA_DOMAIN, BGRID_NE, CGRID_NE, DGRID_NE, AGRID
use FMS, only : FOLD_SOUTH_EDGE, FOLD_NORTH_EDGE, FOLD_WEST_EDGE, FOLD_EAST_EDGE

Expand Down Expand Up @@ -64,8 +68,8 @@ module c_fms_mod
public :: cFMS_set_data_domain
public :: cFMS_set_global_domain

integer, parameter :: NAME_LENGTH = 64 !< value taken from mpp_domains
integer, parameter :: MESSAGE_LENGTH=128
integer, public, parameter :: NAME_LENGTH = 64 !< value taken from mpp_domains
integer, public, parameter :: MESSAGE_LENGTH=128
character(NAME_LENGTH), parameter :: input_nml_path="./input.nml"

integer, public, bind(C, name="cFMS_pelist_npes") :: npes
Expand Down Expand Up @@ -97,6 +101,11 @@ module c_fms_mod
integer, public, bind(C, name="WEST") :: WEST_C = WEST
integer, public, bind(C, name="NORTH_WEST") :: NORTH_WEST_C = NORTH_WEST

integer, public, bind(C, name="THIRTY_DAY_MONTHS") :: THIRTY_DAY_MONTHS_C = THIRTY_DAY_MONTHS
integer, public, bind(C, name="GREGORIAN") :: GREGORIAN_C = GREGORIAN
integer, public, bind(C, name="JULIAN") :: JULIAN_C = JULIAN
integer, public, bind(C, name="NOLEAP") :: NOLEAP_C = NOLEAP

type(FmsMppDomain2D), allocatable, target, public :: domain(:)
type(FmsMppDomain2D), pointer :: current_domain

Expand All @@ -112,12 +121,13 @@ subroutine cFMS_end() bind(C, name="cFMS_end")
end subroutine cFMS_end

!> cfms_init
subroutine cFMS_init(localcomm, alt_input_nml_path, ndomain, nnest_domain) bind(C, name="cFMS_init")
subroutine cFMS_init(localcomm, alt_input_nml_path, ndomain, nnest_domain, calendar_type) bind(C, name="cFMS_init")

implicit none
integer, intent(in), optional :: localcomm
integer, intent(in), optional :: ndomain
integer, intent(in), optional :: nnest_domain
integer, intent(in), optional :: calendar_type
character(c_char), intent(in), optional :: alt_input_nml_path(NAME_LENGTH)

character(100) :: alt_input_nml_path_f = input_nml_path
Expand All @@ -127,6 +137,13 @@ subroutine cFMS_init(localcomm, alt_input_nml_path, ndomain, nnest_domain) bind(

call fms_init(localcomm=localcomm, alt_input_nml_path=alt_input_nml_path_f)
call fms_mpp_domains_init()

call fms_time_manager_init()
if(present(calendar_type)) then
call fms_time_manager_set_calendar_type(calendar_type)
else
call fms_time_manager_set_calendar_type(NOLEAP)
end if

if(present(ndomain)) then
allocate(domain(0:ndomain-1))
Expand Down
7 changes: 6 additions & 1 deletion c_fms/c_fms.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ extern int WEST;
extern int NORTH_WEST;
extern int CYCLIC_GLOBAL_DOMAIN;

extern void cFMS_init(int *localcomm, char *alt_input_nml_path, int *ndomain, int *nnest_domain);
extern const int THIRTY_DAY_MONTHS;
extern const int GREGORIAN;
extern const int JULIAN;
extern const int NOLEAP;

extern void cFMS_init(int *localcomm, char *alt_input_nml_path, int *ndomain, int *nnest_domain, int *calendar_type);

extern void cFMS_end();

Expand Down
6 changes: 4 additions & 2 deletions test_cfms/c_data_override/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ TESTS = test_data_override.sh

test_data_override_SOURCES = ../c_fms/c_mpp_domains_helper.c test_data_override.c

test_data_override_ongrid : test_data_override_ongrid.F90
$(FC) $(FCFLAGS) $(LDFLAGS) -I./include test_data_override_ongrid.F90 -o test_data_override_ongrid

TEST_EXTENSIONS = .sh
SH_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(abs_top_srcdir)/test_cfms/tap-driver.sh
Expand All @@ -39,5 +42,4 @@ SH_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
EXTRA_DIST = test_data_override.sh

# Clean up
CLEANFILES = input.nml *.out *.dpi *.spi *.dyn *.spl *_table* input* *trs *.nc*

CLEANFILES = *.nml* *.out *.dpi *.spi *.dyn *.spl *_table* input* *trs *.nc*
Loading