±±¾©Ê¯ÓÍ»¯¹¤Ñ§Ôº2026ÄêÑо¿ÉúÕÐÉú½ÓÊÕµ÷¼Á¹«¸æ
²é¿´: 1247  |  »Ø¸´: 4

liupeiping

гæ (³õÈëÎÄ̳)

[ÇóÖú] Âé·³ÄÄλ´óÉñ°ïæÐÞ¸ÄÒ»ÏÂÕâ¸ö³ÌÐò£¬²»Ê¤¸Ð¼¤£¡ ÒÑÓÐ2È˲ÎÓë

Âé·³ÄÄλ´óÉñ°ïæ¿´Ò»ÏÂÏÂÃæÕâ¸ö³ÌÐò£¬±àÒëµÄʱºò»áÌáʾWhile(true)´¦ÓÐ´í£¬Ó¦¸ÃÔõô¸Ä£¬Çë¸æÖªÒ»Ï£¬²»Ê¤¸Ð¼¤£¡
// stat.cpp : Defines the entry point for the console application.
  //

  #include <stdio.h>
  #include <stdlib.h>
  #include <math.h>
  #include <getopt.h>
  #include <string.h>

  // Show a simple usage information.
  void usage();

  int main(int argc, char* argv[])
  {
       char opt;                              // Options charactors
       int a=30, b=1, c=7;
       double r_critical = 3.3943e-2;
                                              // Critical radius for judging inner or outer
       double alpha = 1.0e-6;
                                              // Error critical for test double equal
       char ofname[255] = "out.txt";  // Output file name
       FILE *fin, *fout;
       unsigned int i = 0;                // Treatment index
       double time = 0.0L;                // Total sampling time
       double time_bak = 0.0L;            // time backup
       unsigned int steps = 0;            // Sampling times
       double y = 0.0L;                   // axis y pos
       double z = 0.0L;                   // axis z pos
       double r = 0.0L;                   // Radius
       double iq = 0.0L;                    // Irradiation quantity
       unsigned int inner = 0;            // Inner sampling counter
       unsigned int outer = 0;            // Outer sampling counter

       while ((opt = getopt(argc, argv, "a:b:c:e:r:h") != -1) {
              switch (opt) {
                      case 'a':
                              a = atoi(optarg);
                              break;
                      case 'b':
                              b = atoi(optarg);
                              break;
                      case 'c':
                              c = atoi(optarg);
                              break;
                      case 'e':
                              alpha = atof(optarg);
                              break;
                      case 'o':
                              strcpy(ofname, optarg);
                              break;
                      case 'r':
                              r_critical = atof(optarg);
                              break;
                      case ':':
                              // Go through
                      case '?':
                              // Go through
                      case 'h':
                              // Go through
                      default:
                             usage();
                             exit(0);
                          }// switch
           }// while
       if (optind != argc-1) {
            fprintf(stderr, "Need a data file.\n";
            fprintf(stderr, "Use option -h to get some helpful message.\n";
            exit(1);
           }
       else
            // Open input & output files
            if ((fin = fopen(argv[optind], "r")==NULL)
                        {
                   printf("data file: %s\n", argv[optind]);
                   printf("Open input file %s failed!\n", argv[optind]);
                   exit(1);
                        }

           if ((fout = fopen(ofname, "w+") == NULL)
           {
             printf("Open/Create output file %s failed!\n", ofname);
             exit(1);
           }
       // Output table header
       fprintf(fout, "\tIndex\t\tTime\t\tSteps\t\tInner\t\tOuter\t\tRate\t\tIrradiation\n";
       fprintf(fout, "\t-------\t\t------\t\t------\t\t------\t\t------\t\t------\t\t------\n";

       // Read a line datas
       do
           {
            // Read a line, but just store useful data
            fscanf(fin, "%le%*le%*le%le%le%*le%*le%*le%*le%*le%*le%*le", &time, &y, &z);

            if (feof(fin)) // end of file
                        {
                  fprintf(fout, "\t%d\t\t%le\t%d\t\t%d\t\t%d\t\t%f\t\t%f\n", i, time_bak, steps, inner,
       outer, ((double)inner)/(inner + outer), iq);
                  printf("\t%d\t\t%le\t%d\t\t%d\t\t%d\t\t%f\t\t%f\n", i, time_bak, steps, inner, outer,
       ((double)inner)/(inner + outer), iq);
                  break;                   // out of repeat
                        }


            if (time < alpha) // time == 0 means a new treatment
                        {
                  // Store treatment data
                  if (i > 0)
                                  {
                        fprintf(fout, "\t%d\t\t%le\t%d\t\t%d\t\t%d\t\t%f\t\t%f\n", i, time_bak, steps,
       inner, outer, ((double)inner)/(inner + outer), iq);
                        printf("\t%d\t\t%le\t%d\t\t%d\t\t%d\t\t%f\t\t%f\n", i, time_bak, steps, inner,
       outer, ((double)inner)/(inner + outer), iq);
                                  }

                  // Clear variable relative to treatment
                  steps = 0;
                  inner = 0;
                  outer = 0;
                  iq = 0;
                  time_bak = 0;
                  i++;     // increment index
                        }

            // Increment step counters
            steps++;
            // Calculate radius
            r = sqrt(y*y + z*z);
            if (r-r_critical > alpha)
                        {
                  outer++;
                        }
            else
                        {
                  inner++;
                        }

                // Calculate irradiation quantity
            //printf("r=%lf\n", r);
            iq += a*b*pow(10, -1*c*r)*fabs(time-time_bak);

                time_bak = time;
           } while (true);

       // Close files
       fclose(fin);
       fclose(fout);

       //printf("Calculate finished, press ENTER to exit.";
       //printf("pow(10, 1) = %f", pow(10, 1));
       //getchar();
       return 0;
   }

   void usage()
   {
         printf("[Usage]: stat datafile.\n";
         printf("Options: \n";
         printf("\t-a, -b, -c: set coefficiency relatively.\n";
         printf("\t-o: set output file name.\n";
         printf("\t-e: set alpha used to compare two float number.\n";
         printf("\t-r: set referrence diameter.\n";
         printf("\nDeveloped by Sam <yeahspyme@sina.com>, published under GPL licence.\n";
   }
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:

ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

rbs

ľ³æ (СÓÐÃûÆø)

¡¾´ð°¸¡¿Ó¦Öú»ØÌû

¸Ðл²ÎÓ룬ӦÖúÖ¸Êý +1
´íÎóÌáʾÊÇʲô£¿
2Â¥2015-01-14 18:21:16
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

liupeiping

гæ (³õÈëÎÄ̳)

ÒýÓûØÌû:
2Â¥: Originally posted by rbs at 2015-01-14 18:21:16
´íÎóÌáʾÊÇʲô£¿

лл¹Ø×¢£¬ÌáʾµÄÊÇ while (true)´¦ÓÐÎÊÌ⣺ error C2065: 'true' : undeclared identifier¡£Ó¦¸ÃÔõôÐÞ¸ÄÄØ£¿
3Â¥2015-01-15 09:31:32
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

sxu2009

ÖÁ×ðľ³æ (ÕýʽдÊÖ)

¡¾´ð°¸¡¿Ó¦Öú»ØÌû

¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï
¸Ðл²ÎÓ룬ӦÖúÖ¸Êý +1
liupeiping: ½ð±Ò+20, ¡ï¡ï¡ïºÜÓаïÖú, ÎÊÌâÒѽâ¾ö 2015-01-16 09:24:15
ÒýÓûØÌû:
3Â¥: Originally posted by liupeiping at 2015-01-15 09:31:32
лл¹Ø×¢£¬ÌáʾµÄÊÇ while (true)´¦ÓÐÎÊÌ⣺ error C2065: 'true' : undeclared identifier¡£Ó¦¸ÃÔõôÐÞ¸ÄÄØ£¿...

ÉùÃ÷Ò»¸öºêÊÔÊÔ£¬¼Ó£º
#define true 1
4Â¥2015-01-15 10:57:51
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

liupeiping

гæ (³õÈëÎÄ̳)

ÒýÓûØÌû:
4Â¥: Originally posted by sxu2009 at 2015-01-15 10:57:51
ÉùÃ÷Ò»¸öºêÊÔÊÔ£¬¼Ó£º
#define true 1...

ºÃµÄ£¬ÎÒÊÔÊÔ£¬Ð»Ð»£¡
5Â¥2015-01-16 09:23:37
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ liupeiping µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] ²ÄÁϵ÷¼Á +11 Ò¼·¡·¡ÒÚ 2026-04-04 11/550 2026-04-05 18:47 by À¶ÔÆË¼Óê
[¿¼ÑÐ] 358Çóµ÷¼Á +7 Çïgk 2026-04-04 7/350 2026-04-05 13:29 by huangmoli
[¿¼ÑÐ] Ò»Ö¾Ô¸±±¾©»¯¹¤´óѧ£¬³õÊԳɼ¨350Çóµ÷¼Á +9 ÑØ°¶?±´¿Ç 2026-04-04 14/700 2026-04-05 01:09 by ÑØ°¶?±´¿Ç
[¿¼ÑÐ] 320·ÖÈ˹¤ÖÇÄܵ÷¼Á +7 Õñ¡ªTZ 2026-04-03 7/350 2026-04-05 00:42 by chongya
[¿¼ÑÐ] 323Çóµ÷¼Á +8 Àî¼ÑÀÖ1 2026-04-04 8/400 2026-04-04 22:26 by hemengdong
[¿¼ÑÐ] ²ÄÁϵ÷¼Á +12 Ò»ÑùYWY 2026-04-02 13/650 2026-04-04 20:49 by À¶ÔÆË¼Óê
[¿¼ÑÐ] Ò»Ö¾Ô¸Äϲý´óѧ324Çóµ÷¼Á +9 hanamiko 2026-03-30 9/450 2026-04-04 11:04 by Öí»á·É
[¿¼ÑÐ] 266Çóµ÷¼Á +8 ѧԱ97LZgn 2026-04-03 8/400 2026-04-04 09:02 by 20021109
[¿¼ÑÐ] 387Çóµ÷¼Á +4 °®³ÔƬ¶¹ÍÁ 2026-04-03 5/250 2026-04-04 08:10 by °¶ÉϵÄÒ»ÌõÓã
[¿¼ÑÐ] µ÷¼Á0855-288 +5 xÐܶþa 2026-04-03 5/250 2026-04-04 00:19 by Öí»á·É
[¿¼ÑÐ] 322Çóµ÷¼Á +6 FZAC123 2026-04-03 6/300 2026-04-03 22:23 by ¿ÆÑÐСר¼Ò
[¿¼ÑÐ] 085601Ò»Ö¾Ô¸±±Àí325·ÖÇóµ÷¼Á +6 ÕÒµ÷¼Á£¬£¬ 2026-04-02 6/300 2026-04-03 22:20 by –¹Æ?
[¿¼ÑÐ] ѧ˶288µ÷¼Á!!! +3 СÍõxw123 2026-04-03 3/150 2026-04-03 21:20 by à£à£à£0119
[¿¼ÑÐ] 273Çóµ÷¼Á +20 ÀîÜÆÐÂ1 2026-03-31 20/1000 2026-04-03 09:58 by linyelide
[¿¼ÑÐ] Çóµ÷¼Á22408 288·Ö +5 new382 2026-04-02 5/250 2026-04-03 09:13 by ×íÔÚ·çÀï
[¿¼ÑÐ] Ò»Ö¾Ô¸´ó¹¤Ñ§Ë¶£¬Çóµ÷¼Á +4 yub0811 2026-04-02 4/200 2026-04-02 21:36 by °ÙÁéͯ888
[¿¼ÑÐ] 322Çóµ÷¼Á +5 ìäÙÒXX 2026-03-31 6/300 2026-04-02 10:08 by Çóµ÷¼Ázz
[¿¼ÑÐ] 0817»¯¹¤Ñ§Ë¶µ÷¼Á +11 ŬÁ¦Éϰ¶ÖУ¡ 2026-03-31 11/550 2026-04-01 20:30 by Àµ´ºÑÞ
[¿¼ÑÐ] ¿¼ÑÐÉúÎïÓëÒ½Ò©µ÷¼Á +7 Ìúº©º©123425 2026-03-31 7/350 2026-04-01 08:45 by JourneyLucky
[¿¼ÑÐ] ¿¼Ñе÷¼ÁÇóÖú +7 13287130938 2026-03-31 7/350 2026-03-31 16:39 by 690616278
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û