Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Finding location of x in array..

donkarnage
Beginner
303 Views
Hello everyone !

Two questions:

1. Is there an intrinsic function similar to MAXLOC/MINLOC that will allow me to locate the index of a say a value "n" in an array ..and return an error code if it does not ?

2. I am trying to read a config file that dictates the behavior of my code. The config file contains some line that provide description followed by the parameter values. for eg:

***** now defining pulse shape ***********
t_rise t_fall t_on s_factor
0.1 0.1 5 105


SO in this the first two lines are essentially junk,from the code's perspective. I tried reading them an a character strings, but what happens is that the first such read statement return ONLY ***** , and not the Character line.

Any input will be deeply appreciated.

Cheers !
0 Kudos
2 Replies
TimP
Honored Contributor III
303 Views
1. A simple search is often done by writing out a counted DO loop with an EXIT for the compare match, so you could treat it as an error if the loop terminates on count without a match found. It no longer takes any special tricks to persuade ifort to optimize this, even on Itanium.
This could be done also by using MINLOC() on the absolute value of the difference between the array and the target value. That might be as good a method as any, in case you can't assure an exact floating point match. Then your error condition would be where the minimum absolute difference exceeds your tolerance.
2. Are you reading into a CHARACTER variable large enough to contain the input line? If you don't want to do that, you can skip lines with a plain READ with no iolist. You might add IOSTAT processing to your READ to make it easier to catch problems.
0 Kudos
donkarnage
Beginner
303 Views


tim18 wrote:
1. A simple search is often done by writing out a counted DO loop with an EXIT for the compare match, so you could treat it as an error if the loop terminates on count without a match found. It no longer takes any special tricks to persuade ifort to optimize this, even on Itanium.
This could be done also by using MINLOC() on the absolute value of the difference between the array and the target value. That might be as good a method as any, in case you can't assure an exact floating point match. Then your error condition would be where the minimum absolute difference exceeds your tolerance.
2. Are you reading into a CHARACTER variable large enough to contain the input line? If you don't want to do that, you can skip lines with a plain READ with no iolist. You might add IOSTAT processing to your READ to make it easier to catch problems.





Hi there...

I was thinking about the MINLOC as you had suggested and decided against it. Instead went with an explicit "look-and-match" option. Needless to mention - does the job accurately, however, when the target vectors are long (i.e where i am looking), the check time per iteration increases (since this look happen inside an outer loop).

Will try the idea about the blank read you suggested to jump over unwanted lines in a txt file and post my results here soon !

Thanks for the response. I have another question and i am going to post that in a different thread.

Cheers !
0 Kudos
Reply