= #JxnPortable/docs/application_examples/DataAnalysis.jxn

! Shows different ways to read data files
! - fixed width columns
! - character separated columns

! Note: mixed variations of different ways given here for demonstration
!       real life applications should chose a variant and stay with it

src0 = @JxnRealArrayTextFileDataSource( $this.getPath( "data_fixed_width_columns.html" ) )
 = "data_fixed_width_columns.html", 0, ";\t", " " (JxnRealArrayTextFileDataSource)
t = src0.get( 1, -6 )    ! reads characters from position 1 to 6 (excluded)
 = {0.0, 0.001, ... 0.025 "t    "}[26] (JxnRealArrayAlgebra)
sn = src0.get( 6, 7 )    ! reads 7 characters starting from position 6
 = {0.0, 0.309, ... 1.0 "  sin  "}[26] (JxnRealArrayAlgebra)
cs = src0.get( 13, 0 )   ! reads rest of line starting from position 13
 = {1.0, 0.951, ... 0.0 "  cos"}[26] (JxnRealArrayAlgebra)
plot( t, sn, cs )
 = {1} (JxnRealArrayPlotFrame)
!
format( src0.readLines(8) )
 = {     12345678901234567890123456789012345678901234567890123456789012345678901234567890,
 =   1: "<pre>",
 =   2: "file: data_fixed_width_columns.html",
 =   3: "",
 =   4: "ω = 2 π f;  f = 50 Hz",
 =   5: "",
 =   6: "<---><-----><----->",
 =   7: "t      sin    cos",
 =   8: "0      0.000  1.000" } (java.lang.String[9]) (java.lang.String)
! also can read as ' '-separated
src0.setSkipHeadLines(4)
 = "data_fixed_width_columns.html", 4, ";\t", " " (JxnRealArrayTextFileDataSource)
t = src0[1]   ! shortcut for src0.get(1), reads 1st column
 = {0.0, 0.001, ... 0.025 "t"}[26] (JxnRealArrayAlgebra)
sn = src0[2]  ! reads 2nd column
 = {0.0, 0.309, ... 1.0 "sin"}[26] (JxnRealArrayAlgebra)
cs = src0[ "cos" ]  ! reads column labeled "cos"
 = {1.0, 0.951, ... 0.0 "cos"}[26] (JxnRealArrayAlgebra)
plot( t, sn, cs )
 = {2} (JxnRealArrayPlotFrame)


src1 = @JxnRealArrayTextFileDataSource( $this.getPath "data_tab_separated_columns.html", 0, "\t", "" )
 = "data_tab_separated_columns.html", 0, "\t", "" (JxnRealArrayTextFileDataSource)
t = src1["t"]  ! shortcut for src1.get("t"), reads column labeled "t"
 = {0.0, 0.001, ... 0.025 "t"}[26] (JxnRealArrayAlgebra)
sn = src1[2]
 = {0.0, 0.309, ... 1.0 "sin ω t"}[26] (JxnRealArrayAlgebra)
cs = src1[3]
 = {1.0, 0.951, ... 0.0 "cos ω t"}[26] (JxnRealArrayAlgebra)
plot( t, sn, cs )
 = {3} (JxnRealArrayPlotFrame)


src2 = @JxnRealArrayTextFileDataSource $this.getPath "data_semi-colon_separated_columns.html"
 = "data_semi-colon_separated_columns.html", 0, ";\t", " " (JxnRealArrayTextFileDataSource)
src2.setDelimiters( null, "" )  ! null => delim1 not changed, "" => ignores delim2 (see apidocs)
 = "data_semi-colon_separated_columns.html", 0, ";\t", "" (JxnRealArrayTextFileDataSource)
t = src2["t"]
 = {0.0, 0.001, ... 0.025 "t"}[26] (JxnRealArrayAlgebra)
sn = src2[2]
 = {0.0, 0.309, ... 1.0 "sin 2 PI f t"}[26] (JxnRealArrayAlgebra)
cs = src2[ "cos 2 PI f t" ]  ! access by column label
 = {1.0, 0.951, ... 0.0 "cos 2 PI f t"}[26] (JxnRealArrayAlgebra)
plot( t, sn, cs )
 = {4} (JxnRealArrayPlotFrame)