/*$Id: P_out.c 892 2006-03-10 15:24:59Z rcatwood $*/
/* AUTOGENERATED structure input routine */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "machine.h"
/*TO DO: MANUALLY ADD the header for the structure */
/*TO DO: MANUALLY ADD strings or other structures not implemented */
/*TO DO: MANUALLY REMOVE purely internal variables and flags (not to be read in) */
/* start of structure ph_input_struct */
void input_ph_input_struct_values(char * filename,struct ph_input_struct *Struct_Ptr){
   int i;

   char *line;
   char *token;
   FILE *fp;
   char *sep;
   int error;
   int rflag = 0;
   line = (char *)calloc(MAX_STRING_LEN,sizeof(char));
   sep = strdup(" ,;\t\n\r") ;
   
   /*********************************************************/
   /* Open the control file                                 */
   /*********************************************************/
   if((fp = fopen(filename,"r")) == NULL) {
      fprintf(stderr,"ERROR: ph_input_struct reader: can't open input file [%s]\n",filename);
      return;
    }

   while (fgets(line, MAX_STRING_LEN, fp) != NULL) {
      /* ignore comment and blank lines */
      if(line[0]=='%' || line[0]=='#'||(token = strtok(line,sep))==NULL) {
	      continue;
/* Input section for char pointer: * filename */ 
      }else if (strcasecmp(token,"filename")==0){
         if ((token = strtok(NULL, sep)) != NULL){
            sprintf(Struct_Ptr->filename,token);
         }
      }else if (strcasecmp(token,"ncomp")==0){
         if ((token = strtok(NULL, sep)) != NULL){
            Struct_Ptr->ncomp = atoi(token);
         }
      }else if (strcasecmp(token,"Tstart")==0){
         if ((token = strtok(NULL, sep)) != NULL){
            Struct_Ptr->Tstart = (double)atof(token);
         }
      }else if (strcasecmp(token,"Tend")==0){
         if ((token = strtok(NULL, sep)) != NULL){
            Struct_Ptr->Tend = (double)atof(token);
         }
      }else if (strcasecmp(token,"Tmax")==0){
         if ((token = strtok(NULL, sep)) != NULL){
            Struct_Ptr->Tmax = (double)atof(token);
         }
      }else if (strcasecmp(token,"Tstep")==0){
         if ((token = strtok(NULL, sep)) != NULL){
            Struct_Ptr->Tstep = (double)atof(token);
         }
/* Input loop for array: Cmin*/
      }else if (strcasecmp(token,"Cmin")==0){
         for(i=0;i<2;i++){
            if ((token = strtok(NULL, sep)) != NULL){
               Struct_Ptr->Cmin[i] = (double)atof(token);
            }
         }/* end of array input loop */
/* Input loop for array: Cmax*/
      }else if (strcasecmp(token,"Cmax")==0){
         for(i=0;i<2;i++){
            if ((token = strtok(NULL, sep)) != NULL){
               Struct_Ptr->Cmax[i] = (double)atof(token);
            }
         }/* end of array input loop */
/* Input loop for array: Cstep*/
      }else if (strcasecmp(token,"Cstep")==0){
         for(i=0;i<2;i++){
            if ((token = strtok(NULL, sep)) != NULL){
               Struct_Ptr->Cstep[i] = (double)atof(token);
            }
         }/* end of array input loop */
      }else if (strcasecmp(token,"nphases")==0){
         if ((token = strtok(NULL, sep)) != NULL){
            Struct_Ptr->nphases = atoi(token);
         }
/* Input section for char pointer: *      phase */ 
      }else if (strcasecmp(token,"phase")==0){
         if ((token = strtok(NULL, sep)) != NULL){
            sprintf(Struct_Ptr->phase,token);
         }
      }else if (strcasecmp(token,"nregions")==0){
         if ((token = strtok(NULL, sep)) != NULL){
            Struct_Ptr->nregions = atoi(token);
         }

      }
   }
free(line);
fclose(fp);
}
/* End of structure PhInp */
