Ejemplo n.º 1
0
	  void SPELLEROBJ::make_suggestions(void)
	  {
		  int i,u,f,x;

			suggestions=0;
		    f=1;
			for (x=strlen(word);(x>0)&&f;)
			{ 
			   x--;
			   if (( (word[x]==' ') || (word[x]=='.')) && (word[x+1]))
			   { f=0; x++; } 
			}

			if (strlen(word)-x>0)
			{
			  for (i=START_WORDS;(i<START_WORDS+wordcount)&&(suggestions<MAX_SUGGEST);i++)
			  {
				f=1;
				for (u=0;(u+x<(int)strlen(word))&&f;u++)
					if (upstr( word[u+x]) != upstr (dict[i].tag[u]) ) f=0;
				
				if (f) { suggest[suggestions++]=i; sugchars=u; }
			  }
			}

			if (strlen(word) && (word[strlen(word)-1]==' ')||(word[strlen(word)-1]=='.')) 
			{ 	
			  for (u=0;(u<MAX_SUGGEST)&&(u<wordcount);u++) suggest[suggestions++]=START_WORDS+u;
			  sugchars=0;
			} 
	  }
Ejemplo n.º 2
0
int			creat_str(t_pf *ptf, int flag, int dot)
{
	char	*str;
	int		size;

	size = 0;
	(flag & 16 && flag & 1 && ptf->type == '%') ? ptf->flag -= 16 : 0;
	if (ptf->type == 'n' && free_ptf(ptf) < 0)
		return (0);
	if (ptf->type == '%' && ptf->dot && !(ptf->dot = 0))
		ptf->prec = 0;
	if (!ptf->dot && ptf->flag & 16)
	{
		ptf->prec = ptf->width;
		if (ptf->value[0] == '-' || ptf->flag & 2 || ptf->flag & 4)
			ptf->prec--;
	}
	if (dot && !ptf->prec && ptf->value[0] && ft_check(ptf))
		ptf->value[0] = 0;
	if (!(str = makeoptions(ptf)))
		return (-1);
	(ptf->type == 'X') ? upstr(&str) : 0;
	size = p_var(ptf, str);
	free(str);
	str = NULL;
	free_ptf(ptf);
	return (size);
}
Ejemplo n.º 3
0
/*
 * new_hsctag
 *
 * alloc & init a new hsctag
 */
HSCTAG *new_hsctag(STRPTR newid)
{

    HSCTAG *newtag = (HSCTAG*) umalloc(sizeof(HSCTAG));

    if (newtag)
    {
        /* init new tag item */
        newtag->name = upstr(strclone(newid));  /* set id */
        newtag->option = 0;
        newtag->o_handle = NULL;        /* no handle functions */
        newtag->c_handle = NULL;
        newtag->occured = FALSE;
        newtag->op_text = NULL;
        newtag->cl_text = NULL;
        newtag->attr = init_dllist(del_hscattr);
        newtag->mbi = NULL;
        newtag->naw = NULL;
        newtag->uri_size = NULL;
        newtag->uri_stripext = NULL;
        newtag->start_fpos = NULL;
        newtag->end_fpos = NULL;

        if (!(newtag->name && newtag->attr))
        {
            del_hsctag(newtag);
            newtag = NULL;
        }
    }

    return (newtag);
}
Ejemplo n.º 4
0
iconv_t
iconv_open (const char *tocode, const char *fromcode)
{
  char *tocode_conv;
  char *fromcode_conv;
  size_t tocode_len;
  size_t fromcode_len;
  __gconv_t cd;
  int res;

  /* Normalize the name.  We remove all characters beside alpha-numeric,
     '_', '-', '/', and '.'.  */
  tocode_len = strlen (tocode);
  tocode_conv = alloca (tocode_len + 3);
  strip (tocode_conv, tocode);
  tocode = tocode_conv[2] == '\0' ? upstr (tocode_conv, tocode) : tocode_conv;

  fromcode_len = strlen (fromcode);
  fromcode_conv = alloca (fromcode_len + 3);
  strip (fromcode_conv, fromcode);
  fromcode = (fromcode_conv[2] == '\0'
	      ? upstr (fromcode_conv, fromcode) : fromcode_conv);

  res = __gconv_open (tocode, fromcode, &cd, 0);

  if (__builtin_expect (res, __GCONV_OK) != __GCONV_OK)
    {
      /* We must set the error number according to the specs.  */
      if (res == __GCONV_NOCONV || res == __GCONV_NODB)
	__set_errno (EINVAL);

      return (iconv_t) -1;
    }

  return (iconv_t) cd;
}
Ejemplo n.º 5
0
/*
** new_hsctag
**
** alloc & init a new hsctag
*/
HSCTAG *new_hsctag( STRPTR newid )
{

    HSCTAG *newtag = (HSCTAG*) malloc( sizeof(HSCTAG) );

    if (newtag) {

        /* init new tag item */
        newtag->name     = upstr( strclone(newid) );        /* set id */
        newtag->option   = 0;
        newtag->vers     = 0;
        newtag->o_handle = NULL;       /* no handle functions */
        newtag->c_handle = NULL;
        newtag->occured  = FALSE;
    }

    return (newtag);

}
Ejemplo n.º 6
0
_IO_FILE *
_IO_new_file_fopen (_IO_FILE *fp, const char *filename, const char *mode,
		    int is32not64)
{
  int oflags = 0, omode;
  int read_write;
  int oprot = 0666;
  int i;
  _IO_FILE *result;
#ifdef _LIBC
  const char *cs;
  const char *last_recognized;
#endif

  if (_IO_file_is_open (fp))
    return 0;
  switch (*mode)
    {
    case 'r':
      omode = O_RDONLY;
      read_write = _IO_NO_WRITES;
      break;
    case 'w':
      omode = O_WRONLY;
      oflags = O_CREAT|O_TRUNC;
      read_write = _IO_NO_READS;
      break;
    case 'a':
      omode = O_WRONLY;
      oflags = O_CREAT|O_APPEND;
      read_write = _IO_NO_READS|_IO_IS_APPENDING;
      break;
    default:
      __set_errno (EINVAL);
      return NULL;
    }
#ifdef _LIBC
  last_recognized = mode;
#endif
  for (i = 1; i < 7; ++i)
    {
      switch (*++mode)
	{
	case '\0':
	  break;
	case '+':
	  omode = O_RDWR;
	  read_write &= _IO_IS_APPENDING;
#ifdef _LIBC
	  last_recognized = mode;
#endif
	  continue;
	case 'x':
	  oflags |= O_EXCL;
#ifdef _LIBC
	  last_recognized = mode;
#endif
	  continue;
	case 'b':
#ifdef _LIBC
	  last_recognized = mode;
#endif
	  continue;
	case 'm':
	  fp->_flags2 |= _IO_FLAGS2_MMAP;
	  continue;
	case 'c':
	  fp->_flags2 |= _IO_FLAGS2_NOTCANCEL;
	  continue;
	case 'e':
#ifdef O_CLOEXEC
	  oflags |= O_CLOEXEC;
#endif
	  fp->_flags2 |= _IO_FLAGS2_CLOEXEC;
	  continue;
	default:
	  /* Ignore.  */
	  continue;
	}
      break;
    }

  result = _IO_file_open (fp, filename, omode|oflags, oprot, read_write,
			  is32not64);

  if (result != NULL)
    {
#ifndef __ASSUME_O_CLOEXEC
      if ((fp->_flags2 & _IO_FLAGS2_CLOEXEC) != 0 && __have_o_cloexec <= 0)
	{
	  int fd = _IO_fileno (fp);
	  if (__have_o_cloexec == 0)
	    {
	      int flags = __fcntl (fd, F_GETFD);
	      __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
	    }
	  if (__have_o_cloexec < 0)
	    __fcntl (fd, F_SETFD, FD_CLOEXEC);
	}
#endif

      /* Test whether the mode string specifies the conversion.  */
      cs = strstr (last_recognized + 1, ",ccs=");
      if (cs != NULL)
	{
	  /* Yep.  Load the appropriate conversions and set the orientation
	     to wide.  */
	  struct gconv_fcts fcts;
	  struct _IO_codecvt *cc;
	  char *endp = __strchrnul (cs + 5, ',');
	  char *ccs = malloc (endp - (cs + 5) + 3);

	  if (ccs == NULL)
	    {
	      int malloc_err = errno;  /* Whatever malloc failed with.  */
	      (void) _IO_file_close_it (fp);
	      __set_errno (malloc_err);
	      return NULL;
	    }

	  *((char *) __mempcpy (ccs, cs + 5, endp - (cs + 5))) = '\0';
	  strip (ccs, ccs);

	  if (__wcsmbs_named_conv (&fcts, ccs[2] == '\0'
				   ? upstr (ccs, cs + 5) : ccs) != 0)
	    {
	      /* Something went wrong, we cannot load the conversion modules.
		 This means we cannot proceed since the user explicitly asked
		 for these.  */
	      (void) _IO_file_close_it (fp);
	      free (ccs);
	      __set_errno (EINVAL);
	      return NULL;
	    }

	  free (ccs);

	  assert (fcts.towc_nsteps == 1);
	  assert (fcts.tomb_nsteps == 1);

	  fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end;
	  fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_write_base;

	  /* Clear the state.  We start all over again.  */
	  memset (&fp->_wide_data->_IO_state, '\0', sizeof (__mbstate_t));
	  memset (&fp->_wide_data->_IO_last_state, '\0', sizeof (__mbstate_t));

	  cc = fp->_codecvt = &fp->_wide_data->_codecvt;

	  /* The functions are always the same.  */
	  *cc = __libio_codecvt;

	  cc->__cd_in.__cd.__nsteps = fcts.towc_nsteps;
	  cc->__cd_in.__cd.__steps = fcts.towc;

	  cc->__cd_in.__cd.__data[0].__invocation_counter = 0;
	  cc->__cd_in.__cd.__data[0].__internal_use = 1;
	  cc->__cd_in.__cd.__data[0].__flags = __GCONV_IS_LAST;
	  cc->__cd_in.__cd.__data[0].__statep = &result->_wide_data->_IO_state;

	  cc->__cd_out.__cd.__nsteps = fcts.tomb_nsteps;
	  cc->__cd_out.__cd.__steps = fcts.tomb;

	  cc->__cd_out.__cd.__data[0].__invocation_counter = 0;
	  cc->__cd_out.__cd.__data[0].__internal_use = 1;
	  cc->__cd_out.__cd.__data[0].__flags
	    = __GCONV_IS_LAST | __GCONV_TRANSLIT;
	  cc->__cd_out.__cd.__data[0].__statep =
	    &result->_wide_data->_IO_state;

	  /* From now on use the wide character callback functions.  */
	  _IO_JUMPS_FILE_plus (fp) = fp->_wide_data->_wide_vtable;

	  /* Set the mode now.  */
	  result->_mode = 1;
	}
    }

  return result;
}
Ejemplo n.º 7
0
    internal_function
_nl_find_locale (const char *locale_path, size_t locale_path_len,
                 int category, const char **name)
{
    int mask;
    /* Name of the locale for this category.  */
    char *loc_name;
    const char *language;
    const char *modifier;
    const char *territory;
    const char *codeset;
    const char *normalized_codeset;
    struct loaded_l10nfile *locale_file;

    if ((*name)[0] == '\0')
    {
        /* The user decides which locale to use by setting environment
        variables.  */
        *name = getenv ("LC_ALL");
        if (*name == NULL || (*name)[0] == '\0')
            *name = getenv (_nl_category_names.str
                            + _nl_category_name_idxs[category]);
        if (*name == NULL || (*name)[0] == '\0')
            *name = getenv ("LANG");
    }

    if (*name == NULL || (*name)[0] == '\0'
            || (__builtin_expect (__libc_enable_secure, 0)
                && strchr (*name, '/') != NULL))
        *name = (char *) _nl_C_name;

    if (__builtin_expect (strcmp (*name, _nl_C_name), 1) == 0
            || __builtin_expect (strcmp (*name, _nl_POSIX_name), 1) == 0)
    {
        /* We need not load anything.  The needed data is contained in
        the library itself.  */
        *name = (char *) _nl_C_name;
        return _nl_C[category];
    }

    /* We really have to load some data.  First we try the archive,
       but only if there was no LOCPATH environment variable specified.  */
    if (__builtin_expect (locale_path == NULL, 1))
    {
        struct __locale_data *data
            = _nl_load_locale_from_archive (category, name);
        if (__builtin_expect (data != NULL, 1))
            return data;

        /* Nothing in the archive.  Set the default path to search below.  */
        locale_path = _nl_default_locale_path;
        locale_path_len = sizeof _nl_default_locale_path;
    }

    /* We really have to load some data.  First see whether the name is
       an alias.  Please note that this makes it impossible to have "C"
       or "POSIX" as aliases.  */
    loc_name = (char *) _nl_expand_alias (*name);
    if (loc_name == NULL)
        /* It is no alias.  */
        loc_name = (char *) *name;

    /* Make a writable copy of the locale name.  */
    loc_name = strdupa (loc_name);

    /* LOCALE can consist of up to four recognized parts for the XPG syntax:

    	language[_territory[.codeset]][@modifier]

       Beside the first all of them are allowed to be missing.  If the
       full specified locale is not found, the less specific one are
       looked for.  The various part will be stripped off according to
       the following order:
    	(1) codeset
    	(2) normalized codeset
    	(3) territory
    	(4) modifier
     */
    mask = _nl_explode_name (loc_name, &language, &modifier, &territory,
                             &codeset, &normalized_codeset);
    if (mask == -1)
        /* Memory allocate problem.  */
        return NULL;

    /* If exactly this locale was already asked for we have an entry with
       the complete name.  */
    locale_file = _nl_make_l10nflist (&_nl_locale_file_list[category],
                                      locale_path, locale_path_len, mask,
                                      language, territory, codeset,
                                      normalized_codeset, modifier,
                                      _nl_category_names.str
                                      + _nl_category_name_idxs[category], 0);

    if (locale_file == NULL)
    {
        /* Find status record for addressed locale file.  We have to search
        through all directories in the locale path.  */
        locale_file = _nl_make_l10nflist (&_nl_locale_file_list[category],
                                          locale_path, locale_path_len, mask,
                                          language, territory, codeset,
                                          normalized_codeset, modifier,
                                          _nl_category_names.str
                                          + _nl_category_name_idxs[category], 1);
        if (locale_file == NULL)
            /* This means we are out of core.  */
            return NULL;
    }

    /* The space for normalized_codeset is dynamically allocated.  Free it.  */
    if (mask & XPG_NORM_CODESET)
        free ((void *) normalized_codeset);

    if (locale_file->decided == 0)
        _nl_load_locale (locale_file, category);

    if (locale_file->data == NULL)
    {
        int cnt;
        for (cnt = 0; locale_file->successor[cnt] != NULL; ++cnt)
        {
            if (locale_file->successor[cnt]->decided == 0)
                _nl_load_locale (locale_file->successor[cnt], category);
            if (locale_file->successor[cnt]->data != NULL)
                break;
        }
        /* Move the entry we found (or NULL) to the first place of
        successors.  */
        locale_file->successor[0] = locale_file->successor[cnt];
        locale_file = locale_file->successor[cnt];

        if (locale_file == NULL)
            return NULL;
    }

    /* The LC_CTYPE category allows to check whether a locale is really
       usable.  If the locale name contains a charset name and the
       charset name used in the locale (present in the LC_CTYPE data) is
       not the same (after resolving aliases etc) we reject the locale
       since using it would irritate users expecting the charset named
       in the locale name.  */
    if (codeset != NULL)
    {
        /* Get the codeset information from the locale file.  */
        static const int codeset_idx[] =
        {
            [__LC_CTYPE] = _NL_ITEM_INDEX (CODESET),
            [__LC_NUMERIC] = _NL_ITEM_INDEX (_NL_NUMERIC_CODESET),
            [__LC_TIME] = _NL_ITEM_INDEX (_NL_TIME_CODESET),
            [__LC_COLLATE] = _NL_ITEM_INDEX (_NL_COLLATE_CODESET),
            [__LC_MONETARY] = _NL_ITEM_INDEX (_NL_MONETARY_CODESET),
            [__LC_MESSAGES] = _NL_ITEM_INDEX (_NL_MESSAGES_CODESET),
            [__LC_PAPER] = _NL_ITEM_INDEX (_NL_PAPER_CODESET),
            [__LC_NAME] = _NL_ITEM_INDEX (_NL_NAME_CODESET),
            [__LC_ADDRESS] = _NL_ITEM_INDEX (_NL_ADDRESS_CODESET),
            [__LC_TELEPHONE] = _NL_ITEM_INDEX (_NL_TELEPHONE_CODESET),
            [__LC_MEASUREMENT] = _NL_ITEM_INDEX (_NL_MEASUREMENT_CODESET),
            [__LC_IDENTIFICATION] = _NL_ITEM_INDEX (_NL_IDENTIFICATION_CODESET)
        };
        const struct __locale_data *data;
        const char *locale_codeset;
        char *clocale_codeset;
        char *ccodeset;

        data = (const struct __locale_data *) locale_file->data;
        locale_codeset =
            (const char *) data->values[codeset_idx[category]].string;
        assert (locale_codeset != NULL);
        /* Note the length of the allocated memory: +3 for up to two slashes
        and the NUL byte.  */
        clocale_codeset = (char *) alloca (strlen (locale_codeset) + 3);
        strip (clocale_codeset, locale_codeset);

        ccodeset = (char *) alloca (strlen (codeset) + 3);
        strip (ccodeset, codeset);

        if (__gconv_compare_alias (upstr (ccodeset, ccodeset),
                                   upstr (clocale_codeset,
                                          clocale_codeset)) != 0)
            /* The codesets are not identical, don't use the locale.  */
            return NULL;
    }
Ejemplo n.º 8
0
// --------- write data ---------
void write_stats(int total_stn)
{
  int stn, yr, mn, tmn, dy, mon, op, *pd, *pd6, *pdl; float *p;
  char file_bas[MAX_CHAR], file_stn[MAX_CHAR], str_tmp[MAX_CHAR];
  char met_mon[MAX_MON], new_dir[9];
  char *str_mon[13] = {"", "January", "February", "March", "April"," May"," June",
                       "July", "August", "September", "October", "November", "December"};
//  char *str_mon_abv[13] = {"", "Jan", "Feb", "Mar", "Apr"," May"," Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  SAV_HDR sav_hdr;
  FILE *fp, *fp2, *fp_stn;
  
  // change directory to YYYYMMDD if exist, otherwise create it
  sprintf(new_dir, "%s/%8ld.%.3s", path_work, cur_fcst, str_fcst);  // path fmt: YYYYMMDD.ESP/CPC/CFS

  printf("\nwriting data to path: %s/%s\n", path_work, new_dir);
  
  // generate the array to hold the actual month series in each fcst run
  for (mn = 0, mon = mon0; mn < total_mon; mn ++) {
    met_mon[mn] = mon;
    mon ++; if (mon > 12) mon = 1;
  }

  if (op_calc_cum) {
    printf("...writing bas stats and forweb: %s.\n", str_fcst);
    sprintf(file_bas, "%s/%s.%3sstats", path_work, name_bas, str_fcst);
    fp = fopen(file_bas, "wt");
    fprintf(fp, "%s %d, %d\n", str_mon[fcst_mn], fcst_dy, fcst_yr);
    for (stn = 0; stn < total_stn; stn ++) {
      if (stn_idx[stn] == -2) continue; // skip the missing station
      pd = &stn_cum_stat[stn][0];
      if (fcst_type == 1) {  // for ESP forecast
        fprintf(fp, "%-56s %7s %7d %7d %7d %9d %7d %9d %7d\n", 
                name_stn_full[stn], str_cum_period, pd[0], pd[1], pd[2], pd[3], pd[4], pd[5], pd[6]);
      }
      else {                // for CPC forecast. note that we donot print for CFS
        fprintf(fp, "%-56s %7s %7d %7d %7d %9d %7d\n", 
                name_stn_full[stn], str_cum_period, pd[0], pd[1], pd[2], pd[3], pd[4]);
      }
    }
    fclose(fp);
  }

  if (op_trace_year) {
    printf("...writing trace year stats: %s.\n", str_fcst);
    sprintf(file_bas, "%s/%s.%3sstats_trace", path_work, name_bas, str_fcst);
    fp = fopen(file_bas, "wt");
    fprintf(fp, "%-56s %7s %7s %7s\n", "station", "ESP", "enso", "trace"); 
    for (stn = 0; stn < total_stn; stn ++) {
      if (stn_idx[stn] == -2) continue; // skip the missing station
      pd = &stn_cum_stat[stn][0];
      fprintf(fp, "%-56s %7d %7d %7d\n", name_stn_full[stn], pd[4], pd[6], pd[7]);
    }
    fclose(fp);
  }

  printf("...writing forweb file.\n");
  sprintf(file_bas, "%s/%s.forweb2", path_work, name_bas);
  fp = fopen(file_bas, "wt");
  for (stn = 0; stn < total_stn; stn ++) {
    if (stn_idx[stn] == -2) continue; // skip the missing station
    pd = &stn_cum_stat[stn][0];
    pd6 = &stn_6mon_cum[stn][0];
    fprintf(fp, "%s  %5d %5d %5d   %5d %5d %5d\n", 
            name_stn[stn], pd[1], pd[3], pd[4], pd6[1], pd6[3], pd6[4]);
  }
  fclose(fp);

  printf("...writing bas flowdata and stn sflow quart files.\n");
  strcpy(str_tmp, name_bas);
  upstr(str_tmp);
  sprintf(file_bas, "%s/%3s_flowdata_%s.txt", path_work, str_fcst, str_tmp);
  fp = fopen(file_bas, "wt");
  write_flowdata_header(fp, str_fcst, "");
  sprintf(file_bas, "%s/%3s_flowdata_%s_split.txt", path_work, str_fcst, str_tmp);
  fp2 = fopen(file_bas, "wt");
  write_flowdata_header(fp2, str_fcst, " (Apr and Aug are splitted)");

  for (stn = 0; stn < total_stn; stn ++) {
    if (stn_idx[stn] == -2) continue; // skip the missing station

    sprintf(file_stn, "%s/sflow.%s.all", path_work, name_stn[stn]);
    fp_stn = fopen(file_stn, "wt");
    
    // write station sflow data to clim info file
    printf("......writing %s.\n", name_stn[stn]);
    fprintf(fp, "%s\n", name_stn_full[stn]);
    fprintf(fp2, "%s\n", name_stn_full[stn]);
    for (mn = 0; mn < total_mon; mn ++) {
      mon = met_mon[mn];
      switch (mon) {
        case 4: 
          fprintf(fp2, "%19s ", "Apr(1-15) (16-30)");
          break;
        case 8: 
          fprintf(fp2, "%19s ", "Aug(1-15) (16-31)");
          break;
        default:
          fprintf(fp2, "%9s ", str_mon[mon]);   
      }
    }
    fprintf(fp2, "\n");

    for (yr = 0; yr < max_ens; yr ++) {
      tmn = total_mon;
      for (mn = 0; mn < total_mon; mn ++) {
        fprintf(fp, "%9.1f ", flow[stn][mn][yr]);
        fprintf(fp_stn, "%9.1f ", flow[stn][mn][yr]);
        mon = met_mon[mn];
        switch (mon) {
          case 4: 
            fprintf(fp2, "%9.1f %9.1f ", flow[stn][tmn][yr], (flow[stn][mn][yr] * 30.0 - flow[stn][tmn][yr] * 15.0) / 15.0 );
            tmn ++;
            break;
          case 8: 
            fprintf(fp2, "%9.1f %9.1f ", flow[stn][tmn][yr], (flow[stn][mn][yr] * 31.0 - flow[stn][tmn][yr] * 15.0) / 16.0 );
            tmn ++;
            break;
          default:
            fprintf(fp2, "%9.1f ", flow[stn][mn][yr]);
        }
      }
      fprintf(fp, "\n");
      fprintf(fp2, "\n");
      fprintf(fp_stn, "\n");
    }
    fprintf(fp, "---------------------------------------------\n\n");
    fprintf(fp2, "---------------------------------------------\n\n");
    fclose(fp_stn);

    // write station sflow fcst quart file
    sprintf(file_stn, "%s/sflow.%s.quart", path_work, name_stn[stn]);
    fp_stn = fopen(file_stn, "wt");

    printf ("Writing station sflow check !");

    for (mn = 0; mn < total_mon; mn ++) {
      p = &flow_quart[stn][mn][0];
      fprintf(fp_stn, "%d %.2f %.2f %.2f %.2f %.2f\n", met_mon[mn], p[0], p[1], p[2], p[3], p[4]);
    }
    fclose(fp_stn);

    if (fcst_type == 1) {  // write station ENSO quart files for ESP forecast
      // write station sflow ESP_ENSO quart file
      sprintf(file_stn, "%s/sflow.%s.E%s.quart", path_work, name_stn[stn], str_enso);
      fp_stn = fopen(file_stn, "wt");
      for (mn = 0; mn < total_mon; mn ++) {
        p = &flow_ENSO_quart[stn][mn][0];
        fprintf(fp_stn, "%d %.2f %.2f %.2f %.2f %.2f\n", met_mon[mn], p[0], p[1], p[2], p[3], p[4]);
      }
      fclose(fp_stn);

      // write station sflow ESP PDO quart file
      sprintf(file_stn, "%s/sflow.%s.E%s_Ppos.quart", path_work, name_stn[stn], str_enso);
      fp_stn = fopen(file_stn, "wt");
      for (mn = 0; mn < total_mon; mn ++) {
        p = &flow_ENSO_PDO_quart[stn][mn][0];
        fprintf(fp_stn, "%d %.2f %.2f %.2f %.2f %.2f\n", met_mon[mn], p[0], p[1], p[2], p[3], p[4]);
      }
      fclose(fp_stn);
    } // end if for (str_fcst == 1)
  }
  fclose(fp); fclose(fp2);

  // write BAS.sav file (binary) for later use
  // order of data in the file:
  // sav_hdr      (32 bytes)
  // name_stn     (char * NAME_STN * total_stn)
  // flow         (float * MAX_METYR * MAX_MON * total_stn
  // stn_cum_stat (int * MAX_STAT * total_stn)
  sav_hdr.total_stn = total_stn;
  sav_hdr.idx[0] = MAX_METYR; sav_hdr.idx[1] = MAX_MON; sav_hdr.idx[2] = MAX_STAT;
  sav_hdr.p[0] = mon0; sav_hdr.p[1] = total_mon;
  sprintf(file_bas, "%s/%s.sav", path_work, name_bas);
  printf("...now writing the binary data file %s.\n", file_bas);
  fp = fopen(file_bas, "wb");
  fwrite(&sav_hdr, sizeof(SAV_HDR), 1, fp);
  fwrite((void *)&name_stn[0][0], NAME_STN, total_stn, fp);
  fwrite((void *)&flow[0][0][0], sizeof(float) * MAX_METYR, total_stn * MAX_MON, fp);
  fwrite((void *)&stn_cum_stat[0][0], sizeof(int) * MAX_STAT, total_stn, fp);
  fclose(fp);

  // write fcst change file if applicable
  if (op_calc_diff) {
    printf("...now writing %s change since last forecast.\n", str_fcst);
    sprintf(file_bas, "%s/%s.%sstats_DIFF", path_work, name_bas, str_fcst);
    fp = fopen(file_bas, "wt");
    dy = bas_fcst_hist[idx_cur_fcst - 1];
    yr = dy / 10000; dy -= yr * 10000L; 
    mn = dy / 100; dy -= mn * 100;
    fprintf(fp, "%s %d, %d vs %s %d, %d\n", str_mon[fcst_mn], fcst_dy, fcst_yr, str_mon[mn], dy, yr);
 
    for (stn = 0; stn < total_stn; stn ++) {
      switch (stn_idx[stn]) {
        case -1:        // station does not occur in last forecast
          if (fcst_type == 1) {  // for ESP forecast
            fprintf(fp, "%-56s %7s %7s %7s %7s %9s %7s %9s %7s\n", 
                    name_stn_full[stn], str_cum_period, "---", "---", "---", "---", "---", "---", "---");
          }
          else {        // for CPC forecast
            fprintf(fp, "%-56s %7s %7s %7s %7s %9s %7s\n", 
                    name_stn_full[stn], str_cum_period, "---", "---", "---", "---", "---");
          }
          break;
        case -2: break; // skip the missing station
        default:
          pd = &stn_cum_stat[stn][0];
          pdl = &stn_cum_stat_last[(int)stn_idx[stn]][0];
          if (fcst_type == 1) {  // for ESP forecast
            fprintf(fp, "%-56s %7s %7d %7d %7d %9d %7d %9d %7d\n", 
                    name_stn_full[stn], str_cum_period, 
                    pd[0] - pdl[0], pd[1] - pdl[1], pd[2] - pdl[2], pd[3] - pdl[3], 
                    pd[4] - pdl[4], pd[5] - pdl[5], pd[6] - pdl[6]);
          }
          else {        // for CPC forecast
            fprintf(fp, "%-56s %7s %7d %7d %7d %9d %7d\n", 
                    name_stn_full[stn], str_cum_period, 
                    pd[0] - pdl[0], pd[1] - pdl[1], pd[2] - pdl[2], pd[3] - pdl[3], pd[4] - pdl[4]);
          }
      }
    }
    fclose(fp);
  }
}
Ejemplo n.º 9
0
/*
** def_tag_name
**
*/
HSCTAG *def_tag_name( HSCPRC *hp, BOOL *open_tag )
{
    STRPTR  nw  = NULL;
    HSCTAG *tag = NULL;
    DLLIST *taglist = hp->deftag;

    /* get tag name */
    nw = infget_tagid( hp );

    /* create new tag */
    if ( nw ) {

        *open_tag = (BOOL)(strcmp( nw, "/" ));
        if ( !(*open_tag) ) {

            /* add closing tag */
            nw = infget_tagid( hp );
            if ( nw ) {

                tag = find_strtag( taglist, nw );
                if ( tag )
                    /* set closing flag */
                    tag->option |= HT_CLOSE;
                else {

                    hsc_message( hp, MSG_DEFTAG_NO_OPEN,
                                 "no start tag for %c", nw );

                }


            } /* err_eof already called in infget_tagid() */

        } else {

            tag = find_strtag( taglist, nw );
            if ( tag ) {

                /* find tag-node in list */
                /* NOTE: this is rather stupid, 'cause the list */
                /* has to be searched twice this way; but who cares? */
                DLNODE *nd = find_dlnode( hp->deftag->first,
                                          (APTR) nw, cmp_strtag );

                /* new tag/macro replaces old tag/macro */
                if ( (tag->option) & HT_MACRO ) {

                    tag->occured = FALSE;

                    hsc_message( hp, MSG_REDEFINE_MACRO,
                                 "redefined %T", tag );

                } else {

                    hsc_message( hp, MSG_REDEFINE_TAG,
                                 "can not redefine %T", tag );

                }

                del_dlnode( hp->deftag, nd );

            }

            /* create a new opening tag */
            tag = app_tag( taglist, nw );

        }
    } /* err_eof already called in infget_tagid() */

    /* convert tag name to upper  case */
    if ( tag )
        upstr( tag->name );

    return( tag );
}