📄 persistence.c
字号:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright (c) 1999 Intel Corporation. All Rights Reserved.
//
// RCS:
// $Source: initrand.c$
// $Revision: 00.00.28$
// Purpose:
// Contents:
// Loading & Saving of some structures
// Authors:
// Vadim Pisarevsky
//
//M*/
#include "ats.h"
float* atsReadMatrix( const char* filename, int* _m, int* _n )
{
FILE* f = fopen( filename, "rt" );
float* data = 0;
double NaN = sqrt(-1);
if( _m ) *_m = 0;
if( _n ) *_n = 0;
if( f )
{
int m = 0, n = 0, i;
if( fscanf( f, "%d%d", &m, &n ) == 2 && m > 0 && n > 0 )
{
data = (float*)malloc( m*n*sizeof(data[0]));
if( data )
{
for( i = 0; i < m*n; i++ )
{
data[i] = (float)NaN;
if( fscanf( f, "%g", data + i ) != 1 )
{
fscanf( f, "%*s" );
}
}
}
if( data )
{
if( _m ) *_m = m;
if( _n ) *_n = n;
}
}
fclose(f);
}
return data;
}
void atsWriteMatrix( const char* filename, int m, int n, float* data )
{
FILE* f = fopen( filename, "wt" );
if( f )
{
int i, j;
fprintf( f, "%5d%5d\n", m, n );
for( i = 0; i < m; i++ )
{
for( j = 0; j < n; j++ )
{
fprintf( f, "%20.7f", data[i*n + j] );
}
fprintf( f, "\n" );
}
fclose(f);
}
}
/* End of file. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -