// globals

function preprocess () {
  

echo ('  require(eRm)\n');
}


function printout () {
        doPrintout (true);
}

function preview () {
        preprocess ();
        calculate ();
        doPrintout (false);
}

function doPrintout (final) {
        
        
        

  
  inp_items        = getValue("inp_items");
  spin_abilfrom    = getValue("spin_abilfrom");
  spin_abilto      = getValue("spin_abilto");
  spin_probfrom    = getValue("spin_probfrom");
  spin_probto      = getValue("spin_probto");
  annotation       = getValue("annotation");
  chk_ask          = getValue("chk_ask");
  chk_mplot        = getValue("chk_mplot");

  
  plot_options     = getValue("plotoptions.code.printout");
  plot_ops_main    = getValue("plotoptions.main");
  plot_ops_type    = getValue("plotoptions.pointtype");
  plot_ops_xlab    = getValue("plotoptions.xlab");
  plot_ops_ylab    = getValue("plotoptions.ylab");

  
  
  options = array() ;
  
  if(inp_items) {
    
    
    inp_items = str_replace("-",":",inp_items);
    arr_items = split('[ ;]', inp_items);
    options[] = "item.subset=c("+join(",", arr_items)+")"; }
  if(chk_mplot == "mplot")
    options[] = "mplot=TRUE" ;
  if(chk_ask != "ask")
    options[] = "ask=FALSE" ;

  
  
  if((spin_abilfrom != "-4" || spin_abilto != "4") && spin_abilfrom < spin_abilto)
    options[] = "xlim=c("+round(spin_abilfrom,2)+","+round(spin_abilto,2)+")" ;
  if((spin_probfrom != "0" || spin_probto != "1") && spin_probfrom < spin_probto)
    options[] = "ylim=c("+round(spin_probfrom,2)+","+round(spin_probto,2)+")" ;
  
  if(annotation == "plain")
    options[] = "legpos=FALSE" ;

        if (final) { 
echo ('rk.header("Partial credit model plot")\n');
echo ('\n');
echo ('rk.graph.on()\n');
      }
        

        
echo ('try(plotICC(' + getValue("x"));
              if(options) echo (", "+join(", ", options));
              if(plot_options) echo (plot_options);
          echo ('))\n');
        if (final) { 
echo ('rk.graph.off()\n');
}
}
