Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

MBINDEX doesn't appear to work

inaylor
Beginner
910 Views
Hi,

We are currently porting an application from Digital Fortran 6.0 and have hit a problem with the MBINDEX function.

Here's a test program that demonstrates the problem:

=============================

program nls1

use ifnls

implicit none

character*20 strHelloWorld
character*4 strW
integer*4 icb

strHelloWorld = 'Hello World'
strW = 'Worl'

icb = mbindex(strHelloWorld, strW)

print *, 'MBINDEX : icb = ', icb

end program nls1

==============================

icbreturns 0butshould return 7 (which the standard "index" function does)

Also, if strW isa single character, mbindex actually corrupts the strHelloWorld string and icb returns 2.

We are currently trialling version 11.0 Build 72 running on XP SP3 x86.

It looks pretty clear cut that there's a fault in the MBINDEX function unless anyone has anysuggestions ?

Thanks

Ian
0 Kudos
7 Replies
Kevin_D_Intel
Employee
910 Views

Does appear to be a bug with MBINDEX. Thank you for the convenient reproducer Ian. I will inquire with Development and will keep this thread updated with what I learn. (Internal tracking id: DPD200119565)
0 Kudos
inaylor
Beginner
910 Views

Does appear to be a bug with MBINDEX. Thank you for the convenient reproducer Ian. I will inquire with Development and will keep this thread updated with what I learn. (Internal tracking id: DPD200119565)

Fair enough. If youget a hotfix or a workaround that you want me to test, let me know.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
910 Views

Does appear to be a bug with MBINDEX. Thank you for the convenient reproducer Ian. I will inquire with Development and will keep this thread updated with what I learn. (Internal tracking id: DPD200119565)

I fail to see the advantage of MBINDEX to plain INDEX? Can someone enlighten me?

Let us take for example string S, which evaluates to "Hello " in Korean code page, and that last 4 characters take 2 bytes each. INDEX(S, '') should yield 9. (1+5+1+2 bytes for ). What is MBINDEX supposed to return? If 9, then it's no different from INDEX. If 8 (8-th actual character), that's OK, but what is programmer supposed to do with that information?


0 Kudos
inaylor
Beginner
910 Views
Quoting - Jugoslav Dujic

I fail to see the advantage of MBINDEX to plain INDEX? Can someone enlighten me?

Let us take for example string S, which evaluates to "Hello " in Korean code page, and that last 4 characters take 2 bytes each. INDEX(S, '') should yield 9. (1+5+1+2 bytes for ). What is MBINDEX supposed to return? If 9, then it's no different from INDEX. If 8 (8-th actual character), that's OK, but what is programmer supposed to do with that information?



To quote from the manual:


> Performs the same function as the INDEX intrinsic function except that the strings manipulated can contain multibyte characters.


We would expect that, in your example, the return value would be 8.

I don't know the specific circumstances around the use of this function butMBINDEX certainly allows for more consistent string manipulation. For example, if you add "World" onto your example string, then MBINDEX should return the same value(which INDEX wouldn't) when searching for"Wor" regardless of the content ofcharacters 7-10.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
910 Views
Quoting - inaylor

To quote from the manual:


> Performs the same function as the INDEX intrinsic function except that the strings manipulated can contain multibyte characters.


We would expect that, in your example, the return value would be 8.

I don't know the specific circumstances around the use of this function butMBINDEX certainly allows for more consistent string manipulation. For example, if you add "World" onto your example string, then MBINDEX should return the same value(which INDEX wouldn't) when searching for"Wor" regardless of the content ofcharacters 7-10.

My point was, why should you even know that piece of data? You are given a string which is an opaque stream of bytes. Plain INDEX returns the byte offset of the substring, and you can do some operations from that byte offset. MBINDEX returns the glyph offset, but you cannot know what those characters mean until you put it to some output renderer.

Consider:
[cpp]S = 'Hello  world'
i = INDEX(S, 'world')  ! =10
mb = INDEX(S, 'world') ! =9
S(i:i) = 'W'       !S = 'Hello  World'
S(mb:mb) = ???     !What to do with this?
[/cpp]

I would understand function such as MBLEN or MBLEN_TRIM, which would give you number of output glyphs (e.g. for graphic output), but purpose of MBINDEX escapes me.

0 Kudos
Steven_L_Intel1
Employee
910 Views
You can't use such positions for Fortran substring references, lacking compiler support for multibyte characters. You'd have to do all such manipulation with library routines. The reason for MBINDEX is that some encodings switch between 8 and 16 bit values depending on the character used, so simply looking for a sequence of bytes may give you the wrong answer.
0 Kudos
Kevin_D_Intel
Employee
910 Views

Does appear to be a bug with MBINDEX. Thank you for the convenient reproducer Ian. I will inquire with Development and will keep this thread updated with what I learn. (Internal tracking id: DPD200119565)

I confirmed this defect is fixed in the upcoming 11.1 release (mid June).
0 Kudos
Reply