How do I get microsoft word or pycharm to read dot files as a graphic instead of code - ms-word

When I open my .dot file with microsoft word or pycharm it shows me the code and that the code is error free but doesnt display the intended graphic.
I have extensively searched on google for a solution but google insists that microsoft word comes with the ability to read .dot files (which it seems to be able to read the code but not display the graphic). I downloaded the pycharm .dot reading plug-in and now pycharm can read the code and it says that the code is error free, but again it does not display the graphic.
I am unsure what code is necessary so I am just giving the whole thing.
digraph Tree {
node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ;
edge [fontname=helvetica] ;
0 [label="failures <= 0.5\nsamples = 100.0%\nvalue = [0.502, 0.498]\nclass = fail", fillcolor="#e5813902"] ;
1 [label="higher_no <= 0.5\nsamples = 84.8%\nvalue = [0.422, 0.578]\nclass = pass", fillcolor="#399de545"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="school_GP <= 0.5\nsamples = 79.2%\nvalue = [0.386, 0.614]\nclass = pass", fillcolor="#399de55e"] ;
1 -> 2 ;
3 [label="absences <= 1.5\nsamples = 23.0%\nvalue = [0.574, 0.426]\nclass = fail", fillcolor="#e5813942"] ;
2 -> 3 ;
4 [label="freetime <= 4.5\nsamples = 12.4%\nvalue = [0.419, 0.581]\nclass = pass", fillcolor="#399de547"] ;
3 -> 4 ;
5 [label="samples = 11.6%\nvalue = [0.379, 0.621]\nclass = pass", fillcolor="#399de563"] ;
4 -> 5 ;
6 [label="samples = 0.8%\nvalue = [1.0, 0.0]\nclass = fail", fillcolor="#e58139ff"] ;
4 -> 6 ;
7 [label="health <= 1.5\nsamples = 10.6%\nvalue = [0.755, 0.245]\nclass = fail", fillcolor="#e58139ac"] ;
3 -> 7 ;
8 [label="samples = 2.2%\nvalue = [0.455, 0.545]\nclass = pass", fillcolor="#399de52a"] ;
7 -> 8 ;
9 [label="samples = 8.4%\nvalue = [0.833, 0.167]\nclass = fail", fillcolor="#e58139cc"] ;
7 -> 9 ;
10 [label="Walc <= 3.5\nsamples = 56.2%\nvalue = [0.31, 0.69]\nclass = pass", fillcolor="#399de58d"] ;
2 -> 10 ;
11 [label="Medu <= 3.5\nsamples = 46.4%\nvalue = [0.263, 0.737]\nclass = pass", fillcolor="#399de5a4"] ;
10 -> 11 ;
12 [label="samples = 29.4%\nvalue = [0.333, 0.667]\nclass = pass", fillcolor="#399de57f"] ;
11 -> 12 ;
13 [label="samples = 17.0%\nvalue = [0.141, 0.859]\nclass = pass", fillcolor="#399de5d5"] ;
11 -> 13 ;
14 [label="sex_M <= 0.5\nsamples = 9.8%\nvalue = [0.531, 0.469]\nclass = fail", fillcolor="#e581391d"] ;
10 -> 14 ;
15 [label="samples = 3.0%\nvalue = [0.267, 0.733]\nclass = pass", fillcolor="#399de5a2"] ;
14 -> 15 ;
16 [label="samples = 6.8%\nvalue = [0.647, 0.353]\nclass = fail", fillcolor="#e5813974"] ;
14 -> 16 ;
17 [label="reason_course <= 0.5\nsamples = 5.6%\nvalue = [0.929, 0.071]\nclass = fail", fillcolor="#e58139eb"] ;
1 -> 17 ;
18 [label="health <= 3.5\nsamples = 2.6%\nvalue = [0.846, 0.154]\nclass = fail", fillcolor="#e58139d1"] ;
17 -> 18 ;
19 [label="samples = 1.4%\nvalue = [1.0, 0.0]\nclass = fail", fillcolor="#e58139ff"] ;
18 -> 19 ;
20 [label="reason_home <= 0.5\nsamples = 1.2%\nvalue = [0.667, 0.333]\nclass = fail", fillcolor="#e581397f"] ;
18 -> 20 ;
21 [label="samples = 0.6%\nvalue = [0.333, 0.667]\nclass = pass", fillcolor="#399de57f"] ;
20 -> 21 ;
22 [label="samples = 0.6%\nvalue = [1.0, 0.0]\nclass = fail", fillcolor="#e58139ff"] ;
20 -> 22 ;
23 [label="samples = 3.0%\nvalue = [1.0, 0.0]\nclass = fail", fillcolor="#e58139ff"] ;
17 -> 23 ;
24 [label="Fjob_teacher <= 0.5\nsamples = 15.2%\nvalue = [0.947, 0.053]\nclass = fail", fillcolor="#e58139f1"] ;
0 -> 24 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
25 [label="Fjob_health <= 0.5\nsamples = 15.0%\nvalue = [0.96, 0.04]\nclass = fail", fillcolor="#e58139f4"] ;
24 -> 25 ;
26 [label="freetime <= 1.5\nsamples = 14.8%\nvalue = [0.973, 0.027]\nclass = fail", fillcolor="#e58139f8"] ;
25 -> 26 ;
27 [label="Mjob_at_home <= 0.5\nsamples = 0.6%\nvalue = [0.667, 0.333]\nclass = fail", fillcolor="#e581397f"] ;
26 -> 27 ;
28 [label="samples = 0.2%\nvalue = [0.0, 1.0]\nclass = pass", fillcolor="#399de5ff"] ;
27 -> 28 ;
29 [label="samples = 0.4%\nvalue = [1.0, 0.0]\nclass = fail", fillcolor="#e58139ff"] ;
27 -> 29 ;
30 [label="age <= 16.5\nsamples = 14.2%\nvalue = [0.986, 0.014]\nclass = fail", fillcolor="#e58139fb"] ;
26 -> 30 ;
31 [label="samples = 2.4%\nvalue = [0.917, 0.083]\nclass = fail", fillcolor="#e58139e8"] ;
30 -> 31 ;
32 [label="samples = 11.8%\nvalue = [1.0, 0.0]\nclass = fail", fillcolor="#e58139ff"] ;
30 -> 32 ;
33 [label="samples = 0.2%\nvalue = [0.0, 1.0]\nclass = pass", fillcolor="#399de5ff"] ;
25 -> 33 ;
34 [label="samples = 0.2%\nvalue = [0.0, 1.0]\nclass = pass", fillcolor="#399de5ff"] ;
24 -> 34 ;
}
I expect the above code to display a color-coded decision tree. Instead microsoft word, pycharm, and jupyter notebook are all returning the code.

A GraphViz .dot file is not an image file. It rather contains a logical description of some content (nodes and edges), along with some graphical clues how to display them (e.g. color, font sizes). The exact positions of each element are not defined in the .dot file at all. Calculating these positions, and rendering actual image files, is left to a layout engine, such as dot, or derived Javascript libraries (e.g. viz.js).
Almost no application can display GraphViz .dot files directly.
The confusion probably comes from a conflicting naming convention:
GraphViz .dot file (what we are talking about here)
Microsoft .dot file (what Word is expecting and Google might refer to)
A Microsoft .dot file is a template for a Microsoft Word (.doc) file.
In order to present your desired graphic, you need to run your .dot file through a layout engine to produce e.g. an .svg or .png file.
You can do this manually on your local PC or online (e.g. https://dreampuf.github.io/GraphvizOnline/ ), then save the resulting image.
You can present both .svg and .png images in Word (Insert / Image).

I have been able to get the .dot file to open properly using GVEdit (graphviz text editor). Here is a link to a post that answers my question. Graphviz: How to go from .dot to a graph?

Don't try to open dot file directly from word as it will give an error. Open Ms-word first then locate the dot file which you want to open.

Related

Issue trying to sub sample an image

I am trying to resize a given image by sub-sampling it. I am using grayscae iamges.
The way I understand sub-sampling is basically this:
Let's say we have an 5x5 image and we want to resize it by a factor of 2, so the output image will be 3x3.
So if the 5x5 is: (1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20; 21 22 23 24 25)
Then the 3x3 will be: (1 3 5; 11 13 15; 21 23 25)
So if the factor is 2, for the first row we take the first sample and then every second sample and so on. The same for columns.
The code that I wrote for this is:
i = 0;
j = 0;
for row=1:old_rows
if mod((row-1), a) == 0
i = i + 1;
end
for col=1:old_cols
if mod((row-1), a) == 0 && mod((col-1), a) == 0
j = j + 1;
sub_sampled_I(i, j) = I(row, col); % I is the input image
end
end
j = 0;
end
sub_sampled_I = im2uint8(sub_sampled_I);
end
The issue is that the final image has nothing to do with the original. It is just a white image with some black points here and there. What I understand wrong about sub-sampling?

Octave: How can I index single element of an array?

I have the following code written in Octave:
1 %-----------------------------------------------------------------------------%
2 % INPUT SIGNAL %
3 %-----------------------------------------------------------------------------%
4
5 sampling_frequency = 8000;
6 sampling_period = 1/sampling_frequency;
7 samples_count = 8;
8 time_samples = sampling_period * (0 : samples_count-1);
9
10
11 amplitude_1 = 1;
12 frequency_1 = 1000;
13 phase_shift_1 = 0;
14 signal_samples_1 = amplitude_1*sin(2*pi * frequency_1 * ...
15 time_samples + phase_shift_1);
16
17
18 amplitude_2 = 0.5;
19 frequency_2 = 2000;
20 phase_shift_2 = 3*pi/4;
21 signal_samples_2 = amplitude_2*sin(2*pi * frequency_2 * ...
22 time_samples + phase_shift_2);
23
24 signal_samples = signal_samples_1 + signal_samples_2;
25 for samples_index = 0 : samples_count-1
26 fprintf(stdout, "Sample %d: ", samples_index)
27 endfor
28
As you may see, at line 25, I would like to print value of each sample at separate line, i.e.
Sample <sample_number>: <sample_value>
My question is: how can I index separate member of an array (e.g. input_signal array)?
I have found the solution by myself, so I would like to share it with you.
signal_samples = signal_samples_1 + signal_samples_2;
for samples_index = 1 : samples_count
fprintf(stdout, "Sample %d: %8.5f\n", samples_index-1, ...
signal_samples(samples_index:samples_index))
endfor
Output:
Sample 0: 0.35355
Sample 1: 0.35355
Sample 2: 0.64645
Sample 3: 1.06066
Sample 4: 0.35355
Sample 5: -1.06066
Sample 6: -1.35355
Sample 7: -0.35355

How to convert Julian dates to and from different representations using integer arithmetic

The question is how to convert dates between different representations using integer arithmetic, specifically between a "Days since year zero ( Jan 1, 0000 )" representation, and either Year/Day or Year/Month/Day forms, in the Julian calendar. The different representations are useful for date input, date display and date arithmetic.
Specifically, a date such as June 5th, 2020 is represented in Year/Month/Day representation as
2020 * 512 + 6 * 32 + 5
or in Year/Day representation as
2020 * 512 + 157 ( June 5th is day 157 in a leap year ).
Yesterday, I wanted to write code to do this, and surprisingly didn't find much help online, so I thought I would document my solution here ( I will be answering my own question ).
First here is code for converting from Year/Day to Days ( the language is very similar to Microsoft SQL Server T-SQL, except variable names do not begin with '#', and there is a 'bool" data type ) :
CREATE FUNCTION [date].[YearDayToDays]( yd int ) RETURNS int AS
BEGIN
-- Given a date in Year/Day representation stored as y * 512 + d where 1 <= d <= 366 ( so d is day in year )
-- returns the number of days since "day zero" (1 Jan 0000)
-- using the Gregorian calendar where days divisible by 4 are leap years, except if divisible by 100, except if divisible by 400.
DECLARE y int, d int, cycle int
-- Extract y and d from yd.
SET y = yd / 512, d = yd % 512 - 1
SET cycle = y / 400, y = y % 400 -- The Gregorian calendar repeats every 400 years.
-- Result days come from cycles, from years having at least 365 days, from leap years and finally d.
-- 146097 is the number of the days in a 400 year cycle ( 400 * 365 + 97 leap years ).
RETURN cycle * 146097
+ y * 365
+ ( y + 3 ) / 4 - ( y + 99 ) / 100 + ( y + 399 ) / 400
+ d
END
Now the opposite conversion, Days to Year/Day:
CREATE FUNCTION [date].[DaysToYearDay]( days int ) returns int as
begin
-- Given a date represented by the number of days since 1 Jan 0000
-- calculate a date in Year/Day representation stored as
-- y * 512 + d where d is 1..366
DECLARE y int, d int, cycle int
-- 146097 is the number of the days in a 400 year cycle ( 400 * 365 + 97 leap years )
SET cycle = days / 146097
SET days = days % 146097
SET y = days / 365
SET d = days % 365
-- Need to adjust d to allow for leap years.
-- Leap years are 0, 4, 8, 12 ... 96, not 100, 104 ... not 200... not 300, 400, 404 ... not 500.
-- Adjustment as function of y is 0 => 0, 1 => 1, 2 =>1, 3 => 1, 4 => 1, 5 => 2 ..
SET d = d - ( y + 3 ) / 4 - ( y + 99 ) / 100 + ( y + 399 ) / 400
IF d < 0
BEGIN
SET y = y - 1
SET d = d + CASE WHEN date.IsLeapYear( y ) THEN 366 ELSE 365 END
END
RETURN date.YearDay( cycle * 400 + y, d + 1 )
END
The auxiliary function date.IsLeapYear:
CREATE FUNCTION [date].[IsLeapYear]( y int ) RETURNS bool AS
BEGIN
RETURN y % 4 = 0 AND ( y % 100 != 0 OR y % 400 = 0 )
END
and date.YearDay :
CREATE FUNCTION [date].[YearMonthDay]( year int, month int, day int ) RETURNS int AS
BEGIN
RETURN year * 512 + month * 32 + day
END
Conversion from Year/Day to Year/Month/Day:
CREATE FUNCTION [date].[YearDayToYearMonthDay]( yd int ) returns int AS
BEGIN
DECLARE y int, d int, leap bool, fdm int, m int, dim int
SET y = yd / 512
SET d = yd % 512 - 1
SET leap = date.IsLeapYear( y )
-- Jan = 0..30, Feb = 0..27 or 0..28
IF NOT leap AND d >= 59 SET d = d + 1
SET fdm = CASE
WHEN d < 31 THEN 0 -- Jan
WHEN d < 60 THEN 31 -- Feb
WHEN d < 91 THEN 60 -- Mar
WHEN d < 121 THEN 91 -- Apr
WHEN d < 152 THEN 121 -- May
WHEN d < 182 THEN 152 -- Jun
WHEN d < 213 THEN 182 -- Jul
WHEN d < 244 THEN 213 -- Aug
WHEN d < 274 THEN 244 -- Sep
WHEN d < 305 THEN 274 -- Oct
WHEN d < 335 THEN 305 -- Nov
ELSE 335 -- Dec
END
SET dim = d - fdm
SET m = ( d - dim + 28 ) / 31
RETURN date.YearMonthDay( y, m+1, dim+1 )
END
The auxiliary function date.YearMonthDay:
CREATE FUNCTION [date].[YearMonthDay]( year int, month int, day int ) RETURNS int AS
BEGIN
RETURN year * 512 + month * 32 + day
END
Finally conversion from Year/Month/Day to Year/Day:
CREATE FUNCTION [date].[YearMonthDayToYearDay]( ymd int ) RETURNS int AS
BEGIN
DECLARE y int, m int, d int
-- Extract y, m, d from ymd
SET d = ymd % 32, m = ymd / 32
SET y = m / 16, m = m % 16
-- Incorporate m into d ( assuming Feb has 29 days ).
SET d = d + CASE
WHEN m = 1 THEN 0 -- Jan
WHEN m = 2 THEN 31 -- Feb
WHEN m = 3 THEN 60 -- Mar
WHEN m = 4 THEN 91 -- Apr
WHEN m = 5 THEN 121 -- May
WHEN m = 6 THEN 152 -- Jun
WHEN m = 7 THEN 182 -- Jul
WHEN m = 8 THEN 213 -- Aug
WHEN m = 9 THEN 244 -- Sep
WHEN m = 10 THEN 274 -- Oct
WHEN m = 11 THEN 305 -- Nov
ELSE 335 -- Dec
END
-- Allow for Feb being only 28 days in a non-leap-year.
IF m >= 3 AND NOT date.IsLeapYear( y ) SET d = d - 1
RETURN date.YearDay( y, d )
END
I hope it's useful to someone, and I hope it's correct - I have tested by generating test ranges of days to check the generated calendar looks correct, with the correct number of days in each month, especially February. The functions do not check whether the input is valid, that is assumed. This is part of a project to implement SQL in C#.

while loop in my program does not fill the second row

I have 2 inner while loops. Code writes the results to first row on the matrix but when it gets to second row, it just passes the other rows and doesn't fill the columns of the rows. How to solve it? The code and output are like below:
while i <= m-1
i
while a <= m-1
a
den1 = sqrt(((xy{i,j}-xy{a+1,b})^2+(xy{i,j+1}-xy{a+1,b+1})^2 ));
dMat(i,a) = den1;
a = a+1;
end
i = i+1;
end
i = 1
a = 1
a = 2
a = 3
a = 4
a = 5
a = 6
a = 7
a = 8
a = 9
a = 10
a = 11
a = 12
a = 13
a = 14
a = 15
a = 16
a = 17
a = 18
a = 19
a = 20
a = 21
a = 22
a = 23
a = 24
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
i = 9
i = 10
i = 11
i = 12
i = 13
i = 14
i = 15
i = 16
i = 17
i = 18
i = 19
i = 20
i = 21
i = 22
i = 23
i = 24
You have to restart a to a=1 for each iteration. Put it above the while a <= m-1

Export Netcdf variable to text using matlab

I am a newbie with netcdf files and have been trying to export one of the variables from netcdf .nc format to a text file (ascii etc) using MATLAB.
I am able to read the netcdf file using nc_dump, and get the variable using nc_varget.
But when I try saving the variable (which is 4D double), it does not saves a 4D file, instead it saves just the values in that particular variable.
My code:
nc_dump('filename.nc')
var1 = nc_varget('filename.nc','var1');
var2 = nc_varget('filename.nc','var2');
var3 = nc_varget('filename.nc','var3');
var4 = nc_varget('filename.nc','var4');
var5 = nc_varget('filename.nc','var5');
for i = 1:length(var1)
for j = 1:length(var2)
for k = 1:length(var3)
for l = 1:length(var4)
for m = 1:length(var5)
data(i,j,k,l,m) = [var1(i), var2(j), var3(k), var4(l), var5(i,j,k,l)];
end
end
end
end
end
dlmwrite(‘data.txt’, data)
Output from nc_dump:
nc_dump('geoschem_nestedNA_10_20041010.nc')
NetCDF-3 Classic geoschem_nestedNA_10_20041010.nc {
dimensions:
lon = 151 ;
lat = 121 ;
lev = 37 ;
time = UNLIMITED ; (7 currently)
variables:
// Preference 'PRESERVE_FVD': false,
// dimensions consistent with ncBrowse, not with native MATLAB netcdf package.
single lon(lon), shape = [151]
lon:long_name = "Longitude" ;
lon:units = "degrees_east" ;
single lat(lat), shape = [121]
lat:long_name = "Latitude" ;
lat:units = "degrees_north" ;
single lev(lev), shape = [37]
lev:long_name = "Eta Centers" ;
lev:units = "sigma_level" ;
single time(time), shape = [7]
time:long_name = "Time" ;
time:units = "hours since 1985-1-1 00:00:0.0" ;
time:delta_t = "0000-00-00 03:00:00" ;
single IJ_AVG_S__NOx(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__NOx:long_name = "NOx tracer" ;
IJ_AVG_S__NOx:units = "ppbv" ;
single IJ_AVG_S__ACET(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__ACET:long_name = "ACET tracer" ;
IJ_AVG_S__ACET:units = "ppbC" ;
single IJ_AVG_S__SO2(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SO2:long_name = "SO2 tracer" ;
IJ_AVG_S__SO2:units = "ppbv" ;
single IJ_AVG_S__SO4(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SO4:long_name = "SO4 tracer" ;
IJ_AVG_S__SO4:units = "ppbv" ;
single IJ_AVG_S__NH4(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__NH4:long_name = "NH4 tracer" ;
IJ_AVG_S__NH4:units = "ppbv" ;
single IJ_AVG_S__NIT(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__NIT:long_name = "NIT tracer" ;
IJ_AVG_S__NIT:units = "ppbv" ;
single IJ_AVG_S__BCPI(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__BCPI:long_name = "BCPI tracer" ;
IJ_AVG_S__BCPI:units = "ppbv" ;
single IJ_AVG_S__OCPI(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__OCPI:long_name = "OCPI tracer" ;
IJ_AVG_S__OCPI:units = "ppbv" ;
single IJ_AVG_S__BCPO(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__BCPO:long_name = "BCPO tracer" ;
IJ_AVG_S__BCPO:units = "ppbv" ;
single IJ_AVG_S__OCPO(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__OCPO:long_name = "OCPO tracer" ;
IJ_AVG_S__OCPO:units = "ppbv" ;
single IJ_AVG_S__ALPH(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__ALPH:long_name = "ALPH tracer" ;
IJ_AVG_S__ALPH:units = "ppbv" ;
single IJ_AVG_S__LIMO(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__LIMO:long_name = "LIMO tracer" ;
IJ_AVG_S__LIMO:units = "ppbv" ;
single IJ_AVG_S__ALCO(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__ALCO:long_name = "ALCO tracer" ;
IJ_AVG_S__ALCO:units = "ppbv" ;
single IJ_AVG_S__SOG1(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOG1:long_name = "SOG1 tracer" ;
IJ_AVG_S__SOG1:units = "ppbv" ;
single IJ_AVG_S__SOG2(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOG2:long_name = "SOG2 tracer" ;
IJ_AVG_S__SOG2:units = "ppbv" ;
single IJ_AVG_S__SOG3(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOG3:long_name = "SOG3 tracer" ;
IJ_AVG_S__SOG3:units = "ppbv" ;
single IJ_AVG_S__SOG4(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOG4:long_name = "SOG4 tracer" ;
IJ_AVG_S__SOG4:units = "ppbv" ;
single IJ_AVG_S__SOG5(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOG5:long_name = "SOG5 tracer" ;
IJ_AVG_S__SOG5:units = "ppbv" ;
single IJ_AVG_S__SOA1(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOA1:long_name = "SOA1 tracer" ;
IJ_AVG_S__SOA1:units = "ppbv" ;
single IJ_AVG_S__SOA2(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOA2:long_name = "SOA2 tracer" ;
IJ_AVG_S__SOA2:units = "ppbv" ;
single IJ_AVG_S__SOA3(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOA3:long_name = "SOA3 tracer" ;
IJ_AVG_S__SOA3:units = "ppbv" ;
single IJ_AVG_S__SOA4(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOA4:long_name = "SOA4 tracer" ;
IJ_AVG_S__SOA4:units = "ppbv" ;
single IJ_AVG_S__SOA5(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SOA5:long_name = "SOA5 tracer" ;
IJ_AVG_S__SOA5:units = "ppbv" ;
single IJ_AVG_S__DST1(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__DST1:long_name = "DST1 tracer" ;
IJ_AVG_S__DST1:units = "ppbv" ;
single IJ_AVG_S__DST2(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__DST2:long_name = "DST2 tracer" ;
IJ_AVG_S__DST2:units = "ppbv" ;
single IJ_AVG_S__DST3(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__DST3:long_name = "DST3 tracer" ;
IJ_AVG_S__DST3:units = "ppbv" ;
single IJ_AVG_S__DST4(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__DST4:long_name = "DST4 tracer" ;
IJ_AVG_S__DST4:units = "ppbv" ;
single IJ_AVG_S__SALA(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SALA:long_name = "SALA tracer" ;
IJ_AVG_S__SALA:units = "ppbv" ;
single IJ_AVG_S__SALC(time,lev,lat,lon), shape = [7 37 121 151]
IJ_AVG_S__SALC:long_name = "SALC tracer" ;
IJ_AVG_S__SALC:units = "ppbv" ;
single DAO_FLDS__PARDF(time,lev,lat,lon), shape = [7 37 121 151]
DAO_FLDS__PARDF:long_name = "GMAO PARDF field" ;
DAO_FLDS__PARDF:units = "W/m2" ;
single DAO_FLDS__PARDR(time,lev,lat,lon), shape = [7 37 121 151]
DAO_FLDS__PARDR:long_name = "GMAO PARDR field" ;
DAO_FLDS__PARDR:units = "W/m2" ;
single DAO_FLDS__TS(time,lev,lat,lon), shape = [7 37 121 151]
DAO_FLDS__TS:long_name = "GMAO TS field" ;
DAO_FLDS__TS:units = "K" ;
single TIME_SER__D_LAI(time,lev,lat,lon), shape = [7 37 121 151]
TIME_SER__D_LAI:long_name = "Daily LAI" ;
TIME_SER__D_LAI:units = "m2/m2" ;
single BIOGSRCE__ISOP(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__ISOP:long_name = "ISOP emissions" ;
BIOGSRCE__ISOP:units = "atomC/cm2/s" ;
single BIOGSRCE__MONOT(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__MONOT:long_name = "MONOT emissions" ;
BIOGSRCE__MONOT:units = "atomC/cm2/s" ;
single BIOGSRCE__MBO(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__MBO:long_name = "MBO emissions" ;
BIOGSRCE__MBO:units = "atomC/cm2/s" ;
single BIOGSRCE__APINE(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__APINE:long_name = "APINE emissions" ;
BIOGSRCE__APINE:units = "atomC/cm2/s" ;
single BIOGSRCE__BPINE(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__BPINE:long_name = "BPINE emissions" ;
BIOGSRCE__BPINE:units = "atomC/cm2/s" ;
single BIOGSRCE__LIMON(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__LIMON:long_name = "LIMON emissions" ;
BIOGSRCE__LIMON:units = "atomC/cm2/s" ;
single BIOGSRCE__SABIN(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__SABIN:long_name = "SABIN emissions" ;
BIOGSRCE__SABIN:units = "atomC/cm2/s" ;
single BIOGSRCE__MYRCN(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__MYRCN:long_name = "MYRCN emissions" ;
BIOGSRCE__MYRCN:units = "atomC/cm2/s" ;
single BIOGSRCE__CAREN(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__CAREN:long_name = "CAREN emissions" ;
BIOGSRCE__CAREN:units = "atomC/cm2/s" ;
single BIOGSRCE__OCIMN(time,lev,lat,lon), shape = [7 37 121 151]
BIOGSRCE__OCIMN:long_name = "OCIMN emissions" ;
BIOGSRCE__OCIMN:units = "atomC/cm2/s" ;
//global attributes:
:Title = "COARDS/netCDF file created by BPCH2COARDS (GAMAP v2-03+)" ;
:Model = "GEOS5_47L" ;
:Delta_Lon = 0.666667 f;
:Delta_Lat = 0.500000 f;
:NLayers = 47 d;
:Start_Date = 20041010 d;
:Start_Time = 0 d;
:End_Date = 20041010 d;
:End_Time = 21 d;
:Delta_Time = 3 d;
:Conventions = "COARDS" ;
The datafile can be found at the following link:
https://www.dropbox.com/s/8fnpw71yc60fm6z/geoschem_nestedNA_10_20041010.nc
Could someone please help me?
I'm late to the thread but I think this code update should work.
Instead of using
data(i,j,k,l,m) = [var1(i), var2(j), var3(k), var4(l), var5(i,j,k,l)];
which creates a multi-dimensional matrix, I wanted to create a table with each variable filled in.
THis is probably not the most efficient code (I'm very new, opened Matlab for the first time yesterday new) but I think this code works.
The dataset is created, then overwritten so that memory does not have to be continuously reallocated
for n = 2008:2010
name = sprintf('tmax_daily_%d-%d.nc', n, n );
name2 = sprintf('tmax_daily_%d.txt', n);
nc= netcdf.open(name)
data=zeros(2000000000,5);
long3=netcdf.getVar(nc,0);
long=mod((long3+180),360)-180;
lat=netcdf.getVar(nc,1);
height=netcdf.getVar(nc,2);
time=netcdf.getVar(nc,3);
tmax=netcdf.getVar(nc,4);
row=1;
for i=1:length(long)
for j=1:length(lat)
for k=1:length(height)
for l=1:length(time)
for m=1:length(tmax)
data(row,1)=[long(i)];
data(row,2)=[lat(j)];
data(row,3)=[height(k)];
data(row,4)=[time(l)];
data(row,5)=[tmax(i,j,k,l)];
row=row+1;
end
end
end
end
end
csvwrite(name2,data)
fprintf('%d done\n',n);
clear
end