Beispiel #1
0
int csr_start(int argc, char *argv[])
{

  int error;
  struct Parameter para;
  
  int N, NNZ;
  double *bvec, *xvec, *val;
  int *col, *ptr;
  double *Tval;
  int *Tcol, *Tptr;

  double *test;
  malloc_cuda_1d(10, test);
  free_cuda_1d(test);

  init_ver(&para);

  error = get_opt(argc, argv, &para);
  if(error_handle(error, (char*)"error in get_cmd")!=0)
    return -1;

  error = check_opt(&para);
  if(error_handle(error, (char*)"error in check_cmd")!=0)
    return -1;

  error = find_mat(&para);
  if(error_handle(error, (char*)"error in find_mat")!=0)
    return -1;

  show_opt(&para);

  error = set_openmp_thread(para.i_thread);
  if(error_handle(error, (char*)"error in set_openmp_thread")!=0)
    return -1;

  error = get_mat_head(&para, &N, &NNZ);
  if(error_handle(error, (char*)"error in get_mat_head")!=0)
    return -1;

  if( para.f_cuda == false )
  {
    bvec = malloc_1d(N);
    xvec = malloc_1d(N);

    val = malloc_1d(NNZ);
    col = malloc_1i(NNZ);
    ptr = malloc_1i(N+1);

    Tval=malloc_1d(NNZ);
    Tcol=malloc_1i(NNZ);
    Tptr=malloc_1i(N+1);
  }else{
    error_log((char*)"Cuda not done now");
    return -1;
  }


  error = get_mat_data(&para, col, ptr, val, bvec, xvec, N, NNZ);
  if(error_handle(error, (char*)"error in get_mat_data")!=0)
    return -1;

  //A^T
  Transpose_d(val, col, ptr, Tval, Tcol, Tptr, N, NNZ);

  error = outer_selecter(&para, bvec, xvec, val, col, ptr, Tval, Tcol, Tptr, N, NNZ);
  if(error_handle(error, (char*)"error in outer_selecter")!=0)
    return -1;

  show_opt(&para);

  if( para.f_cuda == false )
  {
    free_1d(bvec);
    free_1d(xvec);

    free_1d(val);
    free_1i(col);
    free_1i(ptr);

    free_1d(Tval);
    free_1i(Tcol);
    free_1i(Tptr);
  }else{
    error_log((char*)"Cuda not done now");
    return -1;
  }
  return 0;
}
Beispiel #2
0
// メイン関数
int main( int argc, char *argv[] )
{
	FILE	*fp = NULL;
	char	*s;
	int		i;
	int		file_open	= 0;	// ファイルオープン確認フラグ

	// option解析
	for(i = 1; i < argc; i++){
		if(argv[i][0] == '-'){
			if(argv[i][1] == 't')
				g_thread = strtol(argv[i] + 2, &s, 10);
			else if(argv[i][1] == 'r')
				g_auto_repair = 1;
			else if(argv[i][1] == 'l')
				g_rotation = strtol(argv[i] + 2, &s, 10) + 1;
			else if(argv[i][1] == 'd')
				g_debug_mode = 1;
			else if(argv[i][1] == 'h'){
				switch(argv[i][2]) {
				case 'c':
					g_console = CONSOLE_COLORGAMEBOY; break;
				case 'g':
					g_console = CONSOLE_GAMEBOY; break;
				case 'n':
					g_console = CONSOLE_NEOGEOPOCKETCOLOR; break;
				case 'w':
					g_console = CONSOLE_SWANCRYSTAL; break;
				case 'p':
					g_console = CONSOLE_PIECE; break;
				case 's':
					g_console = CONSOLE_GAMEGEAR; break;
				default:
					printf("パラメータがおかしい = %c\n", argv[i][2]);
					show_opt(fp, argv[0]);
					break;
				}
			}
			else if(argv[i][1] == 'v')
				show_opt(fp, argv[0]);
			else {
				printf("パラメータがおかしい = %s\n", argv[i]);
				show_opt(fp, argv[0]);
			}
		}
		else if(file_open == 0){
			fp = fopen( argv[i], "rb");    /* ファイルオープン(読み込みモード) */
			if(fp == NULL){        /* オープン失敗 */
				printf("ファイルがオープンできません\n");
				exit(-1);
			}
			else file_open = 1;
		}
	}

	if (fp == NULL) show_opt(fp, argv[0]);

	// 変数への初期設定
	if (g_console == 0) show_opt(fp, argv[0]);	// ハード選択必須
	g_thread	= check_thread(g_thread);
	g_rotation	= check_rotation(g_rotation);
	set_xy(g_rotation);

	// 情報出力
	show_outputdata(g_thread, g_rotation);

	// メイン処理
	rawtopng(fp);

	// ファイルクローズ
	fclose(fp);

	return 0;
}
Beispiel #3
0
int main(int argc, char **argv)
{
	double double_var;

	char *input_buffer = NULL;

#if 0
	unsigned char input_tty = 1;
#endif

	int data_file;
	int option;
	int last_option;
	int last_u_option;
	int flip_bytes = 0;

/*	long offset; */
/*	long record_number; */
	long file_position;
	long data_file_length;
	long ops_file_length = 0;
	long new_position;
/*	long long_var; */

	fprintf(stderr, "%s",
#ifdef FF_ALPHA
"\nWelcome to readfile alpha 1.1 "__DATE__" -- an NGDC binary file reader\n"
#elif defined(FF_BETA)
"\nWelcome to readfile beta 1.1 "__DATE__" -- an NGDC binary file reader\n"
#else
"\nWelcome to readfile release 1.1 -- an NGDC binary file reader\n"
#endif
	       );

	if (argc == 1)
	{
		fprintf(stderr, "%s", "\nUSAGE: readfile binary_file\n");
		exit(1);
	}

	show_opt();

#if FF_OS == FF_OS_DOS
	data_file = open(argv[1], O_RDONLY | O_BINARY);
#endif

#if FF_OS == FF_OS_UNIX
	data_file = open(argv[1], O_RDONLY);
#endif

	if(data_file == -1)
	{
		fprintf(stderr,"Could Not Open Input File %s\n", argv[1]);
		exit(0);
	}

	{
		FILE *fp = fopen(argv[1], "r");
		data_file_length = -1;

		if (fp)
		{
			if (!fseek(fp, 0, SEEK_END))
				data_file_length = ftell(fp);

			fclose(fp);
		}
	}

	/* Determine if the input is coming from a file, if so read the file in */
	if (!isatty(fileno(stdin)))
	{
		ops_file_length = lseek(fileno(stdin), 0L, SEEK_END);
		input_buffer = (char *)malloc((size_t)ops_file_length + 1);
		if (!input_buffer)
		{
			fprintf(stderr, "Insufficient memory -- file is too large");
			exit(1);
		}

		lseek(fileno(stdin), 0L, SEEK_SET);
		read(fileno(stdin), input_buffer, (size_t)ops_file_length);
		*(input_buffer + ops_file_length) = '\0';
		input = input_buffer;
	}

	last_u_option = ' ';
	last_option = ' ';

	while ((option = get_option()) != 'q')
	{
		if (option == UINT_PREFIX)
			last_u_option = ' ';
		if (option == EOL_MARKER)
			option = last_option;

		switch(option)
		{
			case TEXT_CODE:

				if (check_error(read(data_file, (char *)&double_var, sizeof(char)), sizeof(char)))
					break;

				fprintf(stdout, "text: \'%c\', dec: %3d, hex: %2x, oct: %3o\n",
				        *(char *)&double_var,
				        *(unsigned char *)&double_var,
				        *(unsigned char *)&double_var,
				        *(unsigned char *)&double_var);

			break;

			case INT8_CODE:

				if (check_error(read(data_file, (char *)&double_var, SIZE_INT8), SIZE_INT8))
					break;

				fprintf(stdout, "int8: ");
				fprintf(stdout, fft_cnv_flags_width[FFNT_INT8], INT8_WIDTH,
				        *((int8 *)&double_var));
				fprintf(stdout, "\n");
			break;

			case INT16_CODE:

				if (check_error(read(data_file, (char *)&double_var, SIZE_INT16), SIZE_INT16))
					break;

				if (flip_bytes)
				{
					flip_2_bytes(&double_var);
					fprintf(stdout,"int16, byte swapped: ");
					fprintf(stdout, fft_cnv_flags_width[FFNT_INT16], INT16_WIDTH,
					        *((int16 *)&double_var));
					flip_2_bytes(&double_var);
					fprintf(stdout,", (\"%s-endian\": ",
					        endian() == LITTLE_ENDIAN ? "little" : "big");
					fprintf(stdout, fft_cnv_flags_width[FFNT_INT16], INT16_WIDTH,
					        *((int16 *)&double_var));
					fprintf(stdout, ")\n");
				}
				else
				{
					fprintf(stdout, "int16: ");
					fprintf(stdout, fft_cnv_flags_width[FFNT_INT16], INT16_WIDTH,
					        *((int16 *)&double_var));
					fprintf(stdout, "\n");
				}

			break;

			case INT32_CODE:

				if (check_error(read(data_file, (char *)&double_var, SIZE_INT32), SIZE_INT32))
					break;

				if (flip_bytes)
				{
					flip_4_bytes(&double_var);
					fprintf(stdout,"int32, byte swapped: ");
					fprintf(stdout, fft_cnv_flags_width[FFNT_INT32], INT32_WIDTH,
					        *((int32 *)&double_var));
					flip_4_bytes(&double_var);
					fprintf(stdout,", (\"%s-endian\": ",
					        endian() == LITTLE_ENDIAN ? "little" : "big");
					fprintf(stdout, fft_cnv_flags_width[FFNT_INT32], INT32_WIDTH,
					        *((int32 *)&double_var));
					fprintf(stdout, ")\n");
				}
				else
				{
					fprintf(stdout, "int32: ");
					fprintf(stdout, fft_cnv_flags_width[FFNT_INT32], INT32_WIDTH,
					        *((int32 *)&double_var));
					fprintf(stdout, "\n");
				}

			break;

#ifdef LONGS_ARE_64

			case INT64_CODE:

				if (check_error(read(data_file, (char *)&double_var, SIZE_INT64), SIZE_INT64))
					break;

				if (flip_bytes)
				{
					flip_8_bytes(&double_var);
					fprintf(stdout,"int64, byte swapped: ");
					fprintf(stdout, fft_cnv_flags_width[FFNT_INT64], INT64_WIDTH,
					        *((int64 *)&double_var));
					flip_8_bytes(&double_var);
					fprintf(stdout,", (\"%s-endian\": ",
					        endian() == LITTLE_ENDIAN ? "little" : "big");
					fprintf(stdout, fft_cnv_flags_width[FFNT_INT64], INT64_WIDTH,
					        *((int64 *)&double_var));
					fprintf(stdout, ")\n");
				}
				else
				{
					fprintf(stdout, "int64: ");
					fprintf(stdout, fft_cnv_flags_width[FFNT_INT64], INT64_WIDTH,
					        *((int64 *)&double_var));
					fprintf(stdout, "\n");
				}

			break;

#endif

			case FLOAT32_CODE:

				if (check_error(read(data_file,(char *)&double_var, SIZE_FLOAT32), SIZE_FLOAT32))
					break;

				if (flip_bytes)
				{
					flip_4_bytes(&double_var);
					fprintf(stdout, "float32, byte swapped: ");
					fprintf(stdout, fft_cnv_flags_width_prec[FFNT_FLOAT32], FLOAT32_WIDTH,
					        FLOAT32_PREC, *((float32 *)&double_var));
					flip_4_bytes(&double_var);
					fprintf(stdout,", (\"%s-endian\": ",
					        endian() == LITTLE_ENDIAN ? "little" : "big");
					fprintf(stdout, fft_cnv_flags_width_prec[FFNT_FLOAT32], FLOAT32_WIDTH,
					        FLOAT32_PREC, *((float32 *)&double_var));
					fprintf(stdout, ")\n");
				}
				else
				{
					fprintf(stdout, "float32: ");
					fprintf(stdout, fft_cnv_flags_width_prec[FFNT_FLOAT32], FLOAT32_WIDTH,
					        FLOAT32_PREC, *((float32 *)&double_var));
					fprintf(stdout, "\n");
				}

			break;

			case FLOAT64_CODE:

				if (check_error(read(data_file,(char *)&double_var, SIZE_FLOAT64), SIZE_FLOAT64))
					break;

				if (flip_bytes)
				{
					flip_8_bytes(&double_var);
					fprintf(stdout, "float64, byte swapped: ");
					fprintf(stdout, fft_cnv_flags_width_prec[FFNT_FLOAT64], FLOAT64_WIDTH,
					        FLOAT64_PREC, *((float64 *)&double_var));
					flip_8_bytes(&double_var);
					fprintf(stdout,", (\"%s-endian\": ",
					        endian() == LITTLE_ENDIAN ? "little" : "big");
					fprintf(stdout, fft_cnv_flags_width_prec[FFNT_FLOAT64], FLOAT64_WIDTH,
					        FLOAT64_PREC, *((float64 *)&double_var));
					fprintf(stdout, ")\n");
				}
				else
				{
					fprintf(stdout, "float64: ");
					fprintf(stdout, fft_cnv_flags_width_prec[FFNT_FLOAT64], FLOAT64_WIDTH,
					        FLOAT64_PREC, *((float64 *)&double_var));
					fprintf(stdout, "\n");
				}

			break;

			case UINT_PREFIX: /* unsigned ... */

				/* If last option is not yet defined, prompt the user */
				if (last_u_option == ' ')
				{
					last_u_option = get_option();
				}

				switch (last_u_option)
				{
					case INT8_CODE: /* unsigned char */

						if (check_error(read(data_file, (char *)&double_var, SIZE_UINT8), SIZE_UINT8))
							break;

						fprintf(stdout, "uint8: ");
						fprintf(stdout, fft_cnv_flags_width[FFNT_UINT8], UINT8_WIDTH,
						        *((uint8 *)&double_var));
						fprintf(stdout, "\n");

					break;

					case INT16_CODE:

						if (check_error(read(data_file, (char *)&double_var, SIZE_UINT16), SIZE_UINT16))
							break;

						if (flip_bytes)
						{
							flip_2_bytes(&double_var);
							fprintf(stdout,"uint16, byte swapped: ");
							fprintf(stdout, fft_cnv_flags_width[FFNT_UINT16], UINT16_WIDTH,
							        *((uint16 *)&double_var));
							flip_2_bytes(&double_var);
							fprintf(stdout,", (\"%s-endian\": ",
							        endian() == LITTLE_ENDIAN ? "little" : "big");
							fprintf(stdout, fft_cnv_flags_width[FFNT_UINT16], UINT16_WIDTH,
							        *((uint16 *)&double_var));
							fprintf(stdout, ")\n");
						}
						else
						{
							fprintf(stdout, "uint16: ");
							fprintf(stdout, fft_cnv_flags_width[FFNT_UINT16], UINT16_WIDTH,
							        *((uint16 *)&double_var));
							fprintf(stdout, "\n");
						}

					break;

					case INT32_CODE:

						if (check_error(read(data_file, (char *)&double_var, SIZE_UINT32), SIZE_UINT32))
							break;

						if (flip_bytes)
						{
							flip_4_bytes(&double_var);
							fprintf(stdout,"uint32, byte swapped: ");
							fprintf(stdout, fft_cnv_flags_width[FFNT_UINT32], UINT32_WIDTH,
							        *((uint32 *)&double_var));
							flip_4_bytes(&double_var);
							fprintf(stdout,", (\"%s-endian\": ",
							        endian() == LITTLE_ENDIAN ? "little" : "big");
							fprintf(stdout, fft_cnv_flags_width[FFNT_UINT32], UINT32_WIDTH,
							        *((uint32 *)&double_var));
							fprintf(stdout, ")\n");
						}
						else
						{
							fprintf(stdout, "uint32: ");
							fprintf(stdout, fft_cnv_flags_width[FFNT_UINT32], UINT32_WIDTH,
							        *((uint32 *)&double_var));
							fprintf(stdout, "\n");
						}

					break;

#ifdef LONGS_ARE_64

					case INT64_CODE:

						if (check_error(read(data_file, (char *)&double_var, SIZE_UINT64), SIZE_UINT64))
							break;

						if (flip_bytes)
						{
							flip_8_bytes(&double_var);
							fprintf(stdout,"uint64, byte swapped: ");
							fprintf(stdout, fft_cnv_flags_width[FFNT_UINT64], UINT64_WIDTH,
							        *((uint64 *)&double_var));
							flip_8_bytes(&double_var);
							fprintf(stdout,", (\"%s-endian\": ",
							        endian() == LITTLE_ENDIAN ? "little" : "big");
							fprintf(stdout, fft_cnv_flags_width[FFNT_UINT64], UINT64_WIDTH,
							        *((uint64 *)&double_var));
							fprintf(stdout, ")\n");
						}
						else
						{
							fprintf(stdout, "uint64: ");
							fprintf(stdout, fft_cnv_flags_width[FFNT_UINT64], UINT64_WIDTH,
							        *((uint64 *)&double_var));
							fprintf(stdout, "\n");
						}

					break;

#endif

					default:
						fprintf(stdout,"Type 'h' or '?' to see options menu.\n");
						last_u_option = ' ';
					break;
				}/* end switch on unsigned types */

			break;

			case 'b': /* toggle between little-endian and big-endian */

				flip_bytes = (flip_bytes) ? 0 : 1;
				if (flip_bytes)
				{
					fprintf(stderr, "Displaying numbers with byte swapping\n");
				}
				else
				{
					/* Say what the native byte order IS */
					fprintf(stderr, "Displaying numbers using your machine's native byte order\n");
				}

			break;

			case 'p': /* position file, don't show file size */

				if (input)
				{
					input = strtok(input, " ");

					/* Check for errors */
					if (!input)
					{
						fprintf(stderr, "Missing blank space after number.");
						exit(1);
					}
					if ((input - input_buffer) >= ops_file_length)
					{
						fprintf(stderr, "Reading past end of input file.");
						exit(1);
					}

					sscanf(input, "%ld", &new_position);
					input += strlen(input) + 1;
				}
				else
				{
					fprintf(stdout,"Input New File Position in Bytes ");
					scanf("%ld", &new_position);

#if FF_OS == FF_OS_UNIX
					os_getch();
#endif

				}

				if (new_position > data_file_length)
				{
					fprintf(stderr,"ERROR: Position not changed.\n");
					fprintf(stderr,"       New position cannot be beyond %ld, the size of %s.\n", data_file_length, argv[1]);
					break;
				}

				file_position = lseek(data_file, new_position, SEEK_SET);
				fprintf(stdout,"New File Position = %ld\n", file_position);
				new_position = 0;

			break;

			case 'P':  /* show file position and size */

				file_position = lseek(data_file, 0L, SEEK_CUR);
				fprintf(stdout,"File Position: %ld\tFile Length: %ld\n", file_position, data_file_length);

			break;

			case 'h':
			case '?':
				show_opt();
			break;

			default:
				fprintf(stdout,"Type 'h' or '?' to see options menu.\n");
		} /* end switch on all types */
		last_option = option;
		if (last_option != 'u')
			last_u_option = ' ';

	}/* end while loop */

	return 0;
}/* end readfile */