FORTRAN -Returning index fir which values fall in a region


 
Thread Tools Search this Thread
Top Forums Programming FORTRAN -Returning index fir which values fall in a region
# 1  
Old 11-30-2010
FORTRAN -Returning index fir which values fall in a region

I have an 10 element array containing numbers, I want the start and end index in the array for which the values lie between DIST1 and DIST2. It is not working quite right. I also might want a value of 0 if I cannot find an index.


Code:
    V=(/10.0,20.0,30.0,40.0,50.0,60.0,70.0,80.0,90.0,100.0/)

    PRINT *, V
    PRINT *, DIST1, DIST2
    I = 1
    ISTART = 0
    DO WHILE ((V(I) < DIST1).AND.(I <= 10))
      ISTART = ISTART + 1
      I = I + 1
    END DO

    I = 0
    IEND = 0
    DO WHILE ((V(I) <= DIST2).AND.(I <= 10))
      IEND = IEND + 1
      I = I + 1
    END DO
    IEND = IEND - 1

# 2  
Old 11-30-2010
Add some print statements in the do while loop to show I, ISTART, and V(I)
Add a print statement after the end do as well.
You should also add a routine to make sure that V is in ascending order, and that DIST1 is not greater than DIST2
# 3  
Old 11-30-2010
I think I have fixed the problem now. Am trying to check id array is in ascending order.

---------- Post updated at 01:40 PM ---------- Previous update was at 01:24 PM ----------

Have tried this to check if array is in ascending order but there is a problem. The first time statement is false I want to exit and return false.

Code:
    DO I = 1, N-1
      IF (VDIST(I) < VDIST(I+1))
          L_ASCENDING = .TRUE.
      ELSE
          L_ASCENDING = .FALSE.
      ENDIF
    ENDDO

---------- Post updated at 01:53 PM ---------- Previous update was at 01:40 PM ----------

Done it now.
# 4  
Old 11-30-2010
Sort an array. Univac Fortran V. I don't think that the implicit statement is still supported though, and I don't have a compiler to confirm that there are no typos in the following code.

Code:
     *DIMENSION TABLE (14,500)
     *FILL TABLE WITH DATA AND SORT ON COLUMNS 2,1,3

     SUBROUTINE TXSORT
     IMPLICIT INTEGER (A-Y)
     X0=TABCTR         * TABCTR IS ONE MORE THAN NUMBER OF ENTRIES IN THE TABLE.
10   X0=X0/2
     IF (X0) 15,70,15
15   X1=TABCTR-X0
     X2=1
20   X3=X2
30   X4=X3+X0
     IF (TABLE(2,X3)-TABLE(2,X4)) 60,45,40
45   IF (TABLE(1,X3)-TABLE(1,X4)) 40,46,60
46   IF (TABLE(3,X3)-TABLE(3,X4)) 60,60,40
40   DO 50 I=1,14
     X5=TABLE(I,X3)
     TABLE(I,X3)=TABLE(I,X4)
     TABLE(I,X4)=X5
50   CONTINUE
     X3=X3-X0
     IF (X3-1) 60,30,30
60   X2=X1
     IF (X2-X1) 20,20,10
70   RETURN

# 5  
Old 11-30-2010
Have written a subroutine that gives an error if values are not in ascending order. In my case, I do not sort the array. This is because should the values not be in ascending order, then there must be a problem with the data.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Returning multiple values in Shell

Hi I have a code as the following #!/usr/bin/ksh set -x row() { a=$1 b=$2 c=$(($a + $b)) d=$(($a * $b)) echo $a $b } e=`row 2 3` set $e echo "The value of c is $c" echo "The value of d is $d" My requirement is I need to pass two arguments to a function and return two values... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

2. Shell Programming and Scripting

Output breaking when returning multiple values

I've been trying to write a command-line function to grab a website's MX records and their ip addresses. The code below works with domains that only have one MX record: function kmx { mx=`host -t MX $1 | awk '{ print $7 }'`; ip=`host $mx | sed '/IPv6/d;/handled/d' | awk '{ print $4 }'`; ... (8 Replies)
Discussion started by: Azrael
8 Replies

3. UNIX for Dummies Questions & Answers

For loop returning more values

Hi All, Thanks all of you for the help you provide to me. Well, I have one more problem, where I am trying to pull file system information in the loop and display the filesystem percentege. I am using following code to achive this, nut it's giving the weired output. My file system is ... (1 Reply)
Discussion started by: alok.behria
1 Replies

4. Shell Programming and Scripting

Finding index values

I have an array XOFFS of size N. I have VDISTMIN and VDISTMAX. I want to find the beginning and and index in XOFFS such that values are within Example Let XOFFS = (10 20 30 40 50) If VDISTMIN = -20 and VDISTMAX = 20 Then ISTR = 1 and IEND = 2 as XOFFS through XOFFS fall within the... (2 Replies)
Discussion started by: kristinu
2 Replies

5. Programming

FORTRAN: Getting Consecutive DIST Values

I have this code and I want to get the first two consecutive distances (obtained by calling GET_TH(IT, 'DIST', DIST) at index IT, the result stored in DIST) for which (ITFLG(IT) .NE. 1). L_FIRST get the first DIST for which ITFLG(IT) .NE. 1. Getting a bit confused on how to achieve this. ... (0 Replies)
Discussion started by: kristinu
0 Replies

6. Programming

returning multiple values from a function in C

hi how can I return multiple values from a C function. I tried the following: #include <stdio.h> void foo(int id, char *first_name, char *last_name) { /* this is just an example to illustrate my problem... real code makes use of the "id" parameter. */ first_name = (char... (8 Replies)
Discussion started by: Andrewkl
8 Replies

7. Programming

random array index returning values not contained

For kicks I wrote up a Password generator after lunch. Let me start with the code: unsigned int x,y,z,c; unsigned int KISS(); unsigned int devrand(); int main( int argc, char** argv ) { int i, j = 1; char pwd = "abcdefghijklmnopqrstuvwxyz" ... (5 Replies)
Discussion started by: VRoemer
5 Replies

8. Solaris

awk/nawk returning decimal values?

Hi Running a specific nawk statement over a 17m lines files returns the following: /bin/nawk: not enough args in ..... input record number 1,25955e+06, file test.1 source line number 1 I'd like to report the line number (in bold above) in decimal not floating so that i can spot it out. ... (1 Reply)
Discussion started by: moutaye
1 Replies

9. Shell Programming and Scripting

Returning values from child to parent shell

I need to send the status from child shell failure to parent shell. I would like to know how could we accomplish this. My parent.sh is as below: #!/bin/ksh set -x echo "I am in parent shell now..." child.sh ret_stat=$? echo "rest_stat=$ret_stat" echo "I am below parent shell end..." ... (4 Replies)
Discussion started by: acheepi
4 Replies

10. Shell Programming and Scripting

Returning Values (shell Script)

I have an application on Informix 4GL, and I am invoking the shell script from the program, but I need to know if the shell script work fine or not, in order to continue the process. I know that we can use $? to get the final status but this is on unix command. How can I return a value from the... (3 Replies)
Discussion started by: jennifer01
3 Replies
Login or Register to Ask a Question