Error message "dataFile does not name a type"

I am attempting to run a Shinyei particulate matter sensor through Arduino. We have a working code that does not save data to an SD card but have been attempting to change the code to allow for an open log that we can leave to run for long trials. I have added parts of code from another particulate matter sensor run through arduino that works for logging its data, but when added to the Shinyei an error message pops up. Any suggestions?

Here is my code…

#include <SPI.h>
#include <SD.h>
const int  cs = 7; //chip select

int measurePin1 = 0; //Connect dust sensor to Arduino A0 pin
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 5000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;

void setup() {
 Serial.begin(9600);
 pinMode(8, INPUT);
 starttime = millis();//get the current time;
 RTC_init();
 //month(1-12), day(1-31), year(0-99), hour(0-23), minute(0-59), second(0-59)
 SetTimeDate(7, 2, 15, 15, 00, 55);
}

void loop() {
 duration = pulseIn(pin, LOW);
 lowpulseoccupancy = lowpulseoccupancy + duration;

 if ((millis() - starttime) > sampletime_ms) //if the sampel time == 30s
 {
   ratio = lowpulseoccupancy / (sampletime_ms * 10.0); // Integer percentage 0=>100
   concentration = 1.1 * pow(ratio, 3) - 3.8 * pow(ratio, 2) + 520 * ratio + 0.62; // using spec sheet curve
   // Serial.print("concentration = ");
   Serial.print(ReadTimeDate());
   Serial.print(",");
   Serial.println(concentration);
   delay(1000);
   // Serial.println(" pcs/0.01cf");
   // Serial.println("\n");
   lowpulseoccupancy = 0;
   starttime = millis();
 }
}



//=====================================
int RTC_init() {
 pinMode(cs, OUTPUT); // chip select
 // start the SPI library:
 SPI.begin();  SPI.setBitOrder(MSBFIRST);
 SPI.setDataMode(SPI_MODE1); // both mode 1 & 3 should work
 //set control register
 digitalWrite(cs, LOW);
 SPI.transfer(0x8E);
 SPI.transfer(0x60); //60= disable Osciallator and Battery SQ wave @1hz, temp compensation, Alarms disabled
 digitalWrite(cs, HIGH);
 delay(10);
}
//=====================================
int SetTimeDate(int d, int mo, int y, int h, int mi, int s) {
 int TimeDate [7] = {s, mi, h, 0, d, mo, y};
 for (int i = 0; i <= 6; i++) {
   if (i == 3)
     i++;
   int b = TimeDate[i] / 10;
   int a = TimeDate[i] - b * 10;
   if (i == 2) {
     if (b == 2)
       b = B00000010;
     else if (b == 1)
       b = B00000001;
   }
   TimeDate[i] = a + (b << 4);

   digitalWrite(cs, LOW);
   SPI.transfer(i + 0x80);
   SPI.transfer(TimeDate[i]);
   digitalWrite(cs, HIGH);
 }
}
//=====================================
String ReadTimeDate() {
 String temp;
 int TimeDate [7]; //second,minute,hour,null,day,month,year
 for (int i = 0; i <= 6; i++) {
   if (i == 3)
     i++;
   digitalWrite(cs, LOW);
   SPI.transfer(i + 0x00);
   unsigned int n = SPI.transfer(0x00);
   digitalWrite(cs, HIGH);
   int a = n & B00001111;
   if (i == 2) {
     int b = (n & B00110000) >> 4; //24 hour mode
     if (b == B00000010)
       b = 20;
     else if (b == B00000001)
       b = 10;
     TimeDate[i] = a + b;
   }
   else if (i == 4) {
     int b = (n & B00110000) >> 4;
     TimeDate[i] = a + b * 10;
   }
   else if (i == 5) {
     int b = (n & B00010000) >> 4;
     TimeDate[i] = a + b * 10;
   }
   else if (i == 6) {
     int b = (n & B11110000) >> 4;
     TimeDate[i] = a + b * 10;
   }
   else {
     int b = (n & B01110000) >> 4;
     TimeDate[i] = a + b * 10;
   }
 }
 temp.concat(TimeDate[4]);
 temp.concat("/") ;
 temp.concat(TimeDate[5]);
 temp.concat("/") ;
 temp.concat(TimeDate[6]);
 temp.concat("     ") ;
 temp.concat(TimeDate[2]);
 temp.concat(":") ;
 temp.concat(TimeDate[1]);
 temp.concat(":") ;
 temp.concat(TimeDate[0]);
 return (temp);
}



//============================================================


 File dataFile = SD.open("datalog.txt", FILE_WRITE);

// if (dataFile)
 dataFile.println(dataString);
 dataFile.close();

 //Serial.println(dataString);

 // else
//    Serial.println("error opening datalog.txt");
}
//======================================

Did you type that all on italics?

Edit your post and add [code] before the code and add [/code] after the code.

YOYOYOY don't people read this before posting a programming question and take note of the advice on how to post code ?

OP - look at the code in your original post. Does it really look like that, italics and all ? I think not.

You appear to have code not in a function.

You definitely have code that is not in code tags.