#! /bin/csh -f
# 
#  transform a table of 256 RGB values into a float[256][3] array
#  e.g.    lut2c $NEMODAT/lut/*lut > all_lut.c
#    

set testbed=0

set names=()

foreach file ($*)
  set last=$file:t
  set name=$last:r
  set names=($names $name)

  echo "/* automatically generated from NEMO's $0 script - do not edit */"

#  echo "static float ${name}[256][3] = { "
  echo "static float ${name}[256*3] = { "
  awk '{printf("   %s , %s , %s ,\n",$1,$2,$3)}' $file
  echo "};"

  if ($testbed) then
    echo '#ifdef TESTBED'                                
    echo '#include <stdio.h>'                            
    echo '#define name ' $name
    echo 'main() {'                                      
    echo '  int i, j;'                                   
    echo '  for (i=0; i<256; i++)'                       
    echo '      printf("%d %f %f %f\n",i+1,'
    echo '      name[i][0],name[i][1],name[i][2]);'
    echo '}'                                             
    echo '#endif'
  endif

end


# now write all the names....

echo ""
echo "/* ------------------------------------------------- */"
echo ""
echo "typedef struct RGB_s {"
echo "   char *name;"
echo "   float *rgb;"
echo "} RGB;"

echo "static RGB rgb[] = {"
foreach name ($names)
   echo '    {"'${name}'", '$name'},'
end
echo "    {0,0}"
echo "};"
