def retrieve_to_file(diagg_name=None, shot=None, subshot=None, channel=None, outdir=None, get_data=True): """ run the retrieve standalone program to get data to files, and/or extract the parameter and summary information. Retrieve Usage from Oct 2009 tar file: Retrieve DiagName ShotNo SubShotNo ChNo [FileName] [-f FrameNo] [-h TransdServer] [-p root] [-n port] [-w|--wait [-t timeout] ] [-R|--real ] """ from pyfusion.acquisition.LHD.LHD_utils import get_free_bytes, purge_old from time import sleep # The old pyfusion used None to indicate this code could choose the location # in the new pyfusion, it is fixed in the config file. # if outdir == None: # outdir = tempfile.gettempdir() + '/' if not (path.exists(outdir)): makedirs(outdir) freebytes = get_free_bytes(outdir) if freebytes < 1e9: purge_old(outdir, "*dat") # ONLY DO .DAT have to manually purge prm if get_free_bytes(outdir) > freebytes * 0.9: print("Warning - unable to clear much space!") # cmd = str("retrieve %s %d %d %d %s" % (diagg_name, shot, subshot, channel, path.join(outdir, diagg_name))) if pyfusion.VERBOSE > 1: print("RETR: %s" % (cmd)) attempt = 1 while 1: if attempt > 1: print("attempt {a}, {c}".format(a=attempt, c=cmd)) retr_pipe = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (resp, err) = retr_pipe.communicate() if (err != "") or (retr_pipe.returncode != 0): attempt += 1 print(resp, err, attempt, ".") # , if attempt > 10: raise LookupError( str( "Error %d accessing retrieve:" "cmd=%s \nstdout=%s, stderr=%s" % (retr_pipe.poll(), cmd, resp, err) ) ) sleep(2) else: break fileroot = "" for lin in resp.split("\n"): if pyfusion.DEBUG > 3: print("*******", lin) if lin.find("parameter file") >= 0: fileroot = lin.split("[")[1].split(".prm")[0] if fileroot == "": raise LookupError("parameter file not found in <<{r}>>".format(r=resp)) return (resp, err, fileroot)
def retrieve_to_file(diagg_name=None, shot=None, subshot=None, channel=None, outdir = None, get_data=True): """ run the retrieve standalone program to get data to files, and/or extract the parameter and summary information. Retrieve Usage from Oct 2009 tar file: Retrieve DiagName ShotNo SubShotNo ChNo [FileName] [-f FrameNo] [-h TransdServer] [-p root] [-n port] [-w|--wait [-t timeout] ] [-R|--real ] """ from pyfusion.acquisition.LHD.LHD_utils import get_free_bytes, purge_old # The old pyfusion used None to indicate this code could choose the location # in the new pyfusion, it is fixed in the config file. # if outdir is None: # outdir = tempfile.gettempdir() + '/' if not(path.exists(outdir)): makedirs(outdir) freebytes=get_free_bytes(outdir) if freebytes < pyfusion.TMP_FREE_BYTES: try_for = 100 # go for 100 files, assum 500k on average purge_old(outdir, '*',try_for) #dat') # ONLY DO .DAT have to manually purge prm if (get_free_bytes(outdir) < freebytes*(try_for * 500e3)): pyfusion.logger.warning("Warning - unable to clear much space! {fGb:.1f}Gb free".format(fGb=freebytes/1e9)) # cmd = str("retrieve %s %d %d %d %s" % (diagg_name, shot, subshot, channel, path.join(outdir, diagg_name))) if (pyfusion.VERBOSE > 1): print('RETR: %s' % (cmd)) (dataOK, resp, err) = persevere_with(cmd, 10, quiet=False) # these errors are bad cmd_t = cmd.replace('retrieve', 'retrieve_t') (timeOK, trep, terr) = persevere_with(cmd_t, 10, quiet=True) # error => retrieve_t N/A fileroot = '' for lin in resp.split('\n'): if pyfusion.DBG() > 3: print('*******',lin) if lin.find('parameter file')>=0: fileroot = lin.split('[')[1].split('.prm')[0] if fileroot == '': raise LookupError('parameter file not found in <<{r}>>'.format(r=resp)) return(resp, err, fileroot, timeOK)
def retrieve_to_file(diagg_name=None, shot=None, subshot=None, channel=None, outdir=None, get_data=True): """ run the retrieve standalone program to get data to files, and/or extract the parameter and summary information. Retrieve Usage from Oct 2009 tar file: Retrieve DiagName ShotNo SubShotNo ChNo [FileName] [-f FrameNo] [-h TransdServer] [-p root] [-n port] [-w|--wait [-t timeout] ] [-R|--real ] """ from pyfusion.acquisition.LHD.LHD_utils import get_free_bytes, purge_old from time import sleep # The old pyfusion used None to indicate this code could choose the location # in the new pyfusion, it is fixed in the config file. # if outdir == None: # outdir = tempfile.gettempdir() + '/' if not (path.exists(outdir)): makedirs(outdir) freebytes = get_free_bytes(outdir) if freebytes < 1e9: purge_old(outdir, '*dat') # ONLY DO .DAT have to manually purge prm if (get_free_bytes(outdir) > freebytes * 0.9): print("Warning - unable to clear much space!") # cmd = str( "retrieve %s %d %d %d %s" % (diagg_name, shot, subshot, channel, path.join(outdir, diagg_name))) if (pyfusion.VERBOSE > 1): print('RETR: %s' % (cmd)) attempt = 1 while (1): if attempt > 1: print('attempt {a}, {c}'.format(a=attempt, c=cmd)) retr_pipe = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (resp, err) = retr_pipe.communicate() if (err != '') or (retr_pipe.returncode != 0): attempt += 1 print(resp, err, attempt, '.') #, if attempt > 10: raise LookupError( str("Error %d accessing retrieve:" "cmd=%s \nstdout=%s, stderr=%s" % (retr_pipe.poll(), cmd, resp, err))) sleep(2) else: break fileroot = '' for lin in resp.split('\n'): if pyfusion.DEBUG > 3: print('*******', lin) if lin.find('parameter file') >= 0: fileroot = lin.split('[')[1].split('.prm')[0] if fileroot == '': raise LookupError('parameter file not found in <<{r}>>'.format(r=resp)) return (resp, err, fileroot)