示例#1
0
文件: mgilib2.c 项目: coecms/auscom
static int bwrite (int chan, void *buffer, int nelem, char *dtype)
     /* To fill the write buffer of initialized channel "chan". When
	the write buffer "chn[chan].buffer" is full, it will write the contents
	out to the data file related to the channel */
{
  int nb, i, j, msg;

  msg = send_command_to_server(chn[chan].gchannel, "WRITE");
#ifdef DEBUG
  printf("mgilib2::bwrite(), ==\n");
#endif

  if(*dtype == 'I' || *dtype == 'R')
    {
      nb = write_record(chn[chan].gchannel, (unsigned char *)buffer, nelem, sizeof(int));
      get_ack_nack(chn[chan].gchannel);
    }

  else if(*dtype == 'D')
    {
      nb = write_record(chn[chan].gchannel, (char *)buffer, nelem, sizeof(double));
      get_ack_nack(chn[chan].gchannel);

    }
  
  else if(*dtype == 'C')
    {
      nb = write_record(chn[chan].gchannel, buffer, nelem, 1);
      get_ack_nack(chn[chan].gchannel);
    }
  return nb;
}
示例#2
0
文件: mgilib2.c 项目: coecms/auscom
ftnword f77name (mgi_term) ()
     /* to remove the PID file, de-allocate memory */
{
  int chan, ier;
  for (chan = 1; chan < ichan; chan++)
    {
      ier = send_command_to_server(chn[chan].gchannel, "END");
      printf("mgi_term %s is closed \n", chn[chan].name);
 
     if (validchan(chan) == -1)
	{
	  printf("MGI_TERM ERROR: %d is an invalid channel number\n", chan);
	  exit(1);
	}
     if(chn[chan].buffer != NULL)
       {
	 free(chn[chan].buffer);
	 chn[chan].buffer = NULL;
       }

    }
  return ier;
}
示例#3
0
文件: main.c 项目: Skip/test
static void increment_upload(void)
{
    char tmp_file_name[19] = "/tmp/testXXXXXX";
    FILE *command_file = NULL;
    int file_id, uploaded = 5, delay, record, remainder;


    record = get_random_byte() % TOTAL_COMMANDS; /* choose record */

    file_id = make_tmp_file_name(tmp_file_name);
    if (file_id == -1) goto increment_upload_quit;

    command_file = fopen(tmp_file_name, "w");
    if (command_file == NULL) {
        printf("fopen() failed: %s\n", strerror(errno));
        unlink(tmp_file_name);
        goto increment_upload_quit;
    }
    fprintf(command_file, "%s", start_command[record]);
    fclose(command_file);

    if (send_command_to_server(tmp_file_name) == -1) goto increment_upload_quit;

    /* make random delay: 40 min <= delay <= 55 mins */
    delay = (get_random_byte() & 0x0f) + 40;
    printf("delay between start and stop packets %d mins\n", delay);
    delay *= 60; /* to seconds */
    remainder = delay;
    do {
        remainder = sleep(remainder);
        if (remainder) printf("program exit in %d mins\n", remainder / 60);
    } while (remainder);

    /* make random upload size: 5 Mb <= size <= 15 Mb */
    uploaded = get_random_byte() & 0x0f;
    if (uploaded < 5) uploaded += 5;
    printf("uploaded %d Mb\n", uploaded);
    uploaded *= (1024 * 1024); /* to bytes */

    memset(&tmp_file_name[12], 'X', sizeof(char) * 6);
    file_id = make_tmp_file_name(tmp_file_name);
    if (file_id == -1) goto increment_upload_quit;

    command_file = fopen(tmp_file_name, "w");
    if (command_file == NULL) {
        printf("fopen() failed: %s\n", strerror(errno));
        unlink(tmp_file_name);
        goto increment_upload_quit;
    }
    fprintf(command_file, "%s%d%s", stop_command1[record],
            uploaded, stop_command2[record]);
    fclose(command_file);

    if (send_command_to_server(tmp_file_name) == -1) goto increment_upload_quit;

    log_data(uploaded / (1024 * 1024), delay / 60, record);

    return;

increment_upload_quit:

    log_message("error, stage not completed");
}
示例#4
0
文件: mgilib2.c 项目: coecms/auscom
ftnword f77name (mgi_read) (ftnword *f_chan, void *buffer, ftnword *f_nelem, char *dtype, int ltype)

     /* to read elements directly from the data file related to the 
	specified channel into "buffer". The channel must be opened for 
	READMODE only.
	The following types of data (dtype) are accepted:
	'I': integer (int)
	'R': real    (float)
	'D': real*8  (double)
     */
{
  int i, ier, nb, chan, nelem, msg;

  /* int *ibuf = (int *) buffer; */
  int *ibuf;
  float *fbuf = (float *) buffer;
  ftnword *lbuf = (ftnword *) buffer;
  double *dbuf = (double *) buffer;
  char * cbuf = (char *) buffer;;

  chan = (int) *f_chan;
  nelem = (int) *f_nelem;
  
  msg = send_command_to_server(chn[chan].gchannel, "READ");
  

  if (*dtype == 'I')
    { /* integer */
      ibuf = (int *)malloc(nelem*sizeof(int));

      ibuf = (int *)read_record(chn[chan].gchannel, ibuf, &nelem, nelem, sizeof(int));
      get_ack_nack(chn[chan].gchannel);
      fprintf(stderr, "MGI_READ, case: \"Integer\", elts Nbr = %d, channel = %s\n", nelem, chn[chan].name);
      
      for(i = 0; i < nelem; i++) 
	((int *)buffer)[i] = ibuf[i];

    }

  else if (*dtype == 'R')
    { /* float */
      fbuf = (float *)malloc(nelem*sizeof(int));
      fprintf(stderr, "MGI_READ, case 1: \"Real\", elts Nbr = %d, channel = %s\n", nelem, chn[chan].name);
	  fbuf = (float *)read_record(chn[chan].gchannel, fbuf, &nelem, nelem, sizeof(int));
	  get_ack_nack(chn[chan].gchannel);

	  for(i = 0; i < nelem; i++) 
	    ((float *)buffer)[i] = fbuf[i];
	
    }
  else if (*dtype == 'D')
    { /* double */
      dbuf = (double *)malloc(nelem*sizeof(double));
      dbuf = (double *)read_record(chn[chan].gchannel, dbuf, &nelem, nelem, sizeof(double));
      fprintf(stderr, "MGI_READ, case: \"Double, 1\", Element's Nbr = %d, channel = %s\n", nelem, chn[chan].name);
      get_ack_nack(chn[chan].gchannel);
      
      for(i = 0; i < nelem; i++) 
	((double *)buffer)[i] = dbuf[i];
    }

  else if (*dtype == 'C')
    { /* character */
      cbuf = (char *)malloc(nelem*sizeof(char));
      cbuf = (char *)read_record(chn[chan].gchannel, cbuf, &nelem, nelem, sizeof(char));
      
      get_ack_nack(chn[chan].gchannel);
      
      for(i = 0; i < nelem; i++) 
	((char *)buffer)[i] = cbuf[i];

      fprintf(stderr, "MGI_READ, case: 'Character', elts Nbr = %d, channel = %s \n", nelem, chn[chan].name);   
    }
  
  else
    {
      printf("MGI_READ: ERROR on channel %s: Unknown data type: %c\n", chn[chan].name, *dtype);
      exit(1);
    }

  ier = chn[chan].nblks;
  return ier;
}