ConfigFile.cpp 18.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
# Copyright 2016-2018 The NOMAD Developers Group
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
 #     http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
*/


18
#include <algorithm>
19
#include <errno.h>
20
#include <string.h>
lrz's avatar
lrz committed
21
#include <stdlib.h>
22 23 24 25

#include "ConfigFile.h"
#include "atoms.hpp"
#include "eprintf.h"
26
#include "polyhedron.h"
27 28 29 30 31 32 33 34 35

const char * PATH;
const char * SCREENSHOT;
int ISOS;
int TIMESTEPS;
float **isocolours; // [ISOS][4];
const char **plyfiles;
float **translations;
float userpos[3];
36 37
float scaling;
float markerscaling;
38 39

float BACKGROUND[3];
40

41 42
float atomScaling;
std::vector<float> *clonedAtoms;
43 44
std::vector<int> bonds;
int *numBonds;
45
bool displaybonds;
46 47 48
float bondscolours[4];
float atomtrajectorycolour[4];

49 50 51 52 53 54 55
int numClonedAtoms;
int *basisvectorreps;

bool showTrajectories;
std::vector<int> atomtrajectories;
std::vector<std::vector<int>> atomtrajectoryrestarts;

56
bool displayunitcell;
57

58 59
float unitcellcolour[4];
float supercellcolour[4];
60

61 62
float infolinecolour[4];

63
int repetitions[3];
64
Solid *solid;
65

66 67
bool saveStereo;
int screenshotdownscaling;
68
bool hapticFeedback;
69
bool showcontrollers;
70 71 72 73
bool gazenavigation;
int transparencyquality;
float nearclip, farclip;

74 75 76
//markers such as hole positions and electron positions
float ** markers;
float ** markercolours;
77

78 79
float animationspeed;
float movementspeed;
80

81 82
menubutton_t menubutton;

83 84
std::vector<information> info;

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
const char * loadConfigFileErrors[] =
{
	"All Ok",//0
	"file could not be opened", //-1
	"unrecognized parameter",//-2
	"values with no previous iso", //-3
	"colours with no previous iso",//-4
	"translations with no previous correct iso",//-5
	"Missing isos and xyzfile",//-6
	"missing values",//-7
	"timesteps from config file and from atom file do not match",//-8, unused, now minimum is used
	"isos parameter specified twice",//-9
	"Error reading unit cell parameters", //-10
	"Error reading repetitions",//-11
	"Non-periodic, but repetitions requested", //-12
	"No basis vectors, but repetitions requested", //-13
	"Error loading config file",// -14
102
	"Error reading atomglyph", //-15
103
	"Error reading token", //-16
104 105
	"markers with no previous correct timesteps parameter", //-17
	"markercolours with no previous correct timesteps parameter", //-18
106
	"Error reading atomcolour", // -19
107
	"Error reading newatom", //-20
108
	"Error loading xyz file, add 100 to see the error",//<-100
109 110 111
	"Error loading cube file, add 200 to see the error",//<-200
	"Error loading encyclopedia json file, add 300 to see the error",//<-300
	"Error loading analytics json file, add 400 to see the error",//<-400
112 113 114 115 116 117 118 119 120 121 122 123
};

void updateTIMESTEPS (int timesteps)
{
if (TIMESTEPS==0)
	TIMESTEPS=timesteps;
else
	TIMESTEPS=std::min(TIMESTEPS, timesteps);
}

int readString(FILE *f, char *s)
{
124
	char s2[2048];
125
	int r, c;
126
	r = fscanf(f, "%2047s", s2);
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	if (r!=1)
		return -1;
	if (s2[0]!='"') {
		strcpy(s, s2);
		return 0;
	} else {
		strcpy(s, s2+1); //skip "
		size_t l = strlen(s);
		if (s[l-1] == '"') {
			s[l-1] = '\0';
			return 0;
		}
		else {
			char *p = s2;
			do {
				c = fgetc(f);
				*p++ = c;
			} while (c != EOF && c != '"');
			*(p-1) = '\0';
			strcat(s, s2);
		}
	}
	return 0;
}

void fixFile(char * file)
{
#ifdef WIN32
	const char c='\\';
#else
	const char c='/';
#endif
while (*file!='\0') {
	if (*file=='/' || *file=='\\')
		*file=c;
	file++;
}
}

166
void initState()
167
{
168
	BACKGROUND[0] = 0.95f;
169 170 171 172 173 174 175 176 177
	BACKGROUND[1] = 0.95f;
	BACKGROUND[2] = 0.95f;
	SCREENSHOT="C:\\temp\\frame";
	ISOS = 0;
	TIMESTEPS=0;
	PATH=strdup("");
	numAtoms=0;
	atomScaling=1;
	clonedAtoms=0;
178
	fixedAtoms=false;
179
	bonds.clear();
180
	displaybonds=false;
181 182 183
	showTrajectories = false;
	basisvectorreps=0;
	numClonedAtoms=0;
184
	has_abc=false;
185 186 187 188
	for (int i=0;i<3;i++)
		repetitions[i]=1;
	for (int i=0;i<3;i++)
		userpos[i] = 0;
189 190
	for (int i=0;i<3;i++)
		supercell[i] = 1;
191
	solid=0;
192

193 194 195 196 197 198 199 200 201 202
	markers=nullptr;
	markercolours=nullptr;
	displayunitcell=false;
	scaling =1;
	markerscaling=0.8;
	for (int i=0;i<3;i++)
		cubetrans[i]=0;
	translations=nullptr;
	for (int i=0;i<3;i++)
		voxelSize[i]=-1;
203 204
	saveStereo=false;
	screenshotdownscaling=1;
205
	hapticFeedback=false;
206
	showcontrollers=false;
207
	gazenavigation=false;
208
	inv_abc_init=false;
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

	transparencyquality=12;
	nearclip=0.2f;
	farclip=200.f;

	for (int i=0;i<4;i++)
		unitcellcolour[i]=1.0f;
	
	supercellcolour[0]=0.0f;
	supercellcolour[1]=1.0f;
	supercellcolour[2]=1.0f;
	supercellcolour[3]=1.0f;

	bondscolours[0]=0.5f;
	bondscolours[1]=0.5f;
	bondscolours[2]=1.0f;
	bondscolours[3]=1.0f;

	atomtrajectorycolour[0]=1.0f;
	atomtrajectorycolour[1]=0.0f;
	atomtrajectorycolour[2]=0.0f;
	atomtrajectorycolour[3]=1.0f;
231 232 233

	animationspeed=1.0f;
	movementspeed=1.0f;
234 235 236 237 238

	infolinecolour[0] = 1.0f;
	infolinecolour[1] = 1.0f;
	infolinecolour[2] = 0.0f;
	infolinecolour[3] = 1.0f;
239 240 241 242

	menubutton = Record;

	bondscaling = 0.7f;
243 244 245 246 247 248 249 250 251 252 253 254
}

int loadConfigFile(const char * f)
{
	//default values
	//eprintf ("load config file start");
	bool nonperiodic=false;
	char base_url[1024]="http://enc-testing-nomad.esc.rzg.mpg.de/v1.0/materials/";
	char material[1024]="";
	initState();
	char *token=0;

255 256 257 258
	FILE *F = fopen(f, "r");
	if (F == 0)
	{
		eprintf( "Could not open config file %s\n", f);
259
		eprintf("Error: %d", errno);
260 261 262 263 264 265 266 267
		return -1;
	}
	char s[100];
	int r;
	while (!feof(F)) {
		r=fscanf(F, "%99s", s);
		if (r <= 0)
			continue;
268 269
		if ((unsigned char)s[0]==0xef && (unsigned char)s[1]==0xbb && (unsigned char)s[2]==0xbf) //utf bom
			strcpy (s, s+3);
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
		if (s[0] == '#') {//comment
			discardline(F);
			continue;
		}
		if (!strcmp(s, "timesteps")) {
			int timesteps;
			r = fscanf(F, "%d", &timesteps);
			if (TIMESTEPS==0)
				TIMESTEPS=timesteps;
			else
				TIMESTEPS=std::min(TIMESTEPS, timesteps);
		}
		else if (!strcmp(s, "isos")) {
			if (ISOS!=0) 
				return -9;
			r = fscanf(F, "%d", &ISOS);
			plyfiles = new const char*[ISOS];
			isocolours = new float*[ISOS];
			translations = new float*[ISOS];
			for (int i = 0; i < ISOS; i++) {
				plyfiles[i] = strdup("");
				isocolours[i] = new float[4];
				translations[i] = new float[3];
				//default values
				for (int j = 0; j < 4; j++)
					isocolours[i][j] = 1.f;
				for (int j = 0; j < 3; j++)
					translations[i][j] = 0.f;
			}
		}
		else if (!strcmp(s, "values")) {
			if (ISOS == 0) {
				eprintf( "values with no previous correct isos parameter\n");
				fclose(F);
				return -3;
			}
			for (int i = 0; i < ISOS; i++) {
				r=readString(F, s);
				if (r!=0)
					return -14;
				free ((void*)(plyfiles[i]));
				plyfiles[i] = strdup(s);
			}

		}
		else if (!strcmp(s, "colours")) {
			if (ISOS == 0) {
				eprintf( "colours with no previous correct isos parameter\n");
				return -4;
			}
			for (int i = 0; i < ISOS; i++) {
				for (int j = 0; j < 4; j++)
					r = fscanf(F, "%f", &(isocolours[i][j]));
				//if (r==0)
			}
		}
		else if (!strcmp(s, "path")) {
			r=readString(F, s);
			if (r!=0)
				return -14;			
			free((void*)PATH);
			PATH = strdup(s);
		}
		else if (!strcmp(s, "background")) {
			for (int i = 0; i < 3; i++)
				r = fscanf(F, "%f", BACKGROUND + i);
		}
		else if (!strcmp(s, "translations")) {
			if (ISOS == 0) {
				eprintf( "translations with no previous correct isos parameter\n");
				fclose(F);
				return -5;
			}
			for (int i=0;i<ISOS;i++)
				for (int j = 0; j < 3; j++) {
					r = fscanf(F, "%f", &(translations[i][j]));
				}
		}
		else if (!strcmp(s, "userpos")) {
			for (int j = 0; j < 3; j++) {
				r = fscanf(F, "%f", &(userpos[j]));
			}
		}
		else if (!strcmp(s, "screenshot")) {
			r=readString(F, s);
			if (r!=0)
				return -14;
			SCREENSHOT = strdup(s);
		}
		else if (!strcmp(s, "xyzfile")||!strcmp(s, "atomfile")) {
			r=readString(F, s);
			if (r!=0)
				return -14;
			int timesteps;
			char file[256];
			sprintf (file, "%s%s", PATH, s);
			fixFile(file);
			int e;
			e=readAtomsXYZ(file, &numAtoms, &timesteps, &atoms);
			if (e<0)
				return e-100;
			updateTIMESTEPS (timesteps);
372
			//eprintf ("After read of xyzfile, numatoms 0 =%d", numAtoms[0]);
373 374 375 376 377
		}
		else if (!strcmp(s, "cubefile")) {
			r=readString(F, s);
			if (r!=0)
				return -14;
378
			int timesteps=TIMESTEPS;
379 380 381 382 383 384 385 386 387 388 389 390 391
			char file[256];
			sprintf(file, "%s%s", PATH, s);
			fixFile(file);
			int e;
			e = readAtomsCube(file, &numAtoms, &timesteps, &atoms);
			if (e<0)
				return e - 200;
			updateTIMESTEPS (timesteps);
			//	return -8;
		}
		else if (!strcmp(s, "atomscaling")) {
			r = fscanf(F, "%f", &atomScaling);
		}
392 393 394
		else if (!strcmp(s, "scaling")) {
			r = fscanf(F, "%f", &scaling);
		}
395 396 397 398 399 400 401 402 403
		else if (!strcmp(s, "abc")) {
			for (int i=0;i<3;i++)
				for (int j=0;j<3;j++) {
					r = fscanf(F, "%f", &(abc[i][j]));
					if (r!=1)
						return -10;
				}
			has_abc = true;
		}
404
		else if (!strcmp(s, "json") || !strcmp (s, "encyclopediajson")) {
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
			r=readString(F, s);
			if (r!=0)
				return -14;
			char file[256];
			sprintf(file, "%s%s", PATH, s);
			fixFile(file);
			int e;
			int timesteps;
			//rgh fixme, we know only one
			e = readAtomsJson (file, &numAtoms, &timesteps, &atoms, abc, &clonedAtoms);
			if (e<0)
				return e-300;
			numClonedAtoms=clonedAtoms[0].size()/4;
			has_abc=true;
			updateTIMESTEPS (timesteps);
420 421 422 423 424 425 426 427 428 429 430 431 432 433
		}
		else if (!strcmp(s, "analyticsjson")) {
			r = readString(F, s);
			if (r != 0)
				return -14;
			char file[256];
			sprintf(file, "%s%s", PATH, s);
			fixFile(file);
			int e;
			int timesteps;
			//rgh fixme, we know only one
			e = readAtomsAnalyticsJson(file, &numAtoms, &timesteps, &atoms, abc, &clonedAtoms);
			if (e<0)
				return e - 400;
434 435 436 437 438 439

			if (has_abc)
				numClonedAtoms = clonedAtoms[0].size() / 4;
			else
				numClonedAtoms=0;

440 441
			updateTIMESTEPS(timesteps);
		}
442 443 444 445 446 447 448 449 450 451 452 453 454 455
		else if (!strcmp(s, "baseurl")) {
			r=readString (F, base_url);
			if (r!=0)
				return -14;
		} 
		else if (!strcmp(s, "jsonurl")) {
			int e;
			int timesteps;
			r=readString (F, material);
			if (r!=0)
				return -14;
			char url[2048];
			sprintf (url, "%s%s", base_url, material);
			//rgh fixme, we know only one
456
			//eprintf ("load config file start, before readAtomsJsonURL");
457
			e = readAtomsJsonURL (url, &numAtoms, &timesteps, &atoms, abc, &clonedAtoms, token);
458
			//eprintf ("load config file start, after readAtomsJsonURL");
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
			if (e<0)
				return e-300;
			numClonedAtoms=clonedAtoms[0].size()/4;
			has_abc=true;
			updateTIMESTEPS (timesteps);
		}
		else if (!strcmp(s, "showtrajectory")) {
			showTrajectories = true;
			int atom;
			while (1 == (r = fscanf(F, "%d", &atom))) {
				atomtrajectories.push_back(atom - 1);
			}
			if (atomtrajectories.size() == 0) //empty showtrajectory
				showTrajectories = false;
		} else if (!strcmp(s, "nonperiodic")) {
			nonperiodic=true;
		} else if (!strcmp(s, "repetitions")) {
			for (int j=0;j<3;j++) {
					r = fscanf(F, "%d", repetitions+j);
					if (r!=1)
						return -11;
			}
481 482 483 484 485 486 487 488 489 490
		} else if (!strcmp(s, "atomglyph")) {
			r=fscanf (F, "%s", s);
			if (r==0)
				return -15;
			if (!strcmp(s, "icosahedron"))
				solid=new Solid(Solid::Type::Icosahedron);
			else if(!strcmp(s, "octahedron"))
				solid=new Solid(Solid::Type::Octahedron);
			else if(!strcmp(s, "tetrahedron"))
				solid=new Solid(Solid::Type::Tetrahedron);
491 492 493 494 495
			else if(!strcmp(s, "sphere")) {
				int subd;
				r=fscanf (F, "%d", &subd);
				solid=new Solid(Solid::Type::Sphere, subd);
			}
496 497
			else
				return -15;
498 499 500 501 502 503 504
		} else if (!strcmp (s, "token")) {
			if (token)
				delete (token);
			token=new char [2048];
			r=readString (F, token);
			if (r!=0)
				return -16;
505 506
		} else if (!strcmp (s, "fixedatoms")) {
			fixedAtoms=true;
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
		} else if (!strcmp (s, "markers")) {
			if (TIMESTEPS == 0) {
				eprintf( "markers with no previous correct timesteps parameter\n");
				fclose(F);
				return -17;
			}
			markers=new float* [TIMESTEPS];
			for (int i=0;i<TIMESTEPS;i++) {
				markers[i]=new float[3];
				//in abc coordinates if they exist
				float tmp[3];
				for (int j = 0; j < 3; j++) {
					r = fscanf(F, "%f", &(tmp[j]));
				}
				if (has_abc) {
					//for (int s=0;s<3;s++) 
					//	tmp[s]-=translations[0][s]; //using translation of iso 0
					//check if coordinates are outside of cell
525 526 527 528 529
					if (translations) {
						for (int s=0;s<3;s++) {
							while (tmp[s]<-translations[0][s])
								tmp[s]+=supercell[2-s];
						}
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
					}
					for (int s=0;s<3;s++) {
						markers[i][s]=tmp[2]*abc[0][s]+tmp[1]*abc[1][s]+tmp[0]*abc[2][s]; //hole positions seem to be in zyx
					}
				}
				else
					for (int s=0;s<3;s++)
						markers[i][s]=tmp[s];

			}
		} else if (!strcmp (s, "markercolours")) {
		if (TIMESTEPS == 0) {
			eprintf( "markecolours with no previous correct timesteps parameter\n");
			fclose(F);
			return -18;
		}
		markercolours=new float* [TIMESTEPS];
		for (int i=0;i<TIMESTEPS;i++) {
			markercolours[i]=new float[4];
			for (int j = 0; j < 4; j++) {
				r = fscanf(F, "%f", &(markercolours[i][j]));
			}
		}
		} else if (!strcmp (s, "displaybonds")) {
			displaybonds=true;
555 556 557
		} else if (!strcmp (s, "atomcolour")) {
			char atom [100];
			float rgb[3];
558
			r = fscanf(F, "%s %f %f %f", atom, rgb, rgb + 1, rgb + 2);
559 560 561 562 563 564 565 566 567 568 569
			if (r!=4) {
				eprintf ("Error loading atom colour");
				return -19;
			}
			int a=findAtom(atom);
			if (a==-1) {
				eprintf ("atomcolour, unknown atom type %s", atom);
				return -19;
			}
			for (int i=0;i<3;i++)
				atomColours[a][i]=rgb[i];
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
		} else if (!strcmp (s, "newatom")) {
			char atom [100];
			float rgb[3];
			float size;
			r = fscanf(F, "%s %f %f %f %f", atom, rgb, rgb + 1, rgb + 2, &size);
			if (r!=5) {
				eprintf ("Error loading newatom");
				return -20;
			}
			int a=findAtom(atom);
			if (a!=-1) {
				if (a<atomsInPeriodicTable) {
					for (int i=0;i<3;i++)
						atomColours[a][i]=rgb[i];
					atomColours[a][3]=size;
				} else {
					for (int i=0;i<3;i++)
						extraAtomData[a-atomsInPeriodicTable][i]=rgb[i];
					extraAtomData[a-atomsInPeriodicTable][3]=size;
				}
			} else { //new
				extraAtomNames.push_back(strdup(atom));
				extraAtomData.push_back(new float[4]);
				float *e=extraAtomData.back();
				for (int i=0;i<3;i++)
					e[i]=rgb[i];
				e[3]=size;
			}
598 599 600 601
		} else if (!strcmp (s, "markerscaling")) {
			r = fscanf(F, "%f", &markerscaling);
		} else if (!strcmp (s, "displayunitcell")) {
			displayunitcell=true;
602 603 604 605 606 607
		} else if (!strcmp (s, "stereoscreenshot")) {
			saveStereo=true;
		} else if (!strcmp (s, "screenshotdownscaling")) {
			r= fscanf(F, "%d", &screenshotdownscaling);
			if (r<1)
				eprintf ("Error reading screenshotdownscaling value");
608 609
		} else if (!strcmp (s, "hapticfeedback")) {
			hapticFeedback=true;
610 611
		} else if (!strcmp (s, "supercell")) {
			r=fscanf (F, "%f %f %f", supercell, supercell+1, supercell+2);
612 613
			if (r<3)
				eprintf ("Error reading supercell value");
614 615
		} else if (!strcmp (s, "showcontrollers")) { 
			showcontrollers=true;
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
		} else if (!strcmp (s, "gazenavigation")) { 
			gazenavigation=true;
		} else if (!strcmp (s, "transparencyquality")) {
			r=fscanf (F, "%d", &transparencyquality);
			if (r<1)
				eprintf ("Error reading transparencyquality value");
		} else if (!strcmp (s, "clippingplanes")) {
			r=fscanf (F, "%f %f", &nearclip, &farclip);
			if (r<2)
				eprintf ("Error reading clippingplanes values");
		}else if (!strcmp (s, "bondscolour")) {
			r=fscanf (F, "%f %f %f", bondscolours, bondscolours+1, bondscolours+2);
			if (r<3)
				eprintf ("Error reading bondscolour value");
		}else if (!strcmp (s, "unitcellcolour")) {
			r=fscanf (F, "%f %f %f", unitcellcolour, unitcellcolour+1, unitcellcolour+2);
			if (r<3)
				eprintf ("Error reading unitcellcolour value");
		}else if (!strcmp (s, "supercellcolour")) {
			r=fscanf (F, "%f %f %f", supercellcolour, supercellcolour+1, supercellcolour+2);
			if (r<3)
				eprintf ("Error reading supercellcolour value");
		}else if (!strcmp (s, "atomtrajectorycolour")) {
			r=fscanf (F, "%f %f %f", atomtrajectorycolour, atomtrajectorycolour+1, atomtrajectorycolour+2);
			if (r<3)
				eprintf ("Error reading atomtrajectorycolour value");
642 643 644 645
		}else if (!strcmp (s, "infolinecolour")) {
			r=fscanf (F, "%f %f %f", infolinecolour, infolinecolour+1, infolinecolour+2);
			if (r<3)
				eprintf ("Error reading atomtrajectorycolour value");
646 647 648 649 650 651 652 653
		}
		else if (!strcmp(s, "animationspeed")) {
			r = fscanf(F, "%f", &animationspeed);
			if (r < 1)
				eprintf("Error reading animationspeed");
		}
		else if (!strcmp(s, "")) {
			r = fscanf(F, "%f", &bondscaling);
654
			if (r<1)
655 656 657 658 659 660 661 662 663 664
				eprintf("Error reading bondscaling");
			bondscaling = sqrt(bondscaling);
		} else if (!strcmp(s, "menubutton")) {
			r = fscanf(F, "%s", s);
			if (!strcmp(s, "Record"))
				menubutton = Record;
			else if (!strcmp(s, "Infobox"))
				menubutton = Infobox;
			else if (!strcmp (s, "Nothing"))
				menubutton = Nothing;
665 666 667 668
		} else if (!strcmp (s, "movementspeed")) {
			r=fscanf (F, "%f", &movementspeed);
			if (r<1)
				eprintf ("Error reading movementspeed");
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
#ifdef WIN32
		} else if (!strcmp (s, "info")) {
			information i;
			r=fscanf (F, "%f %f %f %f %d", i.pos, i.pos+1, i.pos+2, &(i.size), &(i.atom));
			if (r<5)
				eprintf ("Error reading info");
			r=readString(F, s);
			if (r!=0)
				eprintf ("Error reading info");
			char file[256];
			sprintf (file, "%s%s", PATH, s);
			i.filename=strdup(file);
			//i.tex=LoadPNG(i.filename); //opengl not initialized yet
			info.push_back(i);
#endif
684 685 686
		} else if (!strcmp (s, "\x0d")) { //discard windows newline (problem in Sebastian Kokott's phone (?!)
			continue;
		} else {
687
			eprintf( "Unrecognized parameter %s\n", s);
688 689
			for (int i=0;i<strlen(s);i++)
				eprintf ("<%d>", s[i]);
690 691 692 693 694 695 696 697
			fclose(F);
			return -2;
		}
	}

//verification and additional processing
	fclose(F);

698
	/*if (ISOS == 0 && numAtoms==0) {
699 700
		eprintf( "Missing isos and atomfile parameter\n");
		return -6;
701
	} */
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
	if (ISOS !=0 && plyfiles[0] == 0) {
		eprintf( "Missing values parameter\n");
		fclose(F);
		return -7;
	}
	if (nonperiodic) {
		numClonedAtoms=0;
		if (repetitions[0]!=1 ||repetitions[1]!=1 ||repetitions[2]!=1)
			return -12;
	}
	if (repetitions[0]!=1 ||repetitions[1]!=1 ||repetitions[2]!=1) {
		if (!has_abc)
			return (-13);
		numClonedAtoms=0;
	}

	if (showTrajectories && atomtrajectories[0]<0) {
		atomtrajectories.clear();
		for (int i=0;i<*numAtoms;i++)
			atomtrajectories.push_back(i);
	}
723 724 725 726 727

	//chemical bonds
	//if (numAtoms) {
	//}

728
	//eprintf ("Before returning, numatoms 0 =%d", numAtoms[0]);
729
	return 0;
730
}