back up 2

/*
 * 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); */
  FILE *file;
  //FILE *file1;
  int row = 0;
 // int row1 = 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++;
      }
  }


  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("%d \r\n ", row);
  printf("%lf %lf %lf\r\n", data[0][0], data[0][1], data[0][2]);

//  double* ga;
//  double* true_trace;
// file1 = fopen("D://ga_mat1.txt", "r");
//if (file1 == NULL) {
//    printf("open file1 failed.\n");
//    return 0;
//}
//while (!feof(file1))
//{
//    if (fgetc(file1) == '\n')//864000
//    {
//        row1++;
//    }
//}
//printf("%d \r\n ", row1);
//fclose(file1);
  // 获取 Lon1 数组  
  for (i = 0; i < num; i++) {
      Lon1[i] = longitude[i];
  }
  printf("%lf %lf\r\n ", Lon1[1], Lon1[600]); 
  //Lat1 = data(1:num:end, 2);
  for (i = 0; i < n; i++) {
      Lat1[i] = latitude[i * num];
  }
  printf("%lf %lf\r\n ", Lat1[1], Lat1[663]);
  for (i = 0; i < row-1; i++) {
      Gravity[i] = grav[i];
  }
  printf("%lf %lf\r\n ", Gravity[0], Gravity[row-2]);//first last grav value
  
  int m = 664;  int j = 0;  int k = 0;
  for (int i = 0; i < m; i++)
  {
      j = m - i ;

      for (k = 0; k < num; k++)
      {
          G[k] = Gravity[(m - j) * num + k];
          g1[j-1][k] = G[k];
      }
  }
  //for (i = 0; i < 601; i++) {
  //    //printf("%lf\n ",g1[0][i]);//g1 first line
  //    printf("%lf\n ", g1[i][0]);//g1 first coloum //check g1
  //}
  double g[151][151];
  for (i = 0; i < 151; i++) {
      for (j = 0; j < 151; j++) {
          g[i][j]=g1[464 + i][199 + j];
      }      
  }
  //for (i = 0; i < 151; i++) {
  //    //printf("%lf\n ", g[i][0]);//check row
  //    printf("%lf\n ", g[150][i]);//check column
  //}
  double Lon[151];
  double Lat[151];
  for (i = 0; i < 151; i++) {
      Lon[i] = Lon1[199 + i];
      Lat[i] = Lat1[49 + i];
  }
  //printf("%lf %lf\n %lf %lf\n", Lon[0], Lon[150], Lat[0],Lat[150]);//check Lon and Lat 
  double N = 60;
  double T = 3 * 60;
  double total_time = N * T;
  //printf("%lf %lf %lf\n",N,T,total_time);

  free(longitude);
  free(latitude);
  free(grav);
  

/* TERCOMwry(Lon_tmp, 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]
 */

part 2 读第二数据

252-356行

//  // // //*****************************
  FILE* file1;
  int row1 = 0;
  //double* ga;
  double *ga0,*ga1, * ga2, * ga3, * ga4, * ga5, * ga6, * ga7, * ga8, * ga9, * ga10, * ga11, * ga12, * ga13, * ga14, * ga15, * ga16, * ga17, * ga18, * ga19, * ga20;
  //double* true_trace[60][21];
  //double start = 47416;
 file1 = fopen("D://ga_mat1.txt", "r");
if (file1 == NULL) {
    printf("open file1 failed.\n");
    return 0;
}
while (!feof(file1))
{
    if (fgetc(file1) == '\n')//864000
    {
        row1++;
    }
}
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))
{
    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);

//int i_1 = 0;
//for (i_1 = 0; i_1 < 21; i_1++) {
//    printf("%lf\n ",ga[863999][i_1]);
//}
double true_trace[60][21];
int start = 47416;
double N = 60;
double T = 3 * 60;
double total_time = N * T;
//double
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[start+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("%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);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值