def add_to_Cfunc_dict__Cart_to_xx_and_nearest_i0i1i2(rel_path_to_Cparams=os.path.join('./'), relative_to='local_grid_center'):
    gridsuffix = ''
    CoordSystem = par.parval_from_str('reference_metric::CoordSystem')
    prefunc = ''
    desc = 'Given Cartesian point (x,y,z), this function outputs the corresponding\n  (xx0,xx1,xx2) and the "closest" (i0,i1,i2) for the given grid'
    namesuffix = ''
    if (relative_to == 'global_grid_center'):
        namesuffix = ('_' + relative_to)
    name = (('Cart_to_xx_and_nearest_i0i1i2' + namesuffix) + gridsuffix)
    params = 'const paramstruct *restrict params, const REAL xCart[3], REAL xx[3], int Cart_to_i0i1i2[3]'
    preloop = ''
    if (relative_to == 'local_grid_center'):
        preloop = '\n    // First compute the closest (xx0,xx1,xx2) to the given Cartesian gridpoint (x,y,z),\n    //   *relative* to the center of the local grid.\n    //   So for example,\n    //   1) if global xCart[012] = (1,1,1), and the\n    //      origin of the grid is at global xCart (x,y,z) = (1,1,1), then\n    //      (Cartx,Carty,Cartz) = (0,0,0)\n    //   2) if global xCart[012] = (0,0,0), and the\n    //      origin of the grid is at global xCart (x,y,z) = (1,1,1), then\n    //      (Cartx,Carty,Cartz) = (-1,-1,-1)\n    // Therefore, (Cartx,Carty,Cartz) = (xCart[0]-originx, xCart[1]-originy, xCart[2]-originz)\n    const REAL Cartx = xCart[0] - Cart_originx_GRIDSFX_;\n    const REAL Carty = xCart[1] - Cart_originy_GRIDSFX_;\n    const REAL Cartz = xCart[2] - Cart_originz_GRIDSFX_;\n'.replace('_GRIDSFX_', gridsuffix)
    elif (relative_to == 'global_grid_center'):
        preloop = '\n    const REAL Cartx = xCart[0];\n    const REAL Carty = xCart[1];\n    const REAL Cartz = xCart[2];\n'
    else:
        print((('Error: relative_to must be set to either local_grid_center or global_grid_center. ' + relative_to) + ' was chosen.'))
        sys.exit(1)
    if ('theta_adj' in CoordSystem):
        body = outputC([Cart_to_xx[0], Cart_to_xx[1], Cart_to_xx[2]], ['xx[0]', 'const REAL target_th', 'xx[2]'], 'returnstring', params='includebraces=False,preindent=1')
        body += '       xx[1] = NewtonRaphson_get_xx1_from_th(params, target_th);\n'
    else:
        body = outputC([Cart_to_xx[0], Cart_to_xx[1], Cart_to_xx[2]], ['xx[0]', 'xx[1]', 'xx[2]'], 'returnstring', params='includebraces=False,preindent=1')
    body += (((((((((((((((('\n    // Then find the nearest index (i0,i1,i2) on underlying grid to (x,y,z)\n    // Recall that:\n    // xx[0][j] = xxmin[0] + ((REAL)(j-NGHOSTS) + (1.0/2.0))*params->dxx0' + gridsuffix) + '; // Cell-centered grid.\n    //   --> j = (int) ( (xx[0][j] - xxmin[0]) / params->dxx0') + gridsuffix) + ' + (1.0/2.0) + NGHOSTS )\n    Cart_to_i0i1i2[0] = (int)( ( xx[0] - (') + str(xxmin[0])) + ') ) / params->dxx0') + gridsuffix) + ' + (1.0/2.0) + NGHOSTS - 0.5 ); // Account for (int) typecast rounding down\n    Cart_to_i0i1i2[1] = (int)( ( xx[1] - (') + str(xxmin[1])) + ') ) / params->dxx1') + gridsuffix) + ' + (1.0/2.0) + NGHOSTS - 0.5 ); // Account for (int) typecast rounding down\n    Cart_to_i0i1i2[2] = (int)( ( xx[2] - (') + str(xxmin[2])) + ') ) / params->dxx2') + gridsuffix) + ' + (1.0/2.0) + NGHOSTS - 0.5 ); // Account for (int) typecast rounding down\n')
    add_to_Cfunction_dict(includes=[os.path.join(rel_path_to_Cparams, 'NRPy_basic_defines.h')], prefunc=prefunc, desc=desc, c_type='void', name=name, params=params, preloop=preloop, body=body, rel_path_to_Cparams=rel_path_to_Cparams)
def add_to_Cfunc_dict__Cart_to_xx_and_nearest_i0i1i2(rel_path_to_Cparams=os.path.join('./'), relative_to='local_grid_center'):
    gridsuffix = 
    CoordSystem = par.parval_from_str('reference_metric::CoordSystem')
    prefunc = 
    desc = 'Given Cartesian point (x,y,z), this function outputs the corresponding\n  (xx0,xx1,xx2) and the "closest" (i0,i1,i2) for the given grid'
    namesuffix = 
    if (relative_to == 'global_grid_center'):
        namesuffix = ('_' + relative_to)
    name = (('Cart_to_xx_and_nearest_i0i1i2' + namesuffix) + gridsuffix)
    params = 'const paramstruct *restrict params, const REAL xCart[3], REAL xx[3], int Cart_to_i0i1i2[3]'
    preloop = 
    if (relative_to == 'local_grid_center'):
        preloop = '\n    // First compute the closest (xx0,xx1,xx2) to the given Cartesian gridpoint (x,y,z),\n    //   *relative* to the center of the local grid.\n    //   So for example,\n    //   1) if global xCart[012] = (1,1,1), and the\n    //      origin of the grid is at global xCart (x,y,z) = (1,1,1), then\n    //      (Cartx,Carty,Cartz) = (0,0,0)\n    //   2) if global xCart[012] = (0,0,0), and the\n    //      origin of the grid is at global xCart (x,y,z) = (1,1,1), then\n    //      (Cartx,Carty,Cartz) = (-1,-1,-1)\n    // Therefore, (Cartx,Carty,Cartz) = (xCart[0]-originx, xCart[1]-originy, xCart[2]-originz)\n    const REAL Cartx = xCart[0] - Cart_originx_GRIDSFX_;\n    const REAL Carty = xCart[1] - Cart_originy_GRIDSFX_;\n    const REAL Cartz = xCart[2] - Cart_originz_GRIDSFX_;\n'.replace('_GRIDSFX_', gridsuffix)
    elif (relative_to == 'global_grid_center'):
        preloop = '\n    const REAL Cartx = xCart[0];\n    const REAL Carty = xCart[1];\n    const REAL Cartz = xCart[2];\n'
    else:
        print((('Error: relative_to must be set to either local_grid_center or global_grid_center. ' + relative_to) + ' was chosen.'))
        sys.exit(1)
    if ('theta_adj' in CoordSystem):
        body = outputC([Cart_to_xx[0], Cart_to_xx[1], Cart_to_xx[2]], ['xx[0]', 'const REAL target_th', 'xx[2]'], 'returnstring', params='includebraces=False,preindent=1')
        body += '       xx[1] = NewtonRaphson_get_xx1_from_th(params, target_th);\n'
    else:
        body = outputC([Cart_to_xx[0], Cart_to_xx[1], Cart_to_xx[2]], ['xx[0]', 'xx[1]', 'xx[2]'], 'returnstring', params='includebraces=False,preindent=1')
    body += (((((((((((((((('\n    // Then find the nearest index (i0,i1,i2) on underlying grid to (x,y,z)\n    // Recall that:\n    // xx[0][j] = xxmin[0] + ((REAL)(j-NGHOSTS) + (1.0/2.0))*params->dxx0' + gridsuffix) + '; // Cell-centered grid.\n    //   --> j = (int) ( (xx[0][j] - xxmin[0]) / params->dxx0') + gridsuffix) + ' + (1.0/2.0) + NGHOSTS )\n    Cart_to_i0i1i2[0] = (int)( ( xx[0] - (') + str(xxmin[0])) + ') ) / params->dxx0') + gridsuffix) + ' + (1.0/2.0) + NGHOSTS - 0.5 ); // Account for (int) typecast rounding down\n    Cart_to_i0i1i2[1] = (int)( ( xx[1] - (') + str(xxmin[1])) + ') ) / params->dxx1') + gridsuffix) + ' + (1.0/2.0) + NGHOSTS - 0.5 ); // Account for (int) typecast rounding down\n    Cart_to_i0i1i2[2] = (int)( ( xx[2] - (') + str(xxmin[2])) + ') ) / params->dxx2') + gridsuffix) + ' + (1.0/2.0) + NGHOSTS - 0.5 ); // Account for (int) typecast rounding down\n')
    add_to_Cfunction_dict(includes=[os.path.join(rel_path_to_Cparams, 'NRPy_basic_defines.h')], prefunc=prefunc, desc=desc, c_type='void', name=name, params=params, preloop=preloop, body=body, rel_path_to_Cparams=rel_path_to_Cparams)