示例#1
0
static real search_e_diss(int n2m,t_2morse t2m[],char *ai,char *aj)
{
  int i;
  int ibest=-1;
  int nii,njj,nbstii=0,nbstjj=0;
  real ediss = 400;
  
  /* Do a best match search for dissociation energies */
  for(i=0; (i<n2m); i++) {
    /* Check for a perfect match */
    if (((gmx_strcasecmp(t2m[i].ai,ai) == 0) && (gmx_strcasecmp(t2m[i].aj,aj) == 0)) ||
	((gmx_strcasecmp(t2m[i].aj,ai) == 0) && (gmx_strcasecmp(t2m[i].ai,aj) == 0))) {
      ibest = i;
      break;
    }
    else {
      /* Otherwise count the number of equal characters in the strings ai and aj
       * and the ones from the file
       */
      nii = nequal(t2m[i].ai,ai);
      njj = nequal(t2m[i].aj,aj);
      if (((nii >  nbstii) && (njj >= nbstjj)) ||
	  ((nii >= nbstii) && (njj >  nbstjj))) {
	if ((nii > 0) && (njj > 0)) {
	  ibest  = i;
	  nbstii = nii;
	  nbstjj = njj;
	}
      }
      else {
	/* Swap ai and aj (at least in counting the number of equal chars) */
	nii = nequal(t2m[i].ai,aj);
	njj = nequal(t2m[i].aj,ai);
	if (((nii >  nbstii) && (njj >= nbstjj)) ||
	    ((nii >= nbstii) && (njj >  nbstjj))) {
	  if ((nii > 0) && (njj > 0)) {
	    ibest  = i;
	    nbstii = nii;
	    nbstjj = njj;
	  }
	}
      }
    }
  }
  /* Return the dissocation energy corresponding to the best match, if we have
   * found one. Do some debug output anyway.
   */
  if (ibest == -1) {
    if (debug)
      fprintf(debug,"MORSE: Couldn't find E_diss for bond %s - %s, using default %g\n",ai,aj,ediss);
    return ediss;
  }
  else {
    if (debug)
      fprintf(debug,"MORSE: Dissoc. E (%10.3f) for bond %4s-%4s taken from bond %4s-%4s\n",
	      t2m[ibest].e_diss,ai,aj,t2m[ibest].ai,t2m[ibest].aj);
    return t2m[ibest].e_diss;
  }
}
示例#2
0
/** 
 * Get an enumerated header value from the current SAC file
 * 
 * @param kname 
 *    Name of the header field to get
 * @param kvalue 
 *    Value of heade field from the current SAC data file
 *    Each value represents a specific condition
 * @param nerr 
 *    Error Return Flag
 *    - 0 on Success
 *    - ERROR_UNDEFINED_HEADER_FIELD_VALUE
 *    - 1337
 * @param kname_s 
 *    Length of \p kname
 * @param kvalue_s 
 *    Length of \p kvalye
 *
 * @date   870902:  Original version.
 *
 */
void 
getihv(char *kname, 
       char *kvalue, 
       int  *nerr, 
       int   kname_s, 
       int   kvalue_s) {

	char ktest[9];
	int index, ivalue, ntest;

	char *kname_c;
	int callFromC = 0;

	if(kname_s < 0) {
	  callFromC = 1;
	}

	kname_c = fstrdup(kname, kname_s);
	kname_s = strlen(kname_c) + 1;
	

	*nerr = 0;

	/* - Convert input name to uppercase and 
	 *   check versus list of legal names. */
	ntest = min( indexb( kname_c,kname_s ), SAC_HEADER_STRING_LENGTH_FILE );
	strcpy( ktest, "        " );
	modcase( TRUE, kname_c, ntest, ktest );
	index = nequal( ktest, (char*)kmlhf.kihdr,9, SAC_HEADER_ENUMS );

	/* - If legal name, return current value.
	 *   Otherwise, set error condition. */

	if( index > 0 ){
	    ivalue = Ihdr[index];
	    if( ivalue == cmhdr.iundef ){
    	        fstrncpy( kvalue, kvalue_s-1, "UNDEFINED", 9);
		*nerr = ERROR_UNDEFINED_HEADER_FIELD_VALUE;
	    }
	    else{
    	        fstrncpy( kvalue, kvalue_s-1, kmlhf.kiv[ivalue - 1],
                          strlen(kmlhf.kiv[ivalue - 1]) );
	    }
	}
	else{
    	    fstrncpy( kvalue, kvalue_s-1, "ILLEGAL", 7);
	    *nerr = 1337;
	}

	/* - Create error message and write to terminal. */

	if( *nerr != 0 ){
	    setmsg( "WARNING", *nerr );
	    apcmsg( kname_c,kname_s );
	    outmsg();
      clrmsg();
	}

	if(callFromC) { /* C String Termination */
        kvalue[ max(0,min(kvalue_s,8))] = 0;
        } else {        /* Fortran String Non-Termination by Spaces */
          if(kvalue_s > 8) {
            memset(kvalue + 8, ' ', kvalue_s - 8);
          }
        }

	free(kname_c);

	return;

}
示例#3
0
/** 
 * Define cut parameters for a given data file
 * 
 * @param kcut
 *    Which parameter
 * @param ocut
 *    Cut times
 * @param idfl
 *    Data file list number
 * @param nerr
 *    Error Return Flag
 *    - 0 on Success
 *    - ERROR_SAC_LOGIC_ERROR
 *    - ERROR_UNDEFINED_START_CUT_TIME
 *    - ERROR_UNDEFINED_STOP_CUT_TIME
 *    - ERROR_START_TIME_LESS_THAN_BEGIN
 *    - ERROR_STOP_TIME_GREATER_THAN_END
 *    - ERROR_START_TIME_GREATER_THAN_END
 *    - ERROR_STOP_TIME_LESS_THAN_BEGIN
 *    - ERROR_START_TIME_GREATER_THAN_STOP
 *    - ERROR_CORRECTED_BY_FILL_WITH_ZEROS
 *    - ERROR_CORRECTED_BY_USING_START_TIME
 *    - ERROR_CORRECTED_BY_USING_END_TIME
 *
 * @date   961211, 970114, 970214, and 970304:  
 *             I made incremental changes to harden cut.  It now cuts
 *             precisely on the values entered.  maf
 * @date   880128:  Fixed bug that occurred when the sampling interval
 *             was smaller than the machine roundoff factor.
 * @date   850415:  Changes due to restructuring of DFM common block.
 * @date   840228:  Original version from DEFMEM.
 *
 */
void 
defcut(char   kcut[2][9], 
       double ocut[2],
       int    idfl, 
       int   *nerr) {

	int jdx, nptrd;
	float pick[2], start, stop;
	float *const Pick = &pick[0] - 1;
  char *tmp;
	*nerr = 0;

	/* - Get file name from character list. */
    tmp = string_list_get(datafiles, idfl-1);
	/* - Save total number of points in file. */
	Ntotal[idfl] = *npts;

	/* - Compute start value. */
	if( strcmp(kcut[0],"Z       ") == 0 ){
		Pick[1] = 0.;
	}

	else if ( strcmp(kcut[0],"N       ") != 0 ) {
		jdx = nequal( (char*)kcut[0], (char*)kmdfm.kpick,9, MPICK );
		if( jdx > 0 )
			Pick[1] = Fhdr[Ipckhd[jdx]];

		else{
			*nerr = ERROR_SAC_LOGIC_ERROR;
			setmsg( "ERROR", *nerr );
			apcmsg( "DEFCUT #2",10 );
			return ;
		}
	} else {
        *nerr = ERROR_SAC_LOGIC_ERROR;
        setmsg( "ERROR", *nerr );
        apcmsg( "DEFCUT #2",10 );
        return ;        
    }

	/* - Check to make sure the requested pick field 
	 *   in the header is defined. 
	 */
	if( Pick[1] == cmhdr.fundef ){
		if( cmdfm.icuter == 1 ){
			*nerr = ERROR_UNDEFINED_START_CUT_TIME;
			setmsg( "ERROR", *nerr );
            apcmsg2(tmp, strlen(tmp)+1);
			return ;
		}
		else{
			setmsg( "WARNING", ERROR_UNDEFINED_START_CUT_TIME );
            apcmsg2(tmp, strlen(tmp)+1);
			outmsg();
			setmsg( "OUTPUT", ERROR_CORRECTED_BY_USING_BEGIN_TIME );
			outmsg();
			start = *begin;
			Nstart[idfl] = 1;
		}
	}
	else{
    start = Pick[1] + ocut[0];
    cut_define(*begin, *delta, start, &Nstart[idfl]);
	}

	/* -  Compute stop value. */
	if( strcmp(kcut[1],"N       ") == 0 ){
		nptrd = ocut[1] + RNDOFF**delta;
		stop = start + (float)( nptrd - 1 )**delta;
		Nstop[idfl] = Nstart[idfl] + nptrd - 1;
		Pick[2] = 0.;
	}
	else{
		jdx = nequal( (char*)kcut[1], (char*)kmdfm.kpick,9, MPICK );
		if(jdx <= 0) {
            *nerr = ERROR_SAC_LOGIC_ERROR;
			setmsg( "ERROR", *nerr );
			apcmsg( "DEFCUT #3",10 );
			return ;
		} else {
      if(strcmp(kcut[1],"Z       ") == 0 ) {
        Pick[2] = 0.0;
      } else {
        Pick[2] = Fhdr[Ipckhd[jdx]];
      }
      stop = Pick[2] + ocut[1];
      cut_define(*begin, *delta, stop, &Nstop[idfl]);
    }
	}

	/* - Make sure stop pick is defined. */
	if( Pick[2] == cmhdr.fundef ){
		if( cmdfm.icuter == 1 ){
			*nerr = ERROR_UNDEFINED_STOP_CUT_TIME;
			setmsg( "ERROR", *nerr );
            apcmsg2(tmp, strlen(tmp)+1);
			return ;
		}
		else{
			setmsg( "WARNING", ERROR_UNDEFINED_STOP_CUT_TIME );
      apcmsg2(tmp, strlen(tmp)+1);
			outmsg();
			setmsg( "OUTPUT", ERROR_CORRECTED_BY_USING_END_TIME );
			outmsg();
			stop = *ennd;
			Nstop[idfl] = *npts;
		}
    }

  /* Check the cut time and adjust Nstart, Nstop, Nfillb, Nfille */
  cut_define_check(start, stop, *npts, cmdfm.icuter,
                   &Nstart[idfl], &Nstop[idfl],
                   &Nfillb[idfl], &Nfille[idfl], nerr);
  /* Error checking */
  if(*nerr) {
    switch(*nerr) {
    case ERROR_START_TIME_GREATER_THAN_STOP:
      error(*nerr, "%s\n\ttime:  %f >= %f\n\tindex: %d >= %d", tmp, start, stop, Nstart[idfl], Nstop[idfl]);
      return ;
      break;
    case ERROR_START_TIME_GREATER_THAN_END:
      error(*nerr, "%s\n\ttime:  %f > %f\n\tindex: %d > %d", tmp, start, *e, Nstart[idfl], *npts);
      return ;
      break;
    case ERROR_STOP_TIME_LESS_THAN_BEGIN:
      error(*nerr, "%s\n\ttime:  %f < %f\n\tindex: %d < %d", tmp, stop, *b, Nstop[idfl], 1);
      return ;
      break;
    case ERROR_START_TIME_LESS_THAN_BEGIN:
      if( cmdfm.icuter == 2 ){
        setmsg( "WARNING", *nerr);
        apcmsg2(tmp, strlen(tmp)+1);
        outmsg();
        setmsg( "OUTPUT", ERROR_CORRECTED_BY_USING_BEGIN_TIME );
        outmsg();
        *nerr = SAC_OK;
      } else {
        setmsg( "ERROR", *nerr );
        apcmsg2(tmp, strlen(tmp)+1);
        return ;
      }
      break;
    case ERROR_STOP_TIME_GREATER_THAN_END:
      if( cmdfm.icuter == 2 ){
        setmsg( "WARNING", *nerr );
        apcmsg2(tmp, strlen(tmp)+1);
        outmsg();
        setmsg( "OUTPUT", ERROR_CORRECTED_BY_USING_END_TIME );
        outmsg();
        *nerr = SAC_OK;
      } else {
        setmsg( "ERROR", *nerr );
        apcmsg2(tmp, strlen(tmp)+1);
        return ;
      }
      break;
    case ERROR_CUT_TIMES_BEYOND_DATA_LIMITS:
      /* Begin */
      setmsg("WARNING", ERROR_START_TIME_LESS_THAN_BEGIN);
      apcmsg2(tmp, strlen(tmp)+1);
      outmsg();
      setmsg("OUTPUT", ERROR_CORRECTED_BY_USING_BEGIN_TIME);
      outmsg();
      /* End */
      setmsg("WARNING", ERROR_STOP_TIME_GREATER_THAN_END);
      apcmsg2(tmp, strlen(tmp)+1);
      outmsg();
      setmsg("OUTPUT", ERROR_CORRECTED_BY_USING_END_TIME);
      outmsg();
      *nerr = SAC_OK;
      break;
    }
  }
	/* - Convert these start and stop points to new begin and end times. */
	*begin = *begin + (float)( Nstart[idfl] - 1 )**delta;
	*npts = Nstop[idfl] - Nstart[idfl] + 1;
	*ennd = *begin + (float)( *npts - 1 )**delta;

}