esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% dp_files.mac
#%NAME%
#  Macros for generating data processing files at some MX beamlines
#%CATEGORY% MX
#
#%END%

global DP_INPUTS _DP_INPUTS
global XDS_TEMPLATE MOSFLM_TEMPLATE
global STAC_OM_XDS_TEMPLATE STAC_OM_MOSFLM_TEMPLATE
global XDS_INPUT_FILENAME
global RKAP

def dp_files_setup '{
  global DP_INPUTS
  global RKAP

  if (motor_num("r_kap1") >=0) {
    RKAP="r_"
  } else {
    RKAP = ""
  }

  if ($# == 0) {
    DP_INPUTS["beamline"] = getval(sprintf("Please input the beamline name (e.g ESRF_ID14-1/2/3/4,ESRF_BM14/16, ESRF_ID23-1/2, ID29). (%s) \n",DP_INPUTS["beamline"]),DP_INPUTS["beamline"])
    DP_INPUTS["anomalous_flag"] = yesno(sprintf("Is this a MAD beamline? (%s) \n",DP_INPUTS["anomalous_flag"]),DP_INPUTS["anomalous_flag"])
    DP_INPUTS["detector"] = getval(sprintf("What is the detector type (e.g ADSC Quantum4 or MARCCD 165)\n (%s) ? ",DP_INPUTS["detector"]),DP_INPUTS["detector"])
    DP_INPUTS["detector_xds"] = getval(sprintf("What is the xds detector type (e.g ADSC or CCDCHESS)\n (%s) ? ",DP_INPUTS["detector_xds"]),DP_INPUTS["detector_xds"])
    DP_INPUTS["detector_mosflm"] = getval(sprintf("What is the mosflm detector type (e.g ADSC or MARCCD)\n (%s) ? ",DP_INPUTS["detector_mosflm"]),DP_INPUTS["detector_mosflm"])
    DP_INPUTS["file_suffix"] = getval(sprintf("What is the file suffix used by the detector software? (e.g img, mccd,ccd)\n (%s) ? ",DP_INPUTS["file_suffix"]),DP_INPUTS["file_suffix"])
    DP_INPUTS["nx_pixels"] = getval(sprintf("What is number of pixels in x? (%d)",DP_INPUTS["nx_pixels"]),DP_INPUTS["nx_pixels"])
    DP_INPUTS["ny_pixels"] = getval(sprintf("What is number of pixels in y? (%d)",DP_INPUTS["ny_pixels"]),DP_INPUTS["ny_pixels"])
    DP_INPUTS["pixel_size_x"] = getval(sprintf("What is the size of the pixels in x? (%7.4f)",DP_INPUTS["pixel_size_x"]),DP_INPUTS["pixel_size_x"])
    DP_INPUTS["pixel_size_y"] = getval(sprintf("What is the size of the pixels in y? (%7.4f)",DP_INPUTS["pixel_size_y"]),DP_INPUTS["pixel_size_y"])
    printf("\nSetup line would be...\ndp_files_setup %s %d \"%s\" %s %s %s %d %d %7.5f %7.5f\n", \
          DP_INPUTS["beamline"], DP_INPUTS["anomalous_flag"],DP_INPUTS["detector"],DP_INPUTS["detector_xds"],\
          DP_INPUTS["detector_mosflm"], DP_INPUTS["file_suffix"], DP_INPUTS["nx_pixels"], DP_INPUTS["ny_pixels"], \
          DP_INPUTS["pixel_size_x"], DP_INPUTS["pixel_size_y"])
  } else if ($# == 10 ) {
    DP_INPUTS["beamline"] = "$1"
    DP_INPUTS["anomalous_flag"] = $2
    DP_INPUTS["detector"] = "$3"
    DP_INPUTS["detector_xds"] = "$4"
    DP_INPUTS["detector_mosflm"] = "$5"
    DP_INPUTS["file_suffix"] = "$6"
    DP_INPUTS["nx_pixels"] = $7
    DP_INPUTS["ny_pixels"] = $8
    DP_INPUTS["pixel_size_x"] = $9
    DP_INPUTS["pixel_size_y"] = $10
  } else {
    print "Incorrect setup for dp_input_files, please type dp_files_setup and answer the questions. The setup line will be generated at the end."
    exit
  }
    local tt[]
    split(DP_INPUTS["beamline"],tt,"-")
    DP_INPUTS["p_beamline"] = sprintf("%s_%s", tt[0],tt[1])
    if (DP_INPUTS["detector_xds"] == "ADSC"){ DP_INPUTS["minimum_valid_pixel_value"] = 1}
    else if (DP_INPUTS["detector_xds"] == "CCDCHESS"){ DP_INPUTS["minimum_valid_pixel_value"] = 0}
    
    load_templates()
}'

def write_dp_input(input_name, input_str) '{
    open(input_name)
    fprintf(input_name, "%s", input_str)
    close(input_name)
}'

# for handling inverse beam
def write_dp_inputs(cpars,bcmpars) '{
    _write_dp_inputs(cpars,bcmpars,sprintf("%s/process", cpars["fileinfo"]["directory"]),0)
    # also generate input files in RAW_DATA dir. under a process subdirectory
    _write_dp_inputs(cpars,bcmpars,cpars["fileinfo"]["process_directory"],1)

    local tmp[]
    split(cpars["experiment_type"], tmp)
    if (tmp[1]!=0) {
        # INVERSE BEAM
        cpars["fileinfo"]["run_number"]+=1
        cpars["start"]+=180
        _write_dp_inputs(cpars,bcmpars,sprintf("%s/process",cpars["fileinfo"]["directory"]),0)
        _write_dp_inputs(cpars,bcmpars,cpars["fileinfo"]["process_directory"],1)
        cpars["fileinfo"]["run_number"]-=1
        cpars["start"]-=180
    }
}'

def _write_dp_inputs(cpars,bcmpars,dir_location,write_links) '{
  global DIRECTORY_INDEX_NUMBER
  if (cpars["input_files"] == 1) {
    unglobal dirNames dirName dirList
    dirList = "xds mosflm HKL2000"
    split(dirList,dirNames," ")
    runNumber = cpars["fileinfo"]["run_number"]
    prefix = cpars["fileinfo"]["prefix"]

    _DP_INPUTS["frame_first"] = cpars["start_image_number"]
    _DP_INPUTS["frame_last"] = _DP_INPUTS["frame_first"]+ cpars["number_of_images"] - 1
    local frame_template
    if (write_links) {
      frame_template = "../links"
    } else {
      frame_template = "../.."
    }
    _DP_INPUTS["frame_template"] = sprintf("%s/%s_%d_????.%s",\
		frame_template,prefix,runNumber,DP_INPUTS["file_suffix"])

    xds_input = prep_xds_input(cpars,bcmpars)
    mosflm_input = prep_mosflm_input(cpars,bcmpars)

    printf(">>> Writting Data Processing input files\n")
    printf(">>> For mosflm and XDS in directory: %s\n", dir_location)

    #unix(sprintf("mkdir -p %s", dir_location))
    #unix(sprintf("chmod a+rxw %s",dir_location))

    #if (write_links) {
    #  unix(sprintf("ln -snf %s %s/links", cpars["fileinfo"]["directory"], dir_location))
    #}

    #DIRECTORY_INDEX_NUMBER = 1
    #cmd = sprintf("test -d %s/xds_%s_run%d_%d", dir_location,prefix,runNumber,DIRECTORY_INDEX_NUMBER)
    #printf("Check for directory paths... with %s\n",cmd)
    #while (0 == unix(cmd) ) {
    #  DIRECTORY_INDEX_NUMBER++
    #  cmd = sprintf("test -d %s/xds_%s_run%d_%d", dir_location,prefix,runNumber,DIRECTORY_INDEX_NUMBER)
    #}

    unix(sprintf("stat %s", dir_location)) #force NFS cache refresh	
    unix(sprintf("ls -dt %s/xds_%s_run%d_* | head -1 | xargs basename | cut -d_ -f4", dir_location,prefix,runNumber), DIRECTORY_INDEX_NUMBER)
  
    # this code should go (like all the macro by the way...)
    for ( dirName in dirNames ) {
      DPDir = sprintf("%s/%s_%s_run%d_%d",\
        dir_location, dirNames[dirName] ,prefix,runNumber,DIRECTORY_INDEX_NUMBER)
      if (1 == unix(sprintf("test -d %s",DPDir))){
        unix(sprintf("mkdir %s",DPDir))
        unix(sprintf("chmod a+rxw %s",DPDir))
        printf("DPDir = %s\n",DPDir)
      }
    }

    xds_input_name = sprintf("%s/xds_%s_run%d_%d/XDS.INP",\
                                dir_location,prefix,runNumber,DIRECTORY_INDEX_NUMBER)
    XDS_INPUT_FILENAME=xds_input_name #triggers auto-processing in mxCuBE
    mosflm_input_name = sprintf("%s/mosflm_%s_run%d_%d/mosflm.inp",\
                                dir_location,prefix,runNumber,DIRECTORY_INDEX_NUMBER)
    write_dp_input(xds_input_name, xds_input)
    unix(sprintf("chmod a+rw %s",xds_input_name))
    if ((MXBCM_PARS["detector"]["type"]=="pilatus")&&(MXCOLLECT_PARS["beamline"])) {
      unix(sprintf("cp /data/pyarch/%s/*geo_corr.cbf %s", \
	MXCOLLECT_PARS["beamline"], dir_location))
    }
    write_dp_input(mosflm_input_name, mosflm_input)
    unix(sprintf("chmod a+rw %s",mosflm_input_name))

    prep_stac_om_xds_input(cpars,bcmpars,dir_location)
    stac_om_xds_input_name = sprintf("%s/xds_%s_run%d_%d/xds.descr",\
                                dir_location,prefix,runNumber,DIRECTORY_INDEX_NUMBER)
    write_dp_input(stac_om_xds_input_name, stac_om_xds_input)
    unix(sprintf("chmod a+rw %s",stac_om_xds_input_name))
    
    stac_om_mosflm_input_name = sprintf("%s/mosflm_%s_run%d_%d/mosflm.descr",\
                                dir_location,prefix,runNumber,DIRECTORY_INDEX_NUMBER)
    write_dp_input(stac_om_mosflm_input_name, stac_om_mosflm_input)
    unix(sprintf("chmod a+rw %s",stac_om_mosflm_input_name))
  } else {
    printf("No input files generated if not requested by user\n")
    egui_logmsg("No input files generated if not requested by user")
  }
}'


def prep_stac_om_xds_input(cpars,bcmpars,process_directory) '{
  global STAC_OM_XDS_TEMPLATE STAC_OM_MOSFLM_TEMPLATE
  # Get info for STAC .sav file
  if (motor_num("kap1") < 0) {
  	SB_kap1 = 0 
  } else {
  	SB_kap1 = A[motor_num("kap1")]
  }
  if (motor_num("kap2") < 0) {
        SB_kap2 = 0
  } else {
        SB_kap2 = A[motor_num("kap2")]
  }
  SB_X = A[motor_num("sampx")]
  SB_Y = A[motor_num("sampy")]
  SB_Z = A[motor_num("phiy")]
  
  local CORRECTLP
  if (index(process_directory, "PROCESSED_DATA")>0) {
    CORRECTLP="xds_fastproc/CORRECT.LP"
  } else {
    CORRECTLP="CORRECT.LP"
  } 
 
  stac_om_mosflm_input = sprintf(STAC_OM_MOSFLM_TEMPLATE,\
      process_directory,\
      cpars["fileinfo"]["prefix"],\
      cpars["fileinfo"]["run_number"],\
      DIRECTORY_INDEX_NUMBER,\
      cpars["start"],\
      SB_kap1,\
      SB_kap2,\
      SB_X,\
      SB_Y,\
      SB_Z,\
      dial(phi,phi_init_val),\
      dial(kap1,SB_kap1),\
      dial(kap2,SB_kap2),\
      dial(sampx,SB_X),\
      dial(sampy,SB_Y),\
      dial(phiy,SB_Z))

  printf("stac_om_mosflm_input = %s\n",stac_om_mosflm_input)

  stac_om_xds_input = sprintf(STAC_OM_XDS_TEMPLATE,\
      process_directory,\
      cpars["fileinfo"]["prefix"],\
      cpars["fileinfo"]["run_number"],\
      DIRECTORY_INDEX_NUMBER,\
      CORRECTLP,\
      cpars["start"],\
      SB_kap1,\
      SB_kap2,\
      SB_X,\
      SB_Y,\
      SB_Z,\
      dial(phi,phi_init_val),\
      dial(kap1,SB_kap1),\
      dial(kap2,SB_kap2),\
      dial(sampx,SB_X),\
      dial(sampy,SB_Y),\
      dial(phiy,SB_Z))
  printf("stac_om_xds_input = %s\n",stac_om_xds_input)
      
}'

def prep_mosflm_input(cpars,bcmpars) '{
  global MOSFLM_TEMPLATE
  local dpinput
  template="####"
  dpinput = sprintf(MOSFLM_TEMPLATE,\
      DP_INPUTS["beamline"],\
      DP_INPUTS["detector"],\
      date(),\
      cpars["comment"],\
      DP_INPUTS["detector_mosflm"],\
      getMxWavelength(),\
      getMxCurrentDistance(),\
      bcmpars["beam"]["x"],\
      bcmpars["beam"]["y"],\
      cpars["fileinfo"]["directory"], \
      cpars["fileinfo"]["prefix"], \
      cpars["fileinfo"]["run_number"],\
      template,\
      DP_INPUTS["file_suffix"],\
      DP_INPUTS["file_suffix"],\
      cpars["start_image_number"],\
      cpars["start"],\
      cpars["start"] +cpars["range"])
  return(dpinput)

}'

def prep_xds_input(cpars,bcmpars) '{
 global XDS_TEMPLATE    MXSPEC_PARS
 local dpinput
 local rlam1,rlam2,rlam3,airabs
  # If depending on the binning mode for detectors we must double the pixel size
  # for 0=Hardware binned, 1=unbinned, 2=software binned
  # must change the pixel size and number of pixels and xy origin
  #
  if (getMxDetectorBinMode() != 1) {
    pixel_size_x = DP_INPUTS["pixel_size_x"] *2
    pixel_size_y = DP_INPUTS["pixel_size_y"] *2
    nx_pixels = DP_INPUTS["nx_pixels"]/2
    ny_pixels = DP_INPUTS["ny_pixels"]/2
  } else {
    # unbinned mode
    pixel_size_x = DP_INPUTS["pixel_size_x"]
    pixel_size_y = DP_INPUTS["pixel_size_y"]
    nx_pixels = DP_INPUTS["nx_pixels"]
    ny_pixels = DP_INPUTS["ny_pixels"]
  }
  if (MXBCM_PARS["detector"]["type"] == "pilatus") {
    nx_pixels = DP_INPUTS["ny_pixels"]
    ny_pixels = DP_INPUTS["nx_pixels"]
  }
  orgx = bcmpars["beam"]["x"]/pixel_size_x
  orgy = bcmpars["beam"]["y"]/pixel_size_y
  rlam1=getMxWavelength()
  rlam2=rlam1*rlam1
  rlam3=rlam1*rlam1*rlam1
  airabs = 3.0E-5 - (1.3493E-5*rlam1) - (5.5356E-6*rlam2) + (3.1525E-4*rlam3)
  dpinput = sprintf(XDS_TEMPLATE,\
      DP_INPUTS["beamline"],\
      DP_INPUTS["detector"],\
      date(),\
      cpars["comment"],\
      _DP_INPUTS["frame_first"], _DP_INPUTS["frame_last"],\
      _DP_INPUTS["frame_first"], _DP_INPUTS["frame_first"]+3,\
      _DP_INPUTS["frame_last"]-3, _DP_INPUTS["frame_last"],\
      _DP_INPUTS["frame_first"], _DP_INPUTS["frame_first"]+3,\
      cpars["range"],\
      cpars["start"],\
      cpars["start_image_number"],\
      getMxWavelength(),\
      _DP_INPUTS["frame_template"],\
      getMxCurrentDistance(),\
      DP_INPUTS["detector_xds"], DP_INPUTS["minimum_valid_pixel_value"],\
      orgy, orgx,\
      ny_pixels, nx_pixels, \
      pixel_size_y, pixel_size_x,\
      airabs, \
      3* cpars["range"])
  return(dpinput)
}'

def load_templates() '{
  global XDS_TEMPLATE  DIRECTORY_INDEX_NUMBER
  if (MXBCM_PARS["detector"]["type"] == "pilatus") {
  XDS_TEMPLATE = " !=== File Automaticaly generated by mxCuBE\n\
   !=== X-Ray data collected at: %s\n\
   !=== Detector type: %s\n\
   !=== Date: %s\n\
   !=== User comments:  %s\n\
   \n\
   JOB= ALL !XYCORR INIT COLSPOT IDXREF DEFPIX XPLAN INTEGRATE CORRECT\n\
   !JOB= DEFPIX XPLAN INTEGRATE CORRECT\n\
   \n\
   DATA_RANGE= %d %d\n\
   SPOT_RANGE= 1 20
   SPOT_RANGE= %d %d\n\
   !SPOT_RANGE= %d %d\n\
   BACKGROUND_RANGE= %d %d\n\
   !masking non sensitive area of Pilatus
   UNTRUSTED_RECTANGLE= 487  495     0 2528\n\
   UNTRUSTED_RECTANGLE= 981  989     0 2528\n\
   UNTRUSTED_RECTANGLE=1475 1483     0 2528\n\
   UNTRUSTED_RECTANGLE=1969 1977     0 2528\n\
   UNTRUSTED_RECTANGLE=   0 2464   195  213\n\
   UNTRUSTED_RECTANGLE=   0 2464   407  425\n\
   UNTRUSTED_RECTANGLE=   0 2464   619  637\n\
   UNTRUSTED_RECTANGLE=   0 2464   831  849\n\
   UNTRUSTED_RECTANGLE=   0 2464  1043 1061\n\
   UNTRUSTED_RECTANGLE=   0 2464  1255 1273\n\
   UNTRUSTED_RECTANGLE=   0 2464  1467 1485\n\
   UNTRUSTED_RECTANGLE=   0 2464  1679 1697\n\
   UNTRUSTED_RECTANGLE=   0 2464  1891 1909\n\
   UNTRUSTED_RECTANGLE=   0 2464  2103 2121\n\
   UNTRUSTED_RECTANGLE=   0 2464  2315 2333\n\
   TRUSTED_REGION=0.0 1.41 !Relative radii limiting trusted detector region\n\
   
   !correction tables to compensate the misorientations of the modules
   X-GEO_CORR= ../x_geo_corr.cbf\n\
   Y-GEO_CORR= ../y_geo_corr.cbf\n\
   \n\
   SECONDS=600\n\
   MINIMUM_NUMBER_OF_PIXELS_IN_A_SPOT= 4\n\
   !STRONG_PIXEL= 3.0\n\
   \n\
   OSCILLATION_RANGE= %.3f\n\
   STARTING_ANGLE= %.3f\n\
   STARTING_FRAME= %d\n\
   X-RAY_WAVELENGTH=  %.5f\n\
   NAME_TEMPLATE_OF_DATA_FRAMES= %s !CBF\n\
   \n\
   !STARTING_ANGLES_OF_SPINDLE_ROTATION= 0 180 10 \n\
   !TOTAL_SPINDLE_ROTATION_RANGES= 60 180 10 \n\
   \n\
   DETECTOR_DISTANCE= %.2f\n\
   DETECTOR= %s   MINIMUM_VALID_PIXEL_VALUE= %d   OVERLOAD= 1048500\n\
   SENSOR_THICKNESS=0.32\n\
   ORGX= %.2f    ORGY= %.2f\n\
   NX=  %d   NY=  %d   QX= %.5f   QY= %.5f\n\
   VALUE_RANGE_FOR_TRUSTED_DETECTOR_PIXELS= 7000 30000\n\
   \n\
   DIRECTION_OF_DETECTOR_X-AXIS= 1.0 0.0 0.0\n\
   DIRECTION_OF_DETECTOR_Y-AXIS= 0.0 1.0 0.0\n\
   ROTATION_AXIS= 1.0 0.0 0.0\n\
   INCIDENT_BEAM_DIRECTION= 0.0 0.0 1.0\n\
   FRACTION_OF_POLARIZATION= 0.98\n\
   POLARIZATION_PLANE_NORMAL= 0.0 1.0 0.0\n\
   !== Default value recommended
   !AIR= %.8f\n\
   \n\
   SPACE_GROUP_NUMBER= 0\n\
   UNIT_CELL_CONSTANTS= 0 0 0 0 0 0\n\
   INCLUDE_RESOLUTION_RANGE= 50.0 0.0\n\
   !RESOLUTION_SHELLS= 15.0 8.0 4.0 2.8 2.4\n\
   !FRIEDEL\'S_LAW= FALSE !default is TRUE\n\
    \n\
   REFINE(INTEGRATE)= BEAM ORIENTATION CELL\n\
   !== Default value recommended
   !DELPHI= %.3f\n\
   MAXIMUM_NUMBER_OF_PROCESSORS= 16\n\
   !MAXIMUM_NUMBER_OF_JOBS= 16\n\
   "
  } else {
    XDS_TEMPLATE = " !=== File Automaticaly generated by mxCuBE\n\
   !=== X-Ray data collected at: %s\n\
   !=== Detector type: %s\n\
   !=== Date: %s\n\
   !=== User comments:  %s\n\
   \n\
   JOB= ALL !XYCORR INIT COLSPOT IDXREF DEFPIX XPLAN INTEGRATE CORRECT\n\
   !JOB= DEFPIX XPLAN INTEGRATE CORRECT\n\
   \n\
   DATA_RANGE= %d %d\n\
   SPOT_RANGE= 1 20
   SPOT_RANGE= %d %d\n\
   !SPOT_RANGE= %d %d\n\
   BACKGROUND_RANGE= %d %d\n\
   \n\
   SECONDS=60\n\
   MINIMUM_NUMBER_OF_PIXELS_IN_A_SPOT= 6\n\
   STRONG_PIXEL= 6.0\n\
   \n\
   OSCILLATION_RANGE= %.3f\n\
   STARTING_ANGLE= %.3f\n\
   STARTING_FRAME= %d\n\
   X-RAY_WAVELENGTH=  %.5f\n\
   NAME_TEMPLATE_OF_DATA_FRAMES= %s\n\
   \n\
   !STARTING_ANGLES_OF_SPINDLE_ROTATION= 0 180 10 \n\
   !TOTAL_SPINDLE_ROTATION_RANGES= 60 180 10 \n\
   \n\
   DETECTOR_DISTANCE= %.2f\n\
   DETECTOR= %s   MINIMUM_VALID_PIXEL_VALUE= %d   OVERLOAD= 65000\n\
   ORGX= %.2f    ORGY= %.2f\n\
   NX=  %d   NY=  %d   QX= %.5f   QY= %.5f\n\
   VALUE_RANGE_FOR_TRUSTED_DETECTOR_PIXELS= 7000 30000\n\
   \n\
   DIRECTION_OF_DETECTOR_X-AXIS= 1.0 0.0 0.0\n\
   DIRECTION_OF_DETECTOR_Y-AXIS= 0.0 1.0 0.0\n\
   ROTATION_AXIS= 1.0 0.0 0.0\n\
   INCIDENT_BEAM_DIRECTION= 0.0 0.0 1.0\n\
   FRACTION_OF_POLARIZATION= 0.98\n\
   POLARIZATION_PLANE_NORMAL= 0.0 1.0 0.0\n\
   !== Default value recommended
   !AIR= %.8f\n\
   \n\
   SPACE_GROUP_NUMBER= 0\n\
   UNIT_CELL_CONSTANTS= 0 0 0 0 0 0\n\
   INCLUDE_RESOLUTION_RANGE= 50.0 0.0\n\
   !RESOLUTION_SHELLS= 15.0 8.0 4.0 2.8 2.4\n\
   !FRIEDEL\'S_LAW= FALSE\n\ 
   FRIEDEL\'S_LAW= TRUE\n\
   TRUSTED_REGION= 0 1.40 \n\
   \n\
   REFINE(INTEGRATE)= BEAM ORIENTATION CELL\n\
   !== Default value recommended
   !DELPHI= %.3f\n\
   MAXIMUM_NUMBER_OF_PROCESSORS= 16\n\
   !MAXIMUM_NUMBER_OF_JOBS= 16\n\
"
  }
   
  global MOSFLM_TEMPLATE
  if (MXBCM_PARS["detector"]["type"] == "pilatus") {
  MOSFLM_TEMPLATE = "# File Automaticaly generated by mxCuBE\n\
  # X-Ray data collected at %s\n\
  # Detector type: %s\n\
  # Date: %s\n\
  # User comments: %s\n\
   \n\
  #  Basic definitions\n\
   scanner %s\n\
   synchrotron polar 0.99\n\
   dispersion  0.0002\n\
   divergence  0.001 0.001\n\
   genf genfile.gen\n\
   \n\
  #  Better have them\n\
   wavelength  %.6f\n\
   distance    %.2f\n\
   beam  %.2f  %.2f\n\
   \n\
  #  Just a guess\n\
   mosaic  0.5\n\
   \n\
  #  Files\n\
   directory       %s\n\
   template   %s_%d_%s.%s\n\
   extension  %s\n\
   image %d phi %f to %f \n\
   BEST ON\n\
   wait 60
   go\n\
   \n
   "
  } else {
    MOSFLM_TEMPLATE = "# File Automaticaly generated by mxCuBE\n\
  # X-Ray data collected at %s\n\
  # Detector type: %s\n\
  # Date: %s\n\
  # User comments: %s\n\
   \n\
  #  Basic definitions\n\
   scanner %s\n\
   gain 0.4\n\
   synchrotron polar 0.99\n\
   dispersion  0.0002\n\
   divergence  0.001 0.001\n\
   genf genfile.gen\n\
   \n\
  #  Better have them\n\
   wavelength  %.6f\n\
   distance    %.2f\n\
   beam  %.2f  %.2f\n\
   \n\
  #  Just a guess\n\
   mosaic  0.5\n\
   \n\
  #  Files\n\
   directory       %s\n\
   template   %s_%d_%s.%s\n\
   extension  %s\n\
   image %d phi %f to %f\n\
   BEST ON\n\
   wait 60
   go\n\
   \n
"
  }

  global STAC_OM_XDS_TEMPLATE

  if (motor_par(phi, "device_id")=="udiff_mot") {
    STAC_OM_XDS_TEMPLATE = "#STAC OM descriptor (by Sandor Brockhauser)\n\
#==========================================\n\
OMFILENAME %s/xds_%s_run%d_%d/%s\n\
OMTYPE     xds\n\
OmegaPosition        %.4f\n\
KappaPosition       %.4f\n\
KappaPhiPosition       %.4f\n\
CentringTableXAxisPosition      %.4f\n\
CentringTableYAxisPosition      %.4f\n\
PhiTableYAxisPosition       %.4f\n\
phi_dial        %.4f\n\
kap1_dial       %.4f\n\
kap2_dial       %.4f\n\
sampx_dial      %.4f\n\
sampy_dial      %.4f\n\
phiy_dial       %.4f\n"


global STAC_OM_MOSFLM_TEMPLATE
  STAC_OM_MOSFLM_TEMPLATE = "#STAC OM descriptor (by Sandor Brockhauser)\n\
#==========================================\n\
OMFILENAME %s/mosflm_%s_run%d_%d/bestfile.par\n\
OMTYPE     mosflm\n\
OmegaPosition        %.4f\n\
KappaPosition       %.4f\n\
KappaPhiPosition       %.4f\n\
CentringTableXAxisPosition      %.4f\n\
CentringTableYAxisPosition      %.4f\n\
PhiTableYAxisPosition       %.4f\n\
phi_dial        %.4f\n\
kap1_dial       %.4f\n\
kap2_dial       %.4f\n\
sampx_dial      %.4f\n\
sampy_dial      %.4f\n\
phiy_dial       %.4f\n"

  } else {
    STAC_OM_XDS_TEMPLATE = sprintf("#STAC OM descriptor (by Sandor Brockhauser)\n\
#==========================================\n\
OMFILENAME %%s/xds_%%s_run%%d_%%d/%%s\n\
OMTYPE     xds\n\
phi        %%.4f\n\
%skap1       %%.4f\n\
%skap2       %%.4f\n\
sampx      %%.4f\n\
sampy      %%.4f\n\
phiy       %%.4f\n\
phi_dial        %%.4f\n\
%skap1_dial       %%.4f\n\
%skap2_dial       %%.4f\n\
sampx_dial      %%.4f\n\
sampy_dial      %%.4f\n\
phiy_dial       %%.4f\n", RKAP,RKAP,RKAP,RKAP)

 
  
global STAC_OM_MOSFLM_TEMPLATE
  STAC_OM_MOSFLM_TEMPLATE = sprintf("#STAC OM descriptor (by Sandor Brockhauser)\n\
#==========================================\n\
OMFILENAME %%s/mosflm_%%s_run%%d_%%d/bestfile.par\n\
OMTYPE     mosflm\n\
phi        %%.4f\n\
%skap1       %%.4f\n\
%skap2       %%.4f\n\
sampx      %%.4f\n\
sampy      %%.4f\n\
phiy       %%.4f\n\
phi_dial        %%.4f\n\
%skap1_dial       %%.4f\n\
%skap2_dial       %%.4f\n\
sampx_dial      %%.4f\n\
sampy_dial      %%.4f\n\
phiy_dial       %%.4f\n", RKAP,RKAP,RKAP,RKAP)
}

}'