Fortran locate symbol in data file

In summary, the conversation involves the need to remove the string '////' from a data file. The speaker has tried using an if statement to avoid the string, but encountered an error due to the use of an array in the subexpression. They are seeking help on how to achieve their goal. Suggestions have been made to use a VI editor or Wordpad for searching and replacing the string.
  • #1
agalya
9
0
I need to look for the presence of '////' in my data file
i could read it as character
since i need to eliminate them from the file,
I've tried to avoid them using
if(xx .eq. '////') then
but is not working the error comes as
if(mt.ne. '////')then
Equality operator at (1) must operate on two scalar (not array) subexpressions, two function invocations returning arithmetic or character scalars, or a combination of both --
but the subexpression at (2)(it '////') is an array

how to achieve what I am thinking?
Can somebody help me in this regard
thanks in advance
 
Last edited:
Technology news on Phys.org
  • #2
Have you tried just using the VI editor...or even Wordpad (Search and Replace)?
 
  • #3


There are a few things to consider when trying to locate a symbol in a data file using Fortran. First, it is important to make sure that the data file is being read in correctly as a character variable. This can be done by using the "character" keyword in the read statement or by using the "char" intrinsic function to convert the data to characters.

Once the data is being read in as characters, then the "if" statement can be used to check for the presence of the symbol. However, the error message suggests that the "if" statement is being used on an array instead of a scalar value. This could be due to the use of the "mt.ne." operator, which is meant for comparing arrays, not individual characters.

To achieve the desired result, the "if" statement should be rewritten to compare individual characters using the "==" operator. Additionally, the "mt" variable should be declared as a character array instead of a scalar value. This will allow the program to iterate through each character in the data file and check for the presence of the symbol '////'. Once the symbol is located, it can be eliminated from the file using the appropriate command.

If further assistance is needed, it may be helpful to consult the Fortran documentation or seek assistance from a Fortran expert.
 

1. How do I locate a specific symbol in a Fortran data file?

To locate a specific symbol in a Fortran data file, you can use the "LOCATE" function. This function takes in the symbol you are looking for as well as the file name and returns the position of the symbol within the file.

2. Can I use wildcards when searching for a symbol in a Fortran data file?

Yes, you can use wildcards such as asterisks (*) and question marks (?) when searching for a symbol in a Fortran data file. These can be used to represent any character or a single character, respectively.

3. What if the symbol I am looking for is not found in the data file?

If the symbol you are looking for is not found in the data file, the "LOCATE" function will return a value of zero. This indicates that the symbol is not present in the file.

4. Can I search for symbols in multiple data files at once?

Yes, you can use the "LOCATE" function to search for symbols in multiple data files. Simply specify the file names separated by commas in the function and the function will return the position of the symbol in the first file where it is found.

5. Is there a limit to the length of the symbol I can search for in a Fortran data file?

Yes, there is a limit to the length of the symbol that can be searched for in a Fortran data file. This limit is dependent on the specific version of Fortran being used, but it is typically around 256 characters.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
20
Views
8K
  • Programming and Computer Science
Replies
12
Views
14K
Back
Top