Changeset 3243

Show
Ignore:
Timestamp:
01/06/12 16:30:58 (5 months ago)
Author:
jos
Message:

Strip trailing whitespace

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/share/mccode-r.c

    r3231 r3243  
    1616* Runtime system for McStas and McXtrace. 
    1717* Embedded within instrument in runtime mode. 
    18 * Contains SECTIONS:  
     18* Contains SECTIONS: 
    1919*   MPI handling (sum, send, recv) 
    2020*   format definitions 
     
    8282/* Instrument input parameter type handling. */ 
    8383/******************************************************************************* 
    84 * mcparm_double: extract double value from 's' into 'vptr'  
     84* mcparm_double: extract double value from 's' into 'vptr' 
    8585*******************************************************************************/ 
    8686static int 
     
    9999 
    100100/******************************************************************************* 
    101 * mcparminfo_double: display parameter type double  
     101* mcparminfo_double: display parameter type double 
    102102*******************************************************************************/ 
    103103static char * 
     
    108108 
    109109/******************************************************************************* 
    110 * mcparmerror_double: display error message when failed extract double  
     110* mcparmerror_double: display error message when failed extract double 
    111111*******************************************************************************/ 
    112112static void 
     
    118118 
    119119/******************************************************************************* 
    120 * mcparmprinter_double: convert double to string  
     120* mcparmprinter_double: convert double to string 
    121121*******************************************************************************/ 
    122122static void 
     
    128128 
    129129/******************************************************************************* 
    130 * mcparm_int: extract int value from 's' into 'vptr'  
     130* mcparm_int: extract int value from 's' into 'vptr' 
    131131*******************************************************************************/ 
    132132static int 
     
    150150 
    151151/******************************************************************************* 
    152 * mcparminfo_int: display parameter type int  
     152* mcparminfo_int: display parameter type int 
    153153*******************************************************************************/ 
    154154static char * 
     
    159159 
    160160/******************************************************************************* 
    161 * mcparmerror_int: display error message when failed extract int  
     161* mcparmerror_int: display error message when failed extract int 
    162162*******************************************************************************/ 
    163163static void 
     
    169169 
    170170/******************************************************************************* 
    171 * mcparmprinter_int: convert int to string  
     171* mcparmprinter_int: convert int to string 
    172172*******************************************************************************/ 
    173173static void 
     
    179179 
    180180/******************************************************************************* 
    181 * mcparm_string: extract char* value from 's' into 'vptr' (copy)  
     181* mcparm_string: extract char* value from 's' into 'vptr' (copy) 
    182182*******************************************************************************/ 
    183183static int 
     
    196196 
    197197/******************************************************************************* 
    198 * mcparminfo_string: display parameter type string  
     198* mcparminfo_string: display parameter type string 
    199199*******************************************************************************/ 
    200200static char * 
     
    205205 
    206206/******************************************************************************* 
    207 * mcparmerror_string: display error message when failed extract string  
     207* mcparmerror_string: display error message when failed extract string 
    208208*******************************************************************************/ 
    209209static void 
     
    215215 
    216216/******************************************************************************* 
    217 * mcparmprinter_string: convert string to string (including esc chars)  
     217* mcparmprinter_string: convert string to string (including esc chars) 
    218218*******************************************************************************/ 
    219219static void 
     
    266266 
    267267/******************************************************************************* 
    268 * mcestimate_error: compute sigma from N,p,p2 in Gaussian large numbers approx  
     268* mcestimate_error: compute sigma from N,p,p2 in Gaussian large numbers approx 
    269269*******************************************************************************/ 
    270270double mcestimate_error(double N, double p1, double p2) 
     
    281281 
    282282double (*mcestimate_error_p) 
    283   (double V2, double psum, double p2sum)=mcestimate_error;  
     283  (double V2, double psum, double p2sum)=mcestimate_error; 
    284284 
    285285/* SECTION: MPI handling ==================================================== */ 
     
    296296int mc_MPI_Sum(double *sbuf, long count) 
    297297{ 
    298    
     298 
    299299  if (!sbuf || count <= 0) return(MPI_ERR_COUNT); 
    300300  else { 
     
    305305    int    i=0; 
    306306    while (offset < count) { 
    307       if (!length || offset+length > count-1) length=count-offset;  
     307      if (!length || offset+length > count-1) length=count-offset; 
    308308      else length=MPI_REDUCE_BLOCKSIZE; 
    309       MPI_Allreduce((double*)(sbuf+offset), (double*)(rbuf+offset),  
     309      MPI_Allreduce((double*)(sbuf+offset), (double*)(rbuf+offset), 
    310310              length, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); 
    311311      offset += length; 
    312312    } 
    313      
     313 
    314314    for (i=0; i<count; i++) sbuf[i] = rbuf[i]; 
    315315  } 
     
    320320* mc_MPI_Send: Send array to MPI node by blocks to avoid buffer limit 
    321321*******************************************************************************/ 
    322 int mc_MPI_Send(void *sbuf,  
     322int mc_MPI_Send(void *sbuf, 
    323323                  long count, MPI_Datatype dtype, 
    324324                  int dest) 
     
    328328  int  tag=1; 
    329329  int  length=MPI_REDUCE_BLOCKSIZE; /* defined in mcstas.h */ 
    330    
     330 
    331331  if (!sbuf || count <= 0) return(MPI_ERR_COUNT); 
    332332  MPI_Type_size(dtype, &dsize); 
    333333 
    334334  while (offset < count) { 
    335     if (offset+length > count-1) length=count-offset;  
     335    if (offset+length > count-1) length=count-offset; 
    336336    else length=MPI_REDUCE_BLOCKSIZE; 
    337337    MPI_Send((void*)(sbuf+offset*dsize), length, dtype, dest, tag++, MPI_COMM_WORLD); 
     
    346346*             the buffer must have been allocated previously. 
    347347*******************************************************************************/ 
    348 int mc_MPI_Recv(void *sbuf,  
     348int mc_MPI_Recv(void *sbuf, 
    349349                  long count, MPI_Datatype dtype, 
    350350                  int source) 
     
    354354  int  tag=1; 
    355355  int  length=MPI_REDUCE_BLOCKSIZE; /* defined in mcstas.h */ 
    356    
     356 
    357357  if (!sbuf || count <= 0) return(MPI_ERR_COUNT); 
    358358  MPI_Type_size(dtype, &dsize); 
    359359 
    360360  while (offset < count) { 
    361     if (offset+length > count-1) length=count-offset;  
     361    if (offset+length > count-1) length=count-offset; 
    362362    else length=MPI_REDUCE_BLOCKSIZE; 
    363     MPI_Recv((void*)(sbuf+offset*dsize), length, dtype, source, tag++,  
     363    MPI_Recv((void*)(sbuf+offset*dsize), length, dtype, source, tag++, 
    364364            MPI_COMM_WORLD, MPI_STATUS_IGNORE); 
    365365    offset += length; 
     
    385385*******************************************************************************/ 
    386386 
    387 /* {Name, Extension, Header, Footer,  
     387/* {Name, Extension, Header, Footer, 
    388388    BeginSection, EndSection, AssignTag; 
    389389    BeginData, EndData; 
     
    10131013  int   dirlen=0; 
    10141014  char *mem   =NULL; 
    1015    
     1015 
    10161016  dirlen = mcdirname ? strlen(mcdirname) : 0; 
    10171017  mem = malloc(dirlen + strlen(name) + CHAR_BUF_LENGTH); 
     
    10201020  } 
    10211021  strcpy(mem, ""); 
    1022    
     1022 
    10231023  /* prepend directory name to path if name does not contain a path */ 
    10241024  if (dirlen > 0 && !strchr(name, MC_PATHSEP_C)) { 
     
    10261026    strcat(mem, MC_PATHSEP_S); 
    10271027  } /* dirlen */ 
    1028    
     1028 
    10291029  strcat(mem, name); 
    10301030  if (!strchr(name, '.') && ext && strlen(ext)) 
     
    10521052    fprintf(stderr, "Warning: could not open output file '%s' in mode '%s' (mcnew_file)\n", mem, mode); 
    10531053  else { 
    1054     if (!mcopenedfiles ||  
     1054    if (!mcopenedfiles || 
    10551055        (mcopenedfiles && mcopenedfiles_size <= strlen(mcopenedfiles)+strlen(mem))) { 
    10561056      mcopenedfiles_size+=CHAR_BUF_LENGTH; 
     
    10591059      else 
    10601060        mcopenedfiles = realloc(mcopenedfiles, mcopenedfiles_size); 
    1061     }  
     1061    } 
    10621062    strcat(mcopenedfiles, " "); 
    10631063    strcat(mcopenedfiles, mem); 
    10641064  } 
    10651065  free(mem); 
    1066    
     1066 
    10671067  return file; 
    10681068} /* mcnew_file */ 
     
    11231123 
    11241124/******************************************************************************* 
    1125 * pfprintf: just as fprintf with positional arguments %N$t,  
     1125* pfprintf: just as fprintf with positional arguments %N$t, 
    11261126*   but with (char *)fmt_args being the list of arg type 't'. 
    11271127*   Needed as the vfprintf is not correctly handled on some platforms. 
     
    11691169      { /* found a dollar following a percent  and a digit after percent */ 
    11701170        char  this_arg_chr[10]; 
    1171          
     1171 
    11721172 
    11731173        /* extract positional argument index %*$ in fmt */ 
     
    11931193        } else if (strchr(printf_formats,tmp[1])) { 
    11941194          fmt_pos = arg_posB[this_arg]+1;  /* found %s */ 
    1195         } else {  
     1195        } else { 
    11961196          return(-fprintf(stderr,"pfprintf: must use only positional arguments (%s).\n", arg_posB[this_arg])); 
    11971197        } 
     
    12941294  char date[CHAR_BUF_LENGTH]; /* date as a string */ 
    12951295  char valid_parent[VALID_NAME_LENGTH];     /* who generates that: the simulation or mcstas */ 
    1296    
     1296 
    12971297  if (mcdisable_output_files) return(-1); 
    12981298  if (!detector.file_handle && !strstr(detector.format.Name,"NeXus")) return(-1); 
    12991299  if (strcmp(part,"header") && strstr(detector.format.Name, "no header")) return (-2); 
    13001300  if (strcmp(part,"footer") && strstr(detector.format.Name, "no footer")) return (-3); 
    1301    
     1301 
    13021302  /* initiate date and format string ======================================== */ 
    1303    
     1303 
    13041304  date_l = detector.date_l;   /* use current write time (from import) by default */ 
    13051305  strncpy(date, detector.date, CHAR_BUF_LENGTH); 
     
    13091309  else { 
    13101310    HeadFoot = detector.format.Header; /* SIM header has simulation start time */ 
    1311     if (detector.file_handle == mcsiminfo_file  
     1311    if (detector.file_handle == mcsiminfo_file 
    13121312        && !strcmp(detector.filename, mcsiminfo_name)) { 
    13131313      date_l = mcstartdate; 
     
    13181318  } 
    13191319 
    1320   mcvalid_name(valid_parent,  
     1320  mcvalid_name(valid_parent, 
    13211321    strlen(detector.filename) && detector.file_handle!=mcsiminfo_file ? 
    13221322      detector.filename : detector.simulation, VALID_NAME_LENGTH); 
    1323      
     1323 
    13241324  /* output header ========================================================== */ 
    13251325 
     
    13291329      detector.prefix,                          /* %1$s  PRE  */ 
    13301330      detector.instrument,                      /* %2$s  SRC  */ 
    1331       strlen(detector.filename) ?  
     1331      strlen(detector.filename) ? 
    13321332        detector.filename: detector.simulation, /* %3$s  FIL  */ 
    13331333      detector.format.Name,                     /* %4$s  FMT  */ 
     
    13371337      detector.date_l) == NX_ERROR) {           /* %8$li DATL */ 
    13381338        fprintf(stderr, "Error: writing NeXus header file %s (mcinfo_header)\n", 
    1339           strlen(detector.filename) ?  
     1339          strlen(detector.filename) ? 
    13401340            detector.filename: detector.simulation); 
    13411341        /* close information data set opened by mcnxfile_section */ 
    13421342      return(-1); 
    1343     }  
     1343    } 
    13441344    else return(1); 
    13451345  } 
     
    13491349    detector.prefix,                          /* %1$s  PRE  */ 
    13501350    detector.instrument,                      /* %2$s  SRC  */ 
    1351     strlen(detector.filename) ?  
     1351    strlen(detector.filename) ? 
    13521352      detector.filename: detector.simulation, /* %3$s  FIL  */ 
    13531353    detector.format.Name,                     /* %4$s  FMT  */ 
     
    13791379 
    13801380  /* remove quote chars in values =========================================== */ 
    1381   if (strstr(detector.format.Name, "Scilab")  
    1382    || strstr(detector.format.Name, "Matlab")  
     1381  if (strstr(detector.format.Name, "Scilab") 
     1382   || strstr(detector.format.Name, "Matlab") 
    13831383   || strstr(detector.format.Name, "IDL")) 
    13841384    for(i = 0; i < strlen(value); i++) { 
     
    13861386      if (value[i] == '\n'  || value[i] == '\r') value[i] = ';'; 
    13871387    } 
    1388      
     1388 
    13891389  /* output tag ============================================================= */ 
    13901390#ifdef USE_NEXUS 
     
    14341434  else                                strcpy(valid_parent, "root"); 
    14351435 
    1436   if (!strcmp(part,"end") && strlen(detector.prefix) >= 2)  
     1436  if (!strcmp(part,"end") && strlen(detector.prefix) >= 2) 
    14371437    detector.prefix[strlen(detector.prefix)-2]='\0'; /* un-indent prefix */ 
    1438      
     1438 
    14391439  /* output section ========================================================= */ 
    14401440 
     
    14451445      fprintf(stderr, "Error: writing NeXus section %s/%s=NX%s (mcfile_section)\n", parent, section, type); 
    14461446      return(detector); 
    1447     }  
     1447    } 
    14481448  } 
    14491449  else 
     
    14571457    valid_parent,   /* %6$s  VPA  */ 
    14581458    level);         /* %7$i  LVL */ 
    1459      
     1459 
    14601460  /* handle prefix++ and write section start ID ============================= */ 
    14611461 
     
    14981498    if (strlen(Parameters) >= CHAR_BUF_LENGTH-VALID_NAME_LENGTH) break; 
    14991499  } 
    1500    
     1500 
    15011501  /* output data ============================================================ */ 
    15021502  mcinfo_tag(detector, name, "Parameters",    Parameters); 
     
    15341534      char nxname[CHAR_BUF_LENGTH]; 
    15351535      int length; 
    1536       if (mcinputtable[i].par == NULL)  
     1536      if (mcinputtable[i].par == NULL) 
    15371537        strncpy(Parameters, (mcinputtable[i].val ? mcinputtable[i].val : ""), CHAR_BUF_LENGTH); 
    1538       else  
     1538      else 
    15391539        (*mcinputtypes[mcinputtable[i].type].printer)(Parameters, mcinputtable[i].par); 
    15401540      sprintf(nxname, "%s", Parameters); 
     
    15741574  snprintf(Parameters, CHAR_BUF_LENGTH, "%ld", mcseed); 
    15751575  mcinfo_tag(detector, instr, "Seed", Parameters); 
    1576    
     1576 
    15771577  /* output parameter string ================================================ */ 
    15781578  if (!strstr(detector.format.Name, "McStas")) { 
    1579 #ifdef USE_NEXUS     
     1579#ifdef USE_NEXUS 
    15801580    /* close simulation/information */ 
    15811581    if (strstr(detector.format.Name, "NeXus")) 
    15821582    if (NXclosedata(mcnxHandle) == NX_ERROR) 
    15831583      fprintf(stderr, "Warning: NeXus: could not close data set simulation/information in %s\n", detector.filename); 
    1584 #endif       
     1584#endif 
    15851585    detector = mcfile_section(detector, "begin", instr, "parameters", "parameters", 3); 
    15861586  } 
    1587    
     1587 
    15881588  for(i = 0; i < mcnumipar; i++) { 
    15891589    if (mcget_run_num() || (mcinputtable[i].val && strlen(mcinputtable[i].val))) { 
    1590       if (mcinputtable[i].par == NULL)  
     1590      if (mcinputtable[i].par == NULL) 
    15911591        strncpy(Parameters, (mcinputtable[i].val ? mcinputtable[i].val : ""), CHAR_BUF_LENGTH); 
    1592       else  
     1592      else 
    15931593        (*mcinputtypes[mcinputtable[i].type].printer)(Parameters, mcinputtable[i].par); 
    1594       if (strstr(detector.format.Name, "McStas"))  
     1594      if (strstr(detector.format.Name, "McStas")) 
    15951595        fprintf(detector.file_handle, "%sParam: %s=%s\n", detector.prefix, mcinputtable[i].name, Parameters); 
    15961596      else 
     
    16051605    /* in the parameter group, create one SDS per parameter */ 
    16061606    mcnxfile_parameters(mcnxHandle); 
    1607      
    1608     /* this can not be included in nexus-lib as it requires mcinputtypes which  
     1607 
     1608    /* this can not be included in nexus-lib as it requires mcinputtypes which 
    16091609      is defined only in mccode-r.c (points to function that are defined here) */ 
    1610      
    1611      
     1610 
     1611 
    16121612    /* re-open the simulation/information dataset */ 
    16131613    if (NXopendata(mcnxHandle, "information") == NX_ERROR) { 
     
    16161616  } 
    16171617#endif 
    1618   if (!strstr(detector.format.Name, "McStas"))  
     1618  if (!strstr(detector.format.Name, "McStas")) 
    16191619    detector = mcfile_section(detector, "end", instr, "parameters", "parameters", 3); 
    1620      
     1620 
    16211621  fflush(NULL); 
    16221622 
     
    16331633{ 
    16341634  char parent[CHAR_BUF_LENGTH]; 
    1635    
     1635 
    16361636  if (!detector.m || mcdisable_output_files) return; 
    16371637 
     
    16441644    if (!detector.file_handle) return; 
    16451645  } 
    1646    
     1646 
    16471647  /* parent must be a valid name */ 
    16481648  mcvalid_name(parent, detector.filename, VALID_NAME_LENGTH); 
    1649    
     1649 
    16501650  /* output data ============================================================ */ 
    16511651  mcinfo_tag(detector, parent, "type",       detector.type); 
    16521652  mcinfo_tag(detector, parent, "Source",     mcinstrument_source); 
    1653   mcinfo_tag(detector, parent, (strstr(detector.format.Name,"McStas") ?  
     1653  mcinfo_tag(detector, parent, (strstr(detector.format.Name,"McStas") ? 
    16541654        "component" : "parent"),             detector.component); 
    16551655  mcinfo_tag(detector, parent, "position",   detector.position); 
    16561656 
    16571657  mcinfo_tag(detector, parent, "title",      detector.title); 
    1658   mcinfo_tag(detector, parent, !mcget_run_num() || mcget_run_num() >= mcget_ncount() ?  
     1658  mcinfo_tag(detector, parent, !mcget_run_num() || mcget_run_num() >= mcget_ncount() ? 
    16591659      "Ncount" : "ratio",      detector.ncount); 
    1660      
     1660 
    16611661  if (strlen(detector.filename)) { 
    16621662    mcinfo_tag(detector, parent, "filename", detector.filename); 
     
    16651665 
    16661666  mcinfo_tag(detector, parent, "statistics", detector.statistics); 
    1667   mcinfo_tag(detector, parent, strstr(detector.format.Name, "NeXus") ?  
     1667  mcinfo_tag(detector, parent, strstr(detector.format.Name, "NeXus") ? 
    16681668       "Signal" : "signal",                  detector.signal); 
    16691669  mcinfo_tag(detector, parent, "values",     detector.values); 
     
    16711671  if (detector.rank >= 1 || detector.rank == -1) 
    16721672  { 
    1673     mcinfo_tag(detector, parent, (strstr(detector.format.Name," scan ") ?  
     1673    mcinfo_tag(detector, parent, (strstr(detector.format.Name," scan ") ? 
    16741674          "xvars" : "xvar"),                 detector.xvar); 
    1675     mcinfo_tag(detector, parent, (strstr(detector.format.Name," scan ") ?  
     1675    mcinfo_tag(detector, parent, (strstr(detector.format.Name," scan ") ? 
    16761676          "yvars" : "yvar"),                 detector.yvar); 
    16771677    mcinfo_tag(detector, parent, "xlabel",   detector.xlabel); 
     
    16831683  } 
    16841684 
    1685   mcinfo_tag(detector, parent, abs(detector.rank)==1 && strstr(detector.format.Name, "McStas") ?  
     1685  mcinfo_tag(detector, parent, abs(detector.rank)==1 && strstr(detector.format.Name, "McStas") ? 
    16861686                    "xlimits" : "xylimits", detector.limits); 
    16871687  mcinfo_tag(detector, parent, "variables", detector.rank == -1 ? 
    16881688                                            detector.zvar : detector.variables); 
    1689        
     1689 
    16901690   if (mcDetectorCustomHeader && strlen(mcDetectorCustomHeader)) { 
    16911691     mcinfo_tag(detector, parent, "custom",  mcDetectorCustomHeader); 
    1692    }  
     1692   } 
    16931693 
    16941694   fflush(NULL); 
     
    17181718  char   istransposed=0; 
    17191719  char   c[CHAR_BUF_LENGTH]; /* temp var for signal label */ 
    1720    
     1720 
    17211721  MCDETECTOR detector; 
    17221722 
    17231723  /* build MCDETECTOR structure ============================================= */ 
    17241724  /* make sure we do not have NULL for char fields */ 
    1725    
     1725 
    17261726  /* these also apply to simfile */ 
    17271727  strncpy (detector.filename,  filename ? filename : "",    CHAR_BUF_LENGTH); 
     
    17321732    strcat(detector.filename, format.Extension); 
    17331733  } 
    1734   strncpy (detector.component, component ? component : "McStas component", CHAR_BUF_LENGTH);  
     1734  strncpy (detector.component, component ? component : "McStas component", CHAR_BUF_LENGTH); 
    17351735  snprintf(detector.simulation, CHAR_BUF_LENGTH, "%s%s%s", 
    17361736      mcdirname && strlen(mcdirname) ? mcdirname : ".", MC_PATHSEP_S, mcsiminfo_name); 
    17371737  detector.format=format; 
    1738    
     1738 
    17391739  /* set prefix: # for McStas data files, VRML and Python */ 
    1740   strcpy(detector.prefix,  
    1741       (strstr(format.Name, "McStas") && (strlen(detector.filename)) ?  
     1740  strcpy(detector.prefix, 
     1741      (strstr(format.Name, "McStas") && (strlen(detector.filename)) ? 
    17421742      "# " : "")); 
    1743    
     1743 
    17441744  snprintf(detector.instrument, CHAR_BUF_LENGTH, "%s (%s)", mcinstrument_name, mcinstrument_source); 
    17451745  snprintf(detector.user, CHAR_BUF_LENGTH,      "%s on %s", 
     
    17511751  if (strlen(detector.date))   detector.date[strlen(detector.date)-1] = '\0'; /* remove last \n in date */ 
    17521752  detector.date_l = date_l; 
    1753    
     1753 
    17541754  if (!mcget_run_num() || mcget_run_num() >= mcget_ncount()) 
    17551755    snprintf(detector.ncount, CHAR_BUF_LENGTH, "%g", (double)mcget_ncount()); 
    1756   else  
     1756  else 
    17571757    snprintf(detector.ncount, CHAR_BUF_LENGTH, "%g/%g", (double)mcget_run_num(), (double)mcget_ncount()); 
    1758      
     1758 
    17591759  detector.p0         = p0; detector.p0_orig=p0; 
    17601760  detector.p1         = p1; detector.p1_orig=p1; 
    17611761  detector.p2         = p2; detector.p2_orig=p2; 
    17621762  detector.file_handle= filename ? NULL : mcsiminfo_file; 
    1763    
     1763 
    17641764  /* handle transposition */ 
    17651765  if (!strstr(format.Name, "NeXus")) { 
     
    17701770      long i=m; m=abs(n); n=abs(i); p=abs(p); 
    17711771    } 
    1772   }  
     1772  } 
    17731773  m=abs(m); n=abs(n); p=abs(p); /* make sure dimensions are positive */ 
    17741774  detector.istransposed = istransposed; 
    1775    
     1775 
    17761776  /* determine detector rank (dimensionality) */ 
    17771777  if (!m || !n || !p || !p1) detector.rank = 4; /* invalid: exit with m=0 filename="" */ 
     
    17811781  else if (p == 1)           detector.rank = 2; /* 2D */ 
    17821782  else                       detector.rank = 3; /* 3D */ 
    1783    
     1783 
    17841784  /* from rank, set type */ 
    17851785  switch (detector.rank) { 
     
    17911791    default: m=0; strcpy(detector.type, ""); strcpy(detector.filename, "");/* invalid */ 
    17921792  } 
    1793    
     1793 
    17941794  detector.m    = m; 
    17951795  detector.n    = n; 
     
    18071807  detector.centerY    = 0; 
    18081808  detector.halfwidthY = 0; 
    1809    
     1809 
    18101810  /* these only apply to detector files ===================================== */ 
    18111811 
     
    18311831  else 
    18321832    snprintf(detector.variables, CHAR_BUF_LENGTH, "%s %s_err N", c, c); 
    1833    
     1833 
    18341834  /* limits */ 
    18351835  detector.xmin = x1; 
     
    18451845  else 
    18461846    snprintf(detector.limits, CHAR_BUF_LENGTH, "%g %g %g %g %g %g", x1, x2, y1, y2, z1, z2); 
    1847    
    1848   if (!m || !n || !p) {  
     1847 
     1848  if (!m || !n || !p) { 
    18491849    return(detector); 
    18501850  } 
    1851    
     1851 
    18521852  /* if MPI and nodes_nb > 1: reduce data sets when using MPI =============== */ 
    18531853  /* not for scan steps/multiarray (only processed by root */ 
     
    18581858    if (p1) mc_MPI_Sum(p1, abs(m*n*p)); 
    18591859    if (p2) mc_MPI_Sum(p2, abs(m*n*p)); 
    1860      
     1860 
    18611861    if (!p0) {  /* additive signal must be then divided by the number of nodes */ 
    18621862      int i; 
     
    18761876  double Nsum=0; 
    18771877  double P2sum=0; 
    1878    
     1878 
    18791879  double sum_xz  = 0; 
    18801880  double sum_yz  = 0; 
     
    18881888  char   israw = (strstr(detector.format.Name," raw") != NULL); 
    18891889  double *this_p1=NULL; /* new 1D McStas array [x I E N]. Freed after writing data */ 
    1890    
     1890 
    18911891  /* if McStas/PGPLOT and rank==1 we create a new m*4 data block=[x I E N] */ 
    18921892  if (detector.rank == 1 && strstr(detector.format.Name,"McStas")) { 
     
    18951895      exit(-fprintf(stderr, "Error: Out of memory creating %li 1D McStas data set for file '%s' (mcdetector_import)\n", detector.m*detector.n*detector.p*4*sizeof(double*), detector.filename)); 
    18961896  } 
    1897    
     1897 
    18981898  max_z = min_z = p1[0]; 
    1899    
     1899 
    19001900  for(j = 0; j < n*p; j++) 
    19011901  { 
     
    19121912      E = p2 ? p2[index] : 0; 
    19131913      if (p2 && !israw) p2[index] = (*mcestimate_error_p)(p0[i],p1[i],p2[i]); /* set sigma */ 
    1914        
     1914 
    19151915      /* compute stats integrals */ 
    19161916      sum_xz += x*z; 
     
    19261926      Nsum += N; 
    19271927      P2sum += E; 
    1928        
     1928 
    19291929      if (isnan(z) || isnan(E) || isnan(N)) hasnan=1; 
    19301930      if (isinf(z) || isinf(E) || isinf(N)) hasinf=1; 
    1931        
     1931 
    19321932      if (detector.rank == 1 && this_p1 && strstr(detector.format.Name,"McStas")) { 
    19331933        /* fill-in 1D McStas array [x I E N] */ 
    1934         this_p1[index*4]   = x;  
     1934        this_p1[index*4]   = x; 
    19351935        this_p1[index*4+1] = z; 
    19361936        this_p1[index*4+2] = p2 ? p2[index] : 0; 
     
    19391939    } 
    19401940  } /* for j */ 
    1941    
     1941 
    19421942  /* compute 1st and 2nd moments */ 
    19431943  if (sum_z && n*m*p) 
     
    19601960  detector.centerY   = fmon_y; 
    19611961  detector.halfwidthY= smon_y; 
    1962    
     1962 
    19631963  /* if McStas/PGPLOT and rank==1 replace p1 with new m*4 1D McStas and clear others */ 
    19641964  if (detector.rank == 1 && this_p1 && strstr(detector.format.Name,"McStas")) { 
    19651965    detector.p1 = this_p1; 
    1966     detector.n=detector.m; detector.m  = 4;  
     1966    detector.n=detector.m; detector.m  = 4; 
    19671967    detector.p0 = NULL; 
    19681968    detector.p2 = NULL; 
    19691969    detector.istransposed = 1; 
    19701970  } 
    1971    
     1971 
    19721972  if (n*m*p > 1) 
    19731973    sprintf(detector.signal, "Min=%g; Max=%g; Mean=%g;", detector.min, detector.max, detector.mean); 
    1974   else  
     1974  else 
    19751975    strcpy(detector.signal, ""); 
    19761976  sprintf(detector.values, "%g %g %g", detector.intensity, detector.error, detector.events); 
    1977    
     1977 
    19781978  switch (detector.rank) { 
    19791979    case 0:  strcpy(detector.statistics, ""); break; 
    1980     case 1:  snprintf(detector.statistics, CHAR_BUF_LENGTH, "X0=%g; dX=%g;",  
     1980    case 1:  snprintf(detector.statistics, CHAR_BUF_LENGTH, "X0=%g; dX=%g;", 
    19811981      detector.centerX, detector.halfwidthX); break; 
    19821982    case 2: 
    1983     case 3:  snprintf(detector.statistics, CHAR_BUF_LENGTH, "X0=%g; dX=%g; Y0=%g; dY=%g;",  
    1984       detector.centerX, detector.halfwidthX, detector.centerY, detector.halfwidthY);  
     1983    case 3:  snprintf(detector.statistics, CHAR_BUF_LENGTH, "X0=%g; dX=%g; Y0=%g; dY=%g;", 
     1984      detector.centerX, detector.halfwidthX, detector.centerY, detector.halfwidthY); 
    19851985      break; 
    19861986    default: strcpy(detector.statistics, ""); 
     
    19931993  } 
    19941994#endif 
    1995    
     1995 
    19961996  /* output "Detector:" line ================================================ */ 
    1997   /* when this is a detector written by a component (not the SAVE from instrument),  
     1997  /* when this is a detector written by a component (not the SAVE from instrument), 
    19981998     not a multiarray nor event lists */ 
    19991999  if (detector.rank == -1 || strstr(format.Name," list ")) return(detector); 
    2000    
     2000 
    20012001  if (!strcmp(detector.component, mcinstrument_name)) { 
    20022002    if (strlen(detector.filename))  /* we name it from its filename, or from its title */ 
     
    20062006  } else 
    20072007    strncpy(c, detector.component, CHAR_BUF_LENGTH);  /* usual detectors written by components */ 
    2008      
     2008 
    20092009  printf("Detector: %s_I=%g %s_ERR=%g %s_N=%g", 
    2010          c, detector.intensity,  
    2011          c, detector.error,  
     2010         c, detector.intensity, 
     2011         c, detector.error, 
    20122012         c, detector.events); 
    20132013  printf(" \"%s\"\n", strlen(detector.filename) ? detector.filename : detector.component); 
    2014    
    2015   if (hasnan)  
     2014 
     2015  if (hasnan) 
    20162016    printf("WARNING: Nan detected in component %s\n", detector.component); 
    2017   if (hasinf)  
     2017  if (hasinf) 
    20182018    printf("WARNING: Inf detected in component %s\n", detector.component); 
    2019      
     2019 
    20202020  /* add warning in case of low statistics or large number of bins in text format mode */ 
    2021   if (detector.error > detector.intensity/4)  
     2021  if (detector.error > detector.intensity/4) 
    20222022    printf("WARNING: file '%s': Low Statistics\n",    detector.filename); 
    20232023  else if (strlen(detector.filename)) { 
    2024     if (m*n*p > 1000 && Nsum < m*n*p && Nsum)  
     2024    if (m*n*p > 1000 && Nsum < m*n*p && Nsum) 
    20252025       printf( 
    20262026        "WARNING: file '%s': Low Statistics (%g events in %ldx%ldx%ld bins).\n", 
     
    20342034        detector.filename, format.Name, m,n,p); 
    20352035  } 
    2036    
     2036 
    20372037  if (mcDetectorCustomHeader && strlen(mcDetectorCustomHeader)) { 
    20382038   if (strstr(detector.format.Name, "Octave") || strstr(detector.format.Name, "Matlab")) 
     
    20562056#ifdef USE_MPI 
    20572057  /* only for Master */ 
    2058   if(mpi_node_rank != mpi_node_root)                      return(NULL);  
     2058  if(mpi_node_rank != mpi_node_root)                      return(NULL); 
    20592059#endif 
    20602060 
    20612061  if (detector.m) { 
    20622062    /* add detector entry in the mcDetectorArray */ 
    2063     if (!mcDetectorArray ||  
     2063    if (!mcDetectorArray || 
    20642064        (mcDetectorArray && mcDetectorArray_size <= mcDetectorArray_index)) { 
    20652065      mcDetectorArray_size+=CHAR_BUF_LENGTH; 
     
    20732073 
    20742074  return(mcDetectorArray); 
    2075      
     2075 
    20762076} /* mcdetector_register */ 
    20772077 
     
    20832083MCDETECTOR mcdetector_import_sim(void) { 
    20842084  Coords zero={0.0,0.0,0.0}; 
    2085   MCDETECTOR detector=mcdetector_import(mcformat, "mcstas", NULL,  
     2085  MCDETECTOR detector=mcdetector_import(mcformat, "mcstas", NULL, 
    20862086    0,0,0,            /* mnp */ 
    20872087    NULL, NULL, NULL, /* labels */ 
     
    21042104static int mcsiminfo_init(FILE *f) 
    21052105{ 
    2106    
     2106 
    21072107#ifdef USE_MPI 
    21082108  /* only for Master */ 
    2109   if(mpi_node_rank != mpi_node_root)                      return(-1);  
     2109  if(mpi_node_rank != mpi_node_root)                      return(-1); 
    21102110#endif 
    21112111  if (mcdisable_output_files)                             return(-2); 
     
    21142114  /* clear list of opened files to start new save session */ 
    21152115  if (mcopenedfiles && strlen(mcopenedfiles) > 0) strcpy(mcopenedfiles, ""); 
    2116    
     2116 
    21172117  /* open sim file ========================================================== */ 
    2118    
     2118 
    21192119#ifdef USE_NEXUS 
    21202120  /* NeXus sim info is the NeXus root file. */ 
     
    21352135    else mcsiminfo_file = f; 
    21362136  } 
    2137    
     2137 
    21382138  if(!mcsiminfo_file) 
    21392139    return(-fprintf(stderr, 
    21402140            "Warning: could not open simulation description file '%s' (mcsiminfo_init)\n", 
    21412141            mcsiminfo_name)); 
    2142    
     2142 
    21432143  /* initialize sim file information, sets detector.file_handle=mcsiminfo_file */ 
    21442144  MCDETECTOR mcsiminfo = mcdetector_import_sim(); 
    2145    
     2145 
    21462146  /* flag true for McStas or NX data format */ 
    2147   int  ismcstas_nx= (strstr(mcformat.Name, "McStas") || strstr(mcformat.Name, "NeXus"));  
    2148    
     2147  int  ismcstas_nx= (strstr(mcformat.Name, "McStas") || strstr(mcformat.Name, "NeXus")); 
     2148 
    21492149  /* start to write meta data =============================================== */ 
    21502150 
     
    21682168  mcsiminfo = mcfile_section(mcsiminfo, "begin", mcsiminfo.simulation, mcinstrument_name, "instrument", 1); 
    21692169  mcinfo_instrument(mcsiminfo, mcinstrument_name); 
    2170    
     2170 
    21712171#ifdef USE_NEXUS 
    21722172  if (strstr(mcformat.Name, "NeXus")) { 
     
    21842184  mcsiminfo = mcfile_section(mcsiminfo, "begin", mcsiminfo.simulation, mcsiminfo_name, "simulation", 2); 
    21852185  mcsiminfo = mcinfo_simulation(mcsiminfo, mcsiminfo_name); 
    2186    
     2186 
    21872187#ifdef USE_NEXUS 
    21882188  /* close information SDS opened with mcfile_section(siminfo,"simulation") */ 
     
    22122212 
    22132213  mcdetector_write_content(mcDetectorArray, mcDetectorArray_index); 
    2214    
     2214 
    22152215  /* initialize sim file information, sets detector.file_handle=mcsiminfo_file */ 
    22162216  MCDETECTOR mcsiminfo = mcdetector_import_sim(); 
    2217    
     2217 
    22182218  /* close those sections which were opened in mcsiminfo_init =============== */ 
    2219   if (!ismcstas_nx) {  
     2219  if (!ismcstas_nx) { 
    22202220    mcfile_section(mcsiminfo, "end", mcsiminfo.simulation, mcsiminfo_name, "simulation", 2); 
    22212221    mcfile_section(mcsiminfo, "end", mcsiminfo.simulation, mcinstrument_name, "instrument", 1); 
     
    22342234    mcfile_section(mcsiminfo, "end", "mcstas", mcinstrument_name, "entry", 1); 
    22352235  } 
    2236 #endif   
    2237    
     2236#endif 
     2237 
    22382238  /* close sim file ========================================================= */ 
    22392239#ifdef USE_NEXUS 
     
    22622262  char    valid_zlabel[VALID_NAME_LENGTH]; 
    22632263  char    valid_parent[VALID_NAME_LENGTH]; 
    2264    
     2264 
    22652265  if (strstr(part,"data")) 
    22662266  { this_p1=detector.p1; Begin = detector.format.BeginData; End = detector.format.EndData; } 
     
    22692269  if (strstr(part,"ncount") || strstr(part,"events")) 
    22702270  { this_p1=detector.p0;Begin = detector.format.BeginNcount; End = detector.format.EndNcount; } 
    2271    
     2271 
    22722272  if (!this_p1 || mcdisable_output_files) return(-1); 
    22732273  if (!detector.file_handle && !strstr(detector.format.Name,"NeXus")) return(-1); 
    22742274  if (!detector.rank) return(-1); 
    22752275 
    2276    
     2276 
    22772277  mcvalid_name(valid_xlabel, detector.xlabel, VALID_NAME_LENGTH); 
    22782278  mcvalid_name(valid_ylabel, detector.ylabel, VALID_NAME_LENGTH); 
    22792279  mcvalid_name(valid_zlabel, detector.zlabel, VALID_NAME_LENGTH); 
    22802280  mcvalid_name(valid_parent, detector.filename, VALID_NAME_LENGTH); 
    2281    
     2281 
    22822282  /* output Begin =========================================================== */ 
    2283   if (!strstr(detector.format.Name,"NeXus")  
     2283  if (!strstr(detector.format.Name,"NeXus") 
    22842284   && (!strstr(detector.format.Name,"binary") || strstr(part,"empty array")) 
    22852285   && !strstr(detector.format.Name,"no header")) 
     
    23072307      detector.zmin,         /* %21$g  ZMIN */ 
    23082308      detector.zmax);        /* %22$g  ZMAX */ 
    2309    
     2309 
    23102310  /* output array */ 
    23112311  if (strstr(part,"empty array")) { 
    23122312    /* skip array output: set as empty */ 
    2313      
     2313 
    23142314    /* special case of IDL: can not have empty vectors. Init to 'external' */ 
    23152315    if (strstr(detector.format.Name, "IDL")) fprintf(detector.file_handle, "'external'"); 
    23162316  } else { 
    2317 #ifdef USE_NEXUS   
     2317#ifdef USE_NEXUS 
    23182318    /* array NeXus ========================================================== */ 
    23192319    if (strstr(detector.format.Name,"NeXus")) { 
    2320       if(mcnxfile_data(mcnxHandle, detector, part,  
     2320      if(mcnxfile_data(mcnxHandle, detector, part, 
    23212321        valid_parent, valid_xlabel, valid_ylabel, valid_zlabel) == NX_ERROR) { 
    23222322        fprintf(stderr, "Error: writing NeXus data %s/%s (mcfile_data)\n", valid_parent, detector.filename); 
     
    23252325      return(1); 
    23262326    } /* end if NeXus */ 
    2327 #endif     
     2327#endif 
    23282328    /* array non binary (text) ============================================== */ 
    2329     if (!strstr(detector.format.Name, "binary")  
    2330      && !strstr(detector.format.Name, "float") && !strstr(detector.format.Name, "double"))  
     2329    if (!strstr(detector.format.Name, "binary") 
     2330     && !strstr(detector.format.Name, "float") && !strstr(detector.format.Name, "double")) 
    23312331    { 
    23322332      char eol_char[3]; 
     
    23342334      int isPython = (strstr(detector.format.Name, "Python") != NULL); 
    23352335      int i,j; 
    2336       if (isIDL) strcpy(eol_char,"$\n");  
    2337       else if (isPython) strcpy(eol_char,"\\\n");  
     2336      if (isIDL) strcpy(eol_char,"$\n"); 
     2337      else if (isPython) strcpy(eol_char,"\\\n"); 
    23382338      else strcpy(eol_char,"\n"); 
    23392339 
     
    23522352      } /* end 2 loops if not Binary */ 
    23532353    } /* end if !Binary */ 
    2354        
     2354 
    23552355    /* array binary double =================================================== */ 
    2356     if (strstr(detector.format.Name, "double"))  
     2356    if (strstr(detector.format.Name, "double")) 
    23572357    { 
    23582358      long count=0; 
    23592359      count = fwrite(this_p1, sizeof(double), detector.m*detector.n*detector.p, detector.file_handle); 
    2360       if (count != detector.m*detector.n*detector.p)  
     2360      if (count != detector.m*detector.n*detector.p) 
    23612361        fprintf(stderr, "Error: writing double binary file '%s' (%li instead of %li, mcfile_data)\n", detector.filename,count, detector.m*detector.n*detector.p); 
    23622362    } /* end if Binary double */ 
    23632363 
    23642364    /* array binary float =================================================== */ 
    2365     if (strstr(detector.format.Name, "binary") || strstr(detector.format.Name, "float"))  
     2365    if (strstr(detector.format.Name, "binary") || strstr(detector.format.Name, "float")) 
    23662366    { 
    23672367      float *s; 
     
    23702370      { 
    23712371        long    i, count=0; 
    2372         for (i=0; i<detector.m*detector.n*detector.p; i++) {  
     2372        for (i=0; i<detector.m*detector.n*detector.p; i++) { 
    23732373          s[i] = (float)this_p1[i]; } 
    23742374        count = fwrite(s, sizeof(float), detector.m*detector.n*detector.p, detector.file_handle); 
    2375         if (count != detector.m*detector.n*detector.p)  
     2375        if (count != detector.m*detector.n*detector.p) 
    23762376          fprintf(stderr, "Error writing float binary file '%s' (%li instead of %li, mcfile_data)\n", 
    23772377            detector.filename,count, detector.m*detector.n*detector.p); 
    23782378        free(s); 
    2379       } else  
     2379      } else 
    23802380      fprintf(stderr, "Error: Out of memory for writing %li float binary file '%s' (mcfile_data)\n", 
    23812381        detector.m*detector.n*detector.p*sizeof(float), detector.filename); 
    23822382    } /* end if Binary float */ 
    23832383  } /* end if not empty array */ 
    2384    
     2384 
    23852385  /* output End ============================================================= */ 
    23862386  if (!strstr(detector.format.Name,"NeXus") 
     
    24212421  /* MPI: only write sim by Master ========================================== */ 
    24222422#ifdef USE_MPI 
    2423   if(mpi_node_rank != mpi_node_root) return(detector);   
     2423  if(mpi_node_rank != mpi_node_root) return(detector); 
    24242424#endif 
    24252425  /* skip invalid detectors */ 
    24262426  if (!detector.m || mcdisable_output_files) return(detector); 
    24272427 
    2428   /* sim file has been initialized when starting simulation and when calling  
     2428  /* sim file has been initialized when starting simulation and when calling 
    24292429   * mcsave ; this defines mcsiminfo_file as the SIM file handle 
    2430    * and calls:  
     2430   * and calls: 
    24312431   *    mcinfo_header 
    24322432   *    mcfile_section begin instrument 
     
    24412441   * The sim file (and mcnxHandle) is closed when ending mcsave 
    24422442   */ 
    2443     
     2443 
    24442444  MCDETECTOR simfile = mcdetector_import_sim(); /* store reference structure to SIM file */ 
    2445    
     2445 
    24462446  /* add component and data section to SIM file */ 
    24472447  if (!strstr(detector.format.Name,"NeXus")) 
    24482448    simfile = mcfile_section(simfile, "begin", detector.simulation, detector.component, "component", 3); 
    24492449  simfile = mcfile_section(simfile, "begin", detector.component, detector.filename, "data", 4); 
    2450    
     2450 
    24512451  /* handle indentation for simfile */ 
    24522452  char prefix[CHAR_BUF_LENGTH]; 
    24532453  strncpy(prefix, detector.prefix, CHAR_BUF_LENGTH); 
    24542454  strncpy(detector.prefix, simfile.prefix, CHAR_BUF_LENGTH); 
    2455    
     2455 
    24562456  /* WRITE detector information to sim file ================================= */ 
    24572457  mcinfo_data(detector, NULL); 
     
    24622462      fprintf(stderr, "Warning: NeXus: could not close data set %s/information\n", 
    24632463        detector.filename); 
    2464 #endif     
     2464#endif 
    24652465  /* WRITE data link to SIM file */ 
    24662466  if (!strstr(detector.format.Name,"McStas") && !mcsingle_file) { 
     
    24722472    detector.file_handle = file; 
    24732473  } 
    2474    
     2474 
    24752475  /* close component and data sections in SIM file */ 
    24762476  simfile = mcfile_section(simfile, "end", detector.component, detector.filename, "data", 4); 
    24772477  if (!strstr(detector.format.Name,"NeXus")) 
    24782478    simfile = mcfile_section(simfile, "end", detector.simulation, detector.component, "component", 3); 
    2479      
     2479 
    24802480  strncpy(detector.prefix, prefix, CHAR_BUF_LENGTH); 
    24812481 
    2482   return(detector);  
     2482  return(detector); 
    24832483} /* mcdetector_write_sim */ 
    24842484 
     
    24862486* mcdetector_write_data: write information to data file and catenate lists 
    24872487*                        this is where we open/close data files 
    2488 *                        also free detector.p1=this_p1 field which may hold  
     2488*                        also free detector.p1=this_p1 field which may hold 
    24892489*                        1D McStas [x I Ierr N] array which is set in mcdetector_import 
    24902490*******************************************************************************/ 
     
    24922492{ 
    24932493  /* skip if 0D or no filename or no data (only stored in sim file) */ 
    2494   if (!detector.rank || !strlen(detector.filename)  
     2494  if (!detector.rank || !strlen(detector.filename) 
    24952495   || !detector.m) return(detector); 
    24962496 
     
    25082508  } 
    25092509#endif 
    2510    
     2510 
    25112511  /* OPEN data file (possibly appending if already opened) ================== */ 
    25122512  if (mcformat_data.Name && strlen(mcformat_data.Name) && !mcsingle_file) 
    25132513    detector.format = mcformat_data; 
    2514    
     2514 
    25152515  if (!strstr(detector.format.Name, "NeXus")) { 
    25162516    /* explicitely open data file if not NeXus format */ 
     
    25202520    strcpy(mode, 
    25212521           (strstr(detector.format.Name, "no header") 
    2522             || strstr(detector.format.Name, "append") || strstr(detector.format.Name, "catenate")  
     2522            || strstr(detector.format.Name, "append") || strstr(detector.format.Name, "catenate") 
    25232523            || strstr(mcopenedfiles, detector.filename) ? 
    25242524           "a" : "w")); 
    25252525    if (strstr(detector.format.Name, "binary")) strcat(mode, "b"); 
    2526     detector.file_handle = mcnew_file(!mcsingle_file ?  
    2527       detector.filename : mcsiminfo_name,  
     2526    detector.file_handle = mcnew_file(!mcsingle_file ? 
     2527      detector.filename : mcsiminfo_name, 
    25282528      detector.format.Extension, mode); 
    25292529  } else { 
     
    25322532    mcfile_section(detector, "begin", detector.component, detector.filename, "data", 4); 
    25332533  } 
    2534    
     2534 
    25352535  /* WRITE data header (except when in 'no header') */ 
    25362536  if (!strstr(detector.format.Name, "no header")) { 
     
    25502550      fprintf(stderr, "Warning: NeXus: could not close data set %s/information (footer)\n", 
    25512551        detector.filename); 
    2552   /* group remains opened for data to be written */     
    2553 #endif    
    2554    
     2552  /* group remains opened for data to be written */ 
     2553#endif 
     2554 
    25552555  /* case: list of events =================================================== */ 
    25562556  if (strstr(detector.format.Name," list ")) { 
    2557    
     2557 
    25582558#ifdef USE_MPI 
    25592559    if (mpi_node_rank != mpi_node_root) { 
     
    25642564      if (mc_MPI_Send(mnp, 3, MPI_INT, mpi_node_root)!= MPI_SUCCESS) 
    25652565        fprintf(stderr, "Warning: proc %i to master: MPI_Send mnp list error (mcdetector_write_data)", mpi_node_rank); 
    2566       if (!detector.p1  
     2566      if (!detector.p1 
    25672567       || mc_MPI_Send(detector.p1, abs(mnp[0]*mnp[1]*mnp[2]), MPI_DOUBLE, mpi_node_root) != MPI_SUCCESS) 
    25682568        fprintf(stderr, "Warning: proc %i to master: MPI_Send p1 list error (mcdetector_write_data)", mpi_node_rank); 
     
    25732573 
    25742574    /* master node or non-MPI list: store data block */ 
    2575     int     master_mnp[3]={detector.m,detector.n,detector.p};  
    2576      
     2575    int     master_mnp[3]={detector.m,detector.n,detector.p}; 
     2576 
    25772577#ifdef USE_MPI 
    25782578    int     node_i=0; 
     
    25912591        detector.p1 = this_p1; 
    25922592        detector.m  = mnp[0]; detector.n  = mnp[1]; detector.p  = mnp[2]; 
    2593       } else  
     2593      } else 
    25942594#endif 
    25952595      { /* MASTER/single node use its own detector structure */ 
     
    25972597        detector.m  = master_mnp[0]; detector.n  = master_mnp[1]; detector.p  = master_mnp[2]; 
    25982598      } 
    2599      
     2599 
    26002600      /* WRITE list data (will be catenated in case of MPI as file is already opened) */ 
    26012601      mcfile_data(detector, "data"); 
    2602      
     2602 
    26032603#ifdef USE_MPI 
    26042604      /* free temporary MPI block used for Recv from slaves */ 
    2605       if (this_p1 && node_i != mpi_node_root)  
     2605      if (this_p1 && node_i != mpi_node_root) 
    26062606        free(this_p1); 
    26072607      detector.p0 = detector.p0_orig; 
     
    26092609      detector.p2 = detector.p2_orig; 
    26102610      detector.m  = master_mnp[0]; detector.n  = master_mnp[1]; detector.p  = master_mnp[2]; 
    2611      
     2611 
    26122612    } /* for node_i: end loop on nodes */ 
    26132613#endif 
     
    26172617  { 
    26182618  /* case: normal detector ================================================== */ 
    2619    
     2619 
    26202620    /* WRITE data */ 
    26212621    mcfile_data(detector, "data"); 
    2622      
     2622 
    26232623    /* write errors (not for lists) */ 
    26242624    if (detector.p2) mcfile_data(detector, "errors"); 
    2625      
     2625 
    26262626    /* write events (not for lists) */ 
    26272627    if (detector.p0) mcfile_data(detector, "events"); 
    2628      
     2628 
    26292629    if (detector.rank == 1 && detector.p1 && strstr(detector.format.Name,"McStas")) { 
    26302630      free(detector.p1);  /* 'this_p1' allocated in mcdetector_write_sim for 1D McStas data sets [x I E N] */ 
     
    26352635    } 
    26362636  } /* end normal detector case */ 
    2637    
     2637 
    26382638  /* WRITE data footer (except when 'no footer') */ 
    26392639  if (!strstr(detector.format.Name, "no footer") && !strstr(mcformat.Name, "NeXus")) { 
     
    26422642      mcinfo_header(detector, "footer"); 
    26432643  } 
    2644      
     2644 
    26452645  /* close data file and free memory */ 
    26462646  if (mcDetectorCustomHeader && strlen(mcDetectorCustomHeader)) { 
    26472647    free(mcDetectorCustomHeader); mcDetectorCustomHeader=NULL; } 
    2648    
     2648 
    26492649  if (!strstr(mcformat.Name, "NeXus") && detector.file_handle != mcsiminfo_file 
    2650    && !mcdisable_output_files && detector.file_handle)  
     2650   && !mcdisable_output_files && detector.file_handle) 
    26512651    fclose(detector.file_handle); 
    26522652  else if (strstr(mcformat.Name, "NeXus")) { 
     
    26552655  } 
    26562656 
    2657   return(detector);  
     2657  return(detector); 
    26582658} /* mcdetector_write_data */ 
    26592659 
     
    26662666#ifdef USE_MPI 
    26672667  /* only for Master */ 
    2668   if(mpi_node_rank != mpi_node_root)                      return(-1);  
     2668  if(mpi_node_rank != mpi_node_root)                      return(-1); 
    26692669#endif 
    26702670  if (mcdisable_output_files)                             return(-2); 
     
    26752675  double *this_p1 = (double *)calloc(DetectorArray_index*2, sizeof(double)); 
    26762676  int i; 
    2677    
     2677 
    26782678  if (this_p1 && DetectorArray) { 
    26792679    char   *labels=NULL; 
     
    26892689        mcvalid_name(valid, DetectorArray[i].filename, CHAR_BUF_LENGTH); 
    26902690        sprintf(mem, "%s_I %s_Err ", valid, valid); 
    2691         if (!labels ||  
     2691        if (!labels || 
    26922692          (labels && labels_size <= strlen(labels)+strlen(mem))) { 
    26932693          labels_size+=CHAR_BUF_LENGTH; 
     
    26962696          else 
    26972697            labels = realloc(labels, labels_size); 
    2698         }  
     2698        } 
    26992699        strcat(labels, " "); 
    27002700        strcat(labels, mem); 
    27012701    } /* for */ 
    2702      
     2702 
    27032703    struct mcformats_struct format=mcformat; 
    27042704    strcat(format.Name, " scan step"); 
    27052705    Coords zero={0.0,0.0,0.0}; 
    2706      
     2706 
    27072707    /* now create detector and write 'abstract' file */ 
    27082708    MCDETECTOR detector = mcdetector_import(format, 
     
    27132713      0, index-1, 0, 0, 0, 0, "content",  /* use name from OpenOffice content.xml description file */ 
    27142714      NULL, this_p1, NULL, zero); 
    2715        
     2715 
    27162716    mcdetector_write_data(detector); 
    27172717 
    27182718    free(labels); labels=NULL; labels_size=0; 
    2719      
     2719 
    27202720    /* free DETECTOR array */ 
    27212721    free(this_p1); this_p1=NULL; 
     
    27392739    0, 0, 0, 0, 0, 0, "", 
    27402740    &p0, &p1, &p2, posa); /* write Detector: line */ 
    2741      
     2741 
    27422742  /* write detector to simulation file (incl custom header if any) */ 
    2743   detector = mcdetector_write_sim(detector);  
     2743  detector = mcdetector_write_sim(detector); 
    27442744  mcdetector_register(detector); 
    27452745  return(detector); 
     
    27502750*******************************************************************************/ 
    27512751MCDETECTOR mcdetector_out_1D(char *t, char *xl, char *yl, 
    2752         char *xvar, double x1, double x2,  
     2752        char *xvar, double x1, double x2, 
    27532753        int n, 
    27542754        double *p0, double *p1, double *p2, char *f, 
     
    27632763    x1, x2, 0, 0, 0, 0, f, 
    27642764    p0, p1, p2, posa); /* write Detector: line */ 
    2765      
     2765 
    27662766  /* write detector to simulation and data file (incl custom header if any) */ 
    27672767  detector = mcdetector_write_sim(detector); 
     
    27752775*******************************************************************************/ 
    27762776MCDETECTOR mcdetector_out_2D(char *t, char *xl, char *yl, 
    2777                   double x1, double x2, double y1, double y2,  
    2778                   int m, int n,  
     2777                  double x1, double x2, double y1, double y2, 
     2778                  int m, int n, 
    27792779                  double *p0, double *p1, double *p2, char *f, 
    27802780                  char *c, Coords posa) 
     
    28162816MCDETECTOR mcdetector_out_3D(char *t, char *xl, char *yl, char *zl, 
    28172817      char *xvar, char *yvar, char *zvar, 
    2818       double x1, double x2, double y1, double y2, double z1, double z2,  
    2819       int m, int n, int p,  
    2820       double *p0, double *p1, double *p2, char *f,  
     2818      double x1, double x2, double y1, double y2, double z1, double z2, 
     2819      int m, int n, int p, 
     2820      double *p0, double *p1, double *p2, char *f, 
    28212821      char *c, Coords posa) 
    28222822{ 
     
    28292829    x1, x2, y1, y2, z1, z2, f, 
    28302830    p0, p1, p2, posa); /* write Detector: line */ 
    2831      
     2831 
    28322832  /* write detector to simulation and data file (incl custom header if any) */ 
    28332833  detector = mcdetector_write_sim(detector); 
     
    28382838 
    28392839/******************************************************************************* 
    2840 * mcuse_format_header: Replaces aliases names in format fields (header part)  
     2840* mcuse_format_header: Replaces aliases names in format fields (header part) 
    28412841*******************************************************************************/ 
    28422842char *mcuse_format_header(char *format_const) 
     
    28612861 
    28622862/******************************************************************************* 
    2863 * mcuse_format_tag: Replaces aliases names in format fields (tag part)  
     2863* mcuse_format_tag: Replaces aliases names in format fields (tag part) 
    28642864*******************************************************************************/ 
    28652865char *mcuse_format_tag(char *format_const) 
     
    28822882 
    28832883/******************************************************************************* 
    2884 * mcuse_format_section: Replaces aliases names in format fields (section part)  
     2884* mcuse_format_section: Replaces aliases names in format fields (section part) 
    28852885*******************************************************************************/ 
    28862886char *mcuse_format_section(char *format_const) 
     
    29042904 
    29052905/******************************************************************************* 
    2906 * mcuse_format_data: Replaces aliases names in format fields (data part)  
     2906* mcuse_format_data: Replaces aliases names in format fields (data part) 
    29072907*******************************************************************************/ 
    29082908char *mcuse_format_data(char *format_const) 
     
    30133013 
    30143014/******************************************************************************* 
    3015 * mcclear_format: free format structure  
     3015* mcclear_format: free format structure 
    30163016*******************************************************************************/ 
    30173017void mcclear_format(struct mcformats_struct usedformat) 
     
    30343034 
    30353035/******************************************************************************* 
    3036 * mcuse_file: will save data/sim files  
     3036* mcuse_file: will save data/sim files 
    30373037*******************************************************************************/ 
    30383038static void mcuse_file(char *file) 
     
    30493049 
    30503050/******************************************************************************* 
    3051 * mcset_ncount: set total number of rays to generate  
     3051* mcset_ncount: set total number of rays to generate 
    30523052*******************************************************************************/ 
    30533053void mcset_ncount(unsigned long long int count) 
     
    30723072mcsetn_arg(char *arg) 
    30733073{ 
    3074   mcset_ncount((long long int) strtod(arg, NULL));  
     3074  mcset_ncount((long long int) strtod(arg, NULL)); 
    30753075} 
    30763076 
     
    33863386    double cz = cos(phz); 
    33873387    double sz = sin(phz); 
    3388      
     3388 
    33893389    t[0][0] = cy*cz; 
    33903390    t[0][1] = sx*sy*cz + cx*sz; 
     
    33963396    t[2][1] = -sx*cy; 
    33973397    t[2][2] = cx*cy; 
    3398   }  
     3398  } 
    33993399} 
    34003400 
     
    34023402* rot_test_identity: Test if rotation is identity 
    34033403*******************************************************************************/ 
    3404 int  
     3404int 
    34053405rot_test_identity(Rotation t) 
    34063406{ 
     
    34653465{ 
    34663466  Coords b; 
    3467   if (rot_test_identity(t)) {  
     3467  if (rot_test_identity(t)) { 
    34683468    return a; 
    34693469  } else { 
     
    35263526    *z = b.z; 
    35273527  } 
    3528    
     3528 
    35293529  if (vx != NULL && vy != NULL && vz != NULL) mccoordschange_polarisation(t, vx, vy, vz); 
    3530    
     3530 
    35313531  if (sx != NULL && sy != NULL && sz != NULL) mccoordschange_polarisation(t, sx, sy, sz); 
    35323532 
     
    36163616{ 
    36173617  int ret=0; 
    3618    
     3618 
    36193619  if (!t1) return 0; 
    36203620  *t1 = 0; 
     
    36573657 * randvec_target_circle: Choose random direction towards target at (x,y,z) 
    36583658 * with given radius. 
    3659  * If radius is zero, choose random direction in full 4PI, no target.  
     3659 * If radius is zero, choose random direction in full 4PI, no target. 
    36603660 ******************************************************************************/ 
    36613661void 
     
    37223722 * (xi,yi,zi) with given ANGULAR dimension height x width. height=phi_x, 
    37233723 * width=phi_y (radians) 
    3724  * If height or width is zero, choose random direction in full 4PI, no target.  
     3724 * If height or width is zero, choose random direction in full 4PI, no target. 
    37253725 *******************************************************************************/ 
    37263726void 
     
    37943794 * (See remarks posted to mcstas-users by George Apostolopoulus <gapost@ipta.demokritos.gr>) 
    37953795 * 
    3796  * If height or width is zero, choose random direction in full 4PI, no target.  
    3797  *  
     3796 * If height or width is zero, choose random direction in full 4PI, no target. 
     3797 * 
    37983798 * Traditionally, this routine had the name randvec_target_rect - this is now a 
    37993799 * a define (see mcstas-r.h) pointing here. If you use the old rouine, you are NOT 
    3800  * taking the local emmission coordinate into account.  
     3800 * taking the local emmission coordinate into account. 
    38013801*******************************************************************************/ 
    38023802 
    38033803void 
    38043804randvec_target_rect_real(double *xo, double *yo, double *zo, double *solid_angle, 
    3805                double xi, double yi, double zi,  
    3806                double width, double height, Rotation A,  
     3805               double xi, double yi, double zi, 
     3806               double width, double height, Rotation A, 
    38073807               double lx, double ly, double lz, int order) 
    38083808{ 
     
    38733873      lz = *zo - lz; 
    38743874      dist_p = sqrt(lx*lx + ly*ly + lz*lz); 
    3875        
     3875 
    38763876      /* Adjust the 'solid angle' */ 
    38773877      /* 1/r^2 to the chosen point times cos(\theta) between the normal */ 
    38783878      /* vector of the target rectangle and direction vector of the chosen point. */ 
    38793879      cos_theta = (xi * lx + yi * ly + zi * lz) / (dist * dist_p); 
    3880       *solid_angle = width * height / (dist_p * dist_p);  
     3880      *solid_angle = width * height / (dist_p * dist_p); 
    38813881      int counter; 
    38823882      for (counter = 0; counter < order; counter++) { 
     
    41984198} 
    41994199 
    4200 /**  
     4200/** 
    42014201 * Return a random number between 1 and -1 
    42024202 */ 
     
    42294229 
    42304230/******************************************************************************* 
    4231 * mchelp: displays instrument executable help with possible options  
     4231* mchelp: displays instrument executable help with possible options 
    42324232*******************************************************************************/ 
    42334233static void 
     
    42924292} /* mchelp */ 
    42934293 
     4294 
    42944295/* mcshowhelp: show help and exit with 0 */ 
    42954296static void 
     
    42974298{ 
    42984299  mchelp(pgmname); 
    4299 #ifdef USE_MPI 
    4300 #undef exit 
    4301 #endif 
    43024300  exit(0); 
    4303 #ifdef USE_MPI 
    4304 #define exit(code) MPI_Abort(MPI_COMM_WORLD, code) 
    4305 #endif 
    43064301} 
    43074302 
     
    43344329/******************************************************************************* 
    43354330 * mcuse_dir: set data/sim storage directory and create it, 
    4336  * or exit with error if exists  
     4331 * or exit with error if exists 
    43374332 ******************************************************************************/ 
    43384333static void 
     
    43454340  exit(1); 
    43464341#else  /* !MC_PORTABLE */ 
    4347 #ifdef USE_MPI   
     4342#ifdef USE_MPI 
    43484343  if(mpi_node_rank == mpi_node_root) 
    43494344  { 
     
    43524347#ifndef DANSE 
    43534348      fprintf(stderr, "Error: unable to create directory '%s' (mcuse_dir)\n", dir); 
    4354       fprintf(stderr, "(Maybe the directory already exists?)\n");        
     4349      fprintf(stderr, "(Maybe the directory already exists?)\n"); 
    43554350      exit(1); 
    43564351#endif 
     
    43644359  else 
    43654360    mcdirname = dir+strlen("file:/"); 
    4366      
     4361 
    43674362  /* remove trailing PATHSEP (if any) */ 
    4368   while (strlen(mcdirname) && mcdirname[strlen(mcdirname) - 1] == MC_PATHSEP_C)  
     4363  while (strlen(mcdirname) && mcdirname[strlen(mcdirname) - 1] == MC_PATHSEP_C) 
    43694364    mcdirname[strlen(mcdirname) - 1]='\0'; 
    43704365#endif /* !MC_PORTABLE */ 
     
    43724367 
    43734368/******************************************************************************* 
    4374 * mcinfo: display instrument simulation info to stdout and exit  
     4369* mcinfo: display instrument simulation info to stdout and exit 
    43754370*******************************************************************************/ 
    43764371static void 
     
    43914386 
    43924387/******************************************************************************* 
    4393 * mcreadparams: request parameters from the prompt (or use default)  
     4388* mcreadparams: request parameters from the prompt (or use default) 
    43944389*******************************************************************************/ 
    43954390void 
     
    44744469 
    44754470/******************************************************************************* 
    4476 * mcparseoptions: parse command line arguments (options, parameters)  
     4471* mcparseoptions: parse command line arguments (options, parameters) 
    44774472*******************************************************************************/ 
    44784473void 
     
    45844579    } 
    45854580    else if(!strcmp("--no-output-files", argv[i])) 
    4586       mcdisable_output_files = 1;    
     4581      mcdisable_output_files = 1; 
    45874582    else if(argv[i][0] != '-' && (p = strchr(argv[i], '=')) != NULL) 
    45884583    { 
     
    46434638 
    46444639#ifndef NOSIGNALS 
    4645 mcstatic char  mcsig_message[256];  
    4646  
    4647  
    4648 /******************************************************************************* 
    4649 * sighandler: signal handler that makes simulation stop, and save results  
     4640mcstatic char  mcsig_message[256]; 
     4641 
     4642 
     4643/******************************************************************************* 
     4644* sighandler: signal handler that makes simulation stop, and save results 
    46504645*******************************************************************************/ 
    46514646void sighandler(int sig) 
     
    47274722  else 
    47284723  { 
    4729     printf("%.2f %% (%10.1f/%10.1f)\n", 100.0*mcget_run_num()/mcget_ncount(), 1.0*mcget_run_num(), 1.0*mcget_ncount());  
     4724    printf("%.2f %% (%10.1f/%10.1f)\n", 100.0*mcget_run_num()/mcget_ncount(), 1.0*mcget_run_num(), 1.0*mcget_ncount()); 
    47304725  } 
    47314726  t0 = (time_t)mcstartdate; 
     
    47714766 
    47724767/******************************************************************************* 
    4773 * mccode_main: McCode main() function.  
     4768* mccode_main: McCode main() function. 
    47744769*******************************************************************************/ 
    47754770int mccode_main(int argc, char *argv[])