/********************* * * FUNCTION: cross_power * * DESCRIPTION: * Calculate the cross power between the 2 input arrays. * If the size of both input arrays is not a power of two they are padded to the next power of 2. * If input arrays have different size, the minimum is kept as being the size of both arrays. * ***********************/ void cross_power(INT16 *x, INT32 x_Nelements, INT16 *y, INT32 y_Nelements, FLOAT **mag, INT32 *mag_Nelements) { FLOAT *tempx = NULL; FLOAT *tempy = NULL; FLOAT tmp1,tmp2; INT32 count,count1; tempx = zeropad(x,&x_Nelements); tempy = zeropad(y,&y_Nelements); if (x_Nelements>y_Nelements) x_Nelements = y_Nelements; RealFFT(tempy,y_Nelements); RealFFT(tempx,x_Nelements); if ((*mag)==NULL) (*mag) = (FLOAT*) malloc( (x_Nelements/2) * sizeof(FLOAT)); for (count=0, count1=0; count<x_Nelements-1; count+=2,count1++) { tmp1 = tempx[count]*tempy[count]+tempx[count+1]*tempy[count+1]; tmp2 = tempx[count]*tempy[count+1]-tempx[count+1]*tempy[count]; (*mag)[count1] = (FLOAT) sqrt(tmp1*tmp1 + tmp2*tmp2); (*mag)[count1]/= (x_Nelements*x_Nelements); } *mag_Nelements = count1; free(tempx); free(tempy); }
/********************* * * FUNCTION: cross_power_ratio * * DESCRIPTION: * Compute the cross power correlation and a ratio at the end. * ***********************/ FLOAT cross_power_ratio(INT16 *x, INT32 x_Nelements, INT16 *y, INT32 y_Nelements) { FLOAT *tempx; FLOAT *tempy; FLOAT a=0,b=0,tmp1,tmp2; INT32 count; tempx = zeropad(x,&x_Nelements); tempy = zeropad(y,&y_Nelements); if (x_Nelements>y_Nelements) x_Nelements = y_Nelements; RealFFT(tempx,x_Nelements); RealFFT(tempy,y_Nelements); for (count=0; count<(x_Nelements*0.15); count+=2) { tmp1 = tempx[count]*tempy[count]+tempx[count+1]*tempy[count+1]; tmp2 = tempx[count]*tempy[count+1]-tempx[count+1]*tempy[count]; a+= (FLOAT) sqrt(tmp1*tmp1 + tmp2*tmp2); } for (count=(INT32)(x_Nelements*0.15); count<x_Nelements; count+=2) { tmp1 = tempx[count]*tempy[count]+tempx[count+1]*tempy[count+1]; tmp2 = tempx[count]*tempy[count+1]-tempx[count+1]*tempy[count]; b+= (FLOAT) sqrt(tmp1*tmp1 + tmp2*tmp2); } free(tempx); free(tempy); if (b!=0) return a/b; else return 0; }
int main(int argc, char *argv[]) { char temp[20]; char *foo; double x = 3.12345678901234551111; printf("X: %.10f\n", x); /* Left zero padding a string. */ #ifdef FOO sprintf(temp, "%0*s", 19, "12345"); printf("TEMP: %s\n", temp); /* Left zero padding a string. */ memset(temp, '0', sizeof temp - 1); printf("TEMP: %s\n", temp); foo = temp + sizeof temp - strlen("12345") - 1; sprintf(foo, "%s", "12345"); #endif zeropad("12345", temp, sizeof temp); printf(" 1 2\n"); printf(" 12345678901234567890\n"); printf("TEMP: %s\n", temp); exit(0); }
int writeCompressedGrain(FILE * infile, SectorType lba, FILE * of) { z_stream strm; int ret; int compressedBytes = 0; off_t bytesWritten = 0; size_t bytesRead = 0; u_int8_t buf[GRAINSIZE]; u_int8_t outbuf[2*GRAINSIZE]; memset(buf, 0, GRAINSIZE*sizeof(u_int8_t)); memset(outbuf, 0, GRAINSIZE*sizeof(u_int8_t)); bytesRead = fread(buf, 1, GRAINSIZE*sizeof(u_int8_t), infile); if (bytesRead == 0) { VPRINT("End of file reached.\n"); return 0; } if (! memcmp(buf, zerograin, GRAINSIZE*sizeof(u_int8_t))) { VPRINT("grain at LBA %lld is zero. skipping.\n", (long long)lba); return 0; } /* allocate deflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; ret = deflateInit(&strm, 1); if (ret != Z_OK) exit(2); strm.avail_in = bytesRead; strm.next_in = buf; strm.next_out = outbuf; strm.avail_out = 2*GRAINSIZE; ret = deflate(&strm, Z_FINISH); /* no bad return value */ assert(ret != Z_STREAM_ERROR); /* state not clobbered */ compressedBytes = 2*GRAINSIZE - strm.avail_out; assert(strm.avail_in == 0); /* all input will be used */ assert(ret == Z_STREAM_END); /* stream will be complete */ /* clean up and return */ (void)deflateEnd(&strm); /* write grain marker */ GrainMarker gm; memset(&gm, 0, sizeof(GrainMarker)); gm.lba = lba; gm.size = compressedBytes; bytesWritten = _fwrite((void *)&gm, sizeof(GrainMarker), 1, of); bytesWritten += _fwrite((void *)&outbuf, sizeof(u_int8_t), compressedBytes, of); VPRINT("Wrote a compressed grain of %lld bytes\n", (long long)bytesWritten); off_t padding = bytesWritten % SECTORSIZE; if (padding) { bytesWritten += zeropad(SECTORSIZE - padding, of); } return bytesWritten; }
int main() { zeropad(); printfield(); calculate(); if (check1() || check2() || check3()) printf("No solution\n"); else if (solve()) drawpath(); else printf("Path not found\n"); return 0; }
int writeCompressedGrainDirectory(u_int32_t * gd, int gdsize, FILE * of) { off_t bytesWritten; MetaDataMarker gdm; memset(&gdm, 0, sizeof(MetaDataMarker)); gdm.numSectors = gdsize / GRAINSECTORS; /* this needs to be determined by number of GTs */ gdm.type = MARKER_GD; bytesWritten = _fwrite((void *)&gdm, sizeof(MetaDataMarker), 1, of); VPRINT("Writing Grain Directory\n"); bytesWritten += _fwrite((void *) gd, sizeof(u_int32_t), gdsize, of); /* pad to a sector boundary */ off_t padding = SECTORSIZE - bytesWritten % SECTORSIZE; if (padding != SECTORSIZE) { bytesWritten += zeropad(padding, of); } return bytesWritten; }
int main(int ac, char** av) { if (ac != 2) error_macro("expecting 1 argument: CMAKE_BINARY_DIR") std::string dir = string(av[1]) + "/tests/fig_a/", h5 = dir + "out_blk_1m"; auto n = h5n(h5); for (int at = 0; at < n["t"]; ++at) // TODO: mark what time does it actually mean! { for (auto &plt : std::set<std::string>({"rc", "rr"})) { Gnuplot gp; init(gp, h5 + ".plot/" + plt + "/" + zeropad(at * n["outfreq"]) + ".svg", 1, 1, n); if (plt == "rc") { auto rc = h5load(h5, "rc", at * n["outfreq"]) * 1e3; gp << "set title 'cloud water mixing ratio r_c [g/kg]'\n"; gp << "set cbrange [0:1.5]\n"; plot(gp, rc); } if (plt == "rr") { auto rr = h5load(h5, "rr", at * n["outfreq"]) * 1e3; gp << "set logscale cb\n"; gp << "set title 'rain water mixing ratio r_r [g/kg]'\n"; gp << "set cbrange [1e-2:1]\n"; plot(gp, rr); } } } }
int main(int ac, char** av) { if (ac != 2) error_macro("expecting 1 argument: CMAKE_BINARY_DIR") std::string dir = string(av[1]) + "/paper_GMD_2015/fig_a/", h5 = dir + "out_lgrngn", svg = dir + "out_lgrngn_spec.svg"; Gnuplot gp; int off = 2; // TODO!!! float ymin = .4 * .01, ymax = .9 * 10000; const int at = 9000; gp << "set term svg dynamic enhanced fsize 15 size 900, 1500 \n"; gp << "set output '" << svg << "'\n"; gp << "set logscale xy\n"; gp << "set xrange [.002:100]\n"; gp << "set yrange [" << ymin << ":" << ymax << "]\n"; gp << "set ylabel '[mg^{-1} μm^{-1}]'\n"; // TODO: add textual description (PDF?) gp << "set grid\n"; gp << "set nokey\n"; // FSSP range gp << "set arrow from .5," << ymin << " to .5," << ymax << " nohead\n"; gp << "set arrow from 25," << ymin << " to 25," << ymax << " nohead\n"; gp << "set xlabel offset 0,1.5 'particle radius [μm]'\n"; gp << "set key samplen 1.2\n"; gp << "set xtics rotate by 65 right (.01, .1, 1, 10, 100) \n"; // TODO: use dashed lines to allow printing in black and white... same in image plots assert(focus.first.size() == focus.second.size()); gp << "set multiplot layout " << focus.first.size() << ",2 columnsfirst upwards\n"; // focus to the gridbox from where the size distribution is plotted char lbl = 'i'; for (auto &fcs : std::set<std::set<std::pair<int,int>>>({focus.first, focus.second})) { for (auto it = fcs.begin(); it != fcs.end(); ++it) { const int &x = it->first, &y = it->second; gp << "set label 1 '(" << lbl << ")' at graph -.15, 1.02 font ',20'\n"; //gp << "set title 'x=" << x << " y=" << y << "'\n"; std::map<float, float> focus_d; std::map<float, float> focus_w; //info on the number and location of histogram edges vector<quantity<si::length>> left_edges_rd = bins_dry(); int nsd = left_edges_rd.size() - 1; vector<quantity<si::length>> left_edges_rw = bins_wet(); int nsw = left_edges_rw.size() - 1; for (int i = 0; i < nsd; ++i) { const string name = "rd_rng" + zeropad(i) + "_mom0"; blitz::Array<float, 2> tmp_d(1e-6 * h5load(h5, name, at)); focus_d[left_edges_rd[i] / 1e-6 / si::metres] = sum(tmp_d( blitz::Range(x-1, x+1), blitz::Range(y-1, y+1) )) / 9 // mean over 9 gridpoints / ((left_edges_rd[i+1] - left_edges_rd[i]) / 1e-6 / si::metres); // per micrometre } for (int i = 0; i < nsw; ++i) { const string name = "rw_rng" + zeropad(i + off) + "_mom0"; blitz::Array<float, 2> tmp_w(1e-6 * h5load(h5, name, at)); focus_w[left_edges_rw[i] / 1e-6 / si::metres] = sum(tmp_w( blitz::Range(x-1, x+1), blitz::Range(y-1, y+1) )) / 9 / ((left_edges_rw[i+1] - left_edges_rw[i]) / 1e-6 / si::metres); // per micrometre } notice_macro("setting-up plot parameters"); gp << "plot" << "'-' with histeps title 'wet radius' lw 3 lc rgb 'blue'," << "'-' with histeps title 'dry radius' lw 1 lc rgb 'red' " << endl; gp.send(focus_w); gp.send(focus_d); lbl -= 2; } lbl = 'j'; } }