Fscanf

From HyPhy Wiki
Jump to: navigation, search

fscanf is an input command. It can be used to read values of numbers, matrices or trees from files or the console.

Contents

Syntax

 fscanf(input, format_string, receptacle_1, <receptacle_2>,...,<receptacle_n>);

Functionality

Parameters

  • input: A filename,stdin, or PROMPT_FOR_FILE. The filename is relative to the path from which the batch script is being executed from. stdin takes input from the console. PROMPT_FOR_FILE is to be used if you wish the user to be prompted to select a file.
  • format_string: Format string is a quote-enclosed comma separated list with 5 allowed terms.
Example Explanation
Number Reads a Number
Matrix Reads a Matrix. Matrices must enclosed in `{..}`.
Tree Reads a Tree. Trees are enclosed in `(..)`.
String Reads a String
Raw Split the previously unread contents of the file into strings and store them in a row vector.
  • receptacle_k: The variable to respectfully store what is defined by the format_string.

Notes

fscanf will skip all the characters in between meaningful input (except in `Raw` mode).

Example

fscanf (stdin, "Number,Matrix,Tree",x,m,t);
/* User inputs: "0.12;  {{0,1}{1,0}} sjdiwj ((1,2),3,4)" */

Variables now equal:

  • x: 0.12
  • m: {{0,1}{1,0}}
  • t: ((1,2)Node1,3,4)
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox