void temperature() { TGraph* g = new TGraph(); g->SetMarkerStyle( 20 ); g->SetMarkerSize( 0.5 ); enum { MONTHLY, ANNUAL }; int mode = ANNUAL; ifstream datafile; switch( mode ) { case MONTHLY: datafile.open( "monthly_global.dat" ); break; case ANNUAL: datafile.open( "annual_land_ocean.dat" ); break; } string line; int np = 0; while( getline( datafile, line, '\n' ) ) { float year, month, temp; float time = 0; if( mode == MONTHLY && sscanf( line.c_str(), "%f %f %f", &year, &month, &temp ) == 3 ) { time = year + ( month - 1 ) / 12.; } else if( mode == ANNUAL && sscanf( line.c_str(), "%f %f", &year, &temp ) == 2 ) { time = year; } if( time > 0 && temp > -999 ) { g->SetPoint( np++, year + ( month - 1 )/12., temp ); } } g->Set( np ); TH1* h = new TH1F( "htemp", "Global Temperature Anomaly", 150, 1990, 2020 ); h->SetMaximum( 1.0 ); h->SetMinimum( -1.0 ); h->SetStats( 0 ); h->SetXTitle( "Year" ); h->SetYTitle( "Temperature Anomaly [K]" ); h->Draw(); g->Draw( "p" ); }