#! /usr/bin/awk -f ## this is a test translator for ngx scan file to ## gsas raw file ## NOTE: anglestep must be constant; the data should be in equal step. ## taku j sato 2007/09/07 BEGIN{ dataflag = 0; nl = 0; dangle = 0.02; ## condition to recognize that angles are equally stepped. trancateangle = 0.01; ## anglestep which should be trancated in this precision. } # reading data !/^ *[A-z].*$/{ # if a line starts with alphabetical character, ignore the line if (dataflag == 1){ if (nl == 0) { # if the first data line startangle = $1; } if (nl == 1) { # if the second line comes, assuming angle step is the same anglestep = $1 - startangle; } if (nl > 1) {# check if angle step is constant # print $1, $1-oldangle, anglestep; if (abs(($1 - oldangle) - anglestep) > dangle) { print "Error: scan must be equally stepped!"; errorflag = 1; exit(-1); } } dat[nl] = $2; nl++; oldangle = $1; } } /^ Motor no\. *2.*$/ { #from next line, the datastarts dataflag = 1; } END{ ## recalculate anglestep finalangle = $1; anglestep = (finalangle - startangle)/(nl - 1.0); anglestep = int(anglestep/trancateangle)*trancateangle; ## record translation date "date" | getline translationdate; close("date"); ## now write out the raw file if (errorflag == 1) exit(-1); N = nl; NCHAN = N; NREC = int(N/10); if ((N/10.0 - int(N/10)) != 0){ NREC++; } title = sprintf("%s; converted by ngx2gsas.awk at %s", FILENAME, translationdate); ltitle = length(title); for(i = 0; i < (80-ltitle); i++){ title = title " "; } print title; bankinfo = sprintf("BANK 1 %d %d CONST %3.2f %3.2f 0 0 STD", NCHAN, NREC, startangle*100.0, anglestep*100.0); lbankinfo = length(bankinfo); for(i = 0; i < (80-lbankinfo); i++){ bankinfo = bankinfo " "; } print bankinfo; nl = 0; while(nl < N){ for (i = 0; i < 10; i++){ printf(" %6d", dat[nl]); nl++; if (nl == N) { i++; break; } } if (i < 10) { for (j = i; j < 10; j++){ printf(" ", dat[nl]); } } printf("\n"); } } function abs(x){ if (x < 0) { x = -x; } return (x); }