FORUM Tom's Hardware » Programmation » C / C++ / Java » aide modification d'un fichier en c
 

aide modification d'un fichier en c

Matériel : error-404 Le monde de Windows : TONY571 Shopping en ligne : tisote Mobilité : kris_tofe, 2 utilisateurs anonymes et 413 utilisateurs inconnus
Ajouter une réponse



 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet : aide modification d'un fichier en c
 
Plus d'informations

Bonjour,
Voila je dois modifier un code en c , mais ce dernier n'etant pas été réalisé par moi , je suis totalement perdue.

Voila c'est un peu compliqué comme modification.
Dans le fichier original (fichier toto.c), on demande de lire un autre fichier X c'est à dire lire le jour et la position , les composantes et calculer la moyenne par case suivant des incréments definis. A la fin mon fichier de sortie donne la moyenne et j'obtiens un nombre différent de lignes puisque je fais le calcul par case.

Maintenant, il faudrait que je retrouve dans mon fichier de sortie le jour et la position de mon fichier X , de reprendre les valeurs de moyenne que j'ai obtenu dans le 1er exemple et donc par conséquent retrouver le meme nombre de lignes que mon fichier X (data_in doit etre egale à filled_bin (cf fichier de mon fichier en c)) et de calculer les écarts entre les comosantes de mon fichier X et les données moyennes.

Or mon probleme c'est que je n'arrive pas à voir ou je dois faire toutes ces modifications et donc je fais appel à vous tous. C'est surtout dans l'ecriture des fichiers de sorties (je pense...mais c pas sur )

Mon fichier en .c qui permet de me calculer la moyenne

Voici la ligne de commande que j'utilise
toto.exe 2 (pour avoir la moyenne) fichier X (fichier d'entreé) toto(fichier de sortie) 350 450 -80 -10 0 130 0.25 0.25 100

Code :
  1. [*]/****************************************************************************/
  2. /****    binthedata.c                                                    ****/
  3. /****                                                                    ****/
  4. /****    Lecture des donnees mars et "binnage" au format mgsab          ****/
  5. /****    format (temps), lat, lon, alt, Br, Btheta, Bphi                ****/
  6. /****************************************************************************/
  7. /***********************/
  8. /****    includes    ***/
  9. /***********************/
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <math.h>
  13. #include <malloc.h>
  14. /**********************/
  15. /****    Define    ****/
  16. /**********************/
  17. #define M_PI  3.14159265358979323846
  18. #define PI_180 (M_PI / 180.0)
  19. #define RM 3393.5
  20. #define AMP (int)(alt_max-alt_min)
  21. /***********************/
  22. /****    Formats    ****/
  23. /***********************/
  24. #define READ_bin "%lf %lf %lf %lf %lf %lf %lf %d %lf %lf %lf\n"
  25. #define READs "%lf %lf %lf %lf %lf %lf\n"
  26. #define READl "%lf %lf %lf %lf %lf %lf %lf\n"
  27. #define READld "%lf %lf %lf %lf %lf %lf %lf %1s\n"
  28. #define LECTl1 &dday, &lon, &lat, &alt, &br, &bt, &bp
  29. #define LECTl2 &dday, &lat, &lon, &alt, &br, &bt, &bp
  30. #define LECTld &dday, &lat, &lon, &alt, &br, &bt, &bp, &dl
  31. #define READb "%lf %lf %lf %lf %lf %lf %d %lf %lf %lf\n"
  32. #define LECTb &lon, &lat, &alt, &br, &bt, &bp, &d, &dd, &dd, &dd
  33. #define WRITE_bin "%13.9lf %7.3lf %7.3lf %7.3lf %12.5lf %12.5lf %12.5lf %3d %10.3lf %10.3lf %10.3lf\n"
  34. #define WRITEs "%13.9lf %8.3lf %8.3lf %8.3lf %10.3lf %10.3lf %10.3lf\n"
  35. #define WRITEl "%13.9lf %8.3lf %8.3lf %8.3lf %10.3lf %10.3lf %10.3lf\n"
  36. #define ECRITl dday, lat, lon, alt, br, bt, bp
  37. #define WRITEld "%13.9lf %8.3lf %8.3lf %8.3lf %10.3lf %10.3lf %10.3lf %1s\n"
  38. #define ECRITld dday, lat, lon, alt, br, bt, bp, dl
  39. #define NMAX 50
  40. /****************************/
  41. /****    Main Program    ****/
  42. /****************************/
  43. int main(argc, argv)
  44. int argc;
  45. char *argv[];
  46.       {
  47.     FILE  *fin, *fout;
  48.     FILE  *fout_00, *fout_01, *fout_02, *fout_03, *fout_04;
  49.     FILE  *fout_05, *fout_06, *fout_07, *fout_08, *fout_09;
  50.     FILE  *fout_10, *fout_11, *fout_12, *fout_13, *fout_14;
  51.     FILE  *fout_15, *fout_16, *fout_17, *fout_18, *fout_19;
  52.     FILE  *fout_20, *fout_21, *fout_22, *fout_23, *fout_24;
  53.     FILE  *fout_25, *fout_26, *fout_27, *fout_28, *fout_29;
  54.     FILE  *fout_30, *fout_31, *fout_32, *fout_33, *fout_34;
  55.     FILE  *fout_35, *fout_36, *fout_37, *fout_38, *fout_39;
  56.     FILE  *fout_40, *fout_41, *fout_42, *fout_43, *fout_44;
  57.     FILE  *fout_45, *fout_46, *fout_47, *fout_48, *fout_49;
  58.     char  str[200];
  59.     double alt_max, alt_min;
  60.     double lat_max, lat_min;
  61.     double lon_max, lon_min;
  62.     int    choix;
  63.     int    data_in, data_out;
  64.     int    filled_bin=0;
  65.     int    filled_bin1=0;
  66.     int    filled_bin2=0;
  67.     double inc_lon, inc_lat, inc_alt;
  68.     double amp_lon, amp_lat, amp_alt;
  69.     int    npt_lon, npt_lat, npt_alt;
  70.     int    l, L, A;
  71.     double dday, lat, lon, alt, br, bt, bp;
  72.     int    index_alt;
  73.     int    npt_tot;
  74.     double **BR, **BT, **BP;
  75.     double **alt_var;
  76.     double *BR_max, *BT_max, *BP_max;
  77.     double *BR_min, *BT_min, *BP_min;
  78.     double *BR_moy, *BT_moy, *BP_moy;
  79.     double *BR_med, *BT_med, *BP_med;
  80.     double *BR_std, *BT_std, *BP_std;
  81.     double std_br, std_bt, std_bp;
  82.     double sum_br, sum_bt, sum_bp;
  83.     double dif_br, dif_bt, dif_bp;
  84.     int    i, j, k, index;
  85.     int    *NPT;
  86.     char dl[1];
  87.     double temp;
  88.     int d;
  89.     double dd;
  90.     dday = 0.0;
  91.     /* Introduction */
  92.    
  93.     printf("############################################################\n" );
  94.     printf("binthedata.exe\n\n" );
  95.     /* Test the number of parameters */
  96.     if (argc != 6 && argc != 10 && argc != 13)
  97.       {
  98.         printf("\tYou must call 6, 10 or 13 parameters!\n" );
  99.         printf("\tbinthedata.exe <choix> <fin> <fout> <alt_min> <alt_max>\n" );
  100.         printf("\tand eventually <lat_min> <lat_max> <lon_min> <<lon_max>\n" );
  101.         printf("\tand eventually <inc_lat> <inc_lon> <inc_alt>\n" );
  102.         printf("\t<choix> = 1 (median) or 2 (average) or 3 (minimum) or 4 (maximum)\n" );
  103.         printf("\t<choix> = 5 : one data per orbit per bin.\n" );
  104.         exit(-1);
  105.       }
  106.     choix = atoi(argv[1]);
  107.     if (choix != 1 && choix != 2 && choix != 3 && choix != 4 && choix != 5)
  108.       {
  109.         printf("\tBad <choix> value. Must be 1 <-> 5. Please check!\n" );
  110.         exit(-1);
  111.       }
  112.     fin = fopen(argv[2], "r" );
  113.     if (fin == NULL)
  114.       {
  115.         printf("Reading error on input file <%s>\n. Please check!\n", argv[2]);
  116.         exit(-1);
  117.       }
  118.     fout = fopen(argv[3], "w" );
  119.     if (fin == NULL)
  120.       {
  121.         printf("Writing error on output file <%s>\n. Please check!\n", argv[3]);
  122.         fclose(fin);
  123.         exit(-1);
  124.       }
  125.     /* Minimum and Maximum altitude */
  126.     alt_min = atof(argv[4]);
  127.     alt_max = atof(argv[5]);
  128.     if (argc == 10 || argc == 13)
  129.       {
  130.         lat_min = atof(argv[6]);
  131.         lat_max = atof(argv[7]);
  132.         lon_min = atof(argv[8]);
  133.         lon_max = atof(argv[9]);
  134.       }
  135.     else
  136.       {
  137.         lat_min = -90.;
  138.         lat_max = 90.;
  139.         lon_min = 0.;
  140.         lon_max = 360.;
  141.       }
  142.     if (argc == 13)
  143.       {
  144.         inc_lat = atof(argv[10]);
  145.         inc_lon = atof(argv[11]);
  146.         inc_alt = atof(argv[12]);
  147.       }
  148.     else
  149.       {
  150.         inc_lat = 1.;
  151.         inc_lon = 1.;
  152.         inc_alt = 10.;
  153.       }
  154.     /****    Verification    ****/
  155.     if (alt_min < 0.)
  156.       {
  157.         do
  158.           {
  159.         printf("\t<alt_min> lower than 0! Please enter a new value (0.)\n" );
  160.         fgets(str, 150, stdin);
  161.         if (str[0] == '\n')    alt_min = 0.;
  162.         else
  163.           {
  164.             sscanf(str, "%lf", &alt_min);
  165.           }
  166.           }
  167.         while (alt_max < 0.);
  168.       }
  169.     if (alt_max > 1000.)
  170.       {
  171.         do
  172.           {
  173.         printf("\t<alt_max> greater than 1000! Please enter a new value (1000.)\n" );
  174.         fgets(str, 150, stdin);
  175.         if (str[0] == '\n')    alt_max = 1000.;
  176.         else
  177.           {
  178.             sscanf(str, "%lf", &alt_max);
  179.           }
  180.           }
  181.         while (alt_max > 1000.);
  182.       }
  183.     if (alt_min > alt_max)
  184.       {
  185.         printf("\t<alt_min> greater than <alt_max>.\n" );
  186.         printf("\tPlease check. Exit!\n" );
  187.         fclose(fin);
  188.         exit(-1);
  189.       }
  190.     if (lat_min > lat_max)
  191.       {
  192.         printf("\tError in latitude range. Please check!\n" );
  193.         exit(-1);
  194.       }
  195.     /* parametres */
  196.     /* Initialisation */
  197.     amp_lat = lat_max - lat_min;
  198.     if (lon_max < lon_min)
  199.         amp_lon = 360. + lon_max - lon_min;
  200.     else
  201.         amp_lon = lon_max - lon_min;
  202.     amp_alt = alt_max - alt_min;
  203.     npt_lat = (int)(amp_lat / (double)inc_lat);
  204.     npt_lon = (int)(amp_lon / (double)inc_lon);
  205.     npt_alt = (int)(amp_alt / (double)inc_alt);
  206.     fprintf(stdout, "Nombre de points = %d (lat) x %d (lon) x %d (alt)\n",
  207.         npt_lat, npt_lon, npt_alt);
  208.     l = 0      ; L = 0      ; A = 0      ;
  209.     lat = lat_min + (double)l*inc_lat;
  210.     fprintf(stdout, "\tL'intervalle lat est %7.3lf/", lat);
  211.     l = npt_lat; L = 0      ; A = 0      ;
  212.     lat = lat_min + (double)l*inc_lat;
  213.     fprintf(stdout, "%7.3lf\n", lat);
  214.     l = 0      ; L = 0      ; A = 0      ;
  215.     lon = lon_min + (double)L*inc_lon;
  216.     fprintf(stdout, "\tL'intervalle lon est %7.3lf/", lon);
  217.     l = 0      ; L = npt_lon; A = 0      ;
  218.     lon = lon_min + (double)L*inc_lon;
  219.     fprintf(stdout, "%7.3lf\n", lon);
  220.     l = 0      ; L = 0      ; A = 0      ;
  221.     alt = alt_min + (double)A*inc_alt;
  222.     fprintf(stdout, "\tL'intervalle alt est %7.3lf/", alt);
  223.     l = 0      ; L = 0      ; A = npt_alt;
  224.     alt = alt_min + (double)A*inc_alt;
  225.     fprintf(stdout, "%7.3lf\n", alt);
  226.     fflush(stdout);
  227.     /****    Lecture et ecriture des donnees triees par altitude    ****/
  228.     fprintf(stdout, "\n\tOuverture des fichiers" );
  229.     fflush(stdout);
  230.     fout_00 = fopen("temp_00.alt", "w" );
  231.     fout_01 = fopen("temp_01.alt", "w" );
  232.     fout_02 = fopen("temp_02.alt", "w" );
  233.     fout_03 = fopen("temp_03.alt", "w" );
  234.     fout_04 = fopen("temp_04.alt", "w" );
  235.     fout_05 = fopen("temp_05.alt", "w" );
  236.     fout_06 = fopen("temp_06.alt", "w" );
  237.     fout_07 = fopen("temp_07.alt", "w" );
  238.     fout_08 = fopen("temp_08.alt", "w" );
  239.     fout_09 = fopen("temp_09.alt", "w" );
  240.     fout_10 = fopen("temp_10.alt", "w" );
  241.     fout_11 = fopen("temp_11.alt", "w" );
  242.     fout_12 = fopen("temp_12.alt", "w" );
  243.     fout_13 = fopen("temp_13.alt", "w" );
  244.     fout_14 = fopen("temp_14.alt", "w" );
  245.     fout_15 = fopen("temp_15.alt", "w" );
  246.     fout_16 = fopen("temp_16.alt", "w" );
  247.     fout_17 = fopen("temp_17.alt", "w" );
  248.     fout_18 = fopen("temp_18.alt", "w" );
  249.     fout_19 = fopen("temp_19.alt", "w" );
  250.     fout_20 = fopen("temp_20.alt", "w" );
  251.     fout_21 = fopen("temp_21.alt", "w" );
  252.     fout_22 = fopen("temp_22.alt", "w" );
  253.     fout_23 = fopen("temp_23.alt", "w" );
  254.     fout_24 = fopen("temp_24.alt", "w" );
  255.     fout_25 = fopen("temp_25.alt", "w" );
  256.     fout_26 = fopen("temp_26.alt", "w" );
  257.     fout_27 = fopen("temp_27.alt", "w" );
  258.     fout_28 = fopen("temp_28.alt", "w" );
  259.     fout_29 = fopen("temp_29.alt", "w" );
  260.     fout_30 = fopen("temp_30.alt", "w" );
  261.     fout_31 = fopen("temp_31.alt", "w" );
  262.     fout_32 = fopen("temp_32.alt", "w" );
  263.     fout_33 = fopen("temp_33.alt", "w" );
  264.     fout_34 = fopen("temp_34.alt", "w" );
  265.     fout_35 = fopen("temp_35.alt", "w" );
  266.     fout_36 = fopen("temp_36.alt", "w" );
  267.     fout_37 = fopen("temp_37.alt", "w" );
  268.     fout_38 = fopen("temp_38.alt", "w" );
  269.     fout_39 = fopen("temp_39.alt", "w" );
  270.     fout_40 = fopen("temp_40.alt", "w" );
  271.     fout_41 = fopen("temp_41.alt", "w" );
  272.     fout_42 = fopen("temp_42.alt", "w" );
  273.     fout_43 = fopen("temp_43.alt", "w" );
  274.     fout_44 = fopen("temp_44.alt", "w" );
  275.     fout_45 = fopen("temp_45.alt", "w" );
  276.     fout_46 = fopen("temp_46.alt", "w" );
  277.     fout_47 = fopen("temp_47.alt", "w" );
  278.     fout_48 = fopen("temp_48.alt", "w" );
  279.     fout_49 = fopen("temp_49.alt", "w" );
  280.     data_in = data_out = 0;
  281.     fprintf(stdout,"\tLecture et tri par altitude...\n" );
  282.     fflush(stdout);
  283.     while(!feof(fin))
  284.       {
  285. /*         fscanf(fin, READl, LECTl1); */
  286. /*         fscanf(fin, READl, LECTl2); */
  287.         fscanf(fin, READld, LECTld);
  288.         data_in ++;
  289.         if (lon < 0.)lon += 360.;
  290.         else if (lon >= 360.)lon -= 360.;
  291.         if (lat >= lat_min && lat < lat_max && alt >= alt_min && alt < alt_max)
  292.           {
  293.         if ((lon_min < lon_max && lon >= lon_min && lon < lon_max) ||
  294.             (lon_min > lon_max && (lon >= lon_min || lon < lon_max)))
  295.           {
  296.             index_alt = (int)((alt - alt_min)/inc_alt);
  297.             data_out ++;
  298.             switch(index_alt)
  299.               {
  300.               case 0:
  301.             {
  302.               fprintf(fout_00, WRITEl, ECRITl);
  303.               break;
  304.             }
  305.               case 1:
  306.             {
  307.               fprintf(fout_01, WRITEl, ECRITl);
  308.               break;
  309.             }
  310.               case 2:
  311.             {
  312.               fprintf(fout_02, WRITEl, ECRITl);
  313.               break;
  314.             }
  315.               case 3:
  316.             {
  317.               fprintf(fout_03, WRITEl, ECRITl);
  318.               break;
  319.             }
  320.               case 4:
  321.             {
  322.               fprintf(fout_04, WRITEl, ECRITl);
  323.               break;
  324.             }
  325.               case 5:
  326.             {
  327.               fprintf(fout_05, WRITEl, ECRITl);
  328.               break;
  329.             }
  330.               case 6:
  331.             {
  332.               fprintf(fout_06, WRITEl, ECRITl);
  333.               break;
  334.             }
  335.               case 7:
  336.             {
  337.               fprintf(fout_07, WRITEl, ECRITl);
  338.               break;
  339.             }
  340.               case 8:
  341.             {
  342.               fprintf(fout_08, WRITEl, ECRITl);
  343.               break;
  344.             }
  345.               case 9:
  346.             {
  347.               fprintf(fout_09, WRITEl, ECRITl);
  348.               break;
  349.             }
  350.               case 10:
  351.             {
  352.               fprintf(fout_10, WRITEl, ECRITl);
  353.               break;
  354.             }
  355.               case 11:
  356.             {
  357.               fprintf(fout_11, WRITEl, ECRITl);
  358.               break;
  359.             }
  360.               case 12:
  361.             {
  362.               fprintf(fout_12, WRITEl, ECRITl);
  363.               break;
  364.             }
  365.               case 13:
  366.             {
  367.               fprintf(fout_13, WRITEl, ECRITl);
  368.               break;
  369.             }
  370.               case 14:
  371.             {
  372.               fprintf(fout_14, WRITEl, ECRITl);
  373.               break;
  374.             }
  375.               case 15:
  376.             {
  377.               fprintf(fout_15, WRITEl, ECRITl);
  378.               break;
  379.             }
  380.               case 16:
  381.             {
  382.               fprintf(fout_16, WRITEl, ECRITl);
  383.               break;
  384.             }
  385.               case 17:
  386.             {
  387.               fprintf(fout_17, WRITEl, ECRITl);
  388.               break;
  389.             }
  390.               case 18:
  391.             {
  392.               fprintf(fout_18, WRITEl, ECRITl);
  393.               break;
  394.             }
  395.               case 19:
  396.             {
  397.               fprintf(fout_19, WRITEl, ECRITl);
  398.               break;
  399.             }
  400.               case 20:
  401.             {
  402.               fprintf(fout_20, WRITEl, ECRITl);
  403.               break;
  404.             }
  405.               case 21:
  406.             {
  407.               fprintf(fout_21, WRITEl, ECRITl);
  408.               break;
  409.             }
  410.               case 22:
  411.             {
  412.               fprintf(fout_22, WRITEl, ECRITl);
  413.               break;
  414.             }
  415.               case 23:
  416.             {
  417.               fprintf(fout_23, WRITEl, ECRITl);
  418.               break;
  419.             }
  420.               case 24:
  421.             {
  422.               fprintf(fout_24, WRITEl, ECRITl);
  423.               break;
  424.             }
  425.               case 25:
  426.             {
  427.               fprintf(fout_25, WRITEl, ECRITl);
  428.               break;
  429.             }
  430.               case 26:
  431.             {
  432.               fprintf(fout_26, WRITEl, ECRITl);
  433.               break;
  434.             }
  435.               case 27:
  436.             {
  437.               fprintf(fout_27, WRITEl, ECRITl);
  438.               break;
  439.             }
  440.               case 28:
  441.             {
  442.               fprintf(fout_28, WRITEl, ECRITl);
  443.               break;
  444.             }
  445.               case 29:
  446.             {
  447.               fprintf(fout_29, WRITEl, ECRITl);
  448.               break;
  449.             }
  450.               case 30:
  451.             {
  452.               fprintf(fout_30, WRITEl, ECRITl);
  453.               break;
  454.             }
  455.               case 31:
  456.             {
  457.               fprintf(fout_31, WRITEl, ECRITl);
  458.               break;
  459.             }
  460.               case 32:
  461.             {
  462.               fprintf(fout_32, WRITEl, ECRITl);
  463.               break;
  464.             }
  465.               case 33:
  466.             {
  467.               fprintf(fout_33, WRITEl, ECRITl);
  468.               break;
  469.             }
  470.               case 34:
  471.             {
  472.               fprintf(fout_34, WRITEl, ECRITl);
  473.               break;
  474.             }
  475.               case 35:
  476.             {
  477.               fprintf(fout_35, WRITEl, ECRITl);
  478.               break;
  479.             }
  480.               case 36:
  481.             {
  482.               fprintf(fout_36, WRITEl, ECRITl);
  483.               break;
  484.             }
  485.               case 37:
  486.             {
  487.               fprintf(fout_37, WRITEl, ECRITl);
  488.               break;
  489.             }
  490.               case 38:
  491.             {
  492.               fprintf(fout_38, WRITEl, ECRITl);
  493.               break;
  494.             }
  495.               case 39:
  496.             {
  497.               fprintf(fout_39, WRITEl, ECRITl);
  498.               break;
  499.             }
  500.               case 40:
  501.             {
  502.               fprintf(fout_40, WRITEl, ECRITl);
  503.               break;
  504.             }
  505.               case 41:
  506.             {
  507.               fprintf(fout_41, WRITEl, ECRITl);
  508.               break;
  509.             }
  510.               case 42:
  511.             {
  512.               fprintf(fout_42, WRITEl, ECRITl);
  513.               break;
  514.             }
  515.               case 43:
  516.             {
  517.               fprintf(fout_43, WRITEl, ECRITl);
  518.               break;
  519.             }
  520.               case 44:
  521.             {
  522.               fprintf(fout_44, WRITEl, ECRITl);
  523.               break;
  524.             }
  525.               case 45:
  526.             {
  527.               fprintf(fout_45, WRITEl, ECRITl);
  528.               break;
  529.             }
  530.               case 46:
  531.             {
  532.               fprintf(fout_46, WRITEl, ECRITl);
  533.               break;
  534.             }
  535.               case 47:
  536.             {
  537.               fprintf(fout_47, WRITEl, ECRITl);
  538.               break;
  539.             }
  540.               case 48:
  541.             {
  542.               fprintf(fout_48, WRITEl, ECRITl);
  543.               break;
  544.             }
  545.               case 49:
  546.             {
  547.               fprintf(fout_49, WRITEl, ECRITl);
  548.               break;
  549.             }
  550.               }
  551.           }
  552.           }
  553.       }
  554.     fclose(fout_00);
  555.     fclose(fout_01);
  556.     fclose(fout_02);
  557.     fclose(fout_03);
  558.     fclose(fout_04);
  559.     fclose(fout_05);
  560.     fclose(fout_06);
  561.     fclose(fout_07);
  562.     fclose(fout_08);
  563.     fclose(fout_09);
  564.     fclose(fout_10);
  565.     fclose(fout_11);
  566.     fclose(fout_12);
  567.     fclose(fout_13);
  568.     fclose(fout_14);
  569.     fclose(fout_15);
  570.     fclose(fout_16);
  571.     fclose(fout_17);
  572.     fclose(fout_18);
  573.     fclose(fout_19);
  574.     fclose(fout_20);
  575.     fclose(fout_21);
  576.     fclose(fout_22);
  577.     fclose(fout_23);
  578.     fclose(fout_24);
  579.     fclose(fout_25);
  580.     fclose(fout_26);
  581.     fclose(fout_27);
  582.     fclose(fout_28);
  583.     fclose(fout_29);
  584.     fclose(fout_30);
  585.     fclose(fout_31);
  586.     fclose(fout_32);
  587.     fclose(fout_33);
  588.     fclose(fout_34);
  589.     fclose(fout_35);
  590.     fclose(fout_36);
  591.     fclose(fout_37);
  592.     fclose(fout_38);
  593.     fclose(fout_39);
  594.     fclose(fout_40);
  595.     fclose(fout_41);
  596.     fclose(fout_42);
  597.     fclose(fout_43);
  598.     fclose(fout_44);
  599.     fclose(fout_45);
  600.     fclose(fout_46);
  601.     fclose(fout_47);
  602.     fclose(fout_48);
  603.     fclose(fout_49);
  604.     fclose(fin);
  605.     /****    Lecture fichier par fichier    ****/
  606.     fprintf(stdout,"\n\tLecture OK. Travail par bande d'altitude\n" );
  607.     fflush(stdout);
  608.     npt_tot = npt_lat * npt_lon;
  609.     BR = (double **)malloc(npt_tot*sizeof(double*));
  610.     BT = (double **)malloc(npt_tot*sizeof(double*));
  611.     BP = (double **)malloc(npt_tot*sizeof(double*));
  612.     alt_var = (double **)malloc(npt_tot*sizeof(double*));
  613.     for (i = 0; i < npt_tot; i++)
  614.       {
  615.         BR[i] = (double *)malloc(NMAX*sizeof(double));
  616.         BT[i] = (double *)malloc(NMAX*sizeof(double));
  617.         BP[i] = (double *)malloc(NMAX*sizeof(double));
  618.         alt_var[i] = (double *)malloc(NMAX*sizeof(double));
  619.       }
  620.     if (choix == 1)
  621.       {
  622.         BR_med = (double *)malloc(npt_tot*sizeof(double));
  623.         BT_med = (double *)malloc(npt_tot*sizeof(double));
  624.         BP_med = (double *)malloc(npt_tot*sizeof(double));
  625.       }
  626.     else if (choix == 2)
  627.       {
  628.         BR_moy = (double *)malloc(npt_tot*sizeof(double));
  629.         BT_moy = (double *)malloc(npt_tot*sizeof(double));
  630.         BP_moy = (double *)malloc(npt_tot*sizeof(double));
  631.       }
  632.     else if (choix == 3)
  633.       {
  634.         BR_min = (double *)malloc(npt_tot*sizeof(double));
  635.         BT_min = (double *)malloc(npt_tot*sizeof(double));
  636.         BP_min = (double *)malloc(npt_tot*sizeof(double));
  637.       }
  638.     else if (choix == 4)
  639.       {
  640.         BR_max = (double *)malloc(npt_tot*sizeof(double));
  641.         BT_max = (double *)malloc(npt_tot*sizeof(double));
  642.         BP_max = (double *)malloc(npt_tot*sizeof(double));
  643.       }
  644.     BR_std = (double *)malloc(npt_tot*sizeof(double));
  645.     BT_std = (double *)malloc(npt_tot*sizeof(double));
  646.     BP_std = (double *)malloc(npt_tot*sizeof(double));
  647.     NPT = (int *)malloc(npt_tot*sizeof(int*));
  648.     BR[0][0] = 0.;
  649.     for (A = 0; A < 50 ; A ++)
  650.       {
  651.         fprintf(stdout, "\t\tAltitude = %lf\n", (double)(A * inc_alt) + alt_min);
  652.         sprintf(str, "temp_%02d.alt", A);
  653.         fin = fopen(str, "r" );
  654.         for (i = 0 ; i < npt_tot ; i ++)
  655.           {
  656.         NPT[i] = 0;
  657.           }
  658.         while (!feof(fin))
  659.           {
  660.         d = fscanf(fin, READl, LECTl2);
  661.         if (d == 7)
  662.           {
  663.             l = (lat - lat_min) / inc_lat;
  664.             if (lon_max > lon_min)
  665.               {
  666.             L = (int)((lon - lon_min ) / inc_lon);
  667.               }
  668.             else
  669.               {
  670.             if (lon >= lon_min)
  671.               {
  672.                 L = (int)((lon - lon_min ) /inc_lon);
  673.               }
  674.             else
  675.               {
  676.                 L = (int)((lon + 360. - lon_min ) /inc_lon);
  677.               }
  678.               }
  679.             index = l * npt_lon + L;
  680.             for (i = 0 ; i < NPT[index]; i++)
  681.               {
  682.             if (br < BR[index][i])
  683.               {
  684.                 temp = BR[index][i];
  685. /*                 j = i; */
  686. /*                 fprintf(stdout," %d\n",j);fflush(stdout); */
  687.                 BR[index][i] = br;
  688.                 br = temp;
  689.                 for (j = i+1 ; j < NPT[index]; j++)
  690.                   {
  691.                 temp = BR[index][j];
  692.                 BR[index][j] = br;
  693.                 br = temp;
  694.                   }
  695.                 break;
  696.               }
  697.               }
  698.             BR[index][NPT[index]] = br;
  699.            
  700.             for (i = 0 ; i < NPT[index]; i++)
  701.               {
  702.             if (bt < BT[index][i])
  703.               {
  704.                 temp = BT[index][i];
  705.                 BT[index][i] = bt;
  706.                 bt = temp;
  707.                 for (j = i+1 ; j < NPT[index]; j++)
  708.                   {
  709.                 temp = BT[index][j];
  710.                 BT[index][j] = bt;
  711.                 bt = temp;
  712.                   }
  713.                 break;
  714.               }
  715.               }
  716.             BT[index][NPT[index]] = bt;
  717.            
  718.             for (i = 0 ; i < NPT[index]; i++)
  719.               {
  720.             if (bp < BP[index][i])
  721.               {
  722.                 temp = BP[index][i];
  723.                 BP[index][i] = bp;
  724.                 bp = temp;
  725.                 for (j = i+1 ; j < NPT[index]; j++)
  726.                   {
  727.                 temp = BP[index][j];
  728.                 BP[index][j] = bp;
  729.                 bp = temp;
  730.                   }
  731.                 break;
  732.               }
  733.               }
  734.             BP[index][NPT[index]] = bp;
  735.             alt_var[index][NPT[index]] = alt;
  736.             NPT[index] += 1;
  737.            
  738. /*         fprintf(stdout, "Case %d, %d points lus\n", index, NPT[index]);fflush(stdout); */
  739.           }
  740.           }
  741.         fclose(fin);
  742.         if (choix == 1)
  743.           {
  744.         for (l = 0 ; l < npt_lat; l++)
  745.           {
  746.             for (L = 0 ; L < npt_lon ; L++)
  747.               {
  748.             index = l * npt_lon + L;
  749.             if (NPT[index] > 0)
  750.               {
  751. /*                 for (k = 0 ; k < NPT[index]; k++) */
  752. /*                   { */
  753. /*                 fprintf(stdout, "%3d %8.3lf %8.3lf %8.3lf\n", k,BR[index][k],BT[index][k],BP[index][k]);fflush(stdout); */
  754. /*                   } */
  755.                 if (NPT[index] == 1)
  756.                   {
  757.                 BR_med[index]=BR[index][NPT[index]-1];
  758.                 BT_med[index]=BT[index][NPT[index]-1];
  759.                 BP_med[index]=BP[index][NPT[index]-1];
  760.                   }
  761.                 else if ( NPT[index]%2 == 0)
  762.                   {
  763.                 BR_med[index]=(BR[index][NPT[index]/2-1]+BR[index][NPT[index]/2])/2.;
  764.                 BT_med[index]=(BT[index][NPT[index]/2-1]+BT[index][NPT[index]/2])/2.;
  765.                 BP_med[index]=(BP[index][NPT[index]/2-1]+BP[index][NPT[index]/2])/2.;
  766.                   }
  767.                 else if ( NPT[index]%2 != 0)
  768.                   {
  769.                 BR_med[index]=BR[index][(NPT[index]-1)/2];
  770.                 BT_med[index]=BT[index][(NPT[index]-1)/2];
  771.                 BP_med[index]=BP[index][(NPT[index]-1)/2];
  772.                   }
  773.                 std_br = std_bt = std_bp = 0;
  774.                 for (k = 0; k < NPT[index] ; k ++)
  775.                   {
  776.                 dif_br = (BR[index][k] - BR_med[index]);
  777.                 std_br  += dif_br*dif_br;
  778.                 dif_bt = (BT[index][k] - BT_med[index]);
  779.                 std_bt  += dif_bt*dif_bt;
  780.                 dif_bp = (BP[index][k] - BP_med[index]);
  781.                 std_bp  += dif_bp*dif_bp;
  782.                   }
  783.                 if (NPT[index] > 2)
  784.                   {
  785.                 BR_std[index] = sqrt(std_br/(NPT[index]-1));
  786.                 BT_std[index] = sqrt(std_bt/(NPT[index]-1));
  787.                 BP_std[index] = sqrt(std_bp/(NPT[index]-1));
  788.                   }
  789.                 else
  790.                   {
  791.                 BR_std[index] = 3.;
  792.                 BT_std[index] = 3.;
  793.                 BP_std[index] = 3.;
  794.                   }
  795.                 lat = lat_min + (double)l*inc_lat + inc_lat/2.;
  796.                 lon = lon_min + (double)L*inc_lon + inc_lon/2.;
  797.                 alt = alt_min + (double)A*inc_alt + inc_alt/2.;
  798.                
  799.                 fprintf(fout, WRITE_bin, dday, lon, lat, alt,
  800.                     BR_med[index], BT_med[index], BP_med[index],
  801.                     NPT[index],
  802.                     BR_std[index], BT_std[index], BP_std[index]);
  803.               }
  804.               }
  805.           }
  806.           }
  807.         else if (choix == 2)
  808.           {
  809.         for (l = 0 ; l < npt_lat; l++)
  810.           {
  811.             for (L = 0 ; L < npt_lon ; L++)
  812.               {
  813.             index = l * npt_lon + L;
  814.             if (NPT[index] > 0)
  815.               {
  816.                 sum_br = sum_bt = sum_bp = 0.;
  817.                 for (k = 0; k < NPT[index] ; k ++)
  818.                   {
  819.                 sum_br += BR[index][k];
  820.                 sum_bt += BT[index][k];
  821.                 sum_bp += BP[index][k];
  822.                   }
  823.                 BR_moy[index] = sum_br / (double)NPT[index];
  824.                 BT_moy[index] = sum_bt / (double)NPT[index];
  825.                 BP_moy[index] = sum_bp / (double)NPT[index];
  826.                 std_br = std_bt = std_bp = 0;
  827.                 for (k = 0; k < NPT[index] ; k ++)
  828.                   {
  829.                 dif_br = (BR[index][i] - BR_moy[index]);
  830.                 std_br  += dif_br*dif_br;
  831.                 dif_bt = (BT[index][i] - BT_moy[index]);
  832.                 std_bt  += dif_bt*dif_bt;
  833.                 dif_bp = (BP[index][i] - BP_moy[index]);
  834.                 std_bp  += dif_bp*dif_bp;
  835.                   }
  836.                 if (NPT[index] > 2)
  837.                   {
  838.                 BR_std[index] = sqrt(std_br/(NPT[index]-1));
  839.                 BT_std[index] = sqrt(std_bt/(NPT[index]-1));
  840.                 BP_std[index] = sqrt(std_bp/(NPT[index]-1));
  841.                   }
  842.                 else
  843.                   {
  844.                 BR_std[index] = 3.;
  845.                 BT_std[index] = 3.;
  846.                 BP_std[index] = 3.;
  847.                   }
  848.                 lat = lat_min + (double)l*inc_lat + inc_lat/2.;
  849.                 lon = lon_min + (double)L*inc_lon + inc_lon/2.;
  850.                 if (lon >= 360.)
  851.                   lon -= 360.;
  852.                 alt = alt_min + (double)A*inc_alt + inc_alt/2.;
  853.                 fprintf(fout, WRITE_bin, dday, lon, lat, alt,
  854.                     BR_moy[index], BT_moy[index], BP_moy[index],
  855.                     NPT[index],
  856.                     BR_std[index], BT_std[index], BP_std[index]);
  857.               }
  858.               }
  859.           }
  860.           }
  861.         else if (choix == 3)
  862.           {
  863.         for (l = 0 ; l < npt_lat; l++)
  864.           {
  865.             for (L = 0 ; L < npt_lon ; L++)
  866.               {
  867.             index = l * npt_lon + L;
  868.             if (NPT[index] > 0)
  869.               {
  870.                 BR_min[index] = BR[index][0];
  871.                 BT_min[index] = BT[index][0];
  872.                 BP_min[index] = BP[index][0];
  873.                 std_br = std_bt = std_bp = 0;
  874.                 for (k = 0; k < NPT[index] ; k ++)
  875.                   {
  876.                 dif_br = (BR[index][i] - BR_min[index]);
  877.                 std_br  += dif_br*dif_br;
  878.                 dif_bt = (BT[index][i] - BT_min[index]);
  879.                 std_bt  += dif_bt*dif_bt;
  880.                 dif_bp = (BP[index][i] - BP_min[index]);
  881.                 std_bp  += dif_bp*dif_bp;
  882.                   }
  883.                 if (NPT[index] > 2)
  884.                   {
  885.                 BR_std[index] = sqrt(std_br/(NPT[index]-1));
  886.                 BT_std[index] = sqrt(std_bt/(NPT[index]-1));
  887.                 BP_std[index] = sqrt(std_bp/(NPT[index]-1));
  888.                   }
  889.                 else
  890.                   {
  891.                 BR_std[index] = 3.;
  892.                 BT_std[index] = 3.;
  893.                 BP_std[index] = 3.;
  894.                   }
  895.                 lat = lat_min + (double)l*inc_lat + inc_lat/2.;
  896.                 lon = lon_min + (double)L*inc_lon + inc_lon/2.;
  897.                 if (lon >= 360.)
  898.                   lon -= 360.;
  899.                 alt = alt_min + (double)A*inc_alt + inc_alt/2.;
  900.                 fprintf(fout, WRITE_bin, dday, lon, lat, alt,
  901.                     BR_min[index], BT_min[index], BP_min[index],
  902.                     NPT[index],
  903.                     BR_std[index], BT_std[index], BP_std[index]);
  904.               }
  905.               }
  906.           }
  907.           }
  908.         else if (choix == 4)
  909.           {
  910.         for (l = 0 ; l < npt_lat; l++)
  911.           {
  912.             for (L = 0 ; L < npt_lon ; L++)
  913.               {
  914.             index = l * npt_lon + L;
  915.             if (NPT[index] > 0)
  916.               {
  917.                 BR_max[index] = BR[index][NPT[index]-1];
  918.                 BT_max[index] = BT[index][NPT[index]-1];
  919.                 BP_max[index] = BP[index][NPT[index]-1];
  920.                 std_br = std_bt = std_bp = 0;
  921.                 for (k = 0; k < NPT[index] ; k ++)
  922.                   {
  923.                 dif_br = (BR[index][i] - BR_max[index]);
  924.                 std_br  += dif_br*dif_br;
  925.                 dif_bt = (BT[index][i] - BT_max[index]);
  926.                 std_bt  += dif_bt*dif_bt;
  927.                 dif_bp = (BP[index][i] - BP_max[index]);
  928.                 std_bp  += dif_bp*dif_bp;
  929.                   }
  930.                 if (NPT[index] > 2)
  931.                   {
  932.                 BR_std[index] = sqrt(std_br/(NPT[index]-1));
  933.                 BT_std[index] = sqrt(std_bt/(NPT[index]-1));
  934.                 BP_std[index] = sqrt(std_bp/(NPT[index]-1));
  935.                   }
  936.                 else
  937.                   {
  938.                 BR_std[index] = 3.;
  939.                 BT_std[index] = 3.;
  940.                 BP_std[index] = 3.;
  941.                   }
  942.                 lat = lat_min + (double)l*inc_lat + inc_lat/2.;
  943.                 lon = lon_min + (double)L*inc_lon + inc_lon/2.;
  944.                 if (lon >= 360.)
  945.                   lon -= 360.;
  946.                 alt = alt_min + (double)A*inc_alt + inc_alt/2.;
  947.                 fprintf(fout, WRITE_bin, dday, lon, lat, alt,
  948.                     BR_max[index], BT_max[index], BP_max[index],
  949.                     NPT[index],
  950.                     BR_std[index], BT_std[index], BP_std[index]);
  951.               }
  952.               }
  953.           }
  954.           }
  955.         for (l = 0; l < npt_lat; l++)
  956.           {
  957.         for (L = 0 ; L < npt_lon ; L++)
  958.           {
  959.             index = l * npt_lon + L;
  960.             if (NPT[index] > 0)
  961.               {
  962.             filled_bin ++;
  963.             if (NPT[index] > 2)
  964.               {
  965.                 filled_bin2 ++;
  966.               }
  967.             if (NPT[index] > 1)
  968.               {
  969.                 filled_bin1 ++;
  970.               }
  971.               }
  972.           }
  973.           }
  974.         for (l = 0; l < npt_lat; l++)
  975.           {
  976.         for (L = 0 ; L < npt_lon ; L++)
  977.           {
  978.             index = l * npt_lon + L;
  979.             if (NPT[index] > 1)
  980.               {
  981.             lat = lat_min + (double)l*inc_lat + inc_lat/2.;
  982.             lon = lon_min + (double)L*inc_lon + inc_lon/2.;
  983.             if (lon >= 360.)
  984.               lon -= 360.;
  985.             fprintf(fout, "%7.3lf %7.3lf", lon, lat);
  986.             for (i=0;i<NPT[index]; i++)
  987.               {
  988.                 fprintf(fout, " %7.3lf", alt_var[index][i]);
  989.               }
  990.             fprintf(fout, "\n" );
  991.               }
  992.           }
  993.           }
  994.       }
  995.     fclose(fout);
  996.     fprintf(stdout, "\tNombre de donnees lues      : %10d\n", data_in);
  997.     fprintf(stdout, "\tNombre de donnees utilisees : %10d\n", data_out);
  998.     fprintf(stdout, "\tNombre de bin remplis      : %10d\n", filled_bin);
  999.     fprintf(stdout, "\tNombre de bin remplis (N>1) : %10d\n", filled_bin1);
  1000.     fprintf(stdout, "\tNombre de bin remplis (N>2) : %10d\n", filled_bin2);
  1001.       }



un exemple de mon fichier X
JOUR lat lon alt br bt bp
2032.376403461 -10.894 129.987 383.150 -0.343 2.969 -0.746

Voila je vous remercie de votre aide eventuelle


Aller à :