Create a file on magnetic tape: Difference between revisions

Content added Content deleted
No edit summary
m (syntax highlighting fixup automation)
Line 21: Line 21:


=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>PROC Save(CHAR ARRAY text)
<syntaxhighlight lang="action!">PROC Save(CHAR ARRAY text)
BYTE dev=[1]
BYTE dev=[1]


Line 58: Line 58:
PrintE("Rewind the tape and press any key to load previously saved file from tape.")
PrintE("Rewind the tape and press any key to load previously saved file from tape.")
Load()
Load()
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Create_a_file_on_magnetic_tape.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Create_a_file_on_magnetic_tape.png Screenshot from Atari 8-bit computer]
Line 74: Line 74:


=={{header|Applesoft BASIC}}==
=={{header|Applesoft BASIC}}==
<lang ApplesoftBasic>SAVE</lang>
<syntaxhighlight lang="applesoftbasic">SAVE</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>write "TAPE.FILE" {
<syntaxhighlight lang="rebol">write "TAPE.FILE" {
This code
This code
should be able to write
should be able to write
a file
a file
to magnetic tape
to magnetic tape
}</lang>
}</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
The program is self explanatory. :)
The program is self explanatory. :)
<syntaxhighlight lang="c">
<lang C>
#include<stdio.h>
#include<stdio.h>


Line 108: Line 108:
}
}


</syntaxhighlight>
</lang>


=={{header|C++}}==
=={{header|C++}}==
{{trans|D}}
{{trans|D}}
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <fstream>
#include <fstream>


Line 128: Line 128:
fb.close();
fb.close();
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(spit "/dev/tape" "Hello, World!")</lang>
<syntaxhighlight lang="clojure">(spit "/dev/tape" "Hello, World!")</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
Line 137: Line 137:
{{works with|OpenCOBOL}}
{{works with|OpenCOBOL}}


<lang COBOL> >>SOURCE FORMAT IS FREE
<syntaxhighlight lang="cobol"> >>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
IDENTIFICATION DIVISION.
PROGRAM-ID. MAKE-TAPE-FILE.
PROGRAM-ID. MAKE-TAPE-FILE.
Line 158: Line 158:
FROM "COBOL treats tape files and text files identically."
FROM "COBOL treats tape files and text files identically."
END-WRITE
END-WRITE
STOP RUN.</lang>
STOP RUN.</syntaxhighlight>


=={{header|Crystal}}==
=={{header|Crystal}}==
{{trans|D}}
{{trans|D}}
<lang ruby>filename = {% if flag?(:win32) %}
<syntaxhighlight lang="ruby">filename = {% if flag?(:win32) %}
"TAPE.FILE"
"TAPE.FILE"
{% else %}
{% else %}
"/dev/tape"
"/dev/tape"
{% end %}
{% end %}
File.write filename, "howdy, planet!"</lang>
File.write filename, "howdy, planet!"</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
<lang D>import std.stdio;
<syntaxhighlight lang="d">import std.stdio;


void main() {
void main() {
Line 179: Line 179:
}
}
f.writeln("Hello World!");
f.writeln("Hello World!");
}</lang>
}</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==
{{Trans|D}}
{{Trans|D}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Create_a_file_on_magnetic_tape;
program Create_a_file_on_magnetic_tape;


Line 204: Line 204:
close(f);
close(f);
end.
end.
</syntaxhighlight>
</lang>


=={{header|F#}}==
=={{header|F#}}==
<lang fsharp>
<syntaxhighlight lang="fsharp">
open System
open System
open System.IO
open System.IO
Line 217: Line 217:
| PlatformID.Win32NT | PlatformID.Win32S | PlatformID.Win32Windows | PlatformID.WinCE -> File.WriteAllText("TAPE.FILE", msg)
| PlatformID.Win32NT | PlatformID.Win32S | PlatformID.Win32Windows | PlatformID.WinCE -> File.WriteAllText("TAPE.FILE", msg)
| _ -> File.WriteAllText("/dev/tape", msg)
| _ -> File.WriteAllText("/dev/tape", msg)
</syntaxhighlight>
</lang>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: io.encodings.ascii io.files kernel system ;
<syntaxhighlight lang="factor">USING: io.encodings.ascii io.files kernel system ;


"Hello from Rosetta Code!"
"Hello from Rosetta Code!"
os windows? "tape.file" "/dev/tape" ?
os windows? "tape.file" "/dev/tape" ?
ascii set-file-contents</lang>
ascii set-file-contents</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
Line 237: Line 237:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>Dim As Integer numarch = Freefile
<syntaxhighlight lang="freebasic">Dim As Integer numarch = Freefile
Open "tape.file" For Output As #numarch
Open "tape.file" For Output As #numarch
Print #numarch, "Soy un archivo de cinta ahora, o espero serlo pronto."
Print #numarch, "Soy un archivo de cinta ahora, o espero serlo pronto."
Close #numarch</lang>
Close #numarch</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
Line 249: Line 249:
The tar archive will contain a single file, called <tt>TAPE.FILE</tt> by default,
The tar archive will contain a single file, called <tt>TAPE.FILE</tt> by default,
with the contents of the command line <tt>-data</tt> option.
with the contents of the command line <tt>-data</tt> option.
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 301: Line 301:
log.Fatal("writing data:", err)
log.Fatal("writing data:", err)
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 309: Line 309:
=={{header|Groovy}}==
=={{header|Groovy}}==
{{trans|Java}}
{{trans|Java}}
<lang groovy>import java.nio.file.Files
<syntaxhighlight lang="groovy">import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.Paths
Line 324: Line 324:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==


<lang haskell>module Main (main) where
<syntaxhighlight lang="haskell">module Main (main) where


main :: IO ()
main :: IO ()
main = writeFile "/dev/tape" "Hello from Rosetta Code!"</lang>
main = writeFile "/dev/tape" "Hello from Rosetta Code!"</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==


This solution mimics the solution used in many other languages here and works in both Icon and Unicon.
This solution mimics the solution used in many other languages here and works in both Icon and Unicon.
<lang unicon>procedure main()
<syntaxhighlight lang="unicon">procedure main()
write(open("/dev/tape","w"),"Hi")
write(open("/dev/tape","w"),"Hi")
end</lang>
end</syntaxhighlight>


=={{header|IS-BASIC}}==
=={{header|IS-BASIC}}==
<lang IS-BASIC>100 OPEN #1:"Tape1:README.TXT" ACCESS OUTPUT
<syntaxhighlight lang="is-basic">100 OPEN #1:"Tape1:README.TXT" ACCESS OUTPUT
110 PRINT #1:"I am a tape file now, or hope to be soon."
110 PRINT #1:"I am a tape file now, or hope to be soon."
120 CLOSE #1</lang>
120 CLOSE #1</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<lang java>import java.io.IOException;
<syntaxhighlight lang="java">import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Path;
Line 363: Line 363:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|JCL}}==
=={{header|JCL}}==
<lang JCL>// EXEC PGM=IEBGENER
<syntaxhighlight lang="jcl">// EXEC PGM=IEBGENER
//* Create a file named "TAPE.FILE" on magnetic tape; "UNIT=TAPE"
//* Create a file named "TAPE.FILE" on magnetic tape; "UNIT=TAPE"
//* may vary depending on site-specific esoteric name assignment
//* may vary depending on site-specific esoteric name assignment
Line 374: Line 374:
//SYSUT1 DD *
//SYSUT1 DD *
DATA TO BE WRITTEN TO TAPE
DATA TO BE WRITTEN TO TAPE
/* </lang>
/* </syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>
<syntaxhighlight lang="julia">
open("/dev/tape", "w") do f
open("/dev/tape", "w") do f
write(f, "Hello tape!")
write(f, "Hello tape!")
end
end
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Scala}}
{{trans|Scala}}
<lang scala>// version 1.1.0 (Linux)
<syntaxhighlight lang="scala">// version 1.1.0 (Linux)


import java.io.FileWriter
import java.io.FileWriter
Line 393: Line 393:
lp0.write("Hello, world!")
lp0.write("Hello, world!")
lp0.close()
lp0.close()
}</lang>
}</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>require "lfs"
<syntaxhighlight lang="lua">require "lfs"


local out
local out
Line 406: Line 406:
file = io.open(out, 'w')
file = io.open(out, 'w')
file:write('Hello world')
file:write('Hello world')
io.close(file)</lang>
io.close(file)</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>var t = open("/dev/tape", fmWrite)
<syntaxhighlight lang="nim">var t = open("/dev/tape", fmWrite)
t.writeln "Hi Tape!"
t.writeln "Hi Tape!"
t.close</lang>
t.close</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
<lang Phix>include builtins/write_file.e
<syntaxhighlight lang="phix">include builtins/write_file.e
constant filepath = iff(platform()=WINDOWS?"tape.file":"/dev/tape"),
constant filepath = iff(platform()=WINDOWS?"tape.file":"/dev/tape"),
write_file(file_path,"Hello world!")</lang>
write_file(file_path,"Hello world!")</syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(out "/dev/tape"
<syntaxhighlight lang="picolisp">(out "/dev/tape"
(prin "Hello World!") )</lang>
(prin "Hello World!") )</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
<lang python>>>> with open('/dev/tape', 'w') as t: t.write('Hi Tape!\n')
<syntaxhighlight lang="python">>>> with open('/dev/tape', 'w') as t: t.write('Hi Tape!\n')
...
...
>>> </lang>
>>> </syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
#lang racket
(with-output-to-file "/dev/tape" #:exists 'append
(with-output-to-file "/dev/tape" #:exists 'append
(λ() (displayln "I am a cheap imitation of the Perl code for a boring problem")))
(λ() (displayln "I am a cheap imitation of the Perl code for a boring problem")))
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>my $tape = open "/dev/tape", :w or die "Can't open tape: $!";
<syntaxhighlight lang="raku" line>my $tape = open "/dev/tape", :w or die "Can't open tape: $!";
$tape.say: "I am a tape file now, or hope to be soon.";
$tape.say: "I am a tape file now, or hope to be soon.";
$tape.close;</lang>
$tape.close;</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 446: Line 446:
<br><br>VM/CMS would use a &nbsp; '''CP ATTACH''' &nbsp; command, coupled with a &nbsp; '''CMS FILEDEF''' &nbsp; command which associates a
<br><br>VM/CMS would use a &nbsp; '''CP ATTACH''' &nbsp; command, coupled with a &nbsp; '''CMS FILEDEF''' &nbsp; command which associates a
<br>DSNAME &nbsp; (dataset name) &nbsp; that will be written to on the attached (and mounted) magnetic tape device.
<br>DSNAME &nbsp; (dataset name) &nbsp; that will be written to on the attached (and mounted) magnetic tape device.
<lang rexx>/*REXX pgm demonstrates writing records to an attached magnetic tape.*/
<syntaxhighlight lang="rexx">/*REXX pgm demonstrates writing records to an attached magnetic tape.*/
dsName = 'TAPE.FILE' /*dsName of "file" being written.*/
dsName = 'TAPE.FILE' /*dsName of "file" being written.*/


Line 452: Line 452:
call lineout dsName, 'this is record' j || "."
call lineout dsName, 'this is record' j || "."
end /*j*/
end /*j*/
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</syntaxhighlight>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
# Project : Create a file on magnetic tape
# Project : Create a file on magnetic tape


Line 463: Line 463:
fwrite(fp, str)
fwrite(fp, str)
fclose(fp)
fclose(fp)
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
{{trans|C}}
{{trans|C}}
<lang ruby>File.open("tape.file", "w") do |fh|
<syntaxhighlight lang="ruby">File.open("tape.file", "w") do |fh|
fh.syswrite("This code should be able to write a file to magnetic tape.\n")
fh.syswrite("This code should be able to write a file to magnetic tape.\n")
end</lang>
end</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
<lang Rust>use std::io::Write;
<syntaxhighlight lang="rust">use std::io::Write;
use std::fs::File;
use std::fs::File;


fn main() -> std::io::Result<()> {
fn main() -> std::io::Result<()> {
File::open("/dev/tape")?.write_all(b"Hello from Rosetta Code!")
File::open("/dev/tape")?.write_all(b"Hello from Rosetta Code!")
}</lang>
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
===[[Unix]]===
===[[Unix]]===
Assuming device is attached to "tape"
Assuming device is attached to "tape"
<lang Scala>object LinePrinter extends App {
<syntaxhighlight lang="scala">object LinePrinter extends App {
import java.io.{ FileWriter, IOException }
import java.io.{ FileWriter, IOException }
{
{
Line 489: Line 489:
lp0.close()
lp0.close()
}
}
}</lang>
}</syntaxhighlight>


=={{header|Seed7}}==
=={{header|Seed7}}==


<lang Seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const proc: main is func
const proc: main is func
Line 509: Line 509:
writeln(" ***** Cannot open tape file.");
writeln(" ***** Cannot open tape file.");
end if;
end if;
end func;</lang>
end func;</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
Tcl does not have built-in special support for tape devices, so it relies on the OS to handle most of the details for it. Assuming a relatively modern Unix:
Tcl does not have built-in special support for tape devices, so it relies on the OS to handle most of the details for it. Assuming a relatively modern Unix:
{{trans|UNIX Shell}}
{{trans|UNIX Shell}}
<lang tcl>cd /tmp
<syntaxhighlight lang="tcl">cd /tmp


# Create the file
# Create the file
Line 526: Line 526:
fcopy $fin $fout
fcopy $fin $fout
close $fin
close $fin
close $fout</lang>
close $fout</syntaxhighlight>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>$$ MODE TUSCRIPT
<syntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
STATUS = CREATE ("tape.file",tape-o,-std-)
STATUS = CREATE ("tape.file",tape-o,-std-)
PRINT STATUS</lang>
PRINT STATUS</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 538: Line 538:


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
<lang bash>#!/bin/sh
<syntaxhighlight lang="bash">#!/bin/sh
cd # Make our home directory current
cd # Make our home directory current
echo "Hello World!" > hello.jnk # Create a junk file
echo "Hello World!" > hello.jnk # Create a junk file
# tape rewind # Uncomment this to rewind the tape
# tape rewind # Uncomment this to rewind the tape
tar c hello.jnk # Traditional archivers use magnetic tape by default
tar c hello.jnk # Traditional archivers use magnetic tape by default
# tar c hello.jnk > /dev/tape # With newer archivers redirection is needed</lang>
# tar c hello.jnk > /dev/tape # With newer archivers redirection is needed</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
<lang ecmascript>import "os" for Platform
<syntaxhighlight lang="ecmascript">import "os" for Platform
import "io" for File
import "io" for File


Line 552: Line 552:
File.create(fileName) { |file|
File.create(fileName) { |file|
file.writeBytes("Hello World!\n")
file.writeBytes("Hello World!\n")
}</lang>
}</syntaxhighlight>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
Line 559: Line 559:
We can use any start address, depending on where we want the data to come from.
We can use any start address, depending on where we want the data to come from.
Here we dump the contents of the screen:
Here we dump the contents of the screen:
<lang zxbasic>SAVE "TAPEFILE" CODE 16384,6912</lang>
<syntaxhighlight lang="zxbasic">SAVE "TAPEFILE" CODE 16384,6912</syntaxhighlight>