next up previous contents
Next: The Binary Input/Output System Up: The Input Parser Previous: Syntax   Contents

Sample Use from cscf

These are two slightly simplified pieces of actual code.

From cscf.c:

#include <libipv1/ip_lib.h>

   ffile(&infile,"input.dat",2);     /* input and output files. */
   ffile(&outfile,"output.dat",1);   /* call them whatever you want. */

   ip_set_uppercase(1);              /* case sensitivity selection */
   ip_initialize(infile,outfile);    /* reads input.dat and stores it all */

   ip_cwk_add(":DEFAULT");           /* adds default section */
   ip_cwk_add(":SCF");               /* adds scf section */

   ip_string("OUTPUT",&output,0);    /* bet you didn't know you could */
   if(!strcmp(output,"TERMINAL")) {  /* have cscf write to stdout!    */
     outfile = stdout;
     }
   else if(!strcmp(output,"WRITE")) {
     fclose(outfile);
     ffile(&outfile,"output.dat",0);
     }

From scf_input.c:

   errcod = ip_string("LABEL",&alabel,0);
   if(errcod == IPE_OK) fprintf(outfile,"  label       = %s\n",alabel);

   reordr = 0;    /* easy to set default - if not specified, then */
                  /* this line changes nothing */
   errcod = ip_boolean("REORDER",&reordr,0); 
   if(reordr) {
      errcod = ip_count("MOORDER",&size,0);
      for(i=0; i < size ; i++) {
         errcod = ip_data("MOORDER","%d",&iorder[i],1,i);
         errchk(errcod,"MOORDER");
         }
      }
   second_root = 0;
   if (twocon) {
      errcod = ip_boolean("SECOND_ROOT",&second_root,0);
      }

   if(iopen) {
      errcod = ip_count("SOCC",&size,0);
      if(errcod == IPE_OK && size != num_ir) {
         fprintf(outfile,"\n SOCC array is the wrong size\n");
         fprintf(outfile," is %d, should be %d\n",size,num_ir);
         exit(size);
         }
      if(errcod != IPE_OK) {
         fprintf(outfile,"\n try adding some electrons buddy!\n");
         fprintf(outfile," need SOCC\n");
         ip_print_tree(outfile,NULL);
         exit(1);
         }



psi 2003-01-07