本文整理汇总了C++中MALLOC函数的典型用法代码示例。如果您正苦于以下问题:C++ MALLOC函数的具体用法?C++ MALLOC怎么用?C++ MALLOC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MALLOC函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: onnick
void onnick(char *source, char *newnick, char *body)
{
register aluser *user, **u;
register asuser *suser, **s;
register aserver *serv;
char username[80];
char hostname[80];
char TS[80];
char server[80];
register achannelnode *chan;
register anickchange *curr, *prec;
char buffer[512];
int i = 0;
#ifdef DEBUG
printf("NICK: %s --> %s ...\n", source, newnick);
#endif
/* a new user */
if (!ToLuser(source))
{ /* Not a user, so a server or nothing */
if (strchr(source, '.') == NULL)
{
/* Source is not a user and not a server either */
return;
}
if (!strcasecmp(newnick, mynick))
{
log("ERROR: I'm nick collided");
#ifdef DEBUG
printf("ARGH!!! I'M NICK COLLIDED!\n");
#endif
GetWord(1, body, TS);
GetWord(2, body, username);
GetWord(3, body, hostname);
if (atol(TS) <= logTS &&
strcasecmp(username, myuser) &&
strcasecmp(hostname, mysite))
{
NickInUse();
log(source);
log(newnick);
log(body);
}
else
{
onquit(source);
return; /*ignore */
}
#ifdef BACKUP
}
else if (!strcasecmp(newnick, MAIN_NICK))
{
return; /* ignore */
#endif
}
else if (ToLuser(newnick))
{
#ifdef DEBUG
printf("ARGH!!! NICK COLLISION\n");
#endif
onquit(newnick);
}
GetWord(1, body, TS);
GetWord(2, body, username);
GetWord(3, body, hostname);
GetWord(4, body, server);
#ifdef FAKE_UWORLD
if (Uworld_status == 1 && !strcasecmp(newnick, UFAKE_NICK))
{
if (atol(TS) <= UworldTS && atol(TS) != 0 &&
strcasecmp(username, UFAKE_NICK) &&
strcasecmp(hostname, UFAKE_HOST))
{
sprintf(buffer, "%s nick collided", UFAKE_NICK);
log(buffer);
Uworld_status = 0;
KillUworld("nick collision");
return; /* ignore if younger */
}
}
#endif
user = (aluser *) MALLOC(sizeof(aluser));
user->nick = (char *)MALLOC(strlen(newnick) + 1);
strcpy(user->nick, newnick);
user->username = (char *)MALLOC(strlen(username) + 1);
strcpy(user->username, username);
user->site = (char *)MALLOC(strlen(hostname) + 1);
strcpy(user->site, hostname);
if (*newnick == '+')
serv = &VirtualServer;
//.........这里部分代码省略.........
开发者ID:ArNz8o8,项目名称:undernet-cservice,代码行数:101,代码来源:users.c
示例2: main
int
main(int argc, char *argv[])
{
int fd;
size_t mapped_len;
char *dest;
char *dest1;
char *ret;
START(argc, argv, "pmem_memset");
if (argc != 4)
UT_FATAL("usage: %s file offset length", argv[0]);
fd = OPEN(argv[1], O_RDWR);
/* open a pmem file and memory map it */
if ((dest = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, NULL)) == NULL)
UT_FATAL("!Could not mmap %s\n", argv[1]);
int dest_off = atoi(argv[2]);
size_t bytes = strtoul(argv[3], NULL, 0);
char *buf = MALLOC(bytes);
memset(dest, 0, bytes);
util_persist_auto(util_fd_is_device_dax(fd), dest, bytes);
dest1 = MALLOC(bytes);
memset(dest1, 0, bytes);
/*
* This is used to verify that the value of what a non persistent
* memset matches the outcome of the persistent memset. The
* persistent memset will match the file but may not be the
* correct or expected value.
*/
memset(dest1 + dest_off, 0x5A, bytes / 4);
memset(dest1 + dest_off + (bytes / 4), 0x46, bytes / 4);
/* Test the corner cases */
ret = pmem_memset_persist(dest + dest_off, 0x5A, 0);
UT_ASSERTeq(ret, dest + dest_off);
UT_ASSERTeq(*(char *)(dest + dest_off), 0);
/*
* Do the actual memset with persistence.
*/
ret = pmem_memset_persist(dest + dest_off, 0x5A, bytes / 4);
UT_ASSERTeq(ret, dest + dest_off);
ret = pmem_memset_persist(dest + dest_off + (bytes / 4),
0x46, bytes / 4);
UT_ASSERTeq(ret, dest + dest_off + (bytes / 4));
if (memcmp(dest, dest1, bytes / 2))
UT_ERR("%s: first %zu bytes do not match",
argv[1], bytes / 2);
LSEEK(fd, (os_off_t)0, SEEK_SET);
if (READ(fd, buf, bytes / 2) == bytes / 2) {
if (memcmp(buf, dest, bytes / 2))
UT_ERR("%s: first %zu bytes do not match",
argv[1], bytes / 2);
}
UT_ASSERTeq(pmem_unmap(dest, mapped_len), 0);
FREE(dest1);
FREE(buf);
CLOSE(fd);
DONE(NULL);
}
开发者ID:wojtuss,项目名称:nvml,代码行数:72,代码来源:pmem_memset.c
示例3: alloc_config
struct config *
alloc_config (void)
{
return (struct config *)MALLOC(sizeof(struct config));
}
开发者ID:Aidgas,项目名称:multipath-tools,代码行数:5,代码来源:config.c
示例4: main
//.........这里部分代码省略.........
Currently metadata file don't know anything about multiband imagery.
We will need to convert the current version for single band amplitude
image back to metadata version 0.9 and change a couple of values
sprintf(cmd, "convert_meta %s 1.3 %s 0.9", metaIn, metaOut);
asfSystem(cmd);
*/
newddr.dtype=EBYTE;
newddr.nbands=3;
c_putddr(imgfile,&newddr);
fiamp = fopenImage(fnm1,"rb");
fiphase = fopenImage(fnm2,"rb");
foamp = fopenImage(fnm3,"wb");
fophase = fopenImage(fnm4,"wb");
flas = fopenImage(imgfile,"wb");
/*
* create data buffers
*/
for (i=0;i<256;i++)
{
float phas=((float)i)/256.0*(2*3.14159265358979);
Sin[i]=sin(phas);
Cos[i]=cos(phas);
}
/* set data variables */
ampScale = 1.0/(ll*ls);
nitems = (ll-sl)*inWid;
newitems = sl*inWid;
ds = sizeof(float);
ampIn = (float *)MALLOC(ds*(newitems+nitems+ls));
phaseIn = (float *)MALLOC(ds*(newitems+nitems+ls));
ampOut = (float *)MALLOC(ds*outWid);
ampBuf = (float *)MALLOC(ds*outWid);
phaseOut = (float *)MALLOC(ds*outWid);
table = (RGBDATA *)MALLOC(sizeof(RGBDATA)*MAXENTRIES);
imgData = (RGBDATA *)MALLOC(sizeof(RGBDATA)*outWid);
redPtr = (Uchar *)MALLOC(sizeof(Uchar)*outWid);
grnPtr = (Uchar *)MALLOC(sizeof(Uchar)*outWid);
bluPtr = (Uchar *)MALLOC(sizeof(Uchar)*outWid);
/* calculate mean value */
if (meta_stat->stats)
avg = meta_stat->stats->band_stats[0].mean;
else {
sprintf(cmd, "stats -overmeta -overstat \"%s\"\n", fnm1);
asfSystem(cmd);
meta_free(meta_stat);
meta_stat = meta_read(fnm1);
avg = meta_stat->stats->band_stats[0].mean;
}
/* create a colortable to be used with c2i */
colortable(table);
/* start conversion */
/* printf(" Skipping every %d col and %d row\n",ss,sl);
printf(" Looking at every %d col and %d row\n",ls,ll);*/
printf(" Input is %lld lines by %lld samples\n",inLen,inWid);
printf(" Ouput is %lld lines by %lld samples\n\n",outLen,outWid);
if (logflag) {
sprintf(logbuf, " Input is %lld lines by %lld samples\n",inLen,inWid);
printLog(logbuf);
开发者ID:khogenso,项目名称:ASF_MapReady,代码行数:67,代码来源:multilook.c
示例5: create_frag_shader
static void
create_frag_shader(struct vl_compositor *c)
{
const unsigned max_tokens = 50;
struct pipe_shader_state fs;
struct tgsi_token *tokens;
struct tgsi_header *header;
struct tgsi_full_declaration decl;
struct tgsi_full_instruction inst;
unsigned ti;
unsigned i;
assert(c);
tokens = (struct tgsi_token*)MALLOC(max_tokens * sizeof(struct tgsi_token));
*(struct tgsi_version*)&tokens[0] = tgsi_build_version();
header = (struct tgsi_header*)&tokens[1];
*header = tgsi_build_header();
*(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header);
ti = 3;
/* decl i0 ; Texcoords for s0 */
decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, 1, 0, 0, TGSI_INTERPOLATE_LINEAR);
ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
/*
* decl c0-c3 ; CSC matrix c0-c3
*/
decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 3);
ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
/* decl o0 ; Fragment color */
decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0);
ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
/* decl t0 */
decl = vl_decl_temps(0, 0);
ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
/* decl s0 ; Sampler for tex containing picture to display */
decl = vl_decl_samplers(0, 0);
ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
/* tex2d t0, i0, s0 ; Read src pixel */
inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_INPUT, 0, TGSI_FILE_SAMPLER, 0);
ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
/*
* dp4 o0.x, t0, c0 ; Multiply pixel by the color conversion matrix
* dp4 o0.y, t0, c1
* dp4 o0.z, t0, c2
* dp4 o0.w, t0, c3
*/
for (i = 0; i < 4; ++i) {
inst = vl_inst3(TGSI_OPCODE_DP4, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, i);
inst.FullDstRegisters[0].DstRegister.WriteMask = TGSI_WRITEMASK_X << i;
ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
}
/* end */
inst = vl_end();
ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
assert(ti <= max_tokens);
fs.tokens = tokens;
c->fragment_shader = c->pipe->create_fs_state(c->pipe, &fs);
FREE(tokens);
}
开发者ID:MttDs,项目名称:new-rexeno-tindpe,代码行数:74,代码来源:vl_compositor.c
示例6: while
static char *parse_signature_file(file_stat_t *file_stat, char *pos)
{
while(*pos!='\0')
{
/* skip comments */
while(*pos=='#')
{
while(*pos!='\0' && *pos!='\n')
pos++;
if(*pos=='\0')
return pos;
pos++;
}
/* each line is composed of "extension offset signature" */
{
char *extension;
unsigned int offset=0;
unsigned char *tmp=NULL;
unsigned int signature_max_size=512;
unsigned int signature_size=0;
{
const char *extension_start=pos;
while(*pos!='\0' && !isspace(*pos))
pos++;
if(*pos=='\0')
return pos;
*pos='\0';
extension=strdup(extension_start);
pos++;
}
/* skip space */
while(isspace(*pos))
pos++;
/* read offset */
pos=str_uint(pos, &offset);
/* read signature */
tmp=(unsigned char *)MALLOC(signature_max_size);
while(*pos!='\n' && *pos!='\0')
{
if(signature_size==signature_max_size)
{
unsigned char *tmp_old=tmp;
signature_max_size*=2;
tmp=(unsigned char *)realloc(tmp, signature_max_size);
if(tmp==NULL)
{
free(extension);
free(tmp_old);
return pos;
}
}
if(isspace(*pos) || *pos=='\r' || *pos==',')
pos++;
else if(*pos== '\'')
{
pos++;
if(*pos=='\0')
{
free(extension);
free(tmp);
return pos;
}
else if(*pos=='\\')
{
pos++;
if(*pos=='\0')
{
free(extension);
free(tmp);
return pos;
}
else if(*pos=='b')
tmp[signature_size++]='\b';
else if(*pos=='n')
tmp[signature_size++]='\n';
else if(*pos=='t')
tmp[signature_size++]='\t';
else if(*pos=='r')
tmp[signature_size++]='\r';
else if(*pos=='0')
tmp[signature_size++]='\0';
else
tmp[signature_size++]=*pos;
pos++;
}
else
{
tmp[signature_size++]=*pos;
pos++;
}
if(*pos!='\'')
{
free(extension);
free(tmp);
return pos;
}
pos++;
}
else if(*pos=='"')
{
//.........这里部分代码省略.........
开发者ID:AndrewSmart,项目名称:testdisk,代码行数:101,代码来源:file_sig.c
示例7: change_font
/*
* init = 1 - initialize
*
* fontname == FONT_UP - switch to bigger font
* fontname == FONT_DN - switch to smaller font
*/
void
change_font (int init, const char *fontname)
{
const char *const msg = "can't load font \"%s\"";
XFontStruct *xfont;
static char *newfont[NFONTS];
#ifndef NO_BOLDFONT
static XFontStruct *boldFont = NULL;
#endif
static int fnum = FONT0_IDX; /* logical font number */
int idx = 0; /* index into rs_font[] */
#if (FONT0_IDX == 0)
#define IDX2FNUM(i) (i)
#define FNUM2IDX(f) (f)
#else
#define IDX2FNUM(i) (i == 0? FONT0_IDX : (i <= FONT0_IDX? (i-1) : i))
#define FNUM2IDX(f) (f == FONT0_IDX ? 0 : (f < FONT0_IDX ? (f+1) : f))
#endif
#define FNUM_RANGE(i) (i <= 0 ? 0 : (i >= NFONTS ? (NFONTS-1) : i))
if (!init)
{
switch (fontname[0])
{
case '\0':
fnum = FONT0_IDX;
fontname = NULL;
break;
/* special (internal) prefix for font commands */
case FONT_CMD:
idx = atoi (fontname + 1);
switch (fontname[1])
{
case '+': /* corresponds to FONT_UP */
fnum += (idx ? idx : 1);
fnum = FNUM_RANGE (fnum);
break;
case '-': /* corresponds to FONT_DN */
fnum += (idx ? idx : -1);
fnum = FNUM_RANGE (fnum);
break;
default:
if (fontname[1] != '\0' && !isdigit (fontname[1]))
return;
if (idx < 0 || idx >= (NFONTS))
return;
fnum = IDX2FNUM (idx);
break;
}
fontname = NULL;
break;
default:
if (fontname != NULL)
{
/* search for existing fontname */
for (idx = 0; idx < NFONTS; idx++)
{
if (!strcmp (rs_font[idx], fontname))
{
fnum = IDX2FNUM (idx);
fontname = NULL;
break;
}
}
}
else
return;
break;
}
/* re-position around the normal font */
idx = FNUM2IDX (fnum);
if (fontname != NULL)
{
char *name;
xfont = XLoadQueryFont (Xdisplay, fontname);
if (!xfont)
return;
name = MALLOC (strlen (fontname + 1) * sizeof (char), "font");
if (name == NULL)
{
XFreeFont (Xdisplay, xfont);
return;
}
strcpy (name, fontname);
if (newfont[idx] != NULL)
//.........这里部分代码省略.........
开发者ID:tlwg,项目名称:xiterm-thai,代码行数:101,代码来源:main.c
示例8: main
/*--------------------------------------------------------------------------*/
int main (int argc, char **argv)
{
#define MAXCMDTOKENS 128
int iExitCode = 0;
UINT LastErrorMode = 0;
HINSTANCE hinstLib = NULL;
BOOL fFreeResult = FALSE, fRunTimeLinkSuccess = FALSE;
int argcbis = -1;
LPSTR argvbis[MAXCMDTOKENS];
int i = 0;
int FindNW = 0;
if (GetWindowsVersion() == OS_ERROR )
{
MessageBox(NULL, TEXT(MSG_DETECT_UNKNOW), TEXT(MSG_WARNING), MB_ICONWARNING);
return -1;
}
if (GetWindowsVersion() < OS_WIN32_WINDOWS_XP )
{
MessageBox(NULL, TEXT(MSG_DETECT_XP_OR_MORE), TEXT(MSG_WARNING), MB_ICONWARNING);
return -1;
}
/* http://msdn.microsoft.com/en-us/library/ms724482(VS.85).aspx */
if (!IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE))
{
MessageBox(NULL, TEXT(MSG_DETECT_SSE_OR_MORE), TEXT(MSG_WARNING), MB_ICONWARNING);
return -1;
}
for (i = 0; i < argc; i++)
{
if (_stricmp(argv[i], ARG_NW) == 0) FindNW = 1;
if (_stricmp(argv[i], ARG_NWNI) == 0 ) FindNW = 1;
if (_stricmp(argv[i], ARG_NOGUI) == 0 ) FindNW = 1;
}
if ( FindNW == 0 )
{
/* -nw added as first argument and not last */
char *nwparam = NULL;
nwparam = (char*)MALLOC((strlen(ARG_NW) + 1) * sizeof(char));
strcpy_s(nwparam,(strlen(ARG_NW) + 1), ARG_NW);
argvbis[0] = argv[0];
argvbis[1] = nwparam;
for (i = 1; i<argc; i++)
{
argvbis[i+1] = argv[i];
}
argcbis = argc+1;
}
else
{
for (i = 0; i < argc; i++)
{
argvbis[i] = argv[i];
}
argcbis = argc;
}
/* Disable system errors msgbox */
LastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
hinstLib = LoadLibrary(TEXT(SCILAB_LIBRARY));
/* re enable system errors msgbox */
SetErrorMode(LastErrorMode);
if (hinstLib != NULL)
{
MYPROC1 Console_Main = NULL;
/* launch main */
Console_Main = (MYPROC1) GetProcAddress(hinstLib, MAIN_FUNCTION);
if (NULL != Console_Main)
{
fRunTimeLinkSuccess = TRUE;
#ifndef _DEBUG
/* catch system errors msgbox (release mode only) */
/* http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx */
LastErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS|SEM_NOALIGNMENTFAULTEXCEPT|SEM_NOGPFAULTERRORBOX );
_try
{
#endif
iExitCode = (Console_Main)(argcbis, argvbis);
#ifndef _DEBUG
}
_except (EXCEPTION_EXECUTE_HANDLER)
{
}
#endif
//.........这里部分代码省略.........
开发者ID:rossdrummond,项目名称:scilab,代码行数:101,代码来源:CScilex.c
示例9: InfWriteFile
NTSTATUS
InfWriteFile(HINF InfHandle,
PUNICODE_STRING FileName,
PUNICODE_STRING HeaderComment)
{
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
HANDLE FileHandle;
NTSTATUS Status;
INFSTATUS InfStatus;
PCHAR Buffer;
ULONG BufferSize;
PCHAR HeaderBuffer;
ULONG HeaderBufferSize;
UINT Index;
InfStatus = InfpBuildFileBuffer((PINFCACHE) InfHandle, &Buffer, &BufferSize);
if (! INF_SUCCESS(InfStatus))
{
DPRINT("Failed to create buffer (Status 0x%lx)\n", InfStatus);
return InfStatus;
}
/* Open the inf file */
InitializeObjectAttributes(&ObjectAttributes,
FileName,
0,
NULL,
NULL);
Status = NtOpenFile(&FileHandle,
GENERIC_WRITE | SYNCHRONIZE,
&ObjectAttributes,
&IoStatusBlock,
0,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
if (!INF_SUCCESS(Status))
{
DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
FREE(Buffer);
return Status;
}
DPRINT("NtOpenFile() successful\n");
if (NULL != HeaderComment && 0 != HeaderComment->Length)
{
/* This is just a comment header, don't abort on errors here */
HeaderBufferSize = HeaderComment->Length / sizeof(WCHAR) + 7;
HeaderBuffer = MALLOC(HeaderBufferSize);
if (NULL != HeaderBuffer)
{
strcpy(HeaderBuffer, "; ");
for (Index = 0; Index < HeaderComment->Length / sizeof(WCHAR); Index++)
{
HeaderBuffer[2 + Index] = (CHAR) HeaderComment->Buffer[Index];
}
strcpy(HeaderBuffer + (2 + HeaderComment->Length / sizeof(WCHAR)),
"\r\n\r\n");
NtWriteFile(FileHandle,
NULL,
NULL,
NULL,
&IoStatusBlock,
HeaderBuffer,
HeaderBufferSize,
NULL,
NULL);
FREE(HeaderBuffer);
}
}
/* Write main contents */
Status = NtWriteFile(FileHandle,
NULL,
NULL,
NULL,
&IoStatusBlock,
Buffer,
BufferSize,
NULL,
NULL);
NtClose(FileHandle);
FREE(Buffer);
if (!INF_SUCCESS(Status))
{
DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
FREE(Buffer);
return(Status);
}
return STATUS_SUCCESS;
}
开发者ID:HBelusca,项目名称:NasuTek-Odyssey,代码行数:95,代码来源:infrosput.c
示例10: create_file_names
static void create_file_names(void)
{
register int len;
register char *defines_suffix;
register char *prefix;
prefix = NULL;
defines_suffix = DEFINES_SUFFIX;
/* compute the file_prefix from the user provided output_file_name */
if (output_file_name != 0)
{
defines_suffix = ".h";
if (!(prefix = is_suffix(output_file_name, ".cpp")))
prefix = is_suffix(output_file_name, "");
}
if (prefix != NULL)
{
len = prefix - output_file_name;
file_prefix = (char *)MALLOC(len + 1);
if (file_prefix == 0)
no_space();
strncpy(file_prefix, output_file_name, len)[len] = 0;
}
else
len = strlen(file_prefix);
/* if "-o filename" was not given */
if (output_file_name == 0)
{
oflag = 1;
CREATE_FILE_NAME(output_file_name, OUTPUT_SUFFIX);
}
if (rflag)
{
CREATE_FILE_NAME(code_file_name, CODE_SUFFIX);
}
else
code_file_name = output_file_name;
if (dflag)
{
CREATE_FILE_NAME(defines_file_name, defines_suffix);
}
if (vflag)
{
CREATE_FILE_NAME(verbose_file_name, VERBOSE_SUFFIX);
}
if (gflag)
{
CREATE_FILE_NAME(graph_file_name, GRAPH_SUFFIX);
}
if (prefix != NULL)
{
FREE(file_prefix);
}
create_temp_name(&text_file_name, output_file_name, ".byacc.text");
create_temp_name(&union_file_name, output_file_name, ".byacc.union");
create_temp_name(&action_file_name, output_file_name, ".byacc.action");
}
开发者ID:Mirocow,项目名称:balancer,代码行数:66,代码来源:main.c
示例11: MALLOC
void *mxMalloc(size_t nsize)
{
//TODO
return MALLOC(nsize);
}
开发者ID:scitao,项目名称:scilab,代码行数:5,代码来源:mexlib.cpp
示例12: CKTnoise
int
CKTnoise (CKTcircuit *ckt, int mode, int operation, Ndata *data)
{
double outNdens;
int i;
extern SPICEdev **DEVices;
IFvalue outData; /* output variable (points to list of outputs)*/
IFvalue refVal; /* reference variable (always 0)*/
int error;
outNdens = 0.0;
/* let each device decide how many and what type of noise sources it has */
for (i=0; i < DEVmaxnum; i++) {
if ( DEVices[i] && ((*DEVices[i]).DEVnoise != NULL) && (ckt->CKThead[i] != NULL) ) {
error = (*((*DEVices[i]).DEVnoise))(mode,operation,ckt->CKThead[i],
ckt,data, &outNdens);
if (error) return (error);
}
}
switch (operation) {
case N_OPEN:
/* take care of the noise for the circuit as a whole */
switch (mode) {
case N_DENS:
data->namelist = (IFuid *)trealloc((char *)data->namelist,
(data->numPlots + 1)*sizeof(IFuid));
(*(SPfrontEnd->IFnewUid))(ckt, &(data->namelist[data->numPlots++]),
(IFuid)NULL,"onoise_spectrum",UID_OTHER,(void **)NULL);
data->namelist = (IFuid *)trealloc((char *)data->namelist,
(data->numPlots + 1)*sizeof(IFuid));
(*(SPfrontEnd->IFnewUid))(ckt, &(data->namelist[data->numPlots++]),
(IFuid)NULL,"inoise_spectrum",UID_OTHER,(void **)NULL);
/* we've added two more plots */
data->outpVector =
(double *)MALLOC(data->numPlots * sizeof(double));
break;
case INT_NOIZ:
data->namelist = (IFuid *)trealloc((char *)data->namelist,
(data->numPlots + 1)*sizeof(IFuid));
(*(SPfrontEnd->IFnewUid))(ckt, &(data->namelist[data->numPlots++]),
(IFuid)NULL,"onoise_total",UID_OTHER,(void **)NULL);
data->namelist = (IFuid *)trealloc((char *)data->namelist,
(data->numPlots + 1)*sizeof(IFuid));
(*(SPfrontEnd->IFnewUid))(ckt, &(data->namelist[data->numPlots++]),
(IFuid)NULL,"inoise_total",UID_OTHER,(void **)NULL);
/* we've added two more plots */
data->outpVector =
(double *) MALLOC(data->numPlots * sizeof(double));
break;
default:
return (E_INTERN);
}
break;
case N_CALC:
switch (mode) {
case N_DENS:
if ((((NOISEAN*)ckt->CKTcurJob)->NStpsSm == 0)
|| data->prtSummary)
{
data->outpVector[data->outNumber++] = outNdens;
data->outpVector[data->outNumber++] =
(outNdens * data->GainSqInv);
refVal.rValue = data->freq; /* the reference is the freq */
outData.v.numValue = data->outNumber; /* vector number */
outData.v.vec.rVec = data->outpVector; /* vector of outputs */
(*(SPfrontEnd->OUTpData))(data->NplotPtr,&refVal,&outData);
}
break;
case INT_NOIZ:
data->outpVector[data->outNumber++] = data->outNoiz;
data->outpVector[data->outNumber++] = data->inNoise;
outData.v.vec.rVec = data->outpVector; /* vector of outputs */
outData.v.numValue = data->outNumber; /* vector number */
(*(SPfrontEnd->OUTpData))(data->NplotPtr,&refVal,&outData);
break;
//.........这里部分代码省略.........
开发者ID:rsa-key-20090516,项目名称:ngspice-gss,代码行数:101,代码来源:cktnoise.c
示例13: main
int main (int argc, char *argv[])
{
char cpxName[BUF],ampName[BUF],phsName[BUF]; /* File Names */
FILE *fdCpx, *fdAmp, *pdPhs; /* File Pointers */
int line, sample; /* Line & sample indices for looping*/
int percentComplete; /* Percent of data processed */
int ampBlockSize, phsBlockSize; /* Number of samples gotten */
float *ampBuf, *aP, *phsBuf, *pP; /* Output data buffers */
complexFloat *cpxBuf, *cP; /* Input data buffers */
meta_parameters *inMeta, *outMeta; /* In/Out meta structs */
int i, phaseImage=FALSE;
/* Make sure there are the correct number of args in the command line */
if (argc < 3) { usage(argv[0]); }
/* Make sure input and output names are different */
if (strcmp(argv[1],argv[2])==0) {
printf("p2c: Input and output names cannot be the same. Exiting.\n");
exit(EXIT_FAILURE);
}
/* Get commandline args */
create_name (ampName,argv[1],".amp");
create_name (phsName,argv[1],".phase");
create_name (cpxName,argv[2],".cpx");
// Check whether phase image actually exists. If it does not exist, we will
// generate a phase image with a constant value on the fly.
if (fileExists(phsName))
phaseImage = TRUE;
else
printf("\nCould not find phase image! Generating constant phase image on "
"the fly ...\n");
/* Read the meta data. Write output meta with COMPLEX_* data type. */
inMeta = meta_read(argv[1]);
outMeta = meta_read(argv[1]);
outMeta->general->data_type = meta_polar2complex(inMeta->general->data_type);
meta_write(outMeta,argv[2]);
/* malloc buffers, check and open files */
cpxBuf = (complexFloat *)MALLOC(sizeof(complexFloat)
* outMeta->general->sample_count * CHUNK_OF_LINES);
ampBuf = (float *)MALLOC(sizeof(float)
* inMeta->general->sample_count * CHUNK_OF_LINES);
phsBuf = (float *)MALLOC(sizeof(float)
* inMeta->general->sample_count * CHUNK_OF_LINES);
fdCpx = fopenImage(cpxName, "wb");
fdAmp = fopenImage(ampName, "rb");
pdPhs = fopenImage(phsName, "rb");
/* Run thru the complex file, writing real data to amp and imag data to phase */
printf("\n");
percentComplete = 0;
for (line=0; line<inMeta->general->line_count; line+=CHUNK_OF_LINES)
{
if ((line*100/inMeta->general->line_count == percentComplete)) {
printf("\rConverting amp and phase to complex: %3d%% complete.",
percentComplete++);
fflush(NULL);
}
ampBlockSize = get_float_lines(fdAmp,inMeta,line,CHUNK_OF_LINES,ampBuf);
if (phaseImage) {
phsBlockSize = get_float_lines(pdPhs,inMeta,line,CHUNK_OF_LINES,phsBuf);
if (ampBlockSize != phsBlockSize) {
printf("\n");
printf("p2c: Failed to get the same number of samples from amplitude and phase files.\n");
printf("p2c: Exiting...\n\n");
exit(EXIT_FAILURE);
}
}
else {
for (i=0; i<inMeta->general->sample_count*CHUNK_OF_LINES; i++)
phsBlockSize = 0.0;
}
cP = cpxBuf;
aP = ampBuf;
pP = phsBuf;
for (sample=0; sample<ampBlockSize; sample++) {
cP->real = *aP * cos(*pP);
cP->imag = *aP * sin(*pP);
cP++;
aP++;
pP++;
}
put_complexFloat_lines(fdCpx,outMeta,line,CHUNK_OF_LINES,cpxBuf);
}
printf("\rConverted amp and phase to complex: 100%% complete.\n\n");
/* close, free, halt */
FCLOSE(fdCpx);
FCLOSE(fdAmp);
FCLOSE(pdPhs);
FREE(cpxBuf);
FREE(ampBuf);
FREE(phsBuf);
meta_free(inMeta);
meta_free(outMeta);
return 0;
//.........这里部分代码省略.........
开发者ID:DavinSimmons,项目名称:ASF_MapReady,代码行数:101,代码来源:p2c.c
示例14: get_bladehpi_hostlist
static int
get_bladehpi_hostlist(struct pluginDevice *dev)
{
struct blade_info * bi;
SaErrorT ohrc;
SaHpiEntryIdT ohnextid;
SaHpiRptEntryT ohRPT;
SaHpiDomainInfoT ohdi;
SaHpiUint32T ohupdate;
if (Debug) {
LOG(PIL_DEBUG, "%s: called, dev->device=%s"
, __FUNCTION__, dev->device);
}
if (dev->device == NULL || *dev->device == 0) {
LOG(PIL_CRIT, "Unconfigured stonith object in %s"
, __FUNCTION__);
return S_BADCONFIG;
}
ohrc = saHpiDomainInfoGet(dev->ohsession, &ohdi);
if (ohrc != SA_OK) {
LOG(PIL_CRIT, "Unable to get domain info in %s (%d)"
, __FUNCTION__, ohrc);
return S_BADCONFIG;
}
try_again:
ohupdate = ohdi.RptUpdateCount;
dev->ohdevid = dev->ohsensid = dev->ohsensnum = 0;
ohnextid = SAHPI_FIRST_ENTRY;
do {
char blname[SAHPI_MAX_TEXT_BUFFER_LENGTH];
int blnum;
ohrc = saHpiRptEntryGet(dev->ohsession, ohnextid
, &ohnextid, &ohRPT);
if (ohrc != SA_OK) {
LOG(PIL_CRIT, "Unable to get RPT entry in %s (%d)"
, __FUNCTION__, ohrc);
free_bladehpi_hostlist(dev);
return S_BADCONFIG;
}
switch (get_resource_type(dev->device, &ohRPT)) {
case OHRES_BLADECENT:
dev->ohdevid = ohRPT.ResourceId;
if (Debug) {
LOG(PIL_DEBUG, "BladeCenter '%s' has id %d"
, (char*)ohRPT.ResourceTag.Data
, dev->ohdevid);
}
break;
case OHRES_MGMTMOD:
if (ohRPT.ResourceCapabilities&SAHPI_CAPABILITY_SENSOR){
dev->ohsensnum = get_sensor_num(dev->ohsession
, ohRPT.ResourceId);
if (dev->ohsensnum) {
dev->ohsensid = ohRPT.ResourceId;
if (Debug) {
LOG(PIL_DEBUG
, "MgmtModule '%s' has id %d "
"with sensor #%d"
, (char*)ohRPT.ResourceTag.Data
, dev->ohsensid
, dev->ohsensnum);
}
}
}
break;
case OHRES_BLADE:
if ((bi = (struct blade_info *)
MALLOC(sizeof(struct blade_info))) == NULL) {
LOG(PIL_CRIT, "Out of memory in %s"
, __FUNCTION__);
free_bladehpi_hostlist(dev);
return S_OOPS;
}
/*
* New format consists of "Blade N - name" while older
* format consists only of "name"; we only need to
* stash name because ResourceID is the important info
*/
if (sscanf((char*)ohRPT.ResourceTag.Data, "Blade %d - %s"
, &blnum, blname) == 2) {
bi->name = STRDUP(blname);
} else {
bi->name = STRDUP((char*)ohRPT.ResourceTag.Data);
}
if (bi->name == NULL) {
LOG(PIL_CRIT, "Out of memory for strdup in %s"
, __FUNCTION__);
free_bladehpi_hostlist(dev);
//.........这里部分代码省略.........
开发者ID:ystk,项目名称:debian-cluster-glue,代码行数:101,代码来源:bladehpi.c
示例15: main
//.........这里部分代码省略.........
/*
Read the file and locate the index of the dependent variable
*/
if (readfile ( filename , &nvars , &names , &ncases , &data ))
return EXIT_FAILURE ;
for (idep=0 ; idep<nvars ; idep++) {
if (! strcmp ( depname , names[idep] ))
break ;
}
if (idep == nvars) {
printf ( "\nERROR... Dependent variable %s is not in file", depname ) ;
return EXIT_FAILURE ;
}
if (idep < n_indep_vars) {
printf ( "\nERROR... Dependent variable %s must be beyond independent vars",
depname ) ;
return EXIT_FAILURE ;
}
/*
Allocate scratch memory
crits - Transfer Entropy criterion
index - Indices that sort the criterion
save_info - Ditto, this is univariate criteria, to be sorted
*/
MEMTEXT ( "TRANSFER work allocs" ) ;
work = (double *) MALLOC ( ncases * sizeof(double) ) ;
assert ( work != NULL ) ;
crits = (double *) MALLOC ( n_indep_vars * sizeof(double) ) ;
assert ( crits != NULL ) ;
index = (int *) MALLOC ( n_indep_vars * sizeof(int) ) ;
assert ( index != NULL ) ;
bins_indep = (short int *) MALLOC ( ncases * sizeof(short int) ) ;
assert ( bins_indep != NULL ) ;
bins_dep = (short int *) MALLOC ( ncases * sizeof(short int) ) ;
assert ( bins_dep != NULL ) ;
mcpt_max_counts = (int *) MALLOC ( n_indep_vars * sizeof(int) ) ;
assert ( mcpt_max_counts != NULL ) ;
mcpt_same_counts = (int *) MALLOC ( n_indep_vars * sizeof(int) ) ;
assert ( mcpt_same_counts != NULL ) ;
mcpt_solo_counts = (int *) MALLOC ( n_indep_vars * sizeof(int) ) ;
assert ( mcpt_solo_counts != NULL ) ;
save_info = (double *) MALLOC ( n_indep_vars * sizeof(double) ) ;
assert ( save_info != NULL ) ;
count = (int *) MALLOC ( nbins * nbins * nbins * sizeof(int) ) ;
assert ( count != NULL ) ;
ab = (double *) MALLOC ( nbins * nbins * sizeof(double) ) ;
assert ( ab != NULL ) ;
bc = (double *) MALLOC ( nbins * nbins * sizeof(double) ) ;
assert ( bc != NULL ) ;
b = (double *) MALLOC ( nbins * sizeof(double) ) ;
assert ( b != NULL ) ;
/*
Get the dependent variable and partition it
*/
for (i=0 ; i<ncases ; i++) // Get the 'dependent' variable
work[i] = data[i*nvars+idep] ;
开发者ID:abishekahluwaila,项目名称:read,代码行数:67,代码来源:TRANSFER.CPP
示例16: sci_mcisendstring
/*--------------------------------------------------------------------------*/
int sci_mcisendstring(char *fname,unsigned long l)
{
int m1,n1,l1;
char *Output=NULL;
int *BoolOutput=NULL;
int *CodeOutput=NULL;
CheckRhs(1,1);
CheckLhs(1,3);
if (GetType(1) == sci_strings)
{
MCIERROR Error;
char *MCICommand=NULL;
char ReturnString[2048];
GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
MCICommand=cstk(l1);
Error=mciSendString(MCICommand,(LPSTR)ReturnString,sizeof(ReturnString),NULL);
BoolOutput=(int*)MALLOC(sizeof(int));
CodeOutput=(int*)MALLOC(sizeof(int));
*BoolOutput=(int)0;
*CodeOutput=(int)Error;
if (Error)
{
char ErrorText[128];
*BoolOutput=(int)FALSE;
if ( mciGetErrorString(Error,ErrorText,sizeof(ErrorText)) == FALSE )
{
wsprintf(ErrorText,"%s","Unknown MCI error");
}
Output = strdup(ErrorText);
}
else
{
*BoolOutput=(int)TRUE;
Output = strdup("OK");
}
n1=1;
if ( Lhs == 1 )
{
CreateVarFromPtr(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &BoolOutput);
LhsVar(1)=Rhs+1;
}
else
if ( Lhs == 2 )
{
CreateVarFromPtr(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &BoolOutput);
LhsVar(1)=Rhs+1;
CreateVarFromPtr(Rhs+2,MATRIX_OF_INTEGER_DATATYPE, &n1, &n1, &CodeOutput);
LhsVar(2)=Rhs+2;
}
else /* Lhs == 3 */
{
CreateVarFromPtr(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &BoolOutput);
LhsVar(1)=Rhs+1;
CreateVarFromPtr(Rhs+2,MATRIX_OF_INTEGER_DATATYPE, &n1, &n1, &CodeOutput);
LhsVar(2)=Rhs+2;
CreateVarFromPtr(Rhs+ 3,STRING_DATATYPE,(m1=(int)strlen(Output), &m1),&n1,&Output);
LhsVar(3)=Rhs+3;
}
if (Output) {FREE(Output);Output=NULL;}
if (BoolOutput) {FREE(BoolOutput);BoolOutput=NULL;}
if (CodeOutput) {FREE(CodeOutput);Output=NULL;}
PutLhsVar();
return 0;
}
else
{
Scierror(999,_("%s: Wrong type for input argument #%d: String expected.\n"),fname,1);
return 0;
}
}
开发者ID:vinayrajchoudhary,项目名称:scilab,代码行数:88,代码来源:sci_mcisendstring.c
示例17: getConvertedDateAsDoubleVector
/*--------------------------------------------------------------------------*/
double *getConvertedDateAsMatrixOfDouble(double *dDates, int nbElements, int *iErr)
{
double *dResults = NULL;
int lenResults = nbElements * NB_ELEMNT_ARRAY_GETDATE;
*iErr = 1;
dResults = (double*)MALLOC(sizeof(double) * lenResults);
if (dResults)
{
int k = 0;
int j = 0;
int m = 0;
int n = 0;
double *dResTmp = NULL;
for (k = 0; k < lenResults; k++)
{
dResults[k] = 0;
}
*iErr = 0;
for (k = 0; k < nbElements; k++)
{
int iErr2 = 0;
double *dConverted = getConvertedDateAsDoubleVector(dDates[k], &iErr2);
if (iErr2 == 0)
{
int n = 0;
for (n = 0; n < NB_ELEMNT_ARRAY_GETDATE; n++)
{
dResults[j] = dConverted[n];
j++;
}
FREE(dConverted);
dConverted = NULL;
}
else
{
FREE(dResults);
FREE(dConverted);
dResults = NULL;
*iErr = iErr2;
return NULL;
}
}
m = nbElements;
n = NB_ELEMNT_ARRAY_GETDATE;
dResTmp = transposeMatrixDouble(n, m, dResults);
if (dResTmp)
{
FREE(dResults);
dResults = dResTmp;
*iErr = 0;
}
else
{
*iErr = 1;
}
}
return dResults;
}
开发者ID:leowzukw,项目名称:scilab-mirror,代码行数:66,代码来源:getdate.c
示例18: main
int main(int argc, char **argv)
{
/* SOLVER choice: 1 pcg
2 sbcg
3 bcg
4 sqmr
8 gmres
9 fgmres */
integer SOLVER=4; /* sqmr */
CSRMAT A, ilutmat;
AMGLEVELMAT PRE, *next;
integer nlev=0, nprev, nB;
integer (*perm0)(),(*perm)(),(*permf)();
FILE *fp, *fo;
char rhstyp[3], title[73], key[9], type[3], fname[100], foname[100];
char line[MAX_LINE], *tmpstring, timeout[7], residout[7];
integer i,j,k,m,fnamelen,n,nc,nz,nrhs,mynrhs=2,tmp0,tmp,tmp2,tmp3,ierr,flag,
*invperm, *buff, *ws, *symmmd,flags,elbow,max_it,ipar[20],
nrhsix, *rhsptr, *rhsind, sumit;
REALS eps, DROP_TOL, CONDEST,condest,droptols[2],restol, val,vb;
FLOAT *rhs,*sol,*w, *scale, *rhsval, *dbuff;
float systime, time_start, time_stop, secnds, secndsprep,
timeAx_start, timeAx_stop, secndsAx, sumtime;
integer ELBOW, nnzU, l, nAx;
ILUPACKPARAM param;
size_t nibuff, ndbuff;
/* the last argument passed serves as file name */
if (argc!=5) {
printf("usage '%s <drop tol.> <bound for L^{-1},U^{-1}> <elbow space> <matrix>'\n",argv[0]);
exit(0);
}
i=0;
while (argv[argc-1][i]!='\0')
{
fname[i]=argv[argc-1][i];
i++;
} /* end while */
fname[i]='\0';
fnamelen=i;
while (i>=0 && fname[i]!='/')
i--;
i++;
j=0;
while (i<fnamelen && fname[i]!='.')
foname[j++]=fname[i++];
while (j<16)
foname[j++]=' ';
foname[j]='\0';
ELBOW=atoi(argv[argc-2]);
CONDEST=atof(argv[argc-3]);
DROP_TOL=atof(argv[argc-4]);
/* read in a symmetric matrix in Harwell-Boeing format.
By definition Harwell-Boeing format stores a matrix in compressed sparse
|
请发表评论