+int crt(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ t_stage *stage;
+ t_crt_params *crtp;
+
+ int fd;
+ char line[128];
+ char *wptr;
+ int acount;
+ int ret;
+ void *ptr;
+
+ extern u8 crt;
+ extern u8 *constraints;
+ extern double *trafo_angles;
+
+ t_atom *atom;
+ double dx,dy,dz;
+
+ stage=mdrun->stage.current->data;
+ crtp=stage->params;
+
+ acount=0;
+
+ /* initial stuff */
+
+ if(crtp->count==0) {
+ printf(" crt init\n",acount);
+ // read final positions, constraints and do the alloc
+ fd=open(crtp->file,O_RDONLY);
+ if(fd<0) {
+ perror("[mdrun] FATAL reading constraints file");
+ return fd;
+ }
+ while(1) {
+ ret=get_line(fd,line,128);
+ // check for end of file
+ if(ret<=0) {
+ printf(" -> read %d atom positions\n",acount);
+ crtp->acnt=acount;
+ break;
+ }
+ // ignore # lines and \n
+ if((line[0]=='#')|(ret==1))
+ continue;
+ // allocate new memory
+ ptr=realloc(crtp->r_fin,(acount+1)*sizeof(t_3dvec));
+ if(ptr==NULL) {
+ perror("[mdrun] FATAL realloc crt positions");
+ return -1;
+ }
+ crtp->r_fin=ptr;
+ ptr=realloc(constraints,(acount+1)*3*sizeof(u8));
+ if(ptr==NULL) {
+ perror("[mdrun] FATAL realloc crt constraints");
+ return -1;
+ }
+ constraints=ptr;
+ // ignore type
+ wptr=strtok(line," \t");
+ // read x y z
+ wptr=strtok(NULL," \t");
+ crtp->r_fin.x=atof(wptr);
+ wptr=strtok(NULL," \t");
+ crtp->r_fin.y=atof(wptr);
+ wptr=strtok(NULL," \t");
+ crtp->r_fin.z=atof(wptr);
+ // read constraints
+ wptr=strtok(NULL," \t");
+ constraints[acount]=atoi(wptr);
+ wptr=strtok(NULL," \t");
+ constraints[acount+1]=atoi(wptr);
+ wptr=strtok(NULL," \t");
+ constraints[acount+2]=atoi(wptr);
+ // done reading
+ acount+=1;
+ }
+ // allocate trafo angles
+ trafo_angle=malloc(acount*2*sizeof(double));
+ if(trafo_angle==NULL) {
+ perror("[mdrun] FATAL alloc trafo angles");
+ return -1;
+ }
+ // set crt mode
+ crt=crtp->type;
+ }
+
+ /* crt routines: calculate displacement + set individual constraints */
+
+ for(i=0;i<moldyn->count;i++) {
+ atom=moldyn->atom;
+ dx=atom[i].r.x-crtp->r_fin[i].x;
+ dy=atom[i].r.y-crtp->r_fin[i].y;
+ dz=atom[i].r.z-crtp->r_fin[i].z;
+ // HIER WEITER
+ }
+
+ return 0;
+}
+