Create a file on magnetic tape: Difference between revisions

From Rosetta Code
Content added Content deleted
m (promoted to task)
(→‎Tcl: Added implementation)
Line 12: Line 12:
DATA TO BE WRITTEN TO TAPE
DATA TO BE WRITTEN TO TAPE
/* </lang>
/* </lang>

=={{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:
{{trans|UNIX Shell}}
<lang tcl>cd /tmp

# Create the file
set f [open hello.jnk w]
puts $f "Hello World!"
close $f

# Archive to tape
set fin [open "|tar cf - hello.jnk" rb]
set fout [open /dev/tape wb]
fcopy $fin $fout
close $fin
close $fout</lang>


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


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
<lang bash>#!/bin/sh

<lang sh>#!/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 # Traditonal archivers use magnetic tape by default
tar c hello.jnk # Traditonal archivers use magnetic tape by default
# tar c hello.jnk > /dev/tape # With newer archivers redirection is needed
# tar c hello.jnk > /dev/tape # With newer archivers redirection is needed</lang>
</lang>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==

The ZX Spectrum does not have file type extensions, so we save as TAPEFILE, rather than TAPE.FILE. We can use any start address, depending on where we want the data to come from. Here we dump the contents of the screen:
The ZX Spectrum does not have file type extensions, so we save as TAPEFILE, rather than TAPE.FILE. We can use any start address, depending on where we want the data to come from. Here we dump the contents of the screen:

<lang zxbasic>SAVE "TAPEFILE" CODE 16384,6912</lang>
<lang zxbasic>SAVE "TAPEFILE" CODE 16384,6912</lang>

Revision as of 20:22, 25 February 2013

Task
Create a file on magnetic tape
You are encouraged to solve this task according to the task description, using any language you may know.

The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape

JCL

<lang JCL>// EXEC PGM=IEBGENER //* Create a file named "TAPE.FILE" on magnetic tape; "UNIT=TAPE" //* may vary depending on site-specific esoteric name assignment //SYSPRINT DD SYSOUT=* //SYSIN DD DUMMY //SYSUT2 DD UNIT=TAPE,DSN=TAPE.FILE,DISP=(,CATLG) //SYSUT1 DD * DATA TO BE WRITTEN TO TAPE /* </lang>

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:

Translation of: UNIX Shell

<lang tcl>cd /tmp

  1. Create the file

set f [open hello.jnk w] puts $f "Hello World!" close $f

  1. Archive to tape

set fin [open "|tar cf - hello.jnk" rb] set fout [open /dev/tape wb] fcopy $fin $fout close $fin close $fout</lang>

TUSCRIPT

<lang tuscript>$$ MODE TUSCRIPT STATUS = CREATE ("tape.file",tape-o,-std-) PRINT STATUS</lang> Output:

OK

UNIX Shell

<lang bash>#!/bin/sh cd # Make our home directory current echo "Hello World!" > hello.jnk # Create a junk file

  1. tape rewind # Uncomment this to rewind the tape

tar c hello.jnk # Traditonal archivers use magnetic tape by default

  1. tar c hello.jnk > /dev/tape # With newer archivers redirection is needed</lang>

ZX Spectrum Basic

The ZX Spectrum does not have file type extensions, so we save as TAPEFILE, rather than TAPE.FILE. We can use any start address, depending on where we want the data to come from. Here we dump the contents of the screen: <lang zxbasic>SAVE "TAPEFILE" CODE 16384,6912</lang>