Beispiel #1
1
void free_chk_fix(int *itemp,int index,BUILD_INTRA *build_intra,
    int jmol_typ, int iresidue)

  /*==========================================================================*/
  /*      Begin Routine */
{ /* begin routine */
  /*==========================================================================*/
  /*      Local Variable Declarations */

  int mask; 

  int natmind_1res_now = build_intra->natmind_1res_now;
  int *mask_atm        = build_intra->mask_atm;
  int *index_atm       = build_intra->index_atm;

  /*==========================================================================*/
  /* I) Check range of index */

  if(index>natmind_1res_now){
    PRINTF("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n");
    PRINTF("Free energy atom index out of range  \n");
    PRINTF("in the residue number %d of molecule number %d\n",
        iresidue,jmol_typ);
    PRINTF("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n");
    FFLUSH(stdout);
    EXIT(1);
  }/*endif*/

  /*==========================================================================*/
  /* II) Get and check mask of index */

  mask = mask_atm[index];
  if(mask==0){
    PRINTF("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n");
    PRINTF("Free energy atom has been nuked \n");
    PRINTF("in residue number %d of molecule number %d \n",
        iresidue,jmol_typ);
    PRINTF("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n");
    FFLUSH(stdout);
    EXIT(1);
  }/*endif*/

  /*==========================================================================*/
  /* III) Get rejiggered index       */

  *itemp = index_atm[index];

  /*==========================================================================*/
}/*end routine */
Beispiel #2
0
  void run() {
    suspendCallerUntil(3*SECONDS);

    xprintf("\nPriority ceiler 122 times normal\n");
    for (long long cnt = 0; cnt < 1220000LL; cnt++) {
      if(cnt % 10000 == 0) {
	xprintf("+"); FFLUSH();
      }
    }

    xprintf("\nPriority ceiler 122 tmes prio ceiling\n");
    PRIORITY_CEILING {
    	for (long long cnt = 0; cnt < 1220000LL; cnt++) {
    		if (cnt % 10000 == 0) {
    			xprintf("+"); FFLUSH();
    		}
    	}
    }

    xprintf("\nPriority ceiler 122 times normal\n");
    for (long long cnt = 0; cnt < 1220000LL; cnt++) {
      if(cnt % 10000 == 0) {
        xprintf("+"); FFLUSH();
      }
     }

     xprintf("\nPriority ceiler terminates\n");
     while(1) {
       suspendCallerUntil();
     }
  }
Beispiel #3
0
/*
 *	local exit function
 */
static void userproc_exit (int exit_status, bool dump_core) 
{
	if (RTS_TRACING) {
		MESSAGE ("USERPROC: Exit %d\n", exit_status);
		FFLUSH (stderr);
	}

	if (RTS_TRACING) {
		MESSAGE ("USERPROC: About to kill KBDPROC\n");
		FFLUSH (stderr);
	}

	#if defined(RMOX_BUILD) && defined(BLOCKING_SYSCALLS)
	bsyscalls_destroy_clones ();
	#endif

	if (exit_status) {
		ccsp_show_last_debug_insert ();
	}

	#ifdef DM_DEBUG
	dm_debug_dump ();
	#endif
	dmem_shutdown ();

	ccsp_exit_handler (exit_status, dump_core);
}
Beispiel #4
0
static void *highpri_thread(void *parameter)
{
	int threadno = (int)parameter;
	int ret;

	g_highstate[threadno - 1] = RUNNING;

	printf("highpri_thread-%d: Started\n", threadno);
	FFLUSH();
	sleep(1);

	printf("highpri_thread-%d: Calling sem_wait()\n", threadno);
	g_highstate[threadno - 1] = WAITING;
	ret                     = sem_wait(&g_sem);
	g_highstate[threadno - 1] = DONE;

	if (ret != 0) {
		printf("highpri_thread-%d: sem_take failed: %d\n", threadno, ret);
	} else if (g_middlestate == RUNNING) {
		printf("highpri_thread-%d: SUCCESS midpri_thread is still running!\n", threadno);
	} else {
		printf("highpri_thread-%d: ERROR --  midpri_thread has already exited!\n", threadno);
	}

	sem_post(&g_sem);
	printf("highpri_thread-%d: Okay... I'm done!\n", threadno);
	FFLUSH();
	return NULL;
}
Beispiel #5
0
static void *barrier_func(void *parameter)
{
	int id = (int)parameter;
	int status;

	printf("barrier_func: Thread %d started\n",  id);
#ifndef CONFIG_DISABLE_SIGNALS
	usleep(HALF_SECOND);
#endif

	/* Wait at the barrier until all threads are synchronized. */

	printf("barrier_func: Thread %d calling pthread_barrier_wait()\n", id);
	FFLUSH();
	status = pthread_barrier_wait(&barrier);
	if (status == 0) {
		printf("barrier_func: Thread %d, back with status=0 (I am not special)\n", id);
	} else if (status == PTHREAD_BARRIER_SERIAL_THREAD) {
		printf("barrier_func: Thread %d, back with status=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)\n", id);
	} else {
		printf("barrier_func: ERROR thread %d could not get semaphore value\n", id);
	}
	FFLUSH();

#ifndef CONFIG_DISABLE_SIGNALS
	usleep(HALF_SECOND);
#endif
	printf("barrier_func: Thread %d done\n",  id);
	FFLUSH();
	return NULL;
}
Beispiel #6
0
  void run() {
    suspendCallerUntil(3*SECONDS);
    int64_t aproxLoopsFor3Seconds = getSpeedKiloLoopsPerSecond() * 1500LL;
    int64_t aproxLoopsForPrint = aproxLoopsFor3Seconds / 80;

    xprintf("\nPriority ceiler 122 times normal\n");
    for (int64_t cnt = 0; cnt < aproxLoopsFor3Seconds; cnt++) {
      if(cnt % aproxLoopsForPrint == 0) {
	xprintf("-"); FFLUSH();           
      }
    }

    xprintf("\nPriority ceiler 122 tmes prio ceiling\n");
    PRIORITY_CEILING {
    	for (int64_t cnt = 0; cnt < aproxLoopsFor3Seconds; cnt++) {
    		if (cnt % aproxLoopsForPrint == 0) {
    			xprintf("-"); FFLUSH();           
    		}
    	}
    }

    xprintf("\nPriority ceiler 122 times normal\n");
    for (int64_t cnt = 0; cnt < aproxLoopsFor3Seconds; cnt++) {
      if(cnt % aproxLoopsForPrint == 0) {
        xprintf("-"); FFLUSH();           
      }
     }

    xprintf("\nPriority ceiler 122 tmes atomarLock\n");
    globalAtomarLock(); 
    	for (int64_t cnt = 0; cnt < aproxLoopsFor3Seconds; cnt++) {
    		if (cnt % aproxLoopsForPrint == 0) {
    			xprintf("-"); FFLUSH();           
    		}
    	}
    globalAtomarUnlock();

    xprintf("\nPriority ceiler 122 times normal\n");
    for (int64_t cnt = 0; cnt < aproxLoopsFor3Seconds; cnt++) {
      if(cnt % aproxLoopsForPrint == 0) {
        xprintf("-"); FFLUSH();           
      }
     }


     xprintf("\nPriority ceiler terminates\n");
     while(1) {
       suspendCallerUntil();
     }
  }
Beispiel #7
0
/*{{{  void ccsp_user_process_init (void)*/
bool ccsp_user_process_init (void)
{
	#if defined(TARGET_OS_DARWIN)
	{
		struct clockinfo clockrate;
		size_t len = sizeof(clockrate);
		int mib[2] = { CTL_KERN, KERN_CLOCKRATE };
		
		clockrate.tick = 0;
		sysctl (mib, 2, &clockrate, &len, 0, 0);

		quantum = clockrate.tick;
	}
	#elif defined(HZ) || defined(SOLARIS_TIMER_BUG)
	quantum = 1000000U / HZ;
	#elif !defined(RMOX_BUILD)
	quantum = 0;
	#endif

	#if !defined(RMOX_BUILD)
	setup_min_sleep ();

	if (!set_user_process_signals ()) {
		return false;
	}
	#endif

	if (RTS_TRACING) {
		MESSAGE ("USERPROC: synchronised ok\n");
		FFLUSH (stderr);
	}

	return true;
}
Beispiel #8
0
/*==========================================================================*/
void *crealloc(void *ptr,size_t len,const char *func_name)
{ /* begin routine */
  void *mem_ptr;
  double request;

  if(len==0){
    fftw_free(ptr);
    return NULL;
  }

  mem_ptr = realloc(ptr,len);
  if(mem_ptr == NULL) {
    request = ((double) len)*1.0e-6;
    PRINTF("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n");
    PRINTF("Dude, like your reallocating %g MBytes\n",request);
    PRINTF("of memory -- get real (address was %p)\n\n",ptr);
    PRINTF("Error occurred in function %s\n",func_name);
    PRINTF("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n");
    FFLUSH(stdout);
    EXIT(1);
  }

  return mem_ptr;

} /* end routine */
Beispiel #9
0
/*{{{  static void set_error_flag (int erfl)*/
static void set_error_flag (int erfl)
{       
	if (erfl) {
		BMESSAGE ("error flag set\n");
		FFLUSH (stderr);
	}
}
Beispiel #10
0
 void run() {
   while(1) {
     xprintf("*");
     FFLUSH();
     suspendCallerUntil();
   }
 }
Beispiel #11
0
void log_status_skip(LogInstance instance, const gchar *format, ...)
{
	va_list args;
	gchar buf[BUFFSIZE + LOG_TIME_LEN];
	time_t t;
	LogText *logtext = g_new0(LogText, 1);
	struct tm buft;

	time(&t);
	strftime(buf, LOG_TIME_LEN + 1, "[%H:%M:%S] ", localtime_r(&t, &buft));

	va_start(args, format);
	g_vsnprintf(buf + LOG_TIME_LEN, BUFFSIZE, format, args);
	va_end(args);

	if (debug_get_mode()) g_message("%s", buf + LOG_TIME_LEN);

	logtext->instance = instance;
	logtext->text = g_strdup(buf + LOG_TIME_LEN);
	logtext->type = LOG_STATUS_SKIP;
	
	g_timeout_add(0, invoke_hook_cb, logtext);

	if (log_fp[instance] && prefs_common_enable_log_status()) {
		FWRITE(buf, 1, LOG_TIME_LEN, log_fp[instance])
		FPUTS("* SKIPPED: ", log_fp[instance])
		log_size[instance] += strlen("* SKIPPED: ");
		FPUTS(buf + LOG_TIME_LEN, log_fp[instance])
		log_size[instance] += strlen(buf);
		FFLUSH(log_fp[instance])
		rotate_log(instance);
	}
}
Beispiel #12
0
int repl_log(FILE *fp, boolean_t stamptime, boolean_t flush, char *fmt, ...)
{
	va_list printargs;
	char	time_str[CTIME_BEFORE_NL + 2]; /* for GET_CUR_TIME macro */
	char	fmt_str[BUFSIZ];
	int	rc;

	assert(NULL != fp);
	if (stamptime)
	{
		GET_CUR_TIME(time_str);
		strcpy(fmt_str, time_str);
		fmt_str[CTIME_BEFORE_NL] = ' '; /* Overwrite \n */
		fmt_str[CTIME_BEFORE_NL + 1] = ':';
		fmt_str[CTIME_BEFORE_NL + 2] = ' ';
		strcpy(fmt_str + CTIME_BEFORE_NL + 3, fmt);
		fmt = &fmt_str[0];
	}

	va_start(printargs, fmt);
	VFPRINTF(fp, fmt, printargs, rc);
	assert(0 <= rc);
	va_end(printargs);

	if (flush)
		FFLUSH(fp);

	return(SS_NORMAL);
}
Beispiel #13
0
/*{{{  void user_trap_handler (int sig, int code, struct sigcontext *scp, char *addr)*/
void user_trap_handler (int sig, int code, struct sigcontext *scp, char *addr)
{
	/*      fprintf (stderr, "sig = 0x%x, code = 0x%x\n", sig, code);       */
	BMESSAGE ("");
	switch (code & 0x1f) {           /* why? */
	case _SETERR:
		MESSAGE ("Set error");
		break;
	case _OFLOW:
		MESSAGE ("Integer overflow");
		break;
	case _RANGE:
		MESSAGE ("Range error");
		break;
	case _FLOAT:
		MESSAGE ("Floating-point error");
		break;
	case _UNREC:
		MESSAGE ("Unrecognized instruction");
		break;
	case _UNIMP:
		MESSAGE ("Unimplemented instruction");
		break;
	default:
		MESSAGE ("Unrecognized trap number 0x%x", code & 0x1f);
		break;
	}
	MESSAGE ("\n");
	FFLUSH (stderr);
	userproc_exit (code, 1);
} /* user_trap_handler */
Beispiel #14
0
void
failed(const char *s)
{
    FFLUSH(stdout);
    perror(s);
    exit(FAIL);
    /*NOTREACHED */
}
Beispiel #15
0
/*{{{  void ccsp_dead (int erfl)*/
void ccsp_dead (int erfl)
{       
	MESSAGE0 ("\n");
	BMESSAGE ("program deadlocked (no processes to run)\n");
	FFLUSH (stderr);              /* still in raw mode */
	set_error_flag (erfl);
	userproc_exit (2, 0);
}
Beispiel #16
0
static int waiter_main(int argc, char *argv[])
{
  sigset_t set;
  struct sigaction act;
  int ret;
  int i;

  printf("waiter_main: Waiter started\n" );
  printf("waiter_main: Setting signal mask\n" );

  (void)sigemptyset(&set);
  ret = sigprocmask(SIG_SETMASK, &set, NULL);
  if (ret < 0)
    {
      printf("waiter_main: ERROR sigprocmask failed: %d\n", errno);
      return EXIT_FAILURE;
    }

  printf("waiter_main: Registering signal handler\n" );

  act.sa_handler = waiter_action;
  act.sa_flags   = 0;

  (void)sigemptyset(&act.sa_mask);
  for (i = 1; i < MAX_SIGNO; i += 2)
    {
      (void)sigaddset(&act.sa_mask, i);
    }

  for (i = 1; i < MAX_SIGNO; i++)
    {
      ret = sigaction(i, &act, NULL);
      if (ret < 0)
        {
          printf("waiter_main: ERROR sigaction failed\n" , errno);
          return EXIT_FAILURE;
        }
    }

  /* Now just loop until the test completes */

  printf("waiter_main: Waiting on semaphore\n" );
  FFLUSH();

  g_waiter_running = true;
  while (!g_done)
    {
      ret = sem_wait(&g_waiter_sem);
    }

  /* Just exit, the system should clean up the signal handlers */

  g_waiter_running = false;
  return EXIT_SUCCESS;
}
Beispiel #17
0
static
void InitInstList(void)
{
  unsigned long c;
  for (c=0; c<MAXIMUM_INST_DEPTH; c++) {
    g_instlist[c] = NULL;
  }
  g_depth = 0;
  FPRINTF(ASCERR,"g_instlist initialized\n");
  FFLUSH(ASCERR);
}
Beispiel #18
0
static void *medpri_thread(void *parameter)
{
	printf("medpri_thread: Started ... I won't let go of the CPU!\n");
	g_middlestate = RUNNING;
	FFLUSH();

	/* The following loop will completely block lowpri_thread from running.
	 * UNLESS priority inheritance is working.  In that case, its priority
	 * will be boosted.
	 */

	while (nhighpri_running() > 0) {
		hog_cpu();
	}

	printf("medpri_thread: Okay... I'm done!\n");
	FFLUSH();
	g_middlestate = DONE;
	return NULL;
}
Beispiel #19
0
  void run(){
    long long cnt = 0;
    while(1) {
      cnt++;
      if (cnt % 1000000 == 0) {
        xprintf("."); 
        FFLUSH();
      }
      if (cnt % 10000000 == 0) {
	      highPriorityThread01.resume();
      }
    }
  }
Beispiel #20
0
void PRINTF_CONDITIONAL(int negligibleLevel, const char* fmt, ...) {
    if(negligibleLevel > printfVerbosity) return;
    Yprintf yprintf;
    va_start(yprintf.ap, fmt);
    if (errorCounter != 0) xprintf("prev-ERR(%ld) -- ", errorCounter);
    if (!Scheduler::isSchedulerRunning()) {
        yprintf.vaprintf(fmt);
    } else {
        printfProtector.enter();
            yprintf.vaprintf(fmt);
        printfProtector.leave();
    }
    FFLUSH();
}
Beispiel #21
0
void PRINTF(const char* fmt, ...) {
    if(printfVerbosity == 0) return;
    Yprintf yprintf;
    va_start(yprintf.ap, fmt);
    if (errorCounter != 0) xprintf("prev-ERR(%ld) -- ", errorCounter);
    if (!Scheduler::isSchedulerRunning()) {
        yprintf.vaprintf(fmt);
    } else {
        printfProtector.enter();
            yprintf.vaprintf(fmt);
        printfProtector.leave();
    }
    FFLUSH();
}
Beispiel #22
0
    void run() {
        while(1) {

            //incrementCounter.enter();
            if(strcmp(name,"1")) {
                firstCounter += 50;
            } else {
                secondCounter += 50;
            }
            globalCount += 50;
            //incrementCounter.leave();

            xprintf("Process %s called.\n Sum: %ld, globalCount: %ld, Diff: %ld\n",name,firstCounter + secondCounter,globalCount, firstCounter + secondCounter - globalCount);
            FFLUSH();
        }
    }
Beispiel #23
0
/*{{{  void ccsp_default_exit_handler (int status, bool core)*/
void ccsp_default_exit_handler (int status, bool core)
{
	#if defined(GENERATE_CORES)
	if (core) {
		MESSAGE ("fatal error code %d, core dumped\n", exit_status);
		FFLUSH (stderr);
		abort ();
	}
	#endif

	#if !defined(RMOX_BUILD)
	_exit (status);
	#else
	panic ("exiting CCSP");
	#endif
}
Beispiel #24
0
static int interfere_main(int argc, char *argv[])
{
  /* Now just loop staying in the way as much as possible */

  printf("interfere_main: Waiting on semaphore\n" );
  FFLUSH();

  g_interferer_running = true;
  while (!g_done)
    {
      (void)sem_wait(&g_interferer_sem);
    }

  /* Just exit, the system should clean up the signal handlers */

  g_interferer_running = false;
  return EXIT_SUCCESS;
}
Beispiel #25
0
static
unsigned long ChildNumberbyChar(struct Instance *i, char *name)
{
  struct InstanceName rec;
  symchar *sym;
  unsigned long c = 0;
  unsigned long nch = 0;
  long iindex;

  if((!i)||(!name)) {
    FPRINTF(ASCERR,"Null Instance or name in ChildbyNameChar\n");
    FFLUSH(ASCERR);
    return 0;
  }
  nch = NumberChildren(i);
  sym = AddSymbol(name);
  if(!nch) {
    return 0;
  }
  do {
    c++;
    rec = ChildName(i,c);
    switch (InstanceNameType(rec)) {
    case StrName:
      if (CmpSymchar(InstanceNameStr(rec), sym)==0) {
        return c;
      }
      break;
    case IntArrayIndex:
      iindex = atol(name); /* fixme strtod */
      if (iindex==InstanceIntIndex(rec)) {
        return c;
      }
      break;
    case StrArrayIndex:
      if (CmpSymchar(InstanceStrIndex(rec), sym)==0) {
        return c;
      }
      break;
    }
  } while(c < nch);
  return 0; /*NOTREACHED*/
}
Beispiel #26
0
/*
 *	timer signal (SIGALRM) handler
 *	SIGALRM  handler - only set during hibernate
 */
static void user_tim_handler (int sig)
{
	int threads = att_val (&enabled_threads);
	
	if (RTS_TRACING) {
		MESSAGE ("USERPROC: Alarm ringing (SIGALRM).\n");
		FFLUSH (stderr);
	}

	while (threads) {
		int n 		= bsf (threads);
		sched_t *s 	= schedulers[n];

		threads &= ~(s->id);

		ccsp_wake_thread (s, SYNC_TIME_BIT);
	}
	
	#if defined(SIGNAL_TYPE_SYSV)
		signal (SIGALRM, user_tim_handler);
	#endif /* SIGNAL_TYPE */
}
Beispiel #27
0
/*==========================================================================*/
void *cmalloc(size_t len,const char *func_name)
{ /* begin routine */
  void *mem_ptr;
  double request;

  if(len == 0) return NULL;
  mem_ptr = fftw_malloc(len);
  if(mem_ptr == NULL) {
    request = ((double) len)*1.0e-6;
    PRINTF("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n");
    PRINTF("Dude, like you've just requested %g MBytes\n",request);
    PRINTF("of memory -- get real\n\n");
    PRINTF("Error occurred in function %s\n",func_name);
    PRINTF("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n");
    FFLUSH(stdout);
    EXIT(1);
  }

  memset(mem_ptr,0,len);

  return mem_ptr;

} /* end routine */
Beispiel #28
0
FILE *cfopen(const char file_name[],const char *mode)

  /*==========================================================================*/
{  /* begin routine */
  FILE *fp;
#ifdef DEBUG
  LINE line;
#endif

  /*==========================================================================*/
  /* File name check */ 

  if(strlen(file_name)==0){
    PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    PRINTF("Error, requesting a file pointer with no filename!\n");
    PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    FFLUSH(stdout);
    EXIT(1);
  }/*endif*/

  /*==========================================================================*/
  /* Write to a file  */ 

  if(mode[0] == 'w'){
    if((fp=fopen(file_name,"r")) != NULL){
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      PRINTF("ERROR: %s already exists! (exiting)\n",file_name);
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      FFLUSH(stdout);
      EXIT(1);
    }/*endif*/
    if((fp=fopen(file_name,"w")) == NULL){
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      PRINTF("ERROR: can't open \"%s\" for writing (exiting)\n",file_name);
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      FFLUSH(stdout);
      EXIT(1);
    }/*endif*/
  }/*endif*/

  /*==========================================================================*/
  /* Overwrite a file  */ 

  if(mode[0] == 'o'){
    if((fp=fopen(file_name,"w")) == NULL){
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      PRINTF("ERROR: can't open \"%s\" for writing (exiting)\n",file_name);
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      FFLUSH(stdout);
      EXIT(1);
    }/*endif*/
  }/*endif*/

  /*==========================================================================*/
  /* Read from a file  */ 

  if(mode[0] == 'r'){
    if((fp=fopen(file_name,"r")) == NULL){
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      PRINTF("ERROR: can't open \"%s\" for reading (exiting)\n",file_name);
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      FFLUSH(stdout);
      EXIT(1);
    }/*endif*/
  }/*endif*/

  /*==========================================================================*/
  /* Append to a file  */ 

  if(mode[0] == 'a'){
    if((fp=fopen(file_name,"a")) == NULL){
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      PRINTF("ERROR: can't open \"%s\" for appending (exiting)\n",file_name);
      PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
      FFLUSH(stdout);
      EXIT(1);
    }/*endif*/
  }/*endif*/

#ifdef DEBUG
  PRINTF("name = %s\n",file_name);
  fgets(line,MAXLINE,fp);
  PRINTF("line (%p): %s\n",fp,line);
  rewind(fp);
#endif

  /*==========================================================================*/

  if(fp == NULL){
    PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    PRINTF("ERROR: Null file pointer created for file %s\n",file_name);
    PRINTF("ERROR: Using mode %s\n",mode);
    PRINTF("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
    FFLUSH(stdout);
    EXIT(1);
  }/*endif*/

  return fp;

  /*--------------------------------------------------------------------------*/
}/* end routine */
Beispiel #29
0
int ftpc_main(int argc, char **argv, char **envp)
{
  struct ftpc_connect_s connect = {{0}, 0};
  SESSION handle;
  FAR char *ptr;
#ifndef CONFIG_EXAMPLES_FTPC_FGETS
  int ret;
#endif

  if (argc != 2)
    {
      printf("Usage:\n");
      printf("   %s xx.xx.xx.xx[:pp]\n", argv[0]);
      printf("Where\n");
      printf("  xx.xx.xx.xx is the IP address of the FTP server\n");
      printf("  pp is option port to use with the FTP server\n");
      exit(1);
    }

  /* Check if the argument includes a port number */

  ptr = strchr(argv[1], ':');
  if (ptr)
    {
      *ptr = '\0';
      connect.port = atoi(ptr+1);
    }

  /* In any event, we can now extract the IP address from the comman-line */

  connect.addr.s_addr = inet_addr(argv[1]);

  /* Connect to the FTP server */

  handle = ftpc_connect(&connect);
  if (!handle)
    {
      printf("Failed to connect to the server: %d\n", errno);
      exit(1);
    }

  /* Present a greeting */

  printf("NuttX FTP Client:\n");
  FFLUSH();

  /* Setting optind to -1 is a non-standard, backdoor way to reinitialize
   * getopt().  getopt() is not thread safe and we have no idea what state
   * it is in now!
   */

  optind = -1;

  /* Then enter the command line parsing loop */

  for (;;)
    {
      /* Display the prompt string */

      fputs("nfc> ", stdout);
      FFLUSH();

      /* Get the next line of input */

#ifdef CONFIG_EXAMPLES_FTPC_FGETS
      /* fgets returns NULL on end-of-file or any I/O error */

      if (fgets(g_line, CONFIG_FTPC_LINELEN, stdin) == NULL)
        {
          printf("ERROR: fgets failed: %d\n", errno);
          return 1;
        }
#else
      ret = readline(g_line, CONFIG_FTPC_LINELEN, stdin, stdout);

      /* Readline normally returns the number of characters read,
       * but will return EOF on end of file or if an error occurs.
       * Either will cause the session to terminate.
       */

      if (ret == EOF)
        {
          printf("ERROR: readline failed: %d\n", errno);
          return 1;
        }
#endif
      else
        {
          /* Parse and process the command */

          (void)ftpc_parse(handle, g_line);
          FFLUSH();
        }
    }

  return 0;
}
Beispiel #30
0
int convert_slice(slice *slicei, int *thread_index) {

    char slicefile_svz[1024], slicesizefile_svz[1024];
    int fileversion, one, zero;
    char *slice_file;
    int version_local;
    char filetype[1024];
    char *shortlabel, *unit;
    char units[256];
    int ijkbar[6];
    uLong framesize;
    float *sliceframe_data=NULL;
    unsigned char *sliceframe_compressed=NULL, *sliceframe_uncompressed=NULL;
    unsigned char *sliceframe_compressed_rle=NULL, *sliceframe_uncompressed_rle=NULL;
    char cval[256];
    int sizebefore, sizeafter;
    int returncode;
    float minmax[2];
    float time_local;
    LINT data_loc;
    int percent_done;
    int percent_next=10;
    float valmin, valmax, denom;
    int chop_min, chop_max;
    uLongf ncompressed_zlib;
    int ncompressed_save;
#ifndef pp_THREAD
    int count=0;
#endif
    int ncol, nrow, idir;
    float time_max;
    int itime;
    LINT file_loc;

    FILE *SLICEFILE;
    FILE *slicestream,*slicesizestream;

#ifdef pp_THREAD
    if(GLOBcleanfiles==0) {
        int fileindex;

        fileindex = slicei + 1 - sliceinfo;
        sprintf(threadinfo[*thread_index].label,"sf %i",fileindex);
    }
#endif

    slice_file=slicei->file;
    version_local=slicei->version;

    fileversion = 1;
    one = 1;
    zero=0;

    // check if slice file is accessible

    strcpy(filetype,"");
    shortlabel=slicei->label.shortlabel;
    if(strlen(shortlabel)>0)strcat(filetype,shortlabel);
    trim(filetype);

    if(getfileinfo(slice_file,NULL,NULL)!=0) {
        fprintf(stderr,"*** Warning: The file %s does not exist\n",slice_file);
        return 0;
    }

    SLICEFILE=fopen(slice_file,"rb");
    if(SLICEFILE==NULL) {
        fprintf(stderr,"*** Warning: The file %s could not be opened\n",slice_file);
        return 0;
    }

    // set up slice compressed file

    if(GLOBdestdir!=NULL) {
        strcpy(slicefile_svz,GLOBdestdir);
        strcat(slicefile_svz,slicei->filebase);
    }
    else {
        strcpy(slicefile_svz,slicei->file);
    }
    {

        char *ext;
        int lensvz;

        lensvz = strlen(slicefile_svz);

        if(lensvz>4) {
            ext = slicefile_svz + lensvz - 4;
            if(strcmp(ext,".rle")==0) {
                slicefile_svz[lensvz-4]=0;
            }
            strcat(slicefile_svz,".svz");
        }
    }

    if(GLOBdestdir!=NULL) {
        strcpy(slicesizefile_svz,GLOBdestdir);
        strcat(slicesizefile_svz,slicei->filebase);
    }
    else {
        strcpy(slicesizefile_svz,slicei->file);
    }
    {

        char *ext;
        int lensvz;

        lensvz = strlen(slicesizefile_svz);

        if(lensvz>4) {
            ext = slicesizefile_svz + lensvz - 4;
            if(strcmp(ext,".rle")==0) {
                slicesizefile_svz[lensvz-4]=0;
            }
            strcat(slicesizefile_svz,".sz");
        }
    }

    if(GLOBcleanfiles==1) {
        slicestream=fopen(slicefile_svz,"rb");
        if(slicestream!=NULL) {
            fclose(slicestream);
            PRINTF("  Removing %s\n",slicefile_svz);
            UNLINK(slicefile_svz);
            LOCK_COMPRESS;
            GLOBfilesremoved++;
            UNLOCK_COMPRESS;
        }
        slicesizestream=fopen(slicesizefile_svz,"rb");
        if(slicesizestream!=NULL) {
            fclose(slicesizestream);
            PRINTF("  Removing %s\n",slicesizefile_svz);
            UNLINK(slicesizefile_svz);
            LOCK_COMPRESS;
            GLOBfilesremoved++;
            UNLOCK_COMPRESS;
        }
        return 0;
    }

    if(GLOBoverwrite_slice==0) {
        slicestream=fopen(slicefile_svz,"rb");
        if(slicestream!=NULL) {
            fclose(slicestream);
            fprintf(stderr,"*** Warning:  %s exists.\n",slicefile_svz);
            fprintf(stderr,"     Use the -f option to overwrite smokezip compressed files\n");
            return 0;
        }
    }

    slicestream=fopen(slicefile_svz,"wb");
    slicesizestream=fopen(slicesizefile_svz,"w");
    if(slicestream==NULL||slicesizestream==NULL) {
        if(slicestream==NULL) {
            fprintf(stderr,"*** Warning: The file %s could not be opened for writing\n",slicefile_svz);
        }
        if(slicesizestream==NULL) {
            fprintf(stderr,"  %s could not be opened for writing\n",slicesizefile_svz);
        }
        if(slicestream!=NULL)fclose(slicestream);
        if(slicesizestream!=NULL)fclose(slicesizestream);
        fclose(SLICEFILE);
        return 0;
    }

    // read and write slice header

    strcpy(units,"");
    unit=slicei->label.unit;
    if(strlen(unit)>0)strcat(units,unit);
    trim(units);
    sprintf(cval,"%f",slicei->valmin);
    trimzeros(cval);
#ifndef pp_THREAD
    if(GLOBcleanfiles==0) {
        PRINTF("Compressing %s (%s)\n",slice_file,filetype);
        PRINTF("  using min=%s %s",cval,units);
    }
#endif
    sprintf(cval,"%f",slicei->valmax);
    trimzeros(cval);
#ifndef pp_THREAD
    if(GLOBcleanfiles==0) {
        PRINTF(" max=%s %s\n",cval,units);
        PRINTF(" ");
    }
#endif
    valmin=slicei->valmin;
    valmax=slicei->valmax;
    denom = valmax-valmin;
    if(denom==0.0)denom=1.0;

    chop_min=0;
    chop_max=255;
    if(GLOBno_chop==0) {
        if(slicei->setchopvalmax==1) {
            chop_max = 255*(slicei->chopvalmax-valmin)/denom;
            if(chop_max<0)chop_max=0;
            if(chop_max>255)chop_max=255;
        }
        if(slicei->setchopvalmin==1) {
            chop_min = 255*(slicei->chopvalmin-valmin)/denom;
            if(chop_min<0)chop_min=0;
            if(chop_min>255)chop_min=255;
        }
    }


    fwrite(&one,4,1,slicestream);           // write out a 1 to determine "endianness" when file is read in later
    fwrite(&zero,4,1,slicestream);          // write out a zero now, then a one just before file is closed
    fwrite(&fileversion,4,1,slicestream);   // write out compressed fileversion in case file format changes later
    fwrite(&version_local,4,1,slicestream);       // fds slice file version
    sizeafter=16;

    //*** SLICE FILE FORMATS

    //*** FDS FORMAT (FORTRAN - each FORTRAN record has a 4 byte header and a 4 byte trailer surrounding the data)

    // 30 byte long label
    // 30 byte short label
    // 30 byte unit
    // i1,i2,j1,j2,k1,k2

    // for each time step:

    // time, compressed frame size
    // qq(1,nbuffer)              where nbuffer = (i2+1-i1)*(j2+1-j1)*(k2+1-k1)



    //*** ZLIB format (C - no extra bytes surrounding data)

    //*** header
    // endian
    // completion (0/1)
    // fileversion (compressed format)
    // version_local  (slicef version)
    // global min max (used to perform conversion)
    // i1,i2,j1,j2,k1,k2


    //*** frame
    // time, compressed frame size                        for each frame
    // compressed buffer


    //*** RLE format (FORTRAN)

    //*** header
    // endian
    // fileversion, slice version
    // global min max (used to perform conversion)
    // i1,i2,j1,j2,k1,k2


    //*** frame
    // time
    // compressed frame size                        for each frame
    // compressed buffer

    {
        int skip;

        skip = 3*(4+30+4);  // skip over 3 records each containing a 30 byte FORTRAN character string
        returncode=FSEEK(SLICEFILE,skip,SEEK_CUR);
        sizebefore=skip;
    }

    FORTSLICEREAD(ijkbar,6);
    sizebefore+=8+6*4;

    framesize =  (ijkbar[1]+1-ijkbar[0]);
    framesize *= (ijkbar[3]+1-ijkbar[2]);
    framesize *= (ijkbar[5]+1-ijkbar[4]);

    minmax[0]=slicei->valmin;
    minmax[1]=slicei->valmax;
    fwrite(minmax,4,2,slicestream);    // min max vals
    fwrite(ijkbar,4,6,slicestream);
    sizeafter+=(8+24);


    ncompressed_save=1.02*framesize+600;
    if(NewMemory((void **)&sliceframe_data,ncompressed_save*sizeof(float))==0)goto wrapup;
    if(NewMemory((void **)&sliceframe_compressed,ncompressed_save*sizeof(unsigned char))==0)goto wrapup;
    if(NewMemory((void **)&sliceframe_uncompressed,ncompressed_save*sizeof(unsigned char))==0)goto wrapup;

    fprintf(slicesizestream,"%i %i %i %i %i %i\n",ijkbar[0],ijkbar[1],ijkbar[2],ijkbar[3],ijkbar[4],ijkbar[5]);
    fprintf(slicesizestream,"%f %f\n",minmax[0],minmax[1]);

    idir=0;
    if(ijkbar[0]==ijkbar[1]) {
        idir=1;
        ncol = ijkbar[3] + 1 - ijkbar[2];
        nrow = ijkbar[5] + 1 - ijkbar[4];
    }
    else if(ijkbar[2]==ijkbar[3]) {
        idir=2;
        ncol = ijkbar[1] + 1 - ijkbar[0];
        nrow = ijkbar[5] + 1 - ijkbar[4];
    }
    else if(ijkbar[4]==ijkbar[5]) {
        idir=3;
        ncol = ijkbar[1] + 1 - ijkbar[0];
        nrow = ijkbar[3] + 1 - ijkbar[2];
    }
    if(idir==0) {
        idir=1;
        ncol = ijkbar[3] + 1 - ijkbar[2];
        nrow = ijkbar[5] + 1 - ijkbar[4];
    }


    {
        int ni, nj, nk;

        ni = ijkbar[1]+1-ijkbar[0];
        nj = ijkbar[3]+1-ijkbar[2];
        nk = ijkbar[5]+1-ijkbar[4];

        time_max=-1000000.0;
        itime=-1;
        for(;;) {
            int i;

            FORTSLICEREAD(&time_local,1);
            sizebefore+=12;
            if(returncode==0)break;
            FORTSLICEREAD(sliceframe_data,framesize);    //---------------
            if(returncode==0)break;

            sizebefore+=(8+framesize*4);
            if(time_local<time_max)continue;
            time_max=time_local;

#ifndef pp_THREAD
            count++;
#endif

            data_loc=FTELL(SLICEFILE);
            percent_done=100.0*(float)data_loc/(float)slicei->filesize;
#ifdef pp_THREAD
            threadinfo[*thread_index].stat=percent_done;
            if(percent_done>percent_next) {
                LOCK_PRINT;
                print_thread_stats();
                UNLOCK_PRINT;
                percent_next+=10;
            }
#else
            if(percent_done>percent_next) {
                PRINTF(" %i%s",percent_next,GLOBpp);
                FFLUSH();
                percent_next+=10;
            }
#endif
            for(i=0; i<framesize; i++) {
                int ival;
                int icol, jrow, index2;
                int ii,jj,kk;

                // val_in(i,j,k) = i + j*ni + k*ni*nj

                if(framesize<=ncol*nrow) { // only one slice plane

                    // i = jrow*ncol + icol;

                    icol = i%ncol;
                    jrow = i/ncol;

                    index2 = icol*nrow + jrow;
                }
                else {
                    ii = i%ni;
                    jj = (i/ni)%nj;
                    kk = i/(ni*nj);

                    index2 = ii*nj*nk + jj*nk + kk;
                }

                {
                    float val;

                    val = sliceframe_data[i];
                    if(val<valmin) {
                        ival=0;
                    }
                    else if(val>valmax) {
                        ival=255;
                    }
                    else {
                        ival = 1 + 253*(val-valmin)/denom;
                    }
                    if(ival<chop_min)ival=0;
                    if(ival>chop_max)ival=255;
                    sliceframe_uncompressed[index2] = ival;
                }
            }
            itime++;
            if(itime%GLOBslicezipstep!=0)continue;

            //int compress (Bytef *dest,   uLongf *destLen, const Bytef *source, uLong sourceLen);
            ncompressed_zlib=ncompressed_save;
            returncode=compress(sliceframe_compressed,&ncompressed_zlib,sliceframe_uncompressed,framesize);

            file_loc=FTELL(slicestream);
            fwrite(&time_local,4,1,slicestream);
            fwrite(&ncompressed_zlib,4,1,slicestream);
            fwrite(sliceframe_compressed,1,ncompressed_zlib,slicestream);
            sizeafter+=(8+ncompressed_zlib);
            fprintf(slicesizestream,"%f %i, %li\n",time_local,(int)ncompressed_zlib,(long)file_loc);
        }
        if(returncode!=0) {
            fprintf(stderr,"*** Error: compress returncode=%i\n",returncode);
        }
    }

wrapup:
#ifndef pp_THREAD
    PRINTF(" 100%s completed\n",GLOBpp);
#endif
    FREEMEMORY(sliceframe_data);
    FREEMEMORY(sliceframe_compressed);
    FREEMEMORY(sliceframe_uncompressed);
    FREEMEMORY(sliceframe_compressed_rle);
    FREEMEMORY(sliceframe_uncompressed_rle);

    fclose(SLICEFILE);
    FSEEK(slicestream,4,SEEK_SET);
    fwrite(&one,4,1,slicestream);  // write completion code
    fclose(slicestream);
    fclose(slicesizestream);

    {
        char before_label[256],after_label[256];

        getfilesizelabel(sizebefore,before_label);
        getfilesizelabel(sizeafter,after_label);
#ifdef pp_THREAD
        slicei->compressed=1;
        sprintf(slicei->summary,"compressed from %s to %s (%4.1f%s reduction)",before_label,after_label,(float)sizebefore/(float)sizeafter,GLOBx);
        threadinfo[*thread_index].stat=-1;
#else
        PRINTF("  records=%i, ",count);
        PRINTF("Sizes: original=%s, ",before_label);
        PRINTF("compressed=%s (%4.1f%s reduction)\n\n",after_label,(float)sizebefore/(float)sizeafter,GLOBx);
#endif
    }

    return 1;
}