²é¿´: 1315  |  »Ø¸´: 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 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[»ù½ðÉêÇë] 5¸ö%2F£¬·Ç¹Ì¶¨¶Î22¸ö×Öĸ +8 jaasxulu 2026-07-15 9/450 2026-07-18 17:40 by dxcgbm
[»ù½ðÉêÇë] ÃæÉϵÄË®ºÜÉî +10 ²¼²¼ºÍÒ»¶þ 2026-07-18 15/750 2026-07-18 17:07 by 6543yes
[»ù½ðÉêÇë] ¹úÉç¿ÆÍ¨Ñ¶ÆÀÉó +3 DZˮ¹Ú¾ü123 2026-07-18 4/200 2026-07-18 16:29 by ×î°®±à×ë´Çµä
[»ù½ðÉêÇë] ÉúÃü¿ÚC13ÃæÉÏ»áÆÀʱ¼ä +7 luckinging 2026-07-14 11/550 2026-07-17 20:43 by ³æ²·1988
[½Ìʦ֮¼Ò] ÄÚÐÄØÑ·¦ +16 Ë®±ùÔÂÔÂÒ°Íà 2026-07-12 16/800 2026-07-17 19:25 by otani
[»ù½ðÉêÇë] ÉúÃü¿ÚÃæÉÏ»áÆÀ½áÊøÁËÂð´ó¼ÒÓÐÖªµÀ½á¹ûÂð£¿ÏÖÔÚ»¹Ã»Óнá¹ûÕý³£²»£¿ +6 ±ÌË®00 2026-07-16 9/450 2026-07-17 15:21 by jaasxulu
[ÂÛÎÄͶ¸å] ͶӢÎÄÆÚ¿¯ÈçºÎ²éÖØ 10+5 ²»ÖªµÀȡʲôÃû× 2026-07-15 6/300 2026-07-17 09:07 by bobvan
[»ù½ðÉêÇë] ²»ÒªÔÙÊý¹ú×ÔÈ»ÉêÇëÊéµÄ filecode µÄ·Ö¸ô·û¸öÊýÁË +14 sadpencil 2026-07-12 21/1050 2026-07-17 00:15 by wangze12014
[Óлú½»Á÷] ²®°·Éϼ׻ùÇóÖú 100+4 002tmumu 2026-07-14 7/350 2026-07-16 19:47 by 002tmumu
[ÂÛÎÄͶ¸å] ¿ç³ö°æÉçÉÌͶ¸å 20+5 ÄߺÃ520 2026-07-13 5/250 2026-07-16 17:24 by ÎÞÊÓ¾üÍÅ
[»ù½ðÉêÇë] ÉúÉúÃüѧ²¿»áÆÀ +4 wuke100666 2026-07-15 4/200 2026-07-16 00:12 by À²À²Ð¡ÄÝ×Ó
[»ù½ðÉêÇë] H¿Ú£¬ÃæÉÏ£¬Ê±¼ä´Á7ÔÂ7ÈÕ¡£ +3 plumage5 2026-07-15 3/150 2026-07-15 21:06 by 6543yes
[»ù½ðÉêÇë] Сľ³æÃ»ÂäÁË£¬³ýÁËÆíµ»Ìû×Ó£¬¼¸ºõ¿´²»µ½ÓмÛÖµµÄÌû×Ó +13 botar 2026-07-14 14/700 2026-07-15 19:28 by º®Á÷32
[»ù½ðÉêÇë] »áÆÀ +5 ÎÞÃûÕßµÇɽ 2026-07-15 5/250 2026-07-15 18:15 by ¸Ü¾ÍÊÇÄã¶Ô
[»ù½ðÉêÇë] E¿Ú»áÆÀ +11 ²¼²¼ºÍÒ»¶þ 2026-07-13 13/650 2026-07-15 16:34 by Kittylucky
[»ù½ðÉêÇë] E¿ÚÇàC»áÆÀ½áÊøÁËÂ𣿠40+3 ССÊ鳿c 2026-07-14 9/450 2026-07-15 16:04 by °²¾²µÄÖªÁË
[ÂÛÎÄͶ¸å] ũҵ»úеѧ±¨Í¶¸åÖÜÆÚ +3 G0DLIN 2026-07-14 7/350 2026-07-15 09:26 by xs74101122
[»ù½ðÉêÇë] ¹ú×ÔÈ»ÃæÉÏD¿ÚÆíµ» +4 monkeynana 2026-07-14 4/200 2026-07-15 09:14 by °×Ë®Öó
[»ù½ðÉêÇë] ûÊÕµ½ÏûÏ¢£¬ÔÙ´ÎÅãÅÜ +3 Ìì¿ÕÐdz½fly 2026-07-14 3/150 2026-07-14 19:14 by 6543yes
[»ù½ðÉêÇë] Ã÷ÌìE¿ÚÃæÉÏ»áÆÀ +8 ²¼²¼ºÍÒ»¶þ 2026-07-12 9/450 2026-07-13 22:59 by QTSorange
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û