Fortran77 data compiler problem

In summary,The code is trying to match lines that have the desired number ($num), the chemical name, and the amount of runs. If it finds a match, it prints the line to the output.
  • #1
Carl Loomis-Anderson
6
1
So I am doing a chemical simulation of titans atmosphere and I have potentially 1000 data files to sort through to retrieve concentration values written in Double format. The issue is that each chemical has its own line with well over 80 columns (1993 currently, though it is subject to increase). I was wondering how I could copy a line from each file and paste it into a single output file. This is the current unfinished code I have.

Fortran:
       CHARACTER(len=12) :: FN
c      this is the number of runs/files. The character string has
c      to edited for each chemical it tests
       N=5 !--arbitrary number of files, change for number runs
       CHARACTER*4 :: chem
       chem = C6H6
     
       INT chemnum
       chemnum = ****  !this is the number associated with the chemical

       OPEN(2,FILE=(chem+".DAT"), STATUS="NEW")
       DO I=1,N

       WRITE(FN,10)I
       WRITE(6,*)FN
       OPEN(1,FILE=FN)
     
       DO j=1,(chemnum-1) ! cycles to the appropriate line
       READ(1,*)
       END DO

       Read(1,*)
                 CLOSE(1)
            
       END DO
     
       CLOSE(2)    10 FORMAT('plot',I2.2,'.DAT')
 
Technology news on Phys.org
  • #2
Are these files ascii readable files?

If so then you should consider using a scripting language like awk, ruby or python to read, extract and collect the data into a summarized ascii file.

My guess would be that the grep command could handle this:

Bash:
grep "argon" *.DAT >summary.txt

If you needed something more complicated then switch to awk:

Code:
#!/bin/awk
# ----------------------------------------
#   name of script: mypgm.awk
# ----------------------------------------

/argon/ { if (some selection conditions) print $0 }

and you'd run it from the command line:
Bash:
$ chmod 777 mypgm.awk

$ ./mypgm.awk *.DAT >summary.txt

In both cases, they are looking for the line that contains "argon" and then printing it out. The >summary.txt instructs the bash shell to redirect standard output to the file summary.txt.

If you need to count down lines as your code is doing then awk has an internal variable that can be used
instead of the /argon/ matcher.
 
  • #3
Thanks for the advice! I'll look into switching.
 
  • #4
I recommend Perl instead of the Unix awk, grep, etc. It gave much more capability, was always available on Unix/Linux, and could be easily installed on Windows machines.
I also recommend Perl over Python for scripting tasks like yours.
 
  • #5
I tried out perl and have made much quicker progress than with fortran. I am having a hangup though. The program is copying every line I don't need and not the line that I do need.
Code:
#declare parameters
say "what is the chemical formula?";
my $chem = <STDIN> ;
chomp $chem;
say $chem;
say "what is the number of the chemical?";#this specifies the line needed
my $num = <STDIN>;
chomp $num;
say $num;
say "what is the amount of runs?";
my $nrun = <STDIN>;
chomp$nrun;

#this section will loop through the plot files
#    keeping the chosen data.
$a = 0;
open (my $out, ">>", "$chem.dat"); #opens output with name 'chem'.dat
until ($a >= $nrun) #loop for opening and collecting from data files
{
    say "plot$a.dat";
    open (my $fn, "<", "plot$a.dat")
        or die "can't open plot";
    $a = $a +1;
    while (my $line = <$fn>)
    {
        next if $line =~ $num;
        print $out "$line";
       
    }
    close $fn;
}
 
  • #6
I will assume that the files of data are ASCII files with a line number at the beginning of each line (it would help if you show us what the format of the lines are.)

Try this. It looks at the beginning of the line ('^' indicates that), followed by any number of spaces or tabs ('\s*' indicates that), then the desired number $num, then a space or tab ('\s' indicates that). If it finds that pattern on the line, it prints the line to $out.
Code:
if( $line =~ /^\s*$num\s/ ){
   print $out "$line";
}

PS. Man! You are fast at picking up on Perl!
 
  • #7
Thanks! I just tested it on my research and it had great results!
 
  • Like
Likes FactChecker

1. What is a Fortran77 data compiler?

A Fortran77 data compiler is a software tool used for translating source code written in the Fortran77 programming language into machine code that can be executed by a computer. It is commonly used for scientific and engineering applications.

2. What is the difference between a compiler and an interpreter?

A compiler translates the entire source code into machine code before execution, while an interpreter translates the code line by line during execution. In the context of Fortran77, a data compiler would produce a standalone executable program, while an interpreter would require an interpreter program to be present in order to execute the code.

3. How do I install a Fortran77 data compiler?

The installation process may vary depending on the specific compiler you are using. Generally, you can download the compiler from the manufacturer's website and follow the installation instructions provided. It is important to ensure that your computer meets the system requirements for the compiler.

4. What is a common error encountered when using a Fortran77 data compiler?

A common error is a mismatch between the input data and the format specified in the code. This can result in incorrect output or the compiler throwing an error. It is important to carefully check the code and ensure that all input data is in the correct format.

5. Can a Fortran77 data compiler be used for modern programming tasks?

While Fortran77 is an older programming language, it is still widely used in scientific and engineering applications. However, it may not be the best choice for modern programming tasks due to its limited features and lack of support for newer programming concepts. It is recommended to explore other programming languages that are better suited for modern tasks.

Similar threads

  • Programming and Computer Science
Replies
7
Views
1K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
11
Views
996
  • Programming and Computer Science
Replies
19
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
16
Views
3K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
18
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
Back
Top