home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / fractal / kaos.lha / kaos_batch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-15  |  4.6 KB  |  213 lines

  1. /*
  2.         ### batch driver program for kaos ### 
  3. *****************************************************************************
  4.  
  5.     Swan Kim and John Guckenheimer, POSTECH & Cornell U, 11/1/89
  6.             
  7. *****************************************************************************
  8. */
  9.  
  10. #include "include/kaos.h"
  11.  
  12. main(argc,argv)
  13. int argc;
  14. char **argv;
  15. {
  16.     int i;
  17.     int batch_count;
  18.     char s_key[10];
  19.     
  20.     /* region_index needs to be passed from the main program */
  21.     region_index = 1;
  22.  
  23.     batch_on = 1;
  24.     symbol_type = 0;
  25.     int_driver = 0;
  26.     batch_count = 4;
  27.     mapping_on = 0;
  28.     inverse_on =0;
  29.     cur_color = 1;
  30.     f_color = 1;
  31.     continue_toggle = 0;
  32.     forward_toggle = 1;
  33.     my_colormap_size = 128;
  34.     var_colormap_size = 50;
  35.     segment_count1 = 3;
  36.     sprintf(dir_name,"/mnt/kim/kaos");
  37.     sprintf(file_name,"tmp.dat");
  38.     
  39.     for (i=1; i<argc; i++){
  40.         if (strcmp(argv[i],"-s") == 0) {
  41.             i++;
  42.             symbol_type = atoi(argv[i]);
  43.         }
  44.         if (strcmp(argv[i],"-i") == 0) {
  45.             i++;
  46.             int_driver = atoi(argv[i]);
  47.         }
  48.         if (strcmp(argv[i],"-mo") == 0) {
  49.             i++;
  50.             mapping_on = atoi(argv[i]);
  51.         }
  52.         if (strcmp(argv[i],"-io") == 0) {
  53.             i++;
  54.             inverse_on = atoi(argv[i]);
  55.         }
  56.         if (strcmp(argv[i],"-b") == 0) {
  57.             i++;
  58.             batch_count = atoi(argv[i]);
  59.         }
  60.         if (strcmp(argv[i],"-c") == 0) {
  61.             i++;
  62.             continue_toggle = atoi(argv[i]);
  63.         }
  64.         if (strcmp(argv[i],"-f") == 0) {
  65.             i++;
  66.             forward_toggle = atoi(argv[i]);
  67.         }
  68.         if (strcmp(argv[i],"-cc") == 0) {
  69.             i++;
  70.             cur_color= atoi(argv[i]);
  71.         }
  72.         if (strcmp(argv[i],"-fc") == 0) {
  73.             i++;
  74.             f_color = atoi(argv[i]);
  75.         }
  76.         if (strcmp(argv[i],"-mc") == 0) {
  77.             i++;
  78.             my_colormap_size = atoi(argv[i]);
  79.         }
  80.         if (strcmp(argv[i],"-vc") == 0) {
  81.             i++;
  82.             var_colormap_size = atoi(argv[i]);
  83.         }
  84.         if (strcmp(argv[i],"-n") == 0) {
  85.             i++;
  86.             segment_count1= atoi(argv[i]);
  87.         }
  88.         if (strcmp(argv[i],"-D") == 0) {
  89.             i++;
  90.             sprintf(dir_name,"%s",argv[i]);
  91.         }
  92.         if (strcmp(argv[i],"-F") == 0) {
  93.             i++;
  94.             sprintf(file_name,"%s",argv[i]);
  95.         }
  96.     }
  97.     
  98.     (void) model_init();
  99.  
  100.     /* read the parameters from a temorary file written by a main program */
  101.     sprintf(full_path,"%s/batch.inp%d",dir_name,batch_count);
  102.     ffp = fopen(full_path,"r");
  103.     if(ffp == NULL){
  104.         fclose(ffp);
  105.         return;
  106.     }
  107.  
  108.     if(fgets(lstring,big_length,ffp) != NULL){
  109.         sscanf(lstring,"%s",s_key);
  110.         if(strcmp(s_key,"%%T") ==0){
  111.             new_data_format = 0;
  112.             load_param(ffp);
  113.         }
  114.         else if(strcmp(s_key,"%%TS") == 0){
  115.             system_mess_proc(0,"Batch: Corrent starting header!");
  116.             new_data_format = 1;
  117.             load_param(ffp);
  118.             fscanf(ffp,"%s",s_key);
  119.             if(strcmp(s_key,"%%TE") ==0){
  120.                 system_mess_proc(0,"Batch: Correct ending header!");
  121.             }
  122.             else {
  123.                 fclose(ffp);
  124.                 sprintf(string,"Batch: Incorrent ending header ((%s))!",s_key);
  125.                 system_mess_proc(0,string);
  126.                 return;
  127.             }
  128.         }
  129.         else {
  130.             sprintf(string,"Batch: Nonstandard header (%s)!",s_key);
  131.             system_mess_proc(0,string);
  132.         }
  133.     }
  134.     fclose(ffp);
  135.     
  136.     system_mess_proc(0,"Batch: Read all parameters from a tempoaray file!");
  137.     sprintf(full_path,"%s/batch.tmp%d.%s",dir_name,batch_count,file_name);
  138.     ffp = fopen(full_path,"w");
  139.  
  140.     (void) orbit_colormap_init();
  141.     
  142.     if(!continue_toggle){
  143.         from_window_variables(t_v,win_var_i,polar_coord);
  144.         (void) get_func(func_i,win_var_i,param,time,polar_coord);
  145.     }
  146.     
  147.     /* two routines for map and ode, respectively */
  148.     if(mapping_on){
  149.         if (forward_toggle == 1){
  150.             i_stop = (int) map_forward();
  151.         }
  152.         else {
  153.             if(inverse_on){
  154.                 i_stop = (int) map_forward();
  155.             }
  156.             else {
  157.                 i_stop = (int) map_implicit_backward();
  158.             }
  159.         }
  160.     }
  161.     else {
  162.         if(int_driver == 0 || int_driver == 1){ 
  163.             if (forward_toggle == 1){
  164.                 i_stop = (int) ode_forward();
  165.             }
  166.             else {
  167.                 time_step = -time_step;
  168.                 i_stop = (int) ode_forward();
  169.                 time_step = -time_step;
  170.             }
  171.         }
  172.         else if(int_driver == 2){
  173.             if (forward_toggle == 1){
  174.                 i_stop = (int) ode_qc_forward();
  175.             }
  176.             else {
  177.                 time_step = -time_step;
  178.                 i_stop = (int) ode_qc_forward();
  179.                 time_step = -time_step;
  180.             }
  181.         }
  182.     }
  183.  
  184.     from_window_variables(t_v,win_var_f,polar_coord);
  185.     (void) get_func(func_f,t_v,param,time,var_dim);
  186.     if (section_count == 0)
  187.         average_return_time = -999;
  188.     else
  189.         average_return_time = time_step * i_stop / (double) section_count;
  190.     average_return_time = time_step * i_stop / (double) section_count;
  191.     fclose(ffp);
  192.     
  193.     sprintf(full_path,"%s/%s",dir_name,file_name);
  194.     ffp = fopen(full_path,"w");
  195.     /* save the key header */
  196.     if(new_data_format==1){
  197.         fprintf(ffp, "%%%%TS\n");
  198.     }
  199.     else if(new_data_format==0){
  200.         fprintf(ffp, "%%%%T\n");
  201.     }
  202.     save_param(ffp);
  203.     if(new_data_format==1){
  204.         fprintf(ffp, "%%%%TE\n");
  205.     }
  206.     else {
  207.     }
  208.  
  209.     fclose(ffp);
  210.     sprintf(lstring,"cat %s/batch.tmp%d.%s >> %s/%s; rm -f %s/batch.tmp%d.%s",dir_name,batch_count,file_name,dir_name,file_name,dir_name,batch_count,file_name);
  211.     system(lstring);
  212. }
  213.