READ_ASCII: scalar required error for TEMPLATE variable

Issue #9 resolved
Former user created an issue

As in title: read_ascii's "template" variable is supposed to be a structure, but for some reason the newly-added read_ascii is requiring a scalar.

Comments (8)

  1. Lajos Foldy repo owner

    Scalar means "not a structure array". Have you called it with a structure array?

    Anyway, I have modified the code to allow single element structure arrays for the template.

    Thanks for the report.

  2. Ben West

    "template" is supposed to be in the form defined by the function "ascii_template", which outputs a structure. So, the input should be a multiple-element structure.

  3. Lajos Foldy repo owner

    A structure is OK, a structure array is not. Take this example:

    s1={s, ...}
    s2=replicate(s, 1)
    s3=replicate(s, 2)
    

    s1 is accepted, s2 and s3 are rejected (they are arrays, not "scalars"). I've changed the code to accept s2, too. s1 and s2 are single structures, s3 is an array of structures. I think 'ascii_template' returns an s1-like structure.

    Can you show what you are using for template?

  4. Ben West

    Apologies, I did mean a single structure, not an array of structures.

    template = { $
        VERSION : 1.0, $
        DATASTART : 0, $
        DELIMITER : [44], $
        MISSINGVALUE : 0, $
        COMMENTSYMBOL : "", $
        FIELDCOUNT : 10, $
        FIELDTYPES : [7, 7, 7, 7, 7, 7, 7, 7, 7, 7], $
        FIELDNAMES : ["field01", "field02", "field03", "field04", "field05", "field06", "field07", "field08", "field09", "field10"], $
        FIELDLOCATIONS : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], $
        FIELDGROUPS : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] $
    }
    

    I'm testing this with the example CSV file located at https://people.sc.fsu.edu/~jburkardt/data/csv/cities.csv (not that it should matter, and it doesn't seem to on my end, but regardless)

    This is actually the template variable as pulled from a working version of IDL, specifically out of its copy of read_csv.

  5. Lajos Foldy repo owner

    The "Scalar required" message is OK, the DELIMITER should be a scalar. IDL 8.5.1 prints:

    % READ_ASCII: DELIMITER must be one character.

    The delimiter should be 44b, not an array.

    The next error message comes from checking FIELDLOCATIONS. 'ascii_template' creates a non-zero array. I have suppressed this check in FL when the delimiter is defined.

    Also, there was an error in FL in handling EOF when num_records is not specified The next FL snapshot (in April) will work with your file and template.

    As a workaround, you can use FL 0.79.43.1 with:

    • changing FIELDLOCATIONS to be valid (eg copying FIELDGROUPS)
    • adding NUM_RECORDS=129
  6. Ben West

    Apologies again, I had taken what TEMPLATE was defined as in order to work back and quickly make that command to define it for testing.

    DELIMITER is defined as "byte(',')" within IDL 8.5.1's READ_CSV, which (for some reason or another) defines it as a single-element array of 44b. Strangely, when I try this in IDL 8.5.1 I don't see the error you report (or any error).

    I can confirm that your workaround works.

  7. Lajos Foldy repo owner

    This function fails for me (a=test()):

    function test
    t = { $
        VERSION : 1.0, $
        DATASTART : 0, $
        DELIMITER : [44], $
        MISSINGVALUE : 0, $
        COMMENTSYMBOL : "", $
        FIELDCOUNT : 10, $
        FIELDTYPES : [7, 7, 7, 7, 7, 7, 7, 7, 7, 7], $
        FIELDNAMES : ["f01", "f02", "f03", "f04", "f05", "f06", "f07", "f08", "f09", "f10"], $
        FIELDLOCATIONS : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], $
        FIELDGROUPS : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] $
    }
    return, read_ascii('cities.csv', template=t)
    end
    

    I'm glad that the workaround works :-)

    'read_csv' is still to be written (with the undocumented /CSV keyword for read_ascii).

  8. Log in to comment