+ t_hp *hp;
+ t_moldyn *md;
+ int steps;
+ double tau;
+ double dt;
+
+ hp=hook_params;
+ md=moldyn;
+
+ tau=1.0;
+ steps=0;
+
+ /* switch on t scaling */
+ if(md->schedule.count==0)
+ set_pt_scale(md,0,0,T_SCALE_BERENDSEN,100.0);
+
+ /* my lousy state machine ! */
+
+ /* switch to insert state immediately */
+ if(hp->state==STATE_PRERUN)
+ hp->state=STATE_INSERT;
+
+ /* act according to state */
+ switch(hp->state) {
+ case STATE_INSERT:
+ /* assigne values */
+ steps=INS_RELAX;
+ tau=INS_TAU;
+ /* check temperature */
+ dt=md->t_avg-md->t_ref;
+ if(dt<0)
+ dt=-dt;
+ if(dt>INS_DELTA_TC)
+ break;
+ /* insert atoms */
+ hp->insert_count+=1;
+ printf(" ### insert atoms (%d/%d) ###\n",
+ hp->insert_count*INS_ATOMS,INS_RUNS*INS_ATOMS);
+ insert_atoms(md);
+ /* change state after last insertion */
+ if(hp->insert_count==INS_RUNS)
+ hp->state=STATE_POSTRUN;
+ break;
+ case STATE_POSTRUN:
+ /* assigne values */
+ steps=POST_RELAX;
+ tau=POST_TAU;
+ /* check temperature */
+ dt=md->t_avg-md->t_ref;
+ if(dt<0)
+ dt=-dt;
+ if(dt>INS_DELTA_TC)
+ break;
+ /* decrease temperature */
+ hp->postrun_count+=1;
+ printf(" ### postrun (%d/%d) ###\n",
+ hp->postrun_count,POST_RUNS);
+ set_temperature(md,md->t_ref-POST_DT);
+ if(hp->postrun_count==POST_RUNS)
+ return 0;
+ break;
+ default:
+ printf("[hook] FATAL (default case!?!)\n");
+ break;