#!/bin/csh -f
#
# luconfig
#   make a new configuration like an existing one, but set the
# LU-decomposition parameters and put it in the luconfigs directory.
#
# This takes a few steps
#
# -  build a new directory name
#
# -  update the parameters
#######
#
set usage='luconfig N SLAB_COLS iopfs sorting layout Ndisk'
#
#
# Part of
#              The STARFISH Parallel file-system simulator
#        (Simulation Tool for Advanced Research in File Systems)
# 
#                               David Kotz
#                           Dartmouth College
#                              Version 3.0
#                              October 1996
#                          dfk@cs.dartmouth.edu

if ($#argv != 6) then
    echo "$usage"
    exit 1
endif

onintr cleanup

set N=$1
set slabcols=$2
set iopfs=$3
set sort=$4
set layout=$5
set Ndisk=$6

set recsize=4
set blocksize=16384  # do not change without using config to change lubase files
		    # if you do that, it sets sort, cpfs, iopfs, and layout
		    # so be sure to run config-fix after config

# compute number of blocks needed; round up
@ fileblocks = ($N * $N * $recsize + $blocksize - 1) / $blocksize

set dirname=luconfigs/$N.$slabcols.$blocksize.$iopfs.$sort.$layout.$Ndisk

echo new dir $dirname
if (-d $dirname) exit 

mkdir $dirname
ln -s ../../lubase/{Configfile,ParamHelp} $dirname/
cp lubase/*.param $dirname/
chmod +w $dirname/*.param

cd $dirname
echo $dirname

# NOT ALL PARAMS can be set this way...
# and here I assume that lubase is set to have all options #undef
# among the sort, iopfs, cpfs, and layout choices.

switch ($iopfs)
case cache:
    setparam IOP_CACHE   true     iopfs.param
    setparam CP_NONE   true     cpfs.param
    breaksw

case general:
    setparam IOP_GENERAL   true     iopfs.param
    setparam CP_DIRECT   true     cpfs.param
    breaksw

default:
    echo iopfs $iopfs not supported
    exit 1
    breaksw
endsw

switch ($sort)
case sort:
    setparam DISK_SORT true diskmodel.param
    breaksw
case nosort:
#    setparam DISK_SORT false diskmodel.param
    breaksw
default:
    echo sort $sort not supported
    exit 1
    breaksw
endsw

switch ($layout)
case contig:
    setparam LAYOUT_CONTIGUOUS true diskmodel.param
    breaksw
case rsectors:
    setparam LAYOUT_RANDOM_SECTORS true diskmodel.param
    breaksw
case rtracks:
    setparam LAYOUT_RANDOM_TRACKS true diskmodel.param
    breaksw
default:
    echo layout $layout not supported
    exit 1
    breaksw
endsw

setparam RECORD_SIZE $recsize file.param

setparam FILE_BLOCKS_MAX $fileblocks file.param
setparam NO_OF_DISKS $Ndisk disk.param

setparam LU_MATRIX_SIZE $N lu.param
setparam LU_SLAB_SIZE $slabcols lu.param

setparam REAL_DATA true userdata.param
