// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

shader test_split_v_str_u_sep_u_max (output vector res=0, 
           output vector calres = 0)
{
    string var_str = format("%f",v);
    string uniform_sep = ",";
    int uniform_maxsplit = 3;
        
    //Initialize result output array
    string results[4] = {var_str,var_str,var_str,var_str}; 
    string results1[4] = {var_str,var_str,var_str,var_str};
    
    //Setup uniform string
    int accum1 = 0;
    int sc1 = 0;
    sc1 = split(format("%f,%f,%f,%f", 2*v, 4*u, 6*v, 8*u),results, uniform_sep, uniform_maxsplit); //varying string
    
    for (int i = 0 ; i<sc1; ++i) {
        accum1 += stoi(results[i]); //Segfaults sometimes, but gives correct result.
    }
    res = vector (accum1/40.0, u, (float) sc1*u);
    
    int accum2 = 0;
    int sc2 = 0;
    
    int sc_control = 0;
    if(int(P[0]*64)%2 == 0) {
         sc_control = 3;
         sc2=split(format("%f,%f,%f,%f", 3*(v+u),6*u,9*(u+v),12*(u-v)),results1, uniform_sep, uniform_maxsplit);//varying string
    }
    
    for (int i = 0 ; i<sc2; ++i) {
        accum2 += stoi(results1[i]); 
    }
    
    calres = vector(((float)accum2)+4.0/(15.0 + u*15), u+v, ((float)accum1)+4.0/(10.0 + v*10.0));
}

