chdir <directory>Change the current working directory to <directory>
Example:
chdir "/home/nmr/data"
<directory> = getcwdGet the name of the current working directory.
Example:
%name = getcwd
println %name
Open a general purpose file. <file> is the file handle, <name> is the filename and <mode> is the C-style open mode. If the file can not be opened, the file handle is set to 0.
Example 1:
$newfile = open "myfile", "w"Opens the new file "myfile" for writing, and
$newfile = open "myfile", "r"opens the same file for reading.
Example 2:
$newfile = open "myfile", "r" @r = read $newfile close $newfileRead data from newfile into real array.
Example 3:
%filename = "mydir/myfile" $newfile = open %filename, "r" if $newfile == 0 then println "Error opening file " + %filename exit endifTest if file is opened.
Closes the file, thas was opened with the previous open command. <file> is the file handle of this file.
Example:
close $newfile
Returns the file size in bytes. Returns -1 if file does not exist.
Example:
$filesize = stat "myfile" println %filesize
Get the current access position in the file.
Set the access position in the file. <file> is the file handle and <position> is the new file position.
Example:
seek $newfile, 0positions the read/write position at the beginning of the file.
Read data from <file> into <array> or into <variable>. The number of data read when <array> is used, is determined by the size of the array.
Example 1:
@A[11..20] = read $filehandleReads 10 data elements into buffer A, stored at positions 11..20.
Example 2:
@B = read $filehandleReads data into buffer B. The number of data is equal to the size of buffer B, which is can be accessed by the commands @#B or ?SI.
Example 3:
$newnumber = read $filehandleRead one element from <file> into newnumber.
Read a line of text from a file, up to and including the '\n' character.
Similar to the C function with the same name. Returns an empty string
on error or end of file.
Example:
Write data from <array> to <file> or write <number> to the file. The number of data written when <array> is used, is equal to the size of the array.
Example:
write $filehandle, @cWrite all real and imaginary data to the file. The real data is stored before the imaginary data, and the number of data written is the size of @C * 2.
Read one item (=text) from the text file <file> into the variable <value>. The <identifier string> is a text format string with one C-style scanf '%s'. If <line number> is defined, The first <identifier string> is first look for, and the second one is looked for <line number> lines below the first one.
Example:
$file1 = open "data/1/acqu", "r" %sweep = scan file1, "##$SW_h= %s" close $file1 println "SW = " + %sweep
Read one item (=text) from the text file <file> into the variable <value>. The <identifier string> is a regular expression format string with one C-style scanf '%s'. If <line number> is defined, The first <identifier string> is first looked for, and the second one is looked for <line number> lines below the first one.
Regular Expressions:
The regular_expression defines the pattern to search for. The GREP-like wildcards include:
Example:
$file1 = open "data/procpar", "r" %sfd = scanexp $file1, "^sfrq", 1, ":n %s" close $file1 println "SF = " + %sfd
Read one item (=text) from binary Bruker acqu file <file> into the variable <value>. The <identifier string> is a text string.
Example:
$file1 = open "data/1/acqu", "r" # Test for binary file, first 4 bytes shoul be A000 $test = read $file1 if f2ascii($test) == "A000" then %sweep = scanbin $file1, "SW_h" println "SW = " + %sweep endif close $file1
The print command prints the string <string>, and println does the same and adds a newline. Without the <file> argument, print uses the current output stream. <file> can be a filehandle or the modifiers stdout or stderr, as in the C language.
Example 1:
println "This is" + " an example"Example 2:
println stdout, "The value of var = " + %var
The printf command prints formatted output, much like in C. The argument <format> is a C-type format string, and <arguments> is a list of numbers and strings, separated by comma's. However, the printf command is somewhat more flexible, as it can convert arguments that are of the wrong type. If there is not a sufficient number of arguments, the surplus of format specifies is skipped. The fprintf command is the same as the printf command, but prints its output to a file. Just as in C, sprintf prints to a string.
Example 1:
Example 2:
Example 3:
Example 4: