#!/bin/csh


set init = step5_input
set mini_prefix = step6.0_minimization
set equi_prefix = step6.%d_equilibration
set prod_prefix = step7_production
set prod_step   = step7

set num_rep = 4
set rep_ladder = ( 310 311.18 312.35 313.54 )


set i = 1
while ( ${i} <= ${num_rep} )
    sed "s/#temp/${rep_ladder[${i}]}/g" ${prod_prefix}.mdin > ${prod_prefix}.mdin.rep.${i}
    @ i += 1
end

# Production
set cnt = 1
set cntmax = 3

while ( ${cnt} <= ${cntmax} )
    touch groupfile_prod_${cnt}
    @ pcnt = ${cnt} - 1
    set istep = ${prod_step}_${cnt}
    if ( ${cnt} == 1 ) then
        set pstep = `printf ${equi_prefix} 6`
        set i = 1
        while ( ${i} <= ${num_rep} )
            echo "-O -i ${prod_prefix}.mdin.rep.${i} -p ${init}.parm7 -c ${pstep}.rst7 -o ${istep}.mdout.rep.${i} -r ${istep}.rst7.rep.${i} -inf ${istep}.mdinfo.rep.${i} -x ${istep}.nc.rep.${i}" >> groupfile_prod_${cnt}
            @ i += 1
        end

    else
        set i = 1
        set pstep = ${prod_step}_${pcnt}
        while (${i} <= ${num_rep})
            echo "-O -rem 1 -remlog rem.log -i ${prod_prefix}.mdin.rep.${i} -p ${init}.parm7 -c ${pstep}.rst7.rep.${i} -o ${istep}.mdout.rep.${i} -r ${istep}.rst7.rep.${i} -inf ${istep}.mdinfo.rep.${i} -x ${istep}.nc.rep.${i}" >> groupfile_prod_${cnt}
            @ i += 1
        end
    endif

    mpirun -np ${num_rep} pmemd.cuda_SPFP.MPI -groupfile groupfile_prod_${cnt}

    @ cnt += 1
end

