Dynamic naming of output .txt and/or numerical arrays

2 visualizaciones (últimos 30 días)
Eric Metzger
Eric Metzger el 6 de Abr. de 2020
Comentada: Eric Metzger el 6 de Abr. de 2020
Okay, before I begin my question, let me clearly state what this question is NOT. This question is not asking on how to dynamically name variables or calculation variables within my script, I know that is a very bad thing and can really muck things up.
So, my question is, what is the best way to go about setting up a script that will read in a file from multiple sources that will be of many different lengths and contatin data from mulltiple sites that use multple different names. The information in each row has the "site id" in the first column which will be used to create an output .txt file to parse and save the data for later use.
I have a static version of this script and it will tear through 10K files in about 3 min and put all the data for 24 different .txt files named by their "site id" in a nice orderly set for later analysis by a different script. Each variable is named carefully to make sure this happens with no errors. This works for one AOR but I now need to look at other AORs and each AOR has a different number of uniquely named sites (this is important as this identifies the geographic location and this information needs to be perserved). So I need a way to name my output and temporay arrays dynamically so that I can read in any AOR but still get the resolution and fidelity that I currenty get with my "fixed name and length" script. I don't like the idea of creating 62 different ingest files. Not fun.
Any suggestions?
  2 comentarios
James Tursa
James Tursa el 6 de Abr. de 2020
Can you give us a short example of the file(s) and what you would like as a result? Or describe your desired process in pseudo-code?
Eric Metzger
Eric Metzger el 6 de Abr. de 2020
Here is what part of the ingest code looks like (it is nearly 1000 lines long so I won't put all of it in here).
for i=1: length(D)
file=D(i,:) .name; % pull the file to be processed
workfile=readtable(file);
% Pull out date and other variables from the table, convert into a the
% formats that are needed to complete the function
% t = temporary variable to help parse date
% tv = temporary variable to help parse date
t=workfile(1,4);
%convert to an array/num
t=table2array(t);
% convert to a string
t=num2str(t);
% pull out the year, month and date, save into indiviidual variables and
% convert them back to a number for later use
yr=t(1:4);
yr=str2num(yr);
mm=t(5:6);
mm=str2num(mm);
dy=t(7:8);
dy=str2num(dy);
%place date information into an array and convert to a serial date using
%datenum
date=[yr mm dy];
startdate=datenum(date);
process=['Processing forecast file: ', file];
disp(process)
% Pull the individual station data out, store and then place into the
% needed mat file for later use and analysis
% Extract Actual storm total WFO QPF for specific sites
wfoict=workfile(1,6);
wfoict=table2array(wfoict);
wfolic=workfile(2,6);
wfolic=table2array(wfolic);
wfogrb=workfile(3,6);
wfogrb=table2array(wfogrb);
wfownd=workfile(4,6);
wfownd=table2array(wfownd);
This continues each site and you can see it pulls date information and then nformation from each site. What I need is a way to make arrays dynamice instead of "wfoict". I use readtable as this is the best way to pull the data and get into the form needed for later processing. The attachement is an example of one of the 24 files this script creates. It is a basic output but very easy for MatLab to read an process later.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Seismology en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by