Difference for plugins/molfile_plugin/src/jsplugin.c from version 1.5 to 1.6

version 1.5version 1.6
Line 1
Line 1
 /*************************************************************************** /***************************************************************************
  *cr                                                                         *cr                                                                       
  *cr            (C) Copyright 1995-2009 The Board of Trustees of the             *cr            (C) Copyright 1995-2016 The Board of Trustees of the           
  *cr                        University of Illinois                         *cr                        University of Illinois                       
  *cr                         All Rights Reserved                          *cr                         All Rights Reserved                        
  *cr                                                                     *cr                                                                   
Line 11
Line 11
  *  *
  *      $RCSfile: jsplugin.c,v $  *      $RCSfile: jsplugin.c,v $
  *      $Author: jim $       $Locker:  $             $State: Exp $  *      $Author: jim $       $Locker:  $             $State: Exp $
  *      $Revision: 1.5 $       $Date: 2013/09/30 22:02:44 $  *      $Revision: 1.6 $       $Date: 2017/03/29 21:38:15 $
  *  *
  ***************************************************************************  ***************************************************************************
  * DESCRIPTION:  * DESCRIPTION:
Line 64
Line 64
  *  *
  ***************************************************************************/  ***************************************************************************/
  
 #if 1 
 #define INFOMSGS  1 #define INFOMSGS  1
 #endif 
  
 #if 1 #if 1
 #define ENABLEJSSHORTREADS 1 #define ENABLEJSSHORTREADS 1
Line 120
Line 118
 #define JSENDIANISM      0x12345678 #define JSENDIANISM      0x12345678
  
 #define JSMAJORVERSION   2 #define JSMAJORVERSION   2
 #define JSMINORVERSION   12 #define JSMINORVERSION   15
  
 #define JSNFRAMESOFFSET  (strlen(JSHEADERSTRING) + 20) #define JSNFRAMESOFFSET  (strlen(JSHEADERSTRING) + 20)
  
Line 129
Line 127
 #define JSBADFORMAT         2 #define JSBADFORMAT         2
  
  
  /* Threshold atom count beyond which block-based I/O is used by default */
  /* The overhead from block-alignment padding bytes becomes essentially  */
  /* inconsequential (< 1%) for structures with more than 50,000 atoms.   */
  #define JSBLOCKIO_THRESH    50000
  
  
  /* Option flag macros and their meanings */
 #define JSOPT_NOOPTIONS     0x00000000  /* no structure, only coords    */ #define JSOPT_NOOPTIONS     0x00000000  /* no structure, only coords    */
  
 /* Timesteps are block-size padded and page- or sector-aligned for      */ /* Timesteps are block-size padded and page- or sector-aligned for      */
Line 206
Line 211
 } jshandle; } jshandle;
  
  
  /* Use block-based I/O by default when writing structures larger */
  /* than JSBLOCKIO_THRESH atoms, or when directed by the user and */
  /* not otherwise prohibited...                                   */
  static void js_blockio_check_and_set(jshandle *js) {
    if ((getenv("VMDJSNOBLOCKIO") == NULL) && 
        ((js->natoms > JSBLOCKIO_THRESH) || getenv("VMDJSBLOCKIO"))) {
      js->optflags |= JSOPT_TS_BLOCKIO;
      js->directio_block_size = MOLFILE_DIRECTIO_MIN_BLOCK_SIZE; 
    }
  }
  
  
 static void *open_js_read(const char *path, const char *filetype, int *natoms) { static void *open_js_read(const char *path, const char *filetype, int *natoms) {
   jshandle *js;   jshandle *js;
   int jsmagicnumber, jsendianism, jsmajorversion, jsminorversion;   int jsmagicnumber, jsendianism, jsmajorversion, jsminorversion;
Line 497
Line 514
     /* skip forward to first TS if the caller gives us NULL ptrs */     /* skip forward to first TS if the caller gives us NULL ptrs */
     if (optflags == NULL && atoms == NULL) {     if (optflags == NULL && atoms == NULL) {
       size_t offset=0;       size_t offset=0;
       offset += numatomnames * (16 * sizeof(char));       offset += numatomnames * (16L * sizeof(char));
       offset += numatomtypes * (16 * sizeof(char));       offset += numatomtypes * (16L * sizeof(char));
       offset += numresnames  * (8 * sizeof(char));       offset += numresnames  * (8L * sizeof(char));
       offset += numsegids    * (8 * sizeof(char));       offset += numsegids    * (8L * sizeof(char));
       offset += numchains    * (2 * sizeof(char));       offset += numchains    * (2L * sizeof(char));
       offset += js->natoms * sizeof(short); /* atom name indices    */       offset += js->natoms * sizeof(short); /* atom name indices    */
       offset += js->natoms * sizeof(short); /* atom type indices    */       offset += js->natoms * sizeof(short); /* atom type indices    */
       offset += js->natoms * sizeof(short); /* residue name indices */       offset += js->natoms * sizeof(short); /* residue name indices */
Line 537
Line 554
         }         }
 #endif #endif
  
         offset += 2 * js->nbonds * sizeof(int);         offset += 2L * js->nbonds * sizeof(int);
         if (js->optflags & JSOPT_BONDORDERS)         if (js->optflags & JSOPT_BONDORDERS)
           offset += js->nbonds * sizeof(float);           offset += js->nbonds * sizeof(float);
  
Line 608
Line 625
  
     /* read in the string tables */     /* read in the string tables */
     for (i=0; i<numatomnames; i++) {     for (i=0; i<numatomnames; i++) {
       atomnames[i] = (char *) malloc(16 * sizeof(char));       atomnames[i] = (char *) malloc(16L * sizeof(char));
       fio_fread(atomnames[i], 16 * sizeof(char), 1, js->fd);       fio_fread(atomnames[i], 16L * sizeof(char), 1, js->fd);
     }     }
  
 #if defined(INFOMSGS) #if defined(INFOMSGS)
Line 617
Line 634
       printf("jsplugin)   atom types...\n");       printf("jsplugin)   atom types...\n");
 #endif #endif
     for (i=0; i<numatomtypes; i++) {     for (i=0; i<numatomtypes; i++) {
       atomtypes[i] = (char *) malloc(16 * sizeof(char));       atomtypes[i] = (char *) malloc(16L * sizeof(char));
       fio_fread(atomtypes[i], 16 * sizeof(char), 1, js->fd);       fio_fread(atomtypes[i], 16L * sizeof(char), 1, js->fd);
     }     }
  
 #if defined(INFOMSGS) #if defined(INFOMSGS)
Line 626
Line 643
       printf("jsplugin)   residue names...\n");       printf("jsplugin)   residue names...\n");
 #endif #endif
     for (i=0; i<numresnames; i++) {     for (i=0; i<numresnames; i++) {
       resnames[i] = (char *) malloc(8 * sizeof(char));       resnames[i] = (char *) malloc(8L * sizeof(char));
       fio_fread(resnames[i], 8 * sizeof(char), 1, js->fd);       fio_fread(resnames[i], 8L * sizeof(char), 1, js->fd);
     }     }
  
 #if defined(INFOMSGS) #if defined(INFOMSGS)
Line 635
Line 652
       printf("jsplugin)   segment names...\n");       printf("jsplugin)   segment names...\n");
 #endif #endif
     for (i=0; i<numsegids; i++) {     for (i=0; i<numsegids; i++) {
       segids[i] = (char *) malloc(8 * sizeof(char));       segids[i] = (char *) malloc(8L * sizeof(char));
       fio_fread(segids[i], 8 * sizeof(char), 1, js->fd);       fio_fread(segids[i], 8L * sizeof(char), 1, js->fd);
     }     }
  
 #if defined(INFOMSGS) #if defined(INFOMSGS)
Line 644
Line 661
       printf("jsplugin)   chain names...\n");       printf("jsplugin)   chain names...\n");
 #endif #endif
     for (i=0; i<numchains; i++) {     for (i=0; i<numchains; i++) {
       chains[i] = (char *) malloc(2 * sizeof(char));       chains[i] = (char *) malloc(2L * sizeof(char));
       fio_fread(chains[i], 2 * sizeof(char), 1, js->fd);       fio_fread(chains[i], 2L * sizeof(char), 1, js->fd);
     }     }
  
 #if defined(INFOMSGS) #if defined(INFOMSGS)
Line 1334
Line 1351
   jshandle *js = (jshandle *) mydata;   jshandle *js = (jshandle *) mydata;
   long i;   long i;
  
 #if 1   /* use block-based I/O by default when writing structures larger */
   if (getenv("VMDJSBLOCKIO")) {   /* than JSBLOCKIO_THRESH atoms, or when directed by the user     */
     js->optflags |= JSOPT_TS_BLOCKIO;   js_blockio_check_and_set(js);
     js->directio_block_size = MOLFILE_DIRECTIO_MIN_BLOCK_SIZE;  
   } 
 #endif 
  
   js->optflags |= JSOPT_STRUCTURE;   js->optflags |= JSOPT_STRUCTURE;
  
Line 1455
Line 1469
     for (hashcnt=0,i=0; i<js->natoms; i++) {     for (hashcnt=0,i=0; i<js->natoms; i++) {
       /* add a new string table entry for hash inserts that don't yet exist */       /* add a new string table entry for hash inserts that don't yet exist */
       if (hash_insert(&atomnamehash, atoms[i].name, hashcnt) == HASH_FAIL) {       if (hash_insert(&atomnamehash, atoms[i].name, hashcnt) == HASH_FAIL) {
         atomnames[hashcnt] = (char *) calloc(1, 16 * sizeof(char));         atomnames[hashcnt] = (char *) calloc(1, 16L * sizeof(char));
         strcpy(atomnames[hashcnt], atoms[i].name);         strcpy(atomnames[hashcnt], atoms[i].name);
         hashcnt++;         hashcnt++;
       }       }
     }     }
     for (i=0; i<numatomnames; i++) {     for (i=0; i<numatomnames; i++) {
       fio_fwrite(atomnames[i], 16 * sizeof(char), 1, js->fd);       fio_fwrite(atomnames[i], 16L * sizeof(char), 1, js->fd);
     }     }
  
  
Line 1470
Line 1484
     for (hashcnt=0,i=0; i<js->natoms; i++) {     for (hashcnt=0,i=0; i<js->natoms; i++) {
       /* add a new string table entry for hash inserts that don't yet exist */       /* add a new string table entry for hash inserts that don't yet exist */
       if (hash_insert(&atomtypehash, atoms[i].type, hashcnt) == HASH_FAIL) {       if (hash_insert(&atomtypehash, atoms[i].type, hashcnt) == HASH_FAIL) {
         atomtypes[hashcnt] = (char *) calloc(1, 16 * sizeof(char));         atomtypes[hashcnt] = (char *) calloc(1, 16L * sizeof(char));
         strcpy(atomtypes[hashcnt], atoms[i].type);         strcpy(atomtypes[hashcnt], atoms[i].type);
         hashcnt++;         hashcnt++;
       }       }
     }     }
     for (i=0; i<numatomtypes; i++) {     for (i=0; i<numatomtypes; i++) {
       fio_fwrite(atomtypes[i], 16 * sizeof(char), 1, js->fd);       fio_fwrite(atomtypes[i], 16L * sizeof(char), 1, js->fd);
     }     }
  
  
Line 1485
Line 1499
     for (hashcnt=0,i=0; i<js->natoms; i++) {     for (hashcnt=0,i=0; i<js->natoms; i++) {
       /* add a new string table entry for hash inserts that don't yet exist */       /* add a new string table entry for hash inserts that don't yet exist */
       if (hash_insert(&resnamehash, atoms[i].resname, hashcnt) == HASH_FAIL) {       if (hash_insert(&resnamehash, atoms[i].resname, hashcnt) == HASH_FAIL) {
         resnames[hashcnt] = (char *) calloc(1, 8 * sizeof(char));         resnames[hashcnt] = (char *) calloc(1, 8L * sizeof(char));
         strcpy(resnames[hashcnt], atoms[i].resname);         strcpy(resnames[hashcnt], atoms[i].resname);
         hashcnt++;         hashcnt++;
       }       }
     }     }
     for (i=0; i<numresnames; i++) {     for (i=0; i<numresnames; i++) {
       fio_fwrite(resnames[i], 8 * sizeof(char), 1, js->fd);       fio_fwrite(resnames[i], 8L * sizeof(char), 1, js->fd);
     }     }
  
  
Line 1500
Line 1514
     for (hashcnt=0,i=0; i<js->natoms; i++) {     for (hashcnt=0,i=0; i<js->natoms; i++) {
       /* add a new string table entry for hash inserts that don't yet exist */       /* add a new string table entry for hash inserts that don't yet exist */
       if (hash_insert(&segidhash, atoms[i].segid, hashcnt) == HASH_FAIL) {       if (hash_insert(&segidhash, atoms[i].segid, hashcnt) == HASH_FAIL) {
         segids[hashcnt] = (char *) calloc(1, 8 * sizeof(char));         segids[hashcnt] = (char *) calloc(1, 8L * sizeof(char));
         strcpy(segids[hashcnt], atoms[i].segid);         strcpy(segids[hashcnt], atoms[i].segid);
         hashcnt++;         hashcnt++;
       }       }
     }     }
     for (i=0; i<numsegids; i++) {     for (i=0; i<numsegids; i++) {
       fio_fwrite(segids[i], 8 * sizeof(char), 1, js->fd);       fio_fwrite(segids[i], 8L * sizeof(char), 1, js->fd);
     }     }
  
  
Line 1515
Line 1529
     for (hashcnt=0,i=0; i<js->natoms; i++) {     for (hashcnt=0,i=0; i<js->natoms; i++) {
       /* add a new string table entry for hash inserts that don't yet exist */       /* add a new string table entry for hash inserts that don't yet exist */
       if (hash_insert(&chainhash, atoms[i].chain, hashcnt) == HASH_FAIL) {       if (hash_insert(&chainhash, atoms[i].chain, hashcnt) == HASH_FAIL) {
         chains[hashcnt] = (char *) calloc(1, 2 * sizeof(char));         chains[hashcnt] = (char *) calloc(1, 2L * sizeof(char));
         strcpy(chains[hashcnt], atoms[i].chain);         strcpy(chains[hashcnt], atoms[i].chain);
         hashcnt++;         hashcnt++;
       }       }
     }     }
     for (i=0; i<numchains; i++) {     for (i=0; i<numchains; i++) {
       fio_fwrite(chains[i], 2 * sizeof(char), 1, js->fd);       fio_fwrite(chains[i], 2L * sizeof(char), 1, js->fd);
     }     }
  
  
Line 1719
Line 1733
                           int nbondtypes, char **bondtypename) {                           int nbondtypes, char **bondtypename) {
   jshandle *js = (jshandle *) mydata;   jshandle *js = (jshandle *) mydata;
  
  #if defined(INFOMSGS)
      if (js->verbose) {
        printf("jsplugin) write_js_bonds():\n");
        printf("jsplugin) storing bond info for writing...\n");
        printf("jsplugin) %d %d\n", nbonds, nbondtypes);
      }
  #endif
  
   if (nbonds > 0 && fromptr != NULL && toptr != NULL) {   if (nbonds > 0 && fromptr != NULL && toptr != NULL) {
     js->optflags |= JSOPT_BONDS;      js->optflags |= JSOPT_BONDS; 
  
Line 1757
Line 1779
   js->numimpropers = numimpropers;   js->numimpropers = numimpropers;
   js->numcterms = numcterms;   js->numcterms = numcterms;
  
  #if defined(INFOMSGS)
    if (js->verbose) {
      printf("jsplugin) write_js_angles():\n");
      printf("jsplugin) storing angles/dihedrals/impropers for writing...\n");
      printf("jsplugin) %d %d %d %d\n",
             numangles, numdihedrals, numimpropers, numcterms);
    }
  #endif
  
   if (js->numangles > 0 || js->numdihedrals > 0 || js->numimpropers > 0) {   if (js->numangles > 0 || js->numdihedrals > 0 || js->numimpropers > 0) {
     js->optflags |= JSOPT_ANGLES;     js->optflags |= JSOPT_ANGLES;
  
Line 1824
Line 1855
   /* using direct I/O APIs...                                        */   /* using direct I/O APIs...                                        */
   if (js->directio_ucell_blkbuf == NULL) {   if (js->directio_ucell_blkbuf == NULL) {
     printf("jsplugin) no structure data, writing timesteps only...\n");     printf("jsplugin) no structure data, writing timesteps only...\n");
     if (getenv("VMDJSBLOCKIO")) { 
       js->optflags |= JSOPT_TS_BLOCKIO;     /* use block-based I/O by default when writing structures larger */
       js->directio_block_size = MOLFILE_DIRECTIO_MIN_BLOCK_SIZE;      /* than JSBLOCKIO_THRESH atoms, or when directed by the user     */
     }     js_blockio_check_and_set(js);
  
     /* write flags data to the file */     /* write flags data to the file */
     fio_write_int32(js->fd, js->optflags);      fio_write_int32(js->fd, js->optflags); 


Legend:
Removed in v.1.5 
changed lines
 Added in v.1.6



Made by using version 1.53 of cvs2html