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

shader test_split_u_str_v_sep_v_max (output vector res=0, 
           output vector calres = 0)
{
    string uniform_str =  format("%d",raytype("camera"));
    string var_sep = format("%d", int(u)*2); //Varying sep
    //printf("%s\t", var_sep);
    int var_maxsplit = int(u) + 3*int(u);//varying maxsplit
        
    //Initialize result output array
    string results[4] = {uniform_str,uniform_str,uniform_str,uniform_str}; 
    string results1[4] = {uniform_str,uniform_str,uniform_str,uniform_str};
    
    //Setup uniform string
    int uval = raytype("camera");
    int accum1 = 0;
    int sc1 = 0;
    
    sc1 = split(format("%d,%d,%d,%d,%d", 2*uval, 2, 2*uval, 6*uval, 8*uval ),results, var_sep, var_maxsplit); //varying string amd varying separator
    
    for (int i = 0 ; i<sc1; ++i){
        accum1 = stoi(results[i]);
    }
    res = vector (accum1/40.0, u, (float) sc1*u);
    
    int accum2 = 0;
    int sc2 = 0;
    
    if(int(P[0]*64)%2){
         sc2 = split(format("%d,%d,%d,%d,%d", 3*uval,2, 6*uval, 9*uval,12*uval),results1, var_sep, var_maxsplit);//varying string and varying sep
    }
    
    for (int i = 0 ; i<sc2; ++i){
        accum2 += stoi(results1[i]);
    }
    
    //printf("accum2 is %d", accum2);
    //printf("sc2 is %d \t", sc2);
    //string st = format("%d,%d,%d,%d", 2*uval, 2*uval, 6*uval, 8*uval );
    //printf("string is %s ", st);
    calres = vector(((float)accum2)+14.0/(15.0 + u*15), u+v, ((float)accum1)+4.0/(9.0 + v*9.0)); 
}
