void init_carbon_i(int cnatm,int POPSIZE, ga_struct *beta_population,int i) { double *cx = (double *) malloc(3*cnatm*sizeof(double)); int j=0; FILE *fp_input=fopen("c.coord","r"); read_coord(fp_input,cnatm,cx); for (j=0;j<cnatm;j++) { beta_population[i].cgen[j][0]=(double)(cx[j*3+0]); beta_population[i].cgen[j][1]=(double)(cx[j*3+1]); beta_population[i].cgen[j][2]=(double)(cx[j*3+2]); } free (cx); fclose(fp_input); }
int img_read_item(img *pimg, img_point *p) { int result; pimg->flags = 0; if (pimg->version >= 3) { int opt; pimg->l = pimg->r = pimg->u = pimg->d = -1.0; if (pimg->pending == 256) { pimg->pending = 0; return img_XSECT_END; } if (pimg->pending >= 0x80) { *p = pimg->mv; pimg->flags = (int)(pimg->pending) & 0x3f; pimg->pending = 0; return img_LINE; } again3: /* label to goto if we get a prefix, date, or lrud */ pimg->label = pimg->label_buf; opt = getc(pimg->fh); if (opt == EOF) { img_errno = feof(pimg->fh) ? IMG_BADFORMAT : IMG_READERROR; return img_BAD; } switch (opt >> 6) { case 0: if (opt == 0) { if (!pimg->label_len) return img_STOP; /* end of data marker */ pimg->label_len = 0; goto again3; } if (opt < 15) { /* 1-14 mean trim that many levels from current prefix */ int c; if (pimg->label_len <= 17) { /* zero prefix using "0" */ img_errno = IMG_BADFORMAT; return img_BAD; } /* extra - 1 because label_len points to one past the end */ c = pimg->label_len - 17 - 1; while (pimg->label_buf[c] != '.' || --opt > 0) { if (--c < 0) { /* zero prefix using "0" */ img_errno = IMG_BADFORMAT; return img_BAD; } } c++; pimg->label_len = c; goto again3; } if (opt == 15) { result = img_MOVE; break; } if (opt >= 0x20) { switch (opt) { case 0x20: /* Single date */ pimg->date1 = get32(pimg->fh); pimg->date2 = pimg->date1; break; case 0x21: /* Date range */ pimg->date1 = get32(pimg->fh); pimg->date2 = get32(pimg->fh); break; case 0x22: /* Error info */ pimg->n_legs = get32(pimg->fh); pimg->length = get32(pimg->fh) / 100.0; pimg->E = get32(pimg->fh) / 100.0; pimg->H = get32(pimg->fh) / 100.0; pimg->V = get32(pimg->fh) / 100.0; return img_ERROR_INFO; case 0x30: case 0x31: /* LRUD */ case 0x32: case 0x33: /* Big LRUD! */ if (read_v3label(pimg) == img_BAD) return img_BAD; pimg->flags = (int)opt & 0x01; if (opt < 0x32) { pimg->l = get16(pimg->fh) / 100.0; pimg->r = get16(pimg->fh) / 100.0; pimg->u = get16(pimg->fh) / 100.0; pimg->d = get16(pimg->fh) / 100.0; } else { pimg->l = get32(pimg->fh) / 100.0; pimg->r = get32(pimg->fh) / 100.0; pimg->u = get32(pimg->fh) / 100.0; pimg->d = get32(pimg->fh) / 100.0; } if (pimg->survey_len) { size_t l = pimg->survey_len; const char *s = pimg->label_buf; if (strncmp(pimg->survey, s, l + 1) != 0) { return img_XSECT_END; } pimg->label += l; /* skip the dot if there */ if (*pimg->label) pimg->label++; } /* If this is the last cross-section in this passage, set * pending so we return img_XSECT_END next time. */ if (pimg->flags & 0x01) { pimg->pending = 256; pimg->flags &= ~0x01; } return img_XSECT; default: /* 0x23 - 0x2f and 0x34 - 0x3f are currently unallocated. */ img_errno = IMG_BADFORMAT; return img_BAD; } goto again3; } /* 16-31 mean remove (n - 15) characters from the prefix */ /* zero prefix using 0 */ if (pimg->label_len <= (size_t)(opt - 15)) { img_errno = IMG_BADFORMAT; return img_BAD; } pimg->label_len -= (opt - 15); goto again3; case 1: if (read_v3label(pimg) == img_BAD) return img_BAD; result = img_LABEL; if (pimg->survey_len) { size_t l = pimg->survey_len; const char *s = pimg->label_buf; if (strncmp(pimg->survey, s, l + 1) != 0) { if (!skip_coord(pimg->fh)) return img_BAD; pimg->pending = 0; goto again3; } pimg->label += l; /* skip the dot if there */ if (*pimg->label) pimg->label++; } pimg->flags = (int)opt & 0x3f; break; case 2: if (read_v3label(pimg) == img_BAD) return img_BAD; result = img_LINE; if (pimg->survey_len) { size_t l = pimg->survey_len; const char *s = pimg->label_buf; if (strncmp(pimg->survey, s, l) != 0 || !(s[l] == '.' || s[l] == '\0')) { if (!read_coord(pimg->fh, &(pimg->mv))) return img_BAD; pimg->pending = 15; goto again3; } pimg->label += l; /* skip the dot if there */ if (*pimg->label) pimg->label++; } if (pimg->pending) { *p = pimg->mv; if (!read_coord(pimg->fh, &(pimg->mv))) return img_BAD; pimg->pending = opt; return img_MOVE; } pimg->flags = (int)opt & 0x3f; break; default: img_errno = IMG_BADFORMAT; return img_BAD; } if (!read_coord(pimg->fh, p)) return img_BAD; pimg->pending = 0; return result; }
int main (int argc, char *argv[]) //========================================================================== {// begin routine //========================================================================== // Local Variables int pi_beads,ip,natm_tot; int iextended_on,num_nhc,len_nhc; MDINTEGRATE mdintegrate; MDATOMS mdatoms; MDINTER mdinter; MDINTRA mdintra; GENERAL_DATA general_data; CP cp; // classes to read in position data for leanMD MDCLATOMS_POS *mdclatoms_pos; MDTHERM_POS therm_class; MDTHERM_POS *therm_bead; //======================================================================= // I) Check for input file if(argc < 2) { printf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n"); printf("No input file specified\n"); printf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n"); fflush(stdout); exit(1); }//endif //======================================================================= // II) Invoke User Interface parse(&mdintegrate,&mdatoms,&mdinter,&mdintra,&general_data,&cp,argv[1]); //======================================================================= // III) output state of classes #define DEBUG_PARSE #ifdef DEBUG_PARSE mdintegrate.state_class_out(); mdatoms.state_class_out(); mdinter.state_class_out(); mdintra.state_class_out(); general_data.state_class_out(); cp.state_class_out(); #endif //======================================================================= // IV) Allocate classes, read the coordinates pi_beads = (mdatoms.mdclatoms_info.pi_beads); natm_tot = (mdatoms.mdclatoms_info.natm_tot); iextended_on = (mdintegrate.mdtherm_info.iextended_on); mdclatoms_pos = (MDCLATOMS_POS *) cmalloc(pi_beads*sizeof(MDCLATOMS_POS),"main.C")-1; for(ip=1;ip<=pi_beads;ip++){ mdclatoms_pos[ip].natm_tot = natm_tot; mdclatoms_pos[ip].x = (double *)cmalloc(natm_tot*sizeof(double),"main.C")-1; mdclatoms_pos[ip].y = (double *)cmalloc(natm_tot*sizeof(double),"main.C")-1; mdclatoms_pos[ip].z = (double *)cmalloc(natm_tot*sizeof(double),"main.C")-1; mdclatoms_pos[ip].vx =(double *)cmalloc(natm_tot*sizeof(double),"main.C")-1; mdclatoms_pos[ip].vy =(double *)cmalloc(natm_tot*sizeof(double),"main.C")-1; mdclatoms_pos[ip].vz =(double *)cmalloc(natm_tot*sizeof(double),"main.C")-1; }// endfor therm_bead = (MDTHERM_POS *) cmalloc(pi_beads*sizeof(MDTHERM_POS),"main.C")-1; if(iextended_on==1){ num_nhc = (mdintegrate.mdtherm_info.num_nhc); len_nhc = (mdintegrate.mdtherm_info.len_nhc); therm_class.num_nhc = num_nhc; therm_class.len_nhc = len_nhc; therm_class.x_nhc = cmall_mat(1,len_nhc,1,num_nhc,"main.C"); therm_class.v_nhc = cmall_mat(1,len_nhc,1,num_nhc,"main.C"); }// endif read_coord(&mdintegrate,&mdatoms,&mdinter,&mdintra,&general_data,&cp, mdclatoms_pos,&therm_class,therm_bead); //======================================================================= // V) Exit, stage left fflush(stdout); fflush(stderr); exit(0); return 0; //---------------------------------------------------------------------- }//end routine
void init_population(int ptnatm, int cnatm, int POPSIZE,ga_struct *population, ga_struct *beta_population,double boxl,int flag_res) { double *x = (double *) malloc(3*ptnatm*sizeof(double)); double *cx = (double *) malloc(3*cnatm*sizeof(double)); double efinal=0; FILE *fp_coordc=fopen("c.coord","r"); FILE *fp_coordpt=fopen("pt.coord","r"); if (flag_res==1&&fp_coordpt==NULL) {printf("ERROR, can not open pt.coord!!\n");exit(0);} //read coordinates of graphene from c.coord read_coord(fp_coordc,cnatm,cx); int i=0; int j=0; for(i=0;i<POPSIZE;i++) { population[i].fitness=0; beta_population[i].fitness=0; //reading from first generation // //read_coord(fp_input2,natm,x); if(flag_res==0) {rand_init(ptnatm,x,boxl);} else if(flag_res==1) { read_coord(fp_coordpt,ptnatm,x); } for (j=0;j<ptnatm;j++) { // printf("%d %lf %lf %lf \n", skip,x,y,z); population[i].gen[j][0]=(double)(x[j*3+0]); population[i].gen[j][1]=(double)(x[j*3+1]); population[i].gen[j][2]=(double)(x[j*3+2]); beta_population[i].gen[j][0]=0; beta_population[i].gen[j][1]=0; beta_population[i].gen[j][2]=0; } for (j=0;j<cnatm;j++) { population[i].cgen[j][0]=(double)(cx[j*3+0]); population[i].cgen[j][1]=(double)(cx[j*3+1]); population[i].cgen[j][2]=(double)(cx[j*3+2]); beta_population[i].cgen[j][0]=(double)(cx[j*3+0]); beta_population[i].cgen[j][1]=(double)(cx[j*3+1]); beta_population[i].cgen[j][2]=(double)(cx[j*3+2]); } // center(natm,population[i].gen); printf("%d %lf %lf %lf \n",i,population[i].cgen[cnatm-1][0],population[i].cgen[cnatm-1][1],population[i].cgen[cnatm-1][2]); printf("%d %lf %lf %lf \n",i,population[i].gen[0][0],population[i].gen[ptnatm-1][1],population[i].gen[ptnatm-1][2]); } free (x); free (cx); fclose(fp_coordc); if(fp_coordpt!=NULL){ fclose(fp_coordpt);} }