#!/usr/bin/env perl
# Run NRG calculations for a range of fields. Extract the magnetization
# and tabulate the magnetization curve, <Sz>(B)

use warnings;

open (O, ">magnetization-n.dat") or die;

for ($b = 1e-8 ; $b <= 1e-1; $b *= 1.5) {
    # m4 is a macro processor. It replaces FIELD with the value of $b
    system "m4 -DFIELD=-$b param.m4 >param";
    # Run the NRG
    system "nrginit ; nrgrun";
    # Extract <SZ> at the lowest temperature
    $SZ = `extractcolumn custom SZ | tail -n 1`;
    $SZ *= -1; # flip sign
    print "$b $SZ\n";
    print O "$b $SZ\n";
}
