#! /usr/bin/awk -f ## this is a test translator for filman sc output to ## gsas raw file ## NOTE: anglestep must be constant; the data should be in equal step. ## taku j sato 2006/04/06 ## 2007/09/07: translation date displayed in the raw file BEGIN{ dataflag = 0; nl = 0; } # on 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) > 0.001) { print "Error: scan must be equally stepped!"; errorflag = 1; exit(-1); } } dat[nl] = $3; nl++; oldangle = $1; } } /^ *CALC A2.*$/ { #from next line, the datastarts dataflag = 1; } END{ if (errorflag == 1) exit(-1); N = nl; NCHAN = N; NREC = int(N/10); if ((N/10.0 - int(N/10)) != 0){ NREC++; } ## record translation date "date" | getline translationdate; close("date"); title = sprintf("%s; converted by filman2gsas.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); }