Please enable JavaScript to view this site.

A-Shell Consolidated Reference

An entire CSV file can be loaded into a gridmap in a single step using:

input csv #ch, $gridmap()

For the gridmap(int; int; varstr) variation, the values will all be indexed by numeric row and column, each index starting from 1. The number of columns in each row may vary.

For the gridmap(int; varstr; varstr) variation, the first row of the CSV is assumed to contain the column headers, which are used for indexing the columns by name. In that case the second physical row of the CSV will be treated as row one. The application can determine the column names by iterating across the first row, using the .key($$i,1) function to check when the row number changes. The following example copies the column names from row one into a separate array:

dimx colnames$(0),s,40,auto_extend

dimx $csvmap, gridmap(int; varstr; varstr)

map1 col,i,2

...

input csv #ch, $csvmap()

foreach $$i in $csvmap()

    if .key($$i,1) = 1 then   ! if row 1

        col += 1

        colnames$(col) = .key($$i,2)

    else

        exit    ! quit when we hit the next row

    endif

next $$i

 

History

2023 October, A-Shell 7.0.1750:  non-trailing empty cells are now included in the gridmap. Previously there were not, which might have created confusion, particularly in the gridmap(int;varstr;varstr) case where a column might have been listed on the header row the CSV but empty in the first data row. Note however, that even with this refinement, empty cells are included only if there are non-empty cells to the right of them (and trailing commas on the CSV lines do not count).

2023 March, A-Shell 6.5.1728:  Add INPUT CSV Into Gridmap.