• R/O
  • SSH
  • HTTPS

molby: Commit


Commit MetaInfo

Revision95 (tree)
Time2011-08-03 19:12:54
Authortoshinagata1964

Log Message

Loading GAMESS dat file now can be interrupted by ESC.

Change Summary

Incremental Difference

--- trunk/MolLib/Molecule.c (revision 94)
+++ trunk/MolLib/Molecule.c (revision 95)
@@ -481,6 +481,22 @@
481481 return atomicNumber;
482482 }
483483
484+static int
485+sReadLineWithInterrupt(char *buf, int size, FILE *stream, int *lineNumber)
486+{
487+ static int lastLineNumber = 0;
488+ if (lineNumber != NULL) {
489+ if (*lineNumber == 0)
490+ lastLineNumber = 0;
491+ else if (*lineNumber >= lastLineNumber + 1000) {
492+ if (MyAppCallback_checkInterrupt() != 0)
493+ return -1; /* User interrupt */
494+ lastLineNumber = *lineNumber;
495+ }
496+ }
497+ return ReadLine(buf, size, stream, lineNumber);
498+}
499+
484500 int
485501 MoleculeLoadFile(Molecule *mp, const char *fname, const char *ftype, char *errbuf, int errbufsize)
486502 {
@@ -2473,7 +2489,7 @@
24732489 char sval[16];
24742490 Vector *vbuf = NULL;
24752491 IntGroup *ig;
2476- int optimizing = 0;
2492+ int optimizing = 0, status = 0;
24772493
24782494 if (errbuf == NULL) {
24792495 errbuf = buf;
@@ -2500,7 +2516,7 @@
25002516 }
25012517
25022518 lineNumber = 0;
2503- while (ReadLine(buf, sizeof buf, fp, &lineNumber) > 0) {
2519+ while ((status = sReadLineWithInterrupt(buf, sizeof buf, fp, &lineNumber)) > 0) {
25042520 redo:
25052521 n1 = 0;
25062522 if (strncmp(buf, " $DATA", 6) == 0) {
@@ -2511,7 +2527,7 @@
25112527 i = 0;
25122528 ReadLine(buf, sizeof buf, fp, &lineNumber); /* Title */
25132529 ReadLine(buf, sizeof buf, fp, &lineNumber); /* Symmetry */
2514- while (ReadLine(buf, sizeof buf, fp, &lineNumber) > 0) {
2530+ while ((status = sReadLineWithInterrupt(buf, sizeof buf, fp, &lineNumber)) > 0) {
25152531 if (strncmp(buf, " $END", 5) == 0)
25162532 break;
25172533 if (sscanf(buf, "%12s %lf %lf %lf %lf", sval, &dval[0], &dval[1], &dval[2], &dval[3]) < 5) {
@@ -2545,7 +2561,7 @@
25452561 vbuf[i].z = dval[3];
25462562 }
25472563 /* Skip until a blank line is found */
2548- while (ReadLine(buf, sizeof buf, fp, &lineNumber) > 0) {
2564+ while ((status = sReadLineWithInterrupt(buf, sizeof buf, fp, &lineNumber)) > 0) {
25492565 for (j = 0; buf[j] == ' '; j++);
25502566 if (buf[j] == '\n')
25512567 break;
@@ -2567,6 +2583,8 @@
25672583 if (vbuf == NULL)
25682584 vbuf = (Vector *)calloc(sizeof(Vector), natoms);
25692585 nframes = MoleculeGetNumberOfFrames(mol);
2586+ if (status < 0)
2587+ break;
25702588 continue;
25712589 } else if (strstr(buf, "DATA FROM NSERCH") != NULL || (strstr(buf, "RESULTS FROM SUCCESSFUL") != NULL && (n1 = 1))) {
25722590 /* Skip until the separator line is read (three or four lines) */
@@ -2621,7 +2639,7 @@
26212639 return 9;
26222640 }
26232641 i = k = 0;
2624- while ((n1 = ReadLine(buf, sizeof buf, fp, &lineNumber)) > 0) {
2642+ while ((status = sReadLineWithInterrupt(buf, sizeof buf, fp, &lineNumber)) > 0) {
26252643 len = strlen(buf);
26262644 if (strncmp(buf, " $END", 5) == 0)
26272645 break;
@@ -2644,12 +2662,12 @@
26442662 i++;
26452663 k = 0;
26462664 }
2647- if (n1 < 0)
2665+ if (status < 0)
26482666 break;
26492667 continue;
26502668 } else if ((strstr(buf, "ELECTRIC POTENTIAL") != NULL || strstr(buf, "ELECTROSTATIC POTENTIAL") != NULL) && strstr(buf, "ELPOTT") != NULL) {
26512669 i = 0;
2652- while ((n1 = ReadLine(buf, sizeof buf, fp, &lineNumber)) > 0) {
2670+ while ((status = sReadLineWithInterrupt(buf, sizeof buf, fp, &lineNumber)) > 0) {
26532671 Elpot *ep;
26542672 if (strstr(buf, "TOTAL NUMBER OF GRID POINTS") != NULL)
26552673 continue;
@@ -2662,11 +2680,15 @@
26622680 ep->esp = dval[3];
26632681 i++;
26642682 }
2665- if (n1 > 0)
2683+ if (status > 0)
26662684 goto redo; /* This section has no end line, so the last line should be processed again */
2667- else break; /* End of file encountered */
2685+ else break; /* End of file encountered or interrupted */
26682686 } /* TODO: read MOLPLT info if present */
26692687 }
2688+ if (status < 0) {
2689+ snprintf(errbuf, errbufsize, "User interrupt at line %d", lineNumber);
2690+ return 11;
2691+ }
26702692 if (vbuf != NULL)
26712693 free(vbuf);
26722694 if (newmol && mol->nbonds == 0) {
--- trunk/MolLib/Molecule.h (revision 94)
+++ trunk/MolLib/Molecule.h (revision 95)
@@ -502,6 +502,9 @@
502502 STUB void MoleculeCallback_unlockMutex(void *mutex);
503503 STUB void MoleculeCallback_cannotModifyMoleculeDuringMDError(Molecule *mol);
504504
505+/* This is also defined in Molby_extern.h, but it may be called from functions in Molecule.c */
506+STUB int MyAppCallback_checkInterrupt(void);
507+
505508 void MoleculeLock(Molecule *mol);
506509 void MoleculeUnlock(Molecule *mol);
507510
Show on old repository browser