当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 4 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : [问题]在编译过程中出现警告: 不建议使用从字符串常量到‘char*’的转换
帖子发表于 : 2008-04-30 19:27 

注册: 2008-03-22 1:19
帖子: 45
送出感谢: 0 次
接收感谢: 0 次
各位大侠,本人在编译一个程序时出
使用:
$g++ -c sacdata.cc
然后就出现
sacdata.cc:49: 警告: 不建议使用从字符串常量到‘char*’的转换
请各位高手帮我看看,在线救急,小弟在此先谢过了
源程序代码如下:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include "sacdata.hh"

#define DEBUG__0001 1

char * CSacData :: vname[] = {
"delta", "depmin", "depmax", "scale", "odelta",
"b", "e", "o", "a", "internal1",
"t0", "t1", "t2", "t3", "t4",
"t5", "t6", "t7", "t8", "t9",
"f", "resp0", "resp1", "resp2", "resp3",
"resp4", "resp5", "resp6", "resp7", "resp8",
"resp9", "stla", "stlo", "stel", "stdp",
"evla", "evlo", "evel", "evdp", "unused1",
"user0", "user1", "user2", "user3", "user4",
"user5", "user6", "user7", "user8", "user9",
"dist", "az", "baz", "gcarc", "internal2",
"internal3", "depmen", "cmpaz", "cmpinc", "unused2",
"unused3", "unused4", "unused5", "unused6", "unused7",
"unused8", "unused9", "unused10", "unused11", "unused12",
"nzyear", "nzjday", "nzhour", "nzmin", "nzsec",
"nzmsec", "internal4", "internal5", "internal6", "npts",
"internal7", "internal8", "unused13", "unused14", "unused15",
"iftype", "idep", "iztype", "unused16", "iinst",
"istreg", "ievreg", "ievtyp", "iqual", "isynth",
"unused17", "unused18", "unused19", "unused20", "unused21",
"unused22", "unused23", "unused24", "unused25", "unused26",
"leven", "lpspol", "lovrok", "lcalda", "unused27",
"kstnm", "kevnm", " ",
"khole", "ko", "ka",
"kt0", "kt1", "kt2",
"kt3", "kt4", "kt5",
"kt6", "kt7", "kt8",
"kt9", "kf", "kuser0",
"kuser1", "kuser2", "kcmpnm",
"knetwk", "kdatrd", "kinst"
};


struct sac_header CSacData :: empty_head = {
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345., -12345., -12345., -12345., -12345.,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
-12345, -12345, -12345, -12345, -12345,
{ '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }, { '-','1','2','3','4','5',' ',' ' },
{ '-','1','2','3','4','5',' ',' ' }
};

// constructor and distructor
CSacData :: CSacData( )
{
SStatus = 0;
np = 0;
slflag = 0;
dd = NULL;
fn = NULL;
err[0] = 0;
vvp = ( struct vdata * ) &sh;
}

CSacData :: ~CSacData( )
{
if ( dd != NULL ) delete [] dd;
if ( fn != NULL ) delete [] fn;
}

// read and write
int CSacData :: ReadFile( char * filename )
{
FILE * fp;
int fnl;

fp = fopen( filename, "rb" );
if ( fp == NULL ) {
strcpy( err, "could not open file" );
return -1;
}
fread( &sh, sizeof( sh ), 1, fp );
if ( sh.internal4 != 6 ) {
swapheader( );
if ( sh.internal4 != 6 ) {
strcpy( err, "unavailable sac file" );
fclose( fp );
return -2;
} else {
slflag = 1;
}
}
np = sh.npts;
if ( sh.npts <= 0 ) {
strcpy( err, "unavailable sac file" );
fclose( fp );
return -2;
}
np = ( sh.leven == TRUE ) ? np : np*2;
if ( dd != NULL ) {
delete [] dd;
dd = NULL;
}
dd = new float[np];
if ( dd == NULL ) {
strcpy( err, "memory allocates faile" );
fclose( fp );
return -1;
}
fread( dd, sizeof( float ), np, fp );
if ( slflag == 1 ) {
swapdata( );
}
fclose( fp );
fnl = strlen( filename );
if ( fn != NULL ) {
delete [] fn;
fn = NULL;
}
fn = new char[fnl+1];
strncpy( fn, filename, fnl );
fn[fnl] = 0;
SStatus = 3;
return 0;
}

int CSacData :: WriteFile( char * filename )
{
FILE * fp;
if ( SStatus != 3 ) {
strcpy( err, "sac data empty" );
return -1;
}
if ( filename == NULL ) {
if ( fn == NULL ) {
strcpy( err, "file name empty" );
return -2;
}
fp = fopen( fn, "w" );
} else {
fp = fopen( filename, "w" );
}
if ( fp == NULL ) {
strcpy( err, "coul not open file" );
return -3;
}
fwrite( &sh, sizeof( sh ), 1, fp );
fwrite( dd, sizeof( float ), np, fp );
fclose( fp );
return 0;
}

int CSacData :: WriteFile( char * filename, int dflag )
{
FILE * fp;
if ( dflag != 1 ) {
return WriteFile( filename );
}
if ( SStatus != 3 ) {
strcpy( err, "sac data empty" );
return -1;
}
fp = fopen( filename, "w" );
swapheader( );
fwrite( &sh, sizeof( sh ), 1, fp );
swapheader( );
swapdata( );
fwrite( dd, sizeof( float ), np, fp );
swapdata( );
fclose( fp );
return 0;
}

int CSacData :: WriteFile( char * filename, float * st, float * et )
{
FILE * fp;
int npp, bn, en, npts;
float aa, bb;
float b, e, dmin, dmax;
// check data
if ( SStatus != 3 ) {
strcpy( err, "sac data empty" );
return -1;
}
// check file name
if ( filename == NULL ) {
strcpy( err, "file name empty" );
return -2;
}
// open file for write
fp = fopen( filename, "w" );
if ( fp == NULL ) {
strcpy( err, "coul not open file" );
return -3;
}
// reset some head variables
aa = *st;
if ( aa < sh.b ) aa = sh.b;
bb = *et;
if ( bb > sh.e ) bb = sh.e;
bn = (int)( floor( ( aa - sh.b + 0.01 * sh.delta ) / sh.delta ) );
if ( bn < 0 ) bn = 0;
en = (int)( floor( ( bb - sh.b + 0.01 * sh.delta ) / sh.delta ) );
if ( en > sh.npts ) en = sh.npts;
npp = en - bn;
if ( npp <= 0 ) {
strcpy( err, "cut range error" );
return -4;
}
// story some head variables
b = sh.b;
e = sh.e;
npts = sh.npts;
dmin = sh.depmin;
dmax = sh.depmax;
// set new value;
sh.b = aa;
sh.e = bb;
sh.npts = npp;
setminmax( bn, npp );
// write file head record
fwrite( &sh, sizeof( sh ), 1, fp );
// write data
fwrite( &dd[bn], sizeof( float ), npp, fp );
fclose( fp );
// recoveye the head data
sh.b = b;
sh.e = e;
sh.npts = npts;
sh.depmin = dmin;
sh.depmax = dmax;
return 0;
}

int CSacData :: ReadHead( char * filename )
{
FILE * fp;
int fnl;

fp = fopen( filename, "r" );
if ( fp == NULL ) {
strcpy( err, "Could not open file" );
return -1;
}
fread( &sh, sizeof( sh ), 1, fp );
fclose( fp );
if ( sh.internal4 != 6 ) {
swapheader( );
if ( sh.internal4 != 6 ) {
strcpy( err, "unavailable sac file" );
return -2;
} else {
slflag = 1;
}
}
fnl = strlen( filename );
fn = new char[fnl+1];
strncpy( fn, filename, fnl );
fn[fnl] = 0;
SStatus = 1;
return 0;
}

int CSacData :: WriteHead( char * filename )
{
FILE * fp;
int sl;
if ( ( SStatus & 1 ) == 0 ) {
strcpy( err, "file haed empty" );
return -1;
}
if ( filename == NULL ) {
if ( fn == NULL ) {
strcpy( err, "file name empty" );
return -2;
}
if ( slflag == 1 ) {
strcpy( err, "could not write sun sac file header" );
return -3;
}
} else {
if ( fn != NULL ) {
delete [] fn;
}
sl = strlen( filename );
fn = new char[sl+1];
strcpy( fn, filename );
fn[sl] = 0;
}
fp = fopen( fn, "r+" );
if ( fp == NULL ) {
strcpy( err, "coul not open file" );
return -3;
}
fwrite( &sh, sizeof( sh ), 1, fp );
fclose( fp );
return 0;
}

int CSacData :: Merge( CSacData * sd )
{
struct sac_header * shp;
float * tdd, * mdd;
int tnp, i, rc, mnp;
if ( ( SStatus & 3 ) != 3 ) {
strcpy( err, "data set is not available" );
return -1;
}
rc = sd->GetHead( &shp );
if ( rc != 0 ) {
strcpy( err, "merged data set is not available" );
return -2;
}
// check delta
// check time

rc = sd->GetData( &mdd );
if ( rc != 0 ) {
strcpy( err, "merged data set is not available" );
return -3;
}
sh.npts += shp->npts;
tnp = ( sh.leven == TRUE ) ? sh.npts : sh.npts * 2;
tdd = new float[tnp];
for ( i=0; i<np; i++ ) {
tdd[i] = dd[i];
}
mnp = ( shp->leven == TRUE ) ? shp->npts : shp->npts * 2;
for ( i=0; i<mnp; i++ ) {
tdd[i+np] = mdd[i];
}
sh.e = sh.b + ( sh.npts - 1 ) * sh.delta;
delete [] dd;
dd = tdd;
return 0;
}

int CSacData :: SetHeadV( char * vn, float * vv )
{
int i, j, fd, rc = -1;
if ( ( SStatus & 1 ) == 0 ) {
strcpy( err, "file header is not initialized" );
return rc;
}
for ( i=0, j=FFV, rc=-2; i<NFV; i++, j++ ) {
fd = strcasecmp( vname[j], vn );
if ( fd == 0 ) {
rc = 0; vvp->fv[i] = *vv;
break;
}
}
return rc;
}

int CSacData :: SetHeadV( char * vn, int * vv )
{
int i, j, fd, rc = -1;
if ( ( SStatus & 1 ) == 0 ) {
strcpy( err, "file header is not available" );
return rc;
}
for ( i=0, j=FLV, rc=-2; i<NLV; i++, j++ ) {
fd = strcasecmp( vname[j], vn );
if ( fd == 0 ) {
rc = 0;
vvp->lv[i] = *vv;
break;
}
}
return rc;
}

int CSacData :: SetHeadV( char * vn, char * vc )
{
int i, j, fd, k, nc, sl, rc = -1;
if ( ( SStatus & 1 ) == 0 ) {
strcpy( err, "file header is not available" );
return rc;
}
for ( i=0, j=FKV, rc=-2; i<NKV; i++, j++ ) {
fd = strcasecmp( vname[j], vn );
if ( fd == 0 ) {
nc = (i==1)?16:8;
for ( k=0; k<nc&&vc[k]!=0; k++ ) {
if ( isalnum( vc[k] ) || vc[k] == '_' ) {
sl = k+1;
} else {
break;
}
}
rc = 0;
strncpy( vvp->kv[i], vc, sl );
if ( sl >= nc ) {
sl = nc - 1;
}
vvp->kv[i][sl] = 0;
break;
}
}
return rc;
}

int CSacData :: GetHeadV( char * vn, float * vf )
{
int i, j, fd, rc = -1;
if ( ( SStatus & 1 ) == 0 ) {
strcpy( err, "file header is not initialized" );
return rc;
}
for ( i=0, j=FFV, rc=-2; i<NFV; i++, j++ ) {
fd = strcasecmp( vname[j], vn );
if ( fd == 0 ) {
rc = 0;
*vf = vvp->fv[i];
break;
}
}
return rc;
}
int CSacData :: GetHeadV( char * vn, int * vi )
{
int i, j, fd, rc = -1;
if ( ( SStatus & 1 ) == 0 ) {
strcpy( err, "file header is not available" );
return rc;
}
for ( i=0, j=FLV, rc=-2; i<NLV; i++, j++ ) {
fd = strcasecmp( vname[j], vn );
if ( fd == 0 ) {
rc = 0;
*vi = vvp->lv[i];
break;
}
}
return rc;
}

int CSacData :: GetHeadV( char * vn, char * vc )
{
int sl, i, j, k, fd, nc, rc = -1;
if ( ( SStatus & 1 ) == 0 ) {
strcpy( err, "file header is not available" );
return rc;
}
for ( i=0, j=FKV, k=-1, rc=-2; i<NKV; i++, j++ ) {
fd = strcasecmp( vname[j], vn );
if ( fd == 0 ) {
rc = 0;
k = i;
sl= strlen( vvp->kv[i] );
nc == (i==1) ? 16 : 8;
if ( sl >= nc ) {
sl = nc - 1;
}
strncpy( vc, vvp->kv[i], sl );
vc[sl] = 0;
break;
}
}
// if ( k > -1 ) {
// for ( i=0; i<nc; i++ ) {
// if ( ( ! isalnum( vc[i] ) ) && vc[i] != '_' ) {
// vc[i] = 0;
// break;
// }
// }
// }
return rc;
}

int CSacData :: FindHeadV( char * vn, int *type )
{
int i, j, fd;
// fprintf( stderr, " file status: %d\n", SStatus );
for ( i=0, j=FFV; i<NFV; i++, j++ ) {
// fprintf( stderr, "i, j, vn: %d %d %s\n", i, j, vname[j] );
fd = strcasecmp( vname[j], vn );
if ( fd == 0 ) {
*type = 0;
return i;
}
}
for ( i=0, j=FLV; i<NLV; i++, j++ ) {
fd = strcasecmp( vname[j], vn );
if ( fd == 0 ) {
*type = 1;
return i;
}
}
for ( i=0, j=FKV; i<NKV; i++, j++ ) {
fd = strcasecmp( vname[j], vn );
if ( fd == 0 ) {
*type = 2;
return i;
}
}
return -2;
}

int CSacData :: SetHeadV( int type, int ind, void * vvalue )
{
int rc, * vpi, sl;
float * vpf;
char * vpk;
rc = -1;
if ( ( SStatus & 1 ) != 1 ) {
strcpy( err, "file head empty" );
return rc;
}
rc = 0;
switch ( type ) {
case 0: // float variables
if ( ind < 0 || ind >= NFV ) {
rc = -2;
} else {
vpf = ( float * ) vvalue;
vvp->fv[ind] = *vpf;
}
break;
case 1: // integer variables
if ( ind < 0 || ind >= NLV ) {
rc = -3;
} else {
vpi = ( int * ) vvalue;
vvp->lv[ind] = * vpi;
}
break;
case 2: // string variabels;
if ( ind < 0 || ind >= NKV ) {
rc = -4;
} else {
vpk = ( char * ) vvalue;
sl = strlen( vpk );
if ( ind == 1 ) {
sl = ( sl > 15 )?(15):(sl);
} else {
sl = ( sl > 7 ) ? (7):(sl);
}
strncpy( vvp->kv[ind], vpk, sl );
vvp->kv[ind][sl] = 0;
}
}
return rc;
}

int CSacData :: GetHead( struct sac_header ** shead )
{
if ( ( SStatus & 1 ) != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
*shead = &sh;
return 0;
}

int CSacData :: SetHead( struct sac_header * shead )
{
memcpy( &sh, shead, sizeof( sh ) );
SStatus |= 1;
np = ( sh.leven == TRUE ) ? sh.npts : sh.npts * 2;
return 0;
}

int CSacData :: GetData( float ** data )
{
if ( ( SStatus & 2 ) == 0 ) {
strcpy( err, "file data empty" );
return -1;
}
*data = dd;
return 0;
}

int CSacData :: GetData( float ** data, float * st, float * et )
{
float b, e;
int nb, ne, nl;
if ( ( SStatus & 2 ) == 0 ) {
strcpy( err, " file data empty" );
return -1;
}
b = *st; e = *et;
if ( b < sh.b ) b = sh.b;
if ( e > sh.e ) e = sh.e;
nb = (int)( ( b - sh.b ) / sh.delta );
ne = (int)( ( e - sh.b ) / sh.delta );
nl = ne - nb;
if ( nl <= 0 ) {
strcpy( err, " nonaviable range " );
return -2;
}
*data = ( dd + nb );
return nl;
}

int CSacData :: GetData( float * tp, float * vp )
{
int indp;
float pp;
if ( ( SStatus & 2 ) == 0 ) {
strcpy( err, " file data empty" );
return -1;
}
pp = *tp;
indp = (int)( floor( ( pp - sh.b ) / sh.delta ) );
if ( indp < 0 || indp >= sh.npts ) {
strcpy( err, " data point is out range" );
return -2;
}
*vp = dd[indp];
return 0;
}

int CSacData :: SetData( float * data )
{
int i;
if ( dd != NULL ) {
delete [] dd;
dd = NULL;
}
if ( np == 0 )
np = ( sh.leven == TRUE ) ? sh.npts : sh.npts * 2;
dd = new float[np];
for ( i=0; i<np; i++ )
dd[i] = data[i];
setminmax( 0, 0 );
SStatus |= 2;
return 0;
}

void CSacData :: InitHead( )
{
memcpy( &sh, &empty_head, sizeof( sh ) );
sh.internal4 = 6;
sh.internal5 = 0;
sh.internal6 = 0;
sh.iztype = IB;
sh.leven = TRUE;
sh.iftype = ITIME;
sh.idep = IUNKN;
sh.ievtyp = IUNKN;
sh.lpspol = FALSE;
sh.lcalda = TRUE;
sh.unused27 = FALSE;
SStatus = 1;
}

void CSacData :: GetErr( char ** estr )
{
*estr = err;
}

int CSacData :: Expand( float * before, float * after )
{
float a, b, f, * d;
int ns, nnp, i, nss, nas, nbs;

if ( SStatus & 3 != 3 ) {
strcpy( err, "no data" );
return -1;
}
a = *after; b = *before;
if ( a < 0 ) a = -a;
if ( b < 0 ) b = -b;
f = a + b;
ns = (int)( f / sh.delta + 0.5);
if ( ns == 0 ) {
strcpy( err, "no change" );
return -2;
}
nnp = sh.npts + ns;
nbs = 0;
d = new float[nnp];
if ( b > 0 ) {
sh.b -= b;
nbs = (int)( b / sh.delta + 0.5 );
// fprintf ( stderr, " b, nbs: %f %d\n", sh.b, nbs );
for ( i=0; i<nbs; i++ ) {
d[i] = 0.0;
}
}
for ( i=0; i<sh.npts; i++ ) {
d[i+nbs] = dd[i];
}
if ( a > 0 ) {
nss = nbs + sh.npts;
// fprintf( stderr, " nss: %d\n", nss );
sh.e += a;
nas = (int)( a / sh.delta + 0.5 );
// fprintf( stderr, " e, nas: %f %d\n", sh.e, nas );
for ( i=0; i<nas; i++ ) {
d[i+nss] = 0.0;
}
}
sh.npts += ns;
// fprintf( stderr, " npts: %d\n", sh.npts );
np += ns;
delete [] dd;
dd = d;
return 0;
}

int CSacData :: Cut( float * begin, float * end )
{
float a, b, len, * d;
int nnp, i, nes, nbs;

if ( SStatus & 3 != 3 ) {
strcpy( err, "no data" );
return -1;
}
a = *begin; b = *end;

#ifdef DEBUG__0001
fprintf( stderr, "sacdata:cut a: %f b: %f\n", a, b );
#endif
if ( a >= b ) {
strcpy( err, " cut region is not available " );
return -2;
}
if ( a < 0 ) a = 0;
len = sh.e - sh.b;
if ( b > len ) b = len;
nbs = (int)( a / sh.delta + 0.5 );
nes = (int)( b / sh.delta + 0.5 );
nnp = nes - nbs;
if ( nnp == 0 ) {
strcpy( err, " cut region is not available " );
return -3;
}
if ( nnp == sh.npts ) {
strcpy( err, "no change" );
return -4;
}
sh.b += nbs * sh.delta;
sh.e = sh.b + nnp * sh.delta;
#ifdef DEBUG__0001
fprintf( stderr, "sacdata:cut nnp: %d\n", nnp );
#endif
if ( nbs != 0 ) {
d = new float[nnp];
for ( i=0; i<nnp; i++ ) {
d[i] = dd[i+nbs];
}
delete [] dd;
dd = d;
}
sh.npts = nnp;
np = nnp;
return 0;
}

int CSacData :: FindMax( float * vm, float * tm, float bt, float et )
{
int i, k, nb, ne;
float v;

if ( SStatus & 3 != 3 ) {
strcpy( err, "no data" );
return -1;
}
if ( bt > et ) {
nb = 0;
ne = sh.npts;
} else {
nb = (int)floor( bt / sh.delta + 0.1 );
ne = (int)floor( et / sh.delta + 0.1 );
if ( nb < 0 ) nb = 0;
if ( ne > sh.npts ) ne = sh.npts;
}
// fprintf( stderr, " bt et nb, ne: %f %f %d %d\n", bt, et, nb, ne );
v = -1.0e30;
for ( i=nb; i<ne; i++ ) {
if ( v < dd[i] ) {
v = dd[i];
k = i;
}
}
*vm = v;
*tm = k * sh.delta + sh.b;
// fprintf( stderr, " vm, tm: %f %f\n", *vm, *tm );
return 0;
}

int CSacData :: FindMin( float * vm, float * tm, float bt, float et )
{
int i, k, nb, ne;
float v;

if ( SStatus & 3 != 3 ) {
strcpy( err, "no data" );
return -1;
}
if ( bt > et ) {
nb = 0;
ne = sh.npts;
} else {
nb = (int)floor( bt / sh.delta + 0.1 );
ne = (int)floor( et / sh.delta + 0.1 );
if ( nb < 0 ) nb = 0;
if ( ne > sh.npts ) ne = sh.npts;
}
v = 1.0e30;
for ( i=nb; i<ne; i++ ) {
if ( v > dd[i] ) {
v = dd[i];
k = i;
}
}
*vm = v;
*tm = k * sh.delta + sh.b;
return 0;
}

int CSacData :: GetDateTime( int * year, int * yday, int * hour,
int * min, int * sec, int * msec )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
*year = sh.nzyear;
*yday = sh.nzjday - 1;
*hour = sh.nzhour;
*min = sh.nzmin;
*sec = sh.nzsec;
*msec = sh.nzmsec;
return 0;
}

int CSacData :: SetDateTime( int * year, int * yday, int * hour,
int * min, int * sec, int * msec )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
sh.nzyear = *year;
sh.nzjday = *yday + 1;
sh.nzhour = *hour;
sh.nzmin = *min;
sh.nzsec = *sec;
sh.nzmsec = *msec;
return 0;
}

int CSacData :: SetStnCoor( float * lat, float * lon, float * elv )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
sh.stla = *lat;
sh.stlo = *lon;
sh.stel = *elv;
return 0;
}
int CSacData :: GetStnCoor( float * lat, float * lon, float * elv )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
*lat = sh.stla;
*lon = sh.stlo;
*elv = sh.stel;
return 0;
}

int CSacData :: GetEvtCoor( float * lat, float * lon, float * dep )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
*lat = sh.evla;
*lon = sh.evlo;
*dep = sh.evdp;
return 0;
}

int CSacData :: SetEvtCoor( float * lat, float * lon, float * dep )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
sh.evla = *lat;
sh.evlo = *lon;
sh.evdp = *dep;
return 0;
}

int CSacData :: SetComponent( char * ncom )
{
int sl;
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
sl = 0;
switch ( ncom[0] ) {
case 'e':
case 'E':
sh.cmpaz = 90;
sh.cmpinc = 90;
break;
case 'n':
case 'N':
sh.cmpaz = 0;
sh.cmpinc = 90;
break;
case 'z':
case 'Z':
case 'v':
case 'V':
sh.cmpaz = 0;
sh.cmpinc = 0;
break;
default:
strcpy( err, " ERR component name ! " );
return -1;
}
sl = strlen( ncom );
if ( sl > 7 ) sl = 7;
strncpy( sh.kcmpnm, ncom, sl );
sh.kcmpnm[sl] = 0;
return 0;
}

int CSacData :: GetComponent( char * comn )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
strncpy( comn, sh.kcmpnm, 7 );
comn[7] = 0;
return 0;
}


int CSacData :: SetComponent( float * decl, float * incl, char * comn )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
sh.cmpaz = *decl;
sh.cmpinc = *incl;
strncpy( sh.kcmpnm, comn, 7 );
return 0;
}

int CSacData :: GetComponent( float * decl, float * incl, char * comn )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
*decl = sh.cmpaz;
*incl = sh.cmpinc;
strncpy( comn, sh.kcmpnm, 7 );
comn[7] = 0;
return 0;
}


int CSacData :: GetDistance( float * diskm, float * disdg )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
*diskm = sh.dist;
*disdg = sh.gcarc;
return 0;
}

int CSacData :: GetDataNumber( int * np, int * ndata )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
*np = sh.npts;
*ndata = ( sh.leven == TRUE ) ? sh.npts : 2 * sh.npts;
return 0;
}

int CSacData :: GetNpts( void )
{
return sh.npts;
}

int CSacData :: SetDataNumber( int * np )
{
this->np = *np;
return 0;
}

int CSacData :: GetDelta( float * delta )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
*delta = sh.delta;
return 0;
}

int CSacData :: SetDelta( float * delta )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
sh.delta = *delta;
return 0;
}

int CSacData :: GetAzimuth( float * az, float * baz )
{
if ( SStatus & 1 != 1 ) {
strcpy( err, "file head empty" );
return -1;
}
*az = sh.az;
*baz = sh.baz;
return 0;
}

void CSacData :: setminmax( int bn, int np )
{
int i, npo;
float tmin, tmax;
if ( np == 0 ) {
npo = sh.npts;
} else {
npo = np;
}
tmin = 1.0e30;
tmax = -tmin;
for ( i=0; i<npo; i++ ) {
if ( tmin > dd[i+bn] ) tmin = dd[i+bn];
if ( tmax < dd[i+bn] ) tmax = dd[i+bn];
}
sh.depmin = tmin;
sh.depmax = tmax;
return;
}

int CSacData :: FillZero( int nb, int ne )
{
int i;
if ( nb < 0 ) {
nb = 0;
}
if ( ne > sh.npts ) {
ne = sh.npts;
}
if ( ne <= nb ) {
return -1;
}
for ( i=nb; i<ne; i++ ) {
dd[i] = 0.0;
}
return 0;
}


void CSacData :: swapchars( unsigned char * aa )
{
unsigned char c;
int i;
for ( i=0; i<2; i++ ) {
c = aa[i];
aa[i] = aa[3-i];
aa[3-i] = c;
}
}

void CSacData :: swapdata( void )
{
int i;
for ( i=0; i<np; i++ ) {
swapchars( (unsigned char *)(dd+i) );
}
}
void CSacData :: swapheader( void )
{
int i;
for ( i=0; i<70; i++ ) {
swapchars( (unsigned char *)&(vvp->fv[i]) );
}
for ( i=0; i<40; i++ ) {
swapchars( (unsigned char *)&(vvp->lv[i]) );
}
}


页首
 用户资料  
 
2 楼 
 文章标题 : Re: [问题]在编译过程中出现警告: 不建议使用从字符串常量到‘char*’的转换
帖子发表于 : 2010-07-18 11:41 
头像

注册: 2008-02-24 14:15
帖子: 693
地址: 江苏
系统: Ubuntu
送出感谢: 17
接收感谢: 0 次
定义是Char.

不可以转成Char指针.


_________________

怀念以前的老台式机。可惜现在租的地方没条件用了。目前只能用笔记本和手机了。


页首
 用户资料  
 
3 楼 
 文章标题 : Re: [问题]在编译过程中出现警告: 不建议使用从字符串常量到‘char*’的转换
帖子发表于 : 2010-07-18 12:06 
头像

注册: 2006-07-02 11:16
帖子: 12522
地址: 廣州
送出感谢: 0 次
接收感谢: 8
警告而已


_________________
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。


页首
 用户资料  
 
4 楼 
 文章标题 : Re: [问题]在编译过程中出现警告: 不建议使用从字符串常量到‘char*’的转换
帖子发表于 : 2010-07-18 12:23 
头像

注册: 2005-08-14 21:55
帖子: 58428
地址: 长沙
送出感谢: 4
接收感谢: 272
实际操作,可能会出错的。
常量,就是固定的位置。如果转成char *了。就可以赋值。超下限就可能了。段错误也可能了。


_________________
● 鸣学


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 4 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译