back up 3分开没事,一起就堆栈错误

总的

/*
 * File: main.c
 *
 * MATLAB Coder version            : 4.1
 * C/C++ source code generated on  : 18-Apr-2024 10:01:12
 */

/*************************************************************************/
/* This automatically generated example C main file shows how to call    */
/* entry-point functions that MATLAB Coder generated. You must customize */
/* this file for your application. Do not modify this file directly.     */
/* Instead, make a copy of this file, modify it, and integrate it into   */
/* your development environment.                                         */
/*                                                                       */
/* This file initializes entry-point function arguments to a default     */
/* size and value before calling the entry-point functions. It does      */
/* not store or use any values returned from the entry-point functions.  */
/* If necessary, it does pre-allocate memory for returned values.        */
/* You can use this file as a starting point for a main function that    */
/* you can deploy in your application.                                   */
/*                                                                       */
/* After you copy the file, and before you deploy it, you must make the  */
/* following changes:                                                    */
/* * For variable-size function arguments, change the example sizes to   */
/* the sizes that your application requires.                             */
/* * Change the example values of function arguments to the values that  */
/* your application requires.                                            */
/* * If the entry-point functions return values, store these values or   */
/* otherwise use them as required by your application.                   */
/*                                                                       */
/*************************************************************************/
/* Include Files */
#define _CRT_SECURE_NO_WARNINGS
#include "rt_nonfinite.h"
#include "TERCOMwry.h"
#include "main.h"
#include "TERCOMwry_terminate.h"
#include "TERCOMwry_initialize.h"
#include "stdio.h"
//#include "algorithm"
#include "stdlib.h"
//using namespace std;
/* Function Declarations */
//static void argInit_151x151_real_T(double result[22801]);
//static void argInit_151x1_real_T(double result[151]);
//static void argInit_60x1_real_T(double result[60]);
//static void argInit_60x21_real_T(double result[1260]);
//static void argInit_60x8_real_T(double result[480]);
static double argInit_real_T(void);
static void main_TERCOMwry(void);

/* Function Definitions */

/*
 * Arguments    : double result[22801]
 * Return Type  : void
 */
static void argInit_151x151_real_T(double result[22801])
{
  int idx0;
  int idx1;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 151; idx0++) {
    for (idx1 = 0; idx1 < 151; idx1++) {
      /* Set the value of the array element.
         Change this value to the value that the application requires. */
      result[idx0 + 151 * idx1] = argInit_real_T();
    }
  }
}

/*
 * Arguments    : double result[151]
 * Return Type  : void
 */
static void argInit_151x1_real_T(double result[151])
{
  int idx0;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 151; idx0++) {
    /* Set the value of the array element.
       Change this value to the value that the application requires. */
    result[idx0] = argInit_real_T();
  }
}

/*
 * Arguments    : double result[60]
 * Return Type  : void
 */
static void argInit_60x1_real_T(double result[60])
{
  int idx0;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 60; idx0++) {
    /* Set the value of the array element.
       Change this value to the value that the application requires. */
    result[idx0] = argInit_real_T();
  }
}

/*
 * Arguments    : double result[1260]
 * Return Type  : void
 */
static void argInit_60x21_real_T(double result[1260])
{
  int idx0;
  int idx1;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 60; idx0++) {
    for (idx1 = 0; idx1 < 21; idx1++) {
      /* Set the value of the array element.
         Change this value to the value that the application requires. */
      result[idx0 + 60 * idx1] = argInit_real_T();
    }
  }
}

/*
 * Arguments    : double result[480]
 * Return Type  : void
 */
static void argInit_60x8_real_T(double result[480])
{
  int idx0;
  int idx1;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 60; idx0++) {
    for (idx1 = 0; idx1 < 8; idx1++) {
      /* Set the value of the array element.
         Change this value to the value that the application requires. */
      result[idx0 + 60 * idx1] = argInit_real_T();
    }
  }
}

/*
 * Arguments    : void
 * Return Type  : double
 */
static double argInit_real_T(void)
{
  return 0.0;
}

/*
 * Arguments    : void
 * Return Type  : void
 */
static void main_TERCOMwry(void)
{
 /*double Lon_tmp[151];
  double Lat_tmp[151];
  static double g[22801];
  double dv1[1260];
  double dv2[480];
  double dv3[60];
  double dv4[60];
  double true_trace1[120];
  double ins_trace1[120];
  double delta_g_new[60];
  static double matchline[29160];
  double match_num;
  double final_match[120];
  double X_err[60];
  double Y_err[60];
  double P_err[60];
  double delta_lat_ins[60];
  double delta_lon_ins[60];
  double delta_P_ins[60];
  double Distance;
  */
  /* Initialize function 'TERCOMwry' input arguments. */
  /* Initialize function input argument 'Lon'. */
 /* argInit_151x1_real_T(Lon_tmp);
  argInit_151x1_real_T(Lat_tmp);*/
  /* Initialize function input argument 'Lat'. */
  /* Initialize function input argument 'g'. */
  /* Initialize function input argument 'true_trace'. */
  /* Initialize function input argument 'ins_trace'. */
  /* Initialize function input argument 'true_g'. */
  /* Initialize function input argument 'map_g'. */
  /* Call the entry-point 'TERCOMwry'. */
 /* argInit_151x151_real_T(g);
  argInit_60x21_real_T(dv1);
  argInit_60x8_real_T(dv2);
  argInit_60x1_real_T(dv3);
  argInit_60x1_real_T(dv4); */
     // // //******************************
  //printf("** file **\n");
  //FILE *file; 
  //int row = 0;

  //char buf[100] = {0};

  //double *longitude;
  //double *latitude;
  //double* grav;

  //int num = 601;
  //int n = 664;
  //double Lon1[601];
  //double Lat1[664];
  //double G[601];
  //static double g1[664][601];
  //static double Gravity[399064];
  //int i = 0;

  //file = fopen("D://we120~130sn20~30.txt", "r");
  //if (file == NULL) {
  //    printf("open file failed.\n");
  //    return 0;
  //}
  //while (!feof(file))
  //{
  //    if (fgetc(file) == '\n')//399065
  //    {
  //        row++;
  //        //printf("reading row now!");
  //    }
  //}
  //printf("%d \r\n ", row);
  //longitude = (double*)malloc(row * sizeof(double));
  //latitude = (double*)malloc(row * sizeof(double));
  //grav = (double*)malloc(row * sizeof(double));
  //double(*data)[3] = (double(*)[3])malloc(row * sizeof(double[3]));

  //fseek(file,0,SEEK_SET);

  //while (!feof(file))
  //{
  //    fscanf(file, "%lf %lf %lf\n", &longitude[i],&latitude[i],&grav[i]); 
  //    data[i][0] = longitude[i];
  //    data[i][1] = latitude[i];
  //    data[i][2] = grav[i];
  //    //printf("%lf %lf %lf\r\n ", longitude[i], latitude[i], grav[i]);
  //    //printf("%lf %lf %lf\r\n ", longitude[1], latitude[1], grav[1]);
  //    i++;
  //}
  //fclose(file);

  //printf("%lf %lf %lf\r\n ", longitude[0], latitude[0], grav[0]);
  // printf("final i is %d \r\n ", i);
  //printf("%lf %lf %lf\r\n", data[0][0], data[0][1], data[0][2]);
  //  free(longitude);
  //  free(latitude);
  //  free(grav); 
  //  free(data); 
  //  free(file);
// // // *********************************
//  printf("** file 1 **\n");
//  FILE* file1;
//  int row1 = 0;
//  //int row1 = 864000;
//  double *ga0,*ga1, * ga2, * ga3, * ga4, * ga5, * ga6, * ga7, * ga8, * ga9, * ga10, * ga11, * ga12, * ga13, * ga14, * ga15, * ga16, * ga17, * ga18, * ga19, * ga20;
//  //double* ga0;
//  //double* ga1;
//  //double* ga2;
//  //double* ga3;
//  //double* ga4;
//  //double* ga5;
//  //double* ga6;
//  //double* ga7;
//  //double* ga8;
//  //double* ga9;
//  //double* ga10;
//  //double* ga11;
//  //double* ga12;
//  //double* ga13;
//  //double* ga14;
//  //double* ga15;
//  //double* ga16;
//  //double* ga17; 
//  //double* ga18;
//  //double* ga19;
//  //double *ga20;
//
//  //double true_trace[60][21];
//  // double start = 47416;
 file1 = fopen("D://sins_mat2.txt", "r");
// file1 = fopen("D://ga_mat2.txt", "r");
//if (file1 == NULL) {
//    printf("open file1 failed.\n");
//    return 0;
//}
//fseek(file1, 0, SEEK_SET);
//while (!feof(file1))
//{
//    if (fgetc(file1) == '\n')//864000
//    {
//        row1++;
//        //printf("reading row1 now!");
//    }
//}
//printf("%d \r\n ", row1);
ga = (double*)malloc(row1 * sizeof(double));
//ga0 = (double*)malloc(row1 * sizeof(double));
//ga1 = (double*)malloc(row1 * sizeof(double));
//ga2 = (double*)malloc(row1 * sizeof(double));
//ga3 = (double*)malloc(row1 * sizeof(double));
//ga4 = (double*)malloc(row1 * sizeof(double));
//ga5 = (double*)malloc(row1 * sizeof(double));
//ga6 = (double*)malloc(row1 * sizeof(double));
//ga7 = (double*)malloc(row1 * sizeof(double));
//ga8 = (double*)malloc(row1 * sizeof(double));
//ga9 = (double*)malloc(row1 * sizeof(double));
//ga10 = (double*)malloc(row1 * sizeof(double));
//ga11 = (double*)malloc(row1 * sizeof(double));
//ga12 = (double*)malloc(row1 * sizeof(double));
//ga13 = (double*)malloc(row1 * sizeof(double));
//ga14 = (double*)malloc(row1 * sizeof(double));
//ga15 = (double*)malloc(row1 * sizeof(double));
//ga16 = (double*)malloc(row1 * sizeof(double));
//ga17 = (double*)malloc(row1 * sizeof(double));
//ga18 = (double*)malloc(row1 * sizeof(double));
//ga19 = (double*)malloc(row1 * sizeof(double));
//ga20 = (double*)malloc(row1 * sizeof(double));
//double(*ga)[21] = (double(*)[31])malloc(row1 * sizeof(double[21]));
//fseek(file1, 0, SEEK_SET);
//int ii = 0;
while (!feof(file1))
//for (ii = 0; ii < 864000; ii++)
//{
//    fscanf(file1, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &ga0[ii], &ga1[ii], &ga2[ii], &ga3[ii], &ga4[ii], &ga5[ii], &ga6[ii], &ga7[ii], &ga8[ii], &ga9[ii], &ga10[ii], &ga11[ii], &ga12[ii], &ga13[ii], &ga14[ii], &ga15[ii], &ga16[ii], &ga17[ii], &ga18[ii], &ga19[ii], &ga20[ii]);
//    ga[ii][0] = ga0[ii];
//    ga[ii][1] = ga1[ii];
//    ga[ii][2] = ga2[ii];
//    ga[ii][3] = ga3[ii];
//    ga[ii][4] = ga4[ii];
//    ga[ii][5] = ga5[ii];
//    ga[ii][6] = ga6[ii];
//    ga[ii][7] = ga7[ii];
//    ga[ii][8] = ga8[ii];
//    ga[ii][9] = ga9[ii];
//    ga[ii][10] = ga10[ii];
//    ga[ii][11] = ga11[ii];
//    ga[ii][12] = ga12[ii];
//    ga[ii][13] = ga13[ii];
//    ga[ii][14] = ga14[ii];
//    ga[ii][15] = ga15[ii];
//    ga[ii][16] = ga16[ii];
//    ga[ii][17] = ga17[ii];
//    ga[ii][18] = ga18[ii];
//    ga[ii][19] = ga19[ii];
//    ga[ii][20] = ga20[ii];
//    //ii++;    
//}
//fclose(file1);
//printf("final ii is %d\n ",ii);
//double true_trace[60][21];
//int start = 47416;
//double N = 60;
//double T = 3 * 60;
//double total_time = N * T;
//
//int i_2 = 0;
//int j_2 = 0;
//for (i_2 = 0; i_2 < 60; i_2++) {
//    for (j_2 = 0; j_2 < 21; j_2++) {
//        true_trace[i_2][j_2] = ga[47416 +180*i_2][j_2];
//       // j_2++;
//    }
//}
//printf("%lf\n", true_trace[0][1]);
//int i_3 = 0;
//double true_g[60];
//for (i_3 = 0; i_3 < 60; i_3++) {
//    true_g[i_3] = true_trace[i_3][18];
//}
//printf("true_g is %lf %lf \n", true_g[0],true_g[59]);
//
//free(ga0); free(ga1); free(ga2); free(ga3); free(ga4); free(ga5); free(ga6); free(ga7);
//free(ga8); free(ga9); free(ga10); free(ga11); free(ga12);free(ga13); free(ga14);
//free(ga15); free(ga16); free(ga17); free(ga18); free(ga19); free(ga20); free(ga);
//free(file1); 
  // *****************************
//printf("** file 2 **\n");
//FILE *file2;
//int row2 = 0;
double start = 47416;
//double* sins0, * sins1, * sins2, * sins3, * sins4, * sins5, * sins6, * sins7;
//int start_sins = 2e4;
//double ins_trace[60][8];
int i_6 = 0;
for (i_6 = 0; i_6 < 60; i_6++) {
    memset(ins_trace[i_6], 0, sizeof(double) * 8);
}
printf("first is %f\t and last is %f\n ", ins_trace[0][0], ins_trace[59][7]);
static double sins[36744][8]; // *****栈溢出  -1073741571。
//
//file2 = fopen("d://sins_mat2.txt", "r");
//if (file2 == NULL) {
//    printf("open file2 failed.\n");
//    return 0;
//}
//while (!feof(file2))
//{
//    if (fgetc(file2) == '\n')//367448
//    {
//        row2++;
//    }
//}
//printf("%d \r\n ", row2);
// // read data to array
//sins0 = (double*)malloc(row2 * sizeof(double));
//sins1 = (double*)malloc(row2 * sizeof(double));
//sins2 = (double*)malloc(row2 * sizeof(double));
//sins3 = (double*)malloc(row2 * sizeof(double));
//sins4 = (double*)malloc(row2 * sizeof(double));
//sins5 = (double*)malloc(row2 * sizeof(double));
//sins6 = (double*)malloc(row2 * sizeof(double));
//sins7 = (double*)malloc(row2 * sizeof(double));
//double(*sins)[8] = (double(*)[21])malloc(row2 * sizeof(double[8]));
//fseek(file2, 0, SEEK_SET);
//int i_5 = 0;
//while (!feof(file2))
//{
//    fscanf(file2, "%lf %lf %lf %lf %lf %lf %lf %lf", &sins0[i_5], &sins1[i_5], &sins2[i_5], &sins3[i_5], &sins4[i_5], &sins5[i_5], &sins6[i_5], &sins7[i_5]);
//    sins[i_5][0] = sins0[i_5];
//    sins[i_5][1] = sins1[i_5];
//    sins[i_5][2] = sins2[i_5];
//    sins[i_5][3] = sins3[i_5];
//    sins[i_5][4] = sins4[i_5];
//    sins[i_5][5] = sins5[i_5];
//    sins[i_5][6] = sins6[i_5];
//    sins[i_5][7] = sins7[i_5];
//    i_5++;
//}
//fclose(file2);
//printf("final i_5 is %d\n", i_5);
//
//int i_4 = 0;
//int j_4 = 0;
//for (i_4 = 0; i_4 < 60; i_4++) {
//    for (j_4 = 0; j_4 < 8; j_4++) {
//        ins_trace[i_4][j_4] = sins[start_sins+i_4*180][j_4];
//    }    
//}
//printf("they are %f and %f\r\n", ins_trace[0][0], ins_trace[59][7]);
//
free(file2);
free(sins0); free(sins1); free(sins2); free(sins3); free(sins4); free(sins5); free(sins5); free(sins6); free(sins7);
free(sins);

// // //*****************************
printf("** file 3 **\n");
FILE *file3;
int row3 = 1;
double* map_g1;
file3 = fopen("D://map_g.txt","r");
if (file3 == NULL) {
    printf("open file failed.\n");
    return 0;
}
while (!feof(file3))
{
    if (fgetc(file3) == '\n') {
        row3++;
    }
}
printf("%d\r\n", row3);
map_g1 = (double*)malloc(row3 * sizeof(double));
//double(*map_g)[1] = (double(*)[1])malloc(row3 * sizeof(double[1]));
fseek(file3, 0, SEEK_SET);
int i_7 = 0;
while (!feof(file3))
{
    fscanf(file3, "%lf", &map_g1[i_7]);
    //map_g[i_7][0] = map_g1[i_7];
    i_7++;
}
fclose(file3);

int i_8 = 0;
double map_g[60][1];
for (i_8 = 0; i_8 < 60; i_8++)
{
    map_g[i_8][0] = map_g1[i_8];
}
printf("final i_7 is %d\n map_g1 is %.16f\n map_g60 is %.16f\n", i_7,map_g[0][0],map_g[59][0]);

free(map_g1);
free(file3);

 /*TERCOMwry(Lon_tmp, double Lat_tmp, g, dv1, dv2, dv3, argInit_real_T(), dv4,
            true_trace1, ins_trace1, delta_g_new, matchline, &match_num,
            final_match, X_err, Y_err, P_err, delta_lat_ins, delta_lon_ins,
            delta_P_ins, &Distance);*/
}

/*
 * Arguments    : int argc
 *                const char * const argv[]
 * Return Type  : int
 */

int main(int argc, const char * const argv[])
{
  (void)argc;
  (void)argv;

  /* Initialize the application.
     You do not need to do this more than one time. */
  TERCOMwry_initialize();

  /* Invoke the entry-point functions.
     You can call entry-point functions multiple times. */

  main_TERCOMwry(); 


  /* Terminate the application.
     You do not need to do this more than one time. */
  TERCOMwry_terminate();
  return 0;
}

/*
 * File trailer for main.c
 *
 * [EOF]
 */

file

printf("** file **\n");
FILE *file; 
int row = 0;

char buf[100] = {0};

double *longitude;
double *latitude;
double* grav;

int num = 601;
int n = 664;
double Lon1[601];
double Lat1[664];
double G[601];
static double g1[664][601];
static double Gravity[399064];
int i = 0;

file = fopen("D://we120~130sn20~30.txt", "r");
if (file == NULL) {
    printf("open file failed.\n");
    return 0;
}
while (!feof(file))
{
    if (fgetc(file) == '\n')//399065
    {
        row++;
        //printf("reading row now!");
    }
}
printf("%d \r\n ", row);
longitude = (double*)malloc(row * sizeof(double));
latitude = (double*)malloc(row * sizeof(double));
grav = (double*)malloc(row * sizeof(double));
double(*data)[3] = (double(*)[3])malloc(row * sizeof(double[3]));

fseek(file,0,SEEK_SET);

while (!feof(file))
{
    fscanf(file, "%lf %lf %lf\n", &longitude[i],&latitude[i],&grav[i]); 
    data[i][0] = longitude[i];
    data[i][1] = latitude[i];
    data[i][2] = grav[i];
    //printf("%lf %lf %lf\r\n ", longitude[i], latitude[i], grav[i]);
    //printf("%lf %lf %lf\r\n ", longitude[1], latitude[1], grav[1]);
    i++;
}
fclose(file);

printf("%lf %lf %lf\r\n ", longitude[0], latitude[0], grav[0]);
 printf("final i is %d \r\n ", i);
printf("%lf %lf %lf\r\n", data[0][0], data[0][1], data[0][2]);
  free(longitude);
  free(latitude);
  free(grav); 
  free(data); 
  free(file);

file1

  printf("** file 1 **\n");
  FILE* file1;
  int row1 = 0;
  //int row1 = 864000;
  double *ga0,*ga1, * ga2, * ga3, * ga4, * ga5, * ga6, * ga7, * ga8, * ga9, * ga10, * ga11, * ga12, * ga13, * ga14, * ga15, * ga16, * ga17, * ga18, * ga19, * ga20;
  //double* ga0;
  //double* ga1;
  //double* ga2;
  //double* ga3;
  //double* ga4;
  //double* ga5;
  //double* ga6;
  //double* ga7;
  //double* ga8;
  //double* ga9;
  //double* ga10;
  //double* ga11;
  //double* ga12;
  //double* ga13;
  //double* ga14;
  //double* ga15;
  //double* ga16;
  //double* ga17; 
  //double* ga18;
  //double* ga19;
  //double *ga20;

  //double true_trace[60][21];
  // double start = 47416;
// file1 = fopen("D://sins_mat2.txt", "r");
 file1 = fopen("D://ga_mat2.txt", "r");
if (file1 == NULL) {
    printf("open file1 failed.\n");
    return 0;
}
fseek(file1, 0, SEEK_SET);
while (!feof(file1))
{
    if (fgetc(file1) == '\n')//864000
    {
        row1++;
        //printf("reading row1 now!");
    }
}
printf("%d \r\n ", row1);
//ga = (double*)malloc(row1 * sizeof(double));
ga0 = (double*)malloc(row1 * sizeof(double));
ga1 = (double*)malloc(row1 * sizeof(double));
ga2 = (double*)malloc(row1 * sizeof(double));
ga3 = (double*)malloc(row1 * sizeof(double));
ga4 = (double*)malloc(row1 * sizeof(double));
ga5 = (double*)malloc(row1 * sizeof(double));
ga6 = (double*)malloc(row1 * sizeof(double));
ga7 = (double*)malloc(row1 * sizeof(double));
ga8 = (double*)malloc(row1 * sizeof(double));
ga9 = (double*)malloc(row1 * sizeof(double));
ga10 = (double*)malloc(row1 * sizeof(double));
ga11 = (double*)malloc(row1 * sizeof(double));
ga12 = (double*)malloc(row1 * sizeof(double));
ga13 = (double*)malloc(row1 * sizeof(double));
ga14 = (double*)malloc(row1 * sizeof(double));
ga15 = (double*)malloc(row1 * sizeof(double));
ga16 = (double*)malloc(row1 * sizeof(double));
ga17 = (double*)malloc(row1 * sizeof(double));
ga18 = (double*)malloc(row1 * sizeof(double));
ga19 = (double*)malloc(row1 * sizeof(double));
ga20 = (double*)malloc(row1 * sizeof(double));
double(*ga)[21] = (double(*)[31])malloc(row1 * sizeof(double[21]));
fseek(file1, 0, SEEK_SET);
int ii = 0;
//while (!feof(file1))
for (ii = 0; ii < 864000; ii++)
{
    fscanf(file1, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &ga0[ii], &ga1[ii], &ga2[ii], &ga3[ii], &ga4[ii], &ga5[ii], &ga6[ii], &ga7[ii], &ga8[ii], &ga9[ii], &ga10[ii], &ga11[ii], &ga12[ii], &ga13[ii], &ga14[ii], &ga15[ii], &ga16[ii], &ga17[ii], &ga18[ii], &ga19[ii], &ga20[ii]);
    ga[ii][0] = ga0[ii];
    ga[ii][1] = ga1[ii];
    ga[ii][2] = ga2[ii];
    ga[ii][3] = ga3[ii];
    ga[ii][4] = ga4[ii];
    ga[ii][5] = ga5[ii];
    ga[ii][6] = ga6[ii];
    ga[ii][7] = ga7[ii];
    ga[ii][8] = ga8[ii];
    ga[ii][9] = ga9[ii];
    ga[ii][10] = ga10[ii];
    ga[ii][11] = ga11[ii];
    ga[ii][12] = ga12[ii];
    ga[ii][13] = ga13[ii];
    ga[ii][14] = ga14[ii];
    ga[ii][15] = ga15[ii];
    ga[ii][16] = ga16[ii];
    ga[ii][17] = ga17[ii];
    ga[ii][18] = ga18[ii];
    ga[ii][19] = ga19[ii];
    ga[ii][20] = ga20[ii];
    //ii++;    
}
fclose(file1);
printf("final ii is %d\n ",ii);
double true_trace[60][21];
int start = 47416;
double N = 60;
double T = 3 * 60;
double total_time = N * T;

int i_2 = 0;
int j_2 = 0;
for (i_2 = 0; i_2 < 60; i_2++) {
    for (j_2 = 0; j_2 < 21; j_2++) {
        true_trace[i_2][j_2] = ga[47416 +180*i_2][j_2];
       // j_2++;
    }
}
printf("%lf\n", true_trace[0][1]);
int i_3 = 0;
double true_g[60];
for (i_3 = 0; i_3 < 60; i_3++) {
    true_g[i_3] = true_trace[i_3][18];
}
printf("true_g is %lf %lf \n", true_g[0],true_g[59]);

free(ga0); free(ga1); free(ga2); free(ga3); free(ga4); free(ga5); free(ga6); free(ga7);
free(ga8); free(ga9); free(ga10); free(ga11); free(ga12);free(ga13); free(ga14);
free(ga15); free(ga16); free(ga17); free(ga18); free(ga19); free(ga20); free(ga);
free(file1); 
//  // ****************

file 2

printf("** file 2 **\n");
FILE *file2;
int row2 = 0;
//double start = 47416;
double* sins0, * sins1, * sins2, * sins3, * sins4, * sins5, * sins6, * sins7;
int start_sins = 2e4;
double ins_trace[60][8];
//int i_6 = 0;
//for (i_6 = 0; i_6 < 60; i_6++) {
//    memset(ins_trace[i_6], 0, sizeof(double) * 8);
//}
//printf("first is %f\t and last is %f\n ", ins_trace[0][0], ins_trace[59][7]);
//static double sins[36744][8]; // *****栈溢出  -1073741571。

file2 = fopen("d://sins_mat2.txt", "r");
if (file2 == NULL) {
    printf("open file2 failed.\n");
    return 0;
}
while (!feof(file2))
{
    if (fgetc(file2) == '\n')//367448
    {
        row2++;
    }
}
printf("%d \r\n ", row2);
 // read data to array
sins0 = (double*)malloc(row2 * sizeof(double));
sins1 = (double*)malloc(row2 * sizeof(double));
sins2 = (double*)malloc(row2 * sizeof(double));
sins3 = (double*)malloc(row2 * sizeof(double));
sins4 = (double*)malloc(row2 * sizeof(double));
sins5 = (double*)malloc(row2 * sizeof(double));
sins6 = (double*)malloc(row2 * sizeof(double));
sins7 = (double*)malloc(row2 * sizeof(double));
double(*sins)[8] = (double(*)[21])malloc(row2 * sizeof(double[8]));
fseek(file2, 0, SEEK_SET);
int i_5 = 0;
while (!feof(file2))
{
    fscanf(file2, "%lf %lf %lf %lf %lf %lf %lf %lf", &sins0[i_5], &sins1[i_5], &sins2[i_5], &sins3[i_5], &sins4[i_5], &sins5[i_5], &sins6[i_5], &sins7[i_5]);
    sins[i_5][0] = sins0[i_5];
    sins[i_5][1] = sins1[i_5];
    sins[i_5][2] = sins2[i_5];
    sins[i_5][3] = sins3[i_5];
    sins[i_5][4] = sins4[i_5];
    sins[i_5][5] = sins5[i_5];
    sins[i_5][6] = sins6[i_5];
    sins[i_5][7] = sins7[i_5];
    i_5++;
}
fclose(file2);
printf("final i_5 is %d\n", i_5);

int i_4 = 0;
int j_4 = 0;
for (i_4 = 0; i_4 < 60; i_4++) {
    for (j_4 = 0; j_4 < 8; j_4++) {
        ins_trace[i_4][j_4] = sins[start_sins+i_4*180][j_4];
    }    
}
printf("they are %f and %f\r\n", ins_trace[0][0], ins_trace[59][7]);

//free(file2);
//free(sins0); free(sins1); free(sins2); free(sins3); free(sins4); free(sins5); free(sins5); free(sins6); free(sins7);
//free(sins);

file 3

printf("** file 3 **\n");
FILE *file3;
int row3 = 1;
double* map_g1;
file3 = fopen("D://map_g.txt","r");
if (file3 == NULL) {
    printf("open file failed.\n");
    return 0;
}
while (!feof(file3))
{
    if (fgetc(file3) == '\n') {
        row3++;
    }
}
printf("%d\r\n", row3);
map_g1 = (double*)malloc(row3 * sizeof(double));
//double(*map_g)[1] = (double(*)[1])malloc(row3 * sizeof(double[1]));
fseek(file3, 0, SEEK_SET);
int i_7 = 0;
while (!feof(file3))
{
    fscanf(file3, "%lf", &map_g1[i_7]);
    //map_g[i_7][0] = map_g1[i_7];
    i_7++;
}
fclose(file3);

int i_8 = 0;
double map_g[60][1];
for (i_8 = 0; i_8 < 60; i_8++)
{
    map_g[i_8][0] = map_g1[i_8];
}
printf("final i_7 is %d\n map_g1 is %.16f\n map_g60 is %.16f\n", i_7,map_g[0][0],map_g[59][0]);

free(map_g1);
free(file3);

修正后的总

提示:需要指针先赋值NULL

/*
 * File: main.c
 *
 * MATLAB Coder version            : 4.1
 * C/C++ source code generated on  : 18-Apr-2024 10:01:12
 */

/*************************************************************************/
/* This automatically generated example C main file shows how to call    */
/* entry-point functions that MATLAB Coder generated. You must customize */
/* this file for your application. Do not modify this file directly.     */
/* Instead, make a copy of this file, modify it, and integrate it into   */
/* your development environment.                                         */
/*                                                                       */
/* This file initializes entry-point function arguments to a default     */
/* size and value before calling the entry-point functions. It does      */
/* not store or use any values returned from the entry-point functions.  */
/* If necessary, it does pre-allocate memory for returned values.        */
/* You can use this file as a starting point for a main function that    */
/* you can deploy in your application.                                   */
/*                                                                       */
/* After you copy the file, and before you deploy it, you must make the  */
/* following changes:                                                    */
/* * For variable-size function arguments, change the example sizes to   */
/* the sizes that your application requires.                             */
/* * Change the example values of function arguments to the values that  */
/* your application requires.                                            */
/* * If the entry-point functions return values, store these values or   */
/* otherwise use them as required by your application.                   */
/*                                                                       */
/*************************************************************************/
/* Include Files */
#define _CRT_SECURE_NO_WARNINGS
#include "rt_nonfinite.h"
#include "TERCOMwry.h"
#include "main.h"
#include "TERCOMwry_terminate.h"
#include "TERCOMwry_initialize.h"
#include "stdio.h"
//#include "algorithm"
#include "stdlib.h"
//using namespace std;
/* Function Declarations */
//static void argInit_151x151_real_T(double result[22801]);
//static void argInit_151x1_real_T(double result[151]);
//static void argInit_60x1_real_T(double result[60]);
//static void argInit_60x21_real_T(double result[1260]);
//static void argInit_60x8_real_T(double result[480]);
static double argInit_real_T(void);
static void main_TERCOMwry(void);

/* Function Definitions */

/*
 * Arguments    : double result[22801]
 * Return Type  : void
 */
static void argInit_151x151_real_T(double result[22801])
{
  int idx0;
  int idx1;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 151; idx0++) {
    for (idx1 = 0; idx1 < 151; idx1++) {
      /* Set the value of the array element.
         Change this value to the value that the application requires. */
      result[idx0 + 151 * idx1] = argInit_real_T();
    }
  }
}

/*
 * Arguments    : double result[151]
 * Return Type  : void
 */
static void argInit_151x1_real_T(double result[151])
{
  int idx0;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 151; idx0++) {
    /* Set the value of the array element.
       Change this value to the value that the application requires. */
    result[idx0] = argInit_real_T();
  }
}

/*
 * Arguments    : double result[60]
 * Return Type  : void
 */
static void argInit_60x1_real_T(double result[60])
{
  int idx0;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 60; idx0++) {
    /* Set the value of the array element.
       Change this value to the value that the application requires. */
    result[idx0] = argInit_real_T();
  }
}

/*
 * Arguments    : double result[1260]
 * Return Type  : void
 */
static void argInit_60x21_real_T(double result[1260])
{
  int idx0;
  int idx1;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 60; idx0++) {
    for (idx1 = 0; idx1 < 21; idx1++) {
      /* Set the value of the array element.
         Change this value to the value that the application requires. */
      result[idx0 + 60 * idx1] = argInit_real_T();
    }
  }
}

/*
 * Arguments    : double result[480]
 * Return Type  : void
 */
static void argInit_60x8_real_T(double result[480])
{
  int idx0;
  int idx1;

  /* Loop over the array to initialize each element. */
  for (idx0 = 0; idx0 < 60; idx0++) {
    for (idx1 = 0; idx1 < 8; idx1++) {
      /* Set the value of the array element.
         Change this value to the value that the application requires. */
      result[idx0 + 60 * idx1] = argInit_real_T();
    }
  }
}

/*
 * Arguments    : void
 * Return Type  : double
 */
static double argInit_real_T(void)
{
  return 0.0;
}

/*
 * Arguments    : void
 * Return Type  : void
 */
static void main_TERCOMwry(void)
{
 /*double Lon_tmp[151];
  double Lat_tmp[151];
  static double g[22801];
  double dv1[1260];
  double dv2[480];
  double dv3[60];
  double dv4[60];
  double true_trace1[120];
  double ins_trace1[120];
  double delta_g_new[60];
  static double matchline[29160];
  double match_num;
  double final_match[120];
  double X_err[60];
  double Y_err[60];
  double P_err[60];
  double delta_lat_ins[60];
  double delta_lon_ins[60];
  double delta_P_ins[60];
  double Distance;
  */
  /* Initialize function 'TERCOMwry' input arguments. */
  /* Initialize function input argument 'Lon'. */
 /* argInit_151x1_real_T(Lon_tmp);
  argInit_151x1_real_T(Lat_tmp);*/
  /* Initialize function input argument 'Lat'. */
  /* Initialize function input argument 'g'. */
  /* Initialize function input argument 'true_trace'. */
  /* Initialize function input argument 'ins_trace'. */
  /* Initialize function input argument 'true_g'. */
  /* Initialize function input argument 'map_g'. */
  /* Call the entry-point 'TERCOMwry'. */
 /* argInit_151x151_real_T(g);
  argInit_60x21_real_T(dv1);
  argInit_60x8_real_T(dv2);
  argInit_60x1_real_T(dv3);
  argInit_60x1_real_T(dv4); */
  //   // // //******************************
  printf("** file **\n");
  FILE *file; 
  int row = 0;

  char buf[100] = {0};

  double *longitude;
  double *latitude;
  double* grav;

  int num = 601;
  int n = 664;
  double Lon1[601];
  double Lat1[664];
  double G[601];
  static double g1[664][601];
  static double Gravity[399064];
  int i = 0;

  file = fopen("D://we120~130sn20~30.txt", "r");
  if (file == NULL) {
      printf("open file failed.\n");
      return 0;
  }
  while (!feof(file))
  {
      if (fgetc(file) == '\n')//399065
      {
          row++;
          //printf("reading row now!");
      }
  }
  printf("%d \r\n ", row);
  longitude = (double*)malloc(row * sizeof(double));
  latitude = (double*)malloc(row * sizeof(double));
  grav = (double*)malloc(row * sizeof(double));
  double(*data)[3] = (double(*)[3])malloc(row * sizeof(double[3]));

  fseek(file,0,SEEK_SET);

  while (!feof(file))
  {
      fscanf(file, "%lf %lf %lf\n", &longitude[i],&latitude[i],&grav[i]); 
      data[i][0] = longitude[i];
      data[i][1] = latitude[i];
      data[i][2] = grav[i];
      //printf("%lf %lf %lf\r\n ", longitude[i], latitude[i], grav[i]);
      //printf("%lf %lf %lf\r\n ", longitude[1], latitude[1], grav[1]);
      i++;
  }
  fclose(file);

  printf("%lf %lf %lf\r\n ", longitude[0], latitude[0], grav[0]);
   printf("final i is %d \r\n ", i);
  printf("%lf %lf %lf\r\n", data[0][0], data[0][1], data[0][2]);

  data = NULL;grav = NULL;latitude = NULL;longitude = NULL;file = NULL;
  free(data);  free(grav);  free(latitude);  free(longitude);  free(file);
// // // *********************************
  printf("** file 1 **\n");
  FILE* file1;
  int row1 = 0;
  //int row1 = 864000;
  double *ga0,*ga1, * ga2, * ga3, * ga4, * ga5, * ga6, * ga7, * ga8, * ga9, * ga10, * ga11, * ga12, * ga13, * ga14, * ga15, * ga16, * ga17, * ga18, * ga19, * ga20;
  //double* ga0;
  //double* ga1;
  //double* ga2;
  //double* ga3;
  //double* ga4;
  //double* ga5;
  //double* ga6;
  //double* ga7;
  //double* ga8;
  //double* ga9;
  //double* ga10;
  //double* ga11;
  //double* ga12;
  //double* ga13;
  //double* ga14;
  //double* ga15;
  //double* ga16;
  //double* ga17; 
  //double* ga18;
  //double* ga19;
  //double *ga20;

  //double true_trace[60][21];
  // double start = 47416;
 file1 = fopen("D://sins_mat2.txt", "r");
 file1 = fopen("D://ga_mat2.txt", "r");
if (file1 == NULL) {
    printf("open file1 failed.\n");
    return 0;
}
fseek(file1, 0, SEEK_SET);
while (!feof(file1))
{
    if (fgetc(file1) == '\n')//864000
    {
        row1++;
        //printf("reading row1 now!");
    }
}
printf("%d \r\n ", row1);
//ga = (double*)malloc(row1 * sizeof(double));
ga0 = (double*)malloc(row1 * sizeof(double));
ga1 = (double*)malloc(row1 * sizeof(double));
ga2 = (double*)malloc(row1 * sizeof(double));
ga3 = (double*)malloc(row1 * sizeof(double));
ga4 = (double*)malloc(row1 * sizeof(double));
ga5 = (double*)malloc(row1 * sizeof(double));
ga6 = (double*)malloc(row1 * sizeof(double));
ga7 = (double*)malloc(row1 * sizeof(double));
ga8 = (double*)malloc(row1 * sizeof(double));
ga9 = (double*)malloc(row1 * sizeof(double));
ga10 = (double*)malloc(row1 * sizeof(double));
ga11 = (double*)malloc(row1 * sizeof(double));
ga12 = (double*)malloc(row1 * sizeof(double));
ga13 = (double*)malloc(row1 * sizeof(double));
ga14 = (double*)malloc(row1 * sizeof(double));
ga15 = (double*)malloc(row1 * sizeof(double));
ga16 = (double*)malloc(row1 * sizeof(double));
ga17 = (double*)malloc(row1 * sizeof(double));
ga18 = (double*)malloc(row1 * sizeof(double));
ga19 = (double*)malloc(row1 * sizeof(double));
ga20 = (double*)malloc(row1 * sizeof(double));
double(*ga)[21] = (double(*)[31])malloc(row1 * sizeof(double[21]));
fseek(file1, 0, SEEK_SET);
int ii = 0;
//while (!feof(file1))
for (ii = 0; ii < 864000; ii++)
{
    fscanf(file1, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &ga0[ii], &ga1[ii], &ga2[ii], &ga3[ii], &ga4[ii], &ga5[ii], &ga6[ii], &ga7[ii], &ga8[ii], &ga9[ii], &ga10[ii], &ga11[ii], &ga12[ii], &ga13[ii], &ga14[ii], &ga15[ii], &ga16[ii], &ga17[ii], &ga18[ii], &ga19[ii], &ga20[ii]);
    ga[ii][0] = ga0[ii];
    ga[ii][1] = ga1[ii];
    ga[ii][2] = ga2[ii];
    ga[ii][3] = ga3[ii];
    ga[ii][4] = ga4[ii];
    ga[ii][5] = ga5[ii];
    ga[ii][6] = ga6[ii];
    ga[ii][7] = ga7[ii];
    ga[ii][8] = ga8[ii];
    ga[ii][9] = ga9[ii];
    ga[ii][10] = ga10[ii];
    ga[ii][11] = ga11[ii];
    ga[ii][12] = ga12[ii];
    ga[ii][13] = ga13[ii];
    ga[ii][14] = ga14[ii];
    ga[ii][15] = ga15[ii];
    ga[ii][16] = ga16[ii];
    ga[ii][17] = ga17[ii];
    ga[ii][18] = ga18[ii];
    ga[ii][19] = ga19[ii];
    ga[ii][20] = ga20[ii];
    //ii++;    
}
fclose(file1);
printf("final ii is %d\n ",ii);
double true_trace[60][21];
int start = 47416;
double N = 60;
double T = 3 * 60;
double total_time = N * T;

int i_2 = 0;
int j_2 = 0;
for (i_2 = 0; i_2 < 60; i_2++) {
    for (j_2 = 0; j_2 < 21; j_2++) {
        true_trace[i_2][j_2] = ga[47416 +180*i_2][j_2];
       // j_2++;
    }
}
printf("%lf\n", true_trace[0][1]);
int i_3 = 0;
double true_g[60];
for (i_3 = 0; i_3 < 60; i_3++) {
    true_g[i_3] = true_trace[i_3][18];
}
printf("true_g is %lf %lf \n", true_g[0],true_g[59]);

ga = NULL;ga1 = NULL;ga2 = NULL;ga3 = NULL;ga4 = NULL;ga5 = NULL;ga6 = NULL;ga7 = NULL;ga8 = NULL;ga9 = NULL;
ga10 = NULL;ga11 = NULL;ga12 = NULL;ga13 = NULL;ga14 = NULL;ga15 = NULL;ga16 = NULL;ga17 = NULL;ga18 = NULL;ga19 = NULL;
ga20 = NULL;file1 = NULL;
free(ga0); free(ga1); free(ga2); free(ga3); free(ga4); free(ga5); free(ga6); free(ga7);
free(ga8); free(ga9); free(ga10); free(ga11); free(ga12);free(ga13); free(ga14);
free(ga15); free(ga16); free(ga17); free(ga18); free(ga19); free(ga20); free(ga);
free(file1); 
  // *****************************
printf("** file 2 **\n");
FILE *file2;
int row2 = 0;
//double start = 47416;
double* sins0, * sins1, * sins2, * sins3, * sins4, * sins5, * sins6, * sins7;
int start_sins = 2e4;
double ins_trace[60][8];// = { 0 };
//double sins[36744][8] = { 0 };
//int i_6 = 0;
//for (i_6 = 0; i_6 < 60; i_6++) 
//    memset(ins_trace[i_6], 0, sizeof(double) * 8);
//}
//printf("first is %f\t and last is %f\n ", ins_trace[0][0], ins_trace[59][7]);
//static double sins[36744][8]; // *****栈溢出  -1073741571。

file2 = fopen("d://sins_mat2.txt", "r");
if (file2 == NULL) {
    printf("open file2 failed.\n");
    return 0;
}
//else
//{
//    for (int i = 0; i < 36744; i++)
//    {
//        for (int j = 0; j < 8; j++)
//        {
//            sins[i][j] = 1;
//        }
//    }
//}
while (!feof(file2))
{
    if (fgetc(file2) == '\n')//367448
    {
        row2++;
    }
}
printf("%d \r\n ", row2);
 // read data to array
sins0 = (double*)malloc(row2 * sizeof(double));
sins1 = (double*)malloc(row2 * sizeof(double));
sins2 = (double*)malloc(row2 * sizeof(double));
sins3 = (double*)malloc(row2 * sizeof(double));
sins4 = (double*)malloc(row2 * sizeof(double));
sins5 = (double*)malloc(row2 * sizeof(double));
sins6 = (double*)malloc(row2 * sizeof(double));
sins7 = (double*)malloc(row2 * sizeof(double));
double(*sins)[8] = (double(*)[21])malloc(row2 * sizeof(double[8]));
fseek(file2, 0, SEEK_SET);
int i_5 = 0;
while (!feof(file2))
{
    fscanf(file2, "%lf %lf %lf %lf %lf %lf %lf %lf", &sins0[i_5], &sins1[i_5], &sins2[i_5], &sins3[i_5], &sins4[i_5], &sins5[i_5], &sins6[i_5], &sins7[i_5]);
    sins[i_5][0] = sins0[i_5];
    sins[i_5][1] = sins1[i_5];
    sins[i_5][2] = sins2[i_5];
    sins[i_5][3] = sins3[i_5];
    sins[i_5][4] = sins4[i_5];
    sins[i_5][5] = sins5[i_5];
    sins[i_5][6] = sins6[i_5];
    sins[i_5][7] = sins7[i_5];
    i_5++;
}
fclose(file2);
printf("final i_5 is %d\n", i_5);

int i_4 = 0;
int j_4 = 0;
for (i_4 = 0; i_4 < 60; i_4++) {
    for (j_4 = 0; j_4 < 8; j_4++) {
        ins_trace[i_4][j_4] = sins[start_sins+i_4*180][j_4];
    }    
}
printf("they are %f and %f\r\n", ins_trace[0][0], ins_trace[59][7]);
file2 = NULL;sins0 = NULL;sins1 = NULL;sins2 = NULL;sins3 = NULL;sins4 = NULL;sins5 = NULL;sins6 = NULL;sins7 = NULL;sins = NULL;
free(file2);
free(sins0); free(sins1); free(sins2); free(sins3); free(sins4); free(sins5); free(sins5); free(sins6); free(sins7);
free(sins);

 // //*****************************
printf("** file 3 **\n");
FILE *file3;
int row3 = 1;
double* map_g1;
file3 = fopen("D://map_g.txt","r");
if (file3 == NULL) {
    printf("open file failed.\n");
    return 0;
}
while (!feof(file3))
{
    if (fgetc(file3) == '\n') {
        row3++;
    }
}
printf("%d\r\n", row3);
map_g1 = (double*)malloc(row3 * sizeof(double));
//double(*map_g)[1] = (double(*)[1])malloc(row3 * sizeof(double[1]));
fseek(file3, 0, SEEK_SET);
int i_7 = 0;
while (!feof(file3))
{
    fscanf(file3, "%lf", &map_g1[i_7]);
    //map_g[i_7][0] = map_g1[i_7];
    i_7++;
}
fclose(file3);

int i_8 = 0;
double map_g[60][1];
for (i_8 = 0; i_8 < 60; i_8++)
{
    map_g[i_8][0] = map_g1[i_8];
}
printf("final i_7 is %d\n map_g1 is %.16f\n map_g60 is %.16f\n", i_7,map_g[0][0],map_g[59][0]);

map_g1 = NULL;file3 = NULL;
free(map_g1);free(file3);

 /*TERCOMwry(Lon_tmp, double Lat_tmp, g, dv1, dv2, dv3, argInit_real_T(), dv4,
            true_trace1, ins_trace1, delta_g_new, matchline, &match_num,
            final_match, X_err, Y_err, P_err, delta_lat_ins, delta_lon_ins,
            delta_P_ins, &Distance);*/
}

/*
 * Arguments    : int argc
 *                const char * const argv[]
 * Return Type  : int
 */

int main(int argc, const char * const argv[])
{
  (void)argc;
  (void)argv;

  /* Initialize the application.
     You do not need to do this more than one time. */
  TERCOMwry_initialize();

  /* Invoke the entry-point functions.
     You can call entry-point functions multiple times. */

  main_TERCOMwry(); 


  /* Terminate the application.
     You do not need to do this more than one time. */
  TERCOMwry_terminate();
  return 0;
}

/*
 * File trailer for main.c
 *
 * [EOF]
 */

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值