Fortran help: deleting items from a list

  • Context: Fortran 
  • Thread starter Thread starter brad sue
  • Start date Start date
  • Tags Tags
    Fortran List
Click For Summary
SUMMARY

The discussion focuses on implementing a deletion function in Fortran 77 for removing an integer ID from a list. The function, named delete, should return 0 for successful deletion, -1 if the list is empty, and -2 if the ID is not found. Key issues addressed include checking if the list is empty by evaluating n.eq.0 and determining if the ID exists by initializing indexe to 0 and checking its value post-loop. The provided code snippet requires adjustments to handle these conditions effectively.

PREREQUISITES
  • Understanding of Fortran 77 syntax and structure
  • Knowledge of integer arrays and their manipulation in Fortran
  • Familiarity with control flow statements, including loops and conditionals
  • Basic debugging skills to identify logical errors in code
NEXT STEPS
  • Review Fortran 77 array manipulation techniques
  • Study control flow in Fortran, focusing on if statements and loops
  • Learn about debugging strategies for Fortran programs
  • Explore best practices for writing functions in Fortran
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those working with legacy code in Fortran 77, and anyone looking to enhance their skills in array manipulation and function implementation.

brad sue
Messages
270
Reaction score
0
Hi , I need help to write a code for this function(fortran 77):

integer function delete(id, list, n) where
• delete returns 0 if the deletion was successful, -1 if the list is empty, and -2 if the user is not currently in the list.
•id is the integer identification number of the user.
•list is the integer array from which the id is to be removed.
•n is the current length of the list.

I tried this:
Code:
    integer function delete(id,list,n)
     integer i,indexe,j
     do 20 i=1,n
     if(list(i).EQ.id) then
          indexe=i

20    continue
         do 30 j= indexe,n
          list(i) = list(i+1)
30        continue
      n = n-1
     return 0
I have not finfished because I am stuck . I don't know where to introduce the else statement that would indicat the id is not in the list.
My second problem is that How to check if that array is empty?

please can someone help me?
Thank you for the time.
 
Technology news on Phys.org
The first thing to do is to check if the list is empty, i.e., n.eq.0.

To check if id is not in the list, set indexe to 0 before the first loop and check if it is still 0 after the loop.
 

Similar threads

Replies
9
Views
3K
  • · Replies 34 ·
2
Replies
34
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K