original files of m241

This commit is contained in:
neelimap
2026-07-30 11:19:44 +05:30
parent 170c2b3f3a
commit afc7070c1f
12254 changed files with 7655111 additions and 0 deletions
@@ -0,0 +1,24 @@
# Makefile - makefile for target/src/scopetools
#
# modification history
# --------------------
# 01a,26mar06,c_c created.
#
# DESCRIPTION
# This file contains the makefile rules for building the scopetools libraries
#
#*/
TGT_DIR=$(WIND_BASE)/target
TOOLS_SRC_ROOT = ../../..
LIB_BASE_NAME = matlabls
EXTRA_INCLUDE = -I$(TOOLS_SRC_ROOT)/rtilib/include/share
DOC_FILES=
OBJS= loadmat.o savemat.o testls.o
include $(TOOLS_SRC_ROOT)/make/common_rules.mk
# end of rtilib/utils/matlabls
@@ -0,0 +1,140 @@
/* loadmat.c - brief C language routine to load a matrix from a MAT-file. */
/*
* Copyright (c) 1990-2009, 2013 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
-------------------
01c,10oct13,wzc Fix prevent warnings.
01b,29jun12,wzc WIND00350881 - check malloc return value.
01a,23jul09,wzc Change copyright notice and module layout.
01a,30jun09,wzc fix coverity prevent errors
Converted to ANSI-C, Stan Schneider, 1990
Author J.N. Little 11-3-86
*/
/* $Id: loadmat.c,v 1.6 2002/07/03 00:11:54 gordon Exp $ */
/*
DESCRIPTION
Brief C language routine to load a matrix from a MAT-file.
*/
/* includes */
#include <stdio.h>
#include <stdlib.h>
#include "rtilib/makeheader.h"
/* defines */
typedef struct {
long type; /* type */
long mrows; /* row dimension */
long ncols; /* column dimension */
long imagf; /* flag indicating imag part */
long namlen; /* name length (including NULL) */
} Fmatrix;
Public
/*i
Here is an example that uses 'loadmat' to load a matrix from a MAT-file:
\verbatim
FILE *fp;
char name[20];
int type, mrows, ncols, imagf;
double *xr, *xi;
fp = fopen("foo.mat","r");
loadmat(fp, &type, name, &mrows, &ncols, &imagf, &xr, &xi);
fclose(fp);
free(xr);
if (imagf) free(xi);
\endverbatim
The 'loadmat' routine returns 0 if the read is successful and 1 if
and end-of-file or read error is encountered. 'loadmat' can be called
repeatedly until the file is exhausted and an EOF is encountered.
*/
int loadmat(
FILE *fp, /* File pointer */
int *type, /* Type flag: see reference section of guide */
char *pname, /* pointer to matrix name */
int *mrows, /* row dimension */
int *ncols, /* column dimension */
int *imagf, /* imaginary flag */
double **preal, /* pointer to real data */
double **pimag) /* pointer to imag data */
{
Fmatrix x = {0,0,0,0,0};
size_t mn;
size_t namlen;
size_t len;
/*
* Get Fmatrix structure from file
*/
if (fread((char *)&x, sizeof(Fmatrix), 1, fp) != 1) {
return(1);
}
/* coverity[parm_assign] */
*type = (int)(x.type);
/* coverity[parm_assign] */
*mrows = (int)(x.mrows);
/* coverity[parm_assign] */
*ncols = (int)(x.ncols);
/* coverity[parm_assign] */
*imagf = (int)(x.imagf);
/* coverity[parm_assign] */
namlen = (size_t)(x.namlen);
/* coverity[overflow_assign] */
mn = (size_t)(x.mrows * x.ncols);
/*
* Get matrix name from file
*/
if (fread(pname, sizeof(char), namlen, fp) != namlen) {
return(1);
}
/*
* Get Real part of matrix from file
*/
/* coverity[overflow_assign] */
len = (size_t)(mn*sizeof(double));
*preal = (double *)malloc(len);
if (!(*preal)) {
printf("\nError: Variable too big to load\n");
return(1);
}
if (fread(*preal, sizeof(double), mn, fp) != mn) {
free(*preal);
return(1);
}
/*
* Get Imag part of matrix from file, if it exists
*/
if (x.imagf) {
*pimag = (double *)malloc(len);
if (!(*pimag)) {
printf("\nError: Variable too big to load\n");
free(*preal);
return(1);
}
if (fread(*pimag, sizeof(double), mn, fp) != mn) {
free(*pimag);
free(*preal);
return(1);
}
}
return(0);
}
@@ -0,0 +1,24 @@
# -*- Makefile -*-
# modification history
# --------------------
# --------------------------------------------------------------------------
# $Id: matlablsh.win32,v 1.3 2004/06/08 17:53:51 rwarren Exp $
DIR = .
matlablshSources = loadmat.c savemat.c
../../include/win32/rtilib/matlabls.h : $(matlablshSources)
makeheader -C -k Public -o $@ $^
@@ -0,0 +1,85 @@
/* savemat.c - brief C language routine to save a matrix from a MAT-file */
/*
* Copyright (c) 1990-2009 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
---------------------
01a,23jul09,wzc Change copyright notice and module layout.
Converted to ANSI-C, Stan Schneider, 1990
Author J.N. Little 11-3-86
*/
/* $Id: savemat.c,v 1.4 2002/07/03 00:11:54 gordon Exp $ */
/*
DESCRIPTION
brief C language routine to save a matrix from a MAT-file.
*/
/* includes */
#include <stdio.h>
#include <string.h>
#include "rtilib/makeheader.h"
/* defines */
typedef struct {
long type; /* type */
long mrows; /* row dimension */
long ncols; /* column dimension */
long imagf; /* flag indicating imag part */
long namlen; /* name length (including NULL) */
} Fmatrix;
Public
/*i
Here is an example that uses 'savemat' to save two matrices to disk,
the second of which is complex:
/verbatim
FILE *fp;
double xyz[1000], ar[1000], ai[1000];
fp = fopen("foo.mat","w");
savemat(fp, 2000, "xyz", 2, 3, 0, xyz, (double *)0);
savemat(fp, 2000, "a", 5, 5, 1, ar, ai);
fclose(fp);
/endverbatim
*/
void savemat(
FILE *fp, /* File pointer */
int type, /* Type flag: Normally 0 for PC, 1000 for Sun and Mac, */
/* 2000 for VAX. Add 1 for text variables. */
/* See LOAD in reference section of guide for more info. */
char *pname, /* pointer to matrix name */
int mrows, /* row dimension */
int ncols, /* column dimension */
int imagf, /* imaginary flag */
double *preal, /* pointer to real data */
double *pimag) /* pointer to imag data */
{
Fmatrix x;
int mn;
x.type = type;
x.mrows = mrows;
x.ncols = ncols;
x.imagf = imagf;
x.namlen = strlen(pname) + 1;
mn = x.mrows * x.ncols;
fwrite(&x, sizeof(Fmatrix), 1, fp);
fwrite(pname, sizeof(char), (int)x.namlen, fp);
fwrite(preal, sizeof(double), mn, fp);
if (imagf) {
fwrite(pimag, sizeof(double), mn, fp);
}
}
@@ -0,0 +1,99 @@
/* testls.c - */
/*
* Copyright (c) 2001-2009, 2013 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
01c,12oct13,wzc Fix prevent warnings.
01b,21jun13,wzc WIND00422900 - fix prevent warnings.
01a,23jul09,wzc Change copyright notice and module layout.
*/
/*
DESCRIPTION
A C-language version test routine that shows the use of the
C-language 'loadmat' and 'savemat' to read and write MAT-files.
Author: J.N. Little 11-10-86
*/
/* includes */
#include <stdio.h>
#include <stdlib.h>
/* defines */
extern int loadmat(
FILE *fp, /* File pointer */
int *type, /* Type flag: see reference section of guide */
char *pname, /* pointer to matrix name */
int *mrows, /* row dimension */
int *ncols, /* column dimension */
int *imagf, /* imaginary flag */
double **preal, /* pointer to real data */
double **pimag);
extern void savemat(
FILE *fp, /* File pointer */
int type, /* Type flag: Normally 0 for PC, 1000 for Sun and Mac, */
/* 2000 for VAX. Add 1 for text variables. */
/* See LOAD in reference section of guide for more info. */
char *pname, /* pointer to matrix name */
int mrows, /* row dimension */
int ncols, /* column dimension */
int imagf, /* imaginary flag */
double *preal, /* pointer to real data */
double *pimag);
int main(void)
{
FILE *fp, *fopen();
char name[20] = {0};
int type, mrows, ncols, imagf;
double *xr, *xi;
/*
* Use this fopen on systems that do newline translation, for
* example C86 compiler under MS-DOS
*
* fp = fopen("foo.mat","rb");
*/
fp = fopen("foo.mat","r");
if (fp == NULL)
{
printf("\nfopen error\n");
return -1;
}
/* coverity[tainted_data] */
if (loadmat(fp, &type, &name[0], &mrows, &ncols, &imagf, &xr, &xi)) {
printf("\nRead error\n");
}
fclose(fp);
/*
* fp = fopen("bar.mat","wb");
*/
fp = fopen("bar.mat","w");
if (fp == NULL)
{
printf("\nfopen error\n");
return -1;
}
/* coverity[tainted_data] */
savemat(fp, type, &name[0], mrows, ncols, imagf, xr, xi);
fclose(fp);
free(xr);
if (imagf) {
free(xi);
}
return 0;
}