From 1090c2f454267ecd0c5a6246b339b219a97328d7 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Mon, 3 Jul 2023 17:29:10 -0400 Subject: [PATCH 01/14] Getting the long string --- src/bufr_c2f_interface.F90 | 68 ++++++++++++++++++++++++++++++++++++++ src/bufr_interface.h | 4 +++ test/test_c_interface.c | 56 +++++++++++++++++++++++++++++-- 3 files changed, 125 insertions(+), 3 deletions(-) diff --git a/src/bufr_c2f_interface.F90 b/src/bufr_c2f_interface.F90 index 98447a6d..fd193e29 100644 --- a/src/bufr_c2f_interface.F90 +++ b/src/bufr_c2f_interface.F90 @@ -587,6 +587,74 @@ subroutine get_inv_c(lun, inv_ptr, inv_size) bind(C, name='get_inv_f') inv_ptr = c_loc(inv(1, lun)) end subroutine get_inv_c + !> Function used to get long strings from the BUFR file. + !> + !> @param lun - File ID. + !> @param str_id - Mnemonic for the string for the source field plus the index number + !> (ex: 'IDMN#2') + !> @param output_str - The pre-allocated result string + !> @param output_str_len - The length of the result string + !> + !> @author Ronald McLaren @date 2023-07-03 + subroutine readlc_c(lun, str_id, output_str, output_str_len) bind(C, name='readlc_f') + use moda_rlccmn + integer(c_int), value, intent(in) :: lun + character(kind=c_char, len=1), intent(in) :: str_id + character(kind=c_char, len=1), intent(out) :: output_str + integer(c_int), intent(out) :: output_str_len + + character(len=120) :: output_str_f + + call readlc(lun, output_str_f , c_f_string(str_id)) + call copy_f_c_str(output_str_f, output_str, len(output_str_f)) + output_str_len = len(trim(output_str_f)) + end subroutine readlc_c + +! !> Get pointer to the moda_usrint INV array. +! !> +! !> @param lun - File ID. +! !> @param inv_ptr - C-style pointer to the INV array +! !> @param inv_size - Length of the array +! !> +! !> @author Ronald McLaren @date 2022-03-23 +! subroutine get_long_str_c(lun, node_idx, str_ptr, str_len) bind(C, name='get_long_str_f') +! use moda_usrint +! use moda_usrbit +! use moda_unptyp +! use moda_bitbuf +! use moda_tables +! use moda_rlccmn +! +! integer(c_int), value, intent(in) :: lun +! integer(c_int), intent(in) :: node_idx +! character(kind=c_char, len=1), intent(inout) :: c_str(*) +! integer(c_int), intent(out) :: str_len +! +! character f_str(*) +! integer str_idx +! integer kbit +! +! if (msgunp(lun) .eq. 0 .or. msgunp(lun).eq.1) then +! ! The message is uncompressed +! str_len = nbit(node_idx)/8 +! kbit = mbit(node_idx) +! elseif (msgunp(lun) .eq. 2) then +! ! The message is compressed +! do str_idx=1,nrst +! if (tag(node_idx) .eq. crtag(str_idx)) then +! str_len = irnch(str_idx) +! kbit = irbit(str_idx) +! end if +! end do +! endif +! +! call upc(f_str, str_len, mbay(1, lun), kbit, .true.) +! call copy_f_c_str(f_str, c_str, str_len) +! +! end subroutine get_long_str_c + + + !> Deletes the copies of the moda_tables arrays. !> !> @author Ronald McLaren @date 2022-03-23 diff --git a/src/bufr_interface.h b/src/bufr_interface.h index 9046de35..3243ccf3 100644 --- a/src/bufr_interface.h +++ b/src/bufr_interface.h @@ -372,6 +372,10 @@ extern "C" { */ void get_inv_f(int lun, int** inv_ptr, int* inv_size); + + void readlc_f(int lun, char* str_id, char** output_str, int* output_str_len); + + /** * Deletes the copies of the moda_tables arrays. * diff --git a/test/test_c_interface.c b/test/test_c_interface.c index ae19d564..4968f7b7 100644 --- a/test/test_c_interface.c +++ b/test/test_c_interface.c @@ -17,13 +17,14 @@ static const int BUFR_FILE_UNIT = 12; static const int SUBSET_STRING_LEN = 10; static const char* INPUT_FILE = "testfiles/data/1bamua"; +static const char* INPUT_FILE_LONG_STR = "testfiles/OUT_10"; // Supporting functions -unsigned int countSubsets(const char* subset) +unsigned int countSubsets(const char* filePath, const char* subset) { - open_f(BUFR_FILE_UNIT, INPUT_FILE); + open_f(BUFR_FILE_UNIT, filePath); openbf_f(BUFR_FILE_UNIT, "IN", BUFR_FILE_UNIT); int iddate; @@ -58,7 +59,7 @@ void test_basicInterface() int iret; int iddate; char msg_subset[SUBSET_STRING_LEN]; - unsigned int subset_cnt = countSubsets(subset); + unsigned int subset_cnt = countSubsets(INPUT_FILE, subset); unsigned int idx; open_f(BUFR_FILE_UNIT, INPUT_FILE); @@ -112,6 +113,54 @@ void test_basicInterface() close_f(BUFR_FILE_UNIT); } +void test_longStrings() +{ + const char* subset = "NC002104"; + const char* mnemonic = "SOFTV"; + + int iret; + int iddate; + char msg_subset[SUBSET_STRING_LEN]; + unsigned int subset_cnt = countSubsets(INPUT_FILE_LONG_STR, subset); + unsigned int idx; + + open_f(BUFR_FILE_UNIT, INPUT_FILE_LONG_STR); + openbf_f(BUFR_FILE_UNIT, "IN", BUFR_FILE_UNIT); + + int bufrLoc; + int il, im; // throw away + + char* long_str_ptr[120]; + int long_str_len_ptr; + + int subset_idx = 0; + while (ireadmg_f(BUFR_FILE_UNIT, msg_subset, &iddate, SUBSET_STRING_LEN) == 0) + { + while ((ireadsb_f(BUFR_FILE_UNIT) == 0) && (subset_idx < MAX_SUBSETS)) + { + status_f(BUFR_FILE_UNIT, &bufrLoc, &il, &im); + readlc_f(BUFR_FILE_UNIT, mnemonic, &long_str_ptr, &long_str_len_ptr); + break; + } + break; + } + + if (strncmp(long_str_ptr, "MW41 2.17.0", 11) != 0) + { + printf("%s", "Didn't read the correct long string for SOFTV."); + exit(1); + } + + if (long_str_len_ptr != 11) + { + printf("%s", "Didn't read the correct long string length for SOFTV."); + exit(1); + } + + closbf_f(BUFR_FILE_UNIT); + close_f(BUFR_FILE_UNIT); +} + int cIdx(int fortranIdx) { @@ -478,6 +527,7 @@ void test_getTypeInfo() int main() { test_basicInterface(); + test_longStrings(); test_intrusiveInterface(); test_getTypeInfo(); From 14efcab20613218dc798efd6b68ed7396527b9e4 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Wed, 5 Jul 2023 09:36:38 -0400 Subject: [PATCH 02/14] removed some extra lines from test --- test/test_c_interface.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/test_c_interface.c b/test/test_c_interface.c index 4968f7b7..9e7ca926 100644 --- a/test/test_c_interface.c +++ b/test/test_c_interface.c @@ -115,14 +115,10 @@ void test_basicInterface() void test_longStrings() { - const char* subset = "NC002104"; const char* mnemonic = "SOFTV"; - int iret; int iddate; char msg_subset[SUBSET_STRING_LEN]; - unsigned int subset_cnt = countSubsets(INPUT_FILE_LONG_STR, subset); - unsigned int idx; open_f(BUFR_FILE_UNIT, INPUT_FILE_LONG_STR); openbf_f(BUFR_FILE_UNIT, "IN", BUFR_FILE_UNIT); From c5399d9e9b2aa61beba3a74d5b5db737131caa90 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Wed, 12 Jul 2023 18:21:43 -0400 Subject: [PATCH 03/14] added readlc --- src/bufr_c2f_interface.F90 | 10 +++++----- src/bufr_interface.h | 2 +- test/test_c_interface.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bufr_c2f_interface.F90 b/src/bufr_c2f_interface.F90 index fd193e29..fa7de0c8 100644 --- a/src/bufr_c2f_interface.F90 +++ b/src/bufr_c2f_interface.F90 @@ -589,23 +589,23 @@ end subroutine get_inv_c !> Function used to get long strings from the BUFR file. !> - !> @param lun - File ID. + !> @param lunit - Fortran logical unit. !> @param str_id - Mnemonic for the string for the source field plus the index number !> (ex: 'IDMN#2') !> @param output_str - The pre-allocated result string !> @param output_str_len - The length of the result string !> !> @author Ronald McLaren @date 2023-07-03 - subroutine readlc_c(lun, str_id, output_str, output_str_len) bind(C, name='readlc_f') + subroutine readlc_c(lunit, str_id, output_str, output_str_len) bind(C, name='readlc_f') use moda_rlccmn - integer(c_int), value, intent(in) :: lun + integer(c_int), value, intent(in) :: lunit character(kind=c_char, len=1), intent(in) :: str_id - character(kind=c_char, len=1), intent(out) :: output_str + character(kind=c_char), intent(out) :: output_str(*) integer(c_int), intent(out) :: output_str_len character(len=120) :: output_str_f - call readlc(lun, output_str_f , c_f_string(str_id)) + call readlc(lunit, output_str_f , c_f_string(str_id)) call copy_f_c_str(output_str_f, output_str, len(output_str_f)) output_str_len = len(trim(output_str_f)) end subroutine readlc_c diff --git a/src/bufr_interface.h b/src/bufr_interface.h index 3243ccf3..717b5702 100644 --- a/src/bufr_interface.h +++ b/src/bufr_interface.h @@ -373,7 +373,7 @@ extern "C" { void get_inv_f(int lun, int** inv_ptr, int* inv_size); - void readlc_f(int lun, char* str_id, char** output_str, int* output_str_len); + void readlc_f(int lun, const char* str_id, char* output_str, int* output_str_len); /** diff --git a/test/test_c_interface.c b/test/test_c_interface.c index 9e7ca926..5c0f8d46 100644 --- a/test/test_c_interface.c +++ b/test/test_c_interface.c @@ -126,7 +126,7 @@ void test_longStrings() int bufrLoc; int il, im; // throw away - char* long_str_ptr[120]; + char long_str[120]; int long_str_len_ptr; int subset_idx = 0; @@ -135,13 +135,13 @@ void test_longStrings() while ((ireadsb_f(BUFR_FILE_UNIT) == 0) && (subset_idx < MAX_SUBSETS)) { status_f(BUFR_FILE_UNIT, &bufrLoc, &il, &im); - readlc_f(BUFR_FILE_UNIT, mnemonic, &long_str_ptr, &long_str_len_ptr); + readlc_f(BUFR_FILE_UNIT, mnemonic, &long_str, &long_str_len_ptr); break; } break; } - if (strncmp(long_str_ptr, "MW41 2.17.0", 11) != 0) + if (strncmp(long_str, "MW41 2.17.0", 11) != 0) { printf("%s", "Didn't read the correct long string for SOFTV."); exit(1); From ad0366d4ba534bd956ea4cdffd0543583976db4d Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Thu, 3 Aug 2023 14:59:16 -0400 Subject: [PATCH 04/14] small tweak --- src/bufr_c2f_interface.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bufr_c2f_interface.F90 b/src/bufr_c2f_interface.F90 index fa7de0c8..9e60dc3d 100644 --- a/src/bufr_c2f_interface.F90 +++ b/src/bufr_c2f_interface.F90 @@ -26,7 +26,7 @@ module bufr_c2f_interface public :: ufbint_c, ufbrep_c, ufbseq_c public :: mtinfo_c, bvers_c, status_c, ibfms_c public :: get_isc_c, get_link_c, get_itp_c, get_typ_c, get_tag_c, get_jmpb_c - public :: get_inode_c, get_nval_c, get_val_c, get_inv_c, get_irf_c + public :: get_inode_c, get_nval_c, get_val_c, get_inv_c, get_irf_c, readlc_c public :: delete_table_data_c public :: iupbs01_c, iupb_c, imrkopr_c, istdesc_c, ifxy_c public :: igetntbi_c, igettdi_c, stntbi_c From 26fe58561f9b6a33eb56474bc2c516909ea5daa7 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Fri, 11 Aug 2023 11:22:45 -0400 Subject: [PATCH 05/14] added comment to readlc_c in bufr_interface.h --- src/bufr_interface.h | 12 +++++++++++- src/irev.F | 12 +++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/bufr_interface.h b/src/bufr_interface.h index 717b5702..1a708e92 100644 --- a/src/bufr_interface.h +++ b/src/bufr_interface.h @@ -372,10 +372,20 @@ extern "C" { */ void get_inv_f(int lun, int** inv_ptr, int* inv_size); +/** + * Function used to get long strings from the BUFR file. + * + * @param lunit - Fortran logical unit. + * @param str_id - Mnemonic for the string for the source field plus the index number + * (ex: 'IDMN#2') + * @param output_str - The pre-allocated result string + * @param output_str_len - The length of the result string + * + * @author Ronald McLaren @date 2023-07-03 + */ void readlc_f(int lun, const char* str_id, char* output_str, int* output_str_len); - /** * Deletes the copies of the moda_tables arrays. * diff --git a/src/irev.F b/src/irev.F index 86136008..3e96552a 100644 --- a/src/irev.F +++ b/src/irev.F @@ -44,9 +44,15 @@ FUNCTION IREV(N) IREV = N #else INT = N - DO I=1,NBYTW - DINT(I:I) = CINT(IORD(I):IORD(I)) - ENDDO + + DINT(1:1) = CINT(4:4) + DINT(2:2) = CINT(3:3) + DINT(3:3) = CINT(2:2) + DINT(4:4) = CINT(1:1) + +! DO I=1,NBYTW +! DINT(I:I) = CINT(IORD(I):IORD(I)) +! ENDDO IREV = JNT #endif From 220e8feeae35e714170ba17645df7dc26dc86148 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Fri, 11 Aug 2023 12:39:08 -0400 Subject: [PATCH 06/14] removed commented out code --- src/bufr_c2f_interface.F90 | 45 -------------------------------------- 1 file changed, 45 deletions(-) diff --git a/src/bufr_c2f_interface.F90 b/src/bufr_c2f_interface.F90 index 9e60dc3d..78e8875b 100644 --- a/src/bufr_c2f_interface.F90 +++ b/src/bufr_c2f_interface.F90 @@ -610,51 +610,6 @@ subroutine readlc_c(lunit, str_id, output_str, output_str_len) bind(C, name='rea output_str_len = len(trim(output_str_f)) end subroutine readlc_c -! !> Get pointer to the moda_usrint INV array. -! !> -! !> @param lun - File ID. -! !> @param inv_ptr - C-style pointer to the INV array -! !> @param inv_size - Length of the array -! !> -! !> @author Ronald McLaren @date 2022-03-23 -! subroutine get_long_str_c(lun, node_idx, str_ptr, str_len) bind(C, name='get_long_str_f') -! use moda_usrint -! use moda_usrbit -! use moda_unptyp -! use moda_bitbuf -! use moda_tables -! use moda_rlccmn -! -! integer(c_int), value, intent(in) :: lun -! integer(c_int), intent(in) :: node_idx -! character(kind=c_char, len=1), intent(inout) :: c_str(*) -! integer(c_int), intent(out) :: str_len -! -! character f_str(*) -! integer str_idx -! integer kbit -! -! if (msgunp(lun) .eq. 0 .or. msgunp(lun).eq.1) then -! ! The message is uncompressed -! str_len = nbit(node_idx)/8 -! kbit = mbit(node_idx) -! elseif (msgunp(lun) .eq. 2) then -! ! The message is compressed -! do str_idx=1,nrst -! if (tag(node_idx) .eq. crtag(str_idx)) then -! str_len = irnch(str_idx) -! kbit = irbit(str_idx) -! end if -! end do -! endif -! -! call upc(f_str, str_len, mbay(1, lun), kbit, .true.) -! call copy_f_c_str(f_str, c_str, str_len) -! -! end subroutine get_long_str_c - - - !> Deletes the copies of the moda_tables arrays. !> !> @author Ronald McLaren @date 2022-03-23 From e1a40f8251fb8be231546b8868f8df3fde4ddcc1 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Fri, 11 Aug 2023 12:40:51 -0400 Subject: [PATCH 07/14] undid inadvertant change to irev --- src/irev.F | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/irev.F b/src/irev.F index 3e96552a..86136008 100644 --- a/src/irev.F +++ b/src/irev.F @@ -44,15 +44,9 @@ FUNCTION IREV(N) IREV = N #else INT = N - - DINT(1:1) = CINT(4:4) - DINT(2:2) = CINT(3:3) - DINT(3:3) = CINT(2:2) - DINT(4:4) = CINT(1:1) - -! DO I=1,NBYTW -! DINT(I:I) = CINT(IORD(I):IORD(I)) -! ENDDO + DO I=1,NBYTW + DINT(I:I) = CINT(IORD(I):IORD(I)) + ENDDO IREV = JNT #endif From 839232e1d95c26fbfb5374f2dc79f608e670e99d Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Sat, 26 Aug 2023 12:33:56 -0400 Subject: [PATCH 08/14] fixed lunit, lun label issue --- src/bufr_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bufr_interface.h b/src/bufr_interface.h index 1a708e92..a257b16d 100644 --- a/src/bufr_interface.h +++ b/src/bufr_interface.h @@ -384,7 +384,7 @@ extern "C" { * @author Ronald McLaren @date 2023-07-03 */ - void readlc_f(int lun, const char* str_id, char* output_str, int* output_str_len); + void readlc_f(int lunit, const char* str_id, char* output_str, int* output_str_len); /** * Deletes the copies of the moda_tables arrays. From f600caaf4eaf7ee4a017284a71a4c01764f9be9f Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Mon, 28 Aug 2023 14:02:31 -0400 Subject: [PATCH 09/14] implemented Jeff's suggenstion to fix type issue in linter --- src/bufr_c2f_interface.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bufr_c2f_interface.F90 b/src/bufr_c2f_interface.F90 index 78e8875b..4be3bfdd 100644 --- a/src/bufr_c2f_interface.F90 +++ b/src/bufr_c2f_interface.F90 @@ -600,7 +600,7 @@ subroutine readlc_c(lunit, str_id, output_str, output_str_len) bind(C, name='rea use moda_rlccmn integer(c_int), value, intent(in) :: lunit character(kind=c_char, len=1), intent(in) :: str_id - character(kind=c_char), intent(out) :: output_str(*) + character(kind=c_char, len=1), intent(out) :: output_str(*) integer(c_int), intent(out) :: output_str_len character(len=120) :: output_str_f From 9836c090d1b0fa0793fdc38bc4308dcfa97f8c31 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Mon, 28 Aug 2023 14:24:57 -0400 Subject: [PATCH 10/14] amnother try --- src/bufr_c2f_interface.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bufr_c2f_interface.F90 b/src/bufr_c2f_interface.F90 index 4be3bfdd..4ed076d0 100644 --- a/src/bufr_c2f_interface.F90 +++ b/src/bufr_c2f_interface.F90 @@ -599,7 +599,7 @@ end subroutine get_inv_c subroutine readlc_c(lunit, str_id, output_str, output_str_len) bind(C, name='readlc_f') use moda_rlccmn integer(c_int), value, intent(in) :: lunit - character(kind=c_char, len=1), intent(in) :: str_id + character(kind=c_char, len=1), intent(in) :: str_id(*) character(kind=c_char, len=1), intent(out) :: output_str(*) integer(c_int), intent(out) :: output_str_len From 835f574742d42791e2d2a4922924b52f07c0b0f1 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Mon, 28 Aug 2023 14:42:22 -0400 Subject: [PATCH 11/14] fixed odity in test file --- test/test_c_interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_c_interface.c b/test/test_c_interface.c index 5c0f8d46..9fadaf58 100644 --- a/test/test_c_interface.c +++ b/test/test_c_interface.c @@ -135,7 +135,7 @@ void test_longStrings() while ((ireadsb_f(BUFR_FILE_UNIT) == 0) && (subset_idx < MAX_SUBSETS)) { status_f(BUFR_FILE_UNIT, &bufrLoc, &il, &im); - readlc_f(BUFR_FILE_UNIT, mnemonic, &long_str, &long_str_len_ptr); + readlc_f(BUFR_FILE_UNIT, mnemonic, long_str, &long_str_len_ptr); break; } break; From 842fce005cfad43ada28f6b80f0f685bf3b168dd Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Tue, 29 Aug 2023 09:54:45 -0400 Subject: [PATCH 12/14] long string length now passed as an input. --- src/bufr_c2f_interface.F90 | 7 ++++--- src/bufr_interface.h | 2 +- test/test_c_interface.c | 14 +++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/bufr_c2f_interface.F90 b/src/bufr_c2f_interface.F90 index 4ed076d0..3ec03987 100644 --- a/src/bufr_c2f_interface.F90 +++ b/src/bufr_c2f_interface.F90 @@ -601,13 +601,14 @@ subroutine readlc_c(lunit, str_id, output_str, output_str_len) bind(C, name='rea integer(c_int), value, intent(in) :: lunit character(kind=c_char, len=1), intent(in) :: str_id(*) character(kind=c_char, len=1), intent(out) :: output_str(*) - integer(c_int), intent(out) :: output_str_len + integer(c_int), intent(in), value :: output_str_len character(len=120) :: output_str_f + integer :: output_str_len_f call readlc(lunit, output_str_f , c_f_string(str_id)) - call copy_f_c_str(output_str_f, output_str, len(output_str_f)) - output_str_len = len(trim(output_str_f)) + output_str_len_f = len(trim(output_str_f)) + 1 ! add 1 for the null terminator + call copy_f_c_str(output_str_f, output_str, min(output_str_len_f, output_str_len)) end subroutine readlc_c !> Deletes the copies of the moda_tables arrays. diff --git a/src/bufr_interface.h b/src/bufr_interface.h index a257b16d..b7f74749 100644 --- a/src/bufr_interface.h +++ b/src/bufr_interface.h @@ -384,7 +384,7 @@ extern "C" { * @author Ronald McLaren @date 2023-07-03 */ - void readlc_f(int lunit, const char* str_id, char* output_str, int* output_str_len); + void readlc_f(int lunit, const char* str_id, char* output_str, int output_str_len); /** * Deletes the copies of the moda_tables arrays. diff --git a/test/test_c_interface.c b/test/test_c_interface.c index 9fadaf58..c35801eb 100644 --- a/test/test_c_interface.c +++ b/test/test_c_interface.c @@ -115,6 +115,7 @@ void test_basicInterface() void test_longStrings() { + static const int LONG_STR_LEN = 120; const char* mnemonic = "SOFTV"; int iddate; @@ -126,8 +127,7 @@ void test_longStrings() int bufrLoc; int il, im; // throw away - char long_str[120]; - int long_str_len_ptr; + char long_str[LONG_STR_LEN]; int subset_idx = 0; while (ireadmg_f(BUFR_FILE_UNIT, msg_subset, &iddate, SUBSET_STRING_LEN) == 0) @@ -135,21 +135,21 @@ void test_longStrings() while ((ireadsb_f(BUFR_FILE_UNIT) == 0) && (subset_idx < MAX_SUBSETS)) { status_f(BUFR_FILE_UNIT, &bufrLoc, &il, &im); - readlc_f(BUFR_FILE_UNIT, mnemonic, long_str, &long_str_len_ptr); + readlc_f(BUFR_FILE_UNIT, mnemonic, long_str, LONG_STR_LEN); break; } break; } - if (strncmp(long_str, "MW41 2.17.0", 11) != 0) + if (strlen(long_str) != 11) { - printf("%s", "Didn't read the correct long string for SOFTV."); + printf("%s", "Didn't read the correct long string length for SOFTV."); exit(1); } - if (long_str_len_ptr != 11) + if (strncmp(long_str, "MW41 2.17.0", 11) != 0) { - printf("%s", "Didn't read the correct long string length for SOFTV."); + printf("%s", "Didn't read the correct long string for SOFTV."); exit(1); } From 5418a10d6e3ecb3cf1e7db045f277edd1d8f0e16 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Tue, 29 Aug 2023 10:03:42 -0400 Subject: [PATCH 13/14] tweaked doc string on readlc --- src/bufr_c2f_interface.F90 | 2 +- src/bufr_interface.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bufr_c2f_interface.F90 b/src/bufr_c2f_interface.F90 index 3ec03987..2bf69581 100644 --- a/src/bufr_c2f_interface.F90 +++ b/src/bufr_c2f_interface.F90 @@ -593,7 +593,7 @@ end subroutine get_inv_c !> @param str_id - Mnemonic for the string for the source field plus the index number !> (ex: 'IDMN#2') !> @param output_str - The pre-allocated result string - !> @param output_str_len - The length of the result string + !> @param output_str_len - Size of the result string buffer !> !> @author Ronald McLaren @date 2023-07-03 subroutine readlc_c(lunit, str_id, output_str, output_str_len) bind(C, name='readlc_f') diff --git a/src/bufr_interface.h b/src/bufr_interface.h index b7f74749..156c520c 100644 --- a/src/bufr_interface.h +++ b/src/bufr_interface.h @@ -379,7 +379,7 @@ extern "C" { * @param str_id - Mnemonic for the string for the source field plus the index number * (ex: 'IDMN#2') * @param output_str - The pre-allocated result string - * @param output_str_len - The length of the result string + * @param output_str_len - Size of the result string buffer * * @author Ronald McLaren @date 2023-07-03 */ From bdddb02e300cfce9d1cf1985bed3c5e819892bd3 Mon Sep 17 00:00:00 2001 From: Ron McLaren Date: Tue, 29 Aug 2023 10:11:21 -0400 Subject: [PATCH 14/14] removed extra space --- src/bufr_c2f_interface.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bufr_c2f_interface.F90 b/src/bufr_c2f_interface.F90 index 2bf69581..ff745c89 100644 --- a/src/bufr_c2f_interface.F90 +++ b/src/bufr_c2f_interface.F90 @@ -606,7 +606,7 @@ subroutine readlc_c(lunit, str_id, output_str, output_str_len) bind(C, name='rea character(len=120) :: output_str_f integer :: output_str_len_f - call readlc(lunit, output_str_f , c_f_string(str_id)) + call readlc(lunit, output_str_f, c_f_string(str_id)) output_str_len_f = len(trim(output_str_f)) + 1 ! add 1 for the null terminator call copy_f_c_str(output_str_f, output_str, min(output_str_len_f, output_str_len)) end subroutine readlc_c