int main(void) { printf( "\n I am now awake,\n" "I know this because when my eyes where closed " "I saw nothing but black darkness,\n" "and now that my eyes are open I see nothing...\n" "...but white fog.\n\n" " I get up,\n" "I feel sturdy ground beneath my feet,\n" "but an infernal abyss inside my mind.\n"); while(loop==1) { if(z == 0) { /*-input,cls&roommsg-*/ takeinp(); int i; for(i=0; i != 60; i++) printf("\n"); // clear screen rmsg("type w a s or d to move.\n"); /*-walls&objects-*/ room(0,8,0,8, " I see a great white wall forever rising to infinity...\n" "...How bland."); elev(6,2,4,13,1, " An elegant glass box materializes out of the mist,\n" "it has a height twice its length and width,\n" ">>I wonder if I should go inside, Yes or No : ", "I decide not to enter the box."); /*switches&effects*/ lvr(0,2,6,"I have found a lever. Do I pull it? ", "", "I have already pulled this lever."); /*-map&coordinates-*/ showmap(9,9,2,map0); printf("%i,%i,%i\n",x,y,z); } if(z == 1) { /*-input,cls&roommsg-*/ takeinp(); int i; for(i=0; i != 60; i++) printf("\n"); // clear screen rmsg( " I step into the elevator and the machine begins to hum\n" "as the doors close behind me.\n" "I notice the elevator has no buttons inside as it starts to move.\n" "The elevator continues for a time.\n\n" " The doors open with a hiss.\n" "I step outside and look at the space where I have been deposited,\n" "The white mist is still there, but I can see the ceiling now.\n" "There is a three dimensional network of pipes on the aforementioned ceiling.\n"); /*-walls&objects-*/ char wall[] = {" I see a network of pipes barring my way in that direction,\n" "some of the tubes rising to the ceiling are warm " "and others are very cold."}; char pillar[] = {" There is an unstable pillar before me.\n" "It reminds me of the foundation to all logic and reason."}; block(2,2,11,14,wall); block(6,6,11,14,wall); block(3,5,14,14,wall); block(1,3,8, 10,"you hit a tube"); block(5,7,8, 10,"you hit a tube"); block(0,0,0, 8 ,wall); block(8,8,0, 8 ,wall); block(0,8,0, 0 ,wall); block(4,4,6, 6 ,pillar); block(6,6,4, 4 ,pillar); block(4,4,2, 2 ,pillar); block(2,2,4, 4 ,pillar); elev(4,12,6,3,0,"I see an elevator, enter? ","I don\'t enter."); /*switches&effects*/ if(sw[0]) { map1[4][4]='E';elev(4,4,9,9,2, "I see an elevator, enter? ", "I don\'t enter."); } else { msg(4,4,4,4, " My foot scrapes against a rough spot on the ground,\n" "I look down and see a complex geometric design,\n" "surrounded by an inscription:\n\n" " 2,6,0"); } /*-map&coordinates-*/ showmap(15,9,2,map1); printf("%i,%i,%i\n",x,y,z); } if( z== 2) { /*-input,cls&roommsg-*/ takeinp(); int i; for(i=0; i != 60; i++) printf("\n"); // clear screen rmsg( "A voice echoes throught the room;\n\n" "\"Welcome to the Infinite Cube,\n" "The Cube is a prototype in alternate-reality technology.\n" "You may ask how we know this space is a cube if it is, as has been previously stated, infinite.\n" "Don\'t.\n\n" "It consists of several levels,\n" "designed to test your mental abilities,\n" "which are being enhanced by experiments in the real world.\n" "You are perfectly safe...\n\n" "... as far as we know.\""); /*-walls&objects-*/ char cube[]= {" You see a large cube.\n" "It is inscribed with strange symbols.\n" "They seem to indicate the turning of a lever...\n" "...this is giving me second thoughts about turning that lever."}; block(4 ,6 ,8 ,10,cube); block(8 ,10,4 ,6 ,cube); block(12,14,8 ,10,cube); char wall[]= {""}; block(7 ,11,0 ,0, wall); block(5 ,7 ,0 ,5 ,wall); block(0 ,5, 5, 7 ,wall); block(0 ,0 ,7 ,11,wall); block(0 ,5 ,11,13,wall); block(5 ,7 ,13,18,wall); block(7 ,11,18,18,wall); block(11,13,13,18,wall); block(13,18,11,13,wall); block(18,18,7 ,11,wall); block(13,19,5 ,7 ,wall); block(11,13,0 ,5 ,wall); //...cont. in book /*switches&effects*/ lvr(1,9,11,"I see a lever, do I pull it? ", "", "I already pulled the lever"); if(sw[1]) { map2[13][9]=' '; msg(8 ,10,12,14, "I see the cube around me,\n" "but I can't touch it."); } else {block(8 ,10,12,14,cube);} /*-map&coordinates-*/ showmap(19,19,4,map2); printf("%i,%i,%i\n",x,y,z); } } return 0 ; }
RcppExport SEXP gridStash( const SEXP R_gtc, const SEXP R_gpr, const SEXP R_gfs, const SEXP R_gcChar ) { NumericMatrix temp(R_gtc), prec(R_gpr), fsun(R_gfs), gcChar(R_gcChar); NumericVector lon = fsun(_,0), lat = fsun(_,1), elev = gcChar(_,2), fcap = gcChar(_,3), swc0 = gcChar(_,4); float miss_val; unsigned int mn; unsigned long ll, ncell = fsun.nrow(); NumericMatrix gTOT (ncell,nvar+2), gAET (ncell,14), gEET (ncell,14), gPET (ncell,14), gDET (ncell,14), gPAR (ncell,14), gMI (ncell,14), gALPHA (ncell,14), gGDD0 (ncell,14), gGDD5 (ncell,14), gGDD10 (ncell,14), gCHILL (ncell,14), gRO (ncell,14), gSWC0 (ncell,3); GridCell gridCell; // initialise vectors in object gridCell.init_Day (0.0); gridCell.init_Month (0.0); gridCell.resIn_Year (0.0); // create a new line ready for the progress bar cout << endl; // run through each grid cell and perform daily time-series calculations for( ll=0; ll<ncell; ll++ ) { // initialise the cell and zero object private members gridCell.reset_Day (0.0); gridCell.reset_Month(0.0); gridCell.resIn_Year (0.0); // set cell characteristics gridCell.set_Cell( ll+1 ); gridCell.set_Elev( elev(ll) ); gridCell.set_Fcap( fcap(ll) ); gridCell.set_Coord( lat(ll), lon(ll) ); // if SWC has a value then set this as the initial condition and no spin-up is required if(swc0[ll]!=-9999.) { gridCell.init_SMC( swc0[ll] ); gridCell.set_SpinUp(false); } else { gridCell.set_SpinUp(true); } // store monthly climate drivers in the gridCell object (+2 to get rid of lat-lon columns) for( mn=0; mn<gridCell.get_MLEN(); mn++ ) { gridCell.set_mTEMP( temp(ll,mn+2), mn ); gridCell.set_mFSUN( fsun(ll,mn+2), mn ); gridCell.set_mPPT ( prec(ll,mn+2), mn ); } // echo progress to user if( ll == 0 ) { cout << "STASH Progress:" << endl; } progress_bar(ll, ncell); // if the grid cell does not have any missing values miss_val = gridCell.get_Missing(); if((gridCell.get_mTEMP(1) != miss_val) | (gridCell.get_mFSUN(1) != miss_val) | (gridCell.get_mPPT(1) != miss_val)) { // linearly interpolate monthly values to daily values for the climate drivers gridCell.linearINT( gridCell, gridCell.get_mFSUN(), &GridCell::set_dFSUN ); gridCell.linearINT( gridCell, gridCell.get_mTEMP(), &GridCell::set_dTEMP ); gridCell.linearINT( gridCell, gridCell.get_mPPT (), &GridCell::set_dPPT ); // do water balance calculations waterBucket( gridCell ); // perform monthly and annual sums gridCell.growDegDay(); gridCell.monthlySums(); gridCell.monthlyIndex(); gridCell.annualSums(); } else { gridCell.set_MissingCell(); } // convert back to matrices for export to R assign_Rinit ( gridCell, ll, gSWC0, 364, &GridCell::get_dSMC ); assign_Rtotal( gridCell, ll, gTOT ); assign_Rmonth( gridCell, ll, gAET, &GridCell::get_mAET ); assign_Rmonth( gridCell, ll, gEET, &GridCell::get_mEET ); assign_Rmonth( gridCell, ll, gPET, &GridCell::get_mPET ); assign_Rmonth( gridCell, ll, gDET, &GridCell::get_mDET ); assign_Rmonth( gridCell, ll, gPAR, &GridCell::get_mPAR ); assign_Rmonth( gridCell, ll, gRO, &GridCell::get_mRUN ); assign_Rmonth( gridCell, ll, gMI, &GridCell::get_mMI ); assign_Rmonth( gridCell, ll, gALPHA, &GridCell::get_mALPHA ); assign_Rmonth( gridCell, ll, gGDD0, &GridCell::get_mGDD0 ); assign_Rmonth( gridCell, ll, gGDD5, &GridCell::get_mGDD5 ); assign_Rmonth( gridCell, ll, gGDD10, &GridCell::get_mGDD10 ); assign_Rmonth( gridCell, ll, gCHILL, &GridCell::get_mCHILL ); } // flush screen ready for R output cout << endl << endl; // return SEXP-list to user with outputs return List::create( _("annual") = gTOT, _("act.evap") = gAET, _("equ.evap") = gEET, _("pot.evap") = gPET, _("del.evap") = gDET, _("photo.abs") = gPAR, _("moist.index") = gMI, _("alpha.index") = gALPHA, _("run.off") = gRO, _("grow.deg0") = gGDD0, _("grow.deg5") = gGDD5, _("grow.deg10") = gGDD10, _("chill.day") = gCHILL, _("swc.init") = gSWC0 ); }