From a9506e7381244b4a5267e3bf94fa2259acf6653d Mon Sep 17 00:00:00 2001 From: Enrico Fucile Date: Tue, 8 Nov 2016 14:11:12 +0000 Subject: [PATCH] exposed julian, datetime functions in fortran --- fortran/eccodes_f90_tail.f90 | 52 +++++++++++++++++++++++++++++++++++- fortran/eccodes_visibility.h | 1 + fortran/grib_api_externals.h | 1 + fortran/grib_fortran.c | 33 +++++++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) diff --git a/fortran/eccodes_f90_tail.f90 b/fortran/eccodes_f90_tail.f90 index 381e1957e..4ea059847 100644 --- a/fortran/eccodes_f90_tail.f90 +++ b/fortran/eccodes_f90_tail.f90 @@ -2573,6 +2573,56 @@ subroutine codes_set_samples_path ( path, status ) end subroutine codes_set_samples_path +subroutine codes_julian_to_datetime ( jd,year,month,day,hour,minute,second, status ) + real(kind=kindOfDouble) , intent(in) :: jd + integer(kind=kindOfLong) , intent(out) :: year,month,day,hour,minute,second + integer(kind=kindOfInt),optional, intent(out) :: status + integer(kind=kindOfInt) :: iret + + iret=grib_f_julian_to_datetime(jd,year,month,day,hour,minute,second) + if (iret /= 0) then + if (present(status)) then + status = iret + else + call grib_check(iret,'codes_julian_to_datetime',' ') + endif + return + endif +end subroutine codes_julian_to_datetime + +subroutine codes_datetime_to_julian ( year,month,day,hour,minute,second,jd, status ) + integer(kind=kindOfLong) , intent(in) :: year,month,day,hour,minute,second + real (kind=kindOfDouble) , intent(out) :: jd + integer(kind=kindOfInt),optional, intent(out) :: status + integer(kind=kindOfInt) :: iret + + iret=grib_f_datetime_to_julian(year,month,day,hour,minute,second,jd) + if (iret /= 0) then + if (present(status)) then + status = iret + else + call grib_check(iret,'codes_datetime_to_julian',' ') + endif + return + endif +end subroutine codes_datetime_to_julian + + +subroutine codes_copy_key( msgin,msgout, key,type, status ) + integer(kind=kindOfInt), intent(in) :: msgin,msgout,type + character(len=*), intent(in) :: key + integer(kind=kindOfInt),optional, intent(out) :: status + integer(kind=kindOfInt) :: iret + + iret=grib_f_copy_key ( msgin,msgout, key, type, status ) + if (iret /= 0) then + if (present(status)) then + status = iret + else + call grib_check(iret,'codes_copy_key',key) + endif + return + endif +end subroutine codes_copy_key end module eccodes - diff --git a/fortran/eccodes_visibility.h b/fortran/eccodes_visibility.h index 3c958d09c..dbd69ae2b 100644 --- a/fortran/eccodes_visibility.h +++ b/fortran/eccodes_visibility.h @@ -27,3 +27,4 @@ public :: codes_clone, codes_copy_namespace public :: codes_index_get,codes_index_select,& codes_index_create,codes_index_get_size,codes_index_release,& codes_grib_util_sections_copy +public :: codes_datetime_to_julian,codes_julian_to_datetime,codes_copy_key diff --git a/fortran/grib_api_externals.h b/fortran/grib_api_externals.h index eb9e4a250..ffecc4a58 100644 --- a/fortran/grib_api_externals.h +++ b/fortran/grib_api_externals.h @@ -68,3 +68,4 @@ integer, external :: grib_f_clone, grib_f_copy_namespace external :: grib_f_check integer, external :: grib_f_util_sections_copy integer, external :: grib_f_set_definitions_path, grib_f_set_samples_path +integer, external :: grib_f_julian_to_datetime, grib_f_datetime_to_julian, grib_f_copy_key diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index 761f59c49..2e42ca581 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -1363,6 +1363,18 @@ int grib_f_clone(int* gidsrc,int* giddest){ return grib_f_clone_(gidsrc, giddest); } +/*****************************************************************************/ +int grib_f_copy_key_(int* gidsrc,int* giddest,const char* key,int *type,int len){ + char buf[512]={0,}; + grib_handle *src = get_handle(*gidsrc); + grib_handle *dest = get_handle(*giddest); + + if(src!=NULL && dest!=NULL){ + return codes_copy_key(src,dest,cast_char(buf,key,len),*type); + } + + return GRIB_INVALID_GRIB; +} /*****************************************************************************/ int grib_f_util_sections_copy_(int* gidfrom,int* gidto,int* what,int *gidout){ int err=0; @@ -3104,3 +3116,24 @@ int grib_f_set_samples_path__(char* path, int len){ int grib_f_set_samples_path(char* path, int len){ return grib_f_set_samples_path_(path, len); } + +int grib_f_julian_to_datetime(double* jd,long* year,long* month,long* day,long *hour,long *minute,long *second) { + return grib_julian_to_datetime(*jd,year,month,day,hour,minute,second); +} +int grib_f_julian_to_datetime_(double* jd,long* year,long* month,long* day,long *hour,long *minute,long *second) { + return grib_julian_to_datetime(*jd,year,month,day,hour,minute,second); +} +int grib_f_julian_to_datetime__(double* jd,long* year,long* month,long* day,long *hour,long *minute,long *second) { + return grib_julian_to_datetime(*jd,year,month,day,hour,minute,second); +} + +int grib_f_datetime_to_julian(long* year,long* month,long* day, long* hour,long* minute,long* second,double* jd) { + return grib_datetime_to_julian(*year,*month,*day,*hour,*minute,*second,jd); +} +int grib_f_datetime_to_julian_(long* year,long* month,long* day, long* hour,long* minute,long* second,double* jd) { + return grib_datetime_to_julian(*year,*month,*day,*hour,*minute,*second,jd); +} +int grib_f_datetime_to_julian__(long* year,long* month,long* day, long* hour,long* minute,long* second,double* jd) { + return grib_datetime_to_julian(*year,*month,*day,*hour,*minute,*second,jd); +} +