WeixiangYan/CodeTransOcean huggingface dataset:
Task: Kernighans large earthquake problem

C: #include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    FILE *fp;
    char *line = NULL;
    size_t len = 0;
    ssize_t read;
    char *lw, *lt;
    fp = fopen("data.txt", "r");
    if (fp == NULL) {
        printf("Unable to open file\n");
        exit(1);
    }
    printf("Those earthquakes with a magnitude > 6.0 are:\n\n");
    while ((read = getline(&line, &len, fp)) != EOF) {
        if (read < 2) continue;   
        lw = strrchr(line, ' ');  
        lt = strrchr(line, '\t'); 
        if (!lw && !lt) continue; 
        if (lt > lw) lw = lt;     
        if (atof(lw + 1) > 6.0) printf("%s", line);
    }
    fclose(fp);
    if (line) free(line);
    return 0;
}









COBOL:       
      
      
      
      
      
       >>SOURCE FORMAT IS FREE
       identification division.
       program-id. quakes.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select quake-data
           assign to command-filename
           organization is line sequential
           status is quake-fd-status
           .

       data division.
       file section.
       fd quake-data record varying depending on line-length.
           01 data-line       pic x(32768).

       working-storage section.
       01 quake-fd-status pic xx.
          88 ok values "00", "01", "02", "03", "04",
                       "05", "06", "07", "08", "09".
          88 no-more value "10".
          88 io-error value high-value.

       01 line-length usage binary-long.

       01 date-time pic x(10).
       01 quake pic x(20).
       01 magnitude pic 99v99.

       01 command-filename pic x(80).
        
       procedure division.
       show-big-ones.

       accept command-filename from command-line
       if command-filename equal spaces then
           move "data.txt" to command-filename
       end-if

       open input quake-data
       perform status-check
       if io-error then
           display trim(command-filename) " not found" upon syserr
           goback
       end-if

       read quake-data
       perform status-check
       perform until no-more or io-error
           unstring data-line delimited by all spaces
              into date-time quake magnitude
           end-unstring

           if magnitude greater than 6
               display date-time space quake space magnitude
           end-if

           read quake-data
           perform status-check
       end-perform

       close quake-data
       perform status-check
       goback.
      

       status-check.
       if not ok and not no-more then   
           display "io error: " quake-fd-status upon syserr
           set io-error to true
       end-if
       .

       end program quakes.
Task: Kernighans large earthquake problem



C#: using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    static void Main() {
        foreach (var earthquake in LargeEarthquakes("data.txt", 6))
            Console.WriteLine(string.Join(" ", earthquake));
    }

    static IEnumerable<string[]> LargeEarthquakes(string filename, double limit) =>
        from line in File.ReadLines(filename)
        let parts = line.Split(default(char[]), StringSplitOptions.RemoveEmptyEntries)
        where double.Parse(parts[2]) > limit
        select parts;

}







COBOL:       
      
      
      
      
      
       >>SOURCE FORMAT IS FREE
       identification division.
       program-id. quakes.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select quake-data
           assign to command-filename
           organization is line sequential
           status is quake-fd-status
           .

       data division.
       file section.
       fd quake-data record varying depending on line-length.
           01 data-line       pic x(32768).

       working-storage section.
       01 quake-fd-status pic xx.
          88 ok values "00", "01", "02", "03", "04",
                       "05", "06", "07", "08", "09".
          88 no-more value "10".
          88 io-error value high-value.

       01 line-length usage binary-long.

       01 date-time pic x(10).
       01 quake pic x(20).
       01 magnitude pic 99v99.

       01 command-filename pic x(80).
        
       procedure division.
       show-big-ones.

       accept command-filename from command-line
       if command-filename equal spaces then
           move "data.txt" to command-filename
       end-if

       open input quake-data
       perform status-check
       if io-error then
           display trim(command-filename) " not found" upon syserr
           goback
       end-if

       read quake-data
       perform status-check
       perform until no-more or io-error
           unstring data-line delimited by all spaces
              into date-time quake magnitude
           end-unstring

           if magnitude greater than 6
               display date-time space quake space magnitude
           end-if

           read quake-data
           perform status-check
       end-perform

       close quake-data
       perform status-check
       goback.
      

       status-check.
       if not ok and not no-more then   
           display "io error: " quake-fd-status upon syserr
           set io-error to true
       end-if
       .

       end program quakes.
Task: Kernighans large earthquake problem


C++: 
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    ifstream file("../include/earthquake.txt");

    int count_quake = 0;
    int column = 1;
    string value;
    double size_quake;
    string row = "";


    while(file >> value)
    {
        if(column == 3)
        {
            size_quake = stod(value);

            if(size_quake>6.0)
            {
                count_quake++;
                row += value + "\t";
                cout << row << endl;
            }

            column = 1;
            row = "";
        }
        else
        {
            column++;
            row+=value + "\t";
        }
    }

    cout << "\nNumber of quakes greater than 6 is " << count_quake << endl;

    return 0;
}








COBOL:       
      
      
      
      
      
       >>SOURCE FORMAT IS FREE
       identification division.
       program-id. quakes.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select quake-data
           assign to command-filename
           organization is line sequential
           status is quake-fd-status
           .

       data division.
       file section.
       fd quake-data record varying depending on line-length.
           01 data-line       pic x(32768).

       working-storage section.
       01 quake-fd-status pic xx.
          88 ok values "00", "01", "02", "03", "04",
                       "05", "06", "07", "08", "09".
          88 no-more value "10".
          88 io-error value high-value.

       01 line-length usage binary-long.

       01 date-time pic x(10).
       01 quake pic x(20).
       01 magnitude pic 99v99.

       01 command-filename pic x(80).
        
       procedure division.
       show-big-ones.

       accept command-filename from command-line
       if command-filename equal spaces then
           move "data.txt" to command-filename
       end-if

       open input quake-data
       perform status-check
       if io-error then
           display trim(command-filename) " not found" upon syserr
           goback
       end-if

       read quake-data
       perform status-check
       perform until no-more or io-error
           unstring data-line delimited by all spaces
              into date-time quake magnitude
           end-unstring

           if magnitude greater than 6
               display date-time space quake space magnitude
           end-if

           read quake-data
           perform status-check
       end-perform

       close quake-data
       perform status-check
       goback.
      

       status-check.
       if not ok and not no-more then   
           display "io error: " quake-fd-status upon syserr
           set io-error to true
       end-if
       .

       end program quakes.
Task: Kernighans large earthquake problem





Java: import java.io.BufferedReader;
import java.io.FileReader;

public class KernighansLargeEarthquakeProblem {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader  = new BufferedReader(new FileReader("data.txt")); ) {
            String inLine = null;
            while ( (inLine = reader.readLine()) != null ) {
                String[] split = inLine.split("\\s+");
                double magnitude = Double.parseDouble(split[2]);
                if ( magnitude > 6 ) {
                    System.out.println(inLine);
                }
            }
        }

    }

}





COBOL:       
      
      
      
      
      
       >>SOURCE FORMAT IS FREE
       identification division.
       program-id. quakes.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select quake-data
           assign to command-filename
           organization is line sequential
           status is quake-fd-status
           .

       data division.
       file section.
       fd quake-data record varying depending on line-length.
           01 data-line       pic x(32768).

       working-storage section.
       01 quake-fd-status pic xx.
          88 ok values "00", "01", "02", "03", "04",
                       "05", "06", "07", "08", "09".
          88 no-more value "10".
          88 io-error value high-value.

       01 line-length usage binary-long.

       01 date-time pic x(10).
       01 quake pic x(20).
       01 magnitude pic 99v99.

       01 command-filename pic x(80).
        
       procedure division.
       show-big-ones.

       accept command-filename from command-line
       if command-filename equal spaces then
           move "data.txt" to command-filename
       end-if

       open input quake-data
       perform status-check
       if io-error then
           display trim(command-filename) " not found" upon syserr
           goback
       end-if

       read quake-data
       perform status-check
       perform until no-more or io-error
           unstring data-line delimited by all spaces
              into date-time quake magnitude
           end-unstring

           if magnitude greater than 6
               display date-time space quake space magnitude
           end-if

           read quake-data
           perform status-check
       end-perform

       close quake-data
       perform status-check
       goback.
      

       status-check.
       if not ok and not no-more then   
           display "io error: " quake-fd-status upon syserr
           set io-error to true
       end-if
       .

       end program quakes.
Task: Kernighans large earthquake problem







Python: python -c '
with open("data.txt") as f:
    for ln in f:
        if float(ln.strip().split()[2]) > 6:
            print(ln.strip())'



COBOL:       
      
      
      
      
      
       >>SOURCE FORMAT IS FREE
       identification division.
       program-id. quakes.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select quake-data
           assign to command-filename
           organization is line sequential
           status is quake-fd-status
           .

       data division.
       file section.
       fd quake-data record varying depending on line-length.
           01 data-line       pic x(32768).

       working-storage section.
       01 quake-fd-status pic xx.
          88 ok values "00", "01", "02", "03", "04",
                       "05", "06", "07", "08", "09".
          88 no-more value "10".
          88 io-error value high-value.

       01 line-length usage binary-long.

       01 date-time pic x(10).
       01 quake pic x(20).
       01 magnitude pic 99v99.

       01 command-filename pic x(80).
        
       procedure division.
       show-big-ones.

       accept command-filename from command-line
       if command-filename equal spaces then
           move "data.txt" to command-filename
       end-if

       open input quake-data
       perform status-check
       if io-error then
           display trim(command-filename) " not found" upon syserr
           goback
       end-if

       read quake-data
       perform status-check
       perform until no-more or io-error
           unstring data-line delimited by all spaces
              into date-time quake magnitude
           end-unstring

           if magnitude greater than 6
               display date-time space quake space magnitude
           end-if

           read quake-data
           perform status-check
       end-perform

       close quake-data
       perform status-check
       goback.
      

       status-check.
       if not ok and not no-more then   
           display "io error: " quake-fd-status upon syserr
           set io-error to true
       end-if
       .

       end program quakes.
Task: Kernighans large earthquake problem








VB: Imports System.IO

Module Module1

    Function LargeEarthquakes(filename As String, limit As Double) As IEnumerable(Of String())
        Return From line In File.ReadLines(filename)
               Let parts = line.Split(CType(Nothing, Char()), StringSplitOptions.RemoveEmptyEntries)
               Where Double.Parse(parts(2)) > limit
               Select parts
    End Function

    Sub Main()
        For Each earthquake In LargeEarthquakes("data.txt", 6)
            Console.WriteLine(String.Join(" ", earthquake))
        Next
    End Sub

End Module


COBOL:       
      
      
      
      
      
       >>SOURCE FORMAT IS FREE
       identification division.
       program-id. quakes.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select quake-data
           assign to command-filename
           organization is line sequential
           status is quake-fd-status
           .

       data division.
       file section.
       fd quake-data record varying depending on line-length.
           01 data-line       pic x(32768).

       working-storage section.
       01 quake-fd-status pic xx.
          88 ok values "00", "01", "02", "03", "04",
                       "05", "06", "07", "08", "09".
          88 no-more value "10".
          88 io-error value high-value.

       01 line-length usage binary-long.

       01 date-time pic x(10).
       01 quake pic x(20).
       01 magnitude pic 99v99.

       01 command-filename pic x(80).
        
       procedure division.
       show-big-ones.

       accept command-filename from command-line
       if command-filename equal spaces then
           move "data.txt" to command-filename
       end-if

       open input quake-data
       perform status-check
       if io-error then
           display trim(command-filename) " not found" upon syserr
           goback
       end-if

       read quake-data
       perform status-check
       perform until no-more or io-error
           unstring data-line delimited by all spaces
              into date-time quake magnitude
           end-unstring

           if magnitude greater than 6
               display date-time space quake space magnitude
           end-if

           read quake-data
           perform status-check
       end-perform

       close quake-data
       perform status-check
       goback.
      

       status-check.
       if not ok and not no-more then   
           display "io error: " quake-fd-status upon syserr
           set io-error to true
       end-if
       .

       end program quakes.
Task: Kernighans large earthquake problem




Go: package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)

func main() {
    f, err := os.Open("data.txt")
    if err != nil {
        fmt.Println("Unable to open the file")
        return
    }
    defer f.Close()
    fmt.Println("Those earthquakes with a magnitude > 6.0 are:\n")
    input := bufio.NewScanner(f)
    for input.Scan() {
        line := input.Text()
        fields := strings.Fields(line)
        mag, err := strconv.ParseFloat(fields[2], 64)
        if err != nil {
            fmt.Println("Unable to parse magnitude of an earthquake")
            return
        }
        if mag > 6.0 {
            fmt.Println(line)
        }
    }
}






COBOL:       
      
      
      
      
      
       >>SOURCE FORMAT IS FREE
       identification division.
       program-id. quakes.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select quake-data
           assign to command-filename
           organization is line sequential
           status is quake-fd-status
           .

       data division.
       file section.
       fd quake-data record varying depending on line-length.
           01 data-line       pic x(32768).

       working-storage section.
       01 quake-fd-status pic xx.
          88 ok values "00", "01", "02", "03", "04",
                       "05", "06", "07", "08", "09".
          88 no-more value "10".
          88 io-error value high-value.

       01 line-length usage binary-long.

       01 date-time pic x(10).
       01 quake pic x(20).
       01 magnitude pic 99v99.

       01 command-filename pic x(80).
        
       procedure division.
       show-big-ones.

       accept command-filename from command-line
       if command-filename equal spaces then
           move "data.txt" to command-filename
       end-if

       open input quake-data
       perform status-check
       if io-error then
           display trim(command-filename) " not found" upon syserr
           goback
       end-if

       read quake-data
       perform status-check
       perform until no-more or io-error
           unstring data-line delimited by all spaces
              into date-time quake magnitude
           end-unstring

           if magnitude greater than 6
               display date-time space quake space magnitude
           end-if

           read quake-data
           perform status-check
       end-perform

       close quake-data
       perform status-check
       goback.
      

       status-check.
       if not ok and not no-more then   
           display "io error: " quake-fd-status upon syserr
           set io-error to true
       end-if
       .

       end program quakes.
Task: Kernighans large earthquake problem






PHP: <?php

if ( ! isset( $argv[1] ) )
    die( 'Data file name required' );

if ( ! $fh = fopen( $argv[1], 'r' ) )
    die ( 'Cannot open file: ' . $argv[1] );

while ( list( $date, $loc, $mag ) = fscanf( $fh, "%s %s %f" ) ) {
    if ( $mag > 6 ) {
        printf( "% -12s % -19s %.1f\n", $date, $loc, $mag );
    }
}

fclose( $fh );
Task: Kernighans large earthquake problem






PHP: <?php

if ( ! isset( $argv[1] ) )
    die( 'Data file name required' );

if ( ! $fh = fopen( $argv[1], 'r' ) )
    die ( 'Cannot open file: ' . $argv[1] );

while ( list( $date, $loc, $mag ) = fscanf( $fh, "%s %s %f" ) ) {
    if ( $mag > 6 ) {
        printf( "% -12s % -19s %.1f\n", $date, $loc, $mag );
    }
}

fclose( $fh );






Ada: 
with Ada.Text_IO;       use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
use Ada.Strings;

procedure Main is
   Inpt_File : File_Type;
   Space     : Natural;
begin
   Open (File => Inpt_File, Mode => In_File, Name => "data.txt");
   while not End_Of_File (Inpt_File) loop
      declare
         Line : String :=
           Trim (Source => Get_Line (File => Inpt_File), Side => Both);
      begin

         if Line'Length > 0 then
            Space := Line'Last;
            loop
               exit when Line (Space) = ' ' or else Space = 0;
               Space := Space - 1;
            end loop;

            if Space > 0 then
               if Float'Value (Line (Space .. Line'Last)) > 6.0 then
                  Put_Line (Line);
               end if;
            end if;
         end if;
      end;
   end loop;
   Close (Inpt_File);
end Main;
Task: Kernighans large earthquake problem






PHP: <?php

if ( ! isset( $argv[1] ) )
    die( 'Data file name required' );

if ( ! $fh = fopen( $argv[1], 'r' ) )
    die ( 'Cannot open file: ' . $argv[1] );

while ( list( $date, $loc, $mag ) = fscanf( $fh, "%s %s %f" ) ) {
    if ( $mag > 6 ) {
        printf( "% -12s % -19s %.1f\n", $date, $loc, $mag );
    }
}

fclose( $fh );




COBOL:       
      
      
      
      
      
       >>SOURCE FORMAT IS FREE
       identification division.
       program-id. quakes.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select quake-data
           assign to command-filename
           organization is line sequential
           status is quake-fd-status
           .

       data division.
       file section.
       fd quake-data record varying depending on line-length.
           01 data-line       pic x(32768).

       working-storage section.
       01 quake-fd-status pic xx.
          88 ok values "00", "01", "02", "03", "04",
                       "05", "06", "07", "08", "09".
          88 no-more value "10".
          88 io-error value high-value.

       01 line-length usage binary-long.

       01 date-time pic x(10).
       01 quake pic x(20).
       01 magnitude pic 99v99.

       01 command-filename pic x(80).
        
       procedure division.
       show-big-ones.

       accept command-filename from command-line
       if command-filename equal spaces then
           move "data.txt" to command-filename
       end-if

       open input quake-data
       perform status-check
       if io-error then
           display trim(command-filename) " not found" upon syserr
           goback
       end-if

       read quake-data
       perform status-check
       perform until no-more or io-error
           unstring data-line delimited by all spaces
              into date-time quake magnitude
           end-unstring

           if magnitude greater than 6
               display date-time space quake space magnitude
           end-if

           read quake-data
           perform status-check
       end-perform

       close quake-data
       perform status-check
       goback.
      

       status-check.
       if not ok and not no-more then   
           display "io error: " quake-fd-status upon syserr
           set io-error to true
       end-if
       .

       end program quakes.